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 i40e_rx_queue *rxq)
104 : : {
105 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->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_LIBRTE_I40E_16BYTE_RX_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->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 i40e_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_IPV4_UDP) {
603 : : len = fill_ip4_head(fdir_input, raw_pkt, IPPROTO_UDP,
604 : : len, ether_type);
605 : : } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6)
606 : 0 : len = fill_ip6_head(fdir_input, raw_pkt, IPPROTO_ESP,
607 : : len, ether_type);
608 : : else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6_UDP)
609 : 0 : len = fill_ip6_head(fdir_input, raw_pkt, IPPROTO_UDP,
610 : : len, ether_type);
611 : : else if (cus_pctype->index == I40E_CUSTOMIZED_IPV6_L2TPV3)
612 : 0 : len = fill_ip6_head(fdir_input, raw_pkt, IPPROTO_L2TP,
613 : : len, ether_type);
614 : : } else {
615 : 0 : PMD_DRV_LOG(ERR, "unknown pctype %u.", fdir_input->pctype);
616 : 0 : return -1;
617 : : }
618 : :
619 : 0 : return len;
620 : : }
621 : :
622 : : /**
623 : : * i40e_flow_fdir_construct_pkt - construct packet based on fields in input
624 : : * @pf: board private structure
625 : : * @fdir_input: input set of the flow director entry
626 : : * @raw_pkt: a packet to be constructed
627 : : */
628 : : static int
629 : 0 : i40e_flow_fdir_construct_pkt(struct i40e_pf *pf,
630 : : const struct i40e_fdir_input *fdir_input,
631 : : unsigned char *raw_pkt)
632 : : {
633 : : unsigned char *payload = NULL;
634 : : unsigned char *ptr;
635 : : struct rte_udp_hdr *udp;
636 : : struct rte_tcp_hdr *tcp;
637 : : struct rte_sctp_hdr *sctp;
638 : : struct rte_flow_item_gtp *gtp;
639 : : struct rte_ipv4_hdr *gtp_ipv4;
640 : : struct rte_ipv6_hdr *gtp_ipv6;
641 : : struct rte_flow_item_l2tpv3oip *l2tpv3oip;
642 : : struct rte_flow_item_esp *esp;
643 : : struct rte_ipv4_hdr *esp_ipv4;
644 : : struct rte_ipv6_hdr *esp_ipv6;
645 : :
646 : : uint8_t size, dst = 0;
647 : : uint8_t i, pit_idx, set_idx = I40E_FLXPLD_L4_IDX; /* use l4 by default*/
648 : : int len;
649 : 0 : uint8_t pctype = fdir_input->pctype;
650 : : struct i40e_customized_pctype *cus_pctype;
651 : :
652 : : /* raw packet template - just copy contents of the raw packet */
653 [ # # ]: 0 : if (fdir_input->flow_ext.pkt_template) {
654 : 0 : memcpy(raw_pkt, fdir_input->flow.raw_flow.packet,
655 : 0 : fdir_input->flow.raw_flow.length);
656 : 0 : return 0;
657 : : }
658 : :
659 : : /* fill the ethernet and IP head */
660 : 0 : len = i40e_flow_fdir_fill_eth_ip_head(pf, fdir_input, raw_pkt,
661 : 0 : !!fdir_input->flow_ext.vlan_tci);
662 [ # # ]: 0 : if (len < 0)
663 : : return -EINVAL;
664 : :
665 : : /* fill the L4 head */
666 : : if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_UDP) {
667 : 0 : udp = (struct rte_udp_hdr *)(raw_pkt + len);
668 : 0 : payload = (unsigned char *)udp + sizeof(struct rte_udp_hdr);
669 : : /**
670 : : * The source and destination fields in the transmitted packet
671 : : * need to be presented in a reversed order with respect
672 : : * to the expected received packets.
673 : : */
674 : 0 : udp->src_port = fdir_input->flow.udp4_flow.dst_port;
675 : 0 : udp->dst_port = fdir_input->flow.udp4_flow.src_port;
676 : 0 : udp->dgram_len = rte_cpu_to_be_16(I40E_FDIR_UDP_DEFAULT_LEN);
677 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_TCP) {
678 : 0 : tcp = (struct rte_tcp_hdr *)(raw_pkt + len);
679 : 0 : payload = (unsigned char *)tcp + sizeof(struct rte_tcp_hdr);
680 : : /**
681 : : * The source and destination fields in the transmitted packet
682 : : * need to be presented in a reversed order with respect
683 : : * to the expected received packets.
684 : : */
685 : 0 : tcp->src_port = fdir_input->flow.tcp4_flow.dst_port;
686 : 0 : tcp->dst_port = fdir_input->flow.tcp4_flow.src_port;
687 : 0 : tcp->data_off = I40E_FDIR_TCP_DEFAULT_DATAOFF;
688 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) {
689 : 0 : sctp = (struct rte_sctp_hdr *)(raw_pkt + len);
690 : 0 : payload = (unsigned char *)sctp + sizeof(struct rte_sctp_hdr);
691 : : /**
692 : : * The source and destination fields in the transmitted packet
693 : : * need to be presented in a reversed order with respect
694 : : * to the expected received packets.
695 : : */
696 : 0 : sctp->src_port = fdir_input->flow.sctp4_flow.dst_port;
697 : 0 : sctp->dst_port = fdir_input->flow.sctp4_flow.src_port;
698 : 0 : sctp->tag = fdir_input->flow.sctp4_flow.verify_tag;
699 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER ||
700 : : pctype == I40E_FILTER_PCTYPE_FRAG_IPV4) {
701 : 0 : payload = raw_pkt + len;
702 : : set_idx = I40E_FLXPLD_L3_IDX;
703 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_UDP) {
704 : 0 : udp = (struct rte_udp_hdr *)(raw_pkt + len);
705 : 0 : payload = (unsigned char *)udp + sizeof(struct rte_udp_hdr);
706 : : /**
707 : : * The source and destination fields in the transmitted packet
708 : : * need to be presented in a reversed order with respect
709 : : * to the expected received packets.
710 : : */
711 : 0 : udp->src_port = fdir_input->flow.udp6_flow.dst_port;
712 : 0 : udp->dst_port = fdir_input->flow.udp6_flow.src_port;
713 : 0 : udp->dgram_len = rte_cpu_to_be_16(I40E_FDIR_IPv6_PAYLOAD_LEN);
714 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_TCP) {
715 : 0 : tcp = (struct rte_tcp_hdr *)(raw_pkt + len);
716 : 0 : payload = (unsigned char *)tcp + sizeof(struct rte_tcp_hdr);
717 : : /**
718 : : * The source and destination fields in the transmitted packet
719 : : * need to be presented in a reversed order with respect
720 : : * to the expected received packets.
721 : : */
722 : 0 : tcp->data_off = I40E_FDIR_TCP_DEFAULT_DATAOFF;
723 : 0 : tcp->src_port = fdir_input->flow.udp6_flow.dst_port;
724 : 0 : tcp->dst_port = fdir_input->flow.udp6_flow.src_port;
725 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) {
726 : 0 : sctp = (struct rte_sctp_hdr *)(raw_pkt + len);
727 : 0 : payload = (unsigned char *)sctp + sizeof(struct rte_sctp_hdr);
728 : : /**
729 : : * The source and destination fields in the transmitted packet
730 : : * need to be presented in a reversed order with respect
731 : : * to the expected received packets.
732 : : */
733 : 0 : sctp->src_port = fdir_input->flow.sctp6_flow.dst_port;
734 : 0 : sctp->dst_port = fdir_input->flow.sctp6_flow.src_port;
735 : 0 : sctp->tag = fdir_input->flow.sctp6_flow.verify_tag;
736 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_OTHER ||
737 : : pctype == I40E_FILTER_PCTYPE_FRAG_IPV6) {
738 : 0 : payload = raw_pkt + len;
739 : : set_idx = I40E_FLXPLD_L3_IDX;
740 : : } else if (pctype == I40E_FILTER_PCTYPE_L2_PAYLOAD) {
741 : 0 : payload = raw_pkt + len;
742 : : /**
743 : : * ARP packet is a special case on which the payload
744 : : * starts after the whole ARP header
745 : : */
746 [ # # ]: 0 : if (fdir_input->flow.l2_flow.ether_type ==
747 : : rte_cpu_to_be_16(RTE_ETHER_TYPE_ARP))
748 : 0 : payload += sizeof(struct rte_arp_hdr);
749 : : set_idx = I40E_FLXPLD_L2_IDX;
750 [ # # ]: 0 : } else if (fdir_input->flow_ext.customized_pctype) {
751 : : /* If customized pctype is used */
752 : : cus_pctype = i40e_flow_fdir_find_customized_pctype(pf, pctype);
753 [ # # ]: 0 : if (cus_pctype->index == I40E_CUSTOMIZED_GTPC ||
754 : : cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV4 ||
755 : : cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV6 ||
756 : : cus_pctype->index == I40E_CUSTOMIZED_GTPU) {
757 : 0 : udp = (struct rte_udp_hdr *)(raw_pkt + len);
758 : 0 : udp->dgram_len =
759 : : rte_cpu_to_be_16(I40E_FDIR_UDP_DEFAULT_LEN);
760 : :
761 : : gtp = (struct rte_flow_item_gtp *)
762 : : ((unsigned char *)udp +
763 : : sizeof(struct rte_udp_hdr));
764 : 0 : gtp->hdr.plen =
765 : : rte_cpu_to_be_16(I40E_FDIR_GTP_DEFAULT_LEN);
766 : 0 : gtp->hdr.teid = fdir_input->flow.gtp_flow.teid;
767 : 0 : gtp->hdr.msg_type = I40E_FDIR_GTP_MSG_TYPE_0X01;
768 : :
769 : : /* GTP-C message type is not supported. */
770 [ # # ]: 0 : if (cus_pctype->index == I40E_CUSTOMIZED_GTPC) {
771 : 0 : udp->dst_port =
772 : : rte_cpu_to_be_16(I40E_FDIR_GTPC_DST_PORT);
773 : 0 : gtp->hdr.gtp_hdr_info =
774 : : I40E_FDIR_GTP_VER_FLAG_0X32;
775 : : } else {
776 : 0 : udp->dst_port =
777 : : rte_cpu_to_be_16(I40E_FDIR_GTPU_DST_PORT);
778 : 0 : gtp->hdr.gtp_hdr_info =
779 : : I40E_FDIR_GTP_VER_FLAG_0X30;
780 : : }
781 : :
782 [ # # ]: 0 : if (cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV4) {
783 : 0 : gtp->hdr.msg_type = I40E_FDIR_GTP_MSG_TYPE_0XFF;
784 : : gtp_ipv4 = (struct rte_ipv4_hdr *)
785 : : ((unsigned char *)gtp +
786 : : sizeof(struct rte_flow_item_gtp));
787 : 0 : gtp_ipv4->version_ihl =
788 : : I40E_FDIR_IP_DEFAULT_VERSION_IHL;
789 : 0 : gtp_ipv4->next_proto_id = IPPROTO_IP;
790 : 0 : gtp_ipv4->total_length =
791 : : rte_cpu_to_be_16(
792 : : I40E_FDIR_INNER_IP_DEFAULT_LEN);
793 : 0 : payload = (unsigned char *)gtp_ipv4 +
794 : : sizeof(struct rte_ipv4_hdr);
795 [ # # ]: 0 : } else if (cus_pctype->index ==
796 : : I40E_CUSTOMIZED_GTPU_IPV6) {
797 : 0 : gtp->hdr.msg_type = I40E_FDIR_GTP_MSG_TYPE_0XFF;
798 : : gtp_ipv6 = (struct rte_ipv6_hdr *)
799 : : ((unsigned char *)gtp +
800 : : sizeof(struct rte_flow_item_gtp));
801 : 0 : gtp_ipv6->vtc_flow =
802 : : rte_cpu_to_be_32(
803 : : I40E_FDIR_IPv6_DEFAULT_VTC_FLOW |
804 : : (0 << I40E_FDIR_IPv6_TC_OFFSET));
805 : 0 : gtp_ipv6->proto = IPPROTO_NONE;
806 : 0 : gtp_ipv6->payload_len =
807 : : rte_cpu_to_be_16(
808 : : I40E_FDIR_INNER_IPV6_DEFAULT_LEN);
809 : 0 : gtp_ipv6->hop_limits =
810 : : I40E_FDIR_IPv6_DEFAULT_HOP_LIMITS;
811 : 0 : payload = (unsigned char *)gtp_ipv6 +
812 : : sizeof(struct rte_ipv6_hdr);
813 : : } else
814 : 0 : payload = (unsigned char *)gtp +
815 : : sizeof(struct rte_flow_item_gtp);
816 [ # # ]: 0 : } else if (cus_pctype->index == I40E_CUSTOMIZED_IPV4_L2TPV3 ||
817 : : cus_pctype->index == I40E_CUSTOMIZED_IPV6_L2TPV3) {
818 : 0 : l2tpv3oip = (struct rte_flow_item_l2tpv3oip *)(raw_pkt
819 : 0 : + len);
820 : :
821 [ # # ]: 0 : if (cus_pctype->index == I40E_CUSTOMIZED_IPV4_L2TPV3)
822 : 0 : l2tpv3oip->session_id =
823 : 0 : fdir_input->flow.ip4_l2tpv3oip_flow.session_id;
824 : : else
825 : 0 : l2tpv3oip->session_id =
826 : 0 : fdir_input->flow.ip6_l2tpv3oip_flow.session_id;
827 : 0 : payload = (unsigned char *)l2tpv3oip +
828 : : sizeof(struct rte_flow_item_l2tpv3oip);
829 : 0 : } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4 ||
830 : : cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6 ||
831 [ # # ]: 0 : cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4_UDP ||
832 : : cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6_UDP) {
833 [ # # ]: 0 : if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4) {
834 : 0 : esp_ipv4 = (struct rte_ipv4_hdr *)
835 : 0 : (raw_pkt + len);
836 : : esp = (struct rte_flow_item_esp *)esp_ipv4;
837 : 0 : esp->hdr.spi =
838 : 0 : fdir_input->flow.esp_ipv4_flow.spi;
839 : 0 : payload = (unsigned char *)esp +
840 : : sizeof(struct rte_esp_hdr);
841 : : len += sizeof(struct rte_esp_hdr);
842 [ # # ]: 0 : } else if (cus_pctype->index ==
843 : : I40E_CUSTOMIZED_ESP_IPV4_UDP) {
844 : 0 : esp_ipv4 = (struct rte_ipv4_hdr *)
845 : 0 : (raw_pkt + len);
846 : : udp = (struct rte_udp_hdr *)esp_ipv4;
847 : 0 : udp->dst_port = rte_cpu_to_be_16
848 : : (I40E_FDIR_ESP_DST_PORT);
849 : :
850 : 0 : udp->dgram_len = rte_cpu_to_be_16
851 : : (I40E_FDIR_UDP_DEFAULT_LEN);
852 : : esp = (struct rte_flow_item_esp *)
853 : : ((unsigned char *)esp_ipv4 +
854 : : sizeof(struct rte_udp_hdr));
855 : 0 : esp->hdr.spi =
856 : 0 : fdir_input->flow.esp_ipv4_udp_flow.spi;
857 : 0 : payload = (unsigned char *)esp +
858 : : sizeof(struct rte_esp_hdr);
859 : : len += sizeof(struct rte_udp_hdr) +
860 : : sizeof(struct rte_esp_hdr);
861 [ # # ]: 0 : } else if (cus_pctype->index ==
862 : : I40E_CUSTOMIZED_ESP_IPV6) {
863 : 0 : esp_ipv6 = (struct rte_ipv6_hdr *)
864 : 0 : (raw_pkt + len);
865 : : esp = (struct rte_flow_item_esp *)esp_ipv6;
866 : 0 : esp->hdr.spi =
867 : 0 : fdir_input->flow.esp_ipv6_flow.spi;
868 : 0 : payload = (unsigned char *)esp +
869 : : sizeof(struct rte_esp_hdr);
870 : : len += sizeof(struct rte_esp_hdr);
871 : : } else if (cus_pctype->index ==
872 : : I40E_CUSTOMIZED_ESP_IPV6_UDP) {
873 : 0 : esp_ipv6 = (struct rte_ipv6_hdr *)
874 : 0 : (raw_pkt + len);
875 : : udp = (struct rte_udp_hdr *)esp_ipv6;
876 : 0 : udp->dst_port = rte_cpu_to_be_16
877 : : (I40E_FDIR_ESP_DST_PORT);
878 : :
879 : 0 : udp->dgram_len = rte_cpu_to_be_16
880 : : (I40E_FDIR_UDP_DEFAULT_LEN);
881 : : esp = (struct rte_flow_item_esp *)
882 : : ((unsigned char *)esp_ipv6 +
883 : : sizeof(struct rte_udp_hdr));
884 : 0 : esp->hdr.spi =
885 : 0 : fdir_input->flow.esp_ipv6_udp_flow.spi;
886 : 0 : payload = (unsigned char *)esp +
887 : : sizeof(struct rte_esp_hdr);
888 : : len += sizeof(struct rte_udp_hdr) +
889 : : sizeof(struct rte_esp_hdr);
890 : : }
891 : : }
892 : : } else {
893 : 0 : PMD_DRV_LOG(ERR, "unknown pctype %u.", fdir_input->pctype);
894 : 0 : return -1;
895 : : }
896 : :
897 : : /* fill the flexbytes to payload */
898 [ # # ]: 0 : for (i = 0; i < I40E_MAX_FLXPLD_FIED; i++) {
899 : 0 : pit_idx = set_idx * I40E_MAX_FLXPLD_FIED + i;
900 : 0 : size = pf->fdir.flex_set[pit_idx].size;
901 [ # # ]: 0 : if (size == 0)
902 : 0 : continue;
903 : 0 : dst = pf->fdir.flex_set[pit_idx].dst_offset * sizeof(uint16_t);
904 : 0 : ptr = payload +
905 : 0 : pf->fdir.flex_set[pit_idx].src_offset * sizeof(uint16_t);
906 : 0 : (void)rte_memcpy(ptr,
907 [ # # ]: 0 : &fdir_input->flow_ext.flexbytes[dst],
908 : : size * sizeof(uint16_t));
909 : : }
910 : :
911 : : return 0;
912 : : }
913 : :
914 : : /* Construct the tx flags */
915 : : static inline uint64_t
916 : : i40e_build_ctob(uint32_t td_cmd,
917 : : uint32_t td_offset,
918 : : unsigned int size,
919 : : uint32_t td_tag)
920 : : {
921 : : return rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DATA |
922 : : ((uint64_t)td_cmd << I40E_TXD_QW1_CMD_SHIFT) |
923 : : ((uint64_t)td_offset << I40E_TXD_QW1_OFFSET_SHIFT) |
924 : : ((uint64_t)size << I40E_TXD_QW1_TX_BUF_SZ_SHIFT) |
925 : : ((uint64_t)td_tag << I40E_TXD_QW1_L2TAG1_SHIFT));
926 : : }
927 : :
928 : : /*
929 : : * check the programming status descriptor in rx queue.
930 : : * done after Programming Flow Director is programmed on
931 : : * tx queue
932 : : */
933 : : static inline int
934 : 0 : i40e_check_fdir_programming_status(struct i40e_rx_queue *rxq)
935 : : {
936 : : volatile union i40e_rx_desc *rxdp;
937 : : uint64_t qword1;
938 : : uint32_t rx_status;
939 : : uint32_t len, id;
940 : : uint32_t error;
941 : : int ret = 0;
942 : :
943 : 0 : rxdp = &rxq->rx_ring[rxq->rx_tail];
944 : 0 : qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
945 : : rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK)
946 : 0 : >> I40E_RXD_QW1_STATUS_SHIFT;
947 : :
948 [ # # ]: 0 : if (rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)) {
949 : 0 : len = qword1 >> I40E_RX_PROG_STATUS_DESC_LENGTH_SHIFT;
950 : 0 : id = (qword1 & I40E_RX_PROG_STATUS_DESC_QW1_PROGID_MASK) >>
951 : : I40E_RX_PROG_STATUS_DESC_QW1_PROGID_SHIFT;
952 : :
953 : 0 : if (len == I40E_RX_PROG_STATUS_DESC_LENGTH &&
954 [ # # ]: 0 : id == I40E_RX_PROG_STATUS_DESC_FD_FILTER_STATUS) {
955 : 0 : error = (qword1 &
956 : 0 : I40E_RX_PROG_STATUS_DESC_QW1_ERROR_MASK) >>
957 : : I40E_RX_PROG_STATUS_DESC_QW1_ERROR_SHIFT;
958 [ # # ]: 0 : if (error == (0x1 <<
959 : : I40E_RX_PROG_STATUS_DESC_FD_TBL_FULL_SHIFT)) {
960 : 0 : PMD_DRV_LOG(ERR, "Failed to add FDIR filter"
961 : : " (FD_ID %u): programming status"
962 : : " reported.",
963 : : rxdp->wb.qword0.hi_dword.fd_id);
964 : : ret = -1;
965 [ # # ]: 0 : } else if (error == (0x1 <<
966 : : I40E_RX_PROG_STATUS_DESC_NO_FD_ENTRY_SHIFT)) {
967 : 0 : PMD_DRV_LOG(ERR, "Failed to delete FDIR filter"
968 : : " (FD_ID %u): programming status"
969 : : " reported.",
970 : : rxdp->wb.qword0.hi_dword.fd_id);
971 : : ret = -1;
972 : : } else
973 : 0 : PMD_DRV_LOG(ERR, "invalid programming status"
974 : : " reported, error = %u.", error);
975 : : } else
976 : 0 : PMD_DRV_LOG(INFO, "unknown programming status"
977 : : " reported, len = %d, id = %u.", len, id);
978 : 0 : rxdp->wb.qword1.status_error_len = 0;
979 : 0 : rxq->rx_tail++;
980 [ # # ]: 0 : if (unlikely(rxq->rx_tail == rxq->nb_rx_desc))
981 : 0 : rxq->rx_tail = 0;
982 [ # # ]: 0 : if (rxq->rx_tail == 0)
983 : 0 : I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
984 : : else
985 : 0 : I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->rx_tail - 1);
986 : : }
987 : :
988 : 0 : return ret;
989 : : }
990 : :
991 : : static inline void
992 : 0 : i40e_fdir_programming_status_cleanup(struct i40e_rx_queue *rxq)
993 : : {
994 : : uint16_t retry_count = 0;
995 : :
996 : : /* capture the previous error report(if any) from rx ring */
997 [ # # # # ]: 0 : while ((i40e_check_fdir_programming_status(rxq) < 0) &&
998 : : (++retry_count < I40E_FDIR_NUM_RX_DESC))
999 : 0 : PMD_DRV_LOG(INFO, "error report captured.");
1000 : 0 : }
1001 : :
1002 : : static int
1003 : 0 : i40e_fdir_filter_convert(const struct i40e_fdir_filter_conf *input,
1004 : : struct i40e_fdir_filter *filter)
1005 : : {
1006 [ # # ]: 0 : rte_memcpy(&filter->fdir, input, sizeof(struct i40e_fdir_filter_conf));
1007 [ # # ]: 0 : if (input->input.flow_ext.pkt_template) {
1008 : 0 : filter->fdir.input.flow.raw_flow.packet = NULL;
1009 : 0 : filter->fdir.input.flow.raw_flow.length =
1010 : 0 : rte_hash_crc(input->input.flow.raw_flow.packet,
1011 : 0 : input->input.flow.raw_flow.length,
1012 : 0 : input->input.flow.raw_flow.pctype);
1013 : : }
1014 : 0 : return 0;
1015 : : }
1016 : :
1017 : : /* Check if there exists the flow director filter */
1018 : : static struct i40e_fdir_filter *
1019 : 0 : i40e_sw_fdir_filter_lookup(struct i40e_fdir_info *fdir_info,
1020 : : const struct i40e_fdir_input *input)
1021 : : {
1022 : : int ret;
1023 : :
1024 [ # # ]: 0 : if (input->flow_ext.pkt_template)
1025 : 0 : ret = rte_hash_lookup_with_hash(fdir_info->hash_table,
1026 : : (const void *)input,
1027 : 0 : input->flow.raw_flow.length);
1028 : : else
1029 : 0 : ret = rte_hash_lookup(fdir_info->hash_table,
1030 : : (const void *)input);
1031 [ # # ]: 0 : if (ret < 0)
1032 : : return NULL;
1033 : :
1034 : 0 : return fdir_info->hash_map[ret];
1035 : : }
1036 : :
1037 : : /* Add a flow director filter into the SW list */
1038 : : static int
1039 : 0 : i40e_sw_fdir_filter_insert(struct i40e_pf *pf, struct i40e_fdir_filter *filter)
1040 : : {
1041 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1042 : : struct i40e_fdir_filter *hash_filter;
1043 : : int ret;
1044 : :
1045 [ # # ]: 0 : if (filter->fdir.input.flow_ext.pkt_template)
1046 : 0 : ret = rte_hash_add_key_with_hash(fdir_info->hash_table,
1047 : 0 : &filter->fdir.input,
1048 : : filter->fdir.input.flow.raw_flow.length);
1049 : : else
1050 : 0 : ret = rte_hash_add_key(fdir_info->hash_table,
1051 : 0 : &filter->fdir.input);
1052 [ # # ]: 0 : if (ret < 0) {
1053 : 0 : PMD_DRV_LOG(ERR,
1054 : : "Failed to insert fdir filter to hash table %d!",
1055 : : ret);
1056 : 0 : return ret;
1057 : : }
1058 : :
1059 [ # # ]: 0 : if (fdir_info->hash_map[ret])
1060 : : return -1;
1061 : :
1062 [ # # ]: 0 : hash_filter = &fdir_info->fdir_filter_array[ret];
1063 : : rte_memcpy(hash_filter, filter, sizeof(*filter));
1064 : 0 : fdir_info->hash_map[ret] = hash_filter;
1065 : 0 : TAILQ_INSERT_TAIL(&fdir_info->fdir_list, hash_filter, rules);
1066 : :
1067 : 0 : return 0;
1068 : : }
1069 : :
1070 : : /* Delete a flow director filter from the SW list */
1071 : : int
1072 : 0 : i40e_sw_fdir_filter_del(struct i40e_pf *pf, struct i40e_fdir_input *input)
1073 : : {
1074 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1075 : : struct i40e_fdir_filter *filter;
1076 : : int ret;
1077 : :
1078 [ # # ]: 0 : if (input->flow_ext.pkt_template)
1079 : 0 : ret = rte_hash_del_key_with_hash(fdir_info->hash_table,
1080 : : input,
1081 : : input->flow.raw_flow.length);
1082 : : else
1083 : 0 : ret = rte_hash_del_key(fdir_info->hash_table, input);
1084 [ # # ]: 0 : if (ret < 0) {
1085 : 0 : PMD_DRV_LOG(ERR,
1086 : : "Failed to delete fdir filter to hash table %d!",
1087 : : ret);
1088 : 0 : return ret;
1089 : : }
1090 : 0 : filter = fdir_info->hash_map[ret];
1091 : 0 : fdir_info->hash_map[ret] = NULL;
1092 : :
1093 [ # # ]: 0 : TAILQ_REMOVE(&fdir_info->fdir_list, filter, rules);
1094 : :
1095 : 0 : return 0;
1096 : : }
1097 : :
1098 : : struct rte_flow *
1099 : 0 : i40e_fdir_entry_pool_get(struct i40e_fdir_info *fdir_info)
1100 : : {
1101 : : struct rte_flow *flow = NULL;
1102 : 0 : uint64_t slab = 0;
1103 : 0 : uint32_t pos = 0;
1104 : : uint32_t i = 0;
1105 : : int ret;
1106 : :
1107 : 0 : if (fdir_info->fdir_actual_cnt >=
1108 [ # # ]: 0 : fdir_info->fdir_space_size) {
1109 : 0 : PMD_DRV_LOG(ERR, "Fdir space full");
1110 : 0 : return NULL;
1111 : : }
1112 : :
1113 : 0 : ret = rte_bitmap_scan(fdir_info->fdir_flow_pool.bitmap, &pos,
1114 : : &slab);
1115 : :
1116 : : /* normally this won't happen as the fdir_actual_cnt should be
1117 : : * same with the number of the set bits in fdir_flow_pool,
1118 : : * but anyway handle this error condition here for safe
1119 : : */
1120 [ # # ]: 0 : if (ret == 0) {
1121 : 0 : PMD_DRV_LOG(ERR, "fdir_actual_cnt out of sync");
1122 : 0 : return NULL;
1123 : : }
1124 : :
1125 : 0 : i = rte_bsf64(slab);
1126 : 0 : pos += i;
1127 : 0 : rte_bitmap_clear(fdir_info->fdir_flow_pool.bitmap, pos);
1128 : 0 : flow = &fdir_info->fdir_flow_pool.pool[pos].flow;
1129 : :
1130 : : memset(flow, 0, sizeof(struct rte_flow));
1131 : :
1132 : 0 : return flow;
1133 : : }
1134 : :
1135 : : void
1136 : 0 : i40e_fdir_entry_pool_put(struct i40e_fdir_info *fdir_info,
1137 : : struct rte_flow *flow)
1138 : : {
1139 : : struct i40e_fdir_entry *f;
1140 : :
1141 : : f = FLOW_TO_FLOW_BITMAP(flow);
1142 : 0 : rte_bitmap_set(fdir_info->fdir_flow_pool.bitmap, f->idx);
1143 : 0 : }
1144 : :
1145 : : static int
1146 : 0 : i40e_flow_store_flex_pit(struct i40e_pf *pf,
1147 : : struct i40e_fdir_flex_pit *flex_pit,
1148 : : enum i40e_flxpld_layer_idx layer_idx,
1149 : : uint8_t raw_id)
1150 : : {
1151 : : uint8_t field_idx;
1152 : :
1153 : 0 : field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + raw_id;
1154 : : /* Check if the configuration is conflicted */
1155 [ # # ]: 0 : if (pf->fdir.flex_pit_flag[layer_idx] &&
1156 [ # # ]: 0 : (pf->fdir.flex_set[field_idx].src_offset != flex_pit->src_offset ||
1157 [ # # ]: 0 : pf->fdir.flex_set[field_idx].size != flex_pit->size ||
1158 [ # # ]: 0 : pf->fdir.flex_set[field_idx].dst_offset != flex_pit->dst_offset))
1159 : : return -1;
1160 : :
1161 : : /* Check if the configuration exists. */
1162 [ # # ]: 0 : if (pf->fdir.flex_pit_flag[layer_idx] &&
1163 [ # # ]: 0 : (pf->fdir.flex_set[field_idx].src_offset == flex_pit->src_offset &&
1164 [ # # ]: 0 : pf->fdir.flex_set[field_idx].size == flex_pit->size &&
1165 [ # # ]: 0 : pf->fdir.flex_set[field_idx].dst_offset == flex_pit->dst_offset))
1166 : : return 1;
1167 : :
1168 : 0 : pf->fdir.flex_set[field_idx].src_offset =
1169 : 0 : flex_pit->src_offset;
1170 : 0 : pf->fdir.flex_set[field_idx].size =
1171 : 0 : flex_pit->size;
1172 : 0 : pf->fdir.flex_set[field_idx].dst_offset =
1173 : 0 : flex_pit->dst_offset;
1174 : :
1175 : 0 : return 0;
1176 : : }
1177 : :
1178 : : static void
1179 : 0 : i40e_flow_set_fdir_flex_pit(struct i40e_pf *pf,
1180 : : enum i40e_flxpld_layer_idx layer_idx,
1181 : : uint8_t raw_id)
1182 : : {
1183 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1184 : : uint32_t flx_pit, flx_ort;
1185 : : uint16_t min_next_off = 0;
1186 : : uint8_t field_idx;
1187 : : uint8_t i;
1188 : :
1189 [ # # ]: 0 : if (raw_id) {
1190 : 0 : flx_ort = (1 << I40E_GLQF_ORT_FLX_PAYLOAD_SHIFT) |
1191 : 0 : (raw_id << I40E_GLQF_ORT_FIELD_CNT_SHIFT) |
1192 : 0 : (layer_idx * I40E_MAX_FLXPLD_FIED);
1193 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(33 + layer_idx), flx_ort);
1194 : : }
1195 : :
1196 : : /* Set flex pit */
1197 [ # # ]: 0 : for (i = 0; i < raw_id; i++) {
1198 : 0 : field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
1199 [ # # ]: 0 : flx_pit = MK_FLX_PIT(pf->fdir.flex_set[field_idx].src_offset,
1200 : : pf->fdir.flex_set[field_idx].size,
1201 : : pf->fdir.flex_set[field_idx].dst_offset);
1202 : :
1203 : 0 : I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(field_idx), flx_pit);
1204 : 0 : min_next_off = pf->fdir.flex_set[field_idx].src_offset +
1205 : 0 : pf->fdir.flex_set[field_idx].size;
1206 : : }
1207 : :
1208 [ # # ]: 0 : for (; i < I40E_MAX_FLXPLD_FIED; i++) {
1209 : : /* set the non-used register obeying register's constrain */
1210 : 0 : field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
1211 : 0 : flx_pit = MK_FLX_PIT(min_next_off, NONUSE_FLX_PIT_FSIZE,
1212 : : NONUSE_FLX_PIT_DEST_OFF);
1213 : 0 : I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(field_idx), flx_pit);
1214 : 0 : min_next_off++;
1215 : : }
1216 : 0 : }
1217 : :
1218 : : static int
1219 : 0 : i40e_flow_store_flex_mask(struct i40e_pf *pf,
1220 : : enum i40e_filter_pctype pctype,
1221 : : uint8_t *mask)
1222 : : {
1223 : : struct i40e_fdir_flex_mask flex_mask;
1224 : : uint8_t nb_bitmask = 0;
1225 : : uint16_t mask_tmp;
1226 : : uint8_t i;
1227 : :
1228 : : memset(&flex_mask, 0, sizeof(struct i40e_fdir_flex_mask));
1229 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_MAX_FLEX_LEN; i += sizeof(uint16_t)) {
1230 : 0 : mask_tmp = I40E_WORD(mask[i], mask[i + 1]);
1231 [ # # ]: 0 : if (mask_tmp) {
1232 : 0 : flex_mask.word_mask |=
1233 : 0 : I40E_FLEX_WORD_MASK(i / sizeof(uint16_t));
1234 [ # # ]: 0 : if (mask_tmp != UINT16_MAX) {
1235 : 0 : flex_mask.bitmask[nb_bitmask].mask = ~mask_tmp;
1236 : 0 : flex_mask.bitmask[nb_bitmask].offset =
1237 : : i / sizeof(uint16_t);
1238 : 0 : nb_bitmask++;
1239 [ # # ]: 0 : if (nb_bitmask > I40E_FDIR_BITMASK_NUM_WORD)
1240 : : return -1;
1241 : : }
1242 : : }
1243 : : }
1244 : 0 : flex_mask.nb_bitmask = nb_bitmask;
1245 : :
1246 [ # # ]: 0 : if (pf->fdir.flex_mask_flag[pctype] &&
1247 [ # # ]: 0 : (memcmp(&flex_mask, &pf->fdir.flex_mask[pctype],
1248 : : sizeof(struct i40e_fdir_flex_mask))))
1249 : : return -2;
1250 [ # # ]: 0 : else if (pf->fdir.flex_mask_flag[pctype] &&
1251 [ # # ]: 0 : !(memcmp(&flex_mask, &pf->fdir.flex_mask[pctype],
1252 : : sizeof(struct i40e_fdir_flex_mask))))
1253 : : return 1;
1254 : :
1255 : 0 : memcpy(&pf->fdir.flex_mask[pctype], &flex_mask,
1256 : : sizeof(struct i40e_fdir_flex_mask));
1257 : 0 : return 0;
1258 : : }
1259 : :
1260 : : static void
1261 : 0 : i40e_flow_set_fdir_flex_msk(struct i40e_pf *pf,
1262 : : enum i40e_filter_pctype pctype)
1263 : : {
1264 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1265 : : struct i40e_fdir_flex_mask *flex_mask;
1266 : : uint32_t flxinset, fd_mask;
1267 : : uint8_t i;
1268 : :
1269 : : /* Set flex mask */
1270 : : flex_mask = &pf->fdir.flex_mask[pctype];
1271 : 0 : flxinset = (flex_mask->word_mask <<
1272 : : I40E_PRTQF_FD_FLXINSET_INSET_SHIFT) &
1273 : : I40E_PRTQF_FD_FLXINSET_INSET_MASK;
1274 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_FD_FLXINSET(pctype), flxinset);
1275 : :
1276 [ # # ]: 0 : for (i = 0; i < flex_mask->nb_bitmask; i++) {
1277 : 0 : fd_mask = (flex_mask->bitmask[i].mask <<
1278 : : I40E_PRTQF_FD_MSK_MASK_SHIFT) &
1279 : : I40E_PRTQF_FD_MSK_MASK_MASK;
1280 : 0 : fd_mask |= ((flex_mask->bitmask[i].offset +
1281 : 0 : I40E_FLX_OFFSET_IN_FIELD_VECTOR) <<
1282 : 0 : I40E_PRTQF_FD_MSK_OFFSET_SHIFT) &
1283 : : I40E_PRTQF_FD_MSK_OFFSET_MASK;
1284 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_FD_MSK(pctype, i), fd_mask);
1285 : : }
1286 : :
1287 : 0 : pf->fdir.flex_mask_flag[pctype] = 1;
1288 : 0 : }
1289 : :
1290 : : static int
1291 : 0 : i40e_flow_set_fdir_inset(struct i40e_pf *pf,
1292 : : enum i40e_filter_pctype pctype,
1293 : : uint64_t input_set)
1294 : : {
1295 : 0 : uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
1296 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1297 : : uint64_t inset_reg = 0;
1298 : : int i, num;
1299 : :
1300 : : /* Check if the input set is valid */
1301 [ # # ]: 0 : if (i40e_validate_input_set(pctype, RTE_ETH_FILTER_FDIR,
1302 : : input_set) != 0) {
1303 : 0 : PMD_DRV_LOG(ERR, "Invalid input set");
1304 : 0 : return -EINVAL;
1305 : : }
1306 : :
1307 : : /* Check if the configuration is conflicted */
1308 [ # # ]: 0 : if (pf->fdir.flow_count[pctype] &&
1309 [ # # ]: 0 : memcmp(&pf->fdir.input_set[pctype], &input_set, sizeof(uint64_t))) {
1310 : 0 : PMD_DRV_LOG(ERR, "Conflict with the first rule's input set.");
1311 : 0 : return -EINVAL;
1312 : : }
1313 : :
1314 [ # # ]: 0 : if (pf->fdir.flow_count[pctype] &&
1315 [ # # ]: 0 : !memcmp(&pf->fdir.input_set[pctype], &input_set, sizeof(uint64_t)))
1316 : : return 0;
1317 : :
1318 : 0 : num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
1319 : : I40E_INSET_MASK_NUM_REG);
1320 [ # # ]: 0 : if (num < 0) {
1321 : 0 : PMD_DRV_LOG(ERR, "Invalid pattern mask.");
1322 : 0 : return -EINVAL;
1323 : : }
1324 : :
1325 [ # # ]: 0 : if (pf->support_multi_driver) {
1326 [ # # ]: 0 : for (i = 0; i < num; i++)
1327 : 0 : if (i40e_read_rx_ctl(hw,
1328 : 0 : I40E_GLQF_FD_MSK(i, pctype)) !=
1329 [ # # ]: 0 : mask_reg[i]) {
1330 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not"
1331 : : " supported with"
1332 : : " `support-multi-driver`"
1333 : : " enabled!");
1334 : 0 : return -EPERM;
1335 : : }
1336 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
1337 [ # # ]: 0 : if (i40e_read_rx_ctl(hw,
1338 : 0 : I40E_GLQF_FD_MSK(i, pctype)) != 0) {
1339 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not"
1340 : : " supported with"
1341 : : " `support-multi-driver`"
1342 : : " enabled!");
1343 : 0 : return -EPERM;
1344 : : }
1345 : :
1346 : : } else {
1347 [ # # ]: 0 : for (i = 0; i < num; i++)
1348 : 0 : i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
1349 : : mask_reg[i]);
1350 : : /*clear unused mask registers of the pctype */
1351 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
1352 : 0 : i40e_check_write_reg(hw,
1353 : 0 : I40E_GLQF_FD_MSK(i, pctype), 0);
1354 : : }
1355 : :
1356 : 0 : inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
1357 : :
1358 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
1359 : : (uint32_t)(inset_reg & UINT32_MAX));
1360 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
1361 : 0 : (uint32_t)((inset_reg >>
1362 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
1363 : :
1364 : 0 : I40E_WRITE_FLUSH(hw);
1365 : :
1366 : 0 : pf->fdir.input_set[pctype] = input_set;
1367 : 0 : return 0;
1368 : : }
1369 : :
1370 : : static inline unsigned char *
1371 : 0 : i40e_find_available_buffer(struct rte_eth_dev *dev)
1372 : : {
1373 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1374 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1375 : 0 : struct i40e_tx_queue *txq = pf->fdir.txq;
1376 : :
1377 : : /* no available buffer
1378 : : * search for more available buffers from the current
1379 : : * descriptor, until an unavailable one
1380 : : */
1381 [ # # ]: 0 : if (fdir_info->txq_available_buf_count <= 0) {
1382 : : uint16_t tmp_tail;
1383 : : volatile struct i40e_tx_desc *tmp_txdp;
1384 : :
1385 : 0 : tmp_tail = txq->tx_tail;
1386 : 0 : tmp_txdp = &txq->tx_ring[tmp_tail + 1];
1387 : :
1388 : : do {
1389 [ # # ]: 0 : if ((tmp_txdp->cmd_type_offset_bsz &
1390 : : rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) ==
1391 : : rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
1392 : 0 : fdir_info->txq_available_buf_count++;
1393 : : else
1394 : : break;
1395 : :
1396 : 0 : tmp_tail += 2;
1397 [ # # ]: 0 : if (tmp_tail >= txq->nb_tx_desc)
1398 : : tmp_tail = 0;
1399 [ # # ]: 0 : } while (tmp_tail != txq->tx_tail);
1400 : : }
1401 : :
1402 [ # # ]: 0 : if (fdir_info->txq_available_buf_count > 0)
1403 : 0 : fdir_info->txq_available_buf_count--;
1404 : : else
1405 : : return NULL;
1406 : 0 : return (unsigned char *)fdir_info->prg_pkt[txq->tx_tail >> 1];
1407 : : }
1408 : :
1409 : : /**
1410 : : * i40e_flow_add_del_fdir_filter - add or remove a flow director filter.
1411 : : * @pf: board private structure
1412 : : * @filter: fdir filter entry
1413 : : * @add: 0 - delete, 1 - add
1414 : : */
1415 : : int
1416 : 0 : i40e_flow_add_del_fdir_filter(struct rte_eth_dev *dev,
1417 : : const struct i40e_fdir_filter_conf *filter,
1418 : : bool add)
1419 : : {
1420 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1421 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1422 : : enum i40e_flxpld_layer_idx layer_idx = I40E_FLXPLD_L2_IDX;
1423 : 0 : struct i40e_fdir_info *fdir_info = &pf->fdir;
1424 : : uint8_t flex_mask[I40E_FDIR_MAX_FLEX_LEN];
1425 : : struct i40e_fdir_filter check_filter; /* Check if the filter exists */
1426 : : struct i40e_fdir_flex_pit flex_pit;
1427 : : enum i40e_filter_pctype pctype;
1428 : : struct i40e_fdir_filter *node;
1429 : : unsigned char *pkt = NULL;
1430 : : bool cfg_flex_pit = true;
1431 : : bool wait_status = true;
1432 : : uint8_t field_idx;
1433 : : int ret = 0;
1434 : : int i;
1435 : :
1436 [ # # ]: 0 : if (pf->fdir.fdir_vsi == NULL) {
1437 : 0 : PMD_DRV_LOG(ERR, "FDIR is not enabled");
1438 : 0 : return -ENOTSUP;
1439 : : }
1440 : :
1441 [ # # ]: 0 : if (filter->action.rx_queue >= pf->dev_data->nb_rx_queues) {
1442 : 0 : PMD_DRV_LOG(ERR, "Invalid queue ID");
1443 : 0 : return -EINVAL;
1444 : : }
1445 [ # # ]: 0 : if (filter->input.flow_ext.is_vf &&
1446 [ # # ]: 0 : filter->input.flow_ext.dst_id >= pf->vf_num) {
1447 : 0 : PMD_DRV_LOG(ERR, "Invalid VF ID");
1448 : 0 : return -EINVAL;
1449 : : }
1450 [ # # ]: 0 : if (filter->input.flow_ext.pkt_template) {
1451 [ # # ]: 0 : if (filter->input.flow.raw_flow.length > I40E_FDIR_PKT_LEN ||
1452 [ # # ]: 0 : !filter->input.flow.raw_flow.packet) {
1453 : 0 : PMD_DRV_LOG(ERR, "Invalid raw packet template"
1454 : : " flow filter parameters!");
1455 : 0 : return -EINVAL;
1456 : : }
1457 : 0 : pctype = filter->input.flow.raw_flow.pctype;
1458 : : } else {
1459 : 0 : pctype = filter->input.pctype;
1460 : : }
1461 : :
1462 : : /* Check if there is the filter in SW list */
1463 : : memset(&check_filter, 0, sizeof(check_filter));
1464 : 0 : i40e_fdir_filter_convert(filter, &check_filter);
1465 : :
1466 [ # # ]: 0 : if (add) {
1467 : : /* configure the input set for common PCTYPEs*/
1468 [ # # ]: 0 : if (!filter->input.flow_ext.customized_pctype &&
1469 [ # # ]: 0 : !filter->input.flow_ext.pkt_template) {
1470 : 0 : ret = i40e_flow_set_fdir_inset(pf, pctype,
1471 : 0 : filter->input.flow_ext.input_set);
1472 [ # # ]: 0 : if (ret < 0)
1473 : : return ret;
1474 : : }
1475 : :
1476 [ # # ]: 0 : if (filter->input.flow_ext.is_flex_flow) {
1477 [ # # ]: 0 : for (i = 0; i < filter->input.flow_ext.raw_id; i++) {
1478 : 0 : layer_idx = filter->input.flow_ext.layer_idx;
1479 : 0 : field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
1480 : 0 : flex_pit = filter->input.flow_ext.flex_pit[field_idx];
1481 : :
1482 : : /* Store flex pit to SW */
1483 : 0 : ret = i40e_flow_store_flex_pit(pf, &flex_pit,
1484 : : layer_idx, i);
1485 [ # # ]: 0 : if (ret < 0) {
1486 : 0 : PMD_DRV_LOG(ERR, "Conflict with the"
1487 : : " first flexible rule.");
1488 : 0 : return -EINVAL;
1489 [ # # ]: 0 : } else if (ret > 0) {
1490 : : cfg_flex_pit = false;
1491 : : }
1492 : : }
1493 : :
1494 [ # # ]: 0 : if (cfg_flex_pit)
1495 : 0 : i40e_flow_set_fdir_flex_pit(pf, layer_idx,
1496 : : filter->input.flow_ext.raw_id);
1497 : :
1498 : : /* Store flex mask to SW */
1499 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_MAX_FLEX_LEN; i++)
1500 : 0 : flex_mask[i] =
1501 : 0 : filter->input.flow_ext.flex_mask[i];
1502 : :
1503 : 0 : ret = i40e_flow_store_flex_mask(pf, pctype, flex_mask);
1504 [ # # ]: 0 : if (ret == -1) {
1505 : 0 : PMD_DRV_LOG(ERR, "Exceed maximal"
1506 : : " number of bitmasks");
1507 : 0 : return -EINVAL;
1508 [ # # ]: 0 : } else if (ret == -2) {
1509 : 0 : PMD_DRV_LOG(ERR, "Conflict with the"
1510 : : " first flexible rule");
1511 : 0 : return -EINVAL;
1512 [ # # ]: 0 : } else if (ret == 0) {
1513 : 0 : i40e_flow_set_fdir_flex_msk(pf, pctype);
1514 : : }
1515 : : }
1516 : :
1517 : 0 : ret = i40e_sw_fdir_filter_insert(pf, &check_filter);
1518 [ # # ]: 0 : if (ret < 0) {
1519 : 0 : PMD_DRV_LOG(ERR,
1520 : : "Conflict with existing flow director rules!");
1521 : 0 : return -EINVAL;
1522 : : }
1523 : :
1524 [ # # ]: 0 : if (fdir_info->fdir_invalprio == 1 &&
1525 [ # # ]: 0 : fdir_info->fdir_guarantee_free_space > 0)
1526 : : wait_status = false;
1527 : : } else {
1528 [ # # ]: 0 : if (filter->input.flow_ext.is_flex_flow)
1529 : 0 : layer_idx = filter->input.flow_ext.layer_idx;
1530 : :
1531 : 0 : node = i40e_sw_fdir_filter_lookup(fdir_info,
1532 : : &check_filter.fdir.input);
1533 [ # # ]: 0 : if (!node) {
1534 : 0 : PMD_DRV_LOG(ERR,
1535 : : "There's no corresponding flow director filter!");
1536 : 0 : return -EINVAL;
1537 : : }
1538 : :
1539 : 0 : ret = i40e_sw_fdir_filter_del(pf, &node->fdir.input);
1540 [ # # ]: 0 : if (ret < 0) {
1541 : 0 : PMD_DRV_LOG(ERR,
1542 : : "Error deleting fdir rule from hash table!");
1543 : 0 : return -EINVAL;
1544 : : }
1545 : :
1546 : 0 : pf->fdir.flex_mask_flag[pctype] = 0;
1547 : :
1548 [ # # ]: 0 : if (fdir_info->fdir_invalprio == 1)
1549 : : wait_status = false;
1550 : : }
1551 : :
1552 : : /* find a buffer to store the pkt */
1553 : 0 : pkt = i40e_find_available_buffer(dev);
1554 [ # # ]: 0 : if (pkt == NULL)
1555 : 0 : goto error_op;
1556 : :
1557 : : memset(pkt, 0, I40E_FDIR_PKT_LEN);
1558 : 0 : ret = i40e_flow_fdir_construct_pkt(pf, &filter->input, pkt);
1559 [ # # ]: 0 : if (ret < 0) {
1560 : 0 : PMD_DRV_LOG(ERR, "construct packet for fdir fails.");
1561 : 0 : goto error_op;
1562 : : }
1563 : :
1564 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
1565 : : /* get translated pctype value in fd pctype register */
1566 : 0 : pctype = (enum i40e_filter_pctype)i40e_read_rx_ctl(
1567 : 0 : hw, I40E_GLQF_FD_PCTYPES((int)pctype));
1568 : : }
1569 : :
1570 : 0 : ret = i40e_flow_fdir_filter_programming(pf, pctype, filter, add,
1571 : : wait_status);
1572 [ # # ]: 0 : if (ret < 0) {
1573 : 0 : PMD_DRV_LOG(ERR, "fdir programming fails for PCTYPE(%u).",
1574 : : pctype);
1575 : 0 : goto error_op;
1576 : : }
1577 : :
1578 [ # # ]: 0 : if (filter->input.flow_ext.is_flex_flow) {
1579 [ # # ]: 0 : if (add) {
1580 : 0 : fdir_info->flex_flow_count[layer_idx]++;
1581 : 0 : pf->fdir.flex_pit_flag[layer_idx] = 1;
1582 : : } else {
1583 : 0 : fdir_info->flex_flow_count[layer_idx]--;
1584 [ # # ]: 0 : if (!fdir_info->flex_flow_count[layer_idx])
1585 : 0 : pf->fdir.flex_pit_flag[layer_idx] = 0;
1586 : : }
1587 : : }
1588 : :
1589 [ # # ]: 0 : if (add) {
1590 : 0 : fdir_info->flow_count[pctype]++;
1591 : 0 : fdir_info->fdir_actual_cnt++;
1592 [ # # ]: 0 : if (fdir_info->fdir_invalprio == 1 &&
1593 [ # # ]: 0 : fdir_info->fdir_guarantee_free_space > 0)
1594 : 0 : fdir_info->fdir_guarantee_free_space--;
1595 : : } else {
1596 : 0 : fdir_info->flow_count[pctype]--;
1597 : 0 : fdir_info->fdir_actual_cnt--;
1598 [ # # ]: 0 : if (fdir_info->fdir_invalprio == 1 &&
1599 : 0 : fdir_info->fdir_guarantee_free_space <
1600 [ # # ]: 0 : fdir_info->fdir_guarantee_total_space)
1601 : 0 : fdir_info->fdir_guarantee_free_space++;
1602 : : }
1603 : :
1604 : : return ret;
1605 : :
1606 : 0 : error_op:
1607 : : /* roll back */
1608 [ # # ]: 0 : if (add)
1609 : 0 : i40e_sw_fdir_filter_del(pf, &check_filter.fdir.input);
1610 : : else
1611 : 0 : i40e_sw_fdir_filter_insert(pf, &check_filter);
1612 : :
1613 : : return ret;
1614 : : }
1615 : :
1616 : : /*
1617 : : * i40e_flow_fdir_filter_programming - Program a flow director filter rule.
1618 : : * Is done by Flow Director Programming Descriptor followed by packet
1619 : : * structure that contains the filter fields need to match.
1620 : : * @pf: board private structure
1621 : : * @pctype: pctype
1622 : : * @filter: fdir filter entry
1623 : : * @add: 0 - delete, 1 - add
1624 : : */
1625 : : static int
1626 : 0 : i40e_flow_fdir_filter_programming(struct i40e_pf *pf,
1627 : : enum i40e_filter_pctype pctype,
1628 : : const struct i40e_fdir_filter_conf *filter,
1629 : : bool add, bool wait_status)
1630 : : {
1631 : 0 : struct i40e_tx_queue *txq = pf->fdir.txq;
1632 : 0 : struct i40e_rx_queue *rxq = pf->fdir.rxq;
1633 : : const struct i40e_fdir_action *fdir_action = &filter->action;
1634 : : volatile struct i40e_tx_desc *txdp;
1635 : : volatile struct i40e_filter_program_desc *fdirdp;
1636 : : uint32_t td_cmd;
1637 : : uint16_t vsi_id;
1638 : : uint8_t dest;
1639 : : uint32_t i;
1640 : :
1641 : 0 : PMD_DRV_LOG(INFO, "filling filter programming descriptor.");
1642 : 0 : fdirdp = (volatile struct i40e_filter_program_desc *)
1643 : 0 : (&txq->tx_ring[txq->tx_tail]);
1644 : :
1645 : 0 : fdirdp->qindex_flex_ptype_vsi =
1646 : 0 : rte_cpu_to_le_32((fdir_action->rx_queue <<
1647 : : I40E_TXD_FLTR_QW0_QINDEX_SHIFT) &
1648 : : I40E_TXD_FLTR_QW0_QINDEX_MASK);
1649 : :
1650 : 0 : fdirdp->qindex_flex_ptype_vsi |=
1651 : 0 : rte_cpu_to_le_32((fdir_action->flex_off <<
1652 : : I40E_TXD_FLTR_QW0_FLEXOFF_SHIFT) &
1653 : : I40E_TXD_FLTR_QW0_FLEXOFF_MASK);
1654 : :
1655 : 0 : fdirdp->qindex_flex_ptype_vsi |=
1656 : 0 : rte_cpu_to_le_32((pctype <<
1657 : : I40E_TXD_FLTR_QW0_PCTYPE_SHIFT) &
1658 : : I40E_TXD_FLTR_QW0_PCTYPE_MASK);
1659 : :
1660 [ # # ]: 0 : if (filter->input.flow_ext.is_vf)
1661 : 0 : vsi_id = pf->vfs[filter->input.flow_ext.dst_id].vsi->vsi_id;
1662 : : else
1663 : : /* Use LAN VSI Id by default */
1664 : 0 : vsi_id = pf->main_vsi->vsi_id;
1665 : 0 : fdirdp->qindex_flex_ptype_vsi |=
1666 : 0 : rte_cpu_to_le_32(((uint32_t)vsi_id <<
1667 : : I40E_TXD_FLTR_QW0_DEST_VSI_SHIFT) &
1668 : : I40E_TXD_FLTR_QW0_DEST_VSI_MASK);
1669 : :
1670 : 0 : fdirdp->dtype_cmd_cntindex =
1671 : : rte_cpu_to_le_32(I40E_TX_DESC_DTYPE_FILTER_PROG);
1672 : :
1673 [ # # ]: 0 : if (add)
1674 : 0 : fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32(
1675 : : I40E_FILTER_PROGRAM_DESC_PCMD_ADD_UPDATE <<
1676 : : I40E_TXD_FLTR_QW1_PCMD_SHIFT);
1677 : : else
1678 : 0 : fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32(
1679 : : I40E_FILTER_PROGRAM_DESC_PCMD_REMOVE <<
1680 : : I40E_TXD_FLTR_QW1_PCMD_SHIFT);
1681 : :
1682 [ # # ]: 0 : if (fdir_action->behavior == I40E_FDIR_REJECT)
1683 : : dest = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1684 [ # # ]: 0 : else if (fdir_action->behavior == I40E_FDIR_ACCEPT)
1685 : : dest = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1686 [ # # ]: 0 : else if (fdir_action->behavior == I40E_FDIR_PASSTHRU)
1687 : : dest = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_OTHER;
1688 : : else {
1689 : 0 : PMD_DRV_LOG(ERR, "Failed to program FDIR filter: unsupported fdir behavior.");
1690 : 0 : return -EINVAL;
1691 : : }
1692 : :
1693 : 0 : fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32((dest <<
1694 : : I40E_TXD_FLTR_QW1_DEST_SHIFT) &
1695 : : I40E_TXD_FLTR_QW1_DEST_MASK);
1696 : :
1697 : 0 : fdirdp->dtype_cmd_cntindex |=
1698 : 0 : rte_cpu_to_le_32((fdir_action->report_status <<
1699 : : I40E_TXD_FLTR_QW1_FD_STATUS_SHIFT) &
1700 : : I40E_TXD_FLTR_QW1_FD_STATUS_MASK);
1701 : :
1702 : 0 : fdirdp->dtype_cmd_cntindex |=
1703 : : rte_cpu_to_le_32(I40E_TXD_FLTR_QW1_CNT_ENA_MASK);
1704 : 0 : fdirdp->dtype_cmd_cntindex |=
1705 : 0 : rte_cpu_to_le_32(
1706 : : ((uint32_t)pf->fdir.match_counter_index <<
1707 : : I40E_TXD_FLTR_QW1_CNTINDEX_SHIFT) &
1708 : : I40E_TXD_FLTR_QW1_CNTINDEX_MASK);
1709 : :
1710 : 0 : fdirdp->fd_id = rte_cpu_to_le_32(filter->soft_id);
1711 : :
1712 : 0 : PMD_DRV_LOG(INFO, "filling transmit descriptor.");
1713 : 0 : txdp = &txq->tx_ring[txq->tx_tail + 1];
1714 : 0 : txdp->buffer_addr = rte_cpu_to_le_64(pf->fdir.dma_addr[txq->tx_tail >> 1]);
1715 : :
1716 : : td_cmd = I40E_TX_DESC_CMD_EOP |
1717 : : I40E_TX_DESC_CMD_RS |
1718 : : I40E_TX_DESC_CMD_DUMMY;
1719 : :
1720 : 0 : txdp->cmd_type_offset_bsz =
1721 : : i40e_build_ctob(td_cmd, 0, I40E_FDIR_PKT_LEN, 0);
1722 : :
1723 : 0 : txq->tx_tail += 2; /* set 2 descriptors above, fdirdp and txdp */
1724 [ # # ]: 0 : if (txq->tx_tail >= txq->nb_tx_desc)
1725 : 0 : txq->tx_tail = 0;
1726 : : /* Update the tx tail register */
1727 : : rte_wmb();
1728 : :
1729 : : /* fdir program rx queue cleanup */
1730 : 0 : i40e_fdir_programming_status_cleanup(rxq);
1731 : :
1732 : 0 : I40E_PCI_REG_WRITE(txq->qtx_tail, txq->tx_tail);
1733 : :
1734 [ # # ]: 0 : if (wait_status) {
1735 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_MAX_WAIT_US; i++) {
1736 [ # # ]: 0 : if ((txdp->cmd_type_offset_bsz &
1737 : : rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) ==
1738 : : rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
1739 : : break;
1740 : 0 : rte_delay_us(1);
1741 : : }
1742 [ # # ]: 0 : if (i >= I40E_FDIR_MAX_WAIT_US) {
1743 : 0 : PMD_DRV_LOG(ERR,
1744 : : "Failed to program FDIR filter: time out to get DD on tx queue.");
1745 : 0 : return -ETIMEDOUT;
1746 : : }
1747 : : /* totally delay 10 ms to check programming status*/
1748 : 0 : rte_delay_us(I40E_FDIR_MAX_WAIT_US);
1749 [ # # ]: 0 : if (i40e_check_fdir_programming_status(rxq) < 0) {
1750 : 0 : PMD_DRV_LOG(ERR,
1751 : : "Failed to program FDIR filter: programming status reported.");
1752 : 0 : return -ETIMEDOUT;
1753 : : }
1754 : : }
1755 : :
1756 : : return 0;
1757 : : }
1758 : :
1759 : : /*
1760 : : * i40e_fdir_flush - clear all filters of Flow Director table
1761 : : * @pf: board private structure
1762 : : */
1763 : : int
1764 : 0 : i40e_fdir_flush(struct rte_eth_dev *dev)
1765 : : {
1766 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1767 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1768 : : uint32_t reg;
1769 : : uint16_t guarant_cnt, best_cnt;
1770 : : uint16_t i;
1771 : :
1772 : 0 : I40E_WRITE_REG(hw, I40E_PFQF_CTL_1, I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
1773 : 0 : I40E_WRITE_FLUSH(hw);
1774 : :
1775 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_FLUSH_RETRY; i++) {
1776 : : rte_delay_ms(I40E_FDIR_FLUSH_INTERVAL_MS);
1777 : 0 : reg = I40E_READ_REG(hw, I40E_PFQF_CTL_1);
1778 [ # # ]: 0 : if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
1779 : : break;
1780 : : }
1781 [ # # ]: 0 : if (i >= I40E_FDIR_FLUSH_RETRY) {
1782 : 0 : PMD_DRV_LOG(ERR, "FD table did not flush, may need more time.");
1783 : 0 : return -ETIMEDOUT;
1784 : : }
1785 : 0 : guarant_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
1786 : : I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
1787 : : I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
1788 : 0 : best_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
1789 : 0 : I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
1790 : : I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
1791 [ # # ]: 0 : if (guarant_cnt != 0 || best_cnt != 0) {
1792 : 0 : PMD_DRV_LOG(ERR, "Failed to flush FD table.");
1793 : 0 : return -ENOSYS;
1794 : : } else
1795 : 0 : PMD_DRV_LOG(INFO, "FD table Flush success.");
1796 : 0 : return 0;
1797 : : }
1798 : :
1799 : : static inline void
1800 : 0 : i40e_fdir_info_get_flex_set(struct i40e_pf *pf,
1801 : : struct rte_eth_flex_payload_cfg *flex_set,
1802 : : uint16_t *num)
1803 : : {
1804 : : struct i40e_fdir_flex_pit *flex_pit;
1805 : : struct rte_eth_flex_payload_cfg *ptr = flex_set;
1806 : : uint16_t src, dst, size, j, k;
1807 : : uint8_t i, layer_idx;
1808 : :
1809 : 0 : for (layer_idx = I40E_FLXPLD_L2_IDX;
1810 [ # # ]: 0 : layer_idx <= I40E_FLXPLD_L4_IDX;
1811 : 0 : layer_idx++) {
1812 [ # # ]: 0 : if (layer_idx == I40E_FLXPLD_L2_IDX)
1813 : 0 : ptr->type = RTE_ETH_L2_PAYLOAD;
1814 [ # # ]: 0 : else if (layer_idx == I40E_FLXPLD_L3_IDX)
1815 : 0 : ptr->type = RTE_ETH_L3_PAYLOAD;
1816 : : else if (layer_idx == I40E_FLXPLD_L4_IDX)
1817 : 0 : ptr->type = RTE_ETH_L4_PAYLOAD;
1818 : :
1819 [ # # ]: 0 : for (i = 0; i < I40E_MAX_FLXPLD_FIED; i++) {
1820 : 0 : flex_pit = &pf->fdir.flex_set[layer_idx *
1821 : 0 : I40E_MAX_FLXPLD_FIED + i];
1822 [ # # ]: 0 : if (flex_pit->size == 0)
1823 : 0 : continue;
1824 : 0 : src = flex_pit->src_offset * sizeof(uint16_t);
1825 : 0 : dst = flex_pit->dst_offset * sizeof(uint16_t);
1826 : 0 : size = flex_pit->size * sizeof(uint16_t);
1827 [ # # ]: 0 : for (j = src, k = dst; j < src + size; j++, k++)
1828 : 0 : ptr->src_offset[k] = j;
1829 : : }
1830 : 0 : (*num)++;
1831 : 0 : ptr++;
1832 : : }
1833 : 0 : }
1834 : :
1835 : : static inline void
1836 : 0 : i40e_fdir_info_get_flex_mask(struct i40e_pf *pf,
1837 : : struct rte_eth_fdir_flex_mask *flex_mask,
1838 : : uint16_t *num)
1839 : : {
1840 : : struct i40e_fdir_flex_mask *mask;
1841 : : struct rte_eth_fdir_flex_mask *ptr = flex_mask;
1842 : : uint16_t flow_type;
1843 : : uint8_t i, j;
1844 : : uint16_t off_bytes, mask_tmp;
1845 : :
1846 : 0 : for (i = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
1847 [ # # ]: 0 : i <= I40E_FILTER_PCTYPE_L2_PAYLOAD;
1848 : 0 : i++) {
1849 : 0 : mask = &pf->fdir.flex_mask[i];
1850 : 0 : flow_type = i40e_pctype_to_flowtype(pf->adapter,
1851 : : (enum i40e_filter_pctype)i);
1852 [ # # ]: 0 : if (flow_type == RTE_ETH_FLOW_UNKNOWN)
1853 : 0 : continue;
1854 : :
1855 [ # # ]: 0 : for (j = 0; j < I40E_FDIR_MAX_FLEXWORD_NUM; j++) {
1856 [ # # ]: 0 : if (mask->word_mask & I40E_FLEX_WORD_MASK(j)) {
1857 : 0 : ptr->mask[j * sizeof(uint16_t)] = UINT8_MAX;
1858 : 0 : ptr->mask[j * sizeof(uint16_t) + 1] = UINT8_MAX;
1859 : : } else {
1860 : 0 : ptr->mask[j * sizeof(uint16_t)] = 0x0;
1861 : 0 : ptr->mask[j * sizeof(uint16_t) + 1] = 0x0;
1862 : : }
1863 : : }
1864 [ # # ]: 0 : for (j = 0; j < I40E_FDIR_BITMASK_NUM_WORD; j++) {
1865 : 0 : off_bytes = mask->bitmask[j].offset * sizeof(uint16_t);
1866 : 0 : mask_tmp = ~mask->bitmask[j].mask;
1867 : 0 : ptr->mask[off_bytes] &= I40E_HI_BYTE(mask_tmp);
1868 : 0 : ptr->mask[off_bytes + 1] &= I40E_LO_BYTE(mask_tmp);
1869 : : }
1870 : 0 : ptr->flow_type = flow_type;
1871 : 0 : ptr++;
1872 : 0 : (*num)++;
1873 : : }
1874 : 0 : }
1875 : :
1876 : : /*
1877 : : * i40e_fdir_info_get - get information of Flow Director
1878 : : * @pf: ethernet device to get info from
1879 : : * @fdir: a pointer to a structure of type *rte_eth_fdir_info* to be filled with
1880 : : * the flow director information.
1881 : : */
1882 : : void
1883 : 0 : i40e_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir)
1884 : : {
1885 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1886 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1887 : 0 : uint16_t num_flex_set = 0;
1888 : 0 : uint16_t num_flex_mask = 0;
1889 : : uint16_t i;
1890 : :
1891 : 0 : fdir->mode = RTE_FDIR_MODE_NONE;
1892 : :
1893 : 0 : fdir->guarant_spc =
1894 : 0 : (uint32_t)hw->func_caps.fd_filters_guaranteed;
1895 : 0 : fdir->best_spc =
1896 : 0 : (uint32_t)hw->func_caps.fd_filters_best_effort;
1897 : 0 : fdir->max_flexpayload = I40E_FDIR_MAX_FLEX_LEN;
1898 : 0 : fdir->flow_types_mask[0] = I40E_FDIR_FLOWS;
1899 : : for (i = 1; i < RTE_FLOW_MASK_ARRAY_SIZE; i++)
1900 : : fdir->flow_types_mask[i] = 0ULL;
1901 : 0 : fdir->flex_payload_unit = sizeof(uint16_t);
1902 : 0 : fdir->flex_bitmask_unit = sizeof(uint16_t);
1903 : 0 : fdir->max_flex_payload_segment_num = I40E_MAX_FLXPLD_FIED;
1904 : 0 : fdir->flex_payload_limit = I40E_MAX_FLX_SOURCE_OFF;
1905 : 0 : fdir->max_flex_bitmask_num = I40E_FDIR_BITMASK_NUM_WORD;
1906 : :
1907 : 0 : i40e_fdir_info_get_flex_set(pf,
1908 : 0 : fdir->flex_conf.flex_set,
1909 : : &num_flex_set);
1910 : 0 : i40e_fdir_info_get_flex_mask(pf,
1911 : 0 : fdir->flex_conf.flex_mask,
1912 : : &num_flex_mask);
1913 : :
1914 : 0 : fdir->flex_conf.nb_payloads = num_flex_set;
1915 : 0 : fdir->flex_conf.nb_flexmasks = num_flex_mask;
1916 : 0 : }
1917 : :
1918 : : /*
1919 : : * i40e_fdir_stat_get - get statistics of Flow Director
1920 : : * @pf: ethernet device to get info from
1921 : : * @stat: a pointer to a structure of type *rte_eth_fdir_stats* to be filled with
1922 : : * the flow director statistics.
1923 : : */
1924 : : void
1925 : 0 : i40e_fdir_stats_get(struct rte_eth_dev *dev, struct rte_eth_fdir_stats *stat)
1926 : : {
1927 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1928 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1929 : : uint32_t fdstat;
1930 : :
1931 : 0 : fdstat = I40E_READ_REG(hw, I40E_PFQF_FDSTAT);
1932 : 0 : stat->guarant_cnt =
1933 : 0 : (uint32_t)((fdstat & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
1934 : : I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
1935 : 0 : stat->best_cnt =
1936 : 0 : (uint32_t)((fdstat & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
1937 : : I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
1938 : 0 : }
1939 : :
1940 : : /* Restore flow director filter */
1941 : : void
1942 : 0 : i40e_fdir_filter_restore(struct i40e_pf *pf)
1943 : : {
1944 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(pf->main_vsi);
1945 : : struct i40e_fdir_filter_list *fdir_list = &pf->fdir.fdir_list;
1946 : : struct i40e_fdir_filter *f;
1947 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1948 : : uint32_t fdstat;
1949 : : uint32_t guarant_cnt; /**< Number of filters in guaranteed spaces. */
1950 : : uint32_t best_cnt; /**< Number of filters in best effort spaces. */
1951 : :
1952 [ # # ]: 0 : TAILQ_FOREACH(f, fdir_list, rules)
1953 : 0 : i40e_flow_add_del_fdir_filter(dev, &f->fdir, TRUE);
1954 : :
1955 : 0 : fdstat = I40E_READ_REG(hw, I40E_PFQF_FDSTAT);
1956 : 0 : guarant_cnt =
1957 : : (uint32_t)((fdstat & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
1958 : : I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
1959 : 0 : best_cnt =
1960 : 0 : (uint32_t)((fdstat & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
1961 : : I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
1962 : :
1963 : 0 : PMD_DRV_LOG(INFO, "FDIR: Guarant count: %d, Best count: %d",
1964 : : guarant_cnt, best_cnt);
1965 : 0 : }
|