Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2015 Intel Corporation
3 : : */
4 : :
5 : : #include <stdio.h>
6 : : #include <stdint.h>
7 : : #include <stdarg.h>
8 : : #include <errno.h>
9 : : #include <sys/queue.h>
10 : :
11 : : #include <rte_interrupts.h>
12 : : #include <rte_log.h>
13 : : #include <rte_debug.h>
14 : : #include <rte_pci.h>
15 : : #include <rte_vxlan.h>
16 : : #include <ethdev_driver.h>
17 : : #include <rte_malloc.h>
18 : :
19 : : #include "ixgbe_logs.h"
20 : : #include "base/ixgbe_api.h"
21 : : #include "base/ixgbe_common.h"
22 : : #include "ixgbe_ethdev.h"
23 : :
24 : : /* To get PBALLOC (Packet Buffer Allocation) bits from FDIRCTRL value */
25 : : #define FDIRCTRL_PBALLOC_MASK 0x03
26 : :
27 : : /* For calculating memory required for FDIR filters */
28 : : #define PBALLOC_SIZE_SHIFT 15
29 : :
30 : : /* Number of bits used to mask bucket hash for different pballoc sizes */
31 : : #define PERFECT_BUCKET_64KB_HASH_MASK 0x07FF /* 11 bits */
32 : : #define PERFECT_BUCKET_128KB_HASH_MASK 0x0FFF /* 12 bits */
33 : : #define PERFECT_BUCKET_256KB_HASH_MASK 0x1FFF /* 13 bits */
34 : : #define SIG_BUCKET_64KB_HASH_MASK 0x1FFF /* 13 bits */
35 : : #define SIG_BUCKET_128KB_HASH_MASK 0x3FFF /* 14 bits */
36 : : #define SIG_BUCKET_256KB_HASH_MASK 0x7FFF /* 15 bits */
37 : : #define IXGBE_DEFAULT_FLEXBYTES_OFFSET 12 /* default flexbytes offset in bytes */
38 : : #define IXGBE_FDIR_MAX_FLEX_LEN 2 /* len in bytes of flexbytes */
39 : : #define IXGBE_MAX_FLX_SOURCE_OFF 62
40 : : #define IXGBE_FDIRCTRL_FLEX_MASK (0x1F << IXGBE_FDIRCTRL_FLEX_SHIFT)
41 : : #define IXGBE_FDIRCMD_CMD_INTERVAL_US 10
42 : :
43 : : #define IXGBE_FDIR_FLOW_TYPES ( \
44 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_UDP) | \
45 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_TCP) | \
46 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP) | \
47 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER) | \
48 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_UDP) | \
49 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_TCP) | \
50 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP) | \
51 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER))
52 : :
53 : : #define IPV6_ADDR_TO_MASK(ipaddr, ipv6m) do { \
54 : : uint8_t ipv6_addr[16]; \
55 : : uint8_t i; \
56 : : memcpy(ipv6_addr, (ipaddr), sizeof(ipv6_addr));\
57 : : (ipv6m) = 0; \
58 : : for (i = 0; i < sizeof(ipv6_addr); i++) { \
59 : : if (ipv6_addr[i] == UINT8_MAX) \
60 : : (ipv6m) |= 1 << i; \
61 : : else if (ipv6_addr[i] != 0) { \
62 : : PMD_DRV_LOG(ERR, " invalid IPv6 address mask."); \
63 : : return -EINVAL; \
64 : : } \
65 : : } \
66 : : } while (0)
67 : :
68 : : #define IPV6_MASK_TO_ADDR(ipv6m, ipaddr) do { \
69 : : uint8_t ipv6_addr[16]; \
70 : : for (uint8_t i = 0; i < sizeof(ipv6_addr); i++) { \
71 : : if ((ipv6m) & (1 << i)) \
72 : : ipv6_addr[i] = UINT8_MAX; \
73 : : else \
74 : : ipv6_addr[i] = 0; \
75 : : } \
76 : : memcpy((ipaddr), ipv6_addr, sizeof(ipv6_addr));\
77 : : } while (0)
78 : :
79 : : #define IXGBE_FDIRIP6M_INNER_MAC_SHIFT 4
80 : :
81 : : static int fdir_erase_filter_82599(struct ixgbe_hw *hw, uint32_t fdirhash);
82 : : static int fdir_set_input_mask_82599(struct ixgbe_adapter *adapter,
83 : : const struct ixgbe_hw_fdir_mask *mask,
84 : : enum rte_fdir_mode mode);
85 : : static int fdir_set_input_mask_x550(struct ixgbe_adapter *adapter,
86 : : const struct ixgbe_hw_fdir_mask *mask,
87 : : enum rte_fdir_mode mode);
88 : : static int ixgbe_set_fdir_flex_conf(struct ixgbe_adapter *adapter,
89 : : const struct rte_eth_fdir_flex_conf *conf, uint32_t *fdirctrl);
90 : : static int fdir_enable_82599(struct ixgbe_hw *hw, uint32_t fdirctrl);
91 : : static uint32_t ixgbe_atr_compute_hash_82599(union ixgbe_atr_input *atr_input,
92 : : uint32_t key);
93 : : static uint32_t atr_compute_sig_hash_82599(union ixgbe_atr_input *input,
94 : : enum rte_eth_fdir_pballoc_type pballoc);
95 : : static uint32_t atr_compute_perfect_hash_82599(union ixgbe_atr_input *input,
96 : : enum rte_eth_fdir_pballoc_type pballoc);
97 : : static int fdir_write_perfect_filter_82599(struct ixgbe_hw *hw,
98 : : union ixgbe_atr_input *input, uint8_t queue,
99 : : uint32_t fdircmd, uint32_t fdirhash,
100 : : enum rte_fdir_mode mode);
101 : : static int fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
102 : : union ixgbe_atr_input *input, u8 queue, uint32_t fdircmd,
103 : : uint32_t fdirhash);
104 : : static int ixgbe_fdir_flush(struct rte_eth_dev *dev);
105 : :
106 : : /**
107 : : * This function is based on ixgbe_fdir_enable_82599() in base/ixgbe_82599.c.
108 : : * It adds extra configuration of fdirctrl that is common for all filter types.
109 : : *
110 : : * Initialize Flow Director control registers
111 : : * @hw: pointer to hardware structure
112 : : * @fdirctrl: value to write to flow director control register
113 : : **/
114 : : static int
115 : 0 : fdir_enable_82599(struct ixgbe_hw *hw, uint32_t fdirctrl)
116 : : {
117 : : int i;
118 : :
119 : 0 : PMD_INIT_FUNC_TRACE();
120 : :
121 : : /* Prime the keys for hashing */
122 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY, IXGBE_ATR_BUCKET_HASH_KEY);
123 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY, IXGBE_ATR_SIGNATURE_HASH_KEY);
124 : :
125 : : /*
126 : : * Continue setup of fdirctrl register bits:
127 : : * Set the maximum length per hash bucket to 0xA filters
128 : : * Send interrupt when 64 filters are left
129 : : */
130 : 0 : fdirctrl |= (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT) |
131 : : (4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT);
132 : :
133 : : /*
134 : : * Poll init-done after we write the register. Estimated times:
135 : : * 10G: PBALLOC = 11b, timing is 60us
136 : : * 1G: PBALLOC = 11b, timing is 600us
137 : : * 100M: PBALLOC = 11b, timing is 6ms
138 : : *
139 : : * Multiple these timings by 4 if under full Rx load
140 : : *
141 : : * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for
142 : : * 1 msec per poll time. If we're at line rate and drop to 100M, then
143 : : * this might not finish in our poll time, but we can live with that
144 : : * for now.
145 : : */
146 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
147 : 0 : IXGBE_WRITE_FLUSH(hw);
148 [ # # ]: 0 : for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
149 [ # # ]: 0 : if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
150 : : IXGBE_FDIRCTRL_INIT_DONE)
151 : : break;
152 : 0 : msec_delay(1);
153 : : }
154 : :
155 [ # # ]: 0 : if (i >= IXGBE_FDIR_INIT_DONE_POLL) {
156 : 0 : PMD_INIT_LOG(ERR, "Flow Director poll time exceeded during enabling!");
157 : 0 : return -ETIMEDOUT;
158 : : }
159 : : return 0;
160 : : }
161 : :
162 : : /*
163 : : * Set appropriate bits in fdirctrl for: variable reporting levels, moving
164 : : * flexbytes matching field, and drop queue (only for perfect matching mode).
165 : : */
166 : : static inline int
167 : 0 : configure_fdir_flags(const struct rte_eth_fdir_conf *conf, uint32_t *fdirctrl)
168 : : {
169 : 0 : *fdirctrl = 0;
170 : :
171 [ # # # # ]: 0 : switch (conf->pballoc) {
172 : 0 : case RTE_ETH_FDIR_PBALLOC_64K:
173 : : /* 8k - 1 signature filters */
174 : 0 : *fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_64K;
175 : 0 : break;
176 : 0 : case RTE_ETH_FDIR_PBALLOC_128K:
177 : : /* 16k - 1 signature filters */
178 : 0 : *fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_128K;
179 : 0 : break;
180 : 0 : case RTE_ETH_FDIR_PBALLOC_256K:
181 : : /* 32k - 1 signature filters */
182 : 0 : *fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_256K;
183 : 0 : break;
184 : 0 : default:
185 : : /* bad value */
186 : 0 : PMD_INIT_LOG(ERR, "Invalid fdir_conf->pballoc value");
187 : 0 : return -EINVAL;
188 : : };
189 : :
190 : : /* status flags: write hash & swindex in the rx descriptor */
191 [ # # # # ]: 0 : switch (conf->status) {
192 : : case RTE_FDIR_NO_REPORT_STATUS:
193 : : /* do nothing, default mode */
194 : : break;
195 : 0 : case RTE_FDIR_REPORT_STATUS:
196 : : /* report status when the packet matches a fdir rule */
197 : 0 : *fdirctrl |= IXGBE_FDIRCTRL_REPORT_STATUS;
198 : 0 : break;
199 : 0 : case RTE_FDIR_REPORT_STATUS_ALWAYS:
200 : : /* always report status */
201 : 0 : *fdirctrl |= IXGBE_FDIRCTRL_REPORT_STATUS_ALWAYS;
202 : 0 : break;
203 : 0 : default:
204 : : /* bad value */
205 : 0 : PMD_INIT_LOG(ERR, "Invalid fdir_conf->status value");
206 : 0 : return -EINVAL;
207 : : };
208 : :
209 : 0 : *fdirctrl |= (IXGBE_DEFAULT_FLEXBYTES_OFFSET / sizeof(uint16_t)) <<
210 : : IXGBE_FDIRCTRL_FLEX_SHIFT;
211 : :
212 [ # # ]: 0 : if (conf->mode >= RTE_FDIR_MODE_PERFECT &&
213 : : conf->mode <= RTE_FDIR_MODE_PERFECT_TUNNEL) {
214 : 0 : *fdirctrl |= IXGBE_FDIRCTRL_PERFECT_MATCH;
215 : 0 : *fdirctrl |= (conf->drop_queue << IXGBE_FDIRCTRL_DROP_Q_SHIFT);
216 [ # # ]: 0 : if (conf->mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
217 : 0 : *fdirctrl |= (IXGBE_FDIRCTRL_FILTERMODE_MACVLAN
218 : : << IXGBE_FDIRCTRL_FILTERMODE_SHIFT);
219 [ # # ]: 0 : else if (conf->mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
220 : 0 : *fdirctrl |= (IXGBE_FDIRCTRL_FILTERMODE_CLOUD
221 : : << IXGBE_FDIRCTRL_FILTERMODE_SHIFT);
222 : : }
223 : :
224 : : return 0;
225 : : }
226 : :
227 : : /**
228 : : * Reverse the bits in FDIR registers that store 2 x 16 bit masks.
229 : : *
230 : : * @hi_dword: Bits 31:16 mask to be bit swapped.
231 : : * @lo_dword: Bits 15:0 mask to be bit swapped.
232 : : *
233 : : * Flow director uses several registers to store 2 x 16 bit masks with the
234 : : * bits reversed such as FDIRTCPM, FDIRUDPM. The LS bit of the
235 : : * mask affects the MS bit/byte of the target. This function reverses the
236 : : * bits in these masks.
237 : : * **/
238 : : static inline uint32_t
239 : 0 : reverse_fdir_bitmasks(uint16_t hi_dword, uint16_t lo_dword)
240 : : {
241 : 0 : uint32_t mask = hi_dword << 16;
242 : :
243 : 0 : mask |= lo_dword;
244 : 0 : mask = ((mask & 0x55555555) << 1) | ((mask & 0xAAAAAAAA) >> 1);
245 : 0 : mask = ((mask & 0x33333333) << 2) | ((mask & 0xCCCCCCCC) >> 2);
246 : 0 : mask = ((mask & 0x0F0F0F0F) << 4) | ((mask & 0xF0F0F0F0) >> 4);
247 : 0 : return ((mask & 0x00FF00FF) << 8) | ((mask & 0xFF00FF00) >> 8);
248 : : }
249 : :
250 : : /*
251 : : * This references ixgbe_fdir_set_input_mask_82599() in base/ixgbe_82599.c,
252 : : * but makes use of the rte_fdir_masks structure to see which bits to set.
253 : : */
254 : : static int
255 : 0 : fdir_set_input_mask_82599(struct ixgbe_adapter *adapter,
256 : : const struct ixgbe_hw_fdir_mask *mask,
257 : : enum rte_fdir_mode mode)
258 : : {
259 : : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(adapter);
260 : : /*
261 : : * mask VM pool and DIPv6 since there are currently not supported
262 : : * mask FLEX byte, it will be set in flex_conf
263 : : */
264 : : uint32_t fdirm = IXGBE_FDIRM_POOL | IXGBE_FDIRM_DIPv6;
265 : : uint32_t fdirtcpm; /* TCP source and destination port masks. */
266 : : uint32_t fdiripv6m; /* IPv6 source and destination masks. */
267 : : volatile uint32_t *reg;
268 : :
269 : 0 : PMD_INIT_FUNC_TRACE();
270 : :
271 [ # # ]: 0 : if (!mask->l4_proto_match)
272 : : /* set L4P to ignore L4 protocol for IP traffic */
273 : : fdirm |= IXGBE_FDIRM_L4P;
274 : :
275 [ # # ]: 0 : if (mask->vlan_tci_mask == rte_cpu_to_be_16(0x0FFF))
276 : : /* mask VLAN Priority */
277 : 0 : fdirm |= IXGBE_FDIRM_VLANP;
278 [ # # ]: 0 : else if (mask->vlan_tci_mask == rte_cpu_to_be_16(0xE000))
279 : : /* mask VLAN ID */
280 : 0 : fdirm |= IXGBE_FDIRM_VLANID;
281 [ # # ]: 0 : else if (mask->vlan_tci_mask == 0)
282 : : /* mask VLAN ID and Priority */
283 : 0 : fdirm |= IXGBE_FDIRM_VLANID | IXGBE_FDIRM_VLANP;
284 [ # # ]: 0 : else if (mask->vlan_tci_mask != rte_cpu_to_be_16(0xEFFF)) {
285 : 0 : PMD_INIT_LOG(ERR, "invalid vlan_tci_mask");
286 : 0 : return -EINVAL;
287 : : }
288 : :
289 : : /* flex byte mask */
290 [ # # ]: 0 : if (mask->flex_bytes_mask == 0)
291 : 0 : fdirm |= IXGBE_FDIRM_FLEX;
292 : :
293 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRM, fdirm);
294 : :
295 : : /* store the TCP/UDP port masks, bit reversed from port layout */
296 : 0 : fdirtcpm = reverse_fdir_bitmasks(
297 [ # # ]: 0 : rte_be_to_cpu_16(mask->dst_port_mask),
298 [ # # ]: 0 : rte_be_to_cpu_16(mask->src_port_mask));
299 : :
300 : : /* write all the same so that UDP, TCP and SCTP use the same mask
301 : : * (little-endian)
302 : : */
303 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM, ~fdirtcpm);
304 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM, ~fdirtcpm);
305 : : /* only certain MAC types have SCTP masking register */
306 : 0 : if (hw->mac.type == ixgbe_mac_X550 ||
307 : : hw->mac.type == ixgbe_mac_X550EM_x ||
308 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_a ||
309 : : hw->mac.type == ixgbe_mac_E610)
310 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSCTPM, ~fdirtcpm);
311 : :
312 : : /* Store source and destination IPv4 masks (big-endian),
313 : : * can not use IXGBE_WRITE_REG.
314 : : */
315 : 0 : reg = IXGBE_PCI_REG_ADDR(hw, IXGBE_FDIRSIP4M);
316 : 0 : *reg = ~(mask->src_ipv4_mask);
317 : : reg = IXGBE_PCI_REG_ADDR(hw, IXGBE_FDIRDIP4M);
318 : 0 : *reg = ~(mask->dst_ipv4_mask);
319 : :
320 [ # # ]: 0 : if (mode == RTE_FDIR_MODE_SIGNATURE) {
321 : : /*
322 : : * Store source and destination IPv6 masks (bit reversed)
323 : : */
324 : 0 : fdiripv6m = (mask->dst_ipv6_mask << 16) |
325 : 0 : mask->src_ipv6_mask;
326 : :
327 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRIP6M, ~fdiripv6m);
328 : : }
329 : :
330 : : return IXGBE_SUCCESS;
331 : : }
332 : :
333 : : /*
334 : : * This references ixgbe_fdir_set_input_mask_82599() in base/ixgbe_82599.c,
335 : : * but makes use of the rte_fdir_masks structure to see which bits to set.
336 : : */
337 : : static int
338 : 0 : fdir_set_input_mask_x550(struct ixgbe_adapter *adapter,
339 : : const struct ixgbe_hw_fdir_mask *mask,
340 : : enum rte_fdir_mode mode)
341 : : {
342 : : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(adapter);
343 : : /* mask VM pool and DIPv6 since there are currently not supported
344 : : * mask FLEX byte, it will be set in flex_conf
345 : : */
346 : : uint32_t fdirm = IXGBE_FDIRM_POOL | IXGBE_FDIRM_DIPv6 |
347 : : IXGBE_FDIRM_FLEX;
348 : : uint32_t fdiripv6m;
349 : : uint16_t mac_mask;
350 : :
351 : 0 : PMD_INIT_FUNC_TRACE();
352 : :
353 : : /* set the default UDP port for VxLAN */
354 [ # # ]: 0 : if (mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
355 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, RTE_VXLAN_DEFAULT_PORT);
356 : :
357 : : /* some bits must be set for mac vlan or tunnel mode */
358 : : fdirm |= IXGBE_FDIRM_L4P | IXGBE_FDIRM_L3P;
359 : :
360 [ # # ]: 0 : if (mask->vlan_tci_mask == rte_cpu_to_be_16(0x0FFF))
361 : : /* mask VLAN Priority */
362 : : fdirm |= IXGBE_FDIRM_VLANP;
363 [ # # ]: 0 : else if (mask->vlan_tci_mask == rte_cpu_to_be_16(0xE000))
364 : : /* mask VLAN ID */
365 : : fdirm |= IXGBE_FDIRM_VLANID;
366 [ # # ]: 0 : else if (mask->vlan_tci_mask == 0)
367 : : /* mask VLAN ID and Priority */
368 : : fdirm |= IXGBE_FDIRM_VLANID | IXGBE_FDIRM_VLANP;
369 [ # # ]: 0 : else if (mask->vlan_tci_mask != rte_cpu_to_be_16(0xEFFF)) {
370 : 0 : PMD_INIT_LOG(ERR, "invalid vlan_tci_mask");
371 : 0 : return -EINVAL;
372 : : }
373 : :
374 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRM, fdirm);
375 : :
376 : : fdiripv6m = ((u32)0xFFFFU << IXGBE_FDIRIP6M_DIPM_SHIFT);
377 : : fdiripv6m |= IXGBE_FDIRIP6M_ALWAYS_MASK;
378 [ # # ]: 0 : if (mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
379 : : fdiripv6m |= IXGBE_FDIRIP6M_TUNNEL_TYPE |
380 : : IXGBE_FDIRIP6M_TNI_VNI;
381 : :
382 [ # # ]: 0 : if (mode == RTE_FDIR_MODE_PERFECT_TUNNEL) {
383 : 0 : fdiripv6m |= IXGBE_FDIRIP6M_INNER_MAC;
384 : 0 : mac_mask = mask->mac_addr_byte_mask &
385 : : (IXGBE_FDIRIP6M_INNER_MAC >>
386 : : IXGBE_FDIRIP6M_INNER_MAC_SHIFT);
387 : 0 : fdiripv6m &= ~((mac_mask << IXGBE_FDIRIP6M_INNER_MAC_SHIFT) &
388 : : IXGBE_FDIRIP6M_INNER_MAC);
389 : :
390 [ # # # ]: 0 : switch (mask->tunnel_type_mask) {
391 : 0 : case 0:
392 : : /* Mask tunnel type */
393 : 0 : fdiripv6m |= IXGBE_FDIRIP6M_TUNNEL_TYPE;
394 : 0 : break;
395 : : case 1:
396 : : break;
397 : 0 : default:
398 : 0 : PMD_INIT_LOG(ERR, "invalid tunnel_type_mask");
399 : 0 : return -EINVAL;
400 : : }
401 : :
402 [ # # # # : 0 : switch (rte_be_to_cpu_32(mask->tunnel_id_mask)) {
# # ]
403 : 0 : case 0x0:
404 : : /* Mask vxlan id */
405 : 0 : fdiripv6m |= IXGBE_FDIRIP6M_TNI_VNI;
406 : 0 : break;
407 : 0 : case 0x00FFFFFF:
408 : 0 : fdiripv6m |= IXGBE_FDIRIP6M_TNI_VNI_24;
409 : 0 : break;
410 : : case 0xFFFFFFFF:
411 : : break;
412 : 0 : default:
413 : 0 : PMD_INIT_LOG(ERR, "invalid tunnel_id_mask");
414 : 0 : return -EINVAL;
415 : : }
416 : : }
417 : :
418 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRIP6M, fdiripv6m);
419 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM, 0xFFFFFFFF);
420 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM, 0xFFFFFFFF);
421 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSCTPM, 0xFFFFFFFF);
422 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRDIP4M, 0xFFFFFFFF);
423 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSIP4M, 0xFFFFFFFF);
424 : :
425 : 0 : return IXGBE_SUCCESS;
426 : : }
427 : :
428 : : int
429 : 0 : ixgbe_fdir_set_input_mask(struct ixgbe_adapter *adapter,
430 : : const struct ixgbe_hw_fdir_mask *mask,
431 : : enum rte_fdir_mode mode)
432 : : {
433 [ # # ]: 0 : if (mode >= RTE_FDIR_MODE_SIGNATURE &&
434 : : mode <= RTE_FDIR_MODE_PERFECT)
435 : 0 : return fdir_set_input_mask_82599(adapter, mask, mode);
436 [ # # ]: 0 : else if (mode >= RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
437 : : mode <= RTE_FDIR_MODE_PERFECT_TUNNEL)
438 : 0 : return fdir_set_input_mask_x550(adapter, mask, mode);
439 : :
440 : 0 : PMD_DRV_LOG(ERR, "Not supported fdir mode - %d!", mode);
441 : 0 : return -ENOTSUP;
442 : : }
443 : :
444 : : int
445 : 0 : ixgbe_fdir_set_flexbytes_offset(struct ixgbe_adapter *adapter, uint16_t offset)
446 : : {
447 : : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(adapter);
448 : : uint32_t fdirctrl;
449 : : int i;
450 : :
451 : : /**
452 : : * 82599 adapters flow director init flow cannot be restarted,
453 : : * Workaround 82599 silicon errata by performing the following steps
454 : : * before re-writing the FDIRCTRL control register with the same value.
455 : : * - write 1 to bit 8 of FDIRCMD register &
456 : : * - write 0 to bit 8 of FDIRCMD register
457 : : */
458 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
459 : : (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) |
460 : : IXGBE_FDIRCMD_CLEARHT));
461 : 0 : IXGBE_WRITE_FLUSH(hw);
462 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
463 : : (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
464 : : ~IXGBE_FDIRCMD_CLEARHT));
465 : 0 : IXGBE_WRITE_FLUSH(hw);
466 : :
467 : 0 : fdirctrl = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL);
468 : :
469 : 0 : fdirctrl &= ~IXGBE_FDIRCTRL_FLEX_MASK;
470 : 0 : fdirctrl |= ((offset >> 1) /* convert to word offset */
471 : 0 : << IXGBE_FDIRCTRL_FLEX_SHIFT);
472 : :
473 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
474 : 0 : IXGBE_WRITE_FLUSH(hw);
475 [ # # ]: 0 : for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
476 [ # # ]: 0 : if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
477 : : IXGBE_FDIRCTRL_INIT_DONE)
478 : : break;
479 : 0 : msec_delay(1);
480 : : }
481 : :
482 [ # # ]: 0 : if (i >= IXGBE_FDIR_INIT_DONE_POLL) {
483 : 0 : PMD_DRV_LOG(ERR, "Flow Director poll time exceeded!");
484 : 0 : return -ETIMEDOUT;
485 : : }
486 : :
487 : : return 0;
488 : : }
489 : :
490 : : /*
491 : : * ixgbe_check_fdir_flex_conf -check if the flex payload and mask configuration
492 : : * arguments are valid
493 : : */
494 : : static int
495 : 0 : ixgbe_set_fdir_flex_conf(struct ixgbe_adapter *adapter,
496 : : const struct rte_eth_fdir_flex_conf *conf, uint32_t *fdirctrl)
497 : : {
498 : : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(adapter);
499 : : struct ixgbe_hw_fdir_info *info =
500 : : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(adapter);
501 : : const struct rte_eth_flex_payload_cfg *flex_cfg;
502 : : const struct rte_eth_fdir_flex_mask *flex_mask;
503 : : uint32_t fdirm;
504 : : uint16_t flexbytes = 0;
505 : : uint16_t i;
506 : :
507 : 0 : fdirm = IXGBE_READ_REG(hw, IXGBE_FDIRM);
508 : :
509 [ # # ]: 0 : if (conf == NULL) {
510 : 0 : PMD_DRV_LOG(ERR, "NULL pointer.");
511 : 0 : return -EINVAL;
512 : : }
513 : :
514 [ # # ]: 0 : for (i = 0; i < conf->nb_payloads; i++) {
515 : 0 : flex_cfg = &conf->flex_set[i];
516 [ # # ]: 0 : if (flex_cfg->type != RTE_ETH_RAW_PAYLOAD) {
517 : 0 : PMD_DRV_LOG(ERR, "unsupported payload type.");
518 : 0 : return -EINVAL;
519 : : }
520 [ # # ]: 0 : if (((flex_cfg->src_offset[0] & 0x1) == 0) &&
521 [ # # # # ]: 0 : (flex_cfg->src_offset[1] == flex_cfg->src_offset[0] + 1) &&
522 : : (flex_cfg->src_offset[0] <= IXGBE_MAX_FLX_SOURCE_OFF)) {
523 : 0 : *fdirctrl &= ~IXGBE_FDIRCTRL_FLEX_MASK;
524 : 0 : *fdirctrl |=
525 : 0 : (flex_cfg->src_offset[0] / sizeof(uint16_t)) <<
526 : : IXGBE_FDIRCTRL_FLEX_SHIFT;
527 : : } else {
528 : 0 : PMD_DRV_LOG(ERR, "invalid flexbytes arguments.");
529 : 0 : return -EINVAL;
530 : : }
531 : : }
532 : :
533 [ # # ]: 0 : for (i = 0; i < conf->nb_flexmasks; i++) {
534 : 0 : flex_mask = &conf->flex_mask[i];
535 [ # # ]: 0 : if (flex_mask->flow_type != RTE_ETH_FLOW_UNKNOWN) {
536 : 0 : PMD_DRV_LOG(ERR, "flexmask should be set globally.");
537 : 0 : return -EINVAL;
538 : : }
539 : 0 : flexbytes = (uint16_t)(((flex_mask->mask[0] << 8) & 0xFF00) |
540 : 0 : ((flex_mask->mask[1]) & 0xFF));
541 [ # # ]: 0 : if (flexbytes == UINT16_MAX)
542 : 0 : fdirm &= ~IXGBE_FDIRM_FLEX;
543 [ # # ]: 0 : else if (flexbytes != 0) {
544 : : /* IXGBE_FDIRM_FLEX is set by default when set mask */
545 : 0 : PMD_DRV_LOG(ERR, " invalid flexbytes mask arguments.");
546 : 0 : return -EINVAL;
547 : : }
548 : : }
549 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRM, fdirm);
550 [ # # ]: 0 : info->mask.flex_bytes_mask = flexbytes ? UINT16_MAX : 0;
551 : 0 : info->flex_bytes_offset = (uint8_t)((*fdirctrl &
552 : 0 : IXGBE_FDIRCTRL_FLEX_MASK) >>
553 : : IXGBE_FDIRCTRL_FLEX_SHIFT);
554 : 0 : return 0;
555 : : }
556 : :
557 : : int
558 : 0 : ixgbe_fdir_configure(struct ixgbe_adapter *adapter,
559 : : const struct rte_eth_fdir_conf *fdir_conf,
560 : : const struct ixgbe_hw_fdir_mask *fdir_mask)
561 : : {
562 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(adapter);
563 : : int err;
564 : : uint32_t fdirctrl, pbsize;
565 : : int i;
566 : 0 : enum rte_fdir_mode mode = fdir_conf->mode;
567 : :
568 : 0 : PMD_INIT_FUNC_TRACE();
569 : :
570 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82599EB &&
571 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X540 &&
572 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550 &&
573 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_x &&
574 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_a &&
575 : : hw->mac.type != ixgbe_mac_E610)
576 : : return -ENOSYS;
577 : :
578 : : /* x550 and E610 supports mac-vlan and tunnel mode but other NICs not */
579 : 0 : if (hw->mac.type != ixgbe_mac_X550 &&
580 : : hw->mac.type != ixgbe_mac_X550EM_x &&
581 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_a &&
582 : : hw->mac.type != ixgbe_mac_E610 &&
583 [ # # ]: 0 : mode != RTE_FDIR_MODE_SIGNATURE &&
584 : : mode != RTE_FDIR_MODE_PERFECT)
585 : : return -ENOSYS;
586 : :
587 : 0 : err = configure_fdir_flags(fdir_conf, &fdirctrl);
588 [ # # ]: 0 : if (err)
589 : : return err;
590 : :
591 : : /*
592 : : * Before enabling Flow Director, the Rx Packet Buffer size
593 : : * must be reduced. The new value is the current size minus
594 : : * flow director memory usage size.
595 : : */
596 : 0 : pbsize = (1 << (PBALLOC_SIZE_SHIFT + (fdirctrl & FDIRCTRL_PBALLOC_MASK)));
597 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0),
598 : : (IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) - pbsize));
599 : :
600 : : /*
601 : : * The defaults in the HW for RX PB 1-7 are not zero and so should be
602 : : * initialized to zero for non DCB mode otherwise actual total RX PB
603 : : * would be bigger than programmed and filter space would run into
604 : : * the PB 0 region.
605 : : */
606 [ # # ]: 0 : for (i = 1; i < 8; i++)
607 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
608 : :
609 : 0 : err = ixgbe_fdir_set_input_mask(adapter, fdir_mask, mode);
610 [ # # ]: 0 : if (err < 0) {
611 : 0 : PMD_INIT_LOG(ERR, " Error on setting FD mask");
612 : 0 : return err;
613 : : }
614 : 0 : err = ixgbe_set_fdir_flex_conf(adapter, &fdir_conf->flex_conf,
615 : : &fdirctrl);
616 [ # # ]: 0 : if (err < 0) {
617 : 0 : PMD_INIT_LOG(ERR, " Error on setting FD flexible arguments.");
618 : 0 : return err;
619 : : }
620 : :
621 : 0 : err = fdir_enable_82599(hw, fdirctrl);
622 [ # # ]: 0 : if (err < 0) {
623 : 0 : PMD_INIT_LOG(ERR, " Error on enabling FD.");
624 : 0 : return err;
625 : : }
626 : : return 0;
627 : : }
628 : :
629 : : /*
630 : : * The below function is taken from the FreeBSD IXGBE drivers release
631 : : * 2.3.8. The only change is not to mask hash_result with IXGBE_ATR_HASH_MASK
632 : : * before returning, as the signature hash can use 16bits.
633 : : *
634 : : * The newer driver has optimised functions for calculating bucket and
635 : : * signature hashes. However they don't support IPv6 type packets for signature
636 : : * filters so are not used here.
637 : : *
638 : : * Note that the bkt_hash field in the ixgbe_atr_input structure is also never
639 : : * set.
640 : : *
641 : : * Compute the hashes for SW ATR
642 : : * @stream: input bitstream to compute the hash on
643 : : * @key: 32-bit hash key
644 : : **/
645 : : static uint32_t
646 : 0 : ixgbe_atr_compute_hash_82599(union ixgbe_atr_input *atr_input,
647 : : uint32_t key)
648 : : {
649 : : /*
650 : : * The algorithm is as follows:
651 : : * Hash[15:0] = Sum { S[n] x K[n+16] }, n = 0...350
652 : : * where Sum {A[n]}, n = 0...n is bitwise XOR of A[0], A[1]...A[n]
653 : : * and A[n] x B[n] is bitwise AND between same length strings
654 : : *
655 : : * K[n] is 16 bits, defined as:
656 : : * for n modulo 32 >= 15, K[n] = K[n % 32 : (n % 32) - 15]
657 : : * for n modulo 32 < 15, K[n] =
658 : : * K[(n % 32:0) | (31:31 - (14 - (n % 32)))]
659 : : *
660 : : * S[n] is 16 bits, defined as:
661 : : * for n >= 15, S[n] = S[n:n - 15]
662 : : * for n < 15, S[n] = S[(n:0) | (350:350 - (14 - n))]
663 : : *
664 : : * To simplify for programming, the algorithm is implemented
665 : : * in software this way:
666 : : *
667 : : * key[31:0], hi_hash_dword[31:0], lo_hash_dword[31:0], hash[15:0]
668 : : *
669 : : * for (i = 0; i < 352; i+=32)
670 : : * hi_hash_dword[31:0] ^= Stream[(i+31):i];
671 : : *
672 : : * lo_hash_dword[15:0] ^= Stream[15:0];
673 : : * lo_hash_dword[15:0] ^= hi_hash_dword[31:16];
674 : : * lo_hash_dword[31:16] ^= hi_hash_dword[15:0];
675 : : *
676 : : * hi_hash_dword[31:0] ^= Stream[351:320];
677 : : *
678 : : * if (key[0])
679 : : * hash[15:0] ^= Stream[15:0];
680 : : *
681 : : * for (i = 0; i < 16; i++) {
682 : : * if (key[i])
683 : : * hash[15:0] ^= lo_hash_dword[(i+15):i];
684 : : * if (key[i + 16])
685 : : * hash[15:0] ^= hi_hash_dword[(i+15):i];
686 : : * }
687 : : *
688 : : */
689 : : __be32 common_hash_dword = 0;
690 : : u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan;
691 : : u32 hash_result = 0;
692 : : u8 i;
693 : :
694 : : /* record the flow_vm_vlan bits as they are a key part to the hash */
695 [ # # ]: 0 : flow_vm_vlan = IXGBE_NTOHL(atr_input->dword_stream[0]);
696 : :
697 : : /* generate common hash dword */
698 [ # # ]: 0 : for (i = 1; i <= 13; i++)
699 : 0 : common_hash_dword ^= atr_input->dword_stream[i];
700 : :
701 [ # # ]: 0 : hi_hash_dword = IXGBE_NTOHL(common_hash_dword);
702 : :
703 : : /* low dword is word swapped version of common */
704 : 0 : lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16);
705 : :
706 : : /* apply flow ID/VM pool/VLAN ID bits to hash words */
707 : 0 : hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16);
708 : :
709 : : /* Process bits 0 and 16 */
710 [ # # ]: 0 : if (key & 0x0001)
711 : : hash_result ^= lo_hash_dword;
712 [ # # ]: 0 : if (key & 0x00010000)
713 : 0 : hash_result ^= hi_hash_dword;
714 : :
715 : : /*
716 : : * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to
717 : : * delay this because bit 0 of the stream should not be processed
718 : : * so we do not add the vlan until after bit 0 was processed
719 : : */
720 : 0 : lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16);
721 : :
722 : :
723 : : /* process the remaining 30 bits in the key 2 bits at a time */
724 [ # # ]: 0 : for (i = 15; i; i--) {
725 [ # # ]: 0 : if (key & (0x0001 << i))
726 : 0 : hash_result ^= lo_hash_dword >> i;
727 [ # # ]: 0 : if (key & (0x00010000 << i))
728 : 0 : hash_result ^= hi_hash_dword >> i;
729 : : }
730 : :
731 : 0 : return hash_result;
732 : : }
733 : :
734 : : static uint32_t
735 : 0 : atr_compute_perfect_hash_82599(union ixgbe_atr_input *input,
736 : : enum rte_eth_fdir_pballoc_type pballoc)
737 : : {
738 [ # # ]: 0 : if (pballoc == RTE_ETH_FDIR_PBALLOC_256K)
739 : 0 : return ixgbe_atr_compute_hash_82599(input,
740 : 0 : IXGBE_ATR_BUCKET_HASH_KEY) &
741 : : PERFECT_BUCKET_256KB_HASH_MASK;
742 [ # # ]: 0 : else if (pballoc == RTE_ETH_FDIR_PBALLOC_128K)
743 : 0 : return ixgbe_atr_compute_hash_82599(input,
744 : 0 : IXGBE_ATR_BUCKET_HASH_KEY) &
745 : : PERFECT_BUCKET_128KB_HASH_MASK;
746 : : else
747 : 0 : return ixgbe_atr_compute_hash_82599(input,
748 : 0 : IXGBE_ATR_BUCKET_HASH_KEY) &
749 : : PERFECT_BUCKET_64KB_HASH_MASK;
750 : : }
751 : :
752 : : /**
753 : : * ixgbe_fdir_check_cmd_complete - poll to check whether FDIRCMD is complete
754 : : * @hw: pointer to hardware structure
755 : : */
756 : : static inline int
757 : : ixgbe_fdir_check_cmd_complete(struct ixgbe_hw *hw, uint32_t *fdircmd)
758 : : {
759 : : int i;
760 : :
761 [ # # # # : 0 : for (i = 0; i < IXGBE_FDIRCMD_CMD_POLL; i++) {
# # # # ]
762 : 0 : *fdircmd = IXGBE_READ_REG(hw, IXGBE_FDIRCMD);
763 [ # # # # : 0 : if (!(*fdircmd & IXGBE_FDIRCMD_CMD_MASK))
# # # # ]
764 : : return 0;
765 : 0 : rte_delay_us(IXGBE_FDIRCMD_CMD_INTERVAL_US);
766 : : }
767 : :
768 : : return -ETIMEDOUT;
769 : : }
770 : :
771 : : /*
772 : : * Calculate the hash value needed for signature-match filters. In the FreeBSD
773 : : * driver, this is done by the optimised function
774 : : * ixgbe_atr_compute_sig_hash_82599(). However that can't be used here as it
775 : : * doesn't support calculating a hash for an IPv6 filter.
776 : : */
777 : : static uint32_t
778 : 0 : atr_compute_sig_hash_82599(union ixgbe_atr_input *input,
779 : : enum rte_eth_fdir_pballoc_type pballoc)
780 : : {
781 : : uint32_t bucket_hash, sig_hash;
782 : :
783 [ # # ]: 0 : if (pballoc == RTE_ETH_FDIR_PBALLOC_256K)
784 : 0 : bucket_hash = ixgbe_atr_compute_hash_82599(input,
785 : : IXGBE_ATR_BUCKET_HASH_KEY) &
786 : : SIG_BUCKET_256KB_HASH_MASK;
787 [ # # ]: 0 : else if (pballoc == RTE_ETH_FDIR_PBALLOC_128K)
788 : 0 : bucket_hash = ixgbe_atr_compute_hash_82599(input,
789 : : IXGBE_ATR_BUCKET_HASH_KEY) &
790 : : SIG_BUCKET_128KB_HASH_MASK;
791 : : else
792 : 0 : bucket_hash = ixgbe_atr_compute_hash_82599(input,
793 : : IXGBE_ATR_BUCKET_HASH_KEY) &
794 : : SIG_BUCKET_64KB_HASH_MASK;
795 : :
796 : 0 : sig_hash = ixgbe_atr_compute_hash_82599(input,
797 : : IXGBE_ATR_SIGNATURE_HASH_KEY);
798 : :
799 : 0 : return (sig_hash << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT) | bucket_hash;
800 : : }
801 : :
802 : : /*
803 : : * This is based on ixgbe_fdir_write_perfect_filter_82599() in
804 : : * base/ixgbe_82599.c, with the ability to set extra flags in FDIRCMD register
805 : : * added, and IPv6 support also added. The hash value is also pre-calculated
806 : : * as the pballoc value is needed to do it.
807 : : */
808 : : static int
809 : 0 : fdir_write_perfect_filter_82599(struct ixgbe_hw *hw,
810 : : union ixgbe_atr_input *input, uint8_t queue,
811 : : uint32_t fdircmd, uint32_t fdirhash,
812 : : enum rte_fdir_mode mode)
813 : : {
814 : : uint32_t fdirport, fdirvlan;
815 : : u32 addr_low, addr_high;
816 : : u32 tunnel_type = 0;
817 : : int err = 0;
818 : : volatile uint32_t *reg;
819 : :
820 [ # # ]: 0 : if (mode == RTE_FDIR_MODE_PERFECT) {
821 : : /* record the IPv4 address (big-endian)
822 : : * can not use IXGBE_WRITE_REG.
823 : : */
824 : 0 : reg = IXGBE_PCI_REG_ADDR(hw, IXGBE_FDIRIPSA);
825 : 0 : *reg = input->formatted.src_ip[0];
826 : : reg = IXGBE_PCI_REG_ADDR(hw, IXGBE_FDIRIPDA);
827 : 0 : *reg = input->formatted.dst_ip[0];
828 : :
829 : : /* record source and destination port (little-endian)*/
830 [ # # ]: 0 : fdirport = IXGBE_NTOHS(input->formatted.dst_port);
831 : 0 : fdirport <<= IXGBE_FDIRPORT_DESTINATION_SHIFT;
832 [ # # ]: 0 : fdirport |= IXGBE_NTOHS(input->formatted.src_port);
833 : : IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, fdirport);
834 [ # # ]: 0 : } else if (mode >= RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
835 : : mode <= RTE_FDIR_MODE_PERFECT_TUNNEL) {
836 : : /* for mac vlan and tunnel modes */
837 : 0 : addr_low = ((u32)input->formatted.inner_mac[0] |
838 : 0 : ((u32)input->formatted.inner_mac[1] << 8) |
839 : 0 : ((u32)input->formatted.inner_mac[2] << 16) |
840 : 0 : ((u32)input->formatted.inner_mac[3] << 24));
841 : 0 : addr_high = ((u32)input->formatted.inner_mac[4] |
842 : 0 : ((u32)input->formatted.inner_mac[5] << 8));
843 : :
844 [ # # ]: 0 : if (mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
845 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(0), addr_low);
846 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(1), addr_high);
847 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(2), 0);
848 : : } else {
849 : : /* tunnel mode */
850 [ # # ]: 0 : if (input->formatted.tunnel_type)
851 : : tunnel_type = 0x80000000;
852 : 0 : tunnel_type |= addr_high;
853 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(0), addr_low);
854 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(1), tunnel_type);
855 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(2),
856 : : input->formatted.tni_vni);
857 : : }
858 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRIPSA, 0);
859 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRIPDA, 0);
860 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, 0);
861 : : }
862 : :
863 : : /* record vlan (little-endian) and flex_bytes(big-endian) */
864 : 0 : fdirvlan = input->formatted.flex_bytes;
865 : 0 : fdirvlan <<= IXGBE_FDIRVLAN_FLEX_SHIFT;
866 [ # # ]: 0 : fdirvlan |= IXGBE_NTOHS(input->formatted.vlan_id);
867 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRVLAN, fdirvlan);
868 : :
869 : : /* configure FDIRHASH register */
870 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
871 : :
872 : : /*
873 : : * flush all previous writes to make certain registers are
874 : : * programmed prior to issuing the command
875 : : */
876 : 0 : IXGBE_WRITE_FLUSH(hw);
877 : :
878 : : /* configure FDIRCMD register */
879 : 0 : fdircmd |= IXGBE_FDIRCMD_CMD_ADD_FLOW |
880 : : IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN;
881 : 0 : fdircmd |= input->formatted.flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT;
882 : 0 : fdircmd |= (uint32_t)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
883 : 0 : fdircmd |= (uint32_t)input->formatted.vm_pool << IXGBE_FDIRCMD_VT_POOL_SHIFT;
884 : :
885 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, fdircmd);
886 : :
887 : 0 : PMD_DRV_LOG(DEBUG, "Rx Queue=%x hash=%x", queue, fdirhash);
888 : :
889 : : err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
890 [ # # ]: 0 : if (err < 0)
891 : 0 : PMD_DRV_LOG(ERR, "Timeout writing flow director filter.");
892 : :
893 : 0 : return err;
894 : : }
895 : :
896 : : /**
897 : : * This function is based on ixgbe_atr_add_signature_filter_82599() in
898 : : * base/ixgbe_82599.c, but uses a pre-calculated hash value. It also supports
899 : : * setting extra fields in the FDIRCMD register, and removes the code that was
900 : : * verifying the flow_type field. According to the documentation, a flow type of
901 : : * 00 (i.e. not TCP, UDP, or SCTP) is not supported, however it appears to
902 : : * work ok...
903 : : *
904 : : * Adds a signature hash filter
905 : : * @hw: pointer to hardware structure
906 : : * @input: unique input dword
907 : : * @queue: queue index to direct traffic to
908 : : * @fdircmd: any extra flags to set in fdircmd register
909 : : * @fdirhash: pre-calculated hash value for the filter
910 : : **/
911 : : static int
912 : 0 : fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
913 : : union ixgbe_atr_input *input, u8 queue, uint32_t fdircmd,
914 : : uint32_t fdirhash)
915 : : {
916 : : int err = 0;
917 : :
918 : 0 : PMD_INIT_FUNC_TRACE();
919 : :
920 : : /* configure FDIRCMD register */
921 : 0 : fdircmd |= IXGBE_FDIRCMD_CMD_ADD_FLOW |
922 : : IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN;
923 : 0 : fdircmd |= input->formatted.flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT;
924 : 0 : fdircmd |= (uint32_t)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
925 : :
926 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
927 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, fdircmd);
928 : :
929 : 0 : PMD_DRV_LOG(DEBUG, "Rx Queue=%x hash=%x", queue, fdirhash);
930 : :
931 : : err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
932 [ # # ]: 0 : if (err < 0)
933 : 0 : PMD_DRV_LOG(ERR, "Timeout writing flow director filter.");
934 : :
935 : 0 : return err;
936 : : }
937 : :
938 : : /*
939 : : * This is based on ixgbe_fdir_erase_perfect_filter_82599() in
940 : : * base/ixgbe_82599.c. It is modified to take in the hash as a parameter so
941 : : * that it can be used for removing signature and perfect filters.
942 : : */
943 : : static int
944 : 0 : fdir_erase_filter_82599(struct ixgbe_hw *hw, uint32_t fdirhash)
945 : : {
946 : : uint32_t fdircmd = 0;
947 : : int err = 0;
948 : :
949 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
950 : :
951 : : /* flush hash to HW */
952 : 0 : IXGBE_WRITE_FLUSH(hw);
953 : :
954 : : /* Query if filter is present */
955 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, IXGBE_FDIRCMD_CMD_QUERY_REM_FILT);
956 : :
957 : : err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
958 [ # # ]: 0 : if (err < 0) {
959 : 0 : PMD_INIT_LOG(ERR, "Timeout querying for flow director filter.");
960 : 0 : return err;
961 : : }
962 : :
963 : : /* if filter exists in hardware then remove it */
964 [ # # ]: 0 : if (fdircmd & IXGBE_FDIRCMD_FILTER_VALID) {
965 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
966 : 0 : IXGBE_WRITE_FLUSH(hw);
967 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
968 : : IXGBE_FDIRCMD_CMD_REMOVE_FLOW);
969 : : }
970 : : err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
971 [ # # ]: 0 : if (err < 0)
972 : 0 : PMD_INIT_LOG(ERR, "Timeout erasing flow director filter.");
973 : : return err;
974 : :
975 : : }
976 : :
977 : : static inline struct ixgbe_fdir_filter *
978 : : ixgbe_fdir_filter_lookup(struct ixgbe_hw_fdir_info *fdir_info,
979 : : union ixgbe_atr_input *key)
980 : : {
981 : : int ret;
982 : :
983 : 0 : ret = rte_hash_lookup(fdir_info->hash_handle, (const void *)key);
984 [ # # ]: 0 : if (ret < 0)
985 : : return NULL;
986 : :
987 : 0 : return fdir_info->hash_map[ret];
988 : : }
989 : :
990 : : static inline int
991 : 0 : ixgbe_insert_fdir_filter(struct ixgbe_hw_fdir_info *fdir_info,
992 : : struct ixgbe_fdir_filter *fdir_filter)
993 : : {
994 : : int ret;
995 : :
996 : 0 : ret = rte_hash_add_key(fdir_info->hash_handle,
997 : 0 : &fdir_filter->ixgbe_fdir);
998 : :
999 [ # # ]: 0 : if (ret < 0) {
1000 : 0 : PMD_DRV_LOG(ERR,
1001 : : "Failed to insert fdir filter to hash table %d!",
1002 : : ret);
1003 : 0 : return ret;
1004 : : }
1005 : :
1006 : 0 : fdir_info->hash_map[ret] = fdir_filter;
1007 : :
1008 : 0 : TAILQ_INSERT_TAIL(&fdir_info->fdir_list, fdir_filter, entries);
1009 : :
1010 : 0 : return 0;
1011 : : }
1012 : :
1013 : : static inline int
1014 : 0 : ixgbe_remove_fdir_filter(struct ixgbe_hw_fdir_info *fdir_info,
1015 : : union ixgbe_atr_input *key)
1016 : : {
1017 : : int ret;
1018 : : struct ixgbe_fdir_filter *fdir_filter;
1019 : :
1020 : 0 : ret = rte_hash_del_key(fdir_info->hash_handle, key);
1021 : :
1022 [ # # ]: 0 : if (ret < 0) {
1023 : 0 : PMD_DRV_LOG(ERR, "No such fdir filter to delete %d!", ret);
1024 : 0 : return ret;
1025 : : }
1026 : :
1027 : 0 : fdir_filter = fdir_info->hash_map[ret];
1028 : 0 : fdir_info->hash_map[ret] = NULL;
1029 : :
1030 [ # # ]: 0 : TAILQ_REMOVE(&fdir_info->fdir_list, fdir_filter, entries);
1031 : 0 : rte_free(fdir_filter);
1032 : :
1033 : 0 : return 0;
1034 : : }
1035 : :
1036 : : int
1037 : 0 : ixgbe_fdir_filter_program(struct ixgbe_adapter *adapter,
1038 : : struct rte_eth_fdir_conf *fdir_conf,
1039 : : struct ixgbe_fdir_rule *rule,
1040 : : bool del,
1041 : : bool update)
1042 : : {
1043 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(adapter);
1044 : : uint32_t fdircmd_flags;
1045 : : uint32_t fdirhash;
1046 : : uint8_t queue;
1047 : : bool is_perfect = FALSE;
1048 : : int err;
1049 : 0 : struct ixgbe_hw_fdir_info *info =
1050 : : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(adapter);
1051 : 0 : enum rte_fdir_mode fdir_mode = fdir_conf->mode;
1052 : : struct ixgbe_fdir_filter *node;
1053 : : bool add_node = FALSE;
1054 : :
1055 [ # # ]: 0 : if (fdir_mode == RTE_FDIR_MODE_NONE ||
1056 [ # # ]: 0 : fdir_mode != rule->mode)
1057 : : return -ENOTSUP;
1058 : :
1059 : : /*
1060 : : * Sanity check for x550 and E610.
1061 : : * When adding a new filter with flow type set to IPv4,
1062 : : * the flow director mask should be configed before,
1063 : : * and the L4 protocol and ports are masked.
1064 : : */
1065 [ # # ]: 0 : if ((!del) &&
1066 : 0 : (hw->mac.type == ixgbe_mac_X550 ||
1067 : : hw->mac.type == ixgbe_mac_X550EM_x ||
1068 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_a ||
1069 : 0 : hw->mac.type == ixgbe_mac_E610) &&
1070 : 0 : (rule->ixgbe_fdir.formatted.flow_type ==
1071 [ # # ]: 0 : IXGBE_ATR_FLOW_TYPE_IPV4 ||
1072 : : rule->ixgbe_fdir.formatted.flow_type ==
1073 : 0 : IXGBE_ATR_FLOW_TYPE_IPV6) &&
1074 [ # # ]: 0 : (info->mask.src_port_mask != 0 ||
1075 : 0 : info->mask.dst_port_mask != 0) &&
1076 [ # # ]: 0 : (rule->mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
1077 : : rule->mode != RTE_FDIR_MODE_PERFECT_TUNNEL)) {
1078 : 0 : PMD_DRV_LOG(ERR, "By this device,"
1079 : : " IPv4 is not supported without"
1080 : : " L4 protocol and ports masked!");
1081 : 0 : return -ENOTSUP;
1082 : : }
1083 : :
1084 [ # # ]: 0 : if (fdir_mode >= RTE_FDIR_MODE_PERFECT &&
1085 : : fdir_mode <= RTE_FDIR_MODE_PERFECT_TUNNEL)
1086 : : is_perfect = TRUE;
1087 : :
1088 : : if (is_perfect) {
1089 [ # # ]: 0 : if (rule->ixgbe_fdir.formatted.flow_type &
1090 : : IXGBE_ATR_L4TYPE_IPV6_MASK) {
1091 : 0 : PMD_DRV_LOG(ERR, "IPv6 is not supported in"
1092 : : " perfect mode!");
1093 : 0 : return -ENOTSUP;
1094 : : }
1095 : 0 : fdirhash = atr_compute_perfect_hash_82599(&rule->ixgbe_fdir,
1096 : : fdir_conf->pballoc);
1097 : 0 : fdirhash |= rule->soft_id <<
1098 : : IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT;
1099 : : } else
1100 : 0 : fdirhash = atr_compute_sig_hash_82599(&rule->ixgbe_fdir,
1101 : : fdir_conf->pballoc);
1102 : :
1103 [ # # ]: 0 : if (del) {
1104 : 0 : err = ixgbe_remove_fdir_filter(info, &rule->ixgbe_fdir);
1105 [ # # ]: 0 : if (err < 0)
1106 : : return err;
1107 : :
1108 : 0 : err = fdir_erase_filter_82599(hw, fdirhash);
1109 [ # # ]: 0 : if (err < 0)
1110 : 0 : PMD_DRV_LOG(ERR, "Fail to delete FDIR filter!");
1111 : : else
1112 : 0 : PMD_DRV_LOG(DEBUG, "Success to delete FDIR filter!");
1113 : 0 : return err;
1114 : : }
1115 : : /* add or update an fdir filter*/
1116 [ # # ]: 0 : fdircmd_flags = (update) ? IXGBE_FDIRCMD_FILTER_UPDATE : 0;
1117 [ # # ]: 0 : if (rule->fdirflags & IXGBE_FDIRCMD_DROP) {
1118 [ # # ]: 0 : if (is_perfect) {
1119 : 0 : queue = fdir_conf->drop_queue;
1120 : 0 : fdircmd_flags |= IXGBE_FDIRCMD_DROP;
1121 : : } else {
1122 : 0 : PMD_DRV_LOG(ERR, "Drop option is not supported in"
1123 : : " signature mode.");
1124 : 0 : return -EINVAL;
1125 : : }
1126 [ # # ]: 0 : } else if (rule->queue < IXGBE_MAX_RX_QUEUE_NUM)
1127 : : queue = (uint8_t)rule->queue;
1128 : : else
1129 : : return -EINVAL;
1130 : :
1131 : 0 : node = ixgbe_fdir_filter_lookup(info, &rule->ixgbe_fdir);
1132 [ # # ]: 0 : if (node) {
1133 [ # # ]: 0 : if (update) {
1134 : 0 : node->fdirflags = fdircmd_flags;
1135 : 0 : node->fdirhash = fdirhash;
1136 : 0 : node->queue = queue;
1137 : : } else {
1138 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing fdir filter!");
1139 : 0 : return -EINVAL;
1140 : : }
1141 : : } else {
1142 : : add_node = TRUE;
1143 : 0 : node = rte_zmalloc("ixgbe_fdir",
1144 : : sizeof(struct ixgbe_fdir_filter),
1145 : : 0);
1146 [ # # ]: 0 : if (!node)
1147 : : return -ENOMEM;
1148 : 0 : memcpy(&node->ixgbe_fdir,
1149 : : &rule->ixgbe_fdir,
1150 : : sizeof(union ixgbe_atr_input));
1151 : 0 : node->fdirflags = fdircmd_flags;
1152 : 0 : node->fdirhash = fdirhash;
1153 : 0 : node->queue = queue;
1154 : :
1155 : 0 : err = ixgbe_insert_fdir_filter(info, node);
1156 [ # # ]: 0 : if (err < 0) {
1157 : 0 : rte_free(node);
1158 : 0 : return err;
1159 : : }
1160 : : }
1161 : :
1162 [ # # ]: 0 : if (is_perfect) {
1163 : 0 : err = fdir_write_perfect_filter_82599(hw, &rule->ixgbe_fdir,
1164 : : queue, fdircmd_flags,
1165 : : fdirhash, fdir_mode);
1166 : : } else {
1167 : 0 : err = fdir_add_signature_filter_82599(hw, &rule->ixgbe_fdir,
1168 : : queue, fdircmd_flags,
1169 : : fdirhash);
1170 : : }
1171 [ # # ]: 0 : if (err < 0) {
1172 : 0 : PMD_DRV_LOG(ERR, "Fail to add FDIR filter!");
1173 : :
1174 [ # # ]: 0 : if (add_node)
1175 : 0 : (void)ixgbe_remove_fdir_filter(info, &rule->ixgbe_fdir);
1176 : : } else {
1177 : 0 : PMD_DRV_LOG(DEBUG, "Success to add FDIR filter");
1178 : : }
1179 : :
1180 : : return err;
1181 : : }
1182 : :
1183 : : static int
1184 : 0 : ixgbe_fdir_flush(struct rte_eth_dev *dev)
1185 : : {
1186 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1187 : : struct ixgbe_hw_fdir_info *info =
1188 : : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
1189 : : int ret;
1190 : :
1191 : 0 : ret = ixgbe_reinit_fdir_tables_82599(hw);
1192 [ # # ]: 0 : if (ret < 0) {
1193 : 0 : PMD_INIT_LOG(ERR, "Failed to re-initialize FD table.");
1194 : 0 : return ret;
1195 : : }
1196 : :
1197 : 0 : info->f_add = 0;
1198 : 0 : info->f_remove = 0;
1199 : 0 : info->add = 0;
1200 : 0 : info->remove = 0;
1201 : :
1202 : 0 : return ret;
1203 : : }
1204 : :
1205 : : #define FDIRENTRIES_NUM_SHIFT 10
1206 : : void
1207 : 0 : ixgbe_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
1208 : : {
1209 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1210 : : struct rte_eth_fdir_conf *fdir_conf = IXGBE_DEV_FDIR_CONF(dev);
1211 : : struct ixgbe_hw_fdir_info *info =
1212 : : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
1213 : : uint32_t fdirctrl, max_num;
1214 : : uint8_t offset;
1215 : :
1216 : 0 : fdirctrl = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL);
1217 : 0 : offset = ((fdirctrl & IXGBE_FDIRCTRL_FLEX_MASK) >>
1218 : : IXGBE_FDIRCTRL_FLEX_SHIFT) * sizeof(uint16_t);
1219 : :
1220 : 0 : fdir_info->mode = fdir_conf->mode;
1221 : 0 : max_num = (1 << (FDIRENTRIES_NUM_SHIFT +
1222 : 0 : (fdirctrl & FDIRCTRL_PBALLOC_MASK)));
1223 [ # # ]: 0 : if (fdir_info->mode >= RTE_FDIR_MODE_PERFECT &&
1224 : : fdir_info->mode <= RTE_FDIR_MODE_PERFECT_TUNNEL)
1225 : 0 : fdir_info->guarant_spc = max_num;
1226 [ # # ]: 0 : else if (fdir_info->mode == RTE_FDIR_MODE_SIGNATURE)
1227 : 0 : fdir_info->guarant_spc = max_num * 4;
1228 : :
1229 : 0 : fdir_info->mask.vlan_tci_mask = info->mask.vlan_tci_mask;
1230 : 0 : fdir_info->mask.ipv4_mask.src_ip = info->mask.src_ipv4_mask;
1231 : 0 : fdir_info->mask.ipv4_mask.dst_ip = info->mask.dst_ipv4_mask;
1232 [ # # # # ]: 0 : IPV6_MASK_TO_ADDR(info->mask.src_ipv6_mask,
1233 : : fdir_info->mask.ipv6_mask.src_ip);
1234 [ # # # # : 0 : IPV6_MASK_TO_ADDR(info->mask.dst_ipv6_mask,
# # ]
1235 : : fdir_info->mask.ipv6_mask.dst_ip);
1236 : 0 : fdir_info->mask.src_port_mask = info->mask.src_port_mask;
1237 : 0 : fdir_info->mask.dst_port_mask = info->mask.dst_port_mask;
1238 : 0 : fdir_info->mask.mac_addr_byte_mask = info->mask.mac_addr_byte_mask;
1239 : 0 : fdir_info->mask.tunnel_id_mask = info->mask.tunnel_id_mask;
1240 : 0 : fdir_info->mask.tunnel_type_mask = info->mask.tunnel_type_mask;
1241 : 0 : fdir_info->max_flexpayload = IXGBE_FDIR_MAX_FLEX_LEN;
1242 : :
1243 [ # # ]: 0 : if (fdir_info->mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN ||
1244 : : fdir_info->mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
1245 : 0 : fdir_info->flow_types_mask[0] = 0ULL;
1246 : : else
1247 : 0 : fdir_info->flow_types_mask[0] = IXGBE_FDIR_FLOW_TYPES;
1248 : : for (uint32_t i = 1; i < RTE_FLOW_MASK_ARRAY_SIZE; i++)
1249 : : fdir_info->flow_types_mask[i] = 0ULL;
1250 : :
1251 : 0 : fdir_info->flex_payload_unit = sizeof(uint16_t);
1252 : 0 : fdir_info->max_flex_payload_segment_num = 1;
1253 : 0 : fdir_info->flex_payload_limit = IXGBE_MAX_FLX_SOURCE_OFF;
1254 : 0 : fdir_info->flex_conf.nb_payloads = 1;
1255 : 0 : fdir_info->flex_conf.flex_set[0].type = RTE_ETH_RAW_PAYLOAD;
1256 : 0 : fdir_info->flex_conf.flex_set[0].src_offset[0] = offset;
1257 : 0 : fdir_info->flex_conf.flex_set[0].src_offset[1] = offset + 1;
1258 : 0 : fdir_info->flex_conf.nb_flexmasks = 1;
1259 : 0 : fdir_info->flex_conf.flex_mask[0].flow_type = RTE_ETH_FLOW_UNKNOWN;
1260 : 0 : fdir_info->flex_conf.flex_mask[0].mask[0] =
1261 : 0 : (uint8_t)(info->mask.flex_bytes_mask & 0x00FF);
1262 : 0 : fdir_info->flex_conf.flex_mask[0].mask[1] =
1263 : 0 : (uint8_t)((info->mask.flex_bytes_mask & 0xFF00) >> 8);
1264 : 0 : }
1265 : :
1266 : : void
1267 : 0 : ixgbe_fdir_stats_get(struct rte_eth_dev *dev, struct rte_eth_fdir_stats *fdir_stats)
1268 : : {
1269 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1270 : : struct rte_eth_fdir_conf *fdir_conf = IXGBE_DEV_FDIR_CONF(dev);
1271 : : struct ixgbe_hw_fdir_info *info =
1272 : : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
1273 : : uint32_t reg, max_num;
1274 : 0 : enum rte_fdir_mode fdir_mode = fdir_conf->mode;
1275 : :
1276 : : /* Get the information from registers */
1277 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_FDIRFREE);
1278 : 0 : info->collision = (uint16_t)((reg & IXGBE_FDIRFREE_COLL_MASK) >>
1279 : : IXGBE_FDIRFREE_COLL_SHIFT);
1280 : 0 : info->free = (uint16_t)((reg & IXGBE_FDIRFREE_FREE_MASK) >>
1281 : : IXGBE_FDIRFREE_FREE_SHIFT);
1282 : :
1283 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_FDIRLEN);
1284 : 0 : info->maxhash = (uint16_t)((reg & IXGBE_FDIRLEN_MAXHASH_MASK) >>
1285 : : IXGBE_FDIRLEN_MAXHASH_SHIFT);
1286 : 0 : info->maxlen = (uint8_t)((reg & IXGBE_FDIRLEN_MAXLEN_MASK) >>
1287 : : IXGBE_FDIRLEN_MAXLEN_SHIFT);
1288 : :
1289 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_FDIRUSTAT);
1290 : 0 : info->remove += (reg & IXGBE_FDIRUSTAT_REMOVE_MASK) >>
1291 : : IXGBE_FDIRUSTAT_REMOVE_SHIFT;
1292 : 0 : info->add += (reg & IXGBE_FDIRUSTAT_ADD_MASK) >>
1293 : : IXGBE_FDIRUSTAT_ADD_SHIFT;
1294 : :
1295 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_FDIRFSTAT) & 0xFFFF;
1296 : 0 : info->f_remove += (reg & IXGBE_FDIRFSTAT_FREMOVE_MASK) >>
1297 : : IXGBE_FDIRFSTAT_FREMOVE_SHIFT;
1298 : 0 : info->f_add += (reg & IXGBE_FDIRFSTAT_FADD_MASK) >>
1299 : : IXGBE_FDIRFSTAT_FADD_SHIFT;
1300 : :
1301 : : /* Copy the new information in the fdir parameter */
1302 : 0 : fdir_stats->collision = info->collision;
1303 : 0 : fdir_stats->free = info->free;
1304 : 0 : fdir_stats->maxhash = info->maxhash;
1305 : 0 : fdir_stats->maxlen = info->maxlen;
1306 : 0 : fdir_stats->remove = info->remove;
1307 : 0 : fdir_stats->add = info->add;
1308 : 0 : fdir_stats->f_remove = info->f_remove;
1309 : 0 : fdir_stats->f_add = info->f_add;
1310 : :
1311 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL);
1312 : 0 : max_num = (1 << (FDIRENTRIES_NUM_SHIFT +
1313 : 0 : (reg & FDIRCTRL_PBALLOC_MASK)));
1314 [ # # ]: 0 : if (fdir_mode >= RTE_FDIR_MODE_PERFECT &&
1315 : : fdir_mode <= RTE_FDIR_MODE_PERFECT_TUNNEL)
1316 : 0 : fdir_stats->guarant_cnt = max_num - fdir_stats->free;
1317 [ # # ]: 0 : else if (fdir_mode == RTE_FDIR_MODE_SIGNATURE)
1318 : 0 : fdir_stats->guarant_cnt = max_num * 4 - fdir_stats->free;
1319 : :
1320 : 0 : }
1321 : :
1322 : : /* restore flow director filter */
1323 : : void
1324 : 0 : ixgbe_fdir_filter_restore(struct rte_eth_dev *dev)
1325 : : {
1326 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1327 : : struct rte_eth_fdir_conf *fdir_conf = IXGBE_DEV_FDIR_CONF(dev);
1328 : : struct ixgbe_hw_fdir_info *fdir_info =
1329 : : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
1330 : : struct ixgbe_fdir_filter *node;
1331 : : bool is_perfect = FALSE;
1332 : 0 : enum rte_fdir_mode fdir_mode = fdir_conf->mode;
1333 : :
1334 [ # # ]: 0 : if (fdir_mode >= RTE_FDIR_MODE_PERFECT &&
1335 : : fdir_mode <= RTE_FDIR_MODE_PERFECT_TUNNEL)
1336 : : is_perfect = TRUE;
1337 : :
1338 : : if (is_perfect) {
1339 [ # # ]: 0 : TAILQ_FOREACH(node, &fdir_info->fdir_list, entries) {
1340 : 0 : (void)fdir_write_perfect_filter_82599(hw,
1341 : : &node->ixgbe_fdir,
1342 : 0 : node->queue,
1343 : : node->fdirflags,
1344 : : node->fdirhash,
1345 : : fdir_mode);
1346 : : }
1347 : : } else {
1348 [ # # ]: 0 : TAILQ_FOREACH(node, &fdir_info->fdir_list, entries) {
1349 : 0 : (void)fdir_add_signature_filter_82599(hw,
1350 : : &node->ixgbe_fdir,
1351 : 0 : node->queue,
1352 : : node->fdirflags,
1353 : : node->fdirhash);
1354 : : }
1355 : : }
1356 : 0 : }
1357 : :
1358 : : /* remove all the flow director filters */
1359 : : int
1360 : 0 : ixgbe_clear_all_fdir_filter(struct rte_eth_dev *dev)
1361 : : {
1362 : 0 : struct rte_eth_fdir_conf *fdir_conf = IXGBE_DEV_FDIR_CONF(dev);
1363 : : struct ixgbe_hw_fdir_info *fdir_info =
1364 : : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
1365 : : struct ixgbe_fdir_filter *fdir_filter;
1366 : : bool had_flows;
1367 : : int ret = 0;
1368 : :
1369 : 0 : had_flows = (fdir_info->n_flows != 0);
1370 : :
1371 : : /* flush flow director */
1372 : 0 : rte_hash_reset(fdir_info->hash_handle);
1373 : 0 : memset(fdir_info->hash_map, 0,
1374 : : sizeof(struct ixgbe_fdir_filter *) * IXGBE_MAX_FDIR_FILTER_NUM);
1375 [ # # ]: 0 : while ((fdir_filter = TAILQ_FIRST(&fdir_info->fdir_list))) {
1376 [ # # ]: 0 : TAILQ_REMOVE(&fdir_info->fdir_list,
1377 : : fdir_filter,
1378 : : entries);
1379 : 0 : rte_free(fdir_filter);
1380 : : }
1381 : 0 : fdir_info->n_flows = 0;
1382 : :
1383 : : /* reset internal FDIR state */
1384 : 0 : fdir_info->mask = (struct ixgbe_hw_fdir_mask){0};
1385 : 0 : fdir_info->flex_bytes_offset = 0;
1386 : 0 : fdir_info->mask_added = FALSE;
1387 : 0 : fdir_conf->mode = RTE_FDIR_MODE_NONE;
1388 : :
1389 [ # # ]: 0 : if (had_flows)
1390 : 0 : ret = ixgbe_fdir_flush(dev);
1391 : :
1392 : 0 : return ret;
1393 : : }
|