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