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