Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2020 Intel Corporation
3 : : */
4 : :
5 : : #include <stdio.h>
6 : : #include <errno.h>
7 : : #include <stdint.h>
8 : : #include <string.h>
9 : :
10 : : #include "base/i40e_prototype.h"
11 : : #include "i40e_logs.h"
12 : : #include "i40e_ethdev.h"
13 : : #include "i40e_hash.h"
14 : :
15 : : #include "../common/flow_check.h"
16 : : const uint8_t i40e_rss_key_default[] = {
17 : : 0x44, 0x39, 0x79, 0x6b,
18 : : 0xb5, 0x4c, 0x50, 0x23,
19 : : 0xb6, 0x75, 0xea, 0x5b,
20 : : 0x12, 0x4f, 0x9f, 0x30,
21 : : 0xb8, 0xa2, 0xc0, 0x3d,
22 : : 0xdf, 0xdc, 0x4d, 0x02,
23 : : 0xa0, 0x8c, 0x9b, 0x33,
24 : : 0x4a, 0xf6, 0x4a, 0x4c,
25 : : 0x05, 0xc6, 0xfa, 0x34,
26 : : 0x39, 0x58, 0xd8, 0x55,
27 : : 0x7d, 0x99, 0x58, 0x3a,
28 : : 0xe1, 0x38, 0xc9, 0x2e,
29 : : 0x81, 0x15, 0x03, 0x66
30 : : };
31 : :
32 : : static int
33 : 0 : i40e_hash_config_func(struct i40e_hw *hw, enum rte_eth_hash_function func)
34 : : {
35 : : struct i40e_pf *pf;
36 : : uint32_t reg;
37 : : uint8_t symmetric = 0;
38 : :
39 : 0 : reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
40 : :
41 [ # # ]: 0 : if (func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
42 [ # # ]: 0 : if (!(reg & I40E_GLQF_CTL_HTOEP_MASK))
43 : 0 : goto set_symmetric;
44 : :
45 : 0 : reg &= ~I40E_GLQF_CTL_HTOEP_MASK;
46 : : } else {
47 [ # # ]: 0 : if (func == RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ)
48 : : symmetric = 1;
49 : :
50 [ # # ]: 0 : if (reg & I40E_GLQF_CTL_HTOEP_MASK)
51 : 0 : goto set_symmetric;
52 : :
53 : 0 : reg |= I40E_GLQF_CTL_HTOEP_MASK;
54 : : }
55 : :
56 : 0 : pf = &((struct i40e_adapter *)hw->back)->pf;
57 [ # # ]: 0 : if (pf->support_multi_driver) {
58 : 0 : PMD_DRV_LOG(ERR,
59 : : "Modify hash function is not permitted when multi-driver enabled");
60 : 0 : return -EPERM;
61 : : }
62 : :
63 : 0 : PMD_DRV_LOG(INFO, "NIC hash function is setting to %d", func);
64 : 0 : i40e_write_rx_ctl(hw, I40E_GLQF_CTL, reg);
65 : 0 : I40E_WRITE_FLUSH(hw);
66 : :
67 : 0 : set_symmetric:
68 : 0 : i40e_set_symmetric_hash_enable_per_port(hw, symmetric);
69 : 0 : return 0;
70 : : }
71 : :
72 : : static int
73 : 0 : i40e_hash_config_pctype_symmetric(struct i40e_hw *hw,
74 : : uint32_t pctype,
75 : : bool symmetric)
76 : : {
77 : 0 : struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
78 : : uint32_t reg;
79 : :
80 : 0 : reg = i40e_read_rx_ctl(hw, I40E_GLQF_HSYM(pctype));
81 [ # # ]: 0 : if (symmetric) {
82 [ # # ]: 0 : if (reg & I40E_GLQF_HSYM_SYMH_ENA_MASK)
83 : : return 0;
84 : 0 : reg |= I40E_GLQF_HSYM_SYMH_ENA_MASK;
85 : : } else {
86 [ # # ]: 0 : if (!(reg & I40E_GLQF_HSYM_SYMH_ENA_MASK))
87 : : return 0;
88 : 0 : reg &= ~I40E_GLQF_HSYM_SYMH_ENA_MASK;
89 : : }
90 : :
91 [ # # ]: 0 : if (pf->support_multi_driver) {
92 : 0 : PMD_DRV_LOG(ERR,
93 : : "Enable/Disable symmetric hash is not permitted when multi-driver enabled");
94 : 0 : return -EPERM;
95 : : }
96 : :
97 : 0 : i40e_write_rx_ctl(hw, I40E_GLQF_HSYM(pctype), reg);
98 : 0 : I40E_WRITE_FLUSH(hw);
99 : 0 : return 0;
100 : : }
101 : :
102 : : static void
103 : 0 : i40e_hash_enable_pctype(struct i40e_hw *hw,
104 : : uint32_t pctype, bool enable)
105 : : {
106 : : uint32_t reg, reg_val, mask;
107 : :
108 [ # # ]: 0 : if (pctype < 32) {
109 : 0 : mask = BIT(pctype);
110 : : reg = I40E_PFQF_HENA(0);
111 : : } else {
112 : 0 : mask = BIT(pctype - 32);
113 : : reg = I40E_PFQF_HENA(1);
114 : : }
115 : :
116 : 0 : reg_val = i40e_read_rx_ctl(hw, reg);
117 : :
118 [ # # ]: 0 : if (enable) {
119 [ # # ]: 0 : if (reg_val & mask)
120 : : return;
121 : :
122 : 0 : reg_val |= mask;
123 : : } else {
124 [ # # ]: 0 : if (!(reg_val & mask))
125 : : return;
126 : :
127 : 0 : reg_val &= ~mask;
128 : : }
129 : :
130 : 0 : i40e_write_rx_ctl(hw, reg, reg_val);
131 : 0 : I40E_WRITE_FLUSH(hw);
132 : : }
133 : :
134 : : static int
135 : 0 : i40e_hash_config_pctype(struct i40e_hw *hw,
136 : : struct i40e_rss_conf *rss_conf,
137 : : uint32_t pctype)
138 : : {
139 : 0 : uint64_t rss_types = rss_conf->types;
140 : : int ret;
141 : :
142 [ # # ]: 0 : if (rss_types == 0) {
143 : 0 : i40e_hash_enable_pctype(hw, pctype, false);
144 : 0 : return 0;
145 : : }
146 : :
147 [ # # ]: 0 : if (rss_conf->inset) {
148 : 0 : ret = i40e_set_hash_inset(hw, rss_conf->inset, pctype, false);
149 [ # # ]: 0 : if (ret)
150 : : return ret;
151 : : }
152 : :
153 : 0 : i40e_hash_enable_pctype(hw, pctype, true);
154 : 0 : return 0;
155 : : }
156 : :
157 : : static int
158 : 0 : i40e_hash_config_region(struct i40e_pf *pf,
159 : : const struct i40e_rss_conf *rss_conf)
160 : : {
161 : 0 : struct i40e_hw *hw = &pf->adapter->hw;
162 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
163 : 0 : struct i40e_queue_region_info *regions = pf->queue_region.region;
164 : 0 : uint32_t num = pf->queue_region.queue_region_number;
165 : : uint32_t i, region_id_mask = 0;
166 : :
167 : : /* Use a 32 bit variable to represent all regions */
168 : : RTE_BUILD_BUG_ON(I40E_REGION_MAX_INDEX > 31);
169 : :
170 : : /* Re-configure the region if it existed */
171 [ # # ]: 0 : for (i = 0; i < num; i++) {
172 : 0 : if (rss_conf->region_queue_start ==
173 [ # # ]: 0 : regions[i].queue_start_index &&
174 [ # # ]: 0 : rss_conf->region_queue_num == regions[i].queue_num) {
175 : : uint32_t j;
176 : :
177 [ # # ]: 0 : for (j = 0; j < regions[i].user_priority_num; j++) {
178 : 0 : if (regions[i].user_priority[j] ==
179 [ # # ]: 0 : rss_conf->region_priority)
180 : : return 0;
181 : : }
182 : :
183 [ # # ]: 0 : if (j >= I40E_MAX_USER_PRIORITY) {
184 : 0 : PMD_DRV_LOG(ERR,
185 : : "Priority number exceed the maximum %d",
186 : : I40E_MAX_USER_PRIORITY);
187 : 0 : return -ENOSPC;
188 : : }
189 : :
190 : 0 : regions[i].user_priority[j] = rss_conf->region_priority;
191 : 0 : regions[i].user_priority_num++;
192 : 0 : return i40e_flush_queue_region_all_conf(dev, hw, pf, 1);
193 : : }
194 : :
195 : 0 : region_id_mask |= BIT(regions[i].region_id);
196 : : }
197 : :
198 [ # # ]: 0 : if (num > I40E_REGION_MAX_INDEX) {
199 : 0 : PMD_DRV_LOG(ERR, "Queue region resource used up");
200 : 0 : return -ENOSPC;
201 : : }
202 : :
203 : : /* Add a new region */
204 : :
205 : 0 : pf->queue_region.queue_region_number++;
206 : 0 : memset(®ions[num], 0, sizeof(regions[0]));
207 : :
208 : 0 : regions[num].region_id = rte_bsf32(~region_id_mask);
209 : 0 : regions[num].queue_num = rss_conf->region_queue_num;
210 : 0 : regions[num].queue_start_index = rss_conf->region_queue_start;
211 : 0 : regions[num].user_priority[0] = rss_conf->region_priority;
212 : 0 : regions[num].user_priority_num = 1;
213 : :
214 : 0 : return i40e_flush_queue_region_all_conf(dev, hw, pf, 1);
215 : : }
216 : :
217 : : int
218 : 0 : i40e_hash_program_hw(struct i40e_pf *pf,
219 : : struct i40e_rss_conf *rss_conf)
220 : : {
221 : 0 : struct i40e_hw *hw = &pf->adapter->hw;
222 : : uint64_t pctypes;
223 : : int ret;
224 : :
225 [ # # ]: 0 : if (rss_conf->func != RTE_ETH_HASH_FUNCTION_DEFAULT) {
226 : 0 : ret = i40e_hash_config_func(hw, rss_conf->func);
227 [ # # ]: 0 : if (ret)
228 : : return ret;
229 : : }
230 : :
231 [ # # ]: 0 : if (rss_conf->region_queue_num > 0) {
232 : 0 : ret = i40e_hash_config_region(pf, rss_conf);
233 [ # # ]: 0 : if (ret)
234 : : return ret;
235 : : }
236 : :
237 [ # # ]: 0 : if (rss_conf->key_len > 0) {
238 : 0 : ret = i40e_set_rss_key(pf->main_vsi, rss_conf->key,
239 : : rss_conf->key_len);
240 [ # # ]: 0 : if (ret)
241 : : return ret;
242 : : }
243 : :
244 : : /* Update lookup table */
245 [ # # ]: 0 : if (rss_conf->queue_num > 0) {
246 : : uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512];
247 : : uint32_t i, j = 0;
248 : :
249 [ # # ]: 0 : for (i = 0; i < hw->func_caps.rss_table_size; i++) {
250 : 0 : lut[i] = (uint8_t)rss_conf->queue[j];
251 [ # # ]: 0 : j = (j == rss_conf->queue_num - 1) ? 0 : (j + 1);
252 : : }
253 : :
254 : 0 : ret = i40e_set_rss_lut(pf->main_vsi, lut, (uint16_t)i);
255 [ # # ]: 0 : if (ret)
256 : 0 : return ret;
257 : :
258 : 0 : pf->hash_enabled_queues = 0;
259 [ # # ]: 0 : for (i = 0; i < rss_conf->queue_num; i++)
260 : 0 : pf->hash_enabled_queues |= BIT_ULL(lut[i]);
261 : :
262 : 0 : pf->adapter->rss_reta_updated = 0;
263 : : }
264 : :
265 : : /* The codes behind configure the input sets and symmetric hash
266 : : * function of the packet types and enable hash on them.
267 : : */
268 : 0 : pctypes = rss_conf->config_pctypes;
269 [ # # ]: 0 : if (!pctypes)
270 : : return 0;
271 : :
272 : : /* For first flow that will enable hash on any packet type, we clean
273 : : * the RSS sets that by legacy configuration commands and parameters.
274 : : */
275 [ # # ]: 0 : if (!pf->hash_filter_enabled) {
276 : 0 : i40e_pf_disable_rss(pf);
277 : 0 : pf->hash_filter_enabled = true;
278 : : }
279 : :
280 : : do {
281 : : uint32_t idx = rte_bsf64(pctypes);
282 : :
283 [ # # ]: 0 : if (rss_conf->symmetric_enable) {
284 : 0 : ret = i40e_hash_config_pctype_symmetric(hw, idx, true);
285 [ # # ]: 0 : if (ret)
286 : 0 : return ret;
287 : : }
288 : :
289 : 0 : ret = i40e_hash_config_pctype(hw, rss_conf, idx);
290 [ # # ]: 0 : if (ret)
291 : 0 : return ret;
292 : :
293 : 0 : pctypes &= ~BIT_ULL(idx);
294 [ # # ]: 0 : } while (pctypes);
295 : :
296 : : return 0;
297 : : }
298 : :
299 : : /*
300 : : * Compute the reset flags a filter would own if it were the only RSS filter
301 : : * installed. Pure function of rss_conf; used to reconstruct the ownership of
302 : : * shared RSS state across all currently registered filters.
303 : : */
304 : : void
305 : 0 : i40e_hash_compute_reset_flags(const struct i40e_rss_conf *rss_conf,
306 : : struct i40e_rss_filter_data *filter_data)
307 : : {
308 : : uint64_t pctypes;
309 : :
310 : 0 : *filter_data = (struct i40e_rss_filter_data){0};
311 : :
312 [ # # ]: 0 : if (rss_conf->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
313 : : rss_conf->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
314 : 0 : filter_data->misc_reset_flags |= I40E_HASH_FLOW_RESET_FLAG_FUNC;
315 : :
316 [ # # ]: 0 : if (rss_conf->region_queue_num > 0)
317 : 0 : filter_data->misc_reset_flags |= I40E_HASH_FLOW_RESET_FLAG_REGION;
318 : :
319 [ # # ]: 0 : if (rss_conf->key_len > 0)
320 : 0 : filter_data->misc_reset_flags |= I40E_HASH_FLOW_RESET_FLAG_KEY;
321 : :
322 [ # # ]: 0 : if (rss_conf->queue_num > 0)
323 : 0 : filter_data->misc_reset_flags |= I40E_HASH_FLOW_RESET_FLAG_QUEUE;
324 : :
325 : 0 : pctypes = rss_conf->config_pctypes;
326 [ # # ]: 0 : while (pctypes) {
327 : : uint32_t idx = rte_bsf64(pctypes);
328 : 0 : uint64_t bit = BIT_ULL(idx);
329 : :
330 : 0 : filter_data->reset_config_pctypes |= bit;
331 [ # # ]: 0 : if (rss_conf->symmetric_enable)
332 : 0 : filter_data->reset_symmetric_pctypes |= bit;
333 : :
334 : 0 : pctypes &= ~bit;
335 : : }
336 : 0 : }
337 : :
338 : : /*
339 : : * Revert to defaults only the registers this filter's filter_data records as
340 : : * owned. This is the inverse of i40e_hash_program_hw, but only undoes the
341 : : * owned subset -- it is not a full RSS wipe.
342 : : */
343 : : int
344 : 0 : i40e_hash_deprogram_hw(struct i40e_pf *pf,
345 : : struct i40e_rss_filter_data *filter_data)
346 : : {
347 : 0 : struct i40e_hw *hw = &pf->adapter->hw;
348 : : struct rte_eth_dev *dev;
349 : : uint64_t inset;
350 : : uint32_t idx;
351 : : int ret;
352 : :
353 [ # # ]: 0 : if (filter_data->misc_reset_flags & I40E_HASH_FLOW_RESET_FLAG_FUNC) {
354 : 0 : ret = i40e_hash_config_func(hw, RTE_ETH_HASH_FUNCTION_TOEPLITZ);
355 [ # # ]: 0 : if (ret)
356 : : return ret;
357 : :
358 : 0 : filter_data->misc_reset_flags &= ~I40E_HASH_FLOW_RESET_FLAG_FUNC;
359 : : }
360 : :
361 [ # # ]: 0 : if (filter_data->misc_reset_flags & I40E_HASH_FLOW_RESET_FLAG_REGION) {
362 : 0 : dev = &rte_eth_devices[pf->dev_data->port_id];
363 : 0 : ret = i40e_flush_queue_region_all_conf(dev, hw, pf, 0);
364 [ # # ]: 0 : if (ret)
365 : : return ret;
366 : :
367 : 0 : filter_data->misc_reset_flags &= ~I40E_HASH_FLOW_RESET_FLAG_REGION;
368 : : }
369 : :
370 [ # # ]: 0 : if (filter_data->misc_reset_flags & I40E_HASH_FLOW_RESET_FLAG_KEY) {
371 : 0 : ret = i40e_pf_reset_rss_key(pf);
372 [ # # ]: 0 : if (ret)
373 : : return ret;
374 : :
375 : 0 : filter_data->misc_reset_flags &= ~I40E_HASH_FLOW_RESET_FLAG_KEY;
376 : : }
377 : :
378 [ # # ]: 0 : if (filter_data->misc_reset_flags & I40E_HASH_FLOW_RESET_FLAG_QUEUE) {
379 [ # # ]: 0 : if (!pf->adapter->rss_reta_updated) {
380 : 0 : ret = i40e_pf_reset_rss_reta(pf);
381 [ # # ]: 0 : if (ret)
382 : : return ret;
383 : : }
384 : :
385 : 0 : pf->hash_enabled_queues = 0;
386 : 0 : filter_data->misc_reset_flags &= ~I40E_HASH_FLOW_RESET_FLAG_QUEUE;
387 : : }
388 : :
389 [ # # ]: 0 : while (filter_data->reset_config_pctypes) {
390 : : idx = rte_bsf64(filter_data->reset_config_pctypes);
391 : :
392 : 0 : i40e_hash_enable_pctype(hw, idx, false);
393 : 0 : inset = i40e_get_default_input_set(idx);
394 [ # # ]: 0 : if (inset) {
395 : 0 : ret = i40e_set_hash_inset(hw, inset, idx, false);
396 [ # # ]: 0 : if (ret)
397 : 0 : return ret;
398 : : }
399 : :
400 : 0 : filter_data->reset_config_pctypes &= ~BIT_ULL(idx);
401 : : }
402 : :
403 [ # # ]: 0 : while (filter_data->reset_symmetric_pctypes) {
404 : : idx = rte_bsf64(filter_data->reset_symmetric_pctypes);
405 : :
406 : 0 : ret = i40e_hash_config_pctype_symmetric(hw, idx, false);
407 [ # # ]: 0 : if (ret)
408 : 0 : return ret;
409 : :
410 : 0 : filter_data->reset_symmetric_pctypes &= ~BIT_ULL(idx);
411 : : }
412 : :
413 : : return 0;
414 : : }
|