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