Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2015 Intel Corporation
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : : #include <stdio.h>
7 : : #include <errno.h>
8 : : #include <stdint.h>
9 : : #include <string.h>
10 : : #include <unistd.h>
11 : : #include <stdarg.h>
12 : :
13 : : #include <rte_ether.h>
14 : : #include <ethdev_driver.h>
15 : : #include <rte_log.h>
16 : : #include <rte_memzone.h>
17 : : #include <rte_malloc.h>
18 : : #include <rte_arp.h>
19 : : #include <rte_ip.h>
20 : : #include <rte_udp.h>
21 : : #include <rte_tcp.h>
22 : : #include <rte_sctp.h>
23 : : #include <rte_hash_crc.h>
24 : : #include <rte_bitmap.h>
25 : : #include <rte_os_shim.h>
26 : :
27 : : #include "i40e_logs.h"
28 : : #include "base/i40e_type.h"
29 : : #include "base/i40e_prototype.h"
30 : : #include "i40e_ethdev.h"
31 : : #include "i40e_rxtx.h"
32 : :
33 : : #define I40E_FDIR_MZ_NAME "FDIR_MEMZONE"
34 : : #ifndef IPV6_ADDR_LEN
35 : : #define IPV6_ADDR_LEN 16
36 : : #endif
37 : :
38 : : #ifndef IPPROTO_L2TP
39 : : #define IPPROTO_L2TP 115
40 : : #endif
41 : :
42 : : #define I40E_FDIR_PKT_LEN 512
43 : : #define I40E_FDIR_IP_DEFAULT_LEN 420
44 : : #define I40E_FDIR_IP_DEFAULT_TTL 0x40
45 : : #define I40E_FDIR_IP_DEFAULT_VERSION_IHL 0x45
46 : : #define I40E_FDIR_TCP_DEFAULT_DATAOFF 0x50
47 : : #define I40E_FDIR_IPv6_DEFAULT_VTC_FLOW 0x60000000
48 : :
49 : : #define I40E_FDIR_IPv6_DEFAULT_HOP_LIMITS 0xFF
50 : : #define I40E_FDIR_IPv6_PAYLOAD_LEN 380
51 : : #define I40E_FDIR_UDP_DEFAULT_LEN 400
52 : : #define I40E_FDIR_GTP_DEFAULT_LEN 384
53 : : #define I40E_FDIR_INNER_IP_DEFAULT_LEN 384
54 : : #define I40E_FDIR_INNER_IPV6_DEFAULT_LEN 344
55 : :
56 : : #define I40E_FDIR_GTPC_DST_PORT 2123
57 : : #define I40E_FDIR_GTPU_DST_PORT 2152
58 : : #define I40E_FDIR_GTP_VER_FLAG_0X30 0x30
59 : : #define I40E_FDIR_GTP_VER_FLAG_0X32 0x32
60 : : #define I40E_FDIR_GTP_MSG_TYPE_0X01 0x01
61 : : #define I40E_FDIR_GTP_MSG_TYPE_0XFF 0xFF
62 : :
63 : : #define I40E_FDIR_ESP_DST_PORT 4500
64 : :
65 : : /* Wait time for fdir filter programming */
66 : : #define I40E_FDIR_MAX_WAIT_US 10000
67 : :
68 : : /* Wait count and interval for fdir filter flush */
69 : : #define I40E_FDIR_FLUSH_RETRY 50
70 : : #define I40E_FDIR_FLUSH_INTERVAL_MS 5
71 : :
72 : : #define I40E_COUNTER_PF 2
73 : : /* Statistic counter index for one pf */
74 : : #define I40E_COUNTER_INDEX_FDIR(pf_id) (0 + (pf_id) * I40E_COUNTER_PF)
75 : :
76 : : #define I40E_FDIR_FLOWS ( \
77 : : (1ULL << RTE_ETH_FLOW_FRAG_IPV4) | \
78 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_UDP) | \
79 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_TCP) | \
80 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP) | \
81 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER) | \
82 : : (1ULL << RTE_ETH_FLOW_FRAG_IPV6) | \
83 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_UDP) | \
84 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_TCP) | \
85 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP) | \
86 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
87 : : (1ULL << RTE_ETH_FLOW_L2_PAYLOAD))
88 : :
89 : : static int i40e_fdir_filter_convert(const struct i40e_fdir_filter_conf *input,
90 : : struct i40e_fdir_filter *filter);
91 : : static struct i40e_fdir_filter *
92 : : i40e_sw_fdir_filter_lookup(struct i40e_fdir_info *fdir_info,
93 : : const struct i40e_fdir_input *input);
94 : : static int i40e_sw_fdir_filter_insert(struct i40e_pf *pf,
95 : : struct i40e_fdir_filter *filter);
96 : : static int
97 : : i40e_flow_fdir_filter_programming(struct i40e_pf *pf,
98 : : enum i40e_filter_pctype pctype,
99 : : const struct i40e_fdir_filter_conf *filter,
100 : : bool add, bool wait_status);
101 : :
102 : : static int
103 : 0 : i40e_fdir_rx_queue_init(struct ci_rx_queue *rxq)
104 : : {
105 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->i40e_vsi);
106 : : struct i40e_hmc_obj_rxq rx_ctx;
107 : : int err = I40E_SUCCESS;
108 : :
109 : : memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
110 : : /* Init the RX queue in hardware */
111 : 0 : rx_ctx.dbuff = I40E_RXBUF_SZ_1024 >> I40E_RXQ_CTX_DBUFF_SHIFT;
112 : : rx_ctx.hbuff = 0;
113 : 0 : rx_ctx.base = rxq->rx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
114 : 0 : rx_ctx.qlen = rxq->nb_rx_desc;
115 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
116 : 0 : rx_ctx.dsize = 1;
117 : : #endif
118 : : rx_ctx.dtype = i40e_header_split_none;
119 : : rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_NONE;
120 : 0 : rx_ctx.rxmax = I40E_ETH_MAX_LEN;
121 : 0 : rx_ctx.tphrdesc_ena = 1;
122 : 0 : rx_ctx.tphwdesc_ena = 1;
123 : 0 : rx_ctx.tphdata_ena = 1;
124 : 0 : rx_ctx.tphhead_ena = 1;
125 : 0 : rx_ctx.lrxqthresh = 2;
126 : : rx_ctx.crcstrip = 0;
127 : 0 : rx_ctx.l2tsel = 1;
128 : : rx_ctx.showiv = 0;
129 : 0 : rx_ctx.prefena = 1;
130 : :
131 : 0 : err = i40e_clear_lan_rx_queue_context(hw, rxq->reg_idx);
132 [ # # ]: 0 : if (err != I40E_SUCCESS) {
133 : 0 : PMD_DRV_LOG(ERR, "Failed to clear FDIR RX queue context.");
134 : 0 : return err;
135 : : }
136 : 0 : err = i40e_set_lan_rx_queue_context(hw, rxq->reg_idx, &rx_ctx);
137 [ # # ]: 0 : if (err != I40E_SUCCESS) {
138 : 0 : PMD_DRV_LOG(ERR, "Failed to set FDIR RX queue context.");
139 : 0 : return err;
140 : : }
141 : 0 : rxq->qrx_tail = hw->hw_addr +
142 : 0 : I40E_QRX_TAIL(rxq->i40e_vsi->base_queue);
143 : :
144 : : rte_wmb();
145 : : /* Init the RX tail register. */
146 : 0 : I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
147 : :
148 : 0 : return err;
149 : : }
150 : :
151 : : /*
152 : : * i40e_fdir_setup - reserve and initialize the Flow Director resources
153 : : * @pf: board private structure
154 : : */
155 : : int
156 : 0 : i40e_fdir_setup(struct i40e_pf *pf)
157 : : {
158 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
159 : : struct i40e_vsi *vsi;
160 : : int err = I40E_SUCCESS;
161 : : char z_name[RTE_MEMZONE_NAMESIZE];
162 : : const struct rte_memzone *mz = NULL;
163 : 0 : struct rte_eth_dev *eth_dev = &rte_eth_devices[pf->dev_data->port_id];
164 : : uint16_t i;
165 : :
166 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_FDIR) == 0) {
167 : 0 : PMD_INIT_LOG(ERR, "HW doesn't support FDIR");
168 : 0 : return I40E_NOT_SUPPORTED;
169 : : }
170 : :
171 : 0 : PMD_DRV_LOG(INFO, "FDIR HW Capabilities: num_filters_guaranteed = %u,"
172 : : " num_filters_best_effort = %u.",
173 : : hw->func_caps.fd_filters_guaranteed,
174 : : hw->func_caps.fd_filters_best_effort);
175 : :
176 : 0 : vsi = pf->fdir.fdir_vsi;
177 [ # # ]: 0 : if (vsi) {
178 : 0 : PMD_DRV_LOG(INFO, "FDIR initialization has been done.");
179 : 0 : return I40E_SUCCESS;
180 : : }
181 : :
182 : : /* make new FDIR VSI */
183 : 0 : vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, pf->main_vsi, 0);
184 [ # # ]: 0 : if (!vsi) {
185 : 0 : PMD_DRV_LOG(ERR, "Couldn't create FDIR VSI.");
186 : 0 : return I40E_ERR_NO_AVAILABLE_VSI;
187 : : }
188 : 0 : pf->fdir.fdir_vsi = vsi;
189 : :
190 : : /*Fdir tx queue setup*/
191 : 0 : err = i40e_fdir_setup_tx_resources(pf);
192 [ # # ]: 0 : if (err) {
193 : 0 : PMD_DRV_LOG(ERR, "Failed to setup FDIR TX resources.");
194 : 0 : goto fail_setup_tx;
195 : : }
196 : :
197 : : /*Fdir rx queue setup*/
198 : 0 : err = i40e_fdir_setup_rx_resources(pf);
199 [ # # ]: 0 : if (err) {
200 : 0 : PMD_DRV_LOG(ERR, "Failed to setup FDIR RX resources.");
201 : 0 : goto fail_setup_rx;
202 : : }
203 : :
204 : 0 : err = i40e_tx_queue_init(pf->fdir.txq);
205 [ # # ]: 0 : if (err) {
206 : 0 : PMD_DRV_LOG(ERR, "Failed to do FDIR TX initialization.");
207 : 0 : goto fail_mem;
208 : : }
209 : :
210 : : /* need switch on before dev start*/
211 : 0 : err = i40e_switch_tx_queue(hw, vsi->base_queue, TRUE);
212 [ # # ]: 0 : if (err) {
213 : 0 : PMD_DRV_LOG(ERR, "Failed to do fdir TX switch on.");
214 : 0 : goto fail_mem;
215 : : }
216 : :
217 : : /* Init the rx queue in hardware */
218 : 0 : err = i40e_fdir_rx_queue_init(pf->fdir.rxq);
219 [ # # ]: 0 : if (err) {
220 : 0 : PMD_DRV_LOG(ERR, "Failed to do FDIR RX initialization.");
221 : 0 : goto fail_mem;
222 : : }
223 : :
224 : : /* switch on rx queue */
225 : 0 : err = i40e_switch_rx_queue(hw, vsi->base_queue, TRUE);
226 [ # # ]: 0 : if (err) {
227 : 0 : PMD_DRV_LOG(ERR, "Failed to do FDIR RX switch on.");
228 : 0 : goto fail_mem;
229 : : }
230 : :
231 : : /* enable FDIR MSIX interrupt */
232 : 0 : vsi->nb_used_qps = 1;
233 : 0 : i40e_vsi_queues_bind_intr(vsi, I40E_ITR_INDEX_NONE);
234 : 0 : i40e_vsi_enable_queues_intr(vsi);
235 : :
236 : : /* reserve memory for the fdir programming packet */
237 : 0 : snprintf(z_name, sizeof(z_name), "%s_%s_%d",
238 : 0 : eth_dev->device->driver->name,
239 : : I40E_FDIR_MZ_NAME,
240 : 0 : eth_dev->data->port_id);
241 : 0 : mz = i40e_memzone_reserve(z_name, I40E_FDIR_PKT_LEN *
242 : : I40E_FDIR_PRG_PKT_CNT, SOCKET_ID_ANY);
243 [ # # ]: 0 : if (!mz) {
244 : 0 : PMD_DRV_LOG(ERR, "Cannot init memzone for "
245 : : "flow director program packet.");
246 : : err = I40E_ERR_NO_MEMORY;
247 : 0 : goto fail_mem;
248 : : }
249 : :
250 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_PRG_PKT_CNT; i++) {
251 : 0 : pf->fdir.prg_pkt[i] = (uint8_t *)mz->addr +
252 : 0 : I40E_FDIR_PKT_LEN * i;
253 : 0 : pf->fdir.dma_addr[i] = mz->iova +
254 : : I40E_FDIR_PKT_LEN * i;
255 : : }
256 : :
257 : 0 : pf->fdir.match_counter_index = I40E_COUNTER_INDEX_FDIR(hw->pf_id);
258 : 0 : pf->fdir.fdir_actual_cnt = 0;
259 : 0 : pf->fdir.fdir_guarantee_free_space =
260 : 0 : pf->fdir.fdir_guarantee_total_space;
261 : :
262 : 0 : PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
263 : : vsi->base_queue);
264 : 0 : return I40E_SUCCESS;
265 : :
266 : 0 : fail_mem:
267 : 0 : i40e_rx_queue_release(pf->fdir.rxq);
268 : 0 : pf->fdir.rxq = NULL;
269 : 0 : fail_setup_rx:
270 : 0 : i40e_tx_queue_release(pf->fdir.txq);
271 : 0 : pf->fdir.txq = NULL;
272 : 0 : fail_setup_tx:
273 : 0 : i40e_vsi_release(vsi);
274 : 0 : pf->fdir.fdir_vsi = NULL;
275 : 0 : return err;
276 : : }
277 : :
278 : : /*
279 : : * i40e_fdir_teardown - release the Flow Director resources
280 : : * @pf: board private structure
281 : : */
282 : : void
283 : 0 : i40e_fdir_teardown(struct i40e_pf *pf)
284 : : {
285 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
286 : : struct i40e_vsi *vsi;
287 : :
288 : 0 : vsi = pf->fdir.fdir_vsi;
289 [ # # ]: 0 : if (!vsi)
290 : : return;
291 : :
292 : : /* disable FDIR MSIX interrupt */
293 : 0 : i40e_vsi_queues_unbind_intr(vsi);
294 : 0 : i40e_vsi_disable_queues_intr(vsi);
295 : :
296 : 0 : int err = i40e_switch_tx_queue(hw, vsi->base_queue, FALSE);
297 [ # # ]: 0 : if (err)
298 : 0 : PMD_DRV_LOG(DEBUG, "Failed to do FDIR TX switch off");
299 : 0 : err = i40e_switch_rx_queue(hw, vsi->base_queue, FALSE);
300 [ # # ]: 0 : if (err)
301 : 0 : PMD_DRV_LOG(DEBUG, "Failed to do FDIR RX switch off");
302 : :
303 : 0 : i40e_rx_queue_release(pf->fdir.rxq);
304 : 0 : pf->fdir.rxq = NULL;
305 : 0 : i40e_tx_queue_release(pf->fdir.txq);
306 : 0 : pf->fdir.txq = NULL;
307 : 0 : i40e_vsi_release(vsi);
308 : 0 : pf->fdir.fdir_vsi = NULL;
309 : : }
310 : :
311 : : /* check whether the flow director table in empty */
312 : : static inline int
313 : : i40e_fdir_empty(struct i40e_hw *hw)
314 : : {
315 : : uint32_t guarant_cnt, best_cnt;
316 : :
317 : 0 : guarant_cnt = (uint32_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
318 : : I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
319 : : I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
320 : 0 : best_cnt = (uint32_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
321 : 0 : I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
322 : : I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
323 [ # # ]: 0 : if (best_cnt + guarant_cnt > 0)
324 : : return -1;
325 : :
326 : : return 0;
327 : : }
328 : :
329 : : /*
330 : : * Initialize the configuration about bytes stream extracted as flexible payload
331 : : * and mask setting
332 : : */
333 : : static inline void
334 : 0 : i40e_init_flx_pld(struct i40e_pf *pf)
335 : : {
336 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
337 : : uint8_t pctype;
338 : : int i, index;
339 : : uint16_t flow_type;
340 : :
341 : : /*
342 : : * Define the bytes stream extracted as flexible payload in
343 : : * field vector. By default, select 8 words from the beginning
344 : : * of payload as flexible payload.
345 : : */
346 [ # # ]: 0 : for (i = I40E_FLXPLD_L2_IDX; i < I40E_MAX_FLXPLD_LAYER; i++) {
347 : 0 : index = i * I40E_MAX_FLXPLD_FIED;
348 : 0 : pf->fdir.flex_set[index].src_offset = 0;
349 : 0 : pf->fdir.flex_set[index].size = I40E_FDIR_MAX_FLEXWORD_NUM;
350 : 0 : pf->fdir.flex_set[index].dst_offset = 0;
351 : 0 : I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(index), 0x0000C900);
352 : 0 : I40E_WRITE_REG(hw,
353 : : I40E_PRTQF_FLX_PIT(index + 1), 0x0000FC29);/*non-used*/
354 : 0 : I40E_WRITE_REG(hw,
355 : : I40E_PRTQF_FLX_PIT(index + 2), 0x0000FC2A);/*non-used*/
356 : 0 : pf->fdir.flex_pit_flag[i] = 0;
357 : : }
358 : :
359 : : /* initialize the masks */
360 : : for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
361 [ # # ]: 0 : pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
362 : 0 : flow_type = i40e_pctype_to_flowtype(pf->adapter, pctype);
363 : :
364 [ # # ]: 0 : if (flow_type == RTE_ETH_FLOW_UNKNOWN)
365 : 0 : continue;
366 : 0 : pf->fdir.flex_mask[pctype].word_mask = 0;
367 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_FD_FLXINSET(pctype), 0);
368 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_BITMASK_NUM_WORD; i++) {
369 : 0 : pf->fdir.flex_mask[pctype].bitmask[i].offset = 0;
370 : 0 : pf->fdir.flex_mask[pctype].bitmask[i].mask = 0;
371 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_FD_MSK(pctype, i), 0);
372 : : }
373 : : }
374 : 0 : }
375 : :
376 : : /*
377 : : * Enable/disable flow director RX processing in vector routines.
378 : : */
379 : : void
380 : 0 : i40e_fdir_rx_proc_enable(struct rte_eth_dev *dev, bool on)
381 : : {
382 : : int32_t i;
383 : :
384 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
385 : 0 : struct ci_rx_queue *rxq = dev->data->rx_queues[i];
386 [ # # ]: 0 : if (!rxq)
387 : 0 : continue;
388 : 0 : rxq->fdir_enabled = on;
389 : : }
390 : 0 : PMD_DRV_LOG(DEBUG, "Flow Director processing on RX set to %d", on);
391 : 0 : }
392 : :
393 : : /*
394 : : * Configure flow director related setting
395 : : */
396 : : int
397 : 0 : i40e_fdir_configure(struct rte_eth_dev *dev)
398 : : {
399 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
400 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
401 : : uint32_t val;
402 : : int ret = 0;
403 : :
404 : : /*
405 : : * configuration need to be done before
406 : : * flow director filters are added
407 : : * If filters exist, flush them.
408 : : */
409 : : if (i40e_fdir_empty(hw) < 0) {
410 : 0 : ret = i40e_fdir_flush(dev);
411 [ # # ]: 0 : if (ret) {
412 : 0 : PMD_DRV_LOG(ERR, "failed to flush fdir table.");
413 : 0 : return ret;
414 : : }
415 : : }
416 : :
417 : : /* enable FDIR filter */
418 : 0 : val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
419 : 0 : val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
420 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
421 : :
422 : 0 : i40e_init_flx_pld(pf); /* set flex config to default value */
423 : :
424 : : /* Enable FDIR processing in RX routines */
425 : 0 : i40e_fdir_rx_proc_enable(dev, 1);
426 : :
427 : 0 : return ret;
428 : : }
429 : :
430 : :
431 : : static struct i40e_customized_pctype *
432 : : i40e_flow_fdir_find_customized_pctype(struct i40e_pf *pf, uint8_t pctype)
433 : : {
434 : : struct i40e_customized_pctype *cus_pctype;
435 : : enum i40e_new_pctype i = I40E_CUSTOMIZED_GTPC;
436 : :
437 [ # # # # ]: 0 : for (; i < I40E_CUSTOMIZED_MAX; i++) {
438 : 0 : cus_pctype = &pf->customized_pctype[i];
439 [ # # # # ]: 0 : if (pctype == cus_pctype->pctype)
440 : : return cus_pctype;
441 : : }
442 : : return NULL;
443 : : }
444 : :
445 : : static inline int
446 : 0 : fill_ip6_head(const struct i40e_fdir_input *fdir_input, unsigned char *raw_pkt,
447 : : uint8_t next_proto, uint8_t len, uint16_t *ether_type)
448 : : {
449 : : struct rte_ipv6_hdr *ip6;
450 : :
451 : : ip6 = (struct rte_ipv6_hdr *)raw_pkt;
452 : :
453 : 0 : *ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
454 [ # # ]: 0 : ip6->vtc_flow = rte_cpu_to_be_32(I40E_FDIR_IPv6_DEFAULT_VTC_FLOW |
455 : : (fdir_input->flow.ipv6_flow.tc << I40E_FDIR_IPv6_TC_OFFSET));
456 : 0 : ip6->payload_len = rte_cpu_to_be_16(I40E_FDIR_IPv6_PAYLOAD_LEN);
457 [ # # ]: 0 : ip6->proto = fdir_input->flow.ipv6_flow.proto ?
458 : : fdir_input->flow.ipv6_flow.proto : next_proto;
459 [ # # ]: 0 : ip6->hop_limits = fdir_input->flow.ipv6_flow.hop_limits ?
460 : : fdir_input->flow.ipv6_flow.hop_limits :
461 : : I40E_FDIR_IPv6_DEFAULT_HOP_LIMITS;
462 : : /**
463 : : * The source and destination fields in the transmitted packet
464 : : * need to be presented in a reversed order with respect
465 : : * to the expected received packets.
466 : : */
467 [ # # ]: 0 : rte_memcpy(&ip6->src_addr, &fdir_input->flow.ipv6_flow.dst_ip,
468 : : IPV6_ADDR_LEN);
469 [ # # ]: 0 : rte_memcpy(&ip6->dst_addr, &fdir_input->flow.ipv6_flow.src_ip,
470 : : IPV6_ADDR_LEN);
471 : 0 : len += sizeof(struct rte_ipv6_hdr);
472 : :
473 : 0 : return len;
474 : : }
475 : :
476 : : static inline int
477 : : fill_ip4_head(const struct i40e_fdir_input *fdir_input, unsigned char *raw_pkt,
478 : : uint8_t next_proto, uint8_t len, uint16_t *ether_type)
479 : : {
480 : : struct rte_ipv4_hdr *ip4;
481 : :
482 : : ip4 = (struct rte_ipv4_hdr *)raw_pkt;
483 : :
484 : 0 : *ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
485 : 0 : ip4->version_ihl = I40E_FDIR_IP_DEFAULT_VERSION_IHL;
486 : : /* set len to by default */
487 : 0 : ip4->total_length = rte_cpu_to_be_16(I40E_FDIR_IP_DEFAULT_LEN);
488 [ # # # # : 0 : ip4->time_to_live = fdir_input->flow.ip4_flow.ttl ?
# # # # ]
489 : : fdir_input->flow.ip4_flow.ttl :
490 : : I40E_FDIR_IP_DEFAULT_TTL;
491 : 0 : ip4->type_of_service = fdir_input->flow.ip4_flow.tos;
492 [ # # # # : 0 : ip4->next_proto_id = fdir_input->flow.ip4_flow.proto ?
# # # # #
# ]
493 : : fdir_input->flow.ip4_flow.proto : next_proto;
494 : : /**
495 : : * The source and destination fields in the transmitted packet
496 : : * need to be presented in a reversed order with respect
497 : : * to the expected received packets.
498 : : */
499 : 0 : ip4->src_addr = fdir_input->flow.ip4_flow.dst_ip;
500 : 0 : ip4->dst_addr = fdir_input->flow.ip4_flow.src_ip;
501 : 0 : len += sizeof(struct rte_ipv4_hdr);
502 : :
503 : : return len;
504 : : }
505 : :
506 : : static inline int
507 : 0 : i40e_flow_fdir_fill_eth_ip_head(struct i40e_pf *pf,
508 : : const struct i40e_fdir_input *fdir_input,
509 : : unsigned char *raw_pkt,
510 : : bool vlan)
511 : : {
512 : : struct i40e_customized_pctype *cus_pctype = NULL;
513 : : static uint8_t vlan_frame[] = {0x81, 0, 0, 0};
514 : : uint16_t *ether_type;
515 : : uint8_t len = 2 * sizeof(struct rte_ether_addr);
516 : 0 : uint8_t pctype = fdir_input->pctype;
517 : 0 : bool is_customized_pctype = fdir_input->flow_ext.customized_pctype;
518 : : static const uint8_t next_proto[] = {
519 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] = IPPROTO_IP,
520 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] = IPPROTO_TCP,
521 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] = IPPROTO_UDP,
522 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] = IPPROTO_SCTP,
523 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] = IPPROTO_IP,
524 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] = IPPROTO_NONE,
525 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] = IPPROTO_TCP,
526 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] = IPPROTO_UDP,
527 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] = IPPROTO_SCTP,
528 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] = IPPROTO_NONE,
529 : : };
530 : :
531 [ # # ]: 0 : rte_memcpy(raw_pkt, &fdir_input->flow.l2_flow.dst,
532 : : sizeof(struct rte_ether_addr));
533 : 0 : rte_memcpy(raw_pkt + sizeof(struct rte_ether_addr),
534 [ # # ]: 0 : &fdir_input->flow.l2_flow.src,
535 : : sizeof(struct rte_ether_addr));
536 : 0 : raw_pkt += 2 * sizeof(struct rte_ether_addr);
537 : :
538 [ # # # # ]: 0 : if (vlan && fdir_input->flow_ext.vlan_tci) {
539 : : rte_memcpy(raw_pkt, vlan_frame, sizeof(vlan_frame));
540 : 0 : rte_memcpy(raw_pkt + sizeof(uint16_t),
541 [ # # ]: 0 : &fdir_input->flow_ext.vlan_tci,
542 : : sizeof(uint16_t));
543 : 0 : raw_pkt += sizeof(vlan_frame);
544 : : len += sizeof(vlan_frame);
545 : : }
546 : : ether_type = (uint16_t *)raw_pkt;
547 : 0 : raw_pkt += sizeof(uint16_t);
548 : 0 : len += sizeof(uint16_t);
549 : :
550 [ # # ]: 0 : if (is_customized_pctype) {
551 : : cus_pctype = i40e_flow_fdir_find_customized_pctype(pf, pctype);
552 [ # # ]: 0 : if (!cus_pctype) {
553 : 0 : PMD_DRV_LOG(ERR, "unknown pctype %u.",
554 : : fdir_input->pctype);
555 : 0 : return -1;
556 : : }
557 : : }
558 : :
559 [ # # ]: 0 : if (pctype == I40E_FILTER_PCTYPE_L2_PAYLOAD)
560 : 0 : *ether_type = fdir_input->flow.l2_flow.ether_type;
561 : 0 : else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_TCP ||
562 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_NONF_IPV4_UDP ||
563 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_NONF_IPV4_SCTP ||
564 : : pctype == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER ||
565 : : pctype == I40E_FILTER_PCTYPE_FRAG_IPV4 ||
566 : : pctype == I40E_FILTER_PCTYPE_NONF_IPV6_TCP ||
567 : : pctype == I40E_FILTER_PCTYPE_NONF_IPV6_UDP ||
568 : : pctype == I40E_FILTER_PCTYPE_NONF_IPV6_SCTP ||
569 : : pctype == I40E_FILTER_PCTYPE_NONF_IPV6_OTHER ||
570 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_FRAG_IPV6 ||
571 : : is_customized_pctype) {
572 [ # # ]: 0 : if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_TCP ||
573 : : pctype == I40E_FILTER_PCTYPE_NONF_IPV4_UDP ||
574 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_NONF_IPV4_SCTP ||
575 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER ||
576 : : pctype == I40E_FILTER_PCTYPE_FRAG_IPV4) {
577 : 0 : len = fill_ip4_head(fdir_input, raw_pkt,
578 [ # # ]: 0 : next_proto[pctype], len, ether_type);
579 : 0 : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_TCP ||
580 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_NONF_IPV6_UDP ||
581 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_NONF_IPV6_SCTP ||
582 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_NONF_IPV6_OTHER ||
583 : : pctype == I40E_FILTER_PCTYPE_FRAG_IPV6) {
584 : 0 : len = fill_ip6_head(fdir_input, raw_pkt,
585 : 0 : next_proto[pctype], len,
586 : : ether_type);
587 [ # # ]: 0 : } else if (cus_pctype->index == I40E_CUSTOMIZED_GTPC ||
588 : : cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV4 ||
589 : : cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV6 ||
590 : : cus_pctype->index == I40E_CUSTOMIZED_GTPU) {
591 : : len = fill_ip4_head(fdir_input, raw_pkt, IPPROTO_UDP,
592 : : len, ether_type);
593 : : } else if (cus_pctype->index == I40E_CUSTOMIZED_IPV4_L2TPV3) {
594 : : len = fill_ip4_head(fdir_input, raw_pkt, IPPROTO_L2TP,
595 : : len, ether_type);
596 : : } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4) {
597 : : len = fill_ip4_head(fdir_input, raw_pkt, IPPROTO_ESP,
598 : : len, ether_type);
599 : : } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4_UDP) {
600 : : len = fill_ip4_head(fdir_input, raw_pkt, IPPROTO_UDP,
601 : : len, ether_type);
602 : : } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6) {
603 : 0 : len = fill_ip6_head(fdir_input, raw_pkt, IPPROTO_ESP,
604 : : len, ether_type);
605 : : } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6_UDP) {
606 : 0 : len = fill_ip6_head(fdir_input, raw_pkt, IPPROTO_UDP,
607 : : len, ether_type);
608 : : } else if (cus_pctype->index == I40E_CUSTOMIZED_IPV6_L2TPV3) {
609 : 0 : len = fill_ip6_head(fdir_input, raw_pkt, IPPROTO_L2TP,
610 : : len, ether_type);
611 : : }
612 : : } else {
613 : 0 : PMD_DRV_LOG(ERR, "unknown pctype %u.", fdir_input->pctype);
614 : 0 : return -1;
615 : : }
616 : :
617 : 0 : return len;
618 : : }
619 : :
620 : : /**
621 : : * i40e_flow_fdir_construct_pkt - construct packet based on fields in input
622 : : * @pf: board private structure
623 : : * @fdir_input: input set of the flow director entry
624 : : * @raw_pkt: a packet to be constructed
625 : : */
626 : : static int
627 : 0 : i40e_flow_fdir_construct_pkt(struct i40e_pf *pf,
628 : : const struct i40e_fdir_input *fdir_input,
629 : : unsigned char *raw_pkt)
630 : : {
631 : : unsigned char *payload = NULL;
632 : : unsigned char *ptr;
633 : : struct rte_udp_hdr *udp;
634 : : struct rte_tcp_hdr *tcp;
635 : : struct rte_sctp_hdr *sctp;
636 : : struct rte_flow_item_gtp *gtp;
637 : : struct rte_ipv4_hdr *gtp_ipv4;
638 : : struct rte_ipv6_hdr *gtp_ipv6;
639 : : struct rte_flow_item_l2tpv3oip *l2tpv3oip;
640 : : struct rte_flow_item_esp *esp;
641 : : struct rte_ipv4_hdr *esp_ipv4;
642 : : struct rte_ipv6_hdr *esp_ipv6;
643 : :
644 : : uint8_t size, dst = 0;
645 : : uint8_t i, pit_idx, set_idx = I40E_FLXPLD_L4_IDX; /* use l4 by default*/
646 : : int len;
647 : 0 : uint8_t pctype = fdir_input->pctype;
648 : : struct i40e_customized_pctype *cus_pctype;
649 : :
650 : : /* raw packet template - just copy contents of the raw packet */
651 [ # # ]: 0 : if (fdir_input->flow_ext.pkt_template) {
652 : 0 : memcpy(raw_pkt, fdir_input->flow.raw_flow.packet,
653 : 0 : fdir_input->flow.raw_flow.length);
654 : 0 : return 0;
655 : : }
656 : :
657 : : /* fill the ethernet and IP head */
658 : 0 : len = i40e_flow_fdir_fill_eth_ip_head(pf, fdir_input, raw_pkt,
659 : 0 : !!fdir_input->flow_ext.vlan_tci);
660 [ # # ]: 0 : if (len < 0)
661 : : return -EINVAL;
662 : :
663 : : /* fill the L4 head */
664 : : if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_UDP) {
665 : 0 : udp = (struct rte_udp_hdr *)(raw_pkt + len);
666 : 0 : payload = (unsigned char *)udp + sizeof(struct rte_udp_hdr);
667 : : /**
668 : : * The source and destination fields in the transmitted packet
669 : : * need to be presented in a reversed order with respect
670 : : * to the expected received packets.
671 : : */
672 : 0 : udp->src_port = fdir_input->flow.udp4_flow.dst_port;
673 : 0 : udp->dst_port = fdir_input->flow.udp4_flow.src_port;
674 : 0 : udp->dgram_len = rte_cpu_to_be_16(I40E_FDIR_UDP_DEFAULT_LEN);
675 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_TCP) {
676 : 0 : tcp = (struct rte_tcp_hdr *)(raw_pkt + len);
677 : 0 : payload = (unsigned char *)tcp + sizeof(struct rte_tcp_hdr);
678 : : /**
679 : : * The source and destination fields in the transmitted packet
680 : : * need to be presented in a reversed order with respect
681 : : * to the expected received packets.
682 : : */
683 : 0 : tcp->src_port = fdir_input->flow.tcp4_flow.dst_port;
684 : 0 : tcp->dst_port = fdir_input->flow.tcp4_flow.src_port;
685 : 0 : tcp->data_off = I40E_FDIR_TCP_DEFAULT_DATAOFF;
686 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) {
687 : 0 : sctp = (struct rte_sctp_hdr *)(raw_pkt + len);
688 : 0 : payload = (unsigned char *)sctp + sizeof(struct rte_sctp_hdr);
689 : : /**
690 : : * The source and destination fields in the transmitted packet
691 : : * need to be presented in a reversed order with respect
692 : : * to the expected received packets.
693 : : */
694 : 0 : sctp->src_port = fdir_input->flow.sctp4_flow.dst_port;
695 : 0 : sctp->dst_port = fdir_input->flow.sctp4_flow.src_port;
696 : 0 : sctp->tag = fdir_input->flow.sctp4_flow.verify_tag;
697 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER ||
698 : : pctype == I40E_FILTER_PCTYPE_FRAG_IPV4) {
699 : 0 : payload = raw_pkt + len;
700 : : set_idx = I40E_FLXPLD_L3_IDX;
701 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_UDP) {
702 : 0 : udp = (struct rte_udp_hdr *)(raw_pkt + len);
703 : 0 : payload = (unsigned char *)udp + sizeof(struct rte_udp_hdr);
704 : : /**
705 : : * The source and destination fields in the transmitted packet
706 : : * need to be presented in a reversed order with respect
707 : : * to the expected received packets.
708 : : */
709 : 0 : udp->src_port = fdir_input->flow.udp6_flow.dst_port;
710 : 0 : udp->dst_port = fdir_input->flow.udp6_flow.src_port;
711 : 0 : udp->dgram_len = rte_cpu_to_be_16(I40E_FDIR_IPv6_PAYLOAD_LEN);
712 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_TCP) {
713 : 0 : tcp = (struct rte_tcp_hdr *)(raw_pkt + len);
714 : 0 : payload = (unsigned char *)tcp + sizeof(struct rte_tcp_hdr);
715 : : /**
716 : : * The source and destination fields in the transmitted packet
717 : : * need to be presented in a reversed order with respect
718 : : * to the expected received packets.
719 : : */
720 : 0 : tcp->data_off = I40E_FDIR_TCP_DEFAULT_DATAOFF;
721 : 0 : tcp->src_port = fdir_input->flow.udp6_flow.dst_port;
722 : 0 : tcp->dst_port = fdir_input->flow.udp6_flow.src_port;
723 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) {
724 : 0 : sctp = (struct rte_sctp_hdr *)(raw_pkt + len);
725 : 0 : payload = (unsigned char *)sctp + sizeof(struct rte_sctp_hdr);
726 : : /**
727 : : * The source and destination fields in the transmitted packet
728 : : * need to be presented in a reversed order with respect
729 : : * to the expected received packets.
730 : : */
731 : 0 : sctp->src_port = fdir_input->flow.sctp6_flow.dst_port;
732 : 0 : sctp->dst_port = fdir_input->flow.sctp6_flow.src_port;
733 : 0 : sctp->tag = fdir_input->flow.sctp6_flow.verify_tag;
734 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_OTHER ||
735 : : pctype == I40E_FILTER_PCTYPE_FRAG_IPV6) {
736 : 0 : payload = raw_pkt + len;
737 : : set_idx = I40E_FLXPLD_L3_IDX;
738 : : } else if (pctype == I40E_FILTER_PCTYPE_L2_PAYLOAD) {
739 : 0 : payload = raw_pkt + len;
740 : : /**
741 : : * ARP packet is a special case on which the payload
742 : : * starts after the whole ARP header
743 : : */
744 [ # # ]: 0 : if (fdir_input->flow.l2_flow.ether_type ==
745 : : rte_cpu_to_be_16(RTE_ETHER_TYPE_ARP))
746 : 0 : payload += sizeof(struct rte_arp_hdr);
747 : : set_idx = I40E_FLXPLD_L2_IDX;
748 [ # # ]: 0 : } else if (fdir_input->flow_ext.customized_pctype) {
749 : : /* If customized pctype is used */
750 : : cus_pctype = i40e_flow_fdir_find_customized_pctype(pf, pctype);
751 [ # # ]: 0 : if (cus_pctype->index == I40E_CUSTOMIZED_GTPC ||
752 : : cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV4 ||
753 : : cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV6 ||
754 : : cus_pctype->index == I40E_CUSTOMIZED_GTPU) {
755 : 0 : udp = (struct rte_udp_hdr *)(raw_pkt + len);
756 : 0 : udp->dgram_len =
757 : : rte_cpu_to_be_16(I40E_FDIR_UDP_DEFAULT_LEN);
758 : :
759 : : gtp = (struct rte_flow_item_gtp *)
760 : : ((unsigned char *)udp +
761 : : sizeof(struct rte_udp_hdr));
762 : 0 : gtp->hdr.plen =
763 : : rte_cpu_to_be_16(I40E_FDIR_GTP_DEFAULT_LEN);
764 : 0 : gtp->hdr.teid = fdir_input->flow.gtp_flow.teid;
765 : 0 : gtp->hdr.msg_type = I40E_FDIR_GTP_MSG_TYPE_0X01;
766 : :
767 : : /* GTP-C message type is not supported. */
768 [ # # ]: 0 : if (cus_pctype->index == I40E_CUSTOMIZED_GTPC) {
769 : 0 : udp->dst_port =
770 : : rte_cpu_to_be_16(I40E_FDIR_GTPC_DST_PORT);
771 : 0 : gtp->hdr.gtp_hdr_info =
772 : : I40E_FDIR_GTP_VER_FLAG_0X32;
773 : : } else {
774 : 0 : udp->dst_port =
775 : : rte_cpu_to_be_16(I40E_FDIR_GTPU_DST_PORT);
776 : 0 : gtp->hdr.gtp_hdr_info =
777 : : I40E_FDIR_GTP_VER_FLAG_0X30;
778 : : }
779 : :
780 [ # # ]: 0 : if (cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV4) {
781 : 0 : gtp->hdr.msg_type = I40E_FDIR_GTP_MSG_TYPE_0XFF;
782 : : gtp_ipv4 = (struct rte_ipv4_hdr *)
783 : : ((unsigned char *)gtp +
784 : : sizeof(struct rte_flow_item_gtp));
785 : 0 : gtp_ipv4->version_ihl =
786 : : I40E_FDIR_IP_DEFAULT_VERSION_IHL;
787 : 0 : gtp_ipv4->next_proto_id = IPPROTO_IP;
788 : 0 : gtp_ipv4->total_length =
789 : : rte_cpu_to_be_16(
790 : : I40E_FDIR_INNER_IP_DEFAULT_LEN);
791 : 0 : payload = (unsigned char *)gtp_ipv4 +
792 : : sizeof(struct rte_ipv4_hdr);
793 [ # # ]: 0 : } else if (cus_pctype->index ==
794 : : I40E_CUSTOMIZED_GTPU_IPV6) {
795 : 0 : gtp->hdr.msg_type = I40E_FDIR_GTP_MSG_TYPE_0XFF;
796 : : gtp_ipv6 = (struct rte_ipv6_hdr *)
797 : : ((unsigned char *)gtp +
798 : : sizeof(struct rte_flow_item_gtp));
799 : 0 : gtp_ipv6->vtc_flow =
800 : : rte_cpu_to_be_32(
801 : : I40E_FDIR_IPv6_DEFAULT_VTC_FLOW |
802 : : (0 << I40E_FDIR_IPv6_TC_OFFSET));
803 : 0 : gtp_ipv6->proto = IPPROTO_NONE;
804 : 0 : gtp_ipv6->payload_len =
805 : : rte_cpu_to_be_16(
806 : : I40E_FDIR_INNER_IPV6_DEFAULT_LEN);
807 : 0 : gtp_ipv6->hop_limits =
808 : : I40E_FDIR_IPv6_DEFAULT_HOP_LIMITS;
809 : 0 : payload = (unsigned char *)gtp_ipv6 +
810 : : sizeof(struct rte_ipv6_hdr);
811 : : } else
812 : 0 : payload = (unsigned char *)gtp +
813 : : sizeof(struct rte_flow_item_gtp);
814 [ # # ]: 0 : } else if (cus_pctype->index == I40E_CUSTOMIZED_IPV4_L2TPV3 ||
815 : : cus_pctype->index == I40E_CUSTOMIZED_IPV6_L2TPV3) {
816 : 0 : l2tpv3oip = (struct rte_flow_item_l2tpv3oip *)(raw_pkt
817 : 0 : + len);
818 : :
819 [ # # ]: 0 : if (cus_pctype->index == I40E_CUSTOMIZED_IPV4_L2TPV3)
820 : 0 : l2tpv3oip->session_id =
821 : 0 : fdir_input->flow.ip4_l2tpv3oip_flow.session_id;
822 : : else
823 : 0 : l2tpv3oip->session_id =
824 : 0 : fdir_input->flow.ip6_l2tpv3oip_flow.session_id;
825 : 0 : payload = (unsigned char *)l2tpv3oip +
826 : : sizeof(struct rte_flow_item_l2tpv3oip);
827 : 0 : } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4 ||
828 : : cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6 ||
829 [ # # ]: 0 : cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4_UDP ||
830 : : cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6_UDP) {
831 [ # # ]: 0 : if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4) {
832 : 0 : esp_ipv4 = (struct rte_ipv4_hdr *)
833 : 0 : (raw_pkt + len);
834 : : esp = (struct rte_flow_item_esp *)esp_ipv4;
835 : 0 : esp->hdr.spi =
836 : 0 : fdir_input->flow.esp_ipv4_flow.spi;
837 : 0 : payload = (unsigned char *)esp +
838 : : sizeof(struct rte_esp_hdr);
839 : : len += sizeof(struct rte_esp_hdr);
840 [ # # ]: 0 : } else if (cus_pctype->index ==
841 : : I40E_CUSTOMIZED_ESP_IPV4_UDP) {
842 : 0 : esp_ipv4 = (struct rte_ipv4_hdr *)
843 : 0 : (raw_pkt + len);
844 : : udp = (struct rte_udp_hdr *)esp_ipv4;
845 : 0 : udp->dst_port = rte_cpu_to_be_16
846 : : (I40E_FDIR_ESP_DST_PORT);
847 : :
848 : 0 : udp->dgram_len = rte_cpu_to_be_16
849 : : (I40E_FDIR_UDP_DEFAULT_LEN);
850 : : esp = (struct rte_flow_item_esp *)
851 : : ((unsigned char *)esp_ipv4 +
852 : : sizeof(struct rte_udp_hdr));
853 : 0 : esp->hdr.spi =
854 : 0 : fdir_input->flow.esp_ipv4_udp_flow.spi;
855 : 0 : payload = (unsigned char *)esp +
856 : : sizeof(struct rte_esp_hdr);
857 : : len += sizeof(struct rte_udp_hdr) +
858 : : sizeof(struct rte_esp_hdr);
859 [ # # ]: 0 : } else if (cus_pctype->index ==
860 : : I40E_CUSTOMIZED_ESP_IPV6) {
861 : 0 : esp_ipv6 = (struct rte_ipv6_hdr *)
862 : 0 : (raw_pkt + len);
863 : : esp = (struct rte_flow_item_esp *)esp_ipv6;
864 : 0 : esp->hdr.spi =
865 : 0 : fdir_input->flow.esp_ipv6_flow.spi;
866 : 0 : payload = (unsigned char *)esp +
867 : : sizeof(struct rte_esp_hdr);
868 : : len += sizeof(struct rte_esp_hdr);
869 : : } else if (cus_pctype->index ==
870 : : I40E_CUSTOMIZED_ESP_IPV6_UDP) {
871 : 0 : esp_ipv6 = (struct rte_ipv6_hdr *)
872 : 0 : (raw_pkt + len);
873 : : udp = (struct rte_udp_hdr *)esp_ipv6;
874 : 0 : udp->dst_port = rte_cpu_to_be_16
875 : : (I40E_FDIR_ESP_DST_PORT);
876 : :
877 : 0 : udp->dgram_len = rte_cpu_to_be_16
878 : : (I40E_FDIR_UDP_DEFAULT_LEN);
879 : : esp = (struct rte_flow_item_esp *)
880 : : ((unsigned char *)esp_ipv6 +
881 : : sizeof(struct rte_udp_hdr));
882 : 0 : esp->hdr.spi =
883 : 0 : fdir_input->flow.esp_ipv6_udp_flow.spi;
884 : 0 : payload = (unsigned char *)esp +
885 : : sizeof(struct rte_esp_hdr);
886 : : len += sizeof(struct rte_udp_hdr) +
887 : : sizeof(struct rte_esp_hdr);
888 : : }
889 : : }
890 : : } else {
891 : 0 : PMD_DRV_LOG(ERR, "unknown pctype %u.", fdir_input->pctype);
892 : 0 : return -1;
893 : : }
894 : :
895 : : /* fill the flexbytes to payload */
896 [ # # ]: 0 : for (i = 0; i < I40E_MAX_FLXPLD_FIED; i++) {
897 : 0 : pit_idx = set_idx * I40E_MAX_FLXPLD_FIED + i;
898 : 0 : size = pf->fdir.flex_set[pit_idx].size;
899 [ # # ]: 0 : if (size == 0)
900 : 0 : continue;
901 : 0 : dst = pf->fdir.flex_set[pit_idx].dst_offset * sizeof(uint16_t);
902 : 0 : ptr = payload +
903 : 0 : pf->fdir.flex_set[pit_idx].src_offset * sizeof(uint16_t);
904 : 0 : (void)rte_memcpy(ptr,
905 [ # # ]: 0 : &fdir_input->flow_ext.flexbytes[dst],
906 : : size * sizeof(uint16_t));
907 : : }
908 : :
909 : : return 0;
910 : : }
911 : :
912 : : /* Construct the tx flags */
913 : : static inline uint64_t
914 : : i40e_build_ctob(uint32_t td_cmd,
915 : : uint32_t td_offset,
916 : : unsigned int size,
917 : : uint32_t td_tag)
918 : : {
919 : : return rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DATA |
920 : : ((uint64_t)td_cmd << I40E_TXD_QW1_CMD_SHIFT) |
921 : : ((uint64_t)td_offset << I40E_TXD_QW1_OFFSET_SHIFT) |
922 : : ((uint64_t)size << I40E_TXD_QW1_TX_BUF_SZ_SHIFT) |
923 : : ((uint64_t)td_tag << I40E_TXD_QW1_L2TAG1_SHIFT));
924 : : }
925 : :
926 : : /*
927 : : * check the programming status descriptor in rx queue.
928 : : * done after Programming Flow Director is programmed on
929 : : * tx queue
930 : : */
931 : : static inline int
932 : 0 : i40e_check_fdir_programming_status(struct ci_rx_queue *rxq)
933 : : {
934 : : volatile union ci_rx_desc *rxdp;
935 : : uint64_t qword1;
936 : : uint32_t rx_status;
937 : : uint32_t len, id;
938 : : uint32_t error;
939 : : int ret = 0;
940 : :
941 : 0 : rxdp = &rxq->rx_ring[rxq->rx_tail];
942 : 0 : qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
943 : : rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK)
944 : 0 : >> I40E_RXD_QW1_STATUS_SHIFT;
945 : :
946 [ # # ]: 0 : if (rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)) {
947 : 0 : len = qword1 >> I40E_RX_PROG_STATUS_DESC_LENGTH_SHIFT;
948 : 0 : id = (qword1 & I40E_RX_PROG_STATUS_DESC_QW1_PROGID_MASK) >>
949 : : I40E_RX_PROG_STATUS_DESC_QW1_PROGID_SHIFT;
950 : :
951 : 0 : if (len == I40E_RX_PROG_STATUS_DESC_LENGTH &&
952 [ # # ]: 0 : id == I40E_RX_PROG_STATUS_DESC_FD_FILTER_STATUS) {
953 : 0 : error = (qword1 &
954 : 0 : I40E_RX_PROG_STATUS_DESC_QW1_ERROR_MASK) >>
955 : : I40E_RX_PROG_STATUS_DESC_QW1_ERROR_SHIFT;
956 [ # # ]: 0 : if (error == (0x1 <<
957 : : I40E_RX_PROG_STATUS_DESC_FD_TBL_FULL_SHIFT)) {
958 : 0 : PMD_DRV_LOG(ERR, "Failed to add FDIR filter"
959 : : " (FD_ID %u): programming status"
960 : : " reported.",
961 : : rxdp->wb.qword0.hi_dword.fd_id);
962 : : ret = -1;
963 [ # # ]: 0 : } else if (error == (0x1 <<
964 : : I40E_RX_PROG_STATUS_DESC_NO_FD_ENTRY_SHIFT)) {
965 : 0 : PMD_DRV_LOG(ERR, "Failed to delete FDIR filter"
966 : : " (FD_ID %u): programming status"
967 : : " reported.",
968 : : rxdp->wb.qword0.hi_dword.fd_id);
969 : : ret = -1;
970 : : } else
971 : 0 : PMD_DRV_LOG(ERR, "invalid programming status"
972 : : " reported, error = %u.", error);
973 : : } else
974 : 0 : PMD_DRV_LOG(INFO, "unknown programming status"
975 : : " reported, len = %d, id = %u.", len, id);
976 : 0 : rxdp->wb.qword1.status_error_len = 0;
977 : 0 : rxq->rx_tail++;
978 [ # # ]: 0 : if (unlikely(rxq->rx_tail == rxq->nb_rx_desc))
979 : 0 : rxq->rx_tail = 0;
980 [ # # ]: 0 : if (rxq->rx_tail == 0)
981 : 0 : I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
982 : : else
983 : 0 : I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->rx_tail - 1);
984 : : }
985 : :
986 : 0 : return ret;
987 : : }
988 : :
989 : : static inline void
990 : 0 : i40e_fdir_programming_status_cleanup(struct ci_rx_queue *rxq)
991 : : {
992 : : uint16_t retry_count = 0;
993 : :
994 : : /* capture the previous error report(if any) from rx ring */
995 [ # # # # ]: 0 : while ((i40e_check_fdir_programming_status(rxq) < 0) &&
996 : : (++retry_count < I40E_FDIR_NUM_RX_DESC))
997 : 0 : PMD_DRV_LOG(INFO, "error report captured.");
998 : 0 : }
999 : :
1000 : : static int
1001 : 0 : i40e_fdir_filter_convert(const struct i40e_fdir_filter_conf *input,
1002 : : struct i40e_fdir_filter *filter)
1003 : : {
1004 [ # # ]: 0 : rte_memcpy(&filter->fdir, input, sizeof(struct i40e_fdir_filter_conf));
1005 [ # # ]: 0 : if (input->input.flow_ext.pkt_template) {
1006 : 0 : filter->fdir.input.flow.raw_flow.packet = NULL;
1007 : 0 : filter->fdir.input.flow.raw_flow.length =
1008 : 0 : rte_hash_crc(input->input.flow.raw_flow.packet,
1009 : 0 : input->input.flow.raw_flow.length,
1010 : 0 : input->input.flow.raw_flow.pctype);
1011 : : }
1012 : 0 : return 0;
1013 : : }
1014 : :
1015 : : /* Check if there exists the flow director filter */
1016 : : static struct i40e_fdir_filter *
1017 : 0 : i40e_sw_fdir_filter_lookup(struct i40e_fdir_info *fdir_info,
1018 : : const struct i40e_fdir_input *input)
1019 : : {
1020 : : int ret;
1021 : :
1022 [ # # ]: 0 : if (input->flow_ext.pkt_template)
1023 : 0 : ret = rte_hash_lookup_with_hash(fdir_info->hash_table,
1024 : : (const void *)input,
1025 : 0 : input->flow.raw_flow.length);
1026 : : else
1027 : 0 : ret = rte_hash_lookup(fdir_info->hash_table,
1028 : : (const void *)input);
1029 [ # # ]: 0 : if (ret < 0)
1030 : : return NULL;
1031 : :
1032 : 0 : return fdir_info->hash_map[ret];
1033 : : }
1034 : :
1035 : : /* Add a flow director filter into the SW list */
1036 : : static int
1037 : 0 : i40e_sw_fdir_filter_insert(struct i40e_pf *pf, struct i40e_fdir_filter *filter)
1038 : : {
1039 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1040 : : struct i40e_fdir_filter *hash_filter;
1041 : : int ret;
1042 : :
1043 [ # # ]: 0 : if (filter->fdir.input.flow_ext.pkt_template)
1044 : 0 : ret = rte_hash_add_key_with_hash(fdir_info->hash_table,
1045 : 0 : &filter->fdir.input,
1046 : : filter->fdir.input.flow.raw_flow.length);
1047 : : else
1048 : 0 : ret = rte_hash_add_key(fdir_info->hash_table,
1049 : 0 : &filter->fdir.input);
1050 [ # # ]: 0 : if (ret < 0) {
1051 : 0 : PMD_DRV_LOG(ERR,
1052 : : "Failed to insert fdir filter to hash table %d!",
1053 : : ret);
1054 : 0 : return ret;
1055 : : }
1056 : :
1057 [ # # ]: 0 : if (fdir_info->hash_map[ret])
1058 : : return -1;
1059 : :
1060 [ # # ]: 0 : hash_filter = &fdir_info->fdir_filter_array[ret];
1061 : : rte_memcpy(hash_filter, filter, sizeof(*filter));
1062 : 0 : fdir_info->hash_map[ret] = hash_filter;
1063 : 0 : TAILQ_INSERT_TAIL(&fdir_info->fdir_list, hash_filter, rules);
1064 : :
1065 : 0 : return 0;
1066 : : }
1067 : :
1068 : : /* Delete a flow director filter from the SW list */
1069 : : int
1070 : 0 : i40e_sw_fdir_filter_del(struct i40e_pf *pf, struct i40e_fdir_input *input)
1071 : : {
1072 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1073 : : struct i40e_fdir_filter *filter;
1074 : : int ret;
1075 : :
1076 [ # # ]: 0 : if (input->flow_ext.pkt_template)
1077 : 0 : ret = rte_hash_del_key_with_hash(fdir_info->hash_table,
1078 : : input,
1079 : : input->flow.raw_flow.length);
1080 : : else
1081 : 0 : ret = rte_hash_del_key(fdir_info->hash_table, input);
1082 [ # # ]: 0 : if (ret < 0) {
1083 : 0 : PMD_DRV_LOG(ERR,
1084 : : "Failed to delete fdir filter to hash table %d!",
1085 : : ret);
1086 : 0 : return ret;
1087 : : }
1088 : 0 : filter = fdir_info->hash_map[ret];
1089 : 0 : fdir_info->hash_map[ret] = NULL;
1090 : :
1091 [ # # ]: 0 : TAILQ_REMOVE(&fdir_info->fdir_list, filter, rules);
1092 : :
1093 : 0 : return 0;
1094 : : }
1095 : :
1096 : : struct rte_flow *
1097 : 0 : i40e_fdir_entry_pool_get(struct i40e_fdir_info *fdir_info)
1098 : : {
1099 : : struct rte_flow *flow = NULL;
1100 : 0 : uint64_t slab = 0;
1101 : 0 : uint32_t pos = 0;
1102 : : uint32_t i = 0;
1103 : : int ret;
1104 : :
1105 : 0 : if (fdir_info->fdir_actual_cnt >=
1106 [ # # ]: 0 : fdir_info->fdir_space_size) {
1107 : 0 : PMD_DRV_LOG(ERR, "Fdir space full");
1108 : 0 : return NULL;
1109 : : }
1110 : :
1111 : 0 : ret = rte_bitmap_scan(fdir_info->fdir_flow_pool.bitmap, &pos,
1112 : : &slab);
1113 : :
1114 : : /* normally this won't happen as the fdir_actual_cnt should be
1115 : : * same with the number of the set bits in fdir_flow_pool,
1116 : : * but anyway handle this error condition here for safe
1117 : : */
1118 [ # # ]: 0 : if (ret == 0) {
1119 : 0 : PMD_DRV_LOG(ERR, "fdir_actual_cnt out of sync");
1120 : 0 : return NULL;
1121 : : }
1122 : :
1123 : 0 : i = rte_bsf64(slab);
1124 : 0 : pos += i;
1125 : 0 : rte_bitmap_clear(fdir_info->fdir_flow_pool.bitmap, pos);
1126 : 0 : flow = &fdir_info->fdir_flow_pool.pool[pos].flow;
1127 : :
1128 : : memset(flow, 0, sizeof(struct rte_flow));
1129 : :
1130 : 0 : return flow;
1131 : : }
1132 : :
1133 : : void
1134 : 0 : i40e_fdir_entry_pool_put(struct i40e_fdir_info *fdir_info,
1135 : : struct rte_flow *flow)
1136 : : {
1137 : : struct i40e_fdir_entry *f;
1138 : :
1139 : : f = FLOW_TO_FLOW_BITMAP(flow);
1140 : 0 : rte_bitmap_set(fdir_info->fdir_flow_pool.bitmap, f->idx);
1141 : 0 : }
1142 : :
1143 : : static int
1144 : 0 : i40e_flow_store_flex_pit(struct i40e_pf *pf,
1145 : : struct i40e_fdir_flex_pit *flex_pit,
1146 : : enum i40e_flxpld_layer_idx layer_idx,
1147 : : uint8_t raw_id)
1148 : : {
1149 : : uint8_t field_idx;
1150 : :
1151 : 0 : field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + raw_id;
1152 : : /* Check if the configuration is conflicted */
1153 [ # # ]: 0 : if (pf->fdir.flex_pit_flag[layer_idx] &&
1154 [ # # ]: 0 : (pf->fdir.flex_set[field_idx].src_offset != flex_pit->src_offset ||
1155 [ # # ]: 0 : pf->fdir.flex_set[field_idx].size != flex_pit->size ||
1156 [ # # ]: 0 : pf->fdir.flex_set[field_idx].dst_offset != flex_pit->dst_offset))
1157 : : return -1;
1158 : :
1159 : : /* Check if the configuration exists. */
1160 [ # # ]: 0 : if (pf->fdir.flex_pit_flag[layer_idx] &&
1161 [ # # ]: 0 : (pf->fdir.flex_set[field_idx].src_offset == flex_pit->src_offset &&
1162 [ # # ]: 0 : pf->fdir.flex_set[field_idx].size == flex_pit->size &&
1163 [ # # ]: 0 : pf->fdir.flex_set[field_idx].dst_offset == flex_pit->dst_offset))
1164 : : return 1;
1165 : :
1166 : 0 : pf->fdir.flex_set[field_idx].src_offset =
1167 : 0 : flex_pit->src_offset;
1168 : 0 : pf->fdir.flex_set[field_idx].size =
1169 : 0 : flex_pit->size;
1170 : 0 : pf->fdir.flex_set[field_idx].dst_offset =
1171 : 0 : flex_pit->dst_offset;
1172 : :
1173 : 0 : return 0;
1174 : : }
1175 : :
1176 : : static void
1177 : 0 : i40e_flow_set_fdir_flex_pit(struct i40e_pf *pf,
1178 : : enum i40e_flxpld_layer_idx layer_idx,
1179 : : uint8_t raw_id)
1180 : : {
1181 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1182 : : uint32_t flx_pit, flx_ort;
1183 : : uint16_t min_next_off = 0;
1184 : : uint8_t field_idx;
1185 : : uint8_t i;
1186 : :
1187 [ # # ]: 0 : if (raw_id) {
1188 : 0 : flx_ort = (1 << I40E_GLQF_ORT_FLX_PAYLOAD_SHIFT) |
1189 : 0 : (raw_id << I40E_GLQF_ORT_FIELD_CNT_SHIFT) |
1190 : 0 : (layer_idx * I40E_MAX_FLXPLD_FIED);
1191 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(33 + layer_idx), flx_ort);
1192 : : }
1193 : :
1194 : : /* Set flex pit */
1195 [ # # ]: 0 : for (i = 0; i < raw_id; i++) {
1196 : 0 : field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
1197 [ # # ]: 0 : flx_pit = MK_FLX_PIT(pf->fdir.flex_set[field_idx].src_offset,
1198 : : pf->fdir.flex_set[field_idx].size,
1199 : : pf->fdir.flex_set[field_idx].dst_offset);
1200 : :
1201 : 0 : I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(field_idx), flx_pit);
1202 : 0 : min_next_off = pf->fdir.flex_set[field_idx].src_offset +
1203 : 0 : pf->fdir.flex_set[field_idx].size;
1204 : : }
1205 : :
1206 [ # # ]: 0 : for (; i < I40E_MAX_FLXPLD_FIED; i++) {
1207 : : /* set the non-used register obeying register's constrain */
1208 : 0 : field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
1209 : 0 : flx_pit = MK_FLX_PIT(min_next_off, NONUSE_FLX_PIT_FSIZE,
1210 : : NONUSE_FLX_PIT_DEST_OFF);
1211 : 0 : I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(field_idx), flx_pit);
1212 : 0 : min_next_off++;
1213 : : }
1214 : 0 : }
1215 : :
1216 : : static int
1217 : 0 : i40e_flow_store_flex_mask(struct i40e_pf *pf,
1218 : : enum i40e_filter_pctype pctype,
1219 : : uint8_t *mask)
1220 : : {
1221 : : struct i40e_fdir_flex_mask flex_mask;
1222 : : uint8_t nb_bitmask = 0;
1223 : : uint16_t mask_tmp;
1224 : : uint8_t i;
1225 : :
1226 : : memset(&flex_mask, 0, sizeof(struct i40e_fdir_flex_mask));
1227 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_MAX_FLEX_LEN; i += sizeof(uint16_t)) {
1228 : 0 : mask_tmp = I40E_WORD(mask[i], mask[i + 1]);
1229 [ # # ]: 0 : if (mask_tmp) {
1230 : 0 : flex_mask.word_mask |=
1231 : 0 : I40E_FLEX_WORD_MASK(i / sizeof(uint16_t));
1232 [ # # ]: 0 : if (mask_tmp != UINT16_MAX) {
1233 : 0 : flex_mask.bitmask[nb_bitmask].mask = ~mask_tmp;
1234 : 0 : flex_mask.bitmask[nb_bitmask].offset =
1235 : : i / sizeof(uint16_t);
1236 : 0 : nb_bitmask++;
1237 [ # # ]: 0 : if (nb_bitmask > I40E_FDIR_BITMASK_NUM_WORD)
1238 : : return -1;
1239 : : }
1240 : : }
1241 : : }
1242 : 0 : flex_mask.nb_bitmask = nb_bitmask;
1243 : :
1244 [ # # ]: 0 : if (pf->fdir.flex_mask_flag[pctype] &&
1245 [ # # ]: 0 : (memcmp(&flex_mask, &pf->fdir.flex_mask[pctype],
1246 : : sizeof(struct i40e_fdir_flex_mask))))
1247 : : return -2;
1248 [ # # ]: 0 : else if (pf->fdir.flex_mask_flag[pctype] &&
1249 [ # # ]: 0 : !(memcmp(&flex_mask, &pf->fdir.flex_mask[pctype],
1250 : : sizeof(struct i40e_fdir_flex_mask))))
1251 : : return 1;
1252 : :
1253 : 0 : pf->fdir.flex_mask[pctype] = flex_mask;
1254 : 0 : return 0;
1255 : : }
1256 : :
1257 : : static void
1258 : 0 : i40e_flow_set_fdir_flex_msk(struct i40e_pf *pf,
1259 : : enum i40e_filter_pctype pctype)
1260 : : {
1261 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1262 : : struct i40e_fdir_flex_mask *flex_mask;
1263 : : uint32_t flxinset, fd_mask;
1264 : : uint8_t i;
1265 : :
1266 : : /* Set flex mask */
1267 : : flex_mask = &pf->fdir.flex_mask[pctype];
1268 : 0 : flxinset = (flex_mask->word_mask <<
1269 : : I40E_PRTQF_FD_FLXINSET_INSET_SHIFT) &
1270 : : I40E_PRTQF_FD_FLXINSET_INSET_MASK;
1271 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_FD_FLXINSET(pctype), flxinset);
1272 : :
1273 [ # # ]: 0 : for (i = 0; i < flex_mask->nb_bitmask; i++) {
1274 : 0 : fd_mask = (flex_mask->bitmask[i].mask <<
1275 : : I40E_PRTQF_FD_MSK_MASK_SHIFT) &
1276 : : I40E_PRTQF_FD_MSK_MASK_MASK;
1277 : 0 : fd_mask |= ((flex_mask->bitmask[i].offset +
1278 : 0 : I40E_FLX_OFFSET_IN_FIELD_VECTOR) <<
1279 : 0 : I40E_PRTQF_FD_MSK_OFFSET_SHIFT) &
1280 : : I40E_PRTQF_FD_MSK_OFFSET_MASK;
1281 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_FD_MSK(pctype, i), fd_mask);
1282 : : }
1283 : :
1284 : 0 : pf->fdir.flex_mask_flag[pctype] = 1;
1285 : 0 : }
1286 : :
1287 : : static int
1288 : 0 : i40e_flow_set_fdir_inset(struct i40e_pf *pf,
1289 : : enum i40e_filter_pctype pctype,
1290 : : uint64_t input_set)
1291 : : {
1292 : 0 : uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
1293 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1294 : : uint64_t inset_reg = 0;
1295 : : int i, num;
1296 : :
1297 : : /* Check if the input set is valid */
1298 [ # # ]: 0 : if (i40e_validate_input_set(pctype, RTE_ETH_FILTER_FDIR,
1299 : : input_set) != 0) {
1300 : 0 : PMD_DRV_LOG(ERR, "Invalid input set");
1301 : 0 : return -EINVAL;
1302 : : }
1303 : :
1304 : : /* Check if the configuration is conflicted */
1305 [ # # ]: 0 : if (pf->fdir.flow_count[pctype] &&
1306 [ # # ]: 0 : memcmp(&pf->fdir.input_set[pctype], &input_set, sizeof(uint64_t))) {
1307 : 0 : PMD_DRV_LOG(ERR, "Conflict with the first rule's input set.");
1308 : 0 : return -EINVAL;
1309 : : }
1310 : :
1311 [ # # ]: 0 : if (pf->fdir.flow_count[pctype] &&
1312 [ # # ]: 0 : !memcmp(&pf->fdir.input_set[pctype], &input_set, sizeof(uint64_t)))
1313 : : return 0;
1314 : :
1315 : 0 : num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
1316 : : I40E_INSET_MASK_NUM_REG);
1317 [ # # ]: 0 : if (num < 0) {
1318 : 0 : PMD_DRV_LOG(ERR, "Invalid pattern mask.");
1319 : 0 : return -EINVAL;
1320 : : }
1321 : :
1322 [ # # ]: 0 : if (pf->support_multi_driver) {
1323 [ # # ]: 0 : for (i = 0; i < num; i++)
1324 : 0 : if (i40e_read_rx_ctl(hw,
1325 : 0 : I40E_GLQF_FD_MSK(i, pctype)) !=
1326 [ # # ]: 0 : mask_reg[i]) {
1327 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not"
1328 : : " supported with"
1329 : : " `support-multi-driver`"
1330 : : " enabled!");
1331 : 0 : return -EPERM;
1332 : : }
1333 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
1334 [ # # ]: 0 : if (i40e_read_rx_ctl(hw,
1335 : 0 : I40E_GLQF_FD_MSK(i, pctype)) != 0) {
1336 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not"
1337 : : " supported with"
1338 : : " `support-multi-driver`"
1339 : : " enabled!");
1340 : 0 : return -EPERM;
1341 : : }
1342 : :
1343 : : } else {
1344 [ # # ]: 0 : for (i = 0; i < num; i++)
1345 : 0 : i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
1346 : : mask_reg[i]);
1347 : : /*clear unused mask registers of the pctype */
1348 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
1349 : 0 : i40e_check_write_reg(hw,
1350 : 0 : I40E_GLQF_FD_MSK(i, pctype), 0);
1351 : : }
1352 : :
1353 : 0 : inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
1354 : :
1355 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
1356 : : (uint32_t)(inset_reg & UINT32_MAX));
1357 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
1358 : 0 : (uint32_t)((inset_reg >>
1359 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
1360 : :
1361 : 0 : I40E_WRITE_FLUSH(hw);
1362 : :
1363 : 0 : pf->fdir.input_set[pctype] = input_set;
1364 : 0 : return 0;
1365 : : }
1366 : :
1367 : : static inline unsigned char *
1368 : 0 : i40e_find_available_buffer(struct rte_eth_dev *dev)
1369 : : {
1370 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1371 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1372 : 0 : struct ci_tx_queue *txq = pf->fdir.txq;
1373 : :
1374 : : /* no available buffer
1375 : : * search for more available buffers from the current
1376 : : * descriptor, until an unavailable one
1377 : : */
1378 [ # # ]: 0 : if (fdir_info->txq_available_buf_count <= 0) {
1379 : : uint16_t tmp_tail;
1380 : : volatile struct i40e_tx_desc *tmp_txdp;
1381 : :
1382 : 0 : tmp_tail = txq->tx_tail;
1383 : 0 : tmp_txdp = &txq->i40e_tx_ring[tmp_tail + 1];
1384 : :
1385 : : do {
1386 [ # # ]: 0 : if ((tmp_txdp->cmd_type_offset_bsz &
1387 : : rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) ==
1388 : : rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
1389 : 0 : fdir_info->txq_available_buf_count++;
1390 : : else
1391 : : break;
1392 : :
1393 : 0 : tmp_tail += 2;
1394 [ # # ]: 0 : if (tmp_tail >= txq->nb_tx_desc)
1395 : : tmp_tail = 0;
1396 [ # # ]: 0 : } while (tmp_tail != txq->tx_tail);
1397 : : }
1398 : :
1399 [ # # ]: 0 : if (fdir_info->txq_available_buf_count > 0)
1400 : 0 : fdir_info->txq_available_buf_count--;
1401 : : else
1402 : : return NULL;
1403 : 0 : return (unsigned char *)fdir_info->prg_pkt[txq->tx_tail >> 1];
1404 : : }
1405 : :
1406 : : /**
1407 : : * i40e_flow_add_del_fdir_filter - add or remove a flow director filter.
1408 : : * @pf: board private structure
1409 : : * @filter: fdir filter entry
1410 : : * @add: 0 - delete, 1 - add
1411 : : */
1412 : : int
1413 : 0 : i40e_flow_add_del_fdir_filter(struct rte_eth_dev *dev,
1414 : : const struct i40e_fdir_filter_conf *filter,
1415 : : bool add)
1416 : : {
1417 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1418 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1419 : : enum i40e_flxpld_layer_idx layer_idx = I40E_FLXPLD_L2_IDX;
1420 : 0 : struct i40e_fdir_info *fdir_info = &pf->fdir;
1421 : : uint8_t flex_mask[I40E_FDIR_MAX_FLEX_LEN];
1422 : : struct i40e_fdir_filter check_filter; /* Check if the filter exists */
1423 : : struct i40e_fdir_flex_pit flex_pit;
1424 : : enum i40e_filter_pctype pctype;
1425 : : struct i40e_fdir_filter *node;
1426 : : unsigned char *pkt = NULL;
1427 : : bool cfg_flex_pit = true;
1428 : : bool wait_status = true;
1429 : : uint8_t field_idx;
1430 : : int ret = 0;
1431 : : int i;
1432 : :
1433 [ # # ]: 0 : if (pf->fdir.fdir_vsi == NULL) {
1434 : 0 : PMD_DRV_LOG(ERR, "FDIR is not enabled");
1435 : 0 : return -ENOTSUP;
1436 : : }
1437 : :
1438 [ # # ]: 0 : if (filter->action.rx_queue >= pf->dev_data->nb_rx_queues) {
1439 : 0 : PMD_DRV_LOG(ERR, "Invalid queue ID");
1440 : 0 : return -EINVAL;
1441 : : }
1442 [ # # ]: 0 : if (filter->input.flow_ext.is_vf &&
1443 [ # # ]: 0 : filter->input.flow_ext.dst_id >= pf->vf_num) {
1444 : 0 : PMD_DRV_LOG(ERR, "Invalid VF ID");
1445 : 0 : return -EINVAL;
1446 : : }
1447 [ # # ]: 0 : if (filter->input.flow_ext.pkt_template) {
1448 [ # # ]: 0 : if (filter->input.flow.raw_flow.length > I40E_FDIR_PKT_LEN ||
1449 [ # # ]: 0 : !filter->input.flow.raw_flow.packet) {
1450 : 0 : PMD_DRV_LOG(ERR, "Invalid raw packet template"
1451 : : " flow filter parameters!");
1452 : 0 : return -EINVAL;
1453 : : }
1454 : 0 : pctype = filter->input.flow.raw_flow.pctype;
1455 : : } else {
1456 : 0 : pctype = filter->input.pctype;
1457 : : }
1458 : :
1459 : : /* Check if there is the filter in SW list */
1460 : : memset(&check_filter, 0, sizeof(check_filter));
1461 : 0 : i40e_fdir_filter_convert(filter, &check_filter);
1462 : :
1463 [ # # ]: 0 : if (add) {
1464 : : /* configure the input set for common PCTYPEs*/
1465 [ # # ]: 0 : if (!filter->input.flow_ext.customized_pctype &&
1466 [ # # ]: 0 : !filter->input.flow_ext.pkt_template) {
1467 : 0 : ret = i40e_flow_set_fdir_inset(pf, pctype,
1468 : 0 : filter->input.flow_ext.input_set);
1469 [ # # ]: 0 : if (ret < 0)
1470 : : return ret;
1471 : : }
1472 : :
1473 [ # # ]: 0 : if (filter->input.flow_ext.is_flex_flow) {
1474 [ # # ]: 0 : for (i = 0; i < filter->input.flow_ext.raw_id; i++) {
1475 : 0 : layer_idx = filter->input.flow_ext.layer_idx;
1476 : 0 : field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
1477 : 0 : flex_pit = filter->input.flow_ext.flex_pit[field_idx];
1478 : :
1479 : : /* Store flex pit to SW */
1480 : 0 : ret = i40e_flow_store_flex_pit(pf, &flex_pit,
1481 : : layer_idx, i);
1482 [ # # ]: 0 : if (ret < 0) {
1483 : 0 : PMD_DRV_LOG(ERR, "Conflict with the"
1484 : : " first flexible rule.");
1485 : 0 : return -EINVAL;
1486 [ # # ]: 0 : } else if (ret > 0) {
1487 : : cfg_flex_pit = false;
1488 : : }
1489 : : }
1490 : :
1491 [ # # ]: 0 : if (cfg_flex_pit)
1492 : 0 : i40e_flow_set_fdir_flex_pit(pf, layer_idx,
1493 : : filter->input.flow_ext.raw_id);
1494 : :
1495 : : /* Store flex mask to SW */
1496 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_MAX_FLEX_LEN; i++)
1497 : 0 : flex_mask[i] =
1498 : 0 : filter->input.flow_ext.flex_mask[i];
1499 : :
1500 : 0 : ret = i40e_flow_store_flex_mask(pf, pctype, flex_mask);
1501 [ # # ]: 0 : if (ret == -1) {
1502 : 0 : PMD_DRV_LOG(ERR, "Exceed maximal"
1503 : : " number of bitmasks");
1504 : 0 : return -EINVAL;
1505 [ # # ]: 0 : } else if (ret == -2) {
1506 : 0 : PMD_DRV_LOG(ERR, "Conflict with the"
1507 : : " first flexible rule");
1508 : 0 : return -EINVAL;
1509 [ # # ]: 0 : } else if (ret == 0) {
1510 : 0 : i40e_flow_set_fdir_flex_msk(pf, pctype);
1511 : : }
1512 : : }
1513 : :
1514 : 0 : ret = i40e_sw_fdir_filter_insert(pf, &check_filter);
1515 [ # # ]: 0 : if (ret < 0) {
1516 : 0 : PMD_DRV_LOG(ERR,
1517 : : "Conflict with existing flow director rules!");
1518 : 0 : return -EINVAL;
1519 : : }
1520 : :
1521 [ # # ]: 0 : if (fdir_info->fdir_invalprio == 1 &&
1522 [ # # ]: 0 : fdir_info->fdir_guarantee_free_space > 0)
1523 : : wait_status = false;
1524 : : } else {
1525 [ # # ]: 0 : if (filter->input.flow_ext.is_flex_flow)
1526 : 0 : layer_idx = filter->input.flow_ext.layer_idx;
1527 : :
1528 : 0 : node = i40e_sw_fdir_filter_lookup(fdir_info,
1529 : : &check_filter.fdir.input);
1530 [ # # ]: 0 : if (!node) {
1531 : 0 : PMD_DRV_LOG(ERR,
1532 : : "There's no corresponding flow director filter!");
1533 : 0 : return -EINVAL;
1534 : : }
1535 : :
1536 : 0 : ret = i40e_sw_fdir_filter_del(pf, &node->fdir.input);
1537 [ # # ]: 0 : if (ret < 0) {
1538 : 0 : PMD_DRV_LOG(ERR,
1539 : : "Error deleting fdir rule from hash table!");
1540 : 0 : return -EINVAL;
1541 : : }
1542 : :
1543 : 0 : pf->fdir.flex_mask_flag[pctype] = 0;
1544 : :
1545 [ # # ]: 0 : if (fdir_info->fdir_invalprio == 1)
1546 : : wait_status = false;
1547 : : }
1548 : :
1549 : : /* find a buffer to store the pkt */
1550 : 0 : pkt = i40e_find_available_buffer(dev);
1551 [ # # ]: 0 : if (pkt == NULL)
1552 : 0 : goto error_op;
1553 : :
1554 : : memset(pkt, 0, I40E_FDIR_PKT_LEN);
1555 : 0 : ret = i40e_flow_fdir_construct_pkt(pf, &filter->input, pkt);
1556 [ # # ]: 0 : if (ret < 0) {
1557 : 0 : PMD_DRV_LOG(ERR, "construct packet for fdir fails.");
1558 : 0 : goto error_op;
1559 : : }
1560 : :
1561 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
1562 : : /* get translated pctype value in fd pctype register */
1563 : 0 : pctype = (enum i40e_filter_pctype)i40e_read_rx_ctl(
1564 : 0 : hw, I40E_GLQF_FD_PCTYPES((int)pctype));
1565 : : }
1566 : :
1567 : 0 : ret = i40e_flow_fdir_filter_programming(pf, pctype, filter, add,
1568 : : wait_status);
1569 [ # # ]: 0 : if (ret < 0) {
1570 : 0 : PMD_DRV_LOG(ERR, "fdir programming fails for PCTYPE(%u).",
1571 : : pctype);
1572 : 0 : goto error_op;
1573 : : }
1574 : :
1575 [ # # ]: 0 : if (filter->input.flow_ext.is_flex_flow) {
1576 [ # # ]: 0 : if (add) {
1577 : 0 : fdir_info->flex_flow_count[layer_idx]++;
1578 : 0 : pf->fdir.flex_pit_flag[layer_idx] = 1;
1579 : : } else {
1580 : 0 : fdir_info->flex_flow_count[layer_idx]--;
1581 [ # # ]: 0 : if (!fdir_info->flex_flow_count[layer_idx])
1582 : 0 : pf->fdir.flex_pit_flag[layer_idx] = 0;
1583 : : }
1584 : : }
1585 : :
1586 [ # # ]: 0 : if (add) {
1587 : 0 : fdir_info->flow_count[pctype]++;
1588 : 0 : fdir_info->fdir_actual_cnt++;
1589 [ # # ]: 0 : if (fdir_info->fdir_invalprio == 1 &&
1590 [ # # ]: 0 : fdir_info->fdir_guarantee_free_space > 0)
1591 : 0 : fdir_info->fdir_guarantee_free_space--;
1592 : : } else {
1593 : 0 : fdir_info->flow_count[pctype]--;
1594 : 0 : fdir_info->fdir_actual_cnt--;
1595 [ # # ]: 0 : if (fdir_info->fdir_invalprio == 1 &&
1596 : 0 : fdir_info->fdir_guarantee_free_space <
1597 [ # # ]: 0 : fdir_info->fdir_guarantee_total_space)
1598 : 0 : fdir_info->fdir_guarantee_free_space++;
1599 : : }
1600 : :
1601 : : return ret;
1602 : :
1603 : 0 : error_op:
1604 : : /* roll back */
1605 [ # # ]: 0 : if (add)
1606 : 0 : i40e_sw_fdir_filter_del(pf, &check_filter.fdir.input);
1607 : : else
1608 : 0 : i40e_sw_fdir_filter_insert(pf, &check_filter);
1609 : :
1610 : : return ret;
1611 : : }
1612 : :
1613 : : /*
1614 : : * i40e_flow_fdir_filter_programming - Program a flow director filter rule.
1615 : : * Is done by Flow Director Programming Descriptor followed by packet
1616 : : * structure that contains the filter fields need to match.
1617 : : * @pf: board private structure
1618 : : * @pctype: pctype
1619 : : * @filter: fdir filter entry
1620 : : * @add: 0 - delete, 1 - add
1621 : : */
1622 : : static int
1623 : 0 : i40e_flow_fdir_filter_programming(struct i40e_pf *pf,
1624 : : enum i40e_filter_pctype pctype,
1625 : : const struct i40e_fdir_filter_conf *filter,
1626 : : bool add, bool wait_status)
1627 : : {
1628 : 0 : struct ci_tx_queue *txq = pf->fdir.txq;
1629 : 0 : struct ci_rx_queue *rxq = pf->fdir.rxq;
1630 : : const struct i40e_fdir_action *fdir_action = &filter->action;
1631 : : volatile struct i40e_tx_desc *txdp;
1632 : : volatile struct i40e_filter_program_desc *fdirdp;
1633 : : uint32_t td_cmd;
1634 : : uint16_t vsi_id;
1635 : : uint8_t dest;
1636 : : uint32_t i;
1637 : :
1638 : 0 : PMD_DRV_LOG(INFO, "filling filter programming descriptor.");
1639 : 0 : fdirdp = (volatile struct i40e_filter_program_desc *)
1640 : 0 : (&txq->i40e_tx_ring[txq->tx_tail]);
1641 : :
1642 : 0 : fdirdp->qindex_flex_ptype_vsi =
1643 : 0 : rte_cpu_to_le_32((fdir_action->rx_queue <<
1644 : : I40E_TXD_FLTR_QW0_QINDEX_SHIFT) &
1645 : : I40E_TXD_FLTR_QW0_QINDEX_MASK);
1646 : :
1647 : 0 : fdirdp->qindex_flex_ptype_vsi |=
1648 : 0 : rte_cpu_to_le_32((fdir_action->flex_off <<
1649 : : I40E_TXD_FLTR_QW0_FLEXOFF_SHIFT) &
1650 : : I40E_TXD_FLTR_QW0_FLEXOFF_MASK);
1651 : :
1652 : 0 : fdirdp->qindex_flex_ptype_vsi |=
1653 : 0 : rte_cpu_to_le_32((pctype <<
1654 : : I40E_TXD_FLTR_QW0_PCTYPE_SHIFT) &
1655 : : I40E_TXD_FLTR_QW0_PCTYPE_MASK);
1656 : :
1657 [ # # ]: 0 : if (filter->input.flow_ext.is_vf)
1658 : 0 : vsi_id = pf->vfs[filter->input.flow_ext.dst_id].vsi->vsi_id;
1659 : : else
1660 : : /* Use LAN VSI Id by default */
1661 : 0 : vsi_id = pf->main_vsi->vsi_id;
1662 : 0 : fdirdp->qindex_flex_ptype_vsi |=
1663 : 0 : rte_cpu_to_le_32(((uint32_t)vsi_id <<
1664 : : I40E_TXD_FLTR_QW0_DEST_VSI_SHIFT) &
1665 : : I40E_TXD_FLTR_QW0_DEST_VSI_MASK);
1666 : :
1667 : 0 : fdirdp->dtype_cmd_cntindex =
1668 : : rte_cpu_to_le_32(I40E_TX_DESC_DTYPE_FILTER_PROG);
1669 : :
1670 [ # # ]: 0 : if (add)
1671 : 0 : fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32(
1672 : : I40E_FILTER_PROGRAM_DESC_PCMD_ADD_UPDATE <<
1673 : : I40E_TXD_FLTR_QW1_PCMD_SHIFT);
1674 : : else
1675 : 0 : fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32(
1676 : : I40E_FILTER_PROGRAM_DESC_PCMD_REMOVE <<
1677 : : I40E_TXD_FLTR_QW1_PCMD_SHIFT);
1678 : :
1679 [ # # ]: 0 : if (fdir_action->behavior == I40E_FDIR_REJECT)
1680 : : dest = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1681 [ # # ]: 0 : else if (fdir_action->behavior == I40E_FDIR_ACCEPT)
1682 : : dest = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1683 [ # # ]: 0 : else if (fdir_action->behavior == I40E_FDIR_PASSTHRU)
1684 : : dest = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_OTHER;
1685 : : else {
1686 : 0 : PMD_DRV_LOG(ERR, "Failed to program FDIR filter: unsupported fdir behavior.");
1687 : 0 : return -EINVAL;
1688 : : }
1689 : :
1690 : 0 : fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32((dest <<
1691 : : I40E_TXD_FLTR_QW1_DEST_SHIFT) &
1692 : : I40E_TXD_FLTR_QW1_DEST_MASK);
1693 : :
1694 : 0 : fdirdp->dtype_cmd_cntindex |=
1695 : 0 : rte_cpu_to_le_32((fdir_action->report_status <<
1696 : : I40E_TXD_FLTR_QW1_FD_STATUS_SHIFT) &
1697 : : I40E_TXD_FLTR_QW1_FD_STATUS_MASK);
1698 : :
1699 : 0 : fdirdp->dtype_cmd_cntindex |=
1700 : : rte_cpu_to_le_32(I40E_TXD_FLTR_QW1_CNT_ENA_MASK);
1701 : 0 : fdirdp->dtype_cmd_cntindex |=
1702 : 0 : rte_cpu_to_le_32(
1703 : : ((uint32_t)pf->fdir.match_counter_index <<
1704 : : I40E_TXD_FLTR_QW1_CNTINDEX_SHIFT) &
1705 : : I40E_TXD_FLTR_QW1_CNTINDEX_MASK);
1706 : :
1707 : 0 : fdirdp->fd_id = rte_cpu_to_le_32(filter->soft_id);
1708 : :
1709 : 0 : PMD_DRV_LOG(INFO, "filling transmit descriptor.");
1710 : 0 : txdp = &txq->i40e_tx_ring[txq->tx_tail + 1];
1711 : 0 : txdp->buffer_addr = rte_cpu_to_le_64(pf->fdir.dma_addr[txq->tx_tail >> 1]);
1712 : :
1713 : : td_cmd = I40E_TX_DESC_CMD_EOP |
1714 : : I40E_TX_DESC_CMD_RS |
1715 : : I40E_TX_DESC_CMD_DUMMY;
1716 : :
1717 : 0 : txdp->cmd_type_offset_bsz =
1718 : : i40e_build_ctob(td_cmd, 0, I40E_FDIR_PKT_LEN, 0);
1719 : :
1720 : 0 : txq->tx_tail += 2; /* set 2 descriptors above, fdirdp and txdp */
1721 [ # # ]: 0 : if (txq->tx_tail >= txq->nb_tx_desc)
1722 : 0 : txq->tx_tail = 0;
1723 : : /* Update the tx tail register */
1724 : : rte_wmb();
1725 : :
1726 : : /* fdir program rx queue cleanup */
1727 : 0 : i40e_fdir_programming_status_cleanup(rxq);
1728 : :
1729 : 0 : I40E_PCI_REG_WRITE(txq->qtx_tail, txq->tx_tail);
1730 : :
1731 [ # # ]: 0 : if (wait_status) {
1732 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_MAX_WAIT_US; i++) {
1733 [ # # ]: 0 : if ((txdp->cmd_type_offset_bsz &
1734 : : rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) ==
1735 : : rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
1736 : : break;
1737 : 0 : rte_delay_us(1);
1738 : : }
1739 [ # # ]: 0 : if (i >= I40E_FDIR_MAX_WAIT_US) {
1740 : 0 : PMD_DRV_LOG(ERR,
1741 : : "Failed to program FDIR filter: time out to get DD on tx queue.");
1742 : 0 : return -ETIMEDOUT;
1743 : : }
1744 : : /* totally delay 10 ms to check programming status*/
1745 : 0 : rte_delay_us(I40E_FDIR_MAX_WAIT_US);
1746 [ # # ]: 0 : if (i40e_check_fdir_programming_status(rxq) < 0) {
1747 : 0 : PMD_DRV_LOG(ERR,
1748 : : "Failed to program FDIR filter: programming status reported.");
1749 : 0 : return -ETIMEDOUT;
1750 : : }
1751 : : }
1752 : :
1753 : : return 0;
1754 : : }
1755 : :
1756 : : /*
1757 : : * i40e_fdir_flush - clear all filters of Flow Director table
1758 : : * @pf: board private structure
1759 : : */
1760 : : int
1761 : 0 : i40e_fdir_flush(struct rte_eth_dev *dev)
1762 : : {
1763 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1764 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1765 : : uint32_t reg;
1766 : : uint16_t guarant_cnt, best_cnt;
1767 : : uint16_t i;
1768 : :
1769 : 0 : I40E_WRITE_REG(hw, I40E_PFQF_CTL_1, I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
1770 : 0 : I40E_WRITE_FLUSH(hw);
1771 : :
1772 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_FLUSH_RETRY; i++) {
1773 : : rte_delay_ms(I40E_FDIR_FLUSH_INTERVAL_MS);
1774 : 0 : reg = I40E_READ_REG(hw, I40E_PFQF_CTL_1);
1775 [ # # ]: 0 : if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
1776 : : break;
1777 : : }
1778 [ # # ]: 0 : if (i >= I40E_FDIR_FLUSH_RETRY) {
1779 : 0 : PMD_DRV_LOG(ERR, "FD table did not flush, may need more time.");
1780 : 0 : return -ETIMEDOUT;
1781 : : }
1782 : 0 : guarant_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
1783 : : I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
1784 : : I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
1785 : 0 : best_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
1786 : 0 : I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
1787 : : I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
1788 [ # # ]: 0 : if (guarant_cnt != 0 || best_cnt != 0) {
1789 : 0 : PMD_DRV_LOG(ERR, "Failed to flush FD table.");
1790 : 0 : return -ENOSYS;
1791 : : } else
1792 : 0 : PMD_DRV_LOG(INFO, "FD table Flush success.");
1793 : 0 : return 0;
1794 : : }
1795 : :
1796 : : static inline void
1797 : 0 : i40e_fdir_info_get_flex_set(struct i40e_pf *pf,
1798 : : struct rte_eth_flex_payload_cfg *flex_set,
1799 : : uint16_t *num)
1800 : : {
1801 : : struct i40e_fdir_flex_pit *flex_pit;
1802 : : struct rte_eth_flex_payload_cfg *ptr = flex_set;
1803 : : uint16_t src, dst, size, j, k;
1804 : : uint8_t i, layer_idx;
1805 : :
1806 : 0 : for (layer_idx = I40E_FLXPLD_L2_IDX;
1807 [ # # ]: 0 : layer_idx <= I40E_FLXPLD_L4_IDX;
1808 : 0 : layer_idx++) {
1809 [ # # ]: 0 : if (layer_idx == I40E_FLXPLD_L2_IDX)
1810 : 0 : ptr->type = RTE_ETH_L2_PAYLOAD;
1811 [ # # ]: 0 : else if (layer_idx == I40E_FLXPLD_L3_IDX)
1812 : 0 : ptr->type = RTE_ETH_L3_PAYLOAD;
1813 : : else if (layer_idx == I40E_FLXPLD_L4_IDX)
1814 : 0 : ptr->type = RTE_ETH_L4_PAYLOAD;
1815 : :
1816 [ # # ]: 0 : for (i = 0; i < I40E_MAX_FLXPLD_FIED; i++) {
1817 : 0 : flex_pit = &pf->fdir.flex_set[layer_idx *
1818 : 0 : I40E_MAX_FLXPLD_FIED + i];
1819 [ # # ]: 0 : if (flex_pit->size == 0)
1820 : 0 : continue;
1821 : 0 : src = flex_pit->src_offset * sizeof(uint16_t);
1822 : 0 : dst = flex_pit->dst_offset * sizeof(uint16_t);
1823 : 0 : size = flex_pit->size * sizeof(uint16_t);
1824 [ # # ]: 0 : for (j = src, k = dst; j < src + size; j++, k++)
1825 : 0 : ptr->src_offset[k] = j;
1826 : : }
1827 : 0 : (*num)++;
1828 : 0 : ptr++;
1829 : : }
1830 : 0 : }
1831 : :
1832 : : static inline void
1833 : 0 : i40e_fdir_info_get_flex_mask(struct i40e_pf *pf,
1834 : : struct rte_eth_fdir_flex_mask *flex_mask,
1835 : : uint16_t *num)
1836 : : {
1837 : : struct i40e_fdir_flex_mask *mask;
1838 : : struct rte_eth_fdir_flex_mask *ptr = flex_mask;
1839 : : uint16_t flow_type;
1840 : : uint8_t i, j;
1841 : : uint16_t off_bytes, mask_tmp;
1842 : :
1843 : 0 : for (i = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
1844 [ # # ]: 0 : i <= I40E_FILTER_PCTYPE_L2_PAYLOAD;
1845 : 0 : i++) {
1846 : 0 : mask = &pf->fdir.flex_mask[i];
1847 : 0 : flow_type = i40e_pctype_to_flowtype(pf->adapter,
1848 : : (enum i40e_filter_pctype)i);
1849 [ # # ]: 0 : if (flow_type == RTE_ETH_FLOW_UNKNOWN)
1850 : 0 : continue;
1851 : :
1852 [ # # ]: 0 : for (j = 0; j < I40E_FDIR_MAX_FLEXWORD_NUM; j++) {
1853 [ # # ]: 0 : if (mask->word_mask & I40E_FLEX_WORD_MASK(j)) {
1854 : 0 : ptr->mask[j * sizeof(uint16_t)] = UINT8_MAX;
1855 : 0 : ptr->mask[j * sizeof(uint16_t) + 1] = UINT8_MAX;
1856 : : } else {
1857 : 0 : ptr->mask[j * sizeof(uint16_t)] = 0x0;
1858 : 0 : ptr->mask[j * sizeof(uint16_t) + 1] = 0x0;
1859 : : }
1860 : : }
1861 [ # # ]: 0 : for (j = 0; j < I40E_FDIR_BITMASK_NUM_WORD; j++) {
1862 : 0 : off_bytes = mask->bitmask[j].offset * sizeof(uint16_t);
1863 : 0 : mask_tmp = ~mask->bitmask[j].mask;
1864 : 0 : ptr->mask[off_bytes] &= I40E_HI_BYTE(mask_tmp);
1865 : 0 : ptr->mask[off_bytes + 1] &= I40E_LO_BYTE(mask_tmp);
1866 : : }
1867 : 0 : ptr->flow_type = flow_type;
1868 : 0 : ptr++;
1869 : 0 : (*num)++;
1870 : : }
1871 : 0 : }
1872 : :
1873 : : /*
1874 : : * i40e_fdir_info_get - get information of Flow Director
1875 : : * @pf: ethernet device to get info from
1876 : : * @fdir: a pointer to a structure of type *rte_eth_fdir_info* to be filled with
1877 : : * the flow director information.
1878 : : */
1879 : : void
1880 : 0 : i40e_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir)
1881 : : {
1882 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1883 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1884 : 0 : uint16_t num_flex_set = 0;
1885 : 0 : uint16_t num_flex_mask = 0;
1886 : : uint16_t i;
1887 : :
1888 : 0 : fdir->mode = RTE_FDIR_MODE_NONE;
1889 : :
1890 : 0 : fdir->guarant_spc =
1891 : 0 : (uint32_t)hw->func_caps.fd_filters_guaranteed;
1892 : 0 : fdir->best_spc =
1893 : 0 : (uint32_t)hw->func_caps.fd_filters_best_effort;
1894 : 0 : fdir->max_flexpayload = I40E_FDIR_MAX_FLEX_LEN;
1895 : 0 : fdir->flow_types_mask[0] = I40E_FDIR_FLOWS;
1896 : : for (i = 1; i < RTE_FLOW_MASK_ARRAY_SIZE; i++)
1897 : : fdir->flow_types_mask[i] = 0ULL;
1898 : 0 : fdir->flex_payload_unit = sizeof(uint16_t);
1899 : 0 : fdir->flex_bitmask_unit = sizeof(uint16_t);
1900 : 0 : fdir->max_flex_payload_segment_num = I40E_MAX_FLXPLD_FIED;
1901 : 0 : fdir->flex_payload_limit = I40E_MAX_FLX_SOURCE_OFF;
1902 : 0 : fdir->max_flex_bitmask_num = I40E_FDIR_BITMASK_NUM_WORD;
1903 : :
1904 : 0 : i40e_fdir_info_get_flex_set(pf,
1905 : 0 : fdir->flex_conf.flex_set,
1906 : : &num_flex_set);
1907 : 0 : i40e_fdir_info_get_flex_mask(pf,
1908 : 0 : fdir->flex_conf.flex_mask,
1909 : : &num_flex_mask);
1910 : :
1911 : 0 : fdir->flex_conf.nb_payloads = num_flex_set;
1912 : 0 : fdir->flex_conf.nb_flexmasks = num_flex_mask;
1913 : 0 : }
1914 : :
1915 : : /*
1916 : : * i40e_fdir_stat_get - get statistics of Flow Director
1917 : : * @pf: ethernet device to get info from
1918 : : * @stat: a pointer to a structure of type *rte_eth_fdir_stats* to be filled with
1919 : : * the flow director statistics.
1920 : : */
1921 : : void
1922 : 0 : i40e_fdir_stats_get(struct rte_eth_dev *dev, struct rte_eth_fdir_stats *stat)
1923 : : {
1924 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1925 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1926 : : uint32_t fdstat;
1927 : :
1928 : 0 : fdstat = I40E_READ_REG(hw, I40E_PFQF_FDSTAT);
1929 : 0 : stat->guarant_cnt =
1930 : 0 : (uint32_t)((fdstat & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
1931 : : I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
1932 : 0 : stat->best_cnt =
1933 : 0 : (uint32_t)((fdstat & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
1934 : : I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
1935 : 0 : }
1936 : :
1937 : : /* Restore flow director filter */
1938 : : void
1939 : 0 : i40e_fdir_filter_restore(struct i40e_pf *pf)
1940 : : {
1941 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(pf->main_vsi);
1942 : : struct i40e_fdir_filter_list *fdir_list = &pf->fdir.fdir_list;
1943 : : struct i40e_fdir_filter *f;
1944 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1945 : : uint32_t fdstat;
1946 : : uint32_t guarant_cnt; /**< Number of filters in guaranteed spaces. */
1947 : : uint32_t best_cnt; /**< Number of filters in best effort spaces. */
1948 : :
1949 [ # # ]: 0 : TAILQ_FOREACH(f, fdir_list, rules)
1950 : 0 : i40e_flow_add_del_fdir_filter(dev, &f->fdir, TRUE);
1951 : :
1952 : 0 : fdstat = I40E_READ_REG(hw, I40E_PFQF_FDSTAT);
1953 : 0 : guarant_cnt =
1954 : : (uint32_t)((fdstat & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
1955 : : I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
1956 : 0 : best_cnt =
1957 : 0 : (uint32_t)((fdstat & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
1958 : : I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
1959 : :
1960 : 0 : PMD_DRV_LOG(INFO, "FDIR: Guarant count: %d, Best count: %d",
1961 : : guarant_cnt, best_cnt);
1962 : 0 : }
|