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