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 rte_eth_dev *dev,
559 : : const struct rte_eth_fdir_conf *fdir_conf,
560 : : const struct ixgbe_hw_fdir_mask *fdir_mask)
561 : : {
562 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
563 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(adapter);
564 : : int err;
565 : : uint32_t fdirctrl, pbsize;
566 : : int i;
567 : 0 : enum rte_fdir_mode mode = fdir_conf->mode;
568 : :
569 : 0 : PMD_INIT_FUNC_TRACE();
570 : :
571 [ # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
572 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB:
573 : : case RTE_ETH_MQ_RX_DCB:
574 : : case RTE_ETH_MQ_RX_DCB_RSS:
575 : 0 : PMD_INIT_LOG(ERR, "Flow Director is not supported with DCB");
576 : 0 : return -ENOTSUP;
577 : : default:
578 : : break;
579 : : }
580 : :
581 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82599EB &&
582 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X540 &&
583 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550 &&
584 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_x &&
585 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_a &&
586 : : hw->mac.type != ixgbe_mac_E610)
587 : : return -ENOSYS;
588 : :
589 : : /* x550 and E610 supports mac-vlan and tunnel mode but other NICs not */
590 : 0 : if (hw->mac.type != ixgbe_mac_X550 &&
591 : : hw->mac.type != ixgbe_mac_X550EM_x &&
592 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_a &&
593 : : hw->mac.type != ixgbe_mac_E610 &&
594 [ # # ]: 0 : mode != RTE_FDIR_MODE_SIGNATURE &&
595 : : mode != RTE_FDIR_MODE_PERFECT)
596 : : return -ENOSYS;
597 : :
598 : 0 : err = configure_fdir_flags(fdir_conf, &fdirctrl);
599 [ # # ]: 0 : if (err)
600 : : return err;
601 : :
602 : : /*
603 : : * Before enabling Flow Director, the Rx Packet Buffer size
604 : : * must be reduced. The new value is the current size minus
605 : : * flow director memory usage size.
606 : : */
607 : 0 : pbsize = (1 << (PBALLOC_SIZE_SHIFT + (fdirctrl & FDIRCTRL_PBALLOC_MASK)));
608 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0),
609 : : (IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) - pbsize));
610 : :
611 : : /*
612 : : * The defaults in the HW for RX PB 1-7 are not zero and so should be
613 : : * initialized to zero for non DCB mode otherwise actual total RX PB
614 : : * would be bigger than programmed and filter space would run into
615 : : * the PB 0 region.
616 : : */
617 [ # # ]: 0 : for (i = 1; i < 8; i++)
618 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
619 : :
620 : 0 : err = ixgbe_fdir_set_input_mask(adapter, fdir_mask, mode);
621 [ # # ]: 0 : if (err < 0) {
622 : 0 : PMD_INIT_LOG(ERR, " Error on setting FD mask");
623 : 0 : return err;
624 : : }
625 : 0 : err = ixgbe_set_fdir_flex_conf(adapter, &fdir_conf->flex_conf,
626 : : &fdirctrl);
627 [ # # ]: 0 : if (err < 0) {
628 : 0 : PMD_INIT_LOG(ERR, " Error on setting FD flexible arguments.");
629 : 0 : return err;
630 : : }
631 : :
632 : 0 : err = fdir_enable_82599(hw, fdirctrl);
633 [ # # ]: 0 : if (err < 0) {
634 : 0 : PMD_INIT_LOG(ERR, " Error on enabling FD.");
635 : 0 : return err;
636 : : }
637 : : return 0;
638 : : }
639 : :
640 : : /*
641 : : * The below function is taken from the FreeBSD IXGBE drivers release
642 : : * 2.3.8. The only change is not to mask hash_result with IXGBE_ATR_HASH_MASK
643 : : * before returning, as the signature hash can use 16bits.
644 : : *
645 : : * The newer driver has optimised functions for calculating bucket and
646 : : * signature hashes. However they don't support IPv6 type packets for signature
647 : : * filters so are not used here.
648 : : *
649 : : * Note that the bkt_hash field in the ixgbe_atr_input structure is also never
650 : : * set.
651 : : *
652 : : * Compute the hashes for SW ATR
653 : : * @stream: input bitstream to compute the hash on
654 : : * @key: 32-bit hash key
655 : : **/
656 : : static uint32_t
657 : 0 : ixgbe_atr_compute_hash_82599(union ixgbe_atr_input *atr_input,
658 : : uint32_t key)
659 : : {
660 : : /*
661 : : * The algorithm is as follows:
662 : : * Hash[15:0] = Sum { S[n] x K[n+16] }, n = 0...350
663 : : * where Sum {A[n]}, n = 0...n is bitwise XOR of A[0], A[1]...A[n]
664 : : * and A[n] x B[n] is bitwise AND between same length strings
665 : : *
666 : : * K[n] is 16 bits, defined as:
667 : : * for n modulo 32 >= 15, K[n] = K[n % 32 : (n % 32) - 15]
668 : : * for n modulo 32 < 15, K[n] =
669 : : * K[(n % 32:0) | (31:31 - (14 - (n % 32)))]
670 : : *
671 : : * S[n] is 16 bits, defined as:
672 : : * for n >= 15, S[n] = S[n:n - 15]
673 : : * for n < 15, S[n] = S[(n:0) | (350:350 - (14 - n))]
674 : : *
675 : : * To simplify for programming, the algorithm is implemented
676 : : * in software this way:
677 : : *
678 : : * key[31:0], hi_hash_dword[31:0], lo_hash_dword[31:0], hash[15:0]
679 : : *
680 : : * for (i = 0; i < 352; i+=32)
681 : : * hi_hash_dword[31:0] ^= Stream[(i+31):i];
682 : : *
683 : : * lo_hash_dword[15:0] ^= Stream[15:0];
684 : : * lo_hash_dword[15:0] ^= hi_hash_dword[31:16];
685 : : * lo_hash_dword[31:16] ^= hi_hash_dword[15:0];
686 : : *
687 : : * hi_hash_dword[31:0] ^= Stream[351:320];
688 : : *
689 : : * if (key[0])
690 : : * hash[15:0] ^= Stream[15:0];
691 : : *
692 : : * for (i = 0; i < 16; i++) {
693 : : * if (key[i])
694 : : * hash[15:0] ^= lo_hash_dword[(i+15):i];
695 : : * if (key[i + 16])
696 : : * hash[15:0] ^= hi_hash_dword[(i+15):i];
697 : : * }
698 : : *
699 : : */
700 : : __be32 common_hash_dword = 0;
701 : : u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan;
702 : : u32 hash_result = 0;
703 : : u8 i;
704 : :
705 : : /* record the flow_vm_vlan bits as they are a key part to the hash */
706 [ # # ]: 0 : flow_vm_vlan = IXGBE_NTOHL(atr_input->dword_stream[0]);
707 : :
708 : : /* generate common hash dword */
709 [ # # ]: 0 : for (i = 1; i <= 13; i++)
710 : 0 : common_hash_dword ^= atr_input->dword_stream[i];
711 : :
712 [ # # ]: 0 : hi_hash_dword = IXGBE_NTOHL(common_hash_dword);
713 : :
714 : : /* low dword is word swapped version of common */
715 : 0 : lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16);
716 : :
717 : : /* apply flow ID/VM pool/VLAN ID bits to hash words */
718 : 0 : hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16);
719 : :
720 : : /* Process bits 0 and 16 */
721 [ # # ]: 0 : if (key & 0x0001)
722 : : hash_result ^= lo_hash_dword;
723 [ # # ]: 0 : if (key & 0x00010000)
724 : 0 : hash_result ^= hi_hash_dword;
725 : :
726 : : /*
727 : : * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to
728 : : * delay this because bit 0 of the stream should not be processed
729 : : * so we do not add the vlan until after bit 0 was processed
730 : : */
731 : 0 : lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16);
732 : :
733 : :
734 : : /* process the remaining 30 bits in the key 2 bits at a time */
735 [ # # ]: 0 : for (i = 15; i; i--) {
736 [ # # ]: 0 : if (key & (0x0001 << i))
737 : 0 : hash_result ^= lo_hash_dword >> i;
738 [ # # ]: 0 : if (key & (0x00010000 << i))
739 : 0 : hash_result ^= hi_hash_dword >> i;
740 : : }
741 : :
742 : 0 : return hash_result;
743 : : }
744 : :
745 : : static uint32_t
746 : 0 : atr_compute_perfect_hash_82599(union ixgbe_atr_input *input,
747 : : enum rte_eth_fdir_pballoc_type pballoc)
748 : : {
749 [ # # ]: 0 : if (pballoc == RTE_ETH_FDIR_PBALLOC_256K)
750 : 0 : return ixgbe_atr_compute_hash_82599(input,
751 : 0 : IXGBE_ATR_BUCKET_HASH_KEY) &
752 : : PERFECT_BUCKET_256KB_HASH_MASK;
753 [ # # ]: 0 : else if (pballoc == RTE_ETH_FDIR_PBALLOC_128K)
754 : 0 : return ixgbe_atr_compute_hash_82599(input,
755 : 0 : IXGBE_ATR_BUCKET_HASH_KEY) &
756 : : PERFECT_BUCKET_128KB_HASH_MASK;
757 : : else
758 : 0 : return ixgbe_atr_compute_hash_82599(input,
759 : 0 : IXGBE_ATR_BUCKET_HASH_KEY) &
760 : : PERFECT_BUCKET_64KB_HASH_MASK;
761 : : }
762 : :
763 : : /**
764 : : * ixgbe_fdir_check_cmd_complete - poll to check whether FDIRCMD is complete
765 : : * @hw: pointer to hardware structure
766 : : */
767 : : static inline int
768 : : ixgbe_fdir_check_cmd_complete(struct ixgbe_hw *hw, uint32_t *fdircmd)
769 : : {
770 : : int i;
771 : :
772 [ # # # # : 0 : for (i = 0; i < IXGBE_FDIRCMD_CMD_POLL; i++) {
# # # # ]
773 : 0 : *fdircmd = IXGBE_READ_REG(hw, IXGBE_FDIRCMD);
774 [ # # # # : 0 : if (!(*fdircmd & IXGBE_FDIRCMD_CMD_MASK))
# # # # ]
775 : : return 0;
776 : 0 : rte_delay_us(IXGBE_FDIRCMD_CMD_INTERVAL_US);
777 : : }
778 : :
779 : : return -ETIMEDOUT;
780 : : }
781 : :
782 : : /*
783 : : * Calculate the hash value needed for signature-match filters. In the FreeBSD
784 : : * driver, this is done by the optimised function
785 : : * ixgbe_atr_compute_sig_hash_82599(). However that can't be used here as it
786 : : * doesn't support calculating a hash for an IPv6 filter.
787 : : */
788 : : static uint32_t
789 : 0 : atr_compute_sig_hash_82599(union ixgbe_atr_input *input,
790 : : enum rte_eth_fdir_pballoc_type pballoc)
791 : : {
792 : : uint32_t bucket_hash, sig_hash;
793 : :
794 [ # # ]: 0 : if (pballoc == RTE_ETH_FDIR_PBALLOC_256K)
795 : 0 : bucket_hash = ixgbe_atr_compute_hash_82599(input,
796 : : IXGBE_ATR_BUCKET_HASH_KEY) &
797 : : SIG_BUCKET_256KB_HASH_MASK;
798 [ # # ]: 0 : else if (pballoc == RTE_ETH_FDIR_PBALLOC_128K)
799 : 0 : bucket_hash = ixgbe_atr_compute_hash_82599(input,
800 : : IXGBE_ATR_BUCKET_HASH_KEY) &
801 : : SIG_BUCKET_128KB_HASH_MASK;
802 : : else
803 : 0 : bucket_hash = ixgbe_atr_compute_hash_82599(input,
804 : : IXGBE_ATR_BUCKET_HASH_KEY) &
805 : : SIG_BUCKET_64KB_HASH_MASK;
806 : :
807 : 0 : sig_hash = ixgbe_atr_compute_hash_82599(input,
808 : : IXGBE_ATR_SIGNATURE_HASH_KEY);
809 : :
810 : 0 : return (sig_hash << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT) | bucket_hash;
811 : : }
812 : :
813 : : /*
814 : : * This is based on ixgbe_fdir_write_perfect_filter_82599() in
815 : : * base/ixgbe_82599.c, with the ability to set extra flags in FDIRCMD register
816 : : * added, and IPv6 support also added. The hash value is also pre-calculated
817 : : * as the pballoc value is needed to do it.
818 : : */
819 : : static int
820 : 0 : fdir_write_perfect_filter_82599(struct ixgbe_hw *hw,
821 : : union ixgbe_atr_input *input, uint8_t queue,
822 : : uint32_t fdircmd, uint32_t fdirhash,
823 : : enum rte_fdir_mode mode)
824 : : {
825 : : uint32_t fdirport, fdirvlan;
826 : : u32 addr_low, addr_high;
827 : : u32 tunnel_type = 0;
828 : : int err = 0;
829 : : volatile uint32_t *reg;
830 : :
831 [ # # ]: 0 : if (mode == RTE_FDIR_MODE_PERFECT) {
832 : : /* record the IPv4 address (big-endian)
833 : : * can not use IXGBE_WRITE_REG.
834 : : */
835 : 0 : reg = IXGBE_PCI_REG_ADDR(hw, IXGBE_FDIRIPSA);
836 : 0 : *reg = input->formatted.src_ip[0];
837 : : reg = IXGBE_PCI_REG_ADDR(hw, IXGBE_FDIRIPDA);
838 : 0 : *reg = input->formatted.dst_ip[0];
839 : :
840 : : /* record source and destination port (little-endian)*/
841 [ # # ]: 0 : fdirport = IXGBE_NTOHS(input->formatted.dst_port);
842 : 0 : fdirport <<= IXGBE_FDIRPORT_DESTINATION_SHIFT;
843 [ # # ]: 0 : fdirport |= IXGBE_NTOHS(input->formatted.src_port);
844 : : IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, fdirport);
845 [ # # ]: 0 : } else if (mode >= RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
846 : : mode <= RTE_FDIR_MODE_PERFECT_TUNNEL) {
847 : : /* for mac vlan and tunnel modes */
848 : 0 : addr_low = ((u32)input->formatted.inner_mac[0] |
849 : 0 : ((u32)input->formatted.inner_mac[1] << 8) |
850 : 0 : ((u32)input->formatted.inner_mac[2] << 16) |
851 : 0 : ((u32)input->formatted.inner_mac[3] << 24));
852 : 0 : addr_high = ((u32)input->formatted.inner_mac[4] |
853 : 0 : ((u32)input->formatted.inner_mac[5] << 8));
854 : :
855 [ # # ]: 0 : if (mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
856 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(0), addr_low);
857 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(1), addr_high);
858 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(2), 0);
859 : : } else {
860 : : /* tunnel mode */
861 [ # # ]: 0 : if (input->formatted.tunnel_type)
862 : : tunnel_type = 0x80000000;
863 : 0 : tunnel_type |= addr_high;
864 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(0), addr_low);
865 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(1), tunnel_type);
866 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(2),
867 : : input->formatted.tni_vni);
868 : : }
869 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRIPSA, 0);
870 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRIPDA, 0);
871 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, 0);
872 : : }
873 : :
874 : : /* record vlan (little-endian) and flex_bytes(big-endian) */
875 : 0 : fdirvlan = input->formatted.flex_bytes;
876 : 0 : fdirvlan <<= IXGBE_FDIRVLAN_FLEX_SHIFT;
877 [ # # ]: 0 : fdirvlan |= IXGBE_NTOHS(input->formatted.vlan_id);
878 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRVLAN, fdirvlan);
879 : :
880 : : /* configure FDIRHASH register */
881 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
882 : :
883 : : /*
884 : : * flush all previous writes to make certain registers are
885 : : * programmed prior to issuing the command
886 : : */
887 : 0 : IXGBE_WRITE_FLUSH(hw);
888 : :
889 : : /* configure FDIRCMD register */
890 : 0 : fdircmd |= IXGBE_FDIRCMD_CMD_ADD_FLOW |
891 : : IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN;
892 : 0 : fdircmd |= input->formatted.flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT;
893 : 0 : fdircmd |= (uint32_t)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
894 : 0 : fdircmd |= (uint32_t)input->formatted.vm_pool << IXGBE_FDIRCMD_VT_POOL_SHIFT;
895 : :
896 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, fdircmd);
897 : :
898 : 0 : PMD_DRV_LOG(DEBUG, "Rx Queue=%x hash=%x", queue, fdirhash);
899 : :
900 : : err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
901 [ # # ]: 0 : if (err < 0)
902 : 0 : PMD_DRV_LOG(ERR, "Timeout writing flow director filter.");
903 : :
904 : 0 : return err;
905 : : }
906 : :
907 : : /**
908 : : * This function is based on ixgbe_atr_add_signature_filter_82599() in
909 : : * base/ixgbe_82599.c, but uses a pre-calculated hash value. It also supports
910 : : * setting extra fields in the FDIRCMD register, and removes the code that was
911 : : * verifying the flow_type field. According to the documentation, a flow type of
912 : : * 00 (i.e. not TCP, UDP, or SCTP) is not supported, however it appears to
913 : : * work ok...
914 : : *
915 : : * Adds a signature hash filter
916 : : * @hw: pointer to hardware structure
917 : : * @input: unique input dword
918 : : * @queue: queue index to direct traffic to
919 : : * @fdircmd: any extra flags to set in fdircmd register
920 : : * @fdirhash: pre-calculated hash value for the filter
921 : : **/
922 : : static int
923 : 0 : fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
924 : : union ixgbe_atr_input *input, u8 queue, uint32_t fdircmd,
925 : : uint32_t fdirhash)
926 : : {
927 : : int err = 0;
928 : :
929 : 0 : PMD_INIT_FUNC_TRACE();
930 : :
931 : : /* configure FDIRCMD register */
932 : 0 : fdircmd |= IXGBE_FDIRCMD_CMD_ADD_FLOW |
933 : : IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN;
934 : 0 : fdircmd |= input->formatted.flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT;
935 : 0 : fdircmd |= (uint32_t)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
936 : :
937 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
938 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, fdircmd);
939 : :
940 : 0 : PMD_DRV_LOG(DEBUG, "Rx Queue=%x hash=%x", queue, fdirhash);
941 : :
942 : : err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
943 [ # # ]: 0 : if (err < 0)
944 : 0 : PMD_DRV_LOG(ERR, "Timeout writing flow director filter.");
945 : :
946 : 0 : return err;
947 : : }
948 : :
949 : : /*
950 : : * This is based on ixgbe_fdir_erase_perfect_filter_82599() in
951 : : * base/ixgbe_82599.c. It is modified to take in the hash as a parameter so
952 : : * that it can be used for removing signature and perfect filters.
953 : : */
954 : : static int
955 : 0 : fdir_erase_filter_82599(struct ixgbe_hw *hw, uint32_t fdirhash)
956 : : {
957 : : uint32_t fdircmd = 0;
958 : : int err = 0;
959 : :
960 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
961 : :
962 : : /* flush hash to HW */
963 : 0 : IXGBE_WRITE_FLUSH(hw);
964 : :
965 : : /* Query if filter is present */
966 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, IXGBE_FDIRCMD_CMD_QUERY_REM_FILT);
967 : :
968 : : err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
969 [ # # ]: 0 : if (err < 0) {
970 : 0 : PMD_INIT_LOG(ERR, "Timeout querying for flow director filter.");
971 : 0 : return err;
972 : : }
973 : :
974 : : /* if filter exists in hardware then remove it */
975 [ # # ]: 0 : if (fdircmd & IXGBE_FDIRCMD_FILTER_VALID) {
976 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
977 : 0 : IXGBE_WRITE_FLUSH(hw);
978 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
979 : : IXGBE_FDIRCMD_CMD_REMOVE_FLOW);
980 : : }
981 : : err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
982 [ # # ]: 0 : if (err < 0)
983 : 0 : PMD_INIT_LOG(ERR, "Timeout erasing flow director filter.");
984 : : return err;
985 : :
986 : : }
987 : :
988 : : static inline struct ixgbe_fdir_filter *
989 : : ixgbe_fdir_filter_lookup(struct ixgbe_hw_fdir_info *fdir_info,
990 : : union ixgbe_atr_input *key)
991 : : {
992 : : int ret;
993 : :
994 : 0 : ret = rte_hash_lookup(fdir_info->hash_handle, (const void *)key);
995 [ # # ]: 0 : if (ret < 0)
996 : : return NULL;
997 : :
998 : 0 : return fdir_info->hash_map[ret];
999 : : }
1000 : :
1001 : : static inline int
1002 : 0 : ixgbe_insert_fdir_filter(struct ixgbe_hw_fdir_info *fdir_info,
1003 : : struct ixgbe_fdir_filter *fdir_filter)
1004 : : {
1005 : : int ret;
1006 : :
1007 : 0 : ret = rte_hash_add_key(fdir_info->hash_handle,
1008 : 0 : &fdir_filter->ixgbe_fdir);
1009 : :
1010 [ # # ]: 0 : if (ret < 0) {
1011 : 0 : PMD_DRV_LOG(ERR,
1012 : : "Failed to insert fdir filter to hash table %d!",
1013 : : ret);
1014 : 0 : return ret;
1015 : : }
1016 : :
1017 : 0 : fdir_info->hash_map[ret] = fdir_filter;
1018 : :
1019 : 0 : TAILQ_INSERT_TAIL(&fdir_info->fdir_list, fdir_filter, entries);
1020 : :
1021 : 0 : return 0;
1022 : : }
1023 : :
1024 : : static inline int
1025 : 0 : ixgbe_remove_fdir_filter(struct ixgbe_hw_fdir_info *fdir_info,
1026 : : union ixgbe_atr_input *key)
1027 : : {
1028 : : int ret;
1029 : : struct ixgbe_fdir_filter *fdir_filter;
1030 : :
1031 : 0 : ret = rte_hash_del_key(fdir_info->hash_handle, key);
1032 : :
1033 [ # # ]: 0 : if (ret < 0) {
1034 : 0 : PMD_DRV_LOG(ERR, "No such fdir filter to delete %d!", ret);
1035 : 0 : return ret;
1036 : : }
1037 : :
1038 : 0 : fdir_filter = fdir_info->hash_map[ret];
1039 : 0 : fdir_info->hash_map[ret] = NULL;
1040 : :
1041 [ # # ]: 0 : TAILQ_REMOVE(&fdir_info->fdir_list, fdir_filter, entries);
1042 : 0 : rte_free(fdir_filter);
1043 : :
1044 : 0 : return 0;
1045 : : }
1046 : :
1047 : : int
1048 : 0 : ixgbe_fdir_filter_program(struct ixgbe_adapter *adapter,
1049 : : struct rte_eth_fdir_conf *fdir_conf,
1050 : : struct ixgbe_fdir_rule *rule,
1051 : : bool del,
1052 : : bool update)
1053 : : {
1054 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(adapter);
1055 : : uint32_t fdircmd_flags;
1056 : : uint32_t fdirhash;
1057 : : uint8_t queue;
1058 : : bool is_perfect = FALSE;
1059 : : int err;
1060 : 0 : struct ixgbe_hw_fdir_info *info =
1061 : : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(adapter);
1062 : 0 : enum rte_fdir_mode fdir_mode = fdir_conf->mode;
1063 : : struct ixgbe_fdir_filter *node;
1064 : : bool add_node = FALSE;
1065 : :
1066 [ # # ]: 0 : if (fdir_mode == RTE_FDIR_MODE_NONE ||
1067 [ # # ]: 0 : fdir_mode != rule->mode)
1068 : : return -ENOTSUP;
1069 : :
1070 : : /*
1071 : : * Sanity check for x550 and E610.
1072 : : * When adding a new filter with flow type set to IPv4,
1073 : : * the flow director mask should be configed before,
1074 : : * and the L4 protocol and ports are masked.
1075 : : */
1076 [ # # ]: 0 : if ((!del) &&
1077 : 0 : (hw->mac.type == ixgbe_mac_X550 ||
1078 : : hw->mac.type == ixgbe_mac_X550EM_x ||
1079 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_a ||
1080 : 0 : hw->mac.type == ixgbe_mac_E610) &&
1081 : 0 : (rule->ixgbe_fdir.formatted.flow_type ==
1082 [ # # ]: 0 : IXGBE_ATR_FLOW_TYPE_IPV4 ||
1083 : : rule->ixgbe_fdir.formatted.flow_type ==
1084 : 0 : IXGBE_ATR_FLOW_TYPE_IPV6) &&
1085 [ # # ]: 0 : (info->mask.src_port_mask != 0 ||
1086 : 0 : info->mask.dst_port_mask != 0) &&
1087 [ # # ]: 0 : (rule->mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
1088 : : rule->mode != RTE_FDIR_MODE_PERFECT_TUNNEL)) {
1089 : 0 : PMD_DRV_LOG(ERR, "By this device,"
1090 : : " IPv4 is not supported without"
1091 : : " L4 protocol and ports masked!");
1092 : 0 : return -ENOTSUP;
1093 : : }
1094 : :
1095 [ # # ]: 0 : if (fdir_mode >= RTE_FDIR_MODE_PERFECT &&
1096 : : fdir_mode <= RTE_FDIR_MODE_PERFECT_TUNNEL)
1097 : : is_perfect = TRUE;
1098 : :
1099 : : if (is_perfect) {
1100 [ # # ]: 0 : if (rule->ixgbe_fdir.formatted.flow_type &
1101 : : IXGBE_ATR_L4TYPE_IPV6_MASK) {
1102 : 0 : PMD_DRV_LOG(ERR, "IPv6 is not supported in"
1103 : : " perfect mode!");
1104 : 0 : return -ENOTSUP;
1105 : : }
1106 : 0 : fdirhash = atr_compute_perfect_hash_82599(&rule->ixgbe_fdir,
1107 : : fdir_conf->pballoc);
1108 : 0 : fdirhash |= rule->soft_id <<
1109 : : IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT;
1110 : : } else
1111 : 0 : fdirhash = atr_compute_sig_hash_82599(&rule->ixgbe_fdir,
1112 : : fdir_conf->pballoc);
1113 : :
1114 [ # # ]: 0 : if (del) {
1115 : 0 : err = ixgbe_remove_fdir_filter(info, &rule->ixgbe_fdir);
1116 [ # # ]: 0 : if (err < 0)
1117 : : return err;
1118 : :
1119 : 0 : err = fdir_erase_filter_82599(hw, fdirhash);
1120 [ # # ]: 0 : if (err < 0)
1121 : 0 : PMD_DRV_LOG(ERR, "Fail to delete FDIR filter!");
1122 : : else
1123 : 0 : PMD_DRV_LOG(DEBUG, "Success to delete FDIR filter!");
1124 : 0 : return err;
1125 : : }
1126 : : /* add or update an fdir filter*/
1127 [ # # ]: 0 : fdircmd_flags = (update) ? IXGBE_FDIRCMD_FILTER_UPDATE : 0;
1128 [ # # ]: 0 : if (rule->fdirflags & IXGBE_FDIRCMD_DROP) {
1129 [ # # ]: 0 : if (is_perfect) {
1130 : 0 : queue = fdir_conf->drop_queue;
1131 : 0 : fdircmd_flags |= IXGBE_FDIRCMD_DROP;
1132 : : } else {
1133 : 0 : PMD_DRV_LOG(ERR, "Drop option is not supported in"
1134 : : " signature mode.");
1135 : 0 : return -EINVAL;
1136 : : }
1137 [ # # ]: 0 : } else if (rule->queue < IXGBE_MAX_RX_QUEUE_NUM)
1138 : : queue = (uint8_t)rule->queue;
1139 : : else
1140 : : return -EINVAL;
1141 : :
1142 : 0 : node = ixgbe_fdir_filter_lookup(info, &rule->ixgbe_fdir);
1143 [ # # ]: 0 : if (node) {
1144 [ # # ]: 0 : if (update) {
1145 : 0 : node->fdirflags = fdircmd_flags;
1146 : 0 : node->fdirhash = fdirhash;
1147 : 0 : node->queue = queue;
1148 : : } else {
1149 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing fdir filter!");
1150 : 0 : return -EINVAL;
1151 : : }
1152 : : } else {
1153 : : add_node = TRUE;
1154 : 0 : node = rte_zmalloc("ixgbe_fdir",
1155 : : sizeof(struct ixgbe_fdir_filter),
1156 : : 0);
1157 [ # # ]: 0 : if (!node)
1158 : : return -ENOMEM;
1159 : 0 : memcpy(&node->ixgbe_fdir,
1160 : : &rule->ixgbe_fdir,
1161 : : sizeof(union ixgbe_atr_input));
1162 : 0 : node->fdirflags = fdircmd_flags;
1163 : 0 : node->fdirhash = fdirhash;
1164 : 0 : node->queue = queue;
1165 : :
1166 : 0 : err = ixgbe_insert_fdir_filter(info, node);
1167 [ # # ]: 0 : if (err < 0) {
1168 : 0 : rte_free(node);
1169 : 0 : return err;
1170 : : }
1171 : : }
1172 : :
1173 [ # # ]: 0 : if (is_perfect) {
1174 : 0 : err = fdir_write_perfect_filter_82599(hw, &rule->ixgbe_fdir,
1175 : : queue, fdircmd_flags,
1176 : : fdirhash, fdir_mode);
1177 : : } else {
1178 : 0 : err = fdir_add_signature_filter_82599(hw, &rule->ixgbe_fdir,
1179 : : queue, fdircmd_flags,
1180 : : fdirhash);
1181 : : }
1182 [ # # ]: 0 : if (err < 0) {
1183 : 0 : PMD_DRV_LOG(ERR, "Fail to add FDIR filter!");
1184 : :
1185 [ # # ]: 0 : if (add_node)
1186 : 0 : (void)ixgbe_remove_fdir_filter(info, &rule->ixgbe_fdir);
1187 : : } else {
1188 : 0 : PMD_DRV_LOG(DEBUG, "Success to add FDIR filter");
1189 : : }
1190 : :
1191 : : return err;
1192 : : }
1193 : :
1194 : : static int
1195 : 0 : ixgbe_fdir_flush(struct rte_eth_dev *dev)
1196 : : {
1197 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1198 : : struct ixgbe_hw_fdir_info *info =
1199 : : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
1200 : : int ret;
1201 : :
1202 : 0 : ret = ixgbe_reinit_fdir_tables_82599(hw);
1203 [ # # ]: 0 : if (ret < 0) {
1204 : 0 : PMD_INIT_LOG(ERR, "Failed to re-initialize FD table.");
1205 : 0 : return ret;
1206 : : }
1207 : :
1208 : 0 : info->f_add = 0;
1209 : 0 : info->f_remove = 0;
1210 : 0 : info->add = 0;
1211 : 0 : info->remove = 0;
1212 : :
1213 : 0 : return ret;
1214 : : }
1215 : :
1216 : : #define FDIRENTRIES_NUM_SHIFT 10
1217 : : void
1218 : 0 : ixgbe_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
1219 : : {
1220 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1221 : : struct rte_eth_fdir_conf *fdir_conf = IXGBE_DEV_FDIR_CONF(dev);
1222 : : struct ixgbe_hw_fdir_info *info =
1223 : : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
1224 : : uint32_t fdirctrl, max_num;
1225 : : uint8_t offset;
1226 : :
1227 : 0 : fdirctrl = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL);
1228 : 0 : offset = ((fdirctrl & IXGBE_FDIRCTRL_FLEX_MASK) >>
1229 : : IXGBE_FDIRCTRL_FLEX_SHIFT) * sizeof(uint16_t);
1230 : :
1231 : 0 : fdir_info->mode = fdir_conf->mode;
1232 : 0 : max_num = (1 << (FDIRENTRIES_NUM_SHIFT +
1233 : 0 : (fdirctrl & FDIRCTRL_PBALLOC_MASK)));
1234 [ # # ]: 0 : if (fdir_info->mode >= RTE_FDIR_MODE_PERFECT &&
1235 : : fdir_info->mode <= RTE_FDIR_MODE_PERFECT_TUNNEL)
1236 : 0 : fdir_info->guarant_spc = max_num;
1237 [ # # ]: 0 : else if (fdir_info->mode == RTE_FDIR_MODE_SIGNATURE)
1238 : 0 : fdir_info->guarant_spc = max_num * 4;
1239 : :
1240 : 0 : fdir_info->mask.vlan_tci_mask = info->mask.vlan_tci_mask;
1241 : 0 : fdir_info->mask.ipv4_mask.src_ip = info->mask.src_ipv4_mask;
1242 : 0 : fdir_info->mask.ipv4_mask.dst_ip = info->mask.dst_ipv4_mask;
1243 [ # # # # ]: 0 : IPV6_MASK_TO_ADDR(info->mask.src_ipv6_mask,
1244 : : fdir_info->mask.ipv6_mask.src_ip);
1245 [ # # # # : 0 : IPV6_MASK_TO_ADDR(info->mask.dst_ipv6_mask,
# # ]
1246 : : fdir_info->mask.ipv6_mask.dst_ip);
1247 : 0 : fdir_info->mask.src_port_mask = info->mask.src_port_mask;
1248 : 0 : fdir_info->mask.dst_port_mask = info->mask.dst_port_mask;
1249 : 0 : fdir_info->mask.mac_addr_byte_mask = info->mask.mac_addr_byte_mask;
1250 : 0 : fdir_info->mask.tunnel_id_mask = info->mask.tunnel_id_mask;
1251 : 0 : fdir_info->mask.tunnel_type_mask = info->mask.tunnel_type_mask;
1252 : 0 : fdir_info->max_flexpayload = IXGBE_FDIR_MAX_FLEX_LEN;
1253 : :
1254 [ # # ]: 0 : if (fdir_info->mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN ||
1255 : : fdir_info->mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
1256 : 0 : fdir_info->flow_types_mask[0] = 0ULL;
1257 : : else
1258 : 0 : fdir_info->flow_types_mask[0] = IXGBE_FDIR_FLOW_TYPES;
1259 : : for (uint32_t i = 1; i < RTE_FLOW_MASK_ARRAY_SIZE; i++)
1260 : : fdir_info->flow_types_mask[i] = 0ULL;
1261 : :
1262 : 0 : fdir_info->flex_payload_unit = sizeof(uint16_t);
1263 : 0 : fdir_info->max_flex_payload_segment_num = 1;
1264 : 0 : fdir_info->flex_payload_limit = IXGBE_MAX_FLX_SOURCE_OFF;
1265 : 0 : fdir_info->flex_conf.nb_payloads = 1;
1266 : 0 : fdir_info->flex_conf.flex_set[0].type = RTE_ETH_RAW_PAYLOAD;
1267 : 0 : fdir_info->flex_conf.flex_set[0].src_offset[0] = offset;
1268 : 0 : fdir_info->flex_conf.flex_set[0].src_offset[1] = offset + 1;
1269 : 0 : fdir_info->flex_conf.nb_flexmasks = 1;
1270 : 0 : fdir_info->flex_conf.flex_mask[0].flow_type = RTE_ETH_FLOW_UNKNOWN;
1271 : 0 : fdir_info->flex_conf.flex_mask[0].mask[0] =
1272 : 0 : (uint8_t)(info->mask.flex_bytes_mask & 0x00FF);
1273 : 0 : fdir_info->flex_conf.flex_mask[0].mask[1] =
1274 : 0 : (uint8_t)((info->mask.flex_bytes_mask & 0xFF00) >> 8);
1275 : 0 : }
1276 : :
1277 : : void
1278 : 0 : ixgbe_fdir_stats_get(struct rte_eth_dev *dev, struct rte_eth_fdir_stats *fdir_stats)
1279 : : {
1280 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1281 : : struct rte_eth_fdir_conf *fdir_conf = IXGBE_DEV_FDIR_CONF(dev);
1282 : : struct ixgbe_hw_fdir_info *info =
1283 : : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
1284 : : uint32_t reg, max_num;
1285 : 0 : enum rte_fdir_mode fdir_mode = fdir_conf->mode;
1286 : :
1287 : : /* Get the information from registers */
1288 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_FDIRFREE);
1289 : 0 : info->collision = (uint16_t)((reg & IXGBE_FDIRFREE_COLL_MASK) >>
1290 : : IXGBE_FDIRFREE_COLL_SHIFT);
1291 : 0 : info->free = (uint16_t)((reg & IXGBE_FDIRFREE_FREE_MASK) >>
1292 : : IXGBE_FDIRFREE_FREE_SHIFT);
1293 : :
1294 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_FDIRLEN);
1295 : 0 : info->maxhash = (uint16_t)((reg & IXGBE_FDIRLEN_MAXHASH_MASK) >>
1296 : : IXGBE_FDIRLEN_MAXHASH_SHIFT);
1297 : 0 : info->maxlen = (uint8_t)((reg & IXGBE_FDIRLEN_MAXLEN_MASK) >>
1298 : : IXGBE_FDIRLEN_MAXLEN_SHIFT);
1299 : :
1300 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_FDIRUSTAT);
1301 : 0 : info->remove += (reg & IXGBE_FDIRUSTAT_REMOVE_MASK) >>
1302 : : IXGBE_FDIRUSTAT_REMOVE_SHIFT;
1303 : 0 : info->add += (reg & IXGBE_FDIRUSTAT_ADD_MASK) >>
1304 : : IXGBE_FDIRUSTAT_ADD_SHIFT;
1305 : :
1306 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_FDIRFSTAT) & 0xFFFF;
1307 : 0 : info->f_remove += (reg & IXGBE_FDIRFSTAT_FREMOVE_MASK) >>
1308 : : IXGBE_FDIRFSTAT_FREMOVE_SHIFT;
1309 : 0 : info->f_add += (reg & IXGBE_FDIRFSTAT_FADD_MASK) >>
1310 : : IXGBE_FDIRFSTAT_FADD_SHIFT;
1311 : :
1312 : : /* Copy the new information in the fdir parameter */
1313 : 0 : fdir_stats->collision = info->collision;
1314 : 0 : fdir_stats->free = info->free;
1315 : 0 : fdir_stats->maxhash = info->maxhash;
1316 : 0 : fdir_stats->maxlen = info->maxlen;
1317 : 0 : fdir_stats->remove = info->remove;
1318 : 0 : fdir_stats->add = info->add;
1319 : 0 : fdir_stats->f_remove = info->f_remove;
1320 : 0 : fdir_stats->f_add = info->f_add;
1321 : :
1322 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL);
1323 : 0 : max_num = (1 << (FDIRENTRIES_NUM_SHIFT +
1324 : 0 : (reg & FDIRCTRL_PBALLOC_MASK)));
1325 [ # # ]: 0 : if (fdir_mode >= RTE_FDIR_MODE_PERFECT &&
1326 : : fdir_mode <= RTE_FDIR_MODE_PERFECT_TUNNEL)
1327 : 0 : fdir_stats->guarant_cnt = max_num - fdir_stats->free;
1328 [ # # ]: 0 : else if (fdir_mode == RTE_FDIR_MODE_SIGNATURE)
1329 : 0 : fdir_stats->guarant_cnt = max_num * 4 - fdir_stats->free;
1330 : :
1331 : 0 : }
1332 : :
1333 : : /* restore flow director filter */
1334 : : void
1335 : 0 : ixgbe_fdir_filter_restore(struct rte_eth_dev *dev)
1336 : : {
1337 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1338 : : struct rte_eth_fdir_conf *fdir_conf = IXGBE_DEV_FDIR_CONF(dev);
1339 : : struct ixgbe_hw_fdir_info *fdir_info =
1340 : : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
1341 : : struct ixgbe_fdir_filter *node;
1342 : : bool is_perfect = FALSE;
1343 : 0 : enum rte_fdir_mode fdir_mode = fdir_conf->mode;
1344 : :
1345 [ # # ]: 0 : if (fdir_mode >= RTE_FDIR_MODE_PERFECT &&
1346 : : fdir_mode <= RTE_FDIR_MODE_PERFECT_TUNNEL)
1347 : : is_perfect = TRUE;
1348 : :
1349 : : if (is_perfect) {
1350 [ # # ]: 0 : TAILQ_FOREACH(node, &fdir_info->fdir_list, entries) {
1351 : 0 : (void)fdir_write_perfect_filter_82599(hw,
1352 : : &node->ixgbe_fdir,
1353 : 0 : node->queue,
1354 : : node->fdirflags,
1355 : : node->fdirhash,
1356 : : fdir_mode);
1357 : : }
1358 : : } else {
1359 [ # # ]: 0 : TAILQ_FOREACH(node, &fdir_info->fdir_list, entries) {
1360 : 0 : (void)fdir_add_signature_filter_82599(hw,
1361 : : &node->ixgbe_fdir,
1362 : 0 : node->queue,
1363 : : node->fdirflags,
1364 : : node->fdirhash);
1365 : : }
1366 : : }
1367 : 0 : }
1368 : :
1369 : : /* remove all the flow director filters */
1370 : : int
1371 : 0 : ixgbe_clear_all_fdir_filter(struct rte_eth_dev *dev)
1372 : : {
1373 : 0 : struct rte_eth_fdir_conf *fdir_conf = IXGBE_DEV_FDIR_CONF(dev);
1374 : : struct ixgbe_hw_fdir_info *fdir_info =
1375 : : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
1376 : : struct ixgbe_fdir_filter *fdir_filter;
1377 : : bool had_flows;
1378 : : int ret = 0;
1379 : :
1380 : 0 : had_flows = (fdir_info->n_flows != 0);
1381 : :
1382 : : /* flush flow director */
1383 : 0 : rte_hash_reset(fdir_info->hash_handle);
1384 : 0 : memset(fdir_info->hash_map, 0,
1385 : : sizeof(struct ixgbe_fdir_filter *) * IXGBE_MAX_FDIR_FILTER_NUM);
1386 [ # # ]: 0 : while ((fdir_filter = TAILQ_FIRST(&fdir_info->fdir_list))) {
1387 [ # # ]: 0 : TAILQ_REMOVE(&fdir_info->fdir_list,
1388 : : fdir_filter,
1389 : : entries);
1390 : 0 : rte_free(fdir_filter);
1391 : : }
1392 : 0 : fdir_info->n_flows = 0;
1393 : :
1394 : : /* reset internal FDIR state */
1395 : 0 : fdir_info->mask = (struct ixgbe_hw_fdir_mask){0};
1396 : 0 : fdir_info->flex_bytes_offset = 0;
1397 : 0 : fdir_info->mask_added = FALSE;
1398 : 0 : fdir_conf->mode = RTE_FDIR_MODE_NONE;
1399 : :
1400 [ # # ]: 0 : if (had_flows)
1401 : 0 : ret = ixgbe_fdir_flush(dev);
1402 : :
1403 : 0 : return ret;
1404 : : }
|