1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) 2023 Google LLC 3 */ 4 5 #include "gve_adminq.h" 6 #include "gve_ethdev.h" 7 8 #define GVE_RSS_HASH_IPV4 BIT(0) 9 #define GVE_RSS_HASH_TCPV4 BIT(1) 10 #define GVE_RSS_HASH_IPV6 BIT(2) 11 #define GVE_RSS_HASH_IPV6_EX BIT(3) 12 #define GVE_RSS_HASH_TCPV6 BIT(4) 13 #define GVE_RSS_HASH_TCPV6_EX BIT(5) 14 #define GVE_RSS_HASH_UDPV4 BIT(6) 15 #define GVE_RSS_HASH_UDPV6 BIT(7) 16 #define GVE_RSS_HASH_UDPV6_EX BIT(8) 17 18 #define GVE_RSS_OFFLOAD_DEFAULT ( \ 19 GVE_RSS_HASH_IPV4 | \ 20 GVE_RSS_HASH_TCPV4 | \ 21 GVE_RSS_HASH_IPV6 | \ 22 GVE_RSS_HASH_IPV6_EX | \ 23 GVE_RSS_HASH_TCPV6 | \ 24 GVE_RSS_HASH_TCPV6_EX | \ 25 GVE_RSS_HASH_UDPV4 | \ 26 GVE_RSS_HASH_UDPV6 | \ 27 GVE_RSS_HASH_UDPV6_EX) 28 29 /** 30 * Generates default RSS redirection table based on the number of queues the 31 * device is configured with. This assigns hash values to queues in a 32 * round-robin manner. 33 */ 34 int 35 gve_generate_rss_reta(struct rte_eth_dev *dev, struct gve_rss_config *config); 36 37 /** 38 * Initializes `gve_rss_conf`, setting the fields to default values and 39 * allocating memory for the RSS key and redirection table. 40 */ 41 int 42 gve_init_rss_config(struct gve_rss_config *gve_rss_conf, 43 uint16_t key_size, uint16_t indir_size); 44 45 /** 46 * Initializes `gve_rss_conf` based on the RSS configuration stored in `priv`. 47 */ 48 int 49 gve_init_rss_config_from_priv(struct gve_priv *priv, 50 struct gve_rss_config *gve_rss_conf); 51 52 /** 53 * Frees RSS key and redriection table pointers stored in `gve_rss_conf`. 54 */ 55 void 56 gve_free_rss_config(struct gve_rss_config *gve_rss_conf); 57 58 /** 59 * Updates the rss_config stored in `priv` with the contents of `config`. 60 */ 61 int 62 gve_update_priv_rss_config(struct gve_priv *priv, 63 struct gve_rss_config *config); 64 65 /** 66 * Updates the RSS key stored in `gve_rss_conf`. It is prioritized as follows: 67 * 1) retrieve from `rss_conf`, if non-null 68 * 2) retrieve from `priv`, if non-null 69 * If keys from both sources are unset, return -EINVAL. 70 */ 71 int 72 gve_update_rss_key(struct gve_priv *priv, struct gve_rss_config *gve_rss_conf, 73 struct rte_eth_rss_conf *rss_conf); 74 75 /** 76 * Updates the RSS hash types stored in `gve_rss_conf`. It is prioritized as 77 * follows: 78 * 1) retrieve from `rss_conf`, if set 79 * 2) retrieve from priv, if RSS has been configured 80 * 3) set default RSS offload 81 */ 82 int 83 gve_update_rss_hash_types(struct gve_priv *priv, 84 struct gve_rss_config *gve_rss_conf, struct rte_eth_rss_conf *rss_conf); 85 86 /** 87 * Ensures that only supported RSS hash fields are set in `rte_rss_hf`. 88 */ 89 static inline int 90 gve_validate_rss_hf(uint64_t rte_rss_hf) { 91 return rte_rss_hf & ~GVE_RTE_RSS_OFFLOAD_ALL; 92 } 93 94 /** 95 * Converts RSS hash types from RTE values to GVE values, storing them in 96 * `gve_rss_conf`. 97 */ 98 void 99 rte_to_gve_rss_hf(uint64_t rte_rss_hf, struct gve_rss_config *gve_rss_conf); 100 101 /** 102 * Converts RSS hash types from GVE values to RTE values, storing them in 103 * `rss_conf`. 104 */ 105 void 106 gve_to_rte_rss_hf(uint16_t gve_rss_types, struct rte_eth_rss_conf *rss_conf); 107 108