Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
3 : : * Copyright(c) 2010-2017 Intel Corporation
4 : : */
5 : :
6 : : #include <stdio.h>
7 : : #include <stdint.h>
8 : : #include <stdarg.h>
9 : : #include <errno.h>
10 : : #include <sys/queue.h>
11 : : #include <rte_malloc.h>
12 : :
13 : : #include "txgbe_logs.h"
14 : : #include "base/txgbe.h"
15 : : #include "txgbe_ethdev.h"
16 : :
17 : : #define TXGBE_DEFAULT_FLEXBYTES_OFFSET 12 /*default flexbytes offset in bytes*/
18 : : #define TXGBE_MAX_FLX_SOURCE_OFF 62
19 : : #define TXGBE_FDIRCMD_CMD_INTERVAL_US 10
20 : :
21 : : #define IPV6_ADDR_TO_MASK(ipaddr, ipv6m) do { \
22 : : uint8_t ipv6_addr[16]; \
23 : : uint8_t i; \
24 : : rte_memcpy(ipv6_addr, (ipaddr), sizeof(ipv6_addr));\
25 : : (ipv6m) = 0; \
26 : : for (i = 0; i < sizeof(ipv6_addr); i++) { \
27 : : if (ipv6_addr[i] == UINT8_MAX) \
28 : : (ipv6m) |= 1 << i; \
29 : : else if (ipv6_addr[i] != 0) { \
30 : : PMD_DRV_LOG(ERR, " invalid IPv6 address mask."); \
31 : : return -EINVAL; \
32 : : } \
33 : : } \
34 : : } while (0)
35 : :
36 : : #define IPV6_MASK_TO_ADDR(ipv6m, ipaddr) do { \
37 : : uint8_t ipv6_addr[16]; \
38 : : uint8_t i; \
39 : : for (i = 0; i < sizeof(ipv6_addr); i++) { \
40 : : if ((ipv6m) & (1 << i)) \
41 : : ipv6_addr[i] = UINT8_MAX; \
42 : : else \
43 : : ipv6_addr[i] = 0; \
44 : : } \
45 : : rte_memcpy((ipaddr), ipv6_addr, sizeof(ipv6_addr));\
46 : : } while (0)
47 : :
48 : : /**
49 : : * Initialize Flow Director control registers
50 : : * @hw: pointer to hardware structure
51 : : * @fdirctrl: value to write to flow director control register
52 : : **/
53 : : static int
54 : 0 : txgbe_fdir_enable(struct txgbe_hw *hw, uint32_t fdirctrl)
55 : : {
56 : : int i;
57 : :
58 : 0 : PMD_INIT_FUNC_TRACE();
59 : :
60 : : /* Prime the keys for hashing */
61 : : wr32(hw, TXGBE_FDIRBKTHKEY, TXGBE_ATR_BUCKET_HASH_KEY);
62 : : wr32(hw, TXGBE_FDIRSIGHKEY, TXGBE_ATR_SIGNATURE_HASH_KEY);
63 : :
64 : : /*
65 : : * Continue setup of fdirctrl register bits:
66 : : * Set the maximum length per hash bucket to 0xA filters
67 : : * Send interrupt when 64 filters are left
68 : : */
69 : 0 : fdirctrl |= TXGBE_FDIRCTL_MAXLEN(0xA) |
70 : : TXGBE_FDIRCTL_FULLTHR(4);
71 : :
72 : : /*
73 : : * Poll init-done after we write the register. Estimated times:
74 : : * 10G: PBALLOC = 11b, timing is 60us
75 : : * 1G: PBALLOC = 11b, timing is 600us
76 : : * 100M: PBALLOC = 11b, timing is 6ms
77 : : *
78 : : * Multiple these timings by 4 if under full Rx load
79 : : *
80 : : * So we'll poll for TXGBE_FDIR_INIT_DONE_POLL times, sleeping for
81 : : * 1 msec per poll time. If we're at line rate and drop to 100M, then
82 : : * this might not finish in our poll time, but we can live with that
83 : : * for now.
84 : : */
85 : : wr32(hw, TXGBE_FDIRCTL, fdirctrl);
86 : : txgbe_flush(hw);
87 [ # # ]: 0 : for (i = 0; i < TXGBE_FDIR_INIT_DONE_POLL; i++) {
88 [ # # ]: 0 : if (rd32(hw, TXGBE_FDIRCTL) & TXGBE_FDIRCTL_INITDONE)
89 : : break;
90 : : msec_delay(1);
91 : : }
92 : :
93 [ # # ]: 0 : if (i >= TXGBE_FDIR_INIT_DONE_POLL) {
94 : 0 : PMD_INIT_LOG(ERR, "Flow Director poll time exceeded during enabling!");
95 : 0 : return -ETIMEDOUT;
96 : : }
97 : : return 0;
98 : : }
99 : :
100 : : /*
101 : : * Set appropriate bits in fdirctrl for: variable reporting levels, moving
102 : : * flexbytes matching field, and drop queue (only for perfect matching mode).
103 : : */
104 : : static inline int
105 : 0 : configure_fdir_flags(const struct rte_eth_fdir_conf *conf,
106 : : uint32_t *fdirctrl, uint32_t *flex)
107 : : {
108 : 0 : *fdirctrl = 0;
109 : 0 : *flex = 0;
110 : :
111 [ # # # # ]: 0 : switch (conf->pballoc) {
112 : 0 : case RTE_ETH_FDIR_PBALLOC_64K:
113 : : /* 8k - 1 signature filters */
114 : 0 : *fdirctrl |= TXGBE_FDIRCTL_BUF_64K;
115 : 0 : break;
116 : 0 : case RTE_ETH_FDIR_PBALLOC_128K:
117 : : /* 16k - 1 signature filters */
118 : 0 : *fdirctrl |= TXGBE_FDIRCTL_BUF_128K;
119 : 0 : break;
120 : 0 : case RTE_ETH_FDIR_PBALLOC_256K:
121 : : /* 32k - 1 signature filters */
122 : 0 : *fdirctrl |= TXGBE_FDIRCTL_BUF_256K;
123 : 0 : break;
124 : 0 : default:
125 : : /* bad value */
126 : 0 : PMD_INIT_LOG(ERR, "Invalid fdir_conf->pballoc value");
127 : 0 : return -EINVAL;
128 : : };
129 : :
130 : : /* status flags: write hash & swindex in the rx descriptor */
131 [ # # # # ]: 0 : switch (conf->status) {
132 : : case RTE_FDIR_NO_REPORT_STATUS:
133 : : /* do nothing, default mode */
134 : : break;
135 : 0 : case RTE_FDIR_REPORT_STATUS:
136 : : /* report status when the packet matches a fdir rule */
137 : 0 : *fdirctrl |= TXGBE_FDIRCTL_REPORT_MATCH;
138 : 0 : break;
139 : 0 : case RTE_FDIR_REPORT_STATUS_ALWAYS:
140 : : /* always report status */
141 : 0 : *fdirctrl |= TXGBE_FDIRCTL_REPORT_ALWAYS;
142 : 0 : break;
143 : 0 : default:
144 : : /* bad value */
145 : 0 : PMD_INIT_LOG(ERR, "Invalid fdir_conf->status value");
146 : 0 : return -EINVAL;
147 : : };
148 : :
149 : 0 : *flex |= TXGBE_FDIRFLEXCFG_BASE_MAC;
150 : 0 : *flex |= TXGBE_FDIRFLEXCFG_OFST(TXGBE_DEFAULT_FLEXBYTES_OFFSET / 2);
151 : :
152 [ # # # ]: 0 : switch (conf->mode) {
153 : : case RTE_FDIR_MODE_SIGNATURE:
154 : : break;
155 : 0 : case RTE_FDIR_MODE_PERFECT:
156 : 0 : *fdirctrl |= TXGBE_FDIRCTL_PERFECT;
157 : 0 : *fdirctrl |= TXGBE_FDIRCTL_DROPQP(conf->drop_queue);
158 : 0 : break;
159 : 0 : default:
160 : : /* bad value */
161 : 0 : PMD_INIT_LOG(ERR, "Invalid fdir_conf->mode value");
162 : 0 : return -EINVAL;
163 : : }
164 : :
165 : : return 0;
166 : : }
167 : :
168 : : static inline uint16_t
169 : 0 : txgbe_reverse_fdir_bitmasks(uint16_t mask)
170 : : {
171 : 0 : mask = ((mask & 0x5555) << 1) | ((mask & 0xAAAA) >> 1);
172 : 0 : mask = ((mask & 0x3333) << 2) | ((mask & 0xCCCC) >> 2);
173 : 0 : mask = ((mask & 0x0F0F) << 4) | ((mask & 0xF0F0) >> 4);
174 : 0 : return ((mask & 0x00FF) << 8) | ((mask & 0xFF00) >> 8);
175 : : }
176 : :
177 : : int
178 : 0 : txgbe_fdir_set_input_mask(struct rte_eth_dev *dev)
179 : : {
180 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
181 : : struct txgbe_hw_fdir_info *info = TXGBE_DEV_FDIR(dev);
182 : 0 : enum rte_fdir_mode mode = TXGBE_DEV_FDIR_CONF(dev)->mode;
183 : : /*
184 : : * mask VM pool and DIPv6 since there are currently not supported
185 : : * mask FLEX byte, it will be set in flex_conf
186 : : */
187 : : uint32_t fdirm = TXGBE_FDIRMSK_POOL;
188 : : uint32_t fdirtcpm; /* TCP source and destination port masks. */
189 : : uint32_t fdiripv6m; /* IPv6 source and destination masks. */
190 : :
191 : 0 : PMD_INIT_FUNC_TRACE();
192 : :
193 [ # # ]: 0 : if (mode != RTE_FDIR_MODE_SIGNATURE &&
194 : : mode != RTE_FDIR_MODE_PERFECT) {
195 : 0 : PMD_DRV_LOG(ERR, "Not supported fdir mode - %d!", mode);
196 : 0 : return -ENOTSUP;
197 : : }
198 : :
199 : : /* use the L4 protocol mask for raw IPv4/IPv6 traffic */
200 [ # # ]: 0 : if (info->mask.pkt_type_mask == 0 && info->mask.dst_port_mask == 0 &&
201 : : info->mask.src_port_mask == 0)
202 : 0 : info->mask.pkt_type_mask |= TXGBE_FDIRMSK_L4P;
203 : :
204 : 0 : fdirm |= info->mask.pkt_type_mask;
205 : : wr32(hw, TXGBE_FDIRMSK, fdirm);
206 : :
207 : : /* store the TCP/UDP port masks */
208 [ # # ]: 0 : fdirtcpm = rte_be_to_cpu_16(info->mask.dst_port_mask) << 16;
209 [ # # ]: 0 : fdirtcpm |= rte_be_to_cpu_16(info->mask.src_port_mask);
210 : :
211 : : /* write all the same so that UDP, TCP and SCTP use the same mask
212 : : * (little-endian)
213 : : */
214 : 0 : wr32(hw, TXGBE_FDIRTCPMSK, ~fdirtcpm);
215 : : wr32(hw, TXGBE_FDIRUDPMSK, ~fdirtcpm);
216 : : wr32(hw, TXGBE_FDIRSCTPMSK, ~fdirtcpm);
217 : :
218 : : /* Store source and destination IPv4 masks (little-endian) */
219 [ # # ]: 0 : wr32(hw, TXGBE_FDIRSIP4MSK, rte_be_to_cpu_32(~info->mask.src_ipv4_mask));
220 [ # # ]: 0 : wr32(hw, TXGBE_FDIRDIP4MSK, rte_be_to_cpu_32(~info->mask.dst_ipv4_mask));
221 : :
222 : : /*
223 : : * Store source and destination IPv6 masks (bit reversed)
224 : : */
225 : 0 : fdiripv6m = txgbe_reverse_fdir_bitmasks(info->mask.dst_ipv6_mask) << 16;
226 : 0 : fdiripv6m |= txgbe_reverse_fdir_bitmasks(info->mask.src_ipv6_mask);
227 : 0 : wr32(hw, TXGBE_FDIRIP6MSK, ~fdiripv6m);
228 : :
229 : 0 : return 0;
230 : : }
231 : :
232 : : static int
233 : 0 : txgbe_fdir_store_input_mask(struct rte_eth_dev *dev)
234 : : {
235 : 0 : struct rte_eth_fdir_masks *input_mask = &TXGBE_DEV_FDIR_CONF(dev)->mask;
236 : 0 : enum rte_fdir_mode mode = TXGBE_DEV_FDIR_CONF(dev)->mode;
237 : : struct txgbe_hw_fdir_info *info = TXGBE_DEV_FDIR(dev);
238 : : uint16_t dst_ipv6m = 0;
239 : : uint16_t src_ipv6m = 0;
240 : :
241 [ # # ]: 0 : if (mode != RTE_FDIR_MODE_SIGNATURE &&
242 : : mode != RTE_FDIR_MODE_PERFECT) {
243 : 0 : PMD_DRV_LOG(ERR, "Not supported fdir mode - %d!", mode);
244 : 0 : return -ENOTSUP;
245 : : }
246 : :
247 : 0 : memset(&info->mask, 0, sizeof(struct txgbe_hw_fdir_mask));
248 : 0 : info->mask.vlan_tci_mask = input_mask->vlan_tci_mask;
249 : 0 : info->mask.src_port_mask = input_mask->src_port_mask;
250 : 0 : info->mask.dst_port_mask = input_mask->dst_port_mask;
251 : 0 : info->mask.src_ipv4_mask = input_mask->ipv4_mask.src_ip;
252 : 0 : info->mask.dst_ipv4_mask = input_mask->ipv4_mask.dst_ip;
253 [ # # # # : 0 : IPV6_ADDR_TO_MASK(input_mask->ipv6_mask.src_ip, src_ipv6m);
# # ]
254 [ # # # # : 0 : IPV6_ADDR_TO_MASK(input_mask->ipv6_mask.dst_ip, dst_ipv6m);
# # ]
255 : 0 : info->mask.src_ipv6_mask = src_ipv6m;
256 : 0 : info->mask.dst_ipv6_mask = dst_ipv6m;
257 : :
258 : 0 : return 0;
259 : : }
260 : :
261 : : uint16_t
262 : 0 : txgbe_fdir_get_flex_base(struct txgbe_fdir_rule *rule)
263 : : {
264 [ # # ]: 0 : if (!rule->flex_relative)
265 : : return TXGBE_FDIRFLEXCFG_BASE_MAC;
266 : :
267 [ # # ]: 0 : if (rule->input.flow_type & TXGBE_ATR_L4TYPE_MASK)
268 : 0 : return TXGBE_FDIRFLEXCFG_BASE_PAY;
269 : :
270 : : return TXGBE_FDIRFLEXCFG_BASE_L3;
271 : : }
272 : :
273 : : int
274 : 0 : txgbe_fdir_set_flexbytes_offset(struct rte_eth_dev *dev,
275 : : uint16_t offset, uint16_t flex_base)
276 : : {
277 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
278 : : int i;
279 : :
280 [ # # ]: 0 : for (i = 0; i < 64; i++) {
281 : : uint32_t flexreg, flex;
282 : 0 : flexreg = rd32(hw, TXGBE_FDIRFLEXCFG(i / 4));
283 : 0 : flex = flex_base;
284 : 0 : flex |= TXGBE_FDIRFLEXCFG_OFST(offset / 2);
285 : 0 : flexreg &= ~(TXGBE_FDIRFLEXCFG_ALL(~0UL, i % 4));
286 : 0 : flexreg |= TXGBE_FDIRFLEXCFG_ALL(flex, i % 4);
287 : : wr32(hw, TXGBE_FDIRFLEXCFG(i / 4), flexreg);
288 : : }
289 : :
290 : : txgbe_flush(hw);
291 [ # # ]: 0 : for (i = 0; i < TXGBE_FDIR_INIT_DONE_POLL; i++) {
292 [ # # ]: 0 : if (rd32(hw, TXGBE_FDIRCTL) &
293 : : TXGBE_FDIRCTL_INITDONE)
294 : : break;
295 : : msec_delay(1);
296 : : }
297 : 0 : return 0;
298 : : }
299 : :
300 : : /*
301 : : * txgbe_check_fdir_flex_conf -check if the flex payload and mask configuration
302 : : * arguments are valid
303 : : */
304 : : static int
305 : 0 : txgbe_set_fdir_flex_conf(struct rte_eth_dev *dev, uint32_t flex)
306 : : {
307 : : const struct rte_eth_fdir_flex_conf *conf =
308 : 0 : &TXGBE_DEV_FDIR_CONF(dev)->flex_conf;
309 : : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
310 : : struct txgbe_hw_fdir_info *info = TXGBE_DEV_FDIR(dev);
311 : : const struct rte_eth_flex_payload_cfg *flex_cfg;
312 : : const struct rte_eth_fdir_flex_mask *flex_mask;
313 : : uint16_t flexbytes = 0;
314 : : uint16_t i;
315 : :
316 : : if (conf == NULL) {
317 : : PMD_DRV_LOG(ERR, "NULL pointer.");
318 : : return -EINVAL;
319 : : }
320 : :
321 : 0 : flex |= TXGBE_FDIRFLEXCFG_DIA;
322 : :
323 [ # # ]: 0 : for (i = 0; i < conf->nb_payloads; i++) {
324 : 0 : flex_cfg = &conf->flex_set[i];
325 [ # # ]: 0 : if (flex_cfg->type != RTE_ETH_RAW_PAYLOAD) {
326 : 0 : PMD_DRV_LOG(ERR, "unsupported payload type.");
327 : 0 : return -EINVAL;
328 : : }
329 [ # # ]: 0 : if (((flex_cfg->src_offset[0] & 0x1) == 0) &&
330 [ # # # # ]: 0 : (flex_cfg->src_offset[1] == flex_cfg->src_offset[0] + 1) &&
331 : : flex_cfg->src_offset[0] <= TXGBE_MAX_FLX_SOURCE_OFF) {
332 : 0 : flex &= ~TXGBE_FDIRFLEXCFG_OFST_MASK;
333 : 0 : flex |=
334 : 0 : TXGBE_FDIRFLEXCFG_OFST(flex_cfg->src_offset[0] / 2);
335 : : } else {
336 : 0 : PMD_DRV_LOG(ERR, "invalid flexbytes arguments.");
337 : 0 : return -EINVAL;
338 : : }
339 : : }
340 : :
341 [ # # ]: 0 : for (i = 0; i < conf->nb_flexmasks; i++) {
342 : 0 : flex_mask = &conf->flex_mask[i];
343 [ # # ]: 0 : if (flex_mask->flow_type != RTE_ETH_FLOW_UNKNOWN) {
344 : 0 : PMD_DRV_LOG(ERR, "flexmask should be set globally.");
345 : 0 : return -EINVAL;
346 : : }
347 : 0 : flexbytes = (uint16_t)(((flex_mask->mask[1] << 8) & 0xFF00) |
348 : 0 : ((flex_mask->mask[0]) & 0xFF));
349 [ # # ]: 0 : if (flexbytes == UINT16_MAX) {
350 : 0 : flex &= ~TXGBE_FDIRFLEXCFG_DIA;
351 [ # # ]: 0 : } else if (flexbytes != 0) {
352 : : /* TXGBE_FDIRFLEXCFG_DIA is set by default when set mask */
353 : 0 : PMD_DRV_LOG(ERR, " invalid flexbytes mask arguments.");
354 : 0 : return -EINVAL;
355 : : }
356 : : }
357 : :
358 [ # # ]: 0 : info->mask.flex_bytes_mask = flexbytes ? UINT16_MAX : 0;
359 : 0 : info->flex_bytes_offset = (uint8_t)(TXGBD_FDIRFLEXCFG_OFST(flex) * 2);
360 : :
361 [ # # ]: 0 : for (i = 0; i < 64; i++) {
362 : : uint32_t flexreg;
363 : 0 : flexreg = rd32(hw, TXGBE_FDIRFLEXCFG(i / 4));
364 : 0 : flexreg &= ~(TXGBE_FDIRFLEXCFG_ALL(~0UL, i % 4));
365 : 0 : flexreg |= TXGBE_FDIRFLEXCFG_ALL(flex, i % 4);
366 : : wr32(hw, TXGBE_FDIRFLEXCFG(i / 4), flexreg);
367 : : }
368 : : return 0;
369 : : }
370 : :
371 : : void
372 : 0 : txgbe_fdir_disable(struct txgbe_hw *hw)
373 : : {
374 : : int i;
375 : :
376 : : wr32(hw, TXGBE_FDIRCTL, 0);
377 : 0 : wr32(hw, TXGBE_PBRXSIZE(0), hw->mac.rx_pb_size << 10);
378 [ # # ]: 0 : for (i = 1; i < 8; i++)
379 : 0 : wr32(hw, TXGBE_PBRXSIZE(i), 0);
380 : : txgbe_flush(hw);
381 : 0 : }
382 : :
383 : : int
384 : 0 : txgbe_fdir_configure(struct rte_eth_dev *dev)
385 : : {
386 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
387 : : int err;
388 : : uint32_t fdirctrl, flex, pbsize;
389 : : int i;
390 : 0 : enum rte_fdir_mode mode = TXGBE_DEV_FDIR_CONF(dev)->mode;
391 : :
392 : 0 : PMD_INIT_FUNC_TRACE();
393 : :
394 : : /* supports mac-vlan and tunnel mode */
395 [ # # ]: 0 : if (mode != RTE_FDIR_MODE_SIGNATURE &&
396 : : mode != RTE_FDIR_MODE_PERFECT)
397 : : return -ENOSYS;
398 : :
399 : 0 : err = configure_fdir_flags(TXGBE_DEV_FDIR_CONF(dev), &fdirctrl, &flex);
400 [ # # ]: 0 : if (err)
401 : : return err;
402 : :
403 : : /*
404 : : * Before enabling Flow Director, the Rx Packet Buffer size
405 : : * must be reduced. The new value is the default size minus
406 : : * flow director memory usage size.
407 : : */
408 : 0 : pbsize = (hw->mac.rx_pb_size << 10) - TXGBD_FDIRCTL_BUF_BYTE(fdirctrl);
409 : : wr32(hw, TXGBE_PBRXSIZE(0), pbsize);
410 : :
411 : : /*
412 : : * The defaults in the HW for RX PB 1-7 are not zero and so should be
413 : : * initialized to zero for non DCB mode otherwise actual total RX PB
414 : : * would be bigger than programmed and filter space would run into
415 : : * the PB 0 region.
416 : : */
417 [ # # ]: 0 : for (i = 1; i < 8; i++)
418 : 0 : wr32(hw, TXGBE_PBRXSIZE(i), 0);
419 : :
420 : 0 : err = txgbe_fdir_store_input_mask(dev);
421 [ # # ]: 0 : if (err < 0) {
422 : 0 : PMD_INIT_LOG(ERR, " Error on setting FD mask");
423 : 0 : goto error;
424 : : }
425 : :
426 : 0 : err = txgbe_fdir_set_input_mask(dev);
427 [ # # ]: 0 : if (err < 0) {
428 : 0 : PMD_INIT_LOG(ERR, " Error on setting FD mask");
429 : 0 : goto error;
430 : : }
431 : :
432 : 0 : err = txgbe_set_fdir_flex_conf(dev, flex);
433 [ # # ]: 0 : if (err < 0) {
434 : 0 : PMD_INIT_LOG(ERR, " Error on setting FD flexible arguments.");
435 : 0 : goto error;
436 : : }
437 : :
438 : 0 : err = txgbe_fdir_enable(hw, fdirctrl);
439 [ # # ]: 0 : if (err < 0) {
440 : 0 : PMD_INIT_LOG(ERR, " Error on enabling FD.");
441 : 0 : goto error;
442 : : }
443 : : return 0;
444 : :
445 : 0 : error:
446 : 0 : txgbe_fdir_disable(hw);
447 : 0 : return err;
448 : : }
449 : :
450 : : /*
451 : : * Note that the bkt_hash field in the txgbe_atr_input structure is also never
452 : : * set.
453 : : *
454 : : * Compute the hashes for SW ATR
455 : : * @stream: input bitstream to compute the hash on
456 : : * @key: 32-bit hash key
457 : : **/
458 : : static uint32_t
459 : 0 : txgbe_atr_compute_hash(struct txgbe_atr_input *atr_input,
460 : : uint32_t key)
461 : : {
462 : : /*
463 : : * The algorithm is as follows:
464 : : * Hash[15:0] = Sum { S[n] x K[n+16] }, n = 0...350
465 : : * where Sum {A[n]}, n = 0...n is bitwise XOR of A[0], A[1]...A[n]
466 : : * and A[n] x B[n] is bitwise AND between same length strings
467 : : *
468 : : * K[n] is 16 bits, defined as:
469 : : * for n modulo 32 >= 15, K[n] = K[n % 32 : (n % 32) - 15]
470 : : * for n modulo 32 < 15, K[n] =
471 : : * K[(n % 32:0) | (31:31 - (14 - (n % 32)))]
472 : : *
473 : : * S[n] is 16 bits, defined as:
474 : : * for n >= 15, S[n] = S[n:n - 15]
475 : : * for n < 15, S[n] = S[(n:0) | (350:350 - (14 - n))]
476 : : *
477 : : * To simplify for programming, the algorithm is implemented
478 : : * in software this way:
479 : : *
480 : : * key[31:0], hi_hash_dword[31:0], lo_hash_dword[31:0], hash[15:0]
481 : : *
482 : : * for (i = 0; i < 352; i+=32)
483 : : * hi_hash_dword[31:0] ^= Stream[(i+31):i];
484 : : *
485 : : * lo_hash_dword[15:0] ^= Stream[15:0];
486 : : * lo_hash_dword[15:0] ^= hi_hash_dword[31:16];
487 : : * lo_hash_dword[31:16] ^= hi_hash_dword[15:0];
488 : : *
489 : : * hi_hash_dword[31:0] ^= Stream[351:320];
490 : : *
491 : : * if (key[0])
492 : : * hash[15:0] ^= Stream[15:0];
493 : : *
494 : : * for (i = 0; i < 16; i++) {
495 : : * if (key[i])
496 : : * hash[15:0] ^= lo_hash_dword[(i+15):i];
497 : : * if (key[i + 16])
498 : : * hash[15:0] ^= hi_hash_dword[(i+15):i];
499 : : * }
500 : : *
501 : : */
502 : : __be32 *dword_stream = (__be32 *)atr_input;
503 : : __be32 common_hash_dword = 0;
504 : : u32 hi_hash_dword, lo_hash_dword, flow_pool_ptid;
505 : : u32 hash_result = 0;
506 : : u8 i;
507 : :
508 : : /* record the flow_vm_vlan bits as they are a key part to the hash */
509 [ # # ]: 0 : flow_pool_ptid = be_to_cpu32(dword_stream[0]);
510 : :
511 : : /* generate common hash dword */
512 [ # # ]: 0 : for (i = 1; i <= 10; i++)
513 : 0 : common_hash_dword ^= dword_stream[i];
514 : :
515 [ # # ]: 0 : hi_hash_dword = be_to_cpu32(common_hash_dword);
516 : :
517 : : /* low dword is word swapped version of common */
518 : 0 : lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16);
519 : :
520 : : /* apply (Flow ID/VM Pool/Packet Type) bits to hash words */
521 : 0 : hi_hash_dword ^= flow_pool_ptid ^ (flow_pool_ptid >> 16);
522 : :
523 : : /* Process bits 0 and 16 */
524 [ # # ]: 0 : if (key & 0x0001)
525 : : hash_result ^= lo_hash_dword;
526 [ # # ]: 0 : if (key & 0x00010000)
527 : 0 : hash_result ^= hi_hash_dword;
528 : :
529 : : /*
530 : : * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to
531 : : * delay this because bit 0 of the stream should not be processed
532 : : * so we do not add the vlan until after bit 0 was processed
533 : : */
534 : 0 : lo_hash_dword ^= flow_pool_ptid ^ (flow_pool_ptid << 16);
535 : :
536 : : /* process the remaining 30 bits in the key 2 bits at a time */
537 [ # # ]: 0 : for (i = 15; i; i--) {
538 [ # # ]: 0 : if (key & (0x0001 << i))
539 : 0 : hash_result ^= lo_hash_dword >> i;
540 [ # # ]: 0 : if (key & (0x00010000 << i))
541 : 0 : hash_result ^= hi_hash_dword >> i;
542 : : }
543 : :
544 : 0 : return hash_result;
545 : : }
546 : :
547 : : static uint32_t
548 : : atr_compute_perfect_hash(struct txgbe_atr_input *input,
549 : : enum rte_eth_fdir_pballoc_type pballoc)
550 : : {
551 : : uint32_t bucket_hash;
552 : :
553 : 0 : bucket_hash = txgbe_atr_compute_hash(input,
554 : : TXGBE_ATR_BUCKET_HASH_KEY);
555 [ # # # # ]: 0 : if (pballoc == RTE_ETH_FDIR_PBALLOC_256K)
556 : 0 : bucket_hash &= PERFECT_BUCKET_256KB_HASH_MASK;
557 [ # # # # ]: 0 : else if (pballoc == RTE_ETH_FDIR_PBALLOC_128K)
558 : 0 : bucket_hash &= PERFECT_BUCKET_128KB_HASH_MASK;
559 : : else
560 : 0 : bucket_hash &= PERFECT_BUCKET_64KB_HASH_MASK;
561 : :
562 : : return TXGBE_FDIRPIHASH_BKT(bucket_hash);
563 : : }
564 : :
565 : : /**
566 : : * txgbe_fdir_check_cmd_complete - poll to check whether FDIRPICMD is complete
567 : : * @hw: pointer to hardware structure
568 : : */
569 : : static inline int
570 : : txgbe_fdir_check_cmd_complete(struct txgbe_hw *hw, uint32_t *fdircmd)
571 : : {
572 : : int i;
573 : :
574 [ # # # # : 0 : for (i = 0; i < TXGBE_FDIRCMD_CMD_POLL; i++) {
# # # # ]
575 : : *fdircmd = rd32(hw, TXGBE_FDIRPICMD);
576 [ # # # # : 0 : if (!(*fdircmd & TXGBE_FDIRPICMD_OP_MASK))
# # # # ]
577 : : return 0;
578 : 0 : rte_delay_us(TXGBE_FDIRCMD_CMD_INTERVAL_US);
579 : : }
580 : :
581 : : return -ETIMEDOUT;
582 : : }
583 : :
584 : : /*
585 : : * Calculate the hash value needed for signature-match filters. In the FreeBSD
586 : : * driver, this is done by the optimised function
587 : : * txgbe_atr_compute_sig_hash_raptor(). However that can't be used here as it
588 : : * doesn't support calculating a hash for an IPv6 filter.
589 : : */
590 : : static uint32_t
591 : 0 : atr_compute_signature_hash(struct txgbe_atr_input *input,
592 : : enum rte_eth_fdir_pballoc_type pballoc)
593 : : {
594 : : uint32_t bucket_hash, sig_hash;
595 : :
596 : 0 : bucket_hash = txgbe_atr_compute_hash(input,
597 : : TXGBE_ATR_BUCKET_HASH_KEY);
598 [ # # ]: 0 : if (pballoc == RTE_ETH_FDIR_PBALLOC_256K)
599 : 0 : bucket_hash &= SIG_BUCKET_256KB_HASH_MASK;
600 [ # # ]: 0 : else if (pballoc == RTE_ETH_FDIR_PBALLOC_128K)
601 : 0 : bucket_hash &= SIG_BUCKET_128KB_HASH_MASK;
602 : : else
603 : 0 : bucket_hash &= SIG_BUCKET_64KB_HASH_MASK;
604 : :
605 : 0 : sig_hash = txgbe_atr_compute_hash(input,
606 : : TXGBE_ATR_SIGNATURE_HASH_KEY);
607 : :
608 : 0 : return TXGBE_FDIRPIHASH_SIG(sig_hash) |
609 : : TXGBE_FDIRPIHASH_BKT(bucket_hash);
610 : : }
611 : :
612 : : /**
613 : : * With the ability to set extra flags in FDIRPICMD register
614 : : * added, and IPv6 support also added. The hash value is also pre-calculated
615 : : * as the pballoc value is needed to do it.
616 : : */
617 : : static int
618 : 0 : fdir_write_perfect_filter(struct txgbe_hw *hw,
619 : : struct txgbe_atr_input *input, uint8_t queue,
620 : : uint32_t fdircmd, uint32_t fdirhash,
621 : : enum rte_fdir_mode mode)
622 : : {
623 : : uint32_t fdirport, fdirflex;
624 : : int err = 0;
625 : :
626 : : UNREFERENCED_PARAMETER(mode);
627 : :
628 : : /* record the IPv4 address (little-endian)
629 : : * can not use wr32.
630 : : */
631 [ # # ]: 0 : wr32(hw, TXGBE_FDIRPISIP4, be_to_le32(input->src_ip[0]));
632 [ # # ]: 0 : wr32(hw, TXGBE_FDIRPIDIP4, be_to_le32(input->dst_ip[0]));
633 : :
634 : : /* record source and destination port (little-endian)*/
635 [ # # ]: 0 : fdirport = TXGBE_FDIRPIPORT_DST(be_to_le16(input->dst_port));
636 [ # # ]: 0 : fdirport |= TXGBE_FDIRPIPORT_SRC(be_to_le16(input->src_port));
637 : : wr32(hw, TXGBE_FDIRPIPORT, fdirport);
638 : :
639 : : /* record pkt_type (little-endian) and flex_bytes(big-endian) */
640 [ # # ]: 0 : fdirflex = TXGBE_FDIRPIFLEX_FLEX(be_to_npu16(input->flex_bytes));
641 [ # # ]: 0 : fdirflex |= TXGBE_FDIRPIFLEX_PTYPE(be_to_le16(input->pkt_type));
642 : : wr32(hw, TXGBE_FDIRPIFLEX, fdirflex);
643 : :
644 : : /* configure FDIRHASH register */
645 : 0 : fdirhash |= TXGBE_FDIRPIHASH_VLD;
646 : : wr32(hw, TXGBE_FDIRPIHASH, fdirhash);
647 : :
648 : : /*
649 : : * flush all previous writes to make certain registers are
650 : : * programmed prior to issuing the command
651 : : */
652 : : txgbe_flush(hw);
653 : :
654 : : /* configure FDIRPICMD register */
655 : 0 : fdircmd |= TXGBE_FDIRPICMD_OP_ADD |
656 : : TXGBE_FDIRPICMD_UPD |
657 : : TXGBE_FDIRPICMD_LAST |
658 : : TXGBE_FDIRPICMD_QPENA;
659 : 0 : fdircmd |= TXGBE_FDIRPICMD_FT(input->flow_type);
660 : 0 : fdircmd |= TXGBE_FDIRPICMD_QP(queue);
661 : 0 : fdircmd |= TXGBE_FDIRPICMD_POOL(input->vm_pool);
662 : :
663 [ # # ]: 0 : if (input->flow_type & TXGBE_ATR_L3TYPE_IPV6) {
664 : : /* use SIP4 to store LS Dword of the Source iPv6 address */
665 [ # # ]: 0 : wr32(hw, TXGBE_FDIRPISIP4, be_to_le32(input->src_ip[3]));
666 [ # # ]: 0 : wr32(hw, TXGBE_FDIRPISIP6(0), be_to_le32(input->src_ip[2]));
667 [ # # ]: 0 : wr32(hw, TXGBE_FDIRPISIP6(1), be_to_le32(input->src_ip[1]));
668 [ # # ]: 0 : wr32(hw, TXGBE_FDIRPISIP6(2), be_to_le32(input->src_ip[0]));
669 : 0 : fdircmd |= TXGBE_FDIRPICMD_IP6;
670 : : }
671 : : wr32(hw, TXGBE_FDIRPICMD, fdircmd);
672 : :
673 : 0 : PMD_DRV_LOG(DEBUG, "Rx Queue=%x hash=%x", queue, fdirhash);
674 : :
675 : : err = txgbe_fdir_check_cmd_complete(hw, &fdircmd);
676 [ # # ]: 0 : if (err < 0)
677 : 0 : PMD_DRV_LOG(ERR, "Timeout writing flow director filter.");
678 : :
679 : 0 : return err;
680 : : }
681 : :
682 : : /**
683 : : * This function supports setting extra fields in the FDIRPICMD register, and
684 : : * removes the code that was verifying the flow_type field. According to the
685 : : * documentation, a flow type of 00 (i.e. not TCP, UDP, or SCTP) is not
686 : : * supported, however it appears to work ok...
687 : : * Adds a signature hash filter
688 : : * @hw: pointer to hardware structure
689 : : * @input: unique input dword
690 : : * @queue: queue index to direct traffic to
691 : : * @fdircmd: any extra flags to set in fdircmd register
692 : : * @fdirhash: pre-calculated hash value for the filter
693 : : **/
694 : : static int
695 : 0 : fdir_add_signature_filter(struct txgbe_hw *hw,
696 : : struct txgbe_atr_input *input, uint8_t queue, uint32_t fdircmd,
697 : : uint32_t fdirhash)
698 : : {
699 : : int err = 0;
700 : :
701 : 0 : PMD_INIT_FUNC_TRACE();
702 : :
703 : : /* configure FDIRPICMD register */
704 : 0 : fdircmd |= TXGBE_FDIRPICMD_OP_ADD |
705 : : TXGBE_FDIRPICMD_UPD |
706 : : TXGBE_FDIRPICMD_LAST |
707 : : TXGBE_FDIRPICMD_QPENA;
708 : 0 : fdircmd |= TXGBE_FDIRPICMD_FT(input->flow_type);
709 : 0 : fdircmd |= TXGBE_FDIRPICMD_QP(queue);
710 : :
711 : 0 : fdirhash |= TXGBE_FDIRPIHASH_VLD;
712 : : wr32(hw, TXGBE_FDIRPIHASH, fdirhash);
713 : : wr32(hw, TXGBE_FDIRPICMD, fdircmd);
714 : :
715 : 0 : PMD_DRV_LOG(DEBUG, "Rx Queue=%x hash=%x", queue, fdirhash);
716 : :
717 : : err = txgbe_fdir_check_cmd_complete(hw, &fdircmd);
718 [ # # ]: 0 : if (err < 0)
719 : 0 : PMD_DRV_LOG(ERR, "Timeout writing flow director filter.");
720 : :
721 : 0 : return err;
722 : : }
723 : :
724 : : /*
725 : : * This is modified to take in the hash as a parameter so that
726 : : * it can be used for removing signature and perfect filters.
727 : : */
728 : : static int
729 : 0 : fdir_erase_filter_raptor(struct txgbe_hw *hw, uint32_t fdirhash)
730 : : {
731 : : uint32_t fdircmd = 0;
732 : : int err = 0;
733 : :
734 : : wr32(hw, TXGBE_FDIRPIHASH, fdirhash);
735 : :
736 : : /* flush hash to HW */
737 : : txgbe_flush(hw);
738 : :
739 : : /* Query if filter is present */
740 : : wr32(hw, TXGBE_FDIRPICMD, TXGBE_FDIRPICMD_OP_QRY);
741 : :
742 : : err = txgbe_fdir_check_cmd_complete(hw, &fdircmd);
743 [ # # ]: 0 : if (err < 0) {
744 : 0 : PMD_INIT_LOG(ERR, "Timeout querying for flow director filter.");
745 : 0 : return err;
746 : : }
747 : :
748 : : /* if filter exists in hardware then remove it */
749 [ # # ]: 0 : if (fdircmd & TXGBE_FDIRPICMD_VLD) {
750 : : wr32(hw, TXGBE_FDIRPIHASH, fdirhash);
751 : : txgbe_flush(hw);
752 : : wr32(hw, TXGBE_FDIRPICMD, TXGBE_FDIRPICMD_OP_REM);
753 : : }
754 : :
755 : : err = txgbe_fdir_check_cmd_complete(hw, &fdircmd);
756 [ # # ]: 0 : if (err < 0)
757 : 0 : PMD_INIT_LOG(ERR, "Timeout erasing flow director filter.");
758 : :
759 : : return err;
760 : : }
761 : :
762 : : static inline struct txgbe_fdir_filter *
763 : : txgbe_fdir_filter_lookup(struct txgbe_hw_fdir_info *fdir_info,
764 : : struct txgbe_atr_input *input)
765 : : {
766 : : int ret;
767 : :
768 : 0 : ret = rte_hash_lookup(fdir_info->hash_handle, (const void *)input);
769 [ # # ]: 0 : if (ret < 0)
770 : : return NULL;
771 : :
772 : 0 : return fdir_info->hash_map[ret];
773 : : }
774 : :
775 : : static inline int
776 : 0 : txgbe_insert_fdir_filter(struct txgbe_hw_fdir_info *fdir_info,
777 : : struct txgbe_fdir_filter *fdir_filter)
778 : : {
779 : : int ret;
780 : :
781 : 0 : ret = rte_hash_add_key(fdir_info->hash_handle, &fdir_filter->input);
782 [ # # ]: 0 : if (ret < 0) {
783 : 0 : PMD_DRV_LOG(ERR,
784 : : "Failed to insert fdir filter to hash table %d!",
785 : : ret);
786 : 0 : return ret;
787 : : }
788 : :
789 : 0 : fdir_info->hash_map[ret] = fdir_filter;
790 : :
791 : 0 : TAILQ_INSERT_TAIL(&fdir_info->fdir_list, fdir_filter, entries);
792 : :
793 : 0 : return ret;
794 : : }
795 : :
796 : : static inline int
797 : 0 : txgbe_remove_fdir_filter(struct txgbe_hw_fdir_info *fdir_info,
798 : : struct txgbe_atr_input *input)
799 : : {
800 : : int ret;
801 : : struct txgbe_fdir_filter *fdir_filter;
802 : :
803 : 0 : ret = rte_hash_del_key(fdir_info->hash_handle, input);
804 [ # # ]: 0 : if (ret < 0)
805 : : return ret;
806 : :
807 : 0 : fdir_filter = fdir_info->hash_map[ret];
808 : 0 : fdir_info->hash_map[ret] = NULL;
809 : :
810 [ # # ]: 0 : TAILQ_REMOVE(&fdir_info->fdir_list, fdir_filter, entries);
811 : 0 : rte_free(fdir_filter);
812 : :
813 : 0 : return ret;
814 : : }
815 : :
816 : : static void
817 : 0 : txgbe_fdir_mask_input(struct txgbe_hw_fdir_mask *mask,
818 : : struct txgbe_atr_input *input)
819 : : {
820 : : int i;
821 : :
822 [ # # ]: 0 : if (input->flow_type & TXGBE_ATR_L3TYPE_IPV6) {
823 [ # # ]: 0 : for (i = 0; i < 16; i++) {
824 [ # # ]: 0 : if (!(mask->src_ipv6_mask & (1 << i)))
825 : 0 : input->src_ip[i / 4] &= ~(0xFF << ((i % 4) * 8));
826 : : }
827 : : } else {
828 : 0 : input->src_ip[0] &= mask->src_ipv4_mask;
829 : 0 : input->dst_ip[0] &= mask->dst_ipv4_mask;
830 : : }
831 : :
832 : 0 : input->src_port &= mask->src_port_mask;
833 : 0 : input->dst_port &= mask->dst_port_mask;
834 : 0 : }
835 : :
836 : : int
837 : 0 : txgbe_fdir_filter_program(struct rte_eth_dev *dev,
838 : : struct txgbe_fdir_rule *rule,
839 : : bool del,
840 : : bool update)
841 : : {
842 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
843 : : uint32_t fdirhash;
844 : : uint8_t queue;
845 : : bool is_perfect = FALSE;
846 : : int err;
847 : 0 : struct txgbe_hw_fdir_info *info = TXGBE_DEV_FDIR(dev);
848 : 0 : enum rte_fdir_mode fdir_mode = TXGBE_DEV_FDIR_CONF(dev)->mode;
849 : : struct txgbe_fdir_filter *node;
850 : :
851 [ # # ]: 0 : if (fdir_mode == RTE_FDIR_MODE_NONE ||
852 [ # # ]: 0 : fdir_mode != rule->mode)
853 : : return -ENOTSUP;
854 : :
855 [ # # ]: 0 : if (fdir_mode >= RTE_FDIR_MODE_PERFECT)
856 : : is_perfect = TRUE;
857 : :
858 : 0 : txgbe_fdir_mask_input(&info->mask, &rule->input);
859 : :
860 [ # # ]: 0 : if (is_perfect) {
861 : 0 : fdirhash = atr_compute_perfect_hash(&rule->input,
862 : : TXGBE_DEV_FDIR_CONF(dev)->pballoc);
863 : 0 : fdirhash |= TXGBE_FDIRPIHASH_IDX(rule->soft_id);
864 : : } else {
865 : 0 : fdirhash = atr_compute_signature_hash(&rule->input,
866 : : TXGBE_DEV_FDIR_CONF(dev)->pballoc);
867 : : }
868 : :
869 [ # # ]: 0 : if (del) {
870 : 0 : err = txgbe_remove_fdir_filter(info, &rule->input);
871 [ # # ]: 0 : if (err < 0) {
872 : 0 : PMD_DRV_LOG(ERR,
873 : : "No such fdir filter to delete %d!", err);
874 : 0 : return err;
875 : : }
876 : :
877 : 0 : err = fdir_erase_filter_raptor(hw, fdirhash);
878 [ # # ]: 0 : if (err < 0)
879 : 0 : PMD_DRV_LOG(ERR, "Fail to delete FDIR filter!");
880 : : else
881 : 0 : PMD_DRV_LOG(DEBUG, "Success to delete FDIR filter!");
882 : 0 : return err;
883 : : }
884 : :
885 : : /* add or update an fdir filter*/
886 [ # # ]: 0 : if (rule->fdirflags & TXGBE_FDIRPICMD_DROP) {
887 [ # # ]: 0 : if (!is_perfect) {
888 : 0 : PMD_DRV_LOG(ERR, "Drop option is not supported in"
889 : : " signature mode.");
890 : 0 : return -EINVAL;
891 : : }
892 : 0 : queue = TXGBE_DEV_FDIR_CONF(dev)->drop_queue;
893 [ # # ]: 0 : } else if (rule->queue < TXGBE_MAX_RX_QUEUE_NUM) {
894 : : queue = rule->queue;
895 : : } else {
896 : : return -EINVAL;
897 : : }
898 : :
899 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active)
900 : 0 : queue = RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue;
901 : :
902 : : node = txgbe_fdir_filter_lookup(info, &rule->input);
903 [ # # ]: 0 : if (node) {
904 [ # # ]: 0 : if (!update) {
905 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing fdir filter!");
906 : 0 : return -EINVAL;
907 : : }
908 : 0 : node->fdirflags = rule->fdirflags;
909 : 0 : node->fdirhash = fdirhash;
910 : 0 : node->queue = queue;
911 : : } else {
912 : 0 : node = rte_zmalloc("txgbe_fdir",
913 : : sizeof(struct txgbe_fdir_filter), 0);
914 [ # # ]: 0 : if (!node)
915 : : return -ENOMEM;
916 : : rte_memcpy(&node->input, &rule->input,
917 : : sizeof(struct txgbe_atr_input));
918 : 0 : node->fdirflags = rule->fdirflags;
919 : 0 : node->fdirhash = fdirhash;
920 : 0 : node->queue = queue;
921 : :
922 : 0 : err = txgbe_insert_fdir_filter(info, node);
923 [ # # ]: 0 : if (err < 0) {
924 : 0 : rte_free(node);
925 : 0 : return err;
926 : : }
927 : : }
928 : :
929 [ # # ]: 0 : if (is_perfect)
930 : 0 : err = fdir_write_perfect_filter(hw, &node->input,
931 : 0 : node->queue, node->fdirflags,
932 : : node->fdirhash, fdir_mode);
933 : : else
934 : 0 : err = fdir_add_signature_filter(hw, &node->input,
935 : 0 : node->queue, node->fdirflags,
936 : : node->fdirhash);
937 [ # # ]: 0 : if (err < 0) {
938 : 0 : PMD_DRV_LOG(ERR, "Fail to add FDIR filter!");
939 : 0 : txgbe_remove_fdir_filter(info, &rule->input);
940 : : } else {
941 : 0 : PMD_DRV_LOG(DEBUG, "Success to add FDIR filter");
942 : : }
943 : :
944 : : return err;
945 : : }
946 : :
947 : : static void
948 : : txgbevf_flush_fdir_filter(struct rte_eth_dev *dev)
949 : : {
950 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
951 : 0 : uint32_t msg[2] = {0, 0};
952 : :
953 : : /* flush bit */
954 : 0 : msg[TXGBEVF_FDIR_CMD] = 1 << 16;
955 : :
956 : 0 : txgbevf_set_fdir(hw, msg, FALSE);
957 : : }
958 : :
959 : : static int
960 : 0 : txgbevf_del_fdir_filter(struct rte_eth_dev *dev,
961 : : struct txgbe_fdir_rule *rule,
962 : : int id)
963 : : {
964 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
965 : 0 : struct txgbe_hw_fdir_info *info = TXGBE_DEV_FDIR(dev);
966 : 0 : uint32_t msg[2] = {0, 0};
967 : : int ret = 0;
968 : :
969 : : /* node id [15:0] */
970 : 0 : msg[TXGBEVF_FDIR_CMD] = id;
971 : :
972 : 0 : ret = txgbevf_set_fdir(hw, msg, FALSE);
973 [ # # ]: 0 : if (ret) {
974 : 0 : PMD_DRV_LOG(ERR, "VF request PF to delete FDIR filters failed.");
975 : 0 : return ret;
976 : : }
977 : :
978 : 0 : ret = txgbe_remove_fdir_filter(info, &rule->input);
979 [ # # ]: 0 : if (ret < 0)
980 : 0 : PMD_DRV_LOG(ERR, "Fail to delete FDIR filter!");
981 : :
982 : : return 0;
983 : : }
984 : :
985 : : static int
986 : 0 : txgbevf_add_fdir_filter(struct rte_eth_dev *dev,
987 : : struct txgbe_fdir_rule *rule,
988 : : int id)
989 : : {
990 [ # # ]: 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
991 : : uint32_t msg[TXGBEVF_FDIR_MAX];
992 : : int ret = 0;
993 : :
994 : : memset(msg, 0, sizeof(msg));
995 : :
996 : : /* node id [15:0] */
997 : 0 : msg[TXGBEVF_FDIR_CMD] = id;
998 : : /* ring_idx [23:16] */
999 : 0 : msg[TXGBEVF_FDIR_CMD] |= rule->queue << 16;
1000 : : /* flow_type [30:24] */
1001 : 0 : msg[TXGBEVF_FDIR_CMD] |= rule->input.flow_type << 24;
1002 : :
1003 : 0 : msg[TXGBEVF_FDIR_IP4SA] = rule->input.src_ip[0];
1004 : 0 : msg[TXGBEVF_FDIR_IP4DA] = rule->input.dst_ip[0];
1005 : 0 : msg[TXGBEVF_FDIR_PORT] = (rule->input.dst_port << 16) |
1006 : 0 : rule->input.src_port;
1007 [ # # ]: 0 : if (rule->mask.flex_bytes_mask) {
1008 : : /* base [1:0] */
1009 : 0 : msg[TXGBEVF_FDIR_FLEX] = txgbe_fdir_get_flex_base(rule);
1010 : : /* offset [7:3] */
1011 : 0 : msg[TXGBEVF_FDIR_FLEX] |=
1012 : 0 : TXGBE_FDIRFLEXCFG_OFST(rule->flex_bytes_offset / 2);
1013 : : /* flex bytes [31:16]*/
1014 : 0 : msg[TXGBEVF_FDIR_FLEX] |= rule->input.flex_bytes << 16;
1015 : : }
1016 : 0 : msg[TXGBEVF_FDIR_IP4SM] = rule->mask.src_ipv4_mask;
1017 : 0 : msg[TXGBEVF_FDIR_IP4DM] = rule->mask.dst_ipv4_mask;
1018 : 0 : msg[TXGBEVF_FDIR_PORTM] = (rule->mask.dst_port_mask << 16) |
1019 : 0 : rule->mask.src_port_mask;
1020 : :
1021 : 0 : ret = txgbevf_set_fdir(hw, msg, TRUE);
1022 [ # # ]: 0 : if (ret)
1023 : 0 : PMD_DRV_LOG(ERR, "VF request PF to add FDIR filters failed.");
1024 : :
1025 : 0 : return ret;
1026 : : }
1027 : :
1028 : : int
1029 : 0 : txgbevf_fdir_filter_program(struct rte_eth_dev *dev,
1030 : : struct txgbe_fdir_rule *rule,
1031 : : bool del)
1032 : : {
1033 : 0 : struct txgbe_hw_fdir_info *info = TXGBE_DEV_FDIR(dev);
1034 : 0 : struct txgbe_atr_input *input = &rule->input;
1035 : : struct txgbe_fdir_filter *node;
1036 : : uint32_t fdirhash;
1037 : : int ret;
1038 : :
1039 [ # # ]: 0 : if (rule->mode != RTE_FDIR_MODE_PERFECT ||
1040 [ # # ]: 0 : rule->fdirflags == TXGBE_FDIRPICMD_DROP)
1041 : : return -ENOTSUP;
1042 : :
1043 [ # # ]: 0 : if (input->flow_type & TXGBE_ATR_FLOW_TYPE_IPV6)
1044 : : return -ENOTSUP;
1045 : :
1046 : 0 : fdirhash = atr_compute_perfect_hash(input,
1047 : : TXGBE_DEV_FDIR_CONF(dev)->pballoc);
1048 : :
1049 : 0 : ret = rte_hash_lookup(info->hash_handle, (const void *)input);
1050 [ # # ]: 0 : if (ret < 0) {
1051 [ # # ]: 0 : if (del) {
1052 : 0 : PMD_DRV_LOG(ERR, "No such fdir filter to delete!");
1053 : 0 : return ret;
1054 : : }
1055 : : } else {
1056 [ # # ]: 0 : if (!del) {
1057 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing fdir filter!");
1058 : 0 : return -EINVAL;
1059 : : }
1060 : : }
1061 : :
1062 [ # # ]: 0 : if (del)
1063 : 0 : return txgbevf_del_fdir_filter(dev, rule, ret);
1064 : :
1065 : 0 : node = rte_zmalloc("txgbe_fdir",
1066 : : sizeof(struct txgbe_fdir_filter), 0);
1067 [ # # ]: 0 : if (!node)
1068 : : return -ENOMEM;
1069 : : rte_memcpy(&node->input, input,
1070 : : sizeof(struct txgbe_atr_input));
1071 : 0 : node->fdirflags = rule->fdirflags;
1072 : 0 : node->fdirhash = fdirhash;
1073 : 0 : node->queue = rule->queue;
1074 : :
1075 : 0 : ret = txgbe_insert_fdir_filter(info, node);
1076 [ # # ]: 0 : if (ret < 0) {
1077 : 0 : rte_free(node);
1078 : 0 : return ret;
1079 : : }
1080 : :
1081 : 0 : ret = txgbevf_add_fdir_filter(dev, rule, ret);
1082 [ # # ]: 0 : if (ret)
1083 : 0 : txgbe_remove_fdir_filter(info, input);
1084 : :
1085 : : return ret;
1086 : : }
1087 : :
1088 : : static int
1089 : 0 : txgbe_fdir_flush(struct rte_eth_dev *dev)
1090 : : {
1091 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1092 : : struct txgbe_hw_fdir_info *info = TXGBE_DEV_FDIR(dev);
1093 : : int ret;
1094 : :
1095 [ # # ]: 0 : if (!txgbe_is_pf(hw)) {
1096 : : txgbevf_flush_fdir_filter(dev);
1097 : 0 : return 0;
1098 : : }
1099 : :
1100 : 0 : ret = txgbe_reinit_fdir_tables(hw);
1101 [ # # ]: 0 : if (ret < 0) {
1102 : 0 : PMD_INIT_LOG(ERR, "Failed to re-initialize FD table.");
1103 : 0 : return ret;
1104 : : }
1105 : :
1106 : 0 : info->f_add = 0;
1107 : 0 : info->f_remove = 0;
1108 : 0 : info->add = 0;
1109 : 0 : info->remove = 0;
1110 : :
1111 : 0 : memset(&info->mask, 0, sizeof(struct txgbe_hw_fdir_mask));
1112 : 0 : info->mask_added = false;
1113 : 0 : info->flex_relative = false;
1114 : 0 : info->flex_bytes_offset = 0;
1115 : :
1116 : 0 : return ret;
1117 : : }
1118 : :
1119 : : /* restore flow director filter */
1120 : : void
1121 : 0 : txgbe_fdir_filter_restore(struct rte_eth_dev *dev)
1122 : : {
1123 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1124 : : struct txgbe_hw_fdir_info *fdir_info = TXGBE_DEV_FDIR(dev);
1125 : : struct txgbe_fdir_filter *node;
1126 : : bool is_perfect = FALSE;
1127 : 0 : enum rte_fdir_mode fdir_mode = TXGBE_DEV_FDIR_CONF(dev)->mode;
1128 : :
1129 [ # # ]: 0 : if (fdir_mode >= RTE_FDIR_MODE_PERFECT &&
1130 : : fdir_mode <= RTE_FDIR_MODE_PERFECT_TUNNEL)
1131 : : is_perfect = TRUE;
1132 : :
1133 : : if (is_perfect) {
1134 [ # # ]: 0 : TAILQ_FOREACH(node, &fdir_info->fdir_list, entries) {
1135 : 0 : (void)fdir_write_perfect_filter(hw,
1136 : : &node->input,
1137 : 0 : node->queue,
1138 : : node->fdirflags,
1139 : : node->fdirhash,
1140 : : fdir_mode);
1141 : : }
1142 : : } else {
1143 [ # # ]: 0 : TAILQ_FOREACH(node, &fdir_info->fdir_list, entries) {
1144 : 0 : (void)fdir_add_signature_filter(hw,
1145 : : &node->input,
1146 : 0 : node->queue,
1147 : : node->fdirflags,
1148 : : node->fdirhash);
1149 : : }
1150 : : }
1151 : 0 : }
1152 : :
1153 : : /* remove all the flow director filters */
1154 : : int
1155 : 0 : txgbe_clear_all_fdir_filter(struct rte_eth_dev *dev)
1156 : : {
1157 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1158 : : struct rte_eth_fdir_conf *fdir_conf = TXGBE_DEV_FDIR_CONF(dev);
1159 : : struct txgbe_hw_fdir_info *fdir_info = TXGBE_DEV_FDIR(dev);
1160 : : struct txgbe_fdir_filter *fdir_filter;
1161 : : struct txgbe_fdir_filter *filter_flag;
1162 : : bool fdir_enabled;
1163 : : int ret = 0;
1164 : :
1165 : 0 : fdir_enabled = fdir_conf->mode != RTE_FDIR_MODE_NONE;
1166 : :
1167 : : /* flush flow director */
1168 : 0 : rte_hash_reset(fdir_info->hash_handle);
1169 : 0 : memset(fdir_info->hash_map, 0,
1170 : : sizeof(struct txgbe_fdir_filter *) *
1171 : 0 : ((1024 << (fdir_conf->pballoc + 1)) - 2));
1172 : 0 : fdir_conf->mode = RTE_FDIR_MODE_NONE;
1173 : 0 : filter_flag = TAILQ_FIRST(&fdir_info->fdir_list);
1174 [ # # ]: 0 : while ((fdir_filter = TAILQ_FIRST(&fdir_info->fdir_list))) {
1175 [ # # ]: 0 : TAILQ_REMOVE(&fdir_info->fdir_list,
1176 : : fdir_filter,
1177 : : entries);
1178 : 0 : rte_free(fdir_filter);
1179 : : }
1180 : :
1181 [ # # ]: 0 : if (filter_flag != NULL)
1182 : 0 : ret = txgbe_fdir_flush(dev);
1183 : :
1184 [ # # # # ]: 0 : if (fdir_enabled && txgbe_is_pf(hw))
1185 : 0 : txgbe_fdir_disable(hw);
1186 : :
1187 : 0 : return ret;
1188 : : }
|