41 #if RTE_VERSION < RTE_VERSION_NUM(21, 0, 0, 0)
42 #define I40E_RSS_HKEY_LEN 40
43 #define I40E_RSS_HASH_FUNCTION RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ
45 #define I40E_RSS_HKEY_LEN 52
46 #define I40E_RSS_HASH_FUNCTION RTE_ETH_HASH_FUNCTION_TOEPLITZ
47 #endif // RTE_VERSION < RTE_VERSION_NUM(21, 0, 0, 0)
49 #if RTE_VERSION < RTE_VERSION_NUM(20, 0, 0, 0)
50 static int i40eDeviceEnableSymHash(
51 int port_id,
const char *port_name, uint32_t ftype,
enum rte_eth_hash_function
function)
53 struct rte_eth_hash_filter_info info;
57 memset(&info, 0,
sizeof(info));
59 #pragma GCC diagnostic push
60 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
61 retval = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_HASH);
62 #pragma GCC diagnostic pop
64 SCLogError(
"%s: RTE_ETH_FILTER_HASH not supported", port_name);
68 info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
69 info.info.global_conf.hash_func =
function;
71 idx = ftype / UINT64_BIT;
72 offset = ftype % UINT64_BIT;
73 info.info.global_conf.valid_bit_mask[idx] |= (1ULL <<
offset);
74 info.info.global_conf.sym_hash_enable_mask[idx] |= (1ULL <<
offset);
76 #pragma GCC diagnostic push
77 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
78 retval = rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_HASH, RTE_ETH_FILTER_SET, &info);
79 #pragma GCC diagnostic pop
82 SCLogError(
"%s: cannot set global hash configurations", port_name);
89 static int i40eDeviceSetSymHash(
int port_id,
const char *port_name,
int enable)
92 struct rte_eth_hash_filter_info info;
94 memset(&info, 0,
sizeof(info));
96 #pragma GCC diagnostic push
97 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
98 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_HASH);
99 #pragma GCC diagnostic pop
102 SCLogError(
"%s: RTE_ETH_FILTER_HASH not supported", port_name);
106 info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
107 info.info.enable = enable;
108 #pragma GCC diagnostic push
109 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
110 ret = rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_HASH, RTE_ETH_FILTER_SET, &info);
111 #pragma GCC diagnostic pop
114 SCLogError(
"%s: cannot set symmetric hash enable per port", port_name);
121 static int i40eDeviceApplyRSSFilter(
int port_id,
const char *port_name)
127 retval |= i40eDeviceEnableSymHash(
128 port_id, port_name, RTE_ETH_FLOW_FRAG_IPV4, RTE_ETH_HASH_FUNCTION_TOEPLITZ);
129 retval |= i40eDeviceEnableSymHash(
130 port_id, port_name, RTE_ETH_FLOW_NONFRAG_IPV4_TCP, RTE_ETH_HASH_FUNCTION_TOEPLITZ);
131 retval |= i40eDeviceEnableSymHash(
132 port_id, port_name, RTE_ETH_FLOW_NONFRAG_IPV4_UDP, RTE_ETH_HASH_FUNCTION_TOEPLITZ);
133 retval |= i40eDeviceEnableSymHash(
134 port_id, port_name, RTE_ETH_FLOW_NONFRAG_IPV4_SCTP, RTE_ETH_HASH_FUNCTION_TOEPLITZ);
135 retval |= i40eDeviceEnableSymHash(
136 port_id, port_name, RTE_ETH_FLOW_NONFRAG_IPV4_OTHER, RTE_ETH_HASH_FUNCTION_TOEPLITZ);
138 retval |= i40eDeviceEnableSymHash(
139 port_id, port_name, RTE_ETH_FLOW_FRAG_IPV6, RTE_ETH_HASH_FUNCTION_TOEPLITZ);
140 retval |= i40eDeviceEnableSymHash(
141 port_id, port_name, RTE_ETH_FLOW_NONFRAG_IPV6_TCP, RTE_ETH_HASH_FUNCTION_TOEPLITZ);
142 retval |= i40eDeviceEnableSymHash(
143 port_id, port_name, RTE_ETH_FLOW_NONFRAG_IPV6_UDP, RTE_ETH_HASH_FUNCTION_TOEPLITZ);
144 retval |= i40eDeviceEnableSymHash(
145 port_id, port_name, RTE_ETH_FLOW_NONFRAG_IPV6_SCTP, RTE_ETH_HASH_FUNCTION_TOEPLITZ);
146 retval |= i40eDeviceEnableSymHash(
147 port_id, port_name, RTE_ETH_FLOW_NONFRAG_IPV6_OTHER, RTE_ETH_HASH_FUNCTION_TOEPLITZ);
149 retval |= i40eDeviceSetSymHash(port_id, port_name, 1);
153 static int32_t i40eDeviceSetRSSWithFilter(
int port_id,
const char *port_name)
155 int32_t ret = BondingIsBond(port_id);
160 i40eDeviceApplyRSSFilter(port_id, port_name);
161 }
else if (ret == 0) {
162 uint16_t bonded_devs[RTE_MAX_ETHPORTS];
163 ret = BondingMemberDevicesGet(port_id, bonded_devs, RTE_MAX_ETHPORTS);
164 for (
int i = 0; i < ret; i++) {
165 i40eDeviceApplyRSSFilter(bonded_devs[i], port_name);
168 FatalError(
"Unknown return value from BondingIsBond()");
176 static int i40eDeviceSetRSSFlowIPv4(
177 int port_id,
const char *port_name,
struct rte_flow_action_rss rss_conf)
180 struct rte_flow_item pattern[] = { { 0 }, { 0 }, { 0 }, { 0 } };
182 pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
183 pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4;
184 pattern[2].type = RTE_FLOW_ITEM_TYPE_END;
185 ret |= DPDKCreateRSSFlow(port_id, port_name, rss_conf,
186 RTE_ETH_RSS_NONFRAG_IPV4_OTHER | RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY,
188 memset(pattern, 0,
sizeof(pattern));
190 pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
191 pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4;
192 pattern[2].type = RTE_FLOW_ITEM_TYPE_UDP;
193 pattern[3].type = RTE_FLOW_ITEM_TYPE_END;
194 ret |= DPDKCreateRSSFlow(port_id, port_name, rss_conf,
195 RTE_ETH_RSS_NONFRAG_IPV4_UDP | RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY,
197 memset(pattern, 0,
sizeof(pattern));
199 pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
200 pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4;
201 pattern[2].type = RTE_FLOW_ITEM_TYPE_TCP;
202 pattern[3].type = RTE_FLOW_ITEM_TYPE_END;
203 ret |= DPDKCreateRSSFlow(port_id, port_name, rss_conf,
204 RTE_ETH_RSS_NONFRAG_IPV4_TCP | RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY,
206 memset(pattern, 0,
sizeof(pattern));
208 pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
209 pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4;
210 pattern[2].type = RTE_FLOW_ITEM_TYPE_SCTP;
211 pattern[3].type = RTE_FLOW_ITEM_TYPE_END;
212 ret |= DPDKCreateRSSFlow(port_id, port_name, rss_conf,
213 RTE_ETH_RSS_NONFRAG_IPV4_SCTP | RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY,
215 memset(pattern, 0,
sizeof(pattern));
220 static int i40eDeviceSetRSSFlowIPv6(
221 int port_id,
const char *port_name,
struct rte_flow_action_rss rss_conf)
224 struct rte_flow_item pattern[] = { { 0 }, { 0 }, { 0 }, { 0 } };
226 pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
227 pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV6;
228 pattern[2].type = RTE_FLOW_ITEM_TYPE_END;
229 ret |= DPDKCreateRSSFlow(port_id, port_name, rss_conf,
230 RTE_ETH_RSS_NONFRAG_IPV6_OTHER | RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY,
232 memset(pattern, 0,
sizeof(pattern));
234 pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
235 pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV6;
236 pattern[2].type = RTE_FLOW_ITEM_TYPE_UDP;
237 pattern[3].type = RTE_FLOW_ITEM_TYPE_END;
238 ret |= DPDKCreateRSSFlow(port_id, port_name, rss_conf,
239 RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY,
241 memset(pattern, 0,
sizeof(pattern));
243 pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
244 pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV6;
245 pattern[2].type = RTE_FLOW_ITEM_TYPE_TCP;
246 pattern[3].type = RTE_FLOW_ITEM_TYPE_END;
247 ret |= DPDKCreateRSSFlow(port_id, port_name, rss_conf,
248 RTE_ETH_RSS_NONFRAG_IPV6_TCP | RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY,
250 memset(pattern, 0,
sizeof(pattern));
252 pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
253 pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV6;
254 pattern[2].type = RTE_FLOW_ITEM_TYPE_SCTP;
255 pattern[3].type = RTE_FLOW_ITEM_TYPE_END;
256 ret |= DPDKCreateRSSFlow(port_id, port_name, rss_conf,
257 RTE_ETH_RSS_NONFRAG_IPV6_SCTP | RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY,
259 memset(pattern, 0,
sizeof(pattern));
264 static int i40eDeviceSetRSSWithFlows(
int port_id,
const char *port_name,
int nb_rx_queues)
266 uint16_t queues[RTE_MAX_QUEUES_PER_PORT];
267 struct rte_flow_error flush_error = { 0 };
268 struct rte_eth_rss_conf rss_conf = {
270 .rss_key_len = I40E_RSS_HKEY_LEN,
273 if (nb_rx_queues < 1) {
274 FatalError(
"The number of queues for RSS configuration must be "
275 "configured with a positive number");
278 struct rte_flow_action_rss rss_action_conf =
279 DPDKInitRSSAction(rss_conf, nb_rx_queues, queues, RTE_ETH_HASH_FUNCTION_DEFAULT,
false);
281 int retval = DPDKSetRSSFlowQueues(port_id, port_name, rss_action_conf);
283 memset(&rss_action_conf, 0,
sizeof(
struct rte_flow_action_rss));
284 rss_action_conf = DPDKInitRSSAction(rss_conf, 0, queues, I40E_RSS_HASH_FUNCTION,
true);
286 retval |= i40eDeviceSetRSSFlowIPv4(port_id, port_name, rss_action_conf);
287 retval |= i40eDeviceSetRSSFlowIPv6(port_id, port_name, rss_action_conf);
289 retval = rte_flow_flush(port_id, &flush_error);
291 SCLogError(
"%s: unable to flush rte_flow rules: %s Flush error msg: %s", port_name,
292 rte_strerror(-retval), flush_error.message);
302 int i40eDeviceSetRSS(
int port_id,
int nb_rx_queues,
char *port_name)
306 #if RTE_VERSION >= RTE_VERSION_NUM(20, 0, 0, 0)
307 i40eDeviceSetRSSWithFlows(port_id, port_name, nb_rx_queues);
309 i40eDeviceSetRSSWithFilter(port_id, port_name);
314 void i40eDeviceSetRSSConf(
struct rte_eth_rss_conf *rss_conf)
316 #if RTE_VERSION >= RTE_VERSION_NUM(20, 0, 0, 0)
317 rss_conf->rss_hf = RTE_ETH_RSS_FRAG_IPV4 | RTE_ETH_RSS_NONFRAG_IPV4_OTHER |
318 RTE_ETH_RSS_FRAG_IPV6 | RTE_ETH_RSS_NONFRAG_IPV6_OTHER;
319 rss_conf->rss_key = NULL;
320 rss_conf->rss_key_len = 0;
323 RTE_ETH_RSS_FRAG_IPV4 | RTE_ETH_RSS_NONFRAG_IPV4_TCP | RTE_ETH_RSS_NONFRAG_IPV4_UDP |
324 RTE_ETH_RSS_NONFRAG_IPV4_SCTP | RTE_ETH_RSS_NONFRAG_IPV4_OTHER | RTE_ETH_RSS_FRAG_IPV6 |
325 RTE_ETH_RSS_NONFRAG_IPV6_TCP | RTE_ETH_RSS_NONFRAG_IPV6_UDP |
326 RTE_ETH_RSS_NONFRAG_IPV6_SCTP | RTE_ETH_RSS_NONFRAG_IPV6_OTHER | RTE_ETH_RSS_SCTP;