Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018 Intel Corporation
3 : : */
4 : :
5 : : #include <ethdev_driver.h>
6 : : #include <rte_net.h>
7 : : #include <rte_vect.h>
8 : :
9 : : #include "ice_rxtx.h"
10 : : #include "ice_rxtx_vec_common.h"
11 : :
12 : : #define ICE_TX_CKSUM_OFFLOAD_MASK (RTE_MBUF_F_TX_IP_CKSUM | \
13 : : RTE_MBUF_F_TX_L4_MASK | \
14 : : RTE_MBUF_F_TX_TCP_SEG | \
15 : : RTE_MBUF_F_TX_UDP_SEG | \
16 : : RTE_MBUF_F_TX_OUTER_IP_CKSUM)
17 : :
18 : : /**
19 : : * The mbuf dynamic field pointer for protocol extraction metadata.
20 : : */
21 : : #define ICE_DYNF_PROTO_XTR_METADATA(m, n) \
22 : : RTE_MBUF_DYNFIELD((m), (n), uint32_t *)
23 : :
24 : : static int
25 : 0 : ice_monitor_callback(const uint64_t value,
26 : : const uint64_t arg[RTE_POWER_MONITOR_OPAQUE_SZ] __rte_unused)
27 : : {
28 : : const uint64_t m = rte_cpu_to_le_16(1 << ICE_RX_FLEX_DESC_STATUS0_DD_S);
29 : : /*
30 : : * we expect the DD bit to be set to 1 if this descriptor was already
31 : : * written to.
32 : : */
33 [ # # ]: 0 : return (value & m) == m ? -1 : 0;
34 : : }
35 : :
36 : : int
37 : 0 : ice_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc)
38 : : {
39 : : volatile union ci_rx_flex_desc *rxdp;
40 : : struct ci_rx_queue *rxq = rx_queue;
41 : : uint16_t desc;
42 : :
43 : 0 : desc = rxq->rx_tail;
44 : 0 : rxdp = &rxq->rx_flex_ring[desc];
45 : : /* watch for changes in status bit */
46 : 0 : pmc->addr = &rxdp->wb.status_error0;
47 : :
48 : : /* comparison callback */
49 : 0 : pmc->fn = ice_monitor_callback;
50 : :
51 : : /* register is 16-bit */
52 : 0 : pmc->size = sizeof(uint16_t);
53 : :
54 : 0 : return 0;
55 : : }
56 : :
57 : :
58 : : static inline uint8_t
59 : : ice_proto_xtr_type_to_rxdid(uint8_t xtr_type)
60 : : {
61 : : static uint8_t rxdid_map[] = {
62 : : [PROTO_XTR_NONE] = ICE_RXDID_COMMS_OVS,
63 : : [PROTO_XTR_VLAN] = ICE_RXDID_COMMS_AUX_VLAN,
64 : : [PROTO_XTR_IPV4] = ICE_RXDID_COMMS_AUX_IPV4,
65 : : [PROTO_XTR_IPV6] = ICE_RXDID_COMMS_AUX_IPV6,
66 : : [PROTO_XTR_IPV6_FLOW] = ICE_RXDID_COMMS_AUX_IPV6_FLOW,
67 : : [PROTO_XTR_TCP] = ICE_RXDID_COMMS_AUX_TCP,
68 : : [PROTO_XTR_IP_OFFSET] = ICE_RXDID_COMMS_AUX_IP_OFFSET,
69 : : };
70 : :
71 : : return xtr_type < RTE_DIM(rxdid_map) ?
72 : 0 : rxdid_map[xtr_type] : ICE_RXDID_COMMS_OVS;
73 : : }
74 : :
75 : : static inline void
76 : 0 : ice_rxd_to_pkt_fields_by_comms_generic(__rte_unused struct ci_rx_queue *rxq,
77 : : struct rte_mbuf *mb,
78 : : volatile union ci_rx_flex_desc *rxdp)
79 : : {
80 : : volatile struct ice_32b_rx_flex_desc_comms *desc =
81 : : (volatile struct ice_32b_rx_flex_desc_comms *)rxdp;
82 : 0 : uint16_t stat_err = rte_le_to_cpu_16(desc->status_error0);
83 : :
84 [ # # ]: 0 : if (likely(stat_err & (1 << ICE_RX_FLEX_DESC_STATUS0_RSS_VALID_S))) {
85 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
86 : 0 : mb->hash.rss = rte_le_to_cpu_32(desc->rss_hash);
87 : : }
88 : :
89 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
90 [ # # ]: 0 : if (desc->flow_id != 0xFFFFFFFF) {
91 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
92 : 0 : mb->hash.fdir.hi = rte_le_to_cpu_32(desc->flow_id);
93 : : }
94 : : #endif
95 : 0 : }
96 : :
97 : : static inline void
98 : 0 : ice_rxd_to_pkt_fields_by_comms_ovs(__rte_unused struct ci_rx_queue *rxq,
99 : : struct rte_mbuf *mb,
100 : : volatile union ci_rx_flex_desc *rxdp)
101 : : {
102 : : volatile struct ice_32b_rx_flex_desc_comms_ovs *desc =
103 : : (volatile struct ice_32b_rx_flex_desc_comms_ovs *)rxdp;
104 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
105 : : uint16_t stat_err;
106 : : #endif
107 : :
108 [ # # ]: 0 : if (desc->flow_id != 0xFFFFFFFF) {
109 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
110 : 0 : mb->hash.fdir.hi = rte_le_to_cpu_32(desc->flow_id);
111 : : }
112 : :
113 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
114 : 0 : stat_err = rte_le_to_cpu_16(desc->status_error0);
115 [ # # ]: 0 : if (likely(stat_err & (1 << ICE_RX_FLEX_DESC_STATUS0_RSS_VALID_S))) {
116 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
117 : 0 : mb->hash.rss = rte_le_to_cpu_32(desc->rss_hash);
118 : : }
119 : : #endif
120 : 0 : }
121 : :
122 : : static inline void
123 : 0 : ice_rxd_to_pkt_fields_by_comms_aux_v1(struct ci_rx_queue *rxq,
124 : : struct rte_mbuf *mb,
125 : : volatile union ci_rx_flex_desc *rxdp)
126 : : {
127 : : volatile struct ice_32b_rx_flex_desc_comms *desc =
128 : : (volatile struct ice_32b_rx_flex_desc_comms *)rxdp;
129 : : uint16_t stat_err;
130 : :
131 : 0 : stat_err = rte_le_to_cpu_16(desc->status_error0);
132 [ # # ]: 0 : if (likely(stat_err & (1 << ICE_RX_FLEX_DESC_STATUS0_RSS_VALID_S))) {
133 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
134 : 0 : mb->hash.rss = rte_le_to_cpu_32(desc->rss_hash);
135 : : }
136 : :
137 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
138 [ # # ]: 0 : if (desc->flow_id != 0xFFFFFFFF) {
139 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
140 : 0 : mb->hash.fdir.hi = rte_le_to_cpu_32(desc->flow_id);
141 : : }
142 : :
143 [ # # ]: 0 : if (rxq->xtr_ol_flag) {
144 : : uint32_t metadata = 0;
145 : :
146 : 0 : stat_err = rte_le_to_cpu_16(desc->status_error1);
147 : :
148 [ # # ]: 0 : if (stat_err & (1 << ICE_RX_FLEX_DESC_STATUS1_XTRMD4_VALID_S))
149 : 0 : metadata = rte_le_to_cpu_16(desc->flex_ts.flex.aux0);
150 : :
151 [ # # ]: 0 : if (stat_err & (1 << ICE_RX_FLEX_DESC_STATUS1_XTRMD5_VALID_S))
152 : 0 : metadata |=
153 : 0 : rte_le_to_cpu_16(desc->flex_ts.flex.aux1) << 16;
154 : :
155 [ # # ]: 0 : if (metadata) {
156 : 0 : mb->ol_flags |= rxq->xtr_ol_flag;
157 : :
158 : 0 : *ICE_DYNF_PROTO_XTR_METADATA(mb, rxq->xtr_field_offs) = metadata;
159 : : }
160 : : }
161 : : #else
162 : : RTE_SET_USED(rxq);
163 : : #endif
164 : 0 : }
165 : :
166 : : static inline void
167 : 0 : ice_rxd_to_pkt_fields_by_comms_aux_v2(struct ci_rx_queue *rxq,
168 : : struct rte_mbuf *mb,
169 : : volatile union ci_rx_flex_desc *rxdp)
170 : : {
171 : : volatile struct ice_32b_rx_flex_desc_comms *desc =
172 : : (volatile struct ice_32b_rx_flex_desc_comms *)rxdp;
173 : : uint16_t stat_err;
174 : :
175 : 0 : stat_err = rte_le_to_cpu_16(desc->status_error0);
176 [ # # ]: 0 : if (likely(stat_err & (1 << ICE_RX_FLEX_DESC_STATUS0_RSS_VALID_S))) {
177 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
178 : 0 : mb->hash.rss = rte_le_to_cpu_32(desc->rss_hash);
179 : : }
180 : :
181 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
182 [ # # ]: 0 : if (desc->flow_id != 0xFFFFFFFF) {
183 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
184 : 0 : mb->hash.fdir.hi = rte_le_to_cpu_32(desc->flow_id);
185 : : }
186 : :
187 [ # # ]: 0 : if (rxq->xtr_ol_flag) {
188 : : uint32_t metadata = 0;
189 : :
190 [ # # ]: 0 : if (desc->flex_ts.flex.aux0 != 0xFFFF)
191 : 0 : metadata = rte_le_to_cpu_16(desc->flex_ts.flex.aux0);
192 [ # # ]: 0 : else if (desc->flex_ts.flex.aux1 != 0xFFFF)
193 : 0 : metadata = rte_le_to_cpu_16(desc->flex_ts.flex.aux1);
194 : :
195 [ # # ]: 0 : if (metadata) {
196 : 0 : mb->ol_flags |= rxq->xtr_ol_flag;
197 : :
198 : 0 : *ICE_DYNF_PROTO_XTR_METADATA(mb, rxq->xtr_field_offs) = metadata;
199 : : }
200 : : }
201 : : #else
202 : : RTE_SET_USED(rxq);
203 : : #endif
204 : 0 : }
205 : :
206 : : static const ice_rxd_to_pkt_fields_t rxd_to_pkt_fields_ops[] = {
207 : : [ICE_RXDID_COMMS_AUX_VLAN] = ice_rxd_to_pkt_fields_by_comms_aux_v1,
208 : : [ICE_RXDID_COMMS_AUX_IPV4] = ice_rxd_to_pkt_fields_by_comms_aux_v1,
209 : : [ICE_RXDID_COMMS_AUX_IPV6] = ice_rxd_to_pkt_fields_by_comms_aux_v1,
210 : : [ICE_RXDID_COMMS_AUX_IPV6_FLOW] = ice_rxd_to_pkt_fields_by_comms_aux_v1,
211 : : [ICE_RXDID_COMMS_AUX_TCP] = ice_rxd_to_pkt_fields_by_comms_aux_v1,
212 : : [ICE_RXDID_COMMS_AUX_IP_OFFSET] = ice_rxd_to_pkt_fields_by_comms_aux_v2,
213 : : [ICE_RXDID_COMMS_GENERIC] = ice_rxd_to_pkt_fields_by_comms_generic,
214 : : [ICE_RXDID_COMMS_OVS] = ice_rxd_to_pkt_fields_by_comms_ovs,
215 : : };
216 : :
217 : : void
218 : 0 : ice_select_rxd_to_pkt_fields_handler(struct ci_rx_queue *rxq, uint32_t rxdid)
219 : : {
220 : 0 : rxq->rxdid = rxdid;
221 : :
222 [ # # ]: 0 : switch (rxdid) {
223 : : case ICE_RXDID_COMMS_AUX_VLAN:
224 : : case ICE_RXDID_COMMS_AUX_IPV4:
225 : : case ICE_RXDID_COMMS_AUX_IPV6:
226 : : case ICE_RXDID_COMMS_AUX_IPV6_FLOW:
227 : : case ICE_RXDID_COMMS_AUX_TCP:
228 : : case ICE_RXDID_COMMS_AUX_IP_OFFSET:
229 : : break;
230 : : case ICE_RXDID_COMMS_GENERIC:
231 : : /* fallthrough */
232 : : case ICE_RXDID_COMMS_OVS:
233 : : break;
234 : :
235 : 0 : default:
236 : : /* update this according to the RXDID for PROTO_XTR_NONE */
237 : 0 : rxq->rxdid = ICE_RXDID_COMMS_OVS;
238 : 0 : break;
239 : : }
240 : :
241 [ # # ]: 0 : if (rxq->xtr_field_offs == -1)
242 : 0 : rxq->xtr_ol_flag = 0;
243 : 0 : }
244 : :
245 : : static int
246 : 0 : ice_program_hw_rx_queue(struct ci_rx_queue *rxq)
247 : : {
248 : 0 : struct ice_vsi *vsi = rxq->ice_vsi;
249 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
250 : : struct ice_pf *pf = ICE_VSI_TO_PF(vsi);
251 : 0 : struct rte_eth_dev_data *dev_data = rxq->ice_vsi->adapter->pf.dev_data;
252 : : struct ice_rlan_ctx rx_ctx;
253 : : uint16_t buf_size;
254 : : uint32_t rxdid = ICE_RXDID_COMMS_OVS;
255 : : uint32_t regval;
256 : : struct ice_adapter *ad = rxq->ice_vsi->adapter;
257 : 0 : uint32_t frame_size = dev_data->mtu + ICE_ETH_OVERHEAD;
258 : : int err;
259 : :
260 : : /* Set buffer size as the head split is disabled. */
261 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
262 : : RTE_PKTMBUF_HEADROOM);
263 : 0 : rxq->rx_buf_len = RTE_ALIGN_FLOOR(buf_size, (1 << ICE_RLAN_CTX_DBUF_S));
264 : 0 : rxq->rx_buf_len = RTE_MIN(rxq->rx_buf_len, ICE_RX_MAX_DATA_BUF_SIZE);
265 : 0 : rxq->max_pkt_len =
266 : 0 : RTE_MIN((uint32_t)ICE_SUPPORT_CHAIN_NUM * rxq->rx_buf_len,
267 : : frame_size);
268 : :
269 [ # # ]: 0 : if (rxq->max_pkt_len <= RTE_ETHER_MIN_LEN ||
270 : : rxq->max_pkt_len > ICE_FRAME_SIZE_MAX) {
271 : 0 : PMD_DRV_LOG(ERR, "maximum packet length must "
272 : : "be larger than %u and smaller than %u",
273 : : (uint32_t)RTE_ETHER_MIN_LEN,
274 : : (uint32_t)ICE_FRAME_SIZE_MAX);
275 : 0 : return -EINVAL;
276 : : }
277 : :
278 [ # # # # ]: 0 : if (rxq->ts_flag == 0 && (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)) {
279 : : /* Register mbuf field and flag for Rx timestamp */
280 : 0 : err = rte_mbuf_dyn_rx_timestamp_register(
281 : : &rxq->ts_offset,
282 : : &rxq->ts_flag);
283 [ # # ]: 0 : if (err) {
284 : 0 : PMD_DRV_LOG(ERR,
285 : : "Cannot register mbuf field/flag for timestamp");
286 : 0 : return -EINVAL;
287 : : }
288 : : }
289 : :
290 : : memset(&rx_ctx, 0, sizeof(rx_ctx));
291 : :
292 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT) {
293 : : uint32_t proto_hdr;
294 : 0 : proto_hdr = rxq->rxseg[0].proto_hdr;
295 : :
296 [ # # ]: 0 : if (proto_hdr == RTE_PTYPE_UNKNOWN) {
297 : 0 : PMD_DRV_LOG(ERR, "Buffer split protocol must be configured");
298 : 0 : return -EINVAL;
299 : : }
300 : :
301 [ # # # ]: 0 : switch (proto_hdr & RTE_PTYPE_L4_MASK) {
302 : 0 : case RTE_PTYPE_L4_TCP:
303 : : case RTE_PTYPE_L4_UDP:
304 : 0 : rx_ctx.dtype = ICE_RX_DTYPE_HEADER_SPLIT;
305 : 0 : rx_ctx.hsplit_0 = ICE_RLAN_RX_HSPLIT_0_SPLIT_TCP_UDP;
306 : 0 : goto set_hsplit_finish;
307 : 0 : case RTE_PTYPE_L4_SCTP:
308 : 0 : rx_ctx.dtype = ICE_RX_DTYPE_HEADER_SPLIT;
309 : 0 : rx_ctx.hsplit_0 = ICE_RLAN_RX_HSPLIT_0_SPLIT_SCTP;
310 : 0 : goto set_hsplit_finish;
311 : : }
312 : :
313 [ # # ]: 0 : switch (proto_hdr & RTE_PTYPE_L3_MASK) {
314 : 0 : case RTE_PTYPE_L3_IPV4_EXT_UNKNOWN:
315 : : case RTE_PTYPE_L3_IPV6_EXT_UNKNOWN:
316 : 0 : rx_ctx.dtype = ICE_RX_DTYPE_HEADER_SPLIT;
317 : 0 : rx_ctx.hsplit_0 = ICE_RLAN_RX_HSPLIT_0_SPLIT_IP;
318 : 0 : goto set_hsplit_finish;
319 : : }
320 : :
321 [ # # ]: 0 : switch (proto_hdr & RTE_PTYPE_L2_MASK) {
322 : 0 : case RTE_PTYPE_L2_ETHER:
323 : 0 : rx_ctx.dtype = ICE_RX_DTYPE_HEADER_SPLIT;
324 : 0 : rx_ctx.hsplit_0 = ICE_RLAN_RX_HSPLIT_0_SPLIT_L2;
325 : 0 : rx_ctx.hsplit_1 = ICE_RLAN_RX_HSPLIT_1_SPLIT_L2;
326 : 0 : goto set_hsplit_finish;
327 : : }
328 : :
329 [ # # # ]: 0 : switch (proto_hdr & RTE_PTYPE_INNER_L4_MASK) {
330 : 0 : case RTE_PTYPE_INNER_L4_TCP:
331 : : case RTE_PTYPE_INNER_L4_UDP:
332 : 0 : rx_ctx.dtype = ICE_RX_DTYPE_HEADER_SPLIT;
333 : 0 : rx_ctx.hsplit_0 = ICE_RLAN_RX_HSPLIT_0_SPLIT_TCP_UDP;
334 : 0 : goto set_hsplit_finish;
335 : 0 : case RTE_PTYPE_INNER_L4_SCTP:
336 : 0 : rx_ctx.dtype = ICE_RX_DTYPE_HEADER_SPLIT;
337 : 0 : rx_ctx.hsplit_0 = ICE_RLAN_RX_HSPLIT_0_SPLIT_SCTP;
338 : 0 : goto set_hsplit_finish;
339 : : }
340 : :
341 [ # # ]: 0 : switch (proto_hdr & RTE_PTYPE_INNER_L3_MASK) {
342 : 0 : case RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN:
343 : : case RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN:
344 : 0 : rx_ctx.dtype = ICE_RX_DTYPE_HEADER_SPLIT;
345 : 0 : rx_ctx.hsplit_0 = ICE_RLAN_RX_HSPLIT_0_SPLIT_IP;
346 : 0 : goto set_hsplit_finish;
347 : : }
348 : :
349 [ # # ]: 0 : switch (proto_hdr & RTE_PTYPE_INNER_L2_MASK) {
350 : 0 : case RTE_PTYPE_INNER_L2_ETHER:
351 : 0 : rx_ctx.dtype = ICE_RX_DTYPE_HEADER_SPLIT;
352 : 0 : rx_ctx.hsplit_0 = ICE_RLAN_RX_HSPLIT_0_SPLIT_L2;
353 : 0 : goto set_hsplit_finish;
354 : : }
355 : :
356 [ # # ]: 0 : switch (proto_hdr & RTE_PTYPE_TUNNEL_MASK) {
357 : 0 : case RTE_PTYPE_TUNNEL_GRENAT:
358 : 0 : rx_ctx.dtype = ICE_RX_DTYPE_HEADER_SPLIT;
359 : 0 : rx_ctx.hsplit_1 = ICE_RLAN_RX_HSPLIT_1_SPLIT_ALWAYS;
360 : 0 : goto set_hsplit_finish;
361 : : }
362 : :
363 : 0 : PMD_DRV_LOG(ERR, "Buffer split protocol is not supported");
364 : 0 : return -EINVAL;
365 : :
366 : 0 : set_hsplit_finish:
367 : 0 : rxq->rx_hdr_len = ICE_RX_HDR_BUF_SIZE;
368 : : } else {
369 : 0 : rxq->rx_hdr_len = 0;
370 : : rx_ctx.dtype = 0; /* No Protocol Based Buffer Split mode */
371 : : }
372 : :
373 : 0 : rx_ctx.base = rxq->rx_ring_phys_addr / ICE_QUEUE_BASE_ADDR_UNIT;
374 : 0 : rx_ctx.qlen = rxq->nb_rx_desc;
375 : 0 : rx_ctx.dbuf = rxq->rx_buf_len >> ICE_RLAN_CTX_DBUF_S;
376 : 0 : rx_ctx.hbuf = rxq->rx_hdr_len >> ICE_RLAN_CTX_HBUF_S;
377 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
378 : 0 : rx_ctx.dsize = 1; /* 32B descriptors */
379 : : #endif
380 : 0 : rx_ctx.rxmax = rxq->max_pkt_len;
381 : : /* TPH: Transaction Layer Packet (TLP) processing hints */
382 : 0 : rx_ctx.tphrdesc_ena = 1;
383 : 0 : rx_ctx.tphwdesc_ena = 1;
384 : 0 : rx_ctx.tphdata_ena = 1;
385 : 0 : rx_ctx.tphhead_ena = 1;
386 : : /* Low Receive Queue Threshold defined in 64 descriptors units.
387 : : * When the number of free descriptors goes below the lrxqthresh,
388 : : * an immediate interrupt is triggered.
389 : : */
390 : 0 : rx_ctx.lrxqthresh = 2;
391 : : /*default use 32 byte descriptor, vlan tag extract to L2TAG2(1st)*/
392 : 0 : rx_ctx.l2tsel = 1;
393 : : rx_ctx.showiv = 0;
394 : 0 : rx_ctx.crcstrip = (rxq->crc_len == 0) ? 1 : 0;
395 : :
396 [ # # ]: 0 : rxdid = ice_proto_xtr_type_to_rxdid(rxq->proto_xtr);
397 : :
398 : 0 : PMD_DRV_LOG(DEBUG, "Port (%u) - Rx queue (%u) is set with RXDID : %u",
399 : : rxq->port_id, rxq->queue_id, rxdid);
400 : :
401 [ # # ]: 0 : if (!(pf->supported_rxdid & RTE_BIT64(rxdid))) {
402 : 0 : PMD_DRV_LOG(ERR, "currently package doesn't support RXDID (%u)",
403 : : rxdid);
404 : 0 : return -EINVAL;
405 : : }
406 : :
407 : 0 : rxq->rxdid = rxdid;
408 : :
409 : : /* Enable Flexible Descriptors in the queue context which
410 : : * allows this driver to select a specific receive descriptor format
411 : : */
412 : 0 : regval = (rxdid << QRXFLXP_CNTXT_RXDID_IDX_S) &
413 : : QRXFLXP_CNTXT_RXDID_IDX_M;
414 : :
415 : : /* increasing context priority to pick up profile ID;
416 : : * default is 0x01; setting to 0x03 to ensure profile
417 : : * is programming if prev context is of same priority
418 : : */
419 : 0 : regval |= (0x03 << QRXFLXP_CNTXT_RXDID_PRIO_S) &
420 : : QRXFLXP_CNTXT_RXDID_PRIO_M;
421 : :
422 [ # # # # ]: 0 : if (ad->ptp_ena || rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
423 : 0 : regval |= QRXFLXP_CNTXT_TS_M;
424 : :
425 : 0 : ICE_WRITE_REG(hw, QRXFLXP_CNTXT(rxq->reg_idx), regval);
426 : :
427 : 0 : err = ice_clear_rxq_ctx(hw, rxq->reg_idx);
428 [ # # ]: 0 : if (err) {
429 : 0 : PMD_DRV_LOG(ERR, "Failed to clear Lan Rx queue (%u) context",
430 : : rxq->queue_id);
431 : 0 : return -EINVAL;
432 : : }
433 : 0 : err = ice_write_rxq_ctx(hw, &rx_ctx, rxq->reg_idx);
434 [ # # ]: 0 : if (err) {
435 : 0 : PMD_DRV_LOG(ERR, "Failed to write Lan Rx queue (%u) context",
436 : : rxq->queue_id);
437 : 0 : return -EINVAL;
438 : : }
439 : :
440 : : /* Check if scattered RX needs to be used. */
441 [ # # ]: 0 : if (frame_size > buf_size)
442 : 0 : dev_data->scattered_rx = 1;
443 : :
444 : 0 : rxq->qrx_tail = hw->hw_addr + QRX_TAIL(rxq->reg_idx);
445 : :
446 : : /* Init the Rx tail register*/
447 : 0 : ICE_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
448 : :
449 : 0 : return 0;
450 : : }
451 : :
452 : : /* Allocate mbufs for all descriptors in rx queue */
453 : : static int
454 : 0 : ice_alloc_rx_queue_mbufs(struct ci_rx_queue *rxq)
455 : : {
456 : 0 : struct ci_rx_entry *rxe = rxq->sw_ring;
457 : : uint64_t dma_addr;
458 : : uint16_t i;
459 : :
460 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
461 : : volatile union ci_rx_flex_desc *rxd;
462 : 0 : rxd = &rxq->rx_flex_ring[i];
463 : 0 : struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mp);
464 : :
465 [ # # ]: 0 : if (unlikely(!mbuf)) {
466 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate mbuf for RX");
467 : 0 : return -ENOMEM;
468 : : }
469 : :
470 : 0 : mbuf->data_off = RTE_PKTMBUF_HEADROOM;
471 : 0 : mbuf->nb_segs = 1;
472 [ # # ]: 0 : mbuf->port = rxq->port_id;
473 : :
474 : : dma_addr =
475 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
476 : :
477 [ # # ]: 0 : if (!(rxq->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT)) {
478 : : rte_mbuf_refcnt_set(mbuf, 1);
479 : 0 : mbuf->next = NULL;
480 : 0 : rxd->read.hdr_addr = 0;
481 : 0 : rxd->read.pkt_addr = dma_addr;
482 : : } else {
483 : : struct rte_mbuf *mbuf_pay;
484 : 0 : mbuf_pay = rte_mbuf_raw_alloc(rxq->rxseg[1].mp);
485 [ # # ]: 0 : if (unlikely(!mbuf_pay)) {
486 : 0 : rte_pktmbuf_free(mbuf);
487 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate payload mbuf for RX");
488 : 0 : return -ENOMEM;
489 : : }
490 : :
491 : 0 : mbuf_pay->next = NULL;
492 : 0 : mbuf_pay->data_off = RTE_PKTMBUF_HEADROOM;
493 : 0 : mbuf_pay->nb_segs = 1;
494 : 0 : mbuf_pay->port = rxq->port_id;
495 : 0 : mbuf->next = mbuf_pay;
496 : :
497 : 0 : rxd->read.hdr_addr = dma_addr;
498 : : /* The LS bit should be set to zero regardless of
499 : : * buffer split enablement.
500 : : */
501 : 0 : rxd->read.pkt_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf_pay));
502 : : }
503 : :
504 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
505 : 0 : rxd->read.rsvd1 = 0;
506 : 0 : rxd->read.rsvd2 = 0;
507 : : #endif
508 : 0 : rxe[i].mbuf = mbuf;
509 : : }
510 : :
511 : : return 0;
512 : : }
513 : :
514 : : /* Free all mbufs for descriptors in rx queue */
515 : : static void
516 : 0 : _ice_rx_queue_release_mbufs(struct ci_rx_queue *rxq)
517 : : {
518 : : uint16_t i;
519 : :
520 [ # # # # ]: 0 : if (!rxq || !rxq->sw_ring) {
521 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to sw_ring is NULL");
522 : 0 : return;
523 : : }
524 : :
525 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
526 [ # # ]: 0 : if (rxq->sw_ring[i].mbuf) {
527 : 0 : rte_pktmbuf_free(rxq->sw_ring[i].mbuf);
528 : 0 : rxq->sw_ring[i].mbuf = NULL;
529 : : }
530 : : }
531 [ # # ]: 0 : if (rxq->rx_nb_avail == 0)
532 : : return;
533 [ # # ]: 0 : for (i = 0; i < rxq->rx_nb_avail; i++)
534 : 0 : rte_pktmbuf_free(rxq->rx_stage[rxq->rx_next_avail + i]);
535 : :
536 : 0 : rxq->rx_nb_avail = 0;
537 : : }
538 : :
539 : : /* turn on or off rx queue
540 : : * @q_idx: queue index in pf scope
541 : : * @on: turn on or off the queue
542 : : */
543 : : static int
544 : 0 : ice_switch_rx_queue(struct ice_hw *hw, uint16_t q_idx, bool on)
545 : : {
546 : : uint32_t reg;
547 : : uint16_t j;
548 : :
549 : : /* QRX_CTRL = QRX_ENA */
550 : 0 : reg = ICE_READ_REG(hw, QRX_CTRL(q_idx));
551 : :
552 [ # # ]: 0 : if (on) {
553 [ # # ]: 0 : if (reg & QRX_CTRL_QENA_STAT_M)
554 : : return 0; /* Already on, skip */
555 : 0 : reg |= QRX_CTRL_QENA_REQ_M;
556 : : } else {
557 [ # # ]: 0 : if (!(reg & QRX_CTRL_QENA_STAT_M))
558 : : return 0; /* Already off, skip */
559 : 0 : reg &= ~QRX_CTRL_QENA_REQ_M;
560 : : }
561 : :
562 : : /* Write the register */
563 : 0 : ICE_WRITE_REG(hw, QRX_CTRL(q_idx), reg);
564 : : /* Check the result. It is said that QENA_STAT
565 : : * follows the QENA_REQ not more than 10 use.
566 : : * TODO: need to change the wait counter later
567 : : */
568 [ # # ]: 0 : for (j = 0; j < ICE_CHK_Q_ENA_COUNT; j++) {
569 : 0 : rte_delay_us(ICE_CHK_Q_ENA_INTERVAL_US);
570 : 0 : reg = ICE_READ_REG(hw, QRX_CTRL(q_idx));
571 [ # # ]: 0 : if (on) {
572 [ # # ]: 0 : if ((reg & QRX_CTRL_QENA_REQ_M) &&
573 : : (reg & QRX_CTRL_QENA_STAT_M))
574 : : break;
575 : : } else {
576 [ # # ]: 0 : if (!(reg & QRX_CTRL_QENA_REQ_M) &&
577 : : !(reg & QRX_CTRL_QENA_STAT_M))
578 : : break;
579 : : }
580 : : }
581 : :
582 : : /* Check if it is timeout */
583 [ # # ]: 0 : if (j >= ICE_CHK_Q_ENA_COUNT) {
584 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
585 : : (on ? "enable" : "disable"), q_idx);
586 : 0 : return -ETIMEDOUT;
587 : : }
588 : :
589 : : return 0;
590 : : }
591 : :
592 : : static inline int
593 : 0 : ice_check_rx_burst_bulk_alloc_preconditions(struct ci_rx_queue *rxq)
594 : : {
595 : : int ret = 0;
596 : :
597 [ # # ]: 0 : if (!(rxq->rx_free_thresh >= ICE_RX_MAX_BURST)) {
598 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
599 : : "rxq->rx_free_thresh=%d, "
600 : : "ICE_RX_MAX_BURST=%d",
601 : : rxq->rx_free_thresh, ICE_RX_MAX_BURST);
602 : : ret = -EINVAL;
603 [ # # ]: 0 : } else if (!(rxq->rx_free_thresh < rxq->nb_rx_desc)) {
604 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
605 : : "rxq->rx_free_thresh=%d, "
606 : : "rxq->nb_rx_desc=%d",
607 : : rxq->rx_free_thresh, rxq->nb_rx_desc);
608 : : ret = -EINVAL;
609 [ # # ]: 0 : } else if (rxq->nb_rx_desc % rxq->rx_free_thresh != 0) {
610 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
611 : : "rxq->nb_rx_desc=%d, "
612 : : "rxq->rx_free_thresh=%d",
613 : : rxq->nb_rx_desc, rxq->rx_free_thresh);
614 : : ret = -EINVAL;
615 : : }
616 : :
617 : 0 : return ret;
618 : : }
619 : :
620 : : /* reset fields in ci_rx_queue back to default */
621 : : static void
622 : 0 : ice_reset_rx_queue(struct ci_rx_queue *rxq)
623 : : {
624 : : unsigned int i;
625 : : uint16_t len;
626 : :
627 [ # # ]: 0 : if (!rxq) {
628 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to rxq is NULL");
629 : 0 : return;
630 : : }
631 : :
632 : 0 : len = (uint16_t)(rxq->nb_rx_desc + ICE_RX_MAX_BURST);
633 : :
634 [ # # ]: 0 : for (i = 0; i < len * sizeof(union ci_rx_flex_desc); i++)
635 : 0 : ((volatile char *)rxq->rx_flex_ring)[i] = 0;
636 : :
637 : 0 : memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
638 [ # # ]: 0 : for (i = 0; i < ICE_RX_MAX_BURST; ++i)
639 : 0 : rxq->sw_ring[rxq->nb_rx_desc + i].mbuf = &rxq->fake_mbuf;
640 : :
641 : 0 : rxq->rx_nb_avail = 0;
642 : 0 : rxq->rx_next_avail = 0;
643 : 0 : rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
644 : :
645 : 0 : rxq->rx_tail = 0;
646 : 0 : rxq->nb_rx_hold = 0;
647 : 0 : rxq->pkt_first_seg = NULL;
648 : 0 : rxq->pkt_last_seg = NULL;
649 : :
650 : 0 : rxq->rxrearm_start = 0;
651 : 0 : rxq->rxrearm_nb = 0;
652 : : }
653 : :
654 : : int
655 : 0 : ice_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
656 : : {
657 : : struct ci_rx_queue *rxq;
658 : : int err;
659 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
660 : :
661 : 0 : PMD_INIT_FUNC_TRACE();
662 : :
663 [ # # ]: 0 : if (rx_queue_id >= dev->data->nb_rx_queues) {
664 : 0 : PMD_DRV_LOG(ERR, "RX queue %u is out of range %u",
665 : : rx_queue_id, dev->data->nb_rx_queues);
666 : 0 : return -EINVAL;
667 : : }
668 : :
669 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
670 [ # # # # ]: 0 : if (!rxq || !rxq->q_set) {
671 : 0 : PMD_DRV_LOG(ERR, "RX queue %u not available or setup",
672 : : rx_queue_id);
673 : 0 : return -EINVAL;
674 : : }
675 : :
676 [ # # ]: 0 : if (dev->data->rx_queue_state[rx_queue_id] ==
677 : : RTE_ETH_QUEUE_STATE_STARTED)
678 : : return 0;
679 : :
680 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
681 : 0 : rxq->offloads |= RTE_ETH_RX_OFFLOAD_TIMESTAMP;
682 : 0 : err = ice_program_hw_rx_queue(rxq);
683 [ # # ]: 0 : if (err) {
684 : 0 : PMD_DRV_LOG(ERR, "fail to program RX queue %u",
685 : : rx_queue_id);
686 : 0 : return -EIO;
687 : : }
688 : :
689 : 0 : err = ice_alloc_rx_queue_mbufs(rxq);
690 [ # # ]: 0 : if (err) {
691 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf");
692 : 0 : return -ENOMEM;
693 : : }
694 : :
695 : : /* Init the RX tail register. */
696 : 0 : ICE_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
697 : :
698 : 0 : err = ice_switch_rx_queue(hw, rxq->reg_idx, true);
699 [ # # ]: 0 : if (err) {
700 : 0 : PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
701 : : rx_queue_id);
702 : :
703 : 0 : rxq->rx_rel_mbufs(rxq);
704 : 0 : ice_reset_rx_queue(rxq);
705 : 0 : return -EINVAL;
706 : : }
707 : :
708 : 0 : dev->data->rx_queue_state[rx_queue_id] =
709 : : RTE_ETH_QUEUE_STATE_STARTED;
710 : :
711 : 0 : return 0;
712 : : }
713 : :
714 : : int
715 : 0 : ice_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
716 : : {
717 : : struct ci_rx_queue *rxq;
718 : : int err;
719 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
720 : :
721 [ # # ]: 0 : if (rx_queue_id < dev->data->nb_rx_queues) {
722 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
723 : :
724 [ # # ]: 0 : if (dev->data->rx_queue_state[rx_queue_id] ==
725 : : RTE_ETH_QUEUE_STATE_STOPPED)
726 : : return 0;
727 : :
728 : 0 : err = ice_switch_rx_queue(hw, rxq->reg_idx, false);
729 [ # # ]: 0 : if (err) {
730 : 0 : PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off",
731 : : rx_queue_id);
732 : 0 : return -EINVAL;
733 : : }
734 : 0 : rxq->rx_rel_mbufs(rxq);
735 : 0 : ice_reset_rx_queue(rxq);
736 : 0 : dev->data->rx_queue_state[rx_queue_id] =
737 : : RTE_ETH_QUEUE_STATE_STOPPED;
738 : : }
739 : :
740 : : return 0;
741 : : }
742 : :
743 : : /**
744 : : * ice_setup_txtime_ctx - setup a struct ice_txtime_ctx instance
745 : : * @txq: The queue on which tstamp ring to configure
746 : : * @txtime_ctx: Pointer to the Tx time queue context structure to be initialized
747 : : * @txtime_ena: Tx time enable flag, set to true if Tx time should be enabled
748 : : */
749 : : static int
750 : 0 : ice_setup_txtime_ctx(struct ci_tx_queue *txq,
751 : : struct ice_txtime_ctx *txtime_ctx, bool txtime_ena)
752 : : {
753 : 0 : struct ice_vsi *vsi = txq->ice_vsi;
754 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
755 : :
756 : 0 : txtime_ctx->base = txq->tsq->ts_mz->iova >> ICE_TX_CMPLTNQ_CTX_BASE_S;
757 : :
758 : : /* Tx time Queue Length */
759 : 0 : txtime_ctx->qlen = txq->tsq->nb_ts_desc;
760 : :
761 [ # # ]: 0 : if (txtime_ena)
762 : 0 : txtime_ctx->txtime_ena_q = 1;
763 : :
764 : : /* PF number */
765 : 0 : txtime_ctx->pf_num = hw->pf_id;
766 : :
767 [ # # ]: 0 : switch (vsi->type) {
768 : 0 : case ICE_VSI_PF:
769 : 0 : txtime_ctx->vmvf_type = ICE_TLAN_CTX_VMVF_TYPE_PF;
770 : : break;
771 : 0 : default:
772 : 0 : PMD_DRV_LOG(ERR, "Unable to set VMVF type for VSI type %d", vsi->type);
773 : 0 : return -EINVAL;
774 : : }
775 : :
776 : : /* make sure the context is associated with the right VSI */
777 : 0 : txtime_ctx->src_vsi = vsi->vsi_id;
778 : :
779 : 0 : txtime_ctx->ts_res = ICE_TXTIME_CTX_RESOLUTION_128NS;
780 : 0 : txtime_ctx->drbell_mode_32 = ICE_TXTIME_CTX_DRBELL_MODE_32;
781 : 0 : txtime_ctx->ts_fetch_prof_id = ICE_TXTIME_CTX_FETCH_PROF_ID_0;
782 : :
783 : 0 : return 0;
784 : : }
785 : :
786 : : int
787 : 0 : ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
788 : : {
789 : : struct ci_tx_queue *txq;
790 : : int err;
791 : : struct ice_vsi *vsi;
792 : : struct ice_hw *hw;
793 : : struct ice_pf *pf;
794 : : struct ice_aqc_add_tx_qgrp *txq_elem;
795 : : struct ice_tlan_ctx tx_ctx;
796 : : int buf_len;
797 : 0 : struct ice_adapter *ad = ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
798 : :
799 : 0 : PMD_INIT_FUNC_TRACE();
800 : :
801 [ # # ]: 0 : if (tx_queue_id >= dev->data->nb_tx_queues) {
802 : 0 : PMD_DRV_LOG(ERR, "TX queue %u is out of range %u",
803 : : tx_queue_id, dev->data->nb_tx_queues);
804 : 0 : return -EINVAL;
805 : : }
806 : :
807 : 0 : txq = dev->data->tx_queues[tx_queue_id];
808 [ # # # # ]: 0 : if (!txq || !txq->q_set) {
809 : 0 : PMD_DRV_LOG(ERR, "TX queue %u is not available or setup",
810 : : tx_queue_id);
811 : 0 : return -EINVAL;
812 : : }
813 : :
814 [ # # ]: 0 : if (dev->data->tx_queue_state[tx_queue_id] ==
815 : : RTE_ETH_QUEUE_STATE_STARTED)
816 : : return 0;
817 : :
818 : : buf_len = ice_struct_size(txq_elem, txqs, 1);
819 : 0 : txq_elem = ice_malloc(hw, buf_len);
820 [ # # ]: 0 : if (!txq_elem)
821 : : return -ENOMEM;
822 : :
823 : 0 : vsi = txq->ice_vsi;
824 : 0 : hw = ICE_VSI_TO_HW(vsi);
825 : 0 : pf = ICE_VSI_TO_PF(vsi);
826 : :
827 : : memset(&tx_ctx, 0, sizeof(tx_ctx));
828 : 0 : txq_elem->num_txqs = 1;
829 : 0 : txq_elem->txqs[0].txq_id = rte_cpu_to_le_16(txq->reg_idx);
830 : :
831 : 0 : tx_ctx.base = txq->tx_ring_dma / ICE_QUEUE_BASE_ADDR_UNIT;
832 : 0 : tx_ctx.qlen = txq->nb_tx_desc;
833 : 0 : tx_ctx.pf_num = hw->pf_id;
834 : 0 : tx_ctx.vmvf_type = ICE_TLAN_CTX_VMVF_TYPE_PF;
835 : 0 : tx_ctx.src_vsi = vsi->vsi_id;
836 : 0 : tx_ctx.port_num = hw->port_info->lport;
837 : 0 : tx_ctx.tso_ena = 1; /* tso enable */
838 : 0 : tx_ctx.tso_qnum = txq->reg_idx; /* index for tso state structure */
839 : 0 : tx_ctx.legacy_int = 1; /* Legacy or Advanced Host Interface */
840 : 0 : tx_ctx.tsyn_ena = 1;
841 : :
842 : 0 : ice_set_ctx(hw, (uint8_t *)&tx_ctx, txq_elem->txqs[0].txq_ctx,
843 : : ice_tlan_ctx_info);
844 : :
845 : : /* Fix me, we assume TC always 0 here */
846 : 0 : err = ice_ena_vsi_txq(hw->port_info, vsi->idx, 0, tx_queue_id, 1,
847 : : txq_elem, buf_len, NULL);
848 [ # # ]: 0 : if (err) {
849 : 0 : PMD_DRV_LOG(ERR, "Failed to add lan txq");
850 : 0 : rte_free(txq_elem);
851 : 0 : return -EIO;
852 : : }
853 : : /* store the schedule node id */
854 : 0 : txq->q_teid = txq_elem->txqs[0].q_teid;
855 : :
856 : : /* move the queue to correct position in hierarchy, if explicit hierarchy configured */
857 [ # # ]: 0 : if (pf->tm_conf.committed)
858 [ # # ]: 0 : if (ice_tm_setup_txq_node(pf, hw, tx_queue_id, txq->q_teid) != 0) {
859 : 0 : PMD_DRV_LOG(ERR, "Failed to set up txq traffic management node");
860 : 0 : rte_free(txq_elem);
861 : 0 : return -EIO;
862 : : }
863 : :
864 : : /* record what kind of descriptor cleanup we need on teardown */
865 : 0 : txq->vector_tx = ad->tx_vec_allowed;
866 : :
867 [ # # # # ]: 0 : if (txq->tsq != NULL && txq->tsq->ts_flag > 0) {
868 : : struct ice_aqc_set_txtime_qgrp *ts_elem;
869 : 0 : struct ice_txtime_ctx txtime_ctx = { 0 };
870 : : u8 ts_buf_len = ice_struct_size(ts_elem, txtimeqs, 1);
871 : :
872 : 0 : ts_elem = ice_malloc(hw, ts_buf_len);
873 : 0 : ice_setup_txtime_ctx(txq, &txtime_ctx, true);
874 : 0 : ice_set_ctx(hw, (u8 *)&txtime_ctx,
875 : 0 : ts_elem->txtimeqs[0].txtime_ctx,
876 : : ice_txtime_ctx_info);
877 : :
878 : 0 : txq->qtx_tail = hw->hw_addr + E830_GLQTX_TXTIME_DBELL_LSB(txq->reg_idx);
879 : :
880 : : /* Init the Tx time tail register*/
881 : : ICE_PCI_REG_WRITE(txq->qtx_tail, 0);
882 : :
883 : 0 : err = ice_aq_set_txtimeq(hw, txq->reg_idx, 1, ts_elem, ts_buf_len, NULL);
884 : 0 : rte_free(ts_elem);
885 [ # # ]: 0 : if (err) {
886 : 0 : PMD_DRV_LOG(ERR, "Failed to set Tx Time queue context, error: %d", err);
887 : 0 : rte_free(txq_elem);
888 : 0 : return err;
889 : : }
890 : : } else {
891 : 0 : txq->qtx_tail = hw->hw_addr + QTX_COMM_DBELL(txq->reg_idx);
892 : :
893 : : /* Init the Tx tail register*/
894 : : ICE_PCI_REG_WRITE(txq->qtx_tail, 0);
895 : : }
896 : :
897 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
898 : :
899 : 0 : rte_free(txq_elem);
900 : 0 : return 0;
901 : : }
902 : :
903 : : static int
904 : 0 : ice_fdir_program_hw_rx_queue(struct ci_rx_queue *rxq)
905 : : {
906 : 0 : struct ice_vsi *vsi = rxq->ice_vsi;
907 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
908 : : uint32_t rxdid = ICE_RXDID_LEGACY_1;
909 : : struct ice_rlan_ctx rx_ctx;
910 : : uint32_t regval;
911 : : int err;
912 : :
913 : 0 : rxq->rx_hdr_len = 0;
914 : 0 : rxq->rx_buf_len = 1024;
915 : :
916 : : memset(&rx_ctx, 0, sizeof(rx_ctx));
917 : :
918 : 0 : rx_ctx.base = rxq->rx_ring_phys_addr / ICE_QUEUE_BASE_ADDR_UNIT;
919 : 0 : rx_ctx.qlen = rxq->nb_rx_desc;
920 : 0 : rx_ctx.dbuf = rxq->rx_buf_len >> ICE_RLAN_CTX_DBUF_S;
921 : : rx_ctx.hbuf = rxq->rx_hdr_len >> ICE_RLAN_CTX_HBUF_S;
922 : : rx_ctx.dtype = 0; /* No Buffer Split mode */
923 : 0 : rx_ctx.dsize = 1; /* 32B descriptors */
924 : 0 : rx_ctx.rxmax = ICE_ETH_MAX_LEN;
925 : : /* TPH: Transaction Layer Packet (TLP) processing hints */
926 : 0 : rx_ctx.tphrdesc_ena = 1;
927 : 0 : rx_ctx.tphwdesc_ena = 1;
928 : 0 : rx_ctx.tphdata_ena = 1;
929 : 0 : rx_ctx.tphhead_ena = 1;
930 : : /* Low Receive Queue Threshold defined in 64 descriptors units.
931 : : * When the number of free descriptors goes below the lrxqthresh,
932 : : * an immediate interrupt is triggered.
933 : : */
934 : 0 : rx_ctx.lrxqthresh = 2;
935 : : /*default use 32 byte descriptor, vlan tag extract to L2TAG2(1st)*/
936 : 0 : rx_ctx.l2tsel = 1;
937 : : rx_ctx.showiv = 0;
938 : 0 : rx_ctx.crcstrip = (rxq->crc_len == 0) ? 1 : 0;
939 : :
940 : : /* Enable Flexible Descriptors in the queue context which
941 : : * allows this driver to select a specific receive descriptor format
942 : : */
943 : : regval = (rxdid << QRXFLXP_CNTXT_RXDID_IDX_S) &
944 : : QRXFLXP_CNTXT_RXDID_IDX_M;
945 : :
946 : : /* increasing context priority to pick up profile ID;
947 : : * default is 0x01; setting to 0x03 to ensure profile
948 : : * is programming if prev context is of same priority
949 : : */
950 : : regval |= (0x03 << QRXFLXP_CNTXT_RXDID_PRIO_S) &
951 : : QRXFLXP_CNTXT_RXDID_PRIO_M;
952 : :
953 : 0 : ICE_WRITE_REG(hw, QRXFLXP_CNTXT(rxq->reg_idx), regval);
954 : :
955 : 0 : err = ice_clear_rxq_ctx(hw, rxq->reg_idx);
956 [ # # ]: 0 : if (err) {
957 : 0 : PMD_DRV_LOG(ERR, "Failed to clear Lan Rx queue (%u) context",
958 : : rxq->queue_id);
959 : 0 : return -EINVAL;
960 : : }
961 : 0 : err = ice_write_rxq_ctx(hw, &rx_ctx, rxq->reg_idx);
962 [ # # ]: 0 : if (err) {
963 : 0 : PMD_DRV_LOG(ERR, "Failed to write Lan Rx queue (%u) context",
964 : : rxq->queue_id);
965 : 0 : return -EINVAL;
966 : : }
967 : :
968 : 0 : rxq->qrx_tail = hw->hw_addr + QRX_TAIL(rxq->reg_idx);
969 : :
970 : : /* Init the Rx tail register*/
971 : 0 : ICE_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
972 : :
973 : 0 : return 0;
974 : : }
975 : :
976 : : int
977 : 0 : ice_fdir_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
978 : : {
979 : : struct ci_rx_queue *rxq;
980 : : int err;
981 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
982 : : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
983 : :
984 : 0 : PMD_INIT_FUNC_TRACE();
985 : :
986 : 0 : rxq = pf->fdir.rxq;
987 [ # # # # ]: 0 : if (!rxq || !rxq->q_set) {
988 : 0 : PMD_DRV_LOG(ERR, "FDIR RX queue %u not available or setup",
989 : : rx_queue_id);
990 : 0 : return -EINVAL;
991 : : }
992 : :
993 : 0 : err = ice_fdir_program_hw_rx_queue(rxq);
994 [ # # ]: 0 : if (err) {
995 : 0 : PMD_DRV_LOG(ERR, "fail to program FDIR RX queue %u",
996 : : rx_queue_id);
997 : 0 : return -EIO;
998 : : }
999 : :
1000 : : /* Init the RX tail register. */
1001 : 0 : ICE_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
1002 : :
1003 : 0 : err = ice_switch_rx_queue(hw, rxq->reg_idx, true);
1004 [ # # ]: 0 : if (err) {
1005 : 0 : PMD_DRV_LOG(ERR, "Failed to switch FDIR RX queue %u on",
1006 : : rx_queue_id);
1007 : :
1008 : 0 : ice_reset_rx_queue(rxq);
1009 : 0 : return -EINVAL;
1010 : : }
1011 : :
1012 : : return 0;
1013 : : }
1014 : :
1015 : : int
1016 : 0 : ice_fdir_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1017 : : {
1018 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1019 : : struct ci_tx_queue *txq;
1020 : : int err;
1021 : : struct ice_vsi *vsi;
1022 : : struct ice_hw *hw;
1023 : : struct ice_aqc_add_tx_qgrp *txq_elem;
1024 : : struct ice_tlan_ctx tx_ctx;
1025 : : int buf_len;
1026 : :
1027 : 0 : PMD_INIT_FUNC_TRACE();
1028 : :
1029 : 0 : txq = pf->fdir.txq;
1030 [ # # # # ]: 0 : if (!txq || !txq->q_set) {
1031 : 0 : PMD_DRV_LOG(ERR, "FDIR TX queue %u is not available or setup",
1032 : : tx_queue_id);
1033 : 0 : return -EINVAL;
1034 : : }
1035 : :
1036 : : buf_len = ice_struct_size(txq_elem, txqs, 1);
1037 : 0 : txq_elem = ice_malloc(hw, buf_len);
1038 [ # # ]: 0 : if (!txq_elem)
1039 : : return -ENOMEM;
1040 : :
1041 : 0 : vsi = txq->ice_vsi;
1042 : 0 : hw = ICE_VSI_TO_HW(vsi);
1043 : :
1044 : : memset(&tx_ctx, 0, sizeof(tx_ctx));
1045 : 0 : txq_elem->num_txqs = 1;
1046 : 0 : txq_elem->txqs[0].txq_id = rte_cpu_to_le_16(txq->reg_idx);
1047 : :
1048 : 0 : tx_ctx.base = txq->tx_ring_dma / ICE_QUEUE_BASE_ADDR_UNIT;
1049 : 0 : tx_ctx.qlen = txq->nb_tx_desc;
1050 : 0 : tx_ctx.pf_num = hw->pf_id;
1051 : 0 : tx_ctx.vmvf_type = ICE_TLAN_CTX_VMVF_TYPE_PF;
1052 : 0 : tx_ctx.src_vsi = vsi->vsi_id;
1053 : 0 : tx_ctx.port_num = hw->port_info->lport;
1054 : 0 : tx_ctx.tso_ena = 1; /* tso enable */
1055 : 0 : tx_ctx.tso_qnum = txq->reg_idx; /* index for tso state structure */
1056 : 0 : tx_ctx.legacy_int = 1; /* Legacy or Advanced Host Interface */
1057 : :
1058 : 0 : ice_set_ctx(hw, (uint8_t *)&tx_ctx, txq_elem->txqs[0].txq_ctx,
1059 : : ice_tlan_ctx_info);
1060 : :
1061 : 0 : txq->qtx_tail = hw->hw_addr + QTX_COMM_DBELL(txq->reg_idx);
1062 : :
1063 : : /* Init the Tx tail register*/
1064 : : ICE_PCI_REG_WRITE(txq->qtx_tail, 0);
1065 : :
1066 : : /* Fix me, we assume TC always 0 here */
1067 : 0 : err = ice_ena_vsi_txq(hw->port_info, vsi->idx, 0, tx_queue_id, 1,
1068 : : txq_elem, buf_len, NULL);
1069 [ # # ]: 0 : if (err) {
1070 : 0 : PMD_DRV_LOG(ERR, "Failed to add FDIR txq");
1071 : 0 : rte_free(txq_elem);
1072 : 0 : return -EIO;
1073 : : }
1074 : : /* store the schedule node id */
1075 : 0 : txq->q_teid = txq_elem->txqs[0].q_teid;
1076 : :
1077 : 0 : rte_free(txq_elem);
1078 : 0 : return 0;
1079 : : }
1080 : :
1081 : : static void
1082 : 0 : ice_reset_tx_queue(struct ci_tx_queue *txq)
1083 : : {
1084 : : struct ci_tx_entry *txe;
1085 : : uint16_t i, prev, size;
1086 : :
1087 [ # # ]: 0 : if (!txq) {
1088 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to txq is NULL");
1089 : 0 : return;
1090 : : }
1091 : :
1092 : 0 : txe = txq->sw_ring;
1093 : 0 : size = sizeof(struct ice_tx_desc) * txq->nb_tx_desc;
1094 [ # # ]: 0 : for (i = 0; i < size; i++)
1095 : 0 : ((volatile char *)txq->ice_tx_ring)[i] = 0;
1096 : :
1097 : 0 : prev = (uint16_t)(txq->nb_tx_desc - 1);
1098 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
1099 : 0 : volatile struct ice_tx_desc *txd = &txq->ice_tx_ring[i];
1100 : :
1101 : 0 : txd->cmd_type_offset_bsz =
1102 : : rte_cpu_to_le_64(ICE_TX_DESC_DTYPE_DESC_DONE);
1103 : 0 : txe[i].mbuf = NULL;
1104 : 0 : txe[i].last_id = i;
1105 : 0 : txe[prev].next_id = i;
1106 : : prev = i;
1107 : : }
1108 : :
1109 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
1110 : 0 : txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
1111 : :
1112 : 0 : txq->tx_tail = 0;
1113 : 0 : txq->nb_tx_used = 0;
1114 : :
1115 : 0 : txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
1116 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
1117 : :
1118 [ # # # # ]: 0 : if (txq->tsq != NULL && txq->tsq->ts_flag > 0) {
1119 [ # # ]: 0 : for (i = 0; i < txq->tsq->nb_ts_desc; i++) {
1120 : 0 : volatile struct ice_ts_desc *tsd = &txq->tsq->ice_ts_ring[i];
1121 : 0 : tsd->tx_desc_idx_tstamp = 0;
1122 : : }
1123 : :
1124 : 0 : txq->tsq->ts_tail = 0;
1125 : : }
1126 : : }
1127 : :
1128 : : int
1129 : 0 : ice_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1130 : : {
1131 : : struct ci_tx_queue *txq;
1132 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1133 : : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1134 : 0 : struct ice_vsi *vsi = pf->main_vsi;
1135 : : uint16_t q_ids[1];
1136 : : uint32_t q_teids[1];
1137 : 0 : uint16_t q_handle = tx_queue_id;
1138 : : int status;
1139 : :
1140 [ # # ]: 0 : if (tx_queue_id >= dev->data->nb_tx_queues) {
1141 : 0 : PMD_DRV_LOG(ERR, "TX queue %u is out of range %u",
1142 : : tx_queue_id, dev->data->nb_tx_queues);
1143 : 0 : return -EINVAL;
1144 : : }
1145 : :
1146 : 0 : txq = dev->data->tx_queues[tx_queue_id];
1147 [ # # ]: 0 : if (!txq) {
1148 : 0 : PMD_DRV_LOG(ERR, "TX queue %u is not available",
1149 : : tx_queue_id);
1150 : 0 : return -EINVAL;
1151 : : }
1152 : :
1153 [ # # ]: 0 : if (dev->data->tx_queue_state[tx_queue_id] ==
1154 : : RTE_ETH_QUEUE_STATE_STOPPED)
1155 : : return 0;
1156 : :
1157 : 0 : q_ids[0] = txq->reg_idx;
1158 : 0 : q_teids[0] = txq->q_teid;
1159 : :
1160 [ # # # # ]: 0 : if (txq->tsq != NULL && txq->tsq->ts_flag > 0) {
1161 : : struct ice_aqc_ena_dis_txtime_qgrp txtime_pg;
1162 : :
1163 : 0 : dev->dev_ops->timesync_disable(dev);
1164 : 0 : status = ice_aq_ena_dis_txtimeq(hw, q_ids[0], 1, 0, &txtime_pg, NULL);
1165 [ # # ]: 0 : if (status != ICE_SUCCESS) {
1166 : 0 : PMD_DRV_LOG(DEBUG, "Failed to disable Tx time queue");
1167 : 0 : return -EINVAL;
1168 : : }
1169 : : }
1170 : :
1171 : : /* Fix me, we assume TC always 0 here */
1172 : 0 : status = ice_dis_vsi_txq(hw->port_info, vsi->idx, 0, 1, &q_handle,
1173 : : q_ids, q_teids, ICE_NO_RESET, 0, NULL);
1174 [ # # ]: 0 : if (status != ICE_SUCCESS) {
1175 : 0 : PMD_DRV_LOG(DEBUG, "Failed to disable Lan Tx queue");
1176 : 0 : return -EINVAL;
1177 : : }
1178 : :
1179 : 0 : ci_txq_release_all_mbufs(txq, false);
1180 : 0 : ice_reset_tx_queue(txq);
1181 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
1182 : :
1183 : 0 : return 0;
1184 : : }
1185 : :
1186 : : int
1187 : 0 : ice_fdir_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1188 : : {
1189 : : struct ci_rx_queue *rxq;
1190 : : int err;
1191 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1192 : : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1193 : :
1194 : 0 : rxq = pf->fdir.rxq;
1195 : :
1196 : 0 : err = ice_switch_rx_queue(hw, rxq->reg_idx, false);
1197 [ # # ]: 0 : if (err) {
1198 : 0 : PMD_DRV_LOG(ERR, "Failed to switch FDIR RX queue %u off",
1199 : : rx_queue_id);
1200 : 0 : return -EINVAL;
1201 : : }
1202 : 0 : rxq->rx_rel_mbufs(rxq);
1203 : :
1204 : 0 : return 0;
1205 : : }
1206 : :
1207 : : int
1208 : 0 : ice_fdir_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1209 : : {
1210 : : struct ci_tx_queue *txq;
1211 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1212 : : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1213 : : struct ice_vsi *vsi = pf->main_vsi;
1214 : : uint16_t q_ids[1];
1215 : : uint32_t q_teids[1];
1216 : 0 : uint16_t q_handle = tx_queue_id;
1217 : : int status;
1218 : :
1219 : 0 : txq = pf->fdir.txq;
1220 [ # # ]: 0 : if (!txq) {
1221 : 0 : PMD_DRV_LOG(ERR, "TX queue %u is not available",
1222 : : tx_queue_id);
1223 : 0 : return -EINVAL;
1224 : : }
1225 [ # # ]: 0 : if (txq->qtx_tail == NULL) {
1226 : 0 : PMD_DRV_LOG(INFO, "TX queue %u not started", tx_queue_id);
1227 : 0 : return 0;
1228 : : }
1229 : 0 : vsi = txq->ice_vsi;
1230 : :
1231 : 0 : q_ids[0] = txq->reg_idx;
1232 : 0 : q_teids[0] = txq->q_teid;
1233 : :
1234 : : /* Fix me, we assume TC always 0 here */
1235 : 0 : status = ice_dis_vsi_txq(hw->port_info, vsi->idx, 0, 1, &q_handle,
1236 : : q_ids, q_teids, ICE_NO_RESET, 0, NULL);
1237 [ # # ]: 0 : if (status != ICE_SUCCESS) {
1238 : 0 : PMD_DRV_LOG(DEBUG, "Failed to disable Lan Tx queue");
1239 : 0 : return -EINVAL;
1240 : : }
1241 : :
1242 : 0 : ci_txq_release_all_mbufs(txq, false);
1243 : 0 : txq->qtx_tail = NULL;
1244 : :
1245 : 0 : return 0;
1246 : : }
1247 : :
1248 : : int
1249 : 0 : ice_rx_queue_setup(struct rte_eth_dev *dev,
1250 : : uint16_t queue_idx,
1251 : : uint16_t nb_desc,
1252 : : unsigned int socket_id,
1253 : : const struct rte_eth_rxconf *rx_conf,
1254 : : struct rte_mempool *mp)
1255 : : {
1256 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1257 : : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1258 : : struct ice_adapter *ad =
1259 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1260 : 0 : struct ice_vsi *vsi = pf->main_vsi;
1261 : : struct ci_rx_queue *rxq;
1262 : : const struct rte_memzone *rz;
1263 : : uint32_t ring_size, tlen;
1264 : : uint16_t len;
1265 : : int use_def_burst_func = 1;
1266 : : uint64_t offloads;
1267 : 0 : uint16_t n_seg = rx_conf->rx_nseg;
1268 : : uint16_t i;
1269 : :
1270 [ # # ]: 0 : if (nb_desc % ICE_ALIGN_RING_DESC != 0 ||
1271 [ # # ]: 0 : nb_desc > ICE_MAX_RING_DESC ||
1272 : : nb_desc < ICE_MIN_RING_DESC) {
1273 : 0 : PMD_INIT_LOG(ERR, "Number (%u) of receive descriptors is "
1274 : : "invalid", nb_desc);
1275 : 0 : return -EINVAL;
1276 : : }
1277 : :
1278 : 0 : offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
1279 : :
1280 [ # # ]: 0 : if (mp)
1281 : : n_seg = 1;
1282 : :
1283 [ # # # # ]: 0 : if (n_seg > 1 && !(offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT)) {
1284 : 0 : PMD_INIT_LOG(ERR, "port %u queue index %u split offload not configured",
1285 : : dev->data->port_id, queue_idx);
1286 : 0 : return -EINVAL;
1287 : : }
1288 : :
1289 : : /* Free memory if needed */
1290 [ # # ]: 0 : if (dev->data->rx_queues[queue_idx]) {
1291 : 0 : ice_rx_queue_release(dev->data->rx_queues[queue_idx]);
1292 : 0 : dev->data->rx_queues[queue_idx] = NULL;
1293 : : }
1294 : :
1295 : : /* Allocate the rx queue data structure */
1296 : 0 : rxq = rte_zmalloc_socket(NULL,
1297 : : sizeof(struct ci_rx_queue),
1298 : : RTE_CACHE_LINE_SIZE,
1299 : : socket_id);
1300 : :
1301 [ # # ]: 0 : if (!rxq) {
1302 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for "
1303 : : "rx queue data structure");
1304 : 0 : return -ENOMEM;
1305 : : }
1306 : :
1307 : 0 : rxq->rxseg_nb = n_seg;
1308 [ # # ]: 0 : if (n_seg > 1) {
1309 [ # # ]: 0 : for (i = 0; i < n_seg; i++)
1310 : 0 : memcpy(&rxq->rxseg[i], &rx_conf->rx_seg[i].split,
1311 : : sizeof(struct rte_eth_rxseg_split));
1312 : :
1313 : 0 : rxq->mp = rxq->rxseg[0].mp;
1314 : : } else {
1315 : 0 : rxq->mp = mp;
1316 : : }
1317 : :
1318 : 0 : rxq->nb_rx_desc = nb_desc;
1319 : 0 : rxq->rx_free_thresh = rx_conf->rx_free_thresh;
1320 : 0 : rxq->queue_id = queue_idx;
1321 : 0 : rxq->offloads = offloads;
1322 : :
1323 : 0 : rxq->reg_idx = vsi->base_queue + queue_idx;
1324 : 0 : rxq->port_id = dev->data->port_id;
1325 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
1326 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
1327 : : else
1328 : 0 : rxq->crc_len = 0;
1329 : :
1330 : 0 : rxq->drop_en = rx_conf->rx_drop_en;
1331 : 0 : rxq->ice_vsi = vsi;
1332 : 0 : rxq->rx_deferred_start = rx_conf->rx_deferred_start;
1333 : 0 : rxq->proto_xtr = pf->proto_xtr != NULL ?
1334 [ # # ]: 0 : pf->proto_xtr[queue_idx] : PROTO_XTR_NONE;
1335 [ # # ]: 0 : if (rxq->proto_xtr != PROTO_XTR_NONE &&
1336 [ # # ]: 0 : ad->devargs.xtr_flag_offs[rxq->proto_xtr] != 0xff)
1337 : 0 : rxq->xtr_ol_flag = 1ULL << ad->devargs.xtr_flag_offs[rxq->proto_xtr];
1338 : 0 : rxq->xtr_field_offs = ad->devargs.xtr_field_offs;
1339 : :
1340 : : /* Allocate the maximum number of RX ring hardware descriptor. */
1341 : : len = ICE_MAX_NUM_DESC_BY_MAC(hw);
1342 : :
1343 : : /**
1344 : : * Allocating a little more memory because vectorized/bulk_alloc Rx
1345 : : * functions doesn't check boundaries each time.
1346 : : */
1347 : : len += ICE_RX_MAX_BURST;
1348 : :
1349 : : /* Allocate the maximum number of RX ring hardware descriptor. */
1350 : : ring_size = sizeof(union ci_rx_flex_desc) * len;
1351 : : ring_size = RTE_ALIGN(ring_size, ICE_DMA_MEM_ALIGN);
1352 : 0 : rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
1353 : : ring_size, ICE_RING_BASE_ALIGN,
1354 : : socket_id);
1355 [ # # ]: 0 : if (!rz) {
1356 : 0 : ice_rx_queue_release(rxq);
1357 : 0 : PMD_INIT_LOG(ERR, "Failed to reserve DMA memory for RX");
1358 : 0 : return -ENOMEM;
1359 : : }
1360 : :
1361 : 0 : rxq->mz = rz;
1362 : : /* Zero all the descriptors in the ring. */
1363 [ # # ]: 0 : memset(rz->addr, 0, ring_size);
1364 : :
1365 : 0 : rxq->rx_ring_phys_addr = rz->iova;
1366 : 0 : rxq->rx_flex_ring = rz->addr;
1367 : :
1368 : : /* always reserve more for bulk alloc */
1369 : 0 : len = (uint16_t)(nb_desc + ICE_RX_MAX_BURST);
1370 : :
1371 : : /* allocate extra entries for SW split buffer */
1372 : 0 : tlen = ((rxq->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT) != 0) ?
1373 [ # # ]: 0 : rxq->rx_free_thresh : 0;
1374 : 0 : tlen += len;
1375 : :
1376 : : /* Allocate the software ring. */
1377 : 0 : rxq->sw_ring = rte_zmalloc_socket(NULL,
1378 : : sizeof(struct ci_rx_entry) * tlen,
1379 : : RTE_CACHE_LINE_SIZE,
1380 : : socket_id);
1381 [ # # ]: 0 : if (!rxq->sw_ring) {
1382 : 0 : ice_rx_queue_release(rxq);
1383 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for SW ring");
1384 : 0 : return -ENOMEM;
1385 : : }
1386 : :
1387 [ # # ]: 0 : rxq->sw_split_buf = (tlen == len) ? NULL : rxq->sw_ring + len;
1388 : :
1389 : 0 : ice_reset_rx_queue(rxq);
1390 : 0 : rxq->q_set = true;
1391 : 0 : dev->data->rx_queues[queue_idx] = rxq;
1392 : 0 : rxq->rx_rel_mbufs = _ice_rx_queue_release_mbufs;
1393 : :
1394 : 0 : use_def_burst_func = ice_check_rx_burst_bulk_alloc_preconditions(rxq);
1395 : :
1396 [ # # ]: 0 : if (!use_def_burst_func) {
1397 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
1398 : : "satisfied. Rx Burst Bulk Alloc function will be "
1399 : : "used on port=%d, queue=%d.",
1400 : : rxq->port_id, rxq->queue_id);
1401 : : } else {
1402 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
1403 : : "not satisfied, Scattered Rx is requested. "
1404 : : "on port=%d, queue=%d.",
1405 : : rxq->port_id, rxq->queue_id);
1406 : 0 : ad->rx_bulk_alloc_allowed = false;
1407 : : }
1408 : :
1409 : : return 0;
1410 : : }
1411 : :
1412 : : void
1413 : 0 : ice_rx_queue_release(void *rxq)
1414 : : {
1415 : : struct ci_rx_queue *q = (struct ci_rx_queue *)rxq;
1416 : :
1417 [ # # ]: 0 : if (!q) {
1418 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to rxq is NULL");
1419 : 0 : return;
1420 : : }
1421 : :
1422 [ # # ]: 0 : if (q->rx_rel_mbufs != NULL)
1423 : 0 : q->rx_rel_mbufs(q);
1424 : 0 : rte_free(q->sw_ring);
1425 : 0 : rte_memzone_free(q->mz);
1426 : 0 : rte_free(q);
1427 : : }
1428 : :
1429 : : /**
1430 : : * ice_calc_ts_ring_count - Calculate the number of timestamp descriptors
1431 : : * @hw: pointer to the hardware structure
1432 : : * @tx_desc_count: number of Tx descriptors in the ring
1433 : : *
1434 : : * Return: the number of timestamp descriptors
1435 : : */
1436 : : static uint16_t
1437 : : ice_calc_ts_ring_count(struct ice_hw *hw, u16 tx_desc_count)
1438 : : {
1439 : : u16 prof = ICE_TXTIME_CTX_FETCH_PROF_ID_0;
1440 : : u16 max_fetch_desc = 0;
1441 : : u16 fetch;
1442 : : u32 reg;
1443 : : u16 i;
1444 : :
1445 [ # # ]: 0 : for (i = 0; i < ICE_TXTIME_FETCH_PROFILE_CNT; i++) {
1446 : 0 : reg = rd32(hw, E830_GLTXTIME_FETCH_PROFILE(prof, 0));
1447 : 0 : fetch = FIELD_GET(E830_GLTXTIME_FETCH_PROFILE_FETCH_TS_DESC_M, reg);
1448 : 0 : max_fetch_desc = max(fetch, max_fetch_desc);
1449 : : }
1450 : :
1451 [ # # ]: 0 : if (!max_fetch_desc)
1452 : : max_fetch_desc = ICE_TXTIME_FETCH_TS_DESC_DFLT;
1453 : :
1454 : 0 : max_fetch_desc = RTE_ALIGN(max_fetch_desc, ICE_REQ_DESC_MULTIPLE);
1455 : :
1456 : 0 : return tx_desc_count + max_fetch_desc;
1457 : : }
1458 : :
1459 : : int
1460 : 0 : ice_tx_queue_setup(struct rte_eth_dev *dev,
1461 : : uint16_t queue_idx,
1462 : : uint16_t nb_desc,
1463 : : unsigned int socket_id,
1464 : : const struct rte_eth_txconf *tx_conf)
1465 : : {
1466 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1467 : : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1468 : 0 : struct ice_vsi *vsi = pf->main_vsi;
1469 : : struct ci_tx_queue *txq;
1470 : : const struct rte_memzone *tz;
1471 : : uint32_t ring_size;
1472 : : uint16_t tx_rs_thresh, tx_free_thresh;
1473 : : uint64_t offloads;
1474 : :
1475 : 0 : offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
1476 : :
1477 [ # # ]: 0 : if (nb_desc % ICE_ALIGN_RING_DESC != 0 ||
1478 [ # # ]: 0 : nb_desc > ICE_MAX_RING_DESC ||
1479 : : nb_desc < ICE_MIN_RING_DESC) {
1480 : 0 : PMD_INIT_LOG(ERR, "Number (%u) of transmit descriptors is "
1481 : : "invalid", nb_desc);
1482 : 0 : return -EINVAL;
1483 : : }
1484 : :
1485 : : /**
1486 : : * The following two parameters control the setting of the RS bit on
1487 : : * transmit descriptors. TX descriptors will have their RS bit set
1488 : : * after txq->tx_rs_thresh descriptors have been used. The TX
1489 : : * descriptor ring will be cleaned after txq->tx_free_thresh
1490 : : * descriptors are used or if the number of descriptors required to
1491 : : * transmit a packet is greater than the number of free TX descriptors.
1492 : : *
1493 : : * The following constraints must be satisfied:
1494 : : * - tx_rs_thresh must be greater than 0.
1495 : : * - tx_rs_thresh must be less than the size of the ring minus 2.
1496 : : * - tx_rs_thresh must be less than or equal to tx_free_thresh.
1497 : : * - tx_rs_thresh must be a divisor of the ring size.
1498 : : * - tx_free_thresh must be greater than 0.
1499 : : * - tx_free_thresh must be less than the size of the ring minus 3.
1500 : : * - tx_free_thresh + tx_rs_thresh must not exceed nb_desc.
1501 : : *
1502 : : * One descriptor in the TX ring is used as a sentinel to avoid a H/W
1503 : : * race condition, hence the maximum threshold constraints. When set
1504 : : * to zero use default values.
1505 : : */
1506 [ # # ]: 0 : tx_free_thresh = (uint16_t)(tx_conf->tx_free_thresh ?
1507 : : tx_conf->tx_free_thresh :
1508 : : ICE_DEFAULT_TX_FREE_THRESH);
1509 : : /* force tx_rs_thresh to adapt an aggressive tx_free_thresh */
1510 : 0 : tx_rs_thresh =
1511 [ # # ]: 0 : (ICE_DEFAULT_TX_RSBIT_THRESH + tx_free_thresh > nb_desc) ?
1512 : : nb_desc - tx_free_thresh : ICE_DEFAULT_TX_RSBIT_THRESH;
1513 [ # # ]: 0 : if (tx_conf->tx_rs_thresh)
1514 : : tx_rs_thresh = tx_conf->tx_rs_thresh;
1515 [ # # ]: 0 : if (tx_rs_thresh + tx_free_thresh > nb_desc) {
1516 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh + tx_free_thresh must not "
1517 : : "exceed nb_desc. (tx_rs_thresh=%u "
1518 : : "tx_free_thresh=%u nb_desc=%u port = %d queue=%d)",
1519 : : (unsigned int)tx_rs_thresh,
1520 : : (unsigned int)tx_free_thresh,
1521 : : (unsigned int)nb_desc,
1522 : : (int)dev->data->port_id,
1523 : : (int)queue_idx);
1524 : 0 : return -EINVAL;
1525 : : }
1526 [ # # ]: 0 : if (tx_rs_thresh >= (nb_desc - 2)) {
1527 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than the "
1528 : : "number of TX descriptors minus 2. "
1529 : : "(tx_rs_thresh=%u port=%d queue=%d)",
1530 : : (unsigned int)tx_rs_thresh,
1531 : : (int)dev->data->port_id,
1532 : : (int)queue_idx);
1533 : 0 : return -EINVAL;
1534 : : }
1535 [ # # ]: 0 : if (tx_free_thresh >= (nb_desc - 3)) {
1536 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than the "
1537 : : "tx_free_thresh must be less than the "
1538 : : "number of TX descriptors minus 3. "
1539 : : "(tx_free_thresh=%u port=%d queue=%d)",
1540 : : (unsigned int)tx_free_thresh,
1541 : : (int)dev->data->port_id,
1542 : : (int)queue_idx);
1543 : 0 : return -EINVAL;
1544 : : }
1545 [ # # ]: 0 : if (tx_rs_thresh > tx_free_thresh) {
1546 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than or "
1547 : : "equal to tx_free_thresh. (tx_free_thresh=%u"
1548 : : " tx_rs_thresh=%u port=%d queue=%d)",
1549 : : (unsigned int)tx_free_thresh,
1550 : : (unsigned int)tx_rs_thresh,
1551 : : (int)dev->data->port_id,
1552 : : (int)queue_idx);
1553 : 0 : return -EINVAL;
1554 : : }
1555 [ # # ]: 0 : if ((nb_desc % tx_rs_thresh) != 0) {
1556 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be a divisor of the "
1557 : : "number of TX descriptors. (tx_rs_thresh=%u"
1558 : : " port=%d queue=%d)",
1559 : : (unsigned int)tx_rs_thresh,
1560 : : (int)dev->data->port_id,
1561 : : (int)queue_idx);
1562 : 0 : return -EINVAL;
1563 : : }
1564 [ # # # # ]: 0 : if (tx_rs_thresh > 1 && tx_conf->tx_thresh.wthresh != 0) {
1565 : 0 : PMD_INIT_LOG(ERR, "TX WTHRESH must be set to 0 if "
1566 : : "tx_rs_thresh is greater than 1. "
1567 : : "(tx_rs_thresh=%u port=%d queue=%d)",
1568 : : (unsigned int)tx_rs_thresh,
1569 : : (int)dev->data->port_id,
1570 : : (int)queue_idx);
1571 : 0 : return -EINVAL;
1572 : : }
1573 : :
1574 : : /* Free memory if needed. */
1575 [ # # ]: 0 : if (dev->data->tx_queues[queue_idx]) {
1576 : 0 : ice_tx_queue_release(dev->data->tx_queues[queue_idx]);
1577 : 0 : dev->data->tx_queues[queue_idx] = NULL;
1578 : : }
1579 : :
1580 : : /* Allocate the TX queue data structure. */
1581 : 0 : txq = rte_zmalloc_socket(NULL,
1582 : : sizeof(struct ci_tx_queue),
1583 : : RTE_CACHE_LINE_SIZE,
1584 : : socket_id);
1585 [ # # ]: 0 : if (!txq) {
1586 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for "
1587 : : "tx queue structure");
1588 : 0 : return -ENOMEM;
1589 : : }
1590 : :
1591 : : /* Allocate TX hardware ring descriptors. */
1592 : : ring_size = sizeof(struct ice_tx_desc) * ICE_MAX_NUM_DESC_BY_MAC(hw);
1593 : : ring_size = RTE_ALIGN(ring_size, ICE_DMA_MEM_ALIGN);
1594 : 0 : tz = rte_eth_dma_zone_reserve(dev, "ice_tx_ring", queue_idx,
1595 : : ring_size, ICE_RING_BASE_ALIGN,
1596 : : socket_id);
1597 [ # # ]: 0 : if (!tz) {
1598 : 0 : ice_tx_queue_release(txq);
1599 : 0 : PMD_INIT_LOG(ERR, "Failed to reserve DMA memory for TX");
1600 : 0 : return -ENOMEM;
1601 : : }
1602 : :
1603 : 0 : txq->mz = tz;
1604 : 0 : txq->nb_tx_desc = nb_desc;
1605 : 0 : txq->tx_rs_thresh = tx_rs_thresh;
1606 : 0 : txq->tx_free_thresh = tx_free_thresh;
1607 : 0 : txq->queue_id = queue_idx;
1608 : :
1609 : 0 : txq->reg_idx = vsi->base_queue + queue_idx;
1610 : 0 : txq->port_id = dev->data->port_id;
1611 : 0 : txq->offloads = offloads;
1612 : 0 : txq->ice_vsi = vsi;
1613 : 0 : txq->tx_deferred_start = tx_conf->tx_deferred_start;
1614 : :
1615 : 0 : txq->tx_ring_dma = tz->iova;
1616 : 0 : txq->ice_tx_ring = tz->addr;
1617 : :
1618 : : /* Allocate software ring */
1619 : 0 : txq->sw_ring =
1620 : 0 : rte_zmalloc_socket(NULL,
1621 : : sizeof(struct ci_tx_entry) * nb_desc,
1622 : : RTE_CACHE_LINE_SIZE,
1623 : : socket_id);
1624 [ # # ]: 0 : if (!txq->sw_ring) {
1625 : 0 : ice_tx_queue_release(txq);
1626 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for SW TX ring");
1627 : 0 : return -ENOMEM;
1628 : : }
1629 : :
1630 [ # # # # ]: 0 : if (vsi->type == ICE_VSI_PF && (offloads & RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP)) {
1631 [ # # ]: 0 : if (hw->phy_model != ICE_PHY_E830) {
1632 : 0 : ice_tx_queue_release(txq);
1633 : 0 : PMD_INIT_LOG(ERR, "Tx Time Queue is not supported on this device");
1634 : 0 : return -EINVAL;
1635 : : }
1636 : :
1637 : 0 : txq->tsq = rte_zmalloc_socket(NULL, sizeof(struct ice_txtime),
1638 : : RTE_CACHE_LINE_SIZE, socket_id);
1639 [ # # ]: 0 : if (!txq->tsq) {
1640 : 0 : ice_tx_queue_release(txq);
1641 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for tx time queue structure");
1642 : 0 : return -ENOMEM;
1643 : : }
1644 : :
1645 : : int ret =
1646 : 0 : rte_mbuf_dyn_tx_timestamp_register(&txq->tsq->ts_offset,
1647 : : &txq->tsq->ts_flag);
1648 [ # # ]: 0 : if (ret) {
1649 : 0 : ice_tx_queue_release(txq);
1650 : 0 : PMD_INIT_LOG(ERR, "Cannot register Tx mbuf field/flag for timestamp");
1651 : 0 : return -EINVAL;
1652 : : }
1653 : 0 : dev->dev_ops->timesync_enable(dev);
1654 : :
1655 : 0 : txq->tsq->nb_ts_desc = ice_calc_ts_ring_count(ICE_VSI_TO_HW(vsi), txq->nb_tx_desc);
1656 : 0 : ring_size = sizeof(struct ice_ts_desc) * txq->tsq->nb_ts_desc;
1657 : 0 : ring_size = RTE_ALIGN(ring_size, ICE_DMA_MEM_ALIGN);
1658 : 0 : const struct rte_memzone *ts_z = rte_eth_dma_zone_reserve(dev, "ice_tstamp_ring",
1659 : : queue_idx, ring_size, ICE_RING_BASE_ALIGN, socket_id);
1660 [ # # ]: 0 : if (!ts_z) {
1661 : 0 : ice_tx_queue_release(txq);
1662 : 0 : PMD_INIT_LOG(ERR, "Failed to reserve DMA memory for TX timestamp");
1663 : 0 : return -ENOMEM;
1664 : : }
1665 : 0 : txq->tsq->ts_mz = ts_z;
1666 : 0 : txq->tsq->ice_ts_ring = ts_z->addr;
1667 : : } else {
1668 : 0 : txq->tsq = NULL;
1669 : : }
1670 : :
1671 : 0 : ice_reset_tx_queue(txq);
1672 : 0 : txq->q_set = true;
1673 : 0 : dev->data->tx_queues[queue_idx] = txq;
1674 : 0 : ice_set_tx_function_flag(dev, txq);
1675 : :
1676 : 0 : return 0;
1677 : : }
1678 : :
1679 : : void
1680 : 0 : ice_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1681 : : {
1682 : 0 : ice_rx_queue_release(dev->data->rx_queues[qid]);
1683 : 0 : }
1684 : :
1685 : : void
1686 : 0 : ice_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1687 : : {
1688 : 0 : ice_tx_queue_release(dev->data->tx_queues[qid]);
1689 : 0 : }
1690 : :
1691 : : void
1692 : 0 : ice_tx_queue_release(void *txq)
1693 : : {
1694 : : struct ci_tx_queue *q = (struct ci_tx_queue *)txq;
1695 : :
1696 [ # # ]: 0 : if (!q) {
1697 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to TX queue is NULL");
1698 : 0 : return;
1699 : : }
1700 : :
1701 : 0 : ci_txq_release_all_mbufs(q, false);
1702 : 0 : rte_free(q->sw_ring);
1703 [ # # ]: 0 : if (q->tsq) {
1704 : 0 : rte_memzone_free(q->tsq->ts_mz);
1705 : 0 : rte_free(q->tsq);
1706 : : }
1707 : 0 : rte_memzone_free(q->mz);
1708 : 0 : rte_free(q);
1709 : : }
1710 : :
1711 : : void
1712 : 0 : ice_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
1713 : : struct rte_eth_rxq_info *qinfo)
1714 : : {
1715 : : struct ci_rx_queue *rxq;
1716 : :
1717 : 0 : rxq = dev->data->rx_queues[queue_id];
1718 : :
1719 : 0 : qinfo->mp = rxq->mp;
1720 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
1721 : 0 : qinfo->nb_desc = rxq->nb_rx_desc;
1722 : :
1723 : 0 : qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
1724 : 0 : qinfo->conf.rx_drop_en = rxq->drop_en;
1725 : 0 : qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
1726 : 0 : }
1727 : :
1728 : : void
1729 : 0 : ice_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
1730 : : struct rte_eth_txq_info *qinfo)
1731 : : {
1732 : : struct ci_tx_queue *txq;
1733 : :
1734 : 0 : txq = dev->data->tx_queues[queue_id];
1735 : :
1736 : 0 : qinfo->nb_desc = txq->nb_tx_desc;
1737 : :
1738 : 0 : qinfo->conf.tx_thresh.pthresh = ICE_DEFAULT_TX_PTHRESH;
1739 : 0 : qinfo->conf.tx_thresh.hthresh = ICE_DEFAULT_TX_HTHRESH;
1740 : 0 : qinfo->conf.tx_thresh.wthresh = ICE_DEFAULT_TX_WTHRESH;
1741 : :
1742 : 0 : qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
1743 : 0 : qinfo->conf.tx_rs_thresh = txq->tx_rs_thresh;
1744 : 0 : qinfo->conf.offloads = txq->offloads;
1745 : 0 : qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
1746 : 0 : }
1747 : :
1748 : : int
1749 : 0 : ice_rx_queue_count(void *rx_queue)
1750 : : {
1751 : : #define ICE_RXQ_SCAN_INTERVAL 4
1752 : : volatile union ci_rx_flex_desc *rxdp;
1753 : : struct ci_rx_queue *rxq;
1754 : : uint16_t desc = 0;
1755 : :
1756 : : rxq = rx_queue;
1757 : 0 : rxdp = &rxq->rx_flex_ring[rxq->rx_tail];
1758 [ # # ]: 0 : while ((desc < rxq->nb_rx_desc) &&
1759 [ # # ]: 0 : rte_le_to_cpu_16(rxdp->wb.status_error0) &
1760 : : (1 << ICE_RX_FLEX_DESC_STATUS0_DD_S)) {
1761 : : /**
1762 : : * Check the DD bit of a rx descriptor of each 4 in a group,
1763 : : * to avoid checking too frequently and downgrading performance
1764 : : * too much.
1765 : : */
1766 : 0 : desc += ICE_RXQ_SCAN_INTERVAL;
1767 : 0 : rxdp += ICE_RXQ_SCAN_INTERVAL;
1768 [ # # ]: 0 : if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
1769 : 0 : rxdp = &rxq->rx_flex_ring[rxq->rx_tail + desc - rxq->nb_rx_desc];
1770 : : }
1771 : :
1772 : 0 : return desc;
1773 : : }
1774 : :
1775 : : #define ICE_RX_FLEX_ERR0_BITS \
1776 : : ((1 << ICE_RX_FLEX_DESC_STATUS0_HBO_S) | \
1777 : : (1 << ICE_RX_FLEX_DESC_STATUS0_XSUM_IPE_S) | \
1778 : : (1 << ICE_RX_FLEX_DESC_STATUS0_XSUM_L4E_S) | \
1779 : : (1 << ICE_RX_FLEX_DESC_STATUS0_XSUM_EIPE_S) | \
1780 : : (1 << ICE_RX_FLEX_DESC_STATUS0_XSUM_EUDPE_S) | \
1781 : : (1 << ICE_RX_FLEX_DESC_STATUS0_RXE_S))
1782 : :
1783 : : /* Rx L3/L4 checksum */
1784 : : static inline uint64_t
1785 : 0 : ice_rxd_error_to_pkt_flags(uint16_t stat_err0)
1786 : : {
1787 : : uint64_t flags = 0;
1788 : :
1789 : : /* check if HW has decoded the packet and checksum */
1790 [ # # ]: 0 : if (unlikely(!(stat_err0 & (1 << ICE_RX_FLEX_DESC_STATUS0_L3L4P_S))))
1791 : : return 0;
1792 : :
1793 [ # # ]: 0 : if (likely(!(stat_err0 & ICE_RX_FLEX_ERR0_BITS))) {
1794 : : flags |= (RTE_MBUF_F_RX_IP_CKSUM_GOOD |
1795 : : RTE_MBUF_F_RX_L4_CKSUM_GOOD |
1796 : : RTE_MBUF_F_RX_OUTER_L4_CKSUM_GOOD);
1797 : : return flags;
1798 : : }
1799 : :
1800 [ # # ]: 0 : if (unlikely(stat_err0 & (1 << ICE_RX_FLEX_DESC_STATUS0_XSUM_IPE_S)))
1801 : : flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
1802 : : else
1803 : : flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
1804 : :
1805 [ # # ]: 0 : if (unlikely(stat_err0 & (1 << ICE_RX_FLEX_DESC_STATUS0_XSUM_L4E_S)))
1806 : 0 : flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD;
1807 : : else
1808 : 0 : flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
1809 : :
1810 [ # # ]: 0 : if (unlikely(stat_err0 & (1 << ICE_RX_FLEX_DESC_STATUS0_XSUM_EIPE_S)))
1811 : 0 : flags |= RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD;
1812 : :
1813 [ # # ]: 0 : if (unlikely(stat_err0 & (1 << ICE_RX_FLEX_DESC_STATUS0_XSUM_EUDPE_S)))
1814 : 0 : flags |= RTE_MBUF_F_RX_OUTER_L4_CKSUM_BAD;
1815 : : else
1816 : 0 : flags |= RTE_MBUF_F_RX_OUTER_L4_CKSUM_GOOD;
1817 : :
1818 : : return flags;
1819 : : }
1820 : :
1821 : : static inline void
1822 : 0 : ice_rxd_to_vlan_tci(struct rte_mbuf *mb, volatile union ci_rx_flex_desc *rxdp)
1823 : : {
1824 [ # # ]: 0 : if (rte_le_to_cpu_16(rxdp->wb.status_error0) &
1825 : : (1 << ICE_RX_FLEX_DESC_STATUS0_L2TAG1P_S)) {
1826 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
1827 : 0 : mb->vlan_tci =
1828 : 0 : rte_le_to_cpu_16(rxdp->wb.l2tag1);
1829 : : PMD_RX_LOG(DEBUG, "Descriptor l2tag1: %u",
1830 : : rte_le_to_cpu_16(rxdp->wb.l2tag1));
1831 : : } else {
1832 : 0 : mb->vlan_tci = 0;
1833 : : }
1834 : :
1835 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
1836 [ # # ]: 0 : if (rte_le_to_cpu_16(rxdp->wb.status_error1) &
1837 : : (1 << ICE_RX_FLEX_DESC_STATUS1_L2TAG2P_S)) {
1838 [ # # ]: 0 : if ((mb->ol_flags & RTE_MBUF_F_RX_VLAN_STRIPPED) == 0) {
1839 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
1840 : : } else {
1841 : : /* if two tags, move Tag1 to outer tag field */
1842 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_QINQ_STRIPPED | RTE_MBUF_F_RX_QINQ;
1843 : 0 : mb->vlan_tci_outer = mb->vlan_tci;
1844 : : }
1845 : 0 : mb->vlan_tci = rte_le_to_cpu_16(rxdp->wb.l2tag2_2nd);
1846 : : PMD_RX_LOG(DEBUG, "Descriptor l2tag2_1: %u, l2tag2_2: %u",
1847 : : rte_le_to_cpu_16(rxdp->wb.l2tag2_1st),
1848 : : rte_le_to_cpu_16(rxdp->wb.l2tag2_2nd));
1849 : : } else {
1850 : 0 : mb->vlan_tci_outer = 0;
1851 : : }
1852 : : #endif
1853 : : PMD_RX_LOG(DEBUG, "Mbuf vlan_tci: %u, vlan_tci_outer: %u",
1854 : : mb->vlan_tci, mb->vlan_tci_outer);
1855 : 0 : }
1856 : :
1857 : : #define ICE_LOOK_AHEAD 8
1858 : : #if (ICE_LOOK_AHEAD != 8)
1859 : : #error "PMD ICE: ICE_LOOK_AHEAD must be 8\n"
1860 : : #endif
1861 : :
1862 : : #define ICE_PTP_TS_VALID 0x1
1863 : :
1864 : : static inline int
1865 : 0 : ice_rx_scan_hw_ring(struct ci_rx_queue *rxq)
1866 : : {
1867 : : volatile union ci_rx_flex_desc *rxdp;
1868 : : struct ci_rx_entry *rxep;
1869 : : struct rte_mbuf *mb;
1870 : : uint16_t stat_err0;
1871 : : uint16_t pkt_len, hdr_len;
1872 : : int32_t s[ICE_LOOK_AHEAD], nb_dd;
1873 : : int32_t i, j, nb_rx = 0;
1874 : : uint64_t pkt_flags = 0;
1875 : 0 : uint32_t *ptype_tbl = rxq->ice_vsi->adapter->ptype_tbl;
1876 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
1877 : : bool is_tsinit = false;
1878 : : uint64_t ts_ns;
1879 : : struct ice_vsi *vsi = rxq->ice_vsi;
1880 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
1881 : : struct ice_adapter *ad = rxq->ice_vsi->adapter;
1882 : : #endif
1883 : 0 : rxdp = &rxq->rx_flex_ring[rxq->rx_tail];
1884 : 0 : rxep = &rxq->sw_ring[rxq->rx_tail];
1885 : :
1886 : 0 : stat_err0 = rte_le_to_cpu_16(rxdp->wb.status_error0);
1887 : :
1888 : : /* Make sure there is at least 1 packet to receive */
1889 [ # # ]: 0 : if (!(stat_err0 & (1 << ICE_RX_FLEX_DESC_STATUS0_DD_S)))
1890 : : return 0;
1891 : :
1892 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
1893 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
1894 : 0 : uint64_t sw_cur_time = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
1895 : :
1896 [ # # ]: 0 : if (unlikely(sw_cur_time - rxq->hw_time_update > 4))
1897 : : is_tsinit = 1;
1898 : : }
1899 : : #endif
1900 : :
1901 : : /**
1902 : : * Scan LOOK_AHEAD descriptors at a time to determine which
1903 : : * descriptors reference packets that are ready to be received.
1904 : : */
1905 [ # # ]: 0 : for (i = 0; i < ICE_RX_MAX_BURST; i += ICE_LOOK_AHEAD,
1906 : 0 : rxdp += ICE_LOOK_AHEAD, rxep += ICE_LOOK_AHEAD) {
1907 : : /* Read desc statuses backwards to avoid race condition */
1908 [ # # ]: 0 : for (j = ICE_LOOK_AHEAD - 1; j >= 0; j--)
1909 : 0 : s[j] = rte_le_to_cpu_16(rxdp[j].wb.status_error0);
1910 : :
1911 : 0 : rte_smp_rmb();
1912 : :
1913 : : /* Compute how many status bits were set */
1914 [ # # ]: 0 : for (j = 0, nb_dd = 0; j < ICE_LOOK_AHEAD; j++)
1915 : 0 : nb_dd += s[j] & (1 << ICE_RX_FLEX_DESC_STATUS0_DD_S);
1916 : :
1917 : 0 : nb_rx += nb_dd;
1918 : :
1919 : : /* Translate descriptor info to mbuf parameters */
1920 [ # # ]: 0 : for (j = 0; j < nb_dd; j++) {
1921 : 0 : mb = rxep[j].mbuf;
1922 : 0 : pkt_len = (rte_le_to_cpu_16(rxdp[j].wb.pkt_len) &
1923 : 0 : ICE_RX_FLX_DESC_PKT_LEN_M) - rxq->crc_len;
1924 : : mb->data_len = pkt_len;
1925 : 0 : mb->pkt_len = pkt_len;
1926 : :
1927 [ # # ]: 0 : if (!(rxq->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT)) {
1928 : 0 : pkt_len = (rte_le_to_cpu_16(rxdp[j].wb.pkt_len) &
1929 : : ICE_RX_FLX_DESC_PKT_LEN_M) - rxq->crc_len;
1930 : 0 : mb->data_len = pkt_len;
1931 : 0 : mb->pkt_len = pkt_len;
1932 : : } else {
1933 : 0 : mb->nb_segs = (uint16_t)(mb->nb_segs + mb->next->nb_segs);
1934 : 0 : mb->next->next = NULL;
1935 : 0 : hdr_len = rte_le_to_cpu_16(rxdp[j].wb.hdr_len_sph_flex_flags1) &
1936 : : ICE_RX_FLEX_DESC_HEADER_LEN_M;
1937 : 0 : pkt_len = (rte_le_to_cpu_16(rxdp[j].wb.pkt_len) &
1938 : : ICE_RX_FLX_DESC_PKT_LEN_M) - rxq->crc_len;
1939 : 0 : mb->data_len = hdr_len;
1940 : 0 : mb->pkt_len = hdr_len + pkt_len;
1941 : 0 : mb->next->data_len = pkt_len;
1942 : : #ifdef RTE_ETHDEV_DEBUG_RX
1943 : : rte_pktmbuf_dump(stdout, mb, rte_pktmbuf_pkt_len(mb));
1944 : : #endif
1945 : : }
1946 : :
1947 : 0 : mb->ol_flags = 0;
1948 : 0 : stat_err0 = rte_le_to_cpu_16(rxdp[j].wb.status_error0);
1949 : 0 : pkt_flags = ice_rxd_error_to_pkt_flags(stat_err0);
1950 : 0 : mb->packet_type = ptype_tbl[ICE_RX_FLEX_DESC_PTYPE_M &
1951 : 0 : rte_le_to_cpu_16(rxdp[j].wb.ptype_flex_flags0)];
1952 : 0 : ice_rxd_to_vlan_tci(mb, &rxdp[j]);
1953 : 0 : rxd_to_pkt_fields_ops[rxq->rxdid](rxq, mb, &rxdp[j]);
1954 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
1955 [ # # ]: 0 : if (rxq->ts_flag > 0 &&
1956 [ # # ]: 0 : (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)) {
1957 : 0 : rxq->time_high =
1958 : 0 : rte_le_to_cpu_32(rxdp[j].wb.flex_ts.ts_high);
1959 [ # # ]: 0 : if (unlikely(is_tsinit)) {
1960 : 0 : ts_ns = ice_tstamp_convert_32b_64b(hw, ad, 1,
1961 : : rxq->time_high);
1962 : 0 : rxq->hw_time_low = (uint32_t)ts_ns;
1963 : 0 : rxq->hw_time_high = (uint32_t)(ts_ns >> 32);
1964 : : is_tsinit = false;
1965 : : } else {
1966 [ # # ]: 0 : if (rxq->time_high < rxq->hw_time_low)
1967 : 0 : rxq->hw_time_high += 1;
1968 : 0 : ts_ns = (uint64_t)rxq->hw_time_high << 32 | rxq->time_high;
1969 : 0 : rxq->hw_time_low = rxq->time_high;
1970 : : }
1971 : 0 : rxq->hw_time_update = rte_get_timer_cycles() /
1972 : 0 : (rte_get_timer_hz() / 1000);
1973 : 0 : *RTE_MBUF_DYNFIELD(mb,
1974 : : rxq->ts_offset,
1975 : 0 : rte_mbuf_timestamp_t *) = ts_ns;
1976 : 0 : pkt_flags |= rxq->ts_flag;
1977 : : }
1978 : :
1979 [ # # # # ]: 0 : if (ad->ptp_ena && ((mb->packet_type &
1980 : : RTE_PTYPE_L2_MASK) == RTE_PTYPE_L2_ETHER_TIMESYNC)) {
1981 : 0 : rxq->time_high =
1982 : 0 : rte_le_to_cpu_32(rxdp[j].wb.flex_ts.ts_high);
1983 : 0 : mb->timesync = rxq->queue_id;
1984 : 0 : pkt_flags |= RTE_MBUF_F_RX_IEEE1588_PTP;
1985 [ # # ]: 0 : if (rxdp[j].wb.time_stamp_low &
1986 : : ICE_PTP_TS_VALID)
1987 : 0 : pkt_flags |=
1988 : : RTE_MBUF_F_RX_IEEE1588_TMST;
1989 : : }
1990 : : #endif
1991 : 0 : mb->ol_flags |= pkt_flags;
1992 : : }
1993 : :
1994 [ # # ]: 0 : for (j = 0; j < ICE_LOOK_AHEAD; j++)
1995 : 0 : rxq->rx_stage[i + j] = rxep[j].mbuf;
1996 : :
1997 [ # # ]: 0 : if (nb_dd != ICE_LOOK_AHEAD)
1998 : : break;
1999 : : }
2000 : :
2001 : : /* Clear software ring entries */
2002 [ # # ]: 0 : for (i = 0; i < nb_rx; i++)
2003 : 0 : rxq->sw_ring[rxq->rx_tail + i].mbuf = NULL;
2004 : :
2005 : : PMD_RX_LOG(DEBUG, "ice_rx_scan_hw_ring: "
2006 : : "port_id=%u, queue_id=%u, nb_rx=%d",
2007 : : rxq->port_id, rxq->queue_id, nb_rx);
2008 : :
2009 : : return nb_rx;
2010 : : }
2011 : :
2012 : : static inline uint16_t
2013 : : ice_rx_fill_from_stage(struct ci_rx_queue *rxq,
2014 : : struct rte_mbuf **rx_pkts,
2015 : : uint16_t nb_pkts)
2016 : : {
2017 : : uint16_t i;
2018 : 0 : struct rte_mbuf **stage = &rxq->rx_stage[rxq->rx_next_avail];
2019 : :
2020 : 0 : nb_pkts = (uint16_t)RTE_MIN(nb_pkts, rxq->rx_nb_avail);
2021 : :
2022 [ # # # # ]: 0 : for (i = 0; i < nb_pkts; i++)
2023 : 0 : rx_pkts[i] = stage[i];
2024 : :
2025 : 0 : rxq->rx_nb_avail = (uint16_t)(rxq->rx_nb_avail - nb_pkts);
2026 : 0 : rxq->rx_next_avail = (uint16_t)(rxq->rx_next_avail + nb_pkts);
2027 : :
2028 : : return nb_pkts;
2029 : : }
2030 : :
2031 : : static inline int
2032 : 0 : ice_rx_alloc_bufs(struct ci_rx_queue *rxq)
2033 : : {
2034 : : volatile union ci_rx_flex_desc *rxdp;
2035 : : struct ci_rx_entry *rxep;
2036 : : struct rte_mbuf *mb;
2037 : : uint16_t alloc_idx, i;
2038 : : uint64_t dma_addr;
2039 : : int diag, diag_pay;
2040 : : uint64_t pay_addr;
2041 : :
2042 : : /* Allocate buffers in bulk */
2043 : 0 : alloc_idx = (uint16_t)(rxq->rx_free_trigger -
2044 : 0 : (rxq->rx_free_thresh - 1));
2045 : 0 : rxep = &rxq->sw_ring[alloc_idx];
2046 [ # # ]: 0 : diag = rte_mempool_get_bulk(rxq->mp, (void *)rxep,
2047 : : rxq->rx_free_thresh);
2048 [ # # ]: 0 : if (unlikely(diag != 0)) {
2049 : : PMD_RX_LOG(ERR, "Failed to get mbufs in bulk");
2050 : : return -ENOMEM;
2051 : : }
2052 : :
2053 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT) {
2054 : 0 : diag_pay = rte_mempool_get_bulk(rxq->rxseg[1].mp,
2055 [ # # ]: 0 : (void *)rxq->sw_split_buf, rxq->rx_free_thresh);
2056 [ # # ]: 0 : if (unlikely(diag_pay != 0)) {
2057 : 0 : rte_mempool_put_bulk(rxq->mp, (void *)rxep,
2058 [ # # ]: 0 : rxq->rx_free_thresh);
2059 : : PMD_RX_LOG(ERR, "Failed to get payload mbufs in bulk");
2060 : 0 : return -ENOMEM;
2061 : : }
2062 : : }
2063 : :
2064 : 0 : rxdp = &rxq->rx_flex_ring[alloc_idx];
2065 [ # # ]: 0 : for (i = 0; i < rxq->rx_free_thresh; i++) {
2066 [ # # ]: 0 : if (likely(i < (rxq->rx_free_thresh - 1)))
2067 : : /* Prefetch next mbuf */
2068 : 0 : rte_prefetch0(rxep[i + 1].mbuf);
2069 : :
2070 [ # # ]: 0 : mb = rxep[i].mbuf;
2071 : : rte_mbuf_refcnt_set(mb, 1);
2072 : 0 : mb->data_off = RTE_PKTMBUF_HEADROOM;
2073 : 0 : mb->nb_segs = 1;
2074 [ # # ]: 0 : mb->port = rxq->port_id;
2075 : : dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mb));
2076 : :
2077 [ # # ]: 0 : if (!(rxq->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT)) {
2078 : 0 : mb->next = NULL;
2079 : 0 : rxdp[i].read.hdr_addr = 0;
2080 : 0 : rxdp[i].read.pkt_addr = dma_addr;
2081 : : } else {
2082 : 0 : mb->next = rxq->sw_split_buf[i].mbuf;
2083 : : pay_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mb->next));
2084 : 0 : rxdp[i].read.hdr_addr = dma_addr;
2085 : 0 : rxdp[i].read.pkt_addr = pay_addr;
2086 : : }
2087 : : }
2088 : :
2089 : : /* Update Rx tail register */
2090 : 0 : ICE_PCI_REG_WRITE(rxq->qrx_tail, rxq->rx_free_trigger);
2091 : :
2092 : 0 : rxq->rx_free_trigger =
2093 : 0 : (uint16_t)(rxq->rx_free_trigger + rxq->rx_free_thresh);
2094 [ # # ]: 0 : if (rxq->rx_free_trigger >= rxq->nb_rx_desc)
2095 : 0 : rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
2096 : :
2097 : : return 0;
2098 : : }
2099 : :
2100 : : static inline uint16_t
2101 : 0 : rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2102 : : {
2103 : : struct ci_rx_queue *rxq = (struct ci_rx_queue *)rx_queue;
2104 : : uint16_t nb_rx = 0;
2105 : :
2106 [ # # ]: 0 : if (!nb_pkts)
2107 : : return 0;
2108 : :
2109 [ # # ]: 0 : if (rxq->rx_nb_avail)
2110 : 0 : return ice_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
2111 : :
2112 : 0 : nb_rx = (uint16_t)ice_rx_scan_hw_ring(rxq);
2113 : 0 : rxq->rx_next_avail = 0;
2114 : 0 : rxq->rx_nb_avail = nb_rx;
2115 : 0 : rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_rx);
2116 : :
2117 [ # # ]: 0 : if (rxq->rx_tail > rxq->rx_free_trigger) {
2118 [ # # ]: 0 : if (ice_rx_alloc_bufs(rxq) != 0) {
2119 : : uint16_t i, j;
2120 : :
2121 : 0 : rxq->ice_vsi->adapter->pf.dev_data->rx_mbuf_alloc_failed +=
2122 : 0 : rxq->rx_free_thresh;
2123 : : PMD_RX_LOG(DEBUG, "Rx mbuf alloc failed for "
2124 : : "port_id=%u, queue_id=%u",
2125 : : rxq->port_id, rxq->queue_id);
2126 : 0 : rxq->rx_nb_avail = 0;
2127 : 0 : rxq->rx_tail = (uint16_t)(rxq->rx_tail - nb_rx);
2128 [ # # ]: 0 : for (i = 0, j = rxq->rx_tail; i < nb_rx; i++, j++)
2129 : 0 : rxq->sw_ring[j].mbuf = rxq->rx_stage[i];
2130 : :
2131 : : return 0;
2132 : : }
2133 : : }
2134 : :
2135 [ # # ]: 0 : if (rxq->rx_tail >= rxq->nb_rx_desc)
2136 : 0 : rxq->rx_tail = 0;
2137 : :
2138 [ # # ]: 0 : if (rxq->rx_nb_avail)
2139 : 0 : return ice_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
2140 : :
2141 : : return 0;
2142 : : }
2143 : :
2144 : : static uint16_t
2145 : 0 : ice_recv_pkts_bulk_alloc(void *rx_queue,
2146 : : struct rte_mbuf **rx_pkts,
2147 : : uint16_t nb_pkts)
2148 : : {
2149 : : uint16_t nb_rx = 0;
2150 : : uint16_t n;
2151 : : uint16_t count;
2152 : :
2153 [ # # ]: 0 : if (unlikely(nb_pkts == 0))
2154 : : return nb_rx;
2155 : :
2156 [ # # ]: 0 : if (likely(nb_pkts <= ICE_RX_MAX_BURST))
2157 : 0 : return rx_recv_pkts(rx_queue, rx_pkts, nb_pkts);
2158 : :
2159 [ # # ]: 0 : while (nb_pkts) {
2160 : 0 : n = RTE_MIN(nb_pkts, ICE_RX_MAX_BURST);
2161 : 0 : count = rx_recv_pkts(rx_queue, &rx_pkts[nb_rx], n);
2162 : 0 : nb_rx = (uint16_t)(nb_rx + count);
2163 : 0 : nb_pkts = (uint16_t)(nb_pkts - count);
2164 [ # # ]: 0 : if (count < n)
2165 : : break;
2166 : : }
2167 : :
2168 : : return nb_rx;
2169 : : }
2170 : :
2171 : : static uint16_t
2172 : 0 : ice_recv_scattered_pkts(void *rx_queue,
2173 : : struct rte_mbuf **rx_pkts,
2174 : : uint16_t nb_pkts)
2175 : : {
2176 : : struct ci_rx_queue *rxq = rx_queue;
2177 : 0 : volatile union ci_rx_flex_desc *rx_ring = rxq->rx_flex_ring;
2178 : : volatile union ci_rx_flex_desc *rxdp;
2179 : : union ci_rx_flex_desc rxd;
2180 : 0 : struct ci_rx_entry *sw_ring = rxq->sw_ring;
2181 : : struct ci_rx_entry *rxe;
2182 : 0 : struct rte_mbuf *first_seg = rxq->pkt_first_seg;
2183 : 0 : struct rte_mbuf *last_seg = rxq->pkt_last_seg;
2184 : : struct rte_mbuf *nmb; /* new allocated mbuf */
2185 : : struct rte_mbuf *rxm; /* pointer to store old mbuf in SW ring */
2186 : 0 : uint16_t rx_id = rxq->rx_tail;
2187 : : uint16_t nb_rx = 0;
2188 : : uint16_t nb_hold = 0;
2189 : : uint16_t rx_packet_len;
2190 : : uint16_t rx_stat_err0;
2191 : : uint64_t dma_addr;
2192 : : uint64_t pkt_flags;
2193 : 0 : uint32_t *ptype_tbl = rxq->ice_vsi->adapter->ptype_tbl;
2194 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
2195 : : bool is_tsinit = false;
2196 : : uint64_t ts_ns;
2197 : : struct ice_vsi *vsi = rxq->ice_vsi;
2198 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
2199 : : struct ice_adapter *ad = rxq->ice_vsi->adapter;
2200 : :
2201 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
2202 : 0 : uint64_t sw_cur_time = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
2203 : :
2204 [ # # ]: 0 : if (unlikely(sw_cur_time - rxq->hw_time_update > 4))
2205 : : is_tsinit = true;
2206 : : }
2207 : : #endif
2208 : :
2209 [ # # ]: 0 : while (nb_rx < nb_pkts) {
2210 : 0 : rxdp = &rx_ring[rx_id];
2211 : 0 : rx_stat_err0 = rte_le_to_cpu_16(rxdp->wb.status_error0);
2212 : :
2213 : : /* Check the DD bit first */
2214 [ # # ]: 0 : if (!(rx_stat_err0 & (1 << ICE_RX_FLEX_DESC_STATUS0_DD_S)))
2215 : : break;
2216 : :
2217 : : /* allocate mbuf */
2218 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mp);
2219 [ # # ]: 0 : if (unlikely(!nmb)) {
2220 : 0 : rxq->ice_vsi->adapter->pf.dev_data->rx_mbuf_alloc_failed++;
2221 : 0 : break;
2222 : : }
2223 : 0 : rxd = *rxdp; /* copy descriptor in ring to temp variable*/
2224 : :
2225 : 0 : nb_hold++;
2226 : 0 : rxe = &sw_ring[rx_id]; /* get corresponding mbuf in SW ring */
2227 : 0 : rx_id++;
2228 [ # # ]: 0 : if (unlikely(rx_id == rxq->nb_rx_desc))
2229 : : rx_id = 0;
2230 : :
2231 : : /* Prefetch next mbuf */
2232 : 0 : rte_prefetch0(sw_ring[rx_id].mbuf);
2233 : :
2234 : : /**
2235 : : * When next RX descriptor is on a cache line boundary,
2236 : : * prefetch the next 4 RX descriptors and next 8 pointers
2237 : : * to mbufs.
2238 : : */
2239 [ # # ]: 0 : if ((rx_id & 0x3) == 0) {
2240 : 0 : rte_prefetch0(&rx_ring[rx_id]);
2241 : : rte_prefetch0(&sw_ring[rx_id]);
2242 : : }
2243 : :
2244 : 0 : rxm = rxe->mbuf;
2245 [ # # ]: 0 : rxe->mbuf = nmb;
2246 : : dma_addr =
2247 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
2248 : :
2249 : : /* Set data buffer address and data length of the mbuf */
2250 : 0 : rxdp->read.hdr_addr = 0;
2251 : 0 : rxdp->read.pkt_addr = dma_addr;
2252 : 0 : rx_packet_len = rte_le_to_cpu_16(rxd.wb.pkt_len) &
2253 : : ICE_RX_FLX_DESC_PKT_LEN_M;
2254 : 0 : rxm->data_len = rx_packet_len;
2255 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
2256 : :
2257 : : /**
2258 : : * If this is the first buffer of the received packet, set the
2259 : : * pointer to the first mbuf of the packet and initialize its
2260 : : * context. Otherwise, update the total length and the number
2261 : : * of segments of the current scattered packet, and update the
2262 : : * pointer to the last mbuf of the current packet.
2263 : : */
2264 [ # # ]: 0 : if (!first_seg) {
2265 : : first_seg = rxm;
2266 : 0 : first_seg->nb_segs = 1;
2267 : 0 : first_seg->pkt_len = rx_packet_len;
2268 : : } else {
2269 : 0 : first_seg->pkt_len =
2270 : 0 : (uint16_t)(first_seg->pkt_len +
2271 : : rx_packet_len);
2272 : 0 : first_seg->nb_segs++;
2273 : 0 : last_seg->next = rxm;
2274 : : }
2275 : :
2276 : : /**
2277 : : * If this is not the last buffer of the received packet,
2278 : : * update the pointer to the last mbuf of the current scattered
2279 : : * packet and continue to parse the RX ring.
2280 : : */
2281 [ # # ]: 0 : if (!(rx_stat_err0 & (1 << ICE_RX_FLEX_DESC_STATUS0_EOF_S))) {
2282 : : last_seg = rxm;
2283 : 0 : continue;
2284 : : }
2285 : :
2286 : : /**
2287 : : * This is the last buffer of the received packet. If the CRC
2288 : : * is not stripped by the hardware:
2289 : : * - Subtract the CRC length from the total packet length.
2290 : : * - If the last buffer only contains the whole CRC or a part
2291 : : * of it, free the mbuf associated to the last buffer. If part
2292 : : * of the CRC is also contained in the previous mbuf, subtract
2293 : : * the length of that CRC part from the data length of the
2294 : : * previous mbuf.
2295 : : */
2296 : 0 : rxm->next = NULL;
2297 [ # # ]: 0 : if (unlikely(rxq->crc_len > 0)) {
2298 : 0 : first_seg->pkt_len -= RTE_ETHER_CRC_LEN;
2299 [ # # ]: 0 : if (rx_packet_len <= RTE_ETHER_CRC_LEN) {
2300 : : rte_pktmbuf_free_seg(rxm);
2301 : 0 : first_seg->nb_segs--;
2302 : 0 : last_seg->data_len =
2303 : 0 : (uint16_t)(last_seg->data_len -
2304 : : (RTE_ETHER_CRC_LEN - rx_packet_len));
2305 : 0 : last_seg->next = NULL;
2306 : : } else
2307 : 0 : rxm->data_len = (uint16_t)(rx_packet_len -
2308 : : RTE_ETHER_CRC_LEN);
2309 [ # # ]: 0 : } else if (rx_packet_len == 0) {
2310 : : rte_pktmbuf_free_seg(rxm);
2311 : 0 : first_seg->nb_segs--;
2312 : 0 : last_seg->next = NULL;
2313 : : }
2314 : :
2315 : 0 : first_seg->port = rxq->port_id;
2316 : 0 : first_seg->ol_flags = 0;
2317 : 0 : first_seg->packet_type = ptype_tbl[ICE_RX_FLEX_DESC_PTYPE_M &
2318 : 0 : rte_le_to_cpu_16(rxd.wb.ptype_flex_flags0)];
2319 : 0 : ice_rxd_to_vlan_tci(first_seg, &rxd);
2320 : 0 : rxd_to_pkt_fields_ops[rxq->rxdid](rxq, first_seg, &rxd);
2321 : 0 : pkt_flags = ice_rxd_error_to_pkt_flags(rx_stat_err0);
2322 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
2323 [ # # ]: 0 : if (rxq->ts_flag > 0 &&
2324 [ # # ]: 0 : (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)) {
2325 : 0 : rxq->time_high =
2326 : 0 : rte_le_to_cpu_32(rxd.wb.flex_ts.ts_high);
2327 [ # # ]: 0 : if (unlikely(is_tsinit)) {
2328 : 0 : ts_ns = ice_tstamp_convert_32b_64b(hw, ad, 1, rxq->time_high);
2329 : 0 : rxq->hw_time_low = (uint32_t)ts_ns;
2330 : 0 : rxq->hw_time_high = (uint32_t)(ts_ns >> 32);
2331 : : is_tsinit = false;
2332 : : } else {
2333 [ # # ]: 0 : if (rxq->time_high < rxq->hw_time_low)
2334 : 0 : rxq->hw_time_high += 1;
2335 : 0 : ts_ns = (uint64_t)rxq->hw_time_high << 32 | rxq->time_high;
2336 : 0 : rxq->hw_time_low = rxq->time_high;
2337 : : }
2338 : 0 : rxq->hw_time_update = rte_get_timer_cycles() /
2339 : 0 : (rte_get_timer_hz() / 1000);
2340 : 0 : *RTE_MBUF_DYNFIELD(first_seg,
2341 : : (rxq->ts_offset),
2342 : 0 : rte_mbuf_timestamp_t *) = ts_ns;
2343 : 0 : pkt_flags |= rxq->ts_flag;
2344 : : }
2345 : :
2346 [ # # # # ]: 0 : if (ad->ptp_ena && ((first_seg->packet_type & RTE_PTYPE_L2_MASK)
2347 : : == RTE_PTYPE_L2_ETHER_TIMESYNC)) {
2348 : 0 : rxq->time_high =
2349 : 0 : rte_le_to_cpu_32(rxd.wb.flex_ts.ts_high);
2350 : 0 : first_seg->timesync = rxq->queue_id;
2351 : 0 : pkt_flags |= RTE_MBUF_F_RX_IEEE1588_PTP;
2352 : : }
2353 : : #endif
2354 : 0 : first_seg->ol_flags |= pkt_flags;
2355 : : /* Prefetch data of first segment, if configured to do so. */
2356 : 0 : rte_prefetch0(RTE_PTR_ADD(first_seg->buf_addr,
2357 : : first_seg->data_off));
2358 : 0 : rx_pkts[nb_rx++] = first_seg;
2359 : : first_seg = NULL;
2360 : : }
2361 : :
2362 : : /* Record index of the next RX descriptor to probe. */
2363 : 0 : rxq->rx_tail = rx_id;
2364 : 0 : rxq->pkt_first_seg = first_seg;
2365 : 0 : rxq->pkt_last_seg = last_seg;
2366 : :
2367 : : /**
2368 : : * If the number of free RX descriptors is greater than the RX free
2369 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
2370 : : * register. Update the RDT with the value of the last processed RX
2371 : : * descriptor minus 1, to guarantee that the RDT register is never
2372 : : * equal to the RDH register, which creates a "full" ring situation
2373 : : * from the hardware point of view.
2374 : : */
2375 : 0 : nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
2376 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
2377 [ # # ]: 0 : rx_id = (uint16_t)(rx_id == 0 ?
2378 : 0 : (rxq->nb_rx_desc - 1) : (rx_id - 1));
2379 : : /* write TAIL register */
2380 : 0 : ICE_PCI_REG_WC_WRITE(rxq->qrx_tail, rx_id);
2381 : : nb_hold = 0;
2382 : : }
2383 : 0 : rxq->nb_rx_hold = nb_hold;
2384 : :
2385 : : /* return received packet in the burst */
2386 : 0 : return nb_rx;
2387 : : }
2388 : :
2389 : : const uint32_t *
2390 : 0 : ice_dev_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
2391 : : {
2392 : 0 : struct ice_adapter *ad =
2393 : 0 : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2394 : : const uint32_t *ptypes;
2395 : :
2396 : : static const uint32_t ptypes_os[] = {
2397 : : /* refers to ice_get_default_pkt_type() */
2398 : : RTE_PTYPE_L2_ETHER,
2399 : : RTE_PTYPE_L2_ETHER_TIMESYNC,
2400 : : RTE_PTYPE_L2_ETHER_LLDP,
2401 : : RTE_PTYPE_L2_ETHER_ARP,
2402 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
2403 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
2404 : : RTE_PTYPE_L4_FRAG,
2405 : : RTE_PTYPE_L4_ICMP,
2406 : : RTE_PTYPE_L4_NONFRAG,
2407 : : RTE_PTYPE_L4_SCTP,
2408 : : RTE_PTYPE_L4_TCP,
2409 : : RTE_PTYPE_L4_UDP,
2410 : : RTE_PTYPE_TUNNEL_GRENAT,
2411 : : RTE_PTYPE_TUNNEL_IP,
2412 : : RTE_PTYPE_INNER_L2_ETHER,
2413 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
2414 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
2415 : : RTE_PTYPE_INNER_L4_FRAG,
2416 : : RTE_PTYPE_INNER_L4_ICMP,
2417 : : RTE_PTYPE_INNER_L4_NONFRAG,
2418 : : RTE_PTYPE_INNER_L4_SCTP,
2419 : : RTE_PTYPE_INNER_L4_TCP,
2420 : : RTE_PTYPE_INNER_L4_UDP,
2421 : : };
2422 : :
2423 : : static const uint32_t ptypes_comms[] = {
2424 : : /* refers to ice_get_default_pkt_type() */
2425 : : RTE_PTYPE_L2_ETHER,
2426 : : RTE_PTYPE_L2_ETHER_TIMESYNC,
2427 : : RTE_PTYPE_L2_ETHER_LLDP,
2428 : : RTE_PTYPE_L2_ETHER_ARP,
2429 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
2430 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
2431 : : RTE_PTYPE_L4_FRAG,
2432 : : RTE_PTYPE_L4_ICMP,
2433 : : RTE_PTYPE_L4_NONFRAG,
2434 : : RTE_PTYPE_L4_SCTP,
2435 : : RTE_PTYPE_L4_TCP,
2436 : : RTE_PTYPE_L4_UDP,
2437 : : RTE_PTYPE_TUNNEL_GRENAT,
2438 : : RTE_PTYPE_TUNNEL_IP,
2439 : : RTE_PTYPE_INNER_L2_ETHER,
2440 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
2441 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
2442 : : RTE_PTYPE_INNER_L4_FRAG,
2443 : : RTE_PTYPE_INNER_L4_ICMP,
2444 : : RTE_PTYPE_INNER_L4_NONFRAG,
2445 : : RTE_PTYPE_INNER_L4_SCTP,
2446 : : RTE_PTYPE_INNER_L4_TCP,
2447 : : RTE_PTYPE_INNER_L4_UDP,
2448 : : RTE_PTYPE_TUNNEL_GTPC,
2449 : : RTE_PTYPE_TUNNEL_GTPU,
2450 : : RTE_PTYPE_L2_ETHER_PPPOE,
2451 : : };
2452 : :
2453 [ # # ]: 0 : if (ad->active_pkg_type == ICE_PKG_TYPE_COMMS) {
2454 : 0 : *no_of_elements = RTE_DIM(ptypes_comms);
2455 : : ptypes = ptypes_comms;
2456 : : } else {
2457 : 0 : *no_of_elements = RTE_DIM(ptypes_os);
2458 : : ptypes = ptypes_os;
2459 : : }
2460 : :
2461 [ # # # # ]: 0 : if (dev->rx_pkt_burst == ice_recv_pkts ||
2462 [ # # ]: 0 : dev->rx_pkt_burst == ice_recv_pkts_bulk_alloc ||
2463 : : dev->rx_pkt_burst == ice_recv_scattered_pkts)
2464 : : return ptypes;
2465 : :
2466 : : #ifdef RTE_ARCH_X86
2467 [ # # # # ]: 0 : if (dev->rx_pkt_burst == ice_recv_pkts_vec ||
2468 [ # # ]: 0 : dev->rx_pkt_burst == ice_recv_scattered_pkts_vec ||
2469 : : #ifdef CC_AVX512_SUPPORT
2470 [ # # ]: 0 : dev->rx_pkt_burst == ice_recv_pkts_vec_avx512 ||
2471 [ # # ]: 0 : dev->rx_pkt_burst == ice_recv_pkts_vec_avx512_offload ||
2472 [ # # ]: 0 : dev->rx_pkt_burst == ice_recv_scattered_pkts_vec_avx512 ||
2473 [ # # ]: 0 : dev->rx_pkt_burst == ice_recv_scattered_pkts_vec_avx512_offload ||
2474 : : #endif
2475 [ # # ]: 0 : dev->rx_pkt_burst == ice_recv_pkts_vec_avx2 ||
2476 [ # # ]: 0 : dev->rx_pkt_burst == ice_recv_pkts_vec_avx2_offload ||
2477 [ # # ]: 0 : dev->rx_pkt_burst == ice_recv_scattered_pkts_vec_avx2 ||
2478 : : dev->rx_pkt_burst == ice_recv_scattered_pkts_vec_avx2_offload)
2479 : 0 : return ptypes;
2480 : : #endif
2481 : :
2482 : : return NULL;
2483 : : }
2484 : :
2485 : : int
2486 : 0 : ice_rx_descriptor_status(void *rx_queue, uint16_t offset)
2487 : : {
2488 : : volatile union ci_rx_flex_desc *rxdp;
2489 : : struct ci_rx_queue *rxq = rx_queue;
2490 : : uint32_t desc;
2491 : :
2492 [ # # ]: 0 : if (unlikely(offset >= rxq->nb_rx_desc))
2493 : : return -EINVAL;
2494 : :
2495 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - rxq->nb_rx_hold)
2496 : : return RTE_ETH_RX_DESC_UNAVAIL;
2497 : :
2498 : 0 : desc = rxq->rx_tail + offset;
2499 [ # # ]: 0 : if (desc >= rxq->nb_rx_desc)
2500 : 0 : desc -= rxq->nb_rx_desc;
2501 : :
2502 : 0 : rxdp = &rxq->rx_flex_ring[desc];
2503 [ # # ]: 0 : if (rte_le_to_cpu_16(rxdp->wb.status_error0) &
2504 : : (1 << ICE_RX_FLEX_DESC_STATUS0_DD_S))
2505 : 0 : return RTE_ETH_RX_DESC_DONE;
2506 : :
2507 : : return RTE_ETH_RX_DESC_AVAIL;
2508 : : }
2509 : :
2510 : : int
2511 : 0 : ice_tx_descriptor_status(void *tx_queue, uint16_t offset)
2512 : : {
2513 : : struct ci_tx_queue *txq = tx_queue;
2514 : : volatile uint64_t *status;
2515 : : uint64_t mask, expect;
2516 : : uint32_t desc;
2517 : :
2518 [ # # ]: 0 : if (unlikely(offset >= txq->nb_tx_desc))
2519 : : return -EINVAL;
2520 : :
2521 : 0 : desc = txq->tx_tail + offset;
2522 : : /* go to next desc that has the RS bit */
2523 : 0 : desc = ((desc + txq->tx_rs_thresh - 1) / txq->tx_rs_thresh) *
2524 : : txq->tx_rs_thresh;
2525 [ # # ]: 0 : if (desc >= txq->nb_tx_desc) {
2526 : 0 : desc -= txq->nb_tx_desc;
2527 [ # # ]: 0 : if (desc >= txq->nb_tx_desc)
2528 : 0 : desc -= txq->nb_tx_desc;
2529 : : }
2530 : :
2531 : 0 : status = &txq->ice_tx_ring[desc].cmd_type_offset_bsz;
2532 : : mask = rte_cpu_to_le_64(ICE_TXD_QW1_DTYPE_M);
2533 : : expect = rte_cpu_to_le_64(ICE_TX_DESC_DTYPE_DESC_DONE <<
2534 : : ICE_TXD_QW1_DTYPE_S);
2535 [ # # ]: 0 : if ((*status & mask) == expect)
2536 : 0 : return RTE_ETH_TX_DESC_DONE;
2537 : :
2538 : : return RTE_ETH_TX_DESC_FULL;
2539 : : }
2540 : :
2541 : : void
2542 : 0 : ice_free_queues(struct rte_eth_dev *dev)
2543 : : {
2544 : : uint16_t i;
2545 : :
2546 : 0 : PMD_INIT_FUNC_TRACE();
2547 : :
2548 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2549 [ # # ]: 0 : if (!dev->data->rx_queues[i])
2550 : 0 : continue;
2551 : 0 : ice_rx_queue_release(dev->data->rx_queues[i]);
2552 : 0 : dev->data->rx_queues[i] = NULL;
2553 : : }
2554 : 0 : dev->data->nb_rx_queues = 0;
2555 : :
2556 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
2557 [ # # ]: 0 : if (!dev->data->tx_queues[i])
2558 : 0 : continue;
2559 : 0 : ice_tx_queue_release(dev->data->tx_queues[i]);
2560 : 0 : dev->data->tx_queues[i] = NULL;
2561 : : }
2562 : 0 : dev->data->nb_tx_queues = 0;
2563 : 0 : }
2564 : :
2565 : : #define ICE_FDIR_NUM_TX_DESC ICE_MIN_RING_DESC
2566 : : #define ICE_FDIR_NUM_RX_DESC ICE_MIN_RING_DESC
2567 : :
2568 : : int
2569 : 0 : ice_fdir_setup_tx_resources(struct ice_pf *pf)
2570 : : {
2571 : : struct ci_tx_queue *txq;
2572 : : const struct rte_memzone *tz = NULL;
2573 : : uint32_t ring_size;
2574 : : struct rte_eth_dev *dev;
2575 : :
2576 [ # # ]: 0 : if (!pf) {
2577 : 0 : PMD_DRV_LOG(ERR, "PF is not available");
2578 : 0 : return -EINVAL;
2579 : : }
2580 : :
2581 : 0 : dev = &rte_eth_devices[pf->adapter->pf.dev_data->port_id];
2582 : :
2583 : : /* Allocate the TX queue data structure. */
2584 : 0 : txq = rte_zmalloc_socket("ice fdir tx queue",
2585 : : sizeof(struct ci_tx_queue),
2586 : : RTE_CACHE_LINE_SIZE,
2587 : : SOCKET_ID_ANY);
2588 [ # # ]: 0 : if (!txq) {
2589 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for "
2590 : : "tx queue structure.");
2591 : 0 : return -ENOMEM;
2592 : : }
2593 : :
2594 : : /* Allocate TX hardware ring descriptors. */
2595 : : ring_size = sizeof(struct ice_tx_desc) * ICE_FDIR_NUM_TX_DESC;
2596 : : ring_size = RTE_ALIGN(ring_size, ICE_DMA_MEM_ALIGN);
2597 : :
2598 : 0 : tz = rte_eth_dma_zone_reserve(dev, "fdir_tx_ring",
2599 : : ICE_FDIR_QUEUE_ID, ring_size,
2600 : : ICE_RING_BASE_ALIGN, SOCKET_ID_ANY);
2601 [ # # ]: 0 : if (!tz) {
2602 : 0 : ice_tx_queue_release(txq);
2603 : 0 : PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX.");
2604 : 0 : return -ENOMEM;
2605 : : }
2606 : :
2607 : 0 : txq->mz = tz;
2608 : 0 : txq->nb_tx_desc = ICE_FDIR_NUM_TX_DESC;
2609 : 0 : txq->queue_id = ICE_FDIR_QUEUE_ID;
2610 : 0 : txq->reg_idx = pf->fdir.fdir_vsi->base_queue;
2611 : 0 : txq->ice_vsi = pf->fdir.fdir_vsi;
2612 : :
2613 : 0 : txq->tx_ring_dma = tz->iova;
2614 : 0 : txq->ice_tx_ring = (struct ice_tx_desc *)tz->addr;
2615 : : /*
2616 : : * don't need to allocate software ring and reset for the fdir
2617 : : * program queue just set the queue has been configured.
2618 : : */
2619 : 0 : txq->q_set = true;
2620 : 0 : pf->fdir.txq = txq;
2621 : :
2622 : :
2623 : 0 : return ICE_SUCCESS;
2624 : : }
2625 : :
2626 : : int
2627 : 0 : ice_fdir_setup_rx_resources(struct ice_pf *pf)
2628 : : {
2629 : : struct ci_rx_queue *rxq;
2630 : : const struct rte_memzone *rz = NULL;
2631 : : uint32_t ring_size;
2632 : : struct rte_eth_dev *dev;
2633 : :
2634 [ # # ]: 0 : if (!pf) {
2635 : 0 : PMD_DRV_LOG(ERR, "PF is not available");
2636 : 0 : return -EINVAL;
2637 : : }
2638 : :
2639 : 0 : dev = &rte_eth_devices[pf->adapter->pf.dev_data->port_id];
2640 : :
2641 : : /* Allocate the RX queue data structure. */
2642 : 0 : rxq = rte_zmalloc_socket("ice fdir rx queue",
2643 : : sizeof(struct ci_rx_queue),
2644 : : RTE_CACHE_LINE_SIZE,
2645 : : SOCKET_ID_ANY);
2646 [ # # ]: 0 : if (!rxq) {
2647 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for "
2648 : : "rx queue structure.");
2649 : 0 : return -ENOMEM;
2650 : : }
2651 : :
2652 : : /* Allocate RX hardware ring descriptors. */
2653 : : ring_size = sizeof(union ice_32byte_rx_desc) * ICE_FDIR_NUM_RX_DESC;
2654 : : ring_size = RTE_ALIGN(ring_size, ICE_DMA_MEM_ALIGN);
2655 : :
2656 : 0 : rz = rte_eth_dma_zone_reserve(dev, "fdir_rx_ring",
2657 : : ICE_FDIR_QUEUE_ID, ring_size,
2658 : : ICE_RING_BASE_ALIGN, SOCKET_ID_ANY);
2659 [ # # ]: 0 : if (!rz) {
2660 : 0 : ice_rx_queue_release(rxq);
2661 : 0 : PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX.");
2662 : 0 : return -ENOMEM;
2663 : : }
2664 : :
2665 : 0 : rxq->mz = rz;
2666 : 0 : rxq->nb_rx_desc = ICE_FDIR_NUM_RX_DESC;
2667 : 0 : rxq->queue_id = ICE_FDIR_QUEUE_ID;
2668 : 0 : rxq->reg_idx = pf->fdir.fdir_vsi->base_queue;
2669 : 0 : rxq->ice_vsi = pf->fdir.fdir_vsi;
2670 : :
2671 : 0 : rxq->rx_ring_phys_addr = rz->iova;
2672 : 0 : memset(rz->addr, 0, ICE_FDIR_NUM_RX_DESC *
2673 : : sizeof(union ice_32byte_rx_desc));
2674 : 0 : rxq->rx_flex_ring = (union ci_rx_flex_desc *)rz->addr;
2675 : :
2676 : : /*
2677 : : * Don't need to allocate software ring and reset for the fdir
2678 : : * rx queue, just set the queue has been configured.
2679 : : */
2680 : 0 : rxq->q_set = true;
2681 : 0 : pf->fdir.rxq = rxq;
2682 : :
2683 : 0 : rxq->rx_rel_mbufs = _ice_rx_queue_release_mbufs;
2684 : :
2685 : 0 : return ICE_SUCCESS;
2686 : : }
2687 : :
2688 : : uint16_t
2689 : 0 : ice_recv_pkts(void *rx_queue,
2690 : : struct rte_mbuf **rx_pkts,
2691 : : uint16_t nb_pkts)
2692 : : {
2693 : : struct ci_rx_queue *rxq = rx_queue;
2694 : 0 : volatile union ci_rx_flex_desc *rx_ring = rxq->rx_flex_ring;
2695 : : volatile union ci_rx_flex_desc *rxdp;
2696 : : union ci_rx_flex_desc rxd;
2697 : 0 : struct ci_rx_entry *sw_ring = rxq->sw_ring;
2698 : : struct ci_rx_entry *rxe;
2699 : : struct rte_mbuf *nmb; /* new allocated mbuf */
2700 : : struct rte_mbuf *nmb_pay; /* new allocated payload mbuf */
2701 : : struct rte_mbuf *rxm; /* pointer to store old mbuf in SW ring */
2702 : 0 : uint16_t rx_id = rxq->rx_tail;
2703 : : uint16_t nb_rx = 0;
2704 : : uint16_t nb_hold = 0;
2705 : : uint16_t rx_packet_len;
2706 : : uint16_t rx_header_len;
2707 : : uint16_t rx_stat_err0;
2708 : : uint64_t dma_addr;
2709 : : uint64_t pkt_flags;
2710 : 0 : uint32_t *ptype_tbl = rxq->ice_vsi->adapter->ptype_tbl;
2711 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
2712 : : bool is_tsinit = false;
2713 : : uint64_t ts_ns;
2714 : : struct ice_vsi *vsi = rxq->ice_vsi;
2715 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
2716 : : struct ice_adapter *ad = rxq->ice_vsi->adapter;
2717 : :
2718 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
2719 : 0 : uint64_t sw_cur_time = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
2720 : :
2721 [ # # ]: 0 : if (unlikely(sw_cur_time - rxq->hw_time_update > 4))
2722 : : is_tsinit = 1;
2723 : : }
2724 : : #endif
2725 : :
2726 [ # # ]: 0 : while (nb_rx < nb_pkts) {
2727 : 0 : rxdp = &rx_ring[rx_id];
2728 : 0 : rx_stat_err0 = rte_le_to_cpu_16(rxdp->wb.status_error0);
2729 : :
2730 : : /* Check the DD bit first */
2731 [ # # ]: 0 : if (!(rx_stat_err0 & (1 << ICE_RX_FLEX_DESC_STATUS0_DD_S)))
2732 : : break;
2733 : :
2734 : : /* allocate header mbuf */
2735 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mp);
2736 [ # # ]: 0 : if (unlikely(!nmb)) {
2737 : 0 : rxq->ice_vsi->adapter->pf.dev_data->rx_mbuf_alloc_failed++;
2738 : 0 : break;
2739 : : }
2740 : :
2741 : 0 : rxd = *rxdp; /* copy descriptor in ring to temp variable*/
2742 : :
2743 : 0 : nb_hold++;
2744 : 0 : rxe = &sw_ring[rx_id]; /* get corresponding mbuf in SW ring */
2745 : 0 : rx_id++;
2746 [ # # ]: 0 : if (unlikely(rx_id == rxq->nb_rx_desc))
2747 : : rx_id = 0;
2748 : 0 : rxm = rxe->mbuf;
2749 [ # # ]: 0 : rxe->mbuf = nmb;
2750 : : dma_addr =
2751 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
2752 : :
2753 [ # # ]: 0 : if (!(rxq->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT)) {
2754 : : /**
2755 : : * fill the read format of descriptor with physic address in
2756 : : * new allocated mbuf: nmb
2757 : : */
2758 : 0 : rxdp->read.hdr_addr = 0;
2759 : 0 : rxdp->read.pkt_addr = dma_addr;
2760 : : } else {
2761 : : /* allocate payload mbuf */
2762 : 0 : nmb_pay = rte_mbuf_raw_alloc(rxq->rxseg[1].mp);
2763 [ # # ]: 0 : if (unlikely(!nmb_pay)) {
2764 : 0 : rxq->ice_vsi->adapter->pf.dev_data->rx_mbuf_alloc_failed++;
2765 : 0 : rxe->mbuf = NULL;
2766 : : nb_hold--;
2767 [ # # ]: 0 : if (unlikely(rx_id == 0))
2768 : 0 : rx_id = rxq->nb_rx_desc;
2769 : :
2770 : 0 : rx_id--;
2771 : 0 : rte_pktmbuf_free(nmb);
2772 : 0 : break;
2773 : : }
2774 : :
2775 : 0 : nmb->next = nmb_pay;
2776 : 0 : nmb_pay->next = NULL;
2777 : :
2778 : : /**
2779 : : * fill the read format of descriptor with physic address in
2780 : : * new allocated mbuf: nmb
2781 : : */
2782 : 0 : rxdp->read.hdr_addr = dma_addr;
2783 : 0 : rxdp->read.pkt_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb_pay));
2784 : : }
2785 : :
2786 : : /* fill old mbuf with received descriptor: rxd */
2787 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
2788 : 0 : rte_prefetch0(RTE_PTR_ADD(rxm->buf_addr, RTE_PKTMBUF_HEADROOM));
2789 [ # # ]: 0 : if (!(rxq->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT)) {
2790 : 0 : rxm->nb_segs = 1;
2791 : 0 : rxm->next = NULL;
2792 : : /* calculate rx_packet_len of the received pkt */
2793 : 0 : rx_packet_len = (rte_le_to_cpu_16(rxd.wb.pkt_len) &
2794 : 0 : ICE_RX_FLX_DESC_PKT_LEN_M) - rxq->crc_len;
2795 : 0 : rxm->data_len = rx_packet_len;
2796 : 0 : rxm->pkt_len = rx_packet_len;
2797 : : } else {
2798 : 0 : rxm->nb_segs = (uint16_t)(rxm->nb_segs + rxm->next->nb_segs);
2799 : 0 : rxm->next->next = NULL;
2800 : : /* calculate rx_packet_len of the received pkt */
2801 : 0 : rx_header_len = rte_le_to_cpu_16(rxd.wb.hdr_len_sph_flex_flags1) &
2802 : : ICE_RX_FLEX_DESC_HEADER_LEN_M;
2803 : 0 : rx_packet_len = (rte_le_to_cpu_16(rxd.wb.pkt_len) &
2804 : 0 : ICE_RX_FLX_DESC_PKT_LEN_M) - rxq->crc_len;
2805 : 0 : rxm->data_len = rx_header_len;
2806 : 0 : rxm->pkt_len = rx_header_len + rx_packet_len;
2807 : 0 : rxm->next->data_len = rx_packet_len;
2808 : :
2809 : : #ifdef RTE_ETHDEV_DEBUG_RX
2810 : : rte_pktmbuf_dump(stdout, rxm, rte_pktmbuf_pkt_len(rxm));
2811 : : #endif
2812 : : }
2813 : :
2814 : 0 : rxm->port = rxq->port_id;
2815 : 0 : rxm->packet_type = ptype_tbl[ICE_RX_FLEX_DESC_PTYPE_M &
2816 : 0 : rte_le_to_cpu_16(rxd.wb.ptype_flex_flags0)];
2817 : 0 : ice_rxd_to_vlan_tci(rxm, &rxd);
2818 : 0 : rxd_to_pkt_fields_ops[rxq->rxdid](rxq, rxm, &rxd);
2819 : 0 : pkt_flags = ice_rxd_error_to_pkt_flags(rx_stat_err0);
2820 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
2821 [ # # ]: 0 : if (rxq->ts_flag > 0 &&
2822 [ # # ]: 0 : (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)) {
2823 : 0 : rxq->time_high =
2824 : 0 : rte_le_to_cpu_32(rxd.wb.flex_ts.ts_high);
2825 [ # # ]: 0 : if (unlikely(is_tsinit)) {
2826 : 0 : ts_ns = ice_tstamp_convert_32b_64b(hw, ad, 1, rxq->time_high);
2827 : 0 : rxq->hw_time_low = (uint32_t)ts_ns;
2828 : 0 : rxq->hw_time_high = (uint32_t)(ts_ns >> 32);
2829 : : is_tsinit = false;
2830 : : } else {
2831 [ # # ]: 0 : if (rxq->time_high < rxq->hw_time_low)
2832 : 0 : rxq->hw_time_high += 1;
2833 : 0 : ts_ns = (uint64_t)rxq->hw_time_high << 32 | rxq->time_high;
2834 : 0 : rxq->hw_time_low = rxq->time_high;
2835 : : }
2836 : 0 : rxq->hw_time_update = rte_get_timer_cycles() /
2837 : 0 : (rte_get_timer_hz() / 1000);
2838 : 0 : *RTE_MBUF_DYNFIELD(rxm,
2839 : : (rxq->ts_offset),
2840 : 0 : rte_mbuf_timestamp_t *) = ts_ns;
2841 : 0 : pkt_flags |= rxq->ts_flag;
2842 : : }
2843 : :
2844 [ # # # # ]: 0 : if (ad->ptp_ena && ((rxm->packet_type & RTE_PTYPE_L2_MASK) ==
2845 : : RTE_PTYPE_L2_ETHER_TIMESYNC)) {
2846 : 0 : rxq->time_high =
2847 : 0 : rte_le_to_cpu_32(rxd.wb.flex_ts.ts_high);
2848 : 0 : rxm->timesync = rxq->queue_id;
2849 : 0 : pkt_flags |= RTE_MBUF_F_RX_IEEE1588_PTP;
2850 : : }
2851 : : #endif
2852 : 0 : rxm->ol_flags |= pkt_flags;
2853 : : /* copy old mbuf to rx_pkts */
2854 : 0 : rx_pkts[nb_rx++] = rxm;
2855 : : }
2856 : :
2857 : 0 : rxq->rx_tail = rx_id;
2858 : : /**
2859 : : * If the number of free RX descriptors is greater than the RX free
2860 : : * threshold of the queue, advance the receive tail register of queue.
2861 : : * Update that register with the value of the last processed RX
2862 : : * descriptor minus 1.
2863 : : */
2864 : 0 : nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
2865 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
2866 [ # # ]: 0 : rx_id = (uint16_t)(rx_id == 0 ?
2867 : 0 : (rxq->nb_rx_desc - 1) : (rx_id - 1));
2868 : : /* write TAIL register */
2869 : 0 : ICE_PCI_REG_WC_WRITE(rxq->qrx_tail, rx_id);
2870 : : nb_hold = 0;
2871 : : }
2872 : 0 : rxq->nb_rx_hold = nb_hold;
2873 : :
2874 : : /* return received packet in the burst */
2875 : 0 : return nb_rx;
2876 : : }
2877 : :
2878 : : static inline void
2879 : 0 : ice_parse_tunneling_params(uint64_t ol_flags,
2880 : : union ice_tx_offload tx_offload,
2881 : : uint32_t *cd_tunneling)
2882 : : {
2883 : : /* EIPT: External (outer) IP header type */
2884 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM)
2885 : 0 : *cd_tunneling |= ICE_TX_CTX_EIPT_IPV4;
2886 [ # # ]: 0 : else if (ol_flags & RTE_MBUF_F_TX_OUTER_IPV4)
2887 : 0 : *cd_tunneling |= ICE_TX_CTX_EIPT_IPV4_NO_CSUM;
2888 [ # # ]: 0 : else if (ol_flags & RTE_MBUF_F_TX_OUTER_IPV6)
2889 : 0 : *cd_tunneling |= ICE_TX_CTX_EIPT_IPV6;
2890 : :
2891 : : /* EIPLEN: External (outer) IP header length, in DWords */
2892 : 0 : *cd_tunneling |= (tx_offload.outer_l3_len >> 2) <<
2893 : : ICE_TXD_CTX_QW0_EIPLEN_S;
2894 : :
2895 : : /* L4TUNT: L4 Tunneling Type */
2896 [ # # # # ]: 0 : switch (ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) {
2897 : : case RTE_MBUF_F_TX_TUNNEL_IPIP:
2898 : : /* for non UDP / GRE tunneling, set to 00b */
2899 : : break;
2900 : 0 : case RTE_MBUF_F_TX_TUNNEL_VXLAN:
2901 : : case RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE:
2902 : : case RTE_MBUF_F_TX_TUNNEL_GTP:
2903 : : case RTE_MBUF_F_TX_TUNNEL_GENEVE:
2904 : 0 : *cd_tunneling |= ICE_TXD_CTX_UDP_TUNNELING;
2905 : 0 : break;
2906 : 0 : case RTE_MBUF_F_TX_TUNNEL_GRE:
2907 : 0 : *cd_tunneling |= ICE_TXD_CTX_GRE_TUNNELING;
2908 : 0 : break;
2909 : : default:
2910 : : PMD_TX_LOG(ERR, "Tunnel type not supported");
2911 : : return;
2912 : : }
2913 : :
2914 : : /* L4TUNLEN: L4 Tunneling Length, in Words
2915 : : *
2916 : : * We depend on app to set rte_mbuf.l2_len correctly.
2917 : : * For IP in GRE it should be set to the length of the GRE
2918 : : * header;
2919 : : * For MAC in GRE or MAC in UDP it should be set to the length
2920 : : * of the GRE or UDP headers plus the inner MAC up to including
2921 : : * its last Ethertype.
2922 : : * If MPLS labels exists, it should include them as well.
2923 : : */
2924 : 0 : *cd_tunneling |= (tx_offload.l2_len >> 1) <<
2925 : : ICE_TXD_CTX_QW0_NATLEN_S;
2926 : :
2927 : : /**
2928 : : * Calculate the tunneling UDP checksum.
2929 : : * Shall be set only if L4TUNT = 01b and EIPT is not zero
2930 : : */
2931 [ # # # # ]: 0 : if ((*cd_tunneling & ICE_TXD_CTX_QW0_EIPT_M) &&
2932 : 0 : (*cd_tunneling & ICE_TXD_CTX_UDP_TUNNELING) &&
2933 [ # # ]: 0 : (ol_flags & RTE_MBUF_F_TX_OUTER_UDP_CKSUM))
2934 : 0 : *cd_tunneling |= ICE_TXD_CTX_QW0_L4T_CS_M;
2935 : : }
2936 : :
2937 : : static inline void
2938 : 0 : ice_txd_enable_checksum(uint64_t ol_flags,
2939 : : uint32_t *td_cmd,
2940 : : uint32_t *td_offset,
2941 : : union ice_tx_offload tx_offload)
2942 : : {
2943 : : /* Set MACLEN */
2944 [ # # ]: 0 : if (!(ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK))
2945 : 0 : *td_offset |= (tx_offload.l2_len >> 1)
2946 : 0 : << ICE_TX_DESC_LEN_MACLEN_S;
2947 : :
2948 : : /* Enable L3 checksum offloads */
2949 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM) {
2950 : 0 : *td_cmd |= ICE_TX_DESC_CMD_IIPT_IPV4_CSUM;
2951 : 0 : *td_offset |= (tx_offload.l3_len >> 2) <<
2952 : : ICE_TX_DESC_LEN_IPLEN_S;
2953 [ # # ]: 0 : } else if (ol_flags & RTE_MBUF_F_TX_IPV4) {
2954 : 0 : *td_cmd |= ICE_TX_DESC_CMD_IIPT_IPV4;
2955 : 0 : *td_offset |= (tx_offload.l3_len >> 2) <<
2956 : : ICE_TX_DESC_LEN_IPLEN_S;
2957 [ # # ]: 0 : } else if (ol_flags & RTE_MBUF_F_TX_IPV6) {
2958 : 0 : *td_cmd |= ICE_TX_DESC_CMD_IIPT_IPV6;
2959 : 0 : *td_offset |= (tx_offload.l3_len >> 2) <<
2960 : : ICE_TX_DESC_LEN_IPLEN_S;
2961 : : }
2962 : :
2963 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
2964 : 0 : *td_cmd |= ICE_TX_DESC_CMD_L4T_EOFT_TCP;
2965 : 0 : *td_offset |= (tx_offload.l4_len >> 2) <<
2966 : : ICE_TX_DESC_LEN_L4_LEN_S;
2967 : 0 : return;
2968 : : }
2969 : :
2970 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_UDP_SEG) {
2971 : 0 : *td_cmd |= ICE_TX_DESC_CMD_L4T_EOFT_UDP;
2972 : 0 : *td_offset |= (tx_offload.l4_len >> 2) <<
2973 : : ICE_TX_DESC_LEN_L4_LEN_S;
2974 : 0 : return;
2975 : : }
2976 : :
2977 : : /* Enable L4 checksum offloads */
2978 [ # # # # ]: 0 : switch (ol_flags & RTE_MBUF_F_TX_L4_MASK) {
2979 : 0 : case RTE_MBUF_F_TX_TCP_CKSUM:
2980 : 0 : *td_cmd |= ICE_TX_DESC_CMD_L4T_EOFT_TCP;
2981 : 0 : *td_offset |= (sizeof(struct rte_tcp_hdr) >> 2) <<
2982 : : ICE_TX_DESC_LEN_L4_LEN_S;
2983 : 0 : break;
2984 : 0 : case RTE_MBUF_F_TX_SCTP_CKSUM:
2985 : 0 : *td_cmd |= ICE_TX_DESC_CMD_L4T_EOFT_SCTP;
2986 : 0 : *td_offset |= (sizeof(struct rte_sctp_hdr) >> 2) <<
2987 : : ICE_TX_DESC_LEN_L4_LEN_S;
2988 : 0 : break;
2989 : 0 : case RTE_MBUF_F_TX_UDP_CKSUM:
2990 : 0 : *td_cmd |= ICE_TX_DESC_CMD_L4T_EOFT_UDP;
2991 : 0 : *td_offset |= (sizeof(struct rte_udp_hdr) >> 2) <<
2992 : : ICE_TX_DESC_LEN_L4_LEN_S;
2993 : 0 : break;
2994 : : default:
2995 : : break;
2996 : : }
2997 : : }
2998 : :
2999 : : static inline int
3000 : 0 : ice_xmit_cleanup(struct ci_tx_queue *txq)
3001 : : {
3002 : 0 : struct ci_tx_entry *sw_ring = txq->sw_ring;
3003 : 0 : volatile struct ice_tx_desc *txd = txq->ice_tx_ring;
3004 : 0 : uint16_t last_desc_cleaned = txq->last_desc_cleaned;
3005 : 0 : uint16_t nb_tx_desc = txq->nb_tx_desc;
3006 : : uint16_t desc_to_clean_to;
3007 : : uint16_t nb_tx_to_clean;
3008 : :
3009 : : /* Determine the last descriptor needing to be cleaned */
3010 : 0 : desc_to_clean_to = (uint16_t)(last_desc_cleaned + txq->tx_rs_thresh);
3011 [ # # ]: 0 : if (desc_to_clean_to >= nb_tx_desc)
3012 : 0 : desc_to_clean_to = (uint16_t)(desc_to_clean_to - nb_tx_desc);
3013 : :
3014 : : /* Check to make sure the last descriptor to clean is done */
3015 : 0 : desc_to_clean_to = sw_ring[desc_to_clean_to].last_id;
3016 [ # # ]: 0 : if (!(txd[desc_to_clean_to].cmd_type_offset_bsz &
3017 : : rte_cpu_to_le_64(ICE_TX_DESC_DTYPE_DESC_DONE))) {
3018 : : PMD_TX_LOG(DEBUG, "TX descriptor %4u is not done "
3019 : : "(port=%d queue=%d) value=0x%"PRIx64,
3020 : : desc_to_clean_to,
3021 : : txq->port_id, txq->queue_id,
3022 : : txd[desc_to_clean_to].cmd_type_offset_bsz);
3023 : : /* Failed to clean any descriptors */
3024 : : return -1;
3025 : : }
3026 : :
3027 : : /* Figure out how many descriptors will be cleaned */
3028 [ # # ]: 0 : if (last_desc_cleaned > desc_to_clean_to)
3029 : 0 : nb_tx_to_clean = (uint16_t)((nb_tx_desc - last_desc_cleaned) +
3030 : : desc_to_clean_to);
3031 : : else
3032 : 0 : nb_tx_to_clean = (uint16_t)(desc_to_clean_to -
3033 : : last_desc_cleaned);
3034 : :
3035 : : /* The last descriptor to clean is done, so that means all the
3036 : : * descriptors from the last descriptor that was cleaned
3037 : : * up to the last descriptor with the RS bit set
3038 : : * are done. Only reset the threshold descriptor.
3039 : : */
3040 : 0 : txd[desc_to_clean_to].cmd_type_offset_bsz = 0;
3041 : :
3042 : : /* Update the txq to reflect the last descriptor that was cleaned */
3043 : 0 : txq->last_desc_cleaned = desc_to_clean_to;
3044 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + nb_tx_to_clean);
3045 : :
3046 : 0 : return 0;
3047 : : }
3048 : :
3049 : : /* Construct the tx flags */
3050 : : static inline uint64_t
3051 : : ice_build_ctob(uint32_t td_cmd,
3052 : : uint32_t td_offset,
3053 : : uint16_t size,
3054 : : uint32_t td_tag)
3055 : : {
3056 : 0 : return rte_cpu_to_le_64(ICE_TX_DESC_DTYPE_DATA |
3057 : : ((uint64_t)td_cmd << ICE_TXD_QW1_CMD_S) |
3058 : : ((uint64_t)td_offset << ICE_TXD_QW1_OFFSET_S) |
3059 : : ((uint64_t)size << ICE_TXD_QW1_TX_BUF_SZ_S) |
3060 : : ((uint64_t)td_tag << ICE_TXD_QW1_L2TAG1_S));
3061 : : }
3062 : :
3063 : : /* Check if the context descriptor is needed for TX offloading */
3064 : : static inline uint16_t
3065 : : ice_calc_context_desc(uint64_t flags)
3066 : : {
3067 : : static uint64_t mask = RTE_MBUF_F_TX_TCP_SEG |
3068 : : RTE_MBUF_F_TX_UDP_SEG |
3069 : : RTE_MBUF_F_TX_QINQ |
3070 : : RTE_MBUF_F_TX_OUTER_IP_CKSUM |
3071 : : RTE_MBUF_F_TX_TUNNEL_MASK |
3072 : : RTE_MBUF_F_TX_IEEE1588_TMST;
3073 : :
3074 : 0 : return (flags & mask) ? 1 : 0;
3075 : : }
3076 : :
3077 : : /* set ice TSO context descriptor */
3078 : : static inline uint64_t
3079 : : ice_set_tso_ctx(struct rte_mbuf *mbuf, union ice_tx_offload tx_offload)
3080 : : {
3081 : : uint64_t ctx_desc = 0;
3082 : : uint32_t cd_cmd, hdr_len, cd_tso_len;
3083 : :
3084 [ # # ]: 0 : if (!tx_offload.l4_len) {
3085 : : PMD_TX_LOG(DEBUG, "L4 length set to 0");
3086 : : return ctx_desc;
3087 : : }
3088 : :
3089 : 0 : hdr_len = tx_offload.l2_len + tx_offload.l3_len + tx_offload.l4_len;
3090 : 0 : hdr_len += (mbuf->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) ?
3091 [ # # ]: 0 : tx_offload.outer_l2_len + tx_offload.outer_l3_len : 0;
3092 : :
3093 : : cd_cmd = ICE_TX_CTX_DESC_TSO;
3094 : 0 : cd_tso_len = mbuf->pkt_len - hdr_len;
3095 : 0 : ctx_desc |= ((uint64_t)cd_cmd << ICE_TXD_CTX_QW1_CMD_S) |
3096 : 0 : ((uint64_t)cd_tso_len << ICE_TXD_CTX_QW1_TSO_LEN_S) |
3097 : 0 : ((uint64_t)mbuf->tso_segsz << ICE_TXD_CTX_QW1_MSS_S);
3098 : :
3099 : 0 : return ctx_desc;
3100 : : }
3101 : :
3102 : : /* HW requires that TX buffer size ranges from 1B up to (16K-1)B. */
3103 : : #define ICE_MAX_DATA_PER_TXD \
3104 : : (ICE_TXD_QW1_TX_BUF_SZ_M >> ICE_TXD_QW1_TX_BUF_SZ_S)
3105 : : /* Calculate the number of TX descriptors needed for each pkt */
3106 : : static inline uint16_t
3107 : : ice_calc_pkt_desc(struct rte_mbuf *tx_pkt)
3108 : : {
3109 : : struct rte_mbuf *txd = tx_pkt;
3110 : : uint16_t count = 0;
3111 : :
3112 [ # # ]: 0 : while (txd != NULL) {
3113 : 0 : count += DIV_ROUND_UP(txd->data_len, ICE_MAX_DATA_PER_TXD);
3114 : 0 : txd = txd->next;
3115 : : }
3116 : :
3117 : : return count;
3118 : : }
3119 : :
3120 : : uint16_t
3121 : 0 : ice_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
3122 : : {
3123 : : struct ci_tx_queue *txq;
3124 : : volatile struct ice_tx_desc *ice_tx_ring;
3125 : : volatile struct ice_tx_desc *txd;
3126 : : struct ci_tx_entry *sw_ring;
3127 : : struct ci_tx_entry *txe, *txn;
3128 : : struct rte_mbuf *tx_pkt;
3129 : : struct rte_mbuf *m_seg;
3130 : : uint32_t cd_tunneling_params;
3131 : : uint16_t tx_id;
3132 : : uint16_t ts_id = -1;
3133 : : uint16_t nb_tx;
3134 : : uint16_t nb_used;
3135 : : uint16_t nb_ctx;
3136 : 0 : uint32_t td_cmd = 0;
3137 : 0 : uint32_t td_offset = 0;
3138 : : uint32_t td_tag = 0;
3139 : : uint16_t tx_last;
3140 : : uint16_t slen;
3141 : : uint64_t buf_dma_addr;
3142 : : uint64_t ol_flags;
3143 : 0 : union ice_tx_offload tx_offload = {0};
3144 : :
3145 : : txq = tx_queue;
3146 : 0 : sw_ring = txq->sw_ring;
3147 : 0 : ice_tx_ring = txq->ice_tx_ring;
3148 : 0 : tx_id = txq->tx_tail;
3149 : 0 : txe = &sw_ring[tx_id];
3150 : :
3151 [ # # # # ]: 0 : if (txq->tsq != NULL && txq->tsq->ts_flag > 0)
3152 : 0 : ts_id = txq->tsq->ts_tail;
3153 : :
3154 : : /* Check if the descriptor ring needs to be cleaned. */
3155 [ # # ]: 0 : if (txq->nb_tx_free < txq->tx_free_thresh)
3156 : 0 : (void)ice_xmit_cleanup(txq);
3157 : :
3158 [ # # ]: 0 : for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
3159 : 0 : tx_pkt = *tx_pkts++;
3160 : :
3161 : 0 : td_cmd = 0;
3162 : : td_tag = 0;
3163 : 0 : td_offset = 0;
3164 : 0 : ol_flags = tx_pkt->ol_flags;
3165 : 0 : tx_offload.l2_len = tx_pkt->l2_len;
3166 : 0 : tx_offload.l3_len = tx_pkt->l3_len;
3167 : 0 : tx_offload.outer_l2_len = tx_pkt->outer_l2_len;
3168 : 0 : tx_offload.outer_l3_len = tx_pkt->outer_l3_len;
3169 : 0 : tx_offload.l4_len = tx_pkt->l4_len;
3170 : 0 : tx_offload.tso_segsz = tx_pkt->tso_segsz;
3171 : : /* Calculate the number of context descriptors needed. */
3172 : : nb_ctx = ice_calc_context_desc(ol_flags);
3173 : :
3174 : : /* The number of descriptors that must be allocated for
3175 : : * a packet equals to the number of the segments of that
3176 : : * packet plus the number of context descriptor if needed.
3177 : : * Recalculate the needed tx descs when TSO enabled in case
3178 : : * the mbuf data size exceeds max data size that hw allows
3179 : : * per tx desc.
3180 : : */
3181 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG))
3182 : 0 : nb_used = (uint16_t)(ice_calc_pkt_desc(tx_pkt) +
3183 : : nb_ctx);
3184 : : else
3185 : 0 : nb_used = (uint16_t)(tx_pkt->nb_segs + nb_ctx);
3186 : 0 : tx_last = (uint16_t)(tx_id + nb_used - 1);
3187 : :
3188 : : /* Circular ring */
3189 [ # # ]: 0 : if (tx_last >= txq->nb_tx_desc)
3190 : 0 : tx_last = (uint16_t)(tx_last - txq->nb_tx_desc);
3191 : :
3192 [ # # ]: 0 : if (nb_used > txq->nb_tx_free) {
3193 [ # # ]: 0 : if (ice_xmit_cleanup(txq) != 0) {
3194 [ # # ]: 0 : if (nb_tx == 0)
3195 : : return 0;
3196 : 0 : goto end_of_tx;
3197 : : }
3198 [ # # ]: 0 : if (unlikely(nb_used > txq->tx_rs_thresh)) {
3199 [ # # ]: 0 : while (nb_used > txq->nb_tx_free) {
3200 [ # # ]: 0 : if (ice_xmit_cleanup(txq) != 0) {
3201 [ # # ]: 0 : if (nb_tx == 0)
3202 : : return 0;
3203 : 0 : goto end_of_tx;
3204 : : }
3205 : : }
3206 : : }
3207 : : }
3208 : :
3209 : : /* Descriptor based VLAN insertion */
3210 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_VLAN | RTE_MBUF_F_TX_QINQ)) {
3211 : 0 : td_cmd |= ICE_TX_DESC_CMD_IL2TAG1;
3212 : 0 : td_tag = tx_pkt->vlan_tci;
3213 : : }
3214 : :
3215 : : /* Fill in tunneling parameters if necessary */
3216 : 0 : cd_tunneling_params = 0;
3217 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) {
3218 : 0 : td_offset |= (tx_offload.outer_l2_len >> 1)
3219 : 0 : << ICE_TX_DESC_LEN_MACLEN_S;
3220 : 0 : ice_parse_tunneling_params(ol_flags, tx_offload,
3221 : : &cd_tunneling_params);
3222 : : }
3223 : :
3224 : : /* Enable checksum offloading */
3225 [ # # ]: 0 : if (ol_flags & ICE_TX_CKSUM_OFFLOAD_MASK)
3226 : 0 : ice_txd_enable_checksum(ol_flags, &td_cmd,
3227 : : &td_offset, tx_offload);
3228 : :
3229 [ # # ]: 0 : if (nb_ctx) {
3230 : : /* Setup TX context descriptor if required */
3231 : 0 : volatile struct ice_tx_ctx_desc *ctx_txd =
3232 : : (volatile struct ice_tx_ctx_desc *)
3233 : 0 : &ice_tx_ring[tx_id];
3234 : : uint16_t cd_l2tag2 = 0;
3235 : : uint64_t cd_type_cmd_tso_mss = ICE_TX_DESC_DTYPE_CTX;
3236 : :
3237 : 0 : txn = &sw_ring[txe->next_id];
3238 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
3239 [ # # ]: 0 : if (txe->mbuf) {
3240 : : rte_pktmbuf_free_seg(txe->mbuf);
3241 : 0 : txe->mbuf = NULL;
3242 : : }
3243 : :
3244 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG))
3245 : 0 : cd_type_cmd_tso_mss |=
3246 : : ice_set_tso_ctx(tx_pkt, tx_offload);
3247 [ # # ]: 0 : else if (ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
3248 : 0 : cd_type_cmd_tso_mss |=
3249 : : ((uint64_t)ICE_TX_CTX_DESC_TSYN <<
3250 : : ICE_TXD_CTX_QW1_CMD_S) |
3251 : 0 : (((uint64_t)txq->ice_vsi->adapter->ptp_tx_index <<
3252 : : ICE_TXD_CTX_QW1_TSYN_S) & ICE_TXD_CTX_QW1_TSYN_M);
3253 : :
3254 : 0 : ctx_txd->tunneling_params =
3255 : : rte_cpu_to_le_32(cd_tunneling_params);
3256 : :
3257 : : /* TX context descriptor based double VLAN insert */
3258 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_QINQ) {
3259 : 0 : cd_l2tag2 = tx_pkt->vlan_tci_outer;
3260 : 0 : cd_type_cmd_tso_mss |=
3261 : : ((uint64_t)ICE_TX_CTX_DESC_IL2TAG2 <<
3262 : : ICE_TXD_CTX_QW1_CMD_S);
3263 : : }
3264 : 0 : ctx_txd->l2tag2 = rte_cpu_to_le_16(cd_l2tag2);
3265 : 0 : ctx_txd->qw1 =
3266 : : rte_cpu_to_le_64(cd_type_cmd_tso_mss);
3267 : :
3268 : 0 : txe->last_id = tx_last;
3269 : 0 : tx_id = txe->next_id;
3270 : : txe = txn;
3271 : : }
3272 : : m_seg = tx_pkt;
3273 : :
3274 : : do {
3275 : 0 : txd = &ice_tx_ring[tx_id];
3276 : 0 : txn = &sw_ring[txe->next_id];
3277 : :
3278 [ # # ]: 0 : if (txe->mbuf)
3279 : : rte_pktmbuf_free_seg(txe->mbuf);
3280 : 0 : txe->mbuf = m_seg;
3281 : :
3282 : : /* Setup TX Descriptor */
3283 : 0 : slen = m_seg->data_len;
3284 : : buf_dma_addr = rte_mbuf_data_iova(m_seg);
3285 : :
3286 [ # # ]: 0 : while ((ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)) &&
3287 [ # # ]: 0 : unlikely(slen > ICE_MAX_DATA_PER_TXD)) {
3288 : 0 : txd->buf_addr = rte_cpu_to_le_64(buf_dma_addr);
3289 : 0 : txd->cmd_type_offset_bsz =
3290 : 0 : rte_cpu_to_le_64(ICE_TX_DESC_DTYPE_DATA |
3291 : : ((uint64_t)td_cmd << ICE_TXD_QW1_CMD_S) |
3292 : : ((uint64_t)td_offset << ICE_TXD_QW1_OFFSET_S) |
3293 : : ((uint64_t)ICE_MAX_DATA_PER_TXD <<
3294 : : ICE_TXD_QW1_TX_BUF_SZ_S) |
3295 : : ((uint64_t)td_tag << ICE_TXD_QW1_L2TAG1_S));
3296 : :
3297 : 0 : buf_dma_addr += ICE_MAX_DATA_PER_TXD;
3298 : 0 : slen -= ICE_MAX_DATA_PER_TXD;
3299 : :
3300 : 0 : txe->last_id = tx_last;
3301 : 0 : tx_id = txe->next_id;
3302 : : txe = txn;
3303 : 0 : txd = &ice_tx_ring[tx_id];
3304 : 0 : txn = &sw_ring[txe->next_id];
3305 : : }
3306 : :
3307 : 0 : txd->buf_addr = rte_cpu_to_le_64(buf_dma_addr);
3308 : 0 : txd->cmd_type_offset_bsz =
3309 : 0 : rte_cpu_to_le_64(ICE_TX_DESC_DTYPE_DATA |
3310 : : ((uint64_t)td_cmd << ICE_TXD_QW1_CMD_S) |
3311 : : ((uint64_t)td_offset << ICE_TXD_QW1_OFFSET_S) |
3312 : : ((uint64_t)slen << ICE_TXD_QW1_TX_BUF_SZ_S) |
3313 : : ((uint64_t)td_tag << ICE_TXD_QW1_L2TAG1_S));
3314 : :
3315 : 0 : txe->last_id = tx_last;
3316 : 0 : tx_id = txe->next_id;
3317 : : txe = txn;
3318 : 0 : m_seg = m_seg->next;
3319 [ # # ]: 0 : } while (m_seg);
3320 : :
3321 : : /* fill the last descriptor with End of Packet (EOP) bit */
3322 : 0 : td_cmd |= ICE_TX_DESC_CMD_EOP;
3323 : 0 : txq->nb_tx_used = (uint16_t)(txq->nb_tx_used + nb_used);
3324 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_used);
3325 : :
3326 : : /* set RS bit on the last descriptor of one packet */
3327 [ # # ]: 0 : if (txq->nb_tx_used >= txq->tx_rs_thresh) {
3328 : : PMD_TX_LOG(DEBUG,
3329 : : "Setting RS bit on TXD id="
3330 : : "%4u (port=%d queue=%d)",
3331 : : tx_last, txq->port_id, txq->queue_id);
3332 : :
3333 : 0 : td_cmd |= ICE_TX_DESC_CMD_RS;
3334 : :
3335 : : /* Update txq RS bit counters */
3336 : 0 : txq->nb_tx_used = 0;
3337 : : }
3338 : 0 : txd->cmd_type_offset_bsz |=
3339 : 0 : rte_cpu_to_le_64(((uint64_t)td_cmd) <<
3340 : : ICE_TXD_QW1_CMD_S);
3341 : :
3342 [ # # # # ]: 0 : if (txq->tsq != NULL && txq->tsq->ts_flag > 0) {
3343 : 0 : uint64_t txtime = *RTE_MBUF_DYNFIELD(tx_pkt,
3344 : : txq->tsq->ts_offset, uint64_t *);
3345 : 0 : uint32_t tstamp = (uint32_t)(txtime % NS_PER_S) >>
3346 : : ICE_TXTIME_CTX_RESOLUTION_128NS;
3347 [ # # ]: 0 : const uint32_t desc_tx_id = (tx_id == 0) ? txq->nb_tx_desc : tx_id;
3348 : 0 : __le32 ts_desc = rte_cpu_to_le_32(FIELD_PREP(ICE_TXTIME_TX_DESC_IDX_M,
3349 : : desc_tx_id) | FIELD_PREP(ICE_TXTIME_STAMP_M, tstamp));
3350 : 0 : txq->tsq->ice_ts_ring[ts_id].tx_desc_idx_tstamp = ts_desc;
3351 : 0 : ts_id++;
3352 : : /* To prevent an MDD, when wrapping the tstamp
3353 : : * ring create additional TS descriptors equal
3354 : : * to the number of the fetch TS descriptors
3355 : : * value. HW will merge the TS descriptors with
3356 : : * the same timestamp value into a single
3357 : : * descriptor.
3358 : : */
3359 [ # # ]: 0 : if (ts_id == txq->tsq->nb_ts_desc) {
3360 : 0 : uint16_t fetch = txq->tsq->nb_ts_desc - txq->nb_tx_desc;
3361 : : ts_id = 0;
3362 [ # # ]: 0 : for (; ts_id < fetch; ts_id++)
3363 : 0 : txq->tsq->ice_ts_ring[ts_id].tx_desc_idx_tstamp = ts_desc;
3364 : : }
3365 : : }
3366 : : }
3367 : 0 : end_of_tx:
3368 : : /* update Tail register */
3369 [ # # # # ]: 0 : if (txq->tsq != NULL && txq->tsq->ts_flag > 0) {
3370 : 0 : ICE_PCI_REG_WRITE(txq->qtx_tail, ts_id);
3371 : 0 : txq->tsq->ts_tail = ts_id;
3372 : : } else {
3373 : 0 : ICE_PCI_REG_WRITE(txq->qtx_tail, tx_id);
3374 : : }
3375 : 0 : txq->tx_tail = tx_id;
3376 : :
3377 : 0 : return nb_tx;
3378 : : }
3379 : :
3380 : : static __rte_always_inline int
3381 : : ice_tx_free_bufs(struct ci_tx_queue *txq)
3382 : : {
3383 : : struct ci_tx_entry *txep;
3384 : : uint16_t i;
3385 : :
3386 [ # # # # ]: 0 : if ((txq->ice_tx_ring[txq->tx_next_dd].cmd_type_offset_bsz &
3387 : : rte_cpu_to_le_64(ICE_TXD_QW1_DTYPE_M)) !=
3388 : : rte_cpu_to_le_64(ICE_TX_DESC_DTYPE_DESC_DONE))
3389 : : return 0;
3390 : :
3391 : 0 : txep = &txq->sw_ring[txq->tx_next_dd - (txq->tx_rs_thresh - 1)];
3392 : :
3393 [ # # # # ]: 0 : for (i = 0; i < txq->tx_rs_thresh; i++)
3394 : 0 : rte_prefetch0((txep + i)->mbuf);
3395 : :
3396 [ # # # # ]: 0 : if (txq->offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) {
3397 [ # # # # ]: 0 : for (i = 0; i < txq->tx_rs_thresh; ++i, ++txep) {
3398 [ # # # # ]: 0 : rte_mempool_put(txep->mbuf->pool, txep->mbuf);
3399 : 0 : txep->mbuf = NULL;
3400 : : }
3401 : : } else {
3402 [ # # # # ]: 0 : for (i = 0; i < txq->tx_rs_thresh; ++i, ++txep) {
3403 : 0 : rte_pktmbuf_free_seg(txep->mbuf);
3404 : 0 : txep->mbuf = NULL;
3405 : : }
3406 : : }
3407 : :
3408 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_rs_thresh);
3409 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_rs_thresh);
3410 [ # # # # ]: 0 : if (txq->tx_next_dd >= txq->nb_tx_desc)
3411 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
3412 : :
3413 : 0 : return txq->tx_rs_thresh;
3414 : : }
3415 : :
3416 : : static int
3417 : 0 : ice_tx_done_cleanup_full(struct ci_tx_queue *txq,
3418 : : uint32_t free_cnt)
3419 : : {
3420 : 0 : struct ci_tx_entry *swr_ring = txq->sw_ring;
3421 : : uint16_t i, tx_last, tx_id;
3422 : : uint16_t nb_tx_free_last;
3423 : : uint16_t nb_tx_to_clean;
3424 : : uint32_t pkt_cnt;
3425 : :
3426 : : /* Start free mbuf from the next of tx_tail */
3427 : 0 : tx_last = txq->tx_tail;
3428 : 0 : tx_id = swr_ring[tx_last].next_id;
3429 : :
3430 [ # # # # ]: 0 : if (txq->nb_tx_free == 0 && ice_xmit_cleanup(txq))
3431 : : return 0;
3432 : :
3433 : 0 : nb_tx_to_clean = txq->nb_tx_free;
3434 : : nb_tx_free_last = txq->nb_tx_free;
3435 [ # # ]: 0 : if (!free_cnt)
3436 : 0 : free_cnt = txq->nb_tx_desc;
3437 : :
3438 : : /* Loop through swr_ring to count the amount of
3439 : : * freeable mubfs and packets.
3440 : : */
3441 [ # # ]: 0 : for (pkt_cnt = 0; pkt_cnt < free_cnt; ) {
3442 : 0 : for (i = 0; i < nb_tx_to_clean &&
3443 [ # # # # ]: 0 : pkt_cnt < free_cnt &&
3444 : 0 : tx_id != tx_last; i++) {
3445 [ # # ]: 0 : if (swr_ring[tx_id].mbuf != NULL) {
3446 : : rte_pktmbuf_free_seg(swr_ring[tx_id].mbuf);
3447 : 0 : swr_ring[tx_id].mbuf = NULL;
3448 : :
3449 : : /*
3450 : : * last segment in the packet,
3451 : : * increment packet count
3452 : : */
3453 : 0 : pkt_cnt += (swr_ring[tx_id].last_id == tx_id);
3454 : : }
3455 : :
3456 : 0 : tx_id = swr_ring[tx_id].next_id;
3457 : : }
3458 : :
3459 : 0 : if (txq->tx_rs_thresh > txq->nb_tx_desc -
3460 [ # # # # ]: 0 : txq->nb_tx_free || tx_id == tx_last)
3461 : : break;
3462 : :
3463 [ # # ]: 0 : if (pkt_cnt < free_cnt) {
3464 [ # # ]: 0 : if (ice_xmit_cleanup(txq))
3465 : : break;
3466 : :
3467 : 0 : nb_tx_to_clean = txq->nb_tx_free - nb_tx_free_last;
3468 : : nb_tx_free_last = txq->nb_tx_free;
3469 : : }
3470 : : }
3471 : :
3472 : 0 : return (int)pkt_cnt;
3473 : : }
3474 : :
3475 : : #ifdef RTE_ARCH_X86
3476 : : static int
3477 : : ice_tx_done_cleanup_vec(struct ci_tx_queue *txq __rte_unused,
3478 : : uint32_t free_cnt __rte_unused)
3479 : : {
3480 : : return -ENOTSUP;
3481 : : }
3482 : : #endif
3483 : :
3484 : : static int
3485 : 0 : ice_tx_done_cleanup_simple(struct ci_tx_queue *txq,
3486 : : uint32_t free_cnt)
3487 : : {
3488 : : int i, n, cnt;
3489 : :
3490 [ # # # # ]: 0 : if (free_cnt == 0 || free_cnt > txq->nb_tx_desc)
3491 : 0 : free_cnt = txq->nb_tx_desc;
3492 : :
3493 : 0 : cnt = free_cnt - free_cnt % txq->tx_rs_thresh;
3494 : :
3495 [ # # ]: 0 : for (i = 0; i < cnt; i += n) {
3496 [ # # ]: 0 : if (txq->nb_tx_desc - txq->nb_tx_free < txq->tx_rs_thresh)
3497 : : break;
3498 : :
3499 : : n = ice_tx_free_bufs(txq);
3500 : :
3501 [ # # ]: 0 : if (n == 0)
3502 : : break;
3503 : : }
3504 : :
3505 : 0 : return i;
3506 : : }
3507 : :
3508 : : int
3509 : 0 : ice_tx_done_cleanup(void *txq, uint32_t free_cnt)
3510 : : {
3511 : : struct ci_tx_queue *q = (struct ci_tx_queue *)txq;
3512 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[q->port_id];
3513 : 0 : struct ice_adapter *ad =
3514 : 0 : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3515 : :
3516 : : #ifdef RTE_ARCH_X86
3517 [ # # ]: 0 : if (ad->tx_vec_allowed)
3518 : : return ice_tx_done_cleanup_vec(q, free_cnt);
3519 : : #endif
3520 [ # # ]: 0 : if (ad->tx_simple_allowed)
3521 : 0 : return ice_tx_done_cleanup_simple(q, free_cnt);
3522 : : else
3523 : 0 : return ice_tx_done_cleanup_full(q, free_cnt);
3524 : : }
3525 : :
3526 : : /* Populate 4 descriptors with data from 4 mbufs */
3527 : : static inline void
3528 : : tx4(volatile struct ice_tx_desc *txdp, struct rte_mbuf **pkts)
3529 : : {
3530 : : uint64_t dma_addr;
3531 : : uint32_t i;
3532 : :
3533 [ # # ]: 0 : for (i = 0; i < 4; i++, txdp++, pkts++) {
3534 : 0 : dma_addr = rte_mbuf_data_iova(*pkts);
3535 : 0 : txdp->buf_addr = rte_cpu_to_le_64(dma_addr);
3536 : 0 : txdp->cmd_type_offset_bsz =
3537 : : ice_build_ctob((uint32_t)ICE_TD_CMD, 0,
3538 : 0 : (*pkts)->data_len, 0);
3539 : : }
3540 : : }
3541 : :
3542 : : /* Populate 1 descriptor with data from 1 mbuf */
3543 : : static inline void
3544 : : tx1(volatile struct ice_tx_desc *txdp, struct rte_mbuf **pkts)
3545 : : {
3546 : : uint64_t dma_addr;
3547 : :
3548 : : dma_addr = rte_mbuf_data_iova(*pkts);
3549 : 0 : txdp->buf_addr = rte_cpu_to_le_64(dma_addr);
3550 : 0 : txdp->cmd_type_offset_bsz =
3551 : : ice_build_ctob((uint32_t)ICE_TD_CMD, 0,
3552 : 0 : (*pkts)->data_len, 0);
3553 : : }
3554 : :
3555 : : static inline void
3556 : 0 : ice_tx_fill_hw_ring(struct ci_tx_queue *txq, struct rte_mbuf **pkts,
3557 : : uint16_t nb_pkts)
3558 : : {
3559 : 0 : volatile struct ice_tx_desc *txdp = &txq->ice_tx_ring[txq->tx_tail];
3560 : 0 : struct ci_tx_entry *txep = &txq->sw_ring[txq->tx_tail];
3561 : : const int N_PER_LOOP = 4;
3562 : : const int N_PER_LOOP_MASK = N_PER_LOOP - 1;
3563 : : int mainpart, leftover;
3564 : : int i, j;
3565 : :
3566 : : /**
3567 : : * Process most of the packets in chunks of N pkts. Any
3568 : : * leftover packets will get processed one at a time.
3569 : : */
3570 : 0 : mainpart = nb_pkts & ((uint32_t)~N_PER_LOOP_MASK);
3571 : 0 : leftover = nb_pkts & ((uint32_t)N_PER_LOOP_MASK);
3572 [ # # ]: 0 : for (i = 0; i < mainpart; i += N_PER_LOOP) {
3573 : : /* Copy N mbuf pointers to the S/W ring */
3574 [ # # ]: 0 : for (j = 0; j < N_PER_LOOP; ++j)
3575 : 0 : (txep + i + j)->mbuf = *(pkts + i + j);
3576 : 0 : tx4(txdp + i, pkts + i);
3577 : : }
3578 : :
3579 [ # # ]: 0 : if (unlikely(leftover > 0)) {
3580 [ # # ]: 0 : for (i = 0; i < leftover; ++i) {
3581 : 0 : (txep + mainpart + i)->mbuf = *(pkts + mainpart + i);
3582 : 0 : tx1(txdp + mainpart + i, pkts + mainpart + i);
3583 : : }
3584 : : }
3585 : 0 : }
3586 : :
3587 : : static inline uint16_t
3588 : 0 : tx_xmit_pkts(struct ci_tx_queue *txq,
3589 : : struct rte_mbuf **tx_pkts,
3590 : : uint16_t nb_pkts)
3591 : : {
3592 : 0 : volatile struct ice_tx_desc *txr = txq->ice_tx_ring;
3593 : : uint16_t n = 0;
3594 : :
3595 : : /**
3596 : : * Begin scanning the H/W ring for done descriptors when the number
3597 : : * of available descriptors drops below tx_free_thresh. For each done
3598 : : * descriptor, free the associated buffer.
3599 : : */
3600 [ # # ]: 0 : if (txq->nb_tx_free < txq->tx_free_thresh)
3601 : : ice_tx_free_bufs(txq);
3602 : :
3603 : : /* Use available descriptor only */
3604 : 0 : nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
3605 [ # # ]: 0 : if (unlikely(!nb_pkts))
3606 : : return 0;
3607 : :
3608 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
3609 [ # # ]: 0 : if ((txq->tx_tail + nb_pkts) > txq->nb_tx_desc) {
3610 : 0 : n = (uint16_t)(txq->nb_tx_desc - txq->tx_tail);
3611 : 0 : ice_tx_fill_hw_ring(txq, tx_pkts, n);
3612 : 0 : txr[txq->tx_next_rs].cmd_type_offset_bsz |=
3613 : : rte_cpu_to_le_64(((uint64_t)ICE_TX_DESC_CMD_RS) <<
3614 : : ICE_TXD_QW1_CMD_S);
3615 : 0 : txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
3616 : 0 : txq->tx_tail = 0;
3617 : : }
3618 : :
3619 : : /* Fill hardware descriptor ring with mbuf data */
3620 : 0 : ice_tx_fill_hw_ring(txq, tx_pkts + n, (uint16_t)(nb_pkts - n));
3621 : 0 : txq->tx_tail = (uint16_t)(txq->tx_tail + (nb_pkts - n));
3622 : :
3623 : : /* Determine if RS bit needs to be set */
3624 [ # # ]: 0 : if (txq->tx_tail > txq->tx_next_rs) {
3625 : 0 : txr[txq->tx_next_rs].cmd_type_offset_bsz |=
3626 : : rte_cpu_to_le_64(((uint64_t)ICE_TX_DESC_CMD_RS) <<
3627 : : ICE_TXD_QW1_CMD_S);
3628 : 0 : txq->tx_next_rs =
3629 : 0 : (uint16_t)(txq->tx_next_rs + txq->tx_rs_thresh);
3630 [ # # ]: 0 : if (txq->tx_next_rs >= txq->nb_tx_desc)
3631 : 0 : txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
3632 : : }
3633 : :
3634 [ # # ]: 0 : if (txq->tx_tail >= txq->nb_tx_desc)
3635 : 0 : txq->tx_tail = 0;
3636 : :
3637 : : /* Update the tx tail register */
3638 : 0 : ICE_PCI_REG_WC_WRITE(txq->qtx_tail, txq->tx_tail);
3639 : :
3640 : : return nb_pkts;
3641 : : }
3642 : :
3643 : : static uint16_t
3644 : 0 : ice_xmit_pkts_simple(void *tx_queue,
3645 : : struct rte_mbuf **tx_pkts,
3646 : : uint16_t nb_pkts)
3647 : : {
3648 : : uint16_t nb_tx = 0;
3649 : :
3650 [ # # ]: 0 : if (likely(nb_pkts <= ICE_TX_MAX_BURST))
3651 : 0 : return tx_xmit_pkts((struct ci_tx_queue *)tx_queue,
3652 : : tx_pkts, nb_pkts);
3653 : :
3654 [ # # ]: 0 : while (nb_pkts) {
3655 : 0 : uint16_t ret, num = (uint16_t)RTE_MIN(nb_pkts,
3656 : : ICE_TX_MAX_BURST);
3657 : :
3658 : 0 : ret = tx_xmit_pkts((struct ci_tx_queue *)tx_queue,
3659 : 0 : &tx_pkts[nb_tx], num);
3660 : 0 : nb_tx = (uint16_t)(nb_tx + ret);
3661 : 0 : nb_pkts = (uint16_t)(nb_pkts - ret);
3662 [ # # ]: 0 : if (ret < num)
3663 : : break;
3664 : : }
3665 : :
3666 : : return nb_tx;
3667 : : }
3668 : :
3669 : : static const struct ci_rx_path_info ice_rx_path_infos[] = {
3670 : : [ICE_RX_DEFAULT] = {ice_recv_pkts, "Scalar",
3671 : : {ICE_RX_SCALAR_OFFLOADS, RTE_VECT_SIMD_DISABLED}},
3672 : : [ICE_RX_SCATTERED] = {ice_recv_scattered_pkts, "Scalar Scattered",
3673 : : {ICE_RX_SCALAR_OFFLOADS, RTE_VECT_SIMD_DISABLED, {.scattered = true}}},
3674 : : [ICE_RX_BULK_ALLOC] = {ice_recv_pkts_bulk_alloc, "Scalar Bulk Alloc",
3675 : : {ICE_RX_SCALAR_OFFLOADS, RTE_VECT_SIMD_DISABLED, {.bulk_alloc = true}}},
3676 : : #ifdef RTE_ARCH_X86
3677 : : [ICE_RX_SSE] = {ice_recv_pkts_vec, "Vector SSE",
3678 : : {ICE_RX_VECTOR_OFFLOAD_OFFLOADS, RTE_VECT_SIMD_128, {.bulk_alloc = true}}},
3679 : : [ICE_RX_SSE_SCATTERED] = {ice_recv_scattered_pkts_vec, "Vector SSE Scattered",
3680 : : {ICE_RX_VECTOR_OFFLOAD_OFFLOADS, RTE_VECT_SIMD_128,
3681 : : {.scattered = true, .bulk_alloc = true}}},
3682 : : [ICE_RX_AVX2] = {ice_recv_pkts_vec_avx2, "Vector AVX2",
3683 : : {ICE_RX_VECTOR_OFFLOADS, RTE_VECT_SIMD_256, {.bulk_alloc = true}}},
3684 : : [ICE_RX_AVX2_SCATTERED] = {ice_recv_scattered_pkts_vec_avx2, "Vector AVX2 Scattered",
3685 : : {ICE_RX_VECTOR_OFFLOADS, RTE_VECT_SIMD_256,
3686 : : {.scattered = true, .bulk_alloc = true}}},
3687 : : [ICE_RX_AVX2_OFFLOAD] = {ice_recv_pkts_vec_avx2_offload, "Offload Vector AVX2",
3688 : : {ICE_RX_VECTOR_OFFLOAD_OFFLOADS, RTE_VECT_SIMD_256, {.bulk_alloc = true}}},
3689 : : [ICE_RX_AVX2_SCATTERED_OFFLOAD] = {
3690 : : ice_recv_scattered_pkts_vec_avx2_offload, "Offload Vector AVX2 Scattered",
3691 : : {ICE_RX_VECTOR_OFFLOAD_OFFLOADS, RTE_VECT_SIMD_256,
3692 : : {.scattered = true, .bulk_alloc = true}}},
3693 : : #ifdef CC_AVX512_SUPPORT
3694 : : [ICE_RX_AVX512] = {ice_recv_pkts_vec_avx512, "Vector AVX512",
3695 : : {ICE_RX_VECTOR_OFFLOADS, RTE_VECT_SIMD_512, {.bulk_alloc = true}}},
3696 : : [ICE_RX_AVX512_SCATTERED] = {ice_recv_scattered_pkts_vec_avx512, "Vector AVX512 Scattered",
3697 : : {ICE_RX_VECTOR_OFFLOADS, RTE_VECT_SIMD_512,
3698 : : {.scattered = true, .bulk_alloc = true}}},
3699 : : [ICE_RX_AVX512_OFFLOAD] = {ice_recv_pkts_vec_avx512_offload, "Offload Vector AVX512",
3700 : : {ICE_RX_VECTOR_OFFLOAD_OFFLOADS, RTE_VECT_SIMD_512, {.bulk_alloc = true}}},
3701 : : [ICE_RX_AVX512_SCATTERED_OFFLOAD] = {
3702 : : ice_recv_scattered_pkts_vec_avx512_offload, "Offload Vector AVX512 Scattered",
3703 : : {ICE_RX_VECTOR_OFFLOAD_OFFLOADS, RTE_VECT_SIMD_512,
3704 : : {.scattered = true, .bulk_alloc = true}}},
3705 : : #endif
3706 : : #endif
3707 : : };
3708 : :
3709 : : void __rte_cold
3710 : 0 : ice_set_rx_function(struct rte_eth_dev *dev)
3711 : : {
3712 : 0 : PMD_INIT_FUNC_TRACE();
3713 : 0 : struct ice_adapter *ad =
3714 : 0 : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3715 : : enum rte_vect_max_simd rx_simd_width = RTE_VECT_SIMD_DISABLED;
3716 : 0 : struct ci_rx_path_features req_features = {
3717 : 0 : .rx_offloads = dev->data->dev_conf.rxmode.offloads,
3718 : : .simd_width = RTE_VECT_SIMD_DISABLED,
3719 : : };
3720 : :
3721 : : /* The primary process selects the rx path for all processes. */
3722 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3723 : 0 : goto out;
3724 : :
3725 : : #ifdef RTE_ARCH_X86
3726 [ # # # # ]: 0 : if (ad->ptp_ena || !ad->rx_bulk_alloc_allowed) {
3727 : : rx_simd_width = RTE_VECT_SIMD_DISABLED;
3728 : : } else {
3729 : 0 : rx_simd_width = ice_get_max_simd_bitwidth();
3730 [ # # ]: 0 : if (rx_simd_width >= RTE_VECT_SIMD_128)
3731 [ # # ]: 0 : if (ice_rx_vec_dev_check(dev) == -1)
3732 : : rx_simd_width = RTE_VECT_SIMD_DISABLED;
3733 : : }
3734 : : #endif
3735 : :
3736 : 0 : req_features.simd_width = rx_simd_width;
3737 [ # # ]: 0 : if (dev->data->scattered_rx)
3738 : 0 : req_features.extra.scattered = true;
3739 [ # # ]: 0 : if (ad->rx_bulk_alloc_allowed)
3740 : 0 : req_features.extra.bulk_alloc = true;
3741 : :
3742 : 0 : ad->rx_func_type = ci_rx_path_select(req_features,
3743 : : &ice_rx_path_infos[0],
3744 : : RTE_DIM(ice_rx_path_infos),
3745 : : ICE_RX_DEFAULT);
3746 : : #ifdef RTE_ARCH_X86
3747 : : int i;
3748 : :
3749 [ # # ]: 0 : if (ice_rx_path_infos[ad->rx_func_type].features.simd_width >= RTE_VECT_SIMD_128)
3750 : : /* Vector function selected. Prepare the rxq accordingly. */
3751 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
3752 [ # # ]: 0 : if (dev->data->rx_queues[i])
3753 : 0 : ice_rxq_vec_setup(dev->data->rx_queues[i]);
3754 : : #endif
3755 : :
3756 : 0 : out:
3757 : 0 : dev->rx_pkt_burst = ice_rx_path_infos[ad->rx_func_type].pkt_burst;
3758 : 0 : PMD_DRV_LOG(NOTICE, "Using %s (port %d).",
3759 : : ice_rx_path_infos[ad->rx_func_type].info, dev->data->port_id);
3760 : 0 : }
3761 : :
3762 : : int
3763 : 0 : ice_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
3764 : : struct rte_eth_burst_mode *mode)
3765 : : {
3766 : 0 : eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
3767 : : int ret = -EINVAL;
3768 : : unsigned int i;
3769 : :
3770 [ # # ]: 0 : for (i = 0; i < RTE_DIM(ice_rx_path_infos); ++i) {
3771 [ # # ]: 0 : if (pkt_burst == ice_rx_path_infos[i].pkt_burst) {
3772 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
3773 : 0 : ice_rx_path_infos[i].info);
3774 : : ret = 0;
3775 : 0 : break;
3776 : : }
3777 : : }
3778 : :
3779 : 0 : return ret;
3780 : : }
3781 : :
3782 : : void __rte_cold
3783 : 0 : ice_set_tx_function_flag(struct rte_eth_dev *dev, struct ci_tx_queue *txq)
3784 : : {
3785 : 0 : struct ice_adapter *ad =
3786 : 0 : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3787 : :
3788 : : /* Use a simple Tx queue if possible (only fast free is allowed) */
3789 : 0 : ad->tx_simple_allowed =
3790 : 0 : (txq->offloads ==
3791 [ # # ]: 0 : (txq->offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) &&
3792 [ # # ]: 0 : txq->tx_rs_thresh >= ICE_TX_MAX_BURST);
3793 : :
3794 [ # # ]: 0 : if (ad->tx_simple_allowed)
3795 : 0 : PMD_INIT_LOG(DEBUG, "Simple Tx can be enabled on Tx queue %u.",
3796 : : txq->queue_id);
3797 : : else
3798 : 0 : PMD_INIT_LOG(DEBUG,
3799 : : "Simple Tx can NOT be enabled on Tx queue %u.",
3800 : : txq->queue_id);
3801 : 0 : }
3802 : :
3803 : : /*********************************************************************
3804 : : *
3805 : : * TX prep functions
3806 : : *
3807 : : **********************************************************************/
3808 : : /* The default values of TSO MSS */
3809 : : #define ICE_MIN_TSO_MSS 64
3810 : : #define ICE_MAX_TSO_MSS 9728
3811 : : #define ICE_MAX_TSO_FRAME_SIZE 262144
3812 : :
3813 : : /*Check for empty mbuf*/
3814 : : static inline uint16_t
3815 : : ice_check_empty_mbuf(struct rte_mbuf *tx_pkt)
3816 : : {
3817 : : struct rte_mbuf *txd = tx_pkt;
3818 : :
3819 [ # # ]: 0 : while (txd != NULL) {
3820 [ # # ]: 0 : if (txd->data_len == 0)
3821 : : return -1;
3822 : 0 : txd = txd->next;
3823 : : }
3824 : :
3825 : : return 0;
3826 : : }
3827 : :
3828 : : /* Tx mbuf check */
3829 : : static uint16_t
3830 : 0 : ice_xmit_pkts_check(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
3831 : : {
3832 : : struct ci_tx_queue *txq = tx_queue;
3833 : : uint16_t idx;
3834 : : struct rte_mbuf *mb;
3835 : : bool pkt_error = false;
3836 : : uint16_t good_pkts = nb_pkts;
3837 : 0 : const char *reason = NULL;
3838 : 0 : struct ice_adapter *adapter = txq->ice_vsi->adapter;
3839 : : uint64_t ol_flags;
3840 : :
3841 [ # # ]: 0 : for (idx = 0; idx < nb_pkts; idx++) {
3842 : 0 : mb = tx_pkts[idx];
3843 : 0 : ol_flags = mb->ol_flags;
3844 : :
3845 [ # # # # ]: 0 : if ((adapter->devargs.mbuf_check & ICE_MBUF_CHECK_F_TX_MBUF) &&
3846 : 0 : (rte_mbuf_check(mb, 1, &reason) != 0)) {
3847 : : PMD_TX_LOG(ERR, "INVALID mbuf: %s", reason);
3848 : : pkt_error = true;
3849 : : break;
3850 : : }
3851 : :
3852 [ # # ]: 0 : if ((adapter->devargs.mbuf_check & ICE_MBUF_CHECK_F_TX_SIZE) &&
3853 [ # # # # ]: 0 : (mb->data_len > mb->pkt_len ||
3854 [ # # ]: 0 : mb->data_len < ICE_TX_MIN_PKT_LEN ||
3855 : : mb->data_len > ICE_FRAME_SIZE_MAX)) {
3856 : : PMD_TX_LOG(ERR, "INVALID mbuf: data_len (%u) is out of range, reasonable range (%d - %d)",
3857 : : mb->data_len, ICE_TX_MIN_PKT_LEN, ICE_FRAME_SIZE_MAX);
3858 : : pkt_error = true;
3859 : : break;
3860 : : }
3861 : :
3862 [ # # ]: 0 : if (adapter->devargs.mbuf_check & ICE_MBUF_CHECK_F_TX_SEGMENT) {
3863 [ # # ]: 0 : if (!(ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
3864 : : /**
3865 : : * No TSO case: nb->segs, pkt_len to not exceed
3866 : : * the limites.
3867 : : */
3868 [ # # ]: 0 : if (mb->nb_segs > ICE_TX_MTU_SEG_MAX) {
3869 : : PMD_TX_LOG(ERR, "INVALID mbuf: nb_segs (%d) exceeds HW limit, maximum allowed value is %d",
3870 : : mb->nb_segs, ICE_TX_MTU_SEG_MAX);
3871 : : pkt_error = true;
3872 : : break;
3873 : : }
3874 [ # # ]: 0 : if (mb->pkt_len > ICE_FRAME_SIZE_MAX) {
3875 : : PMD_TX_LOG(ERR, "INVALID mbuf: pkt_len (%d) exceeds HW limit, maximum allowed value is %d",
3876 : : mb->nb_segs, ICE_FRAME_SIZE_MAX);
3877 : : pkt_error = true;
3878 : : break;
3879 : : }
3880 : : } else if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
3881 : : /** TSO case: tso_segsz, nb_segs, pkt_len not exceed
3882 : : * the limits.
3883 : : */
3884 [ # # ]: 0 : if (mb->tso_segsz < ICE_MIN_TSO_MSS ||
3885 : : mb->tso_segsz > ICE_MAX_TSO_MSS) {
3886 : : /**
3887 : : * MSS outside the range are considered malicious
3888 : : */
3889 : : PMD_TX_LOG(ERR, "INVALID mbuf: tso_segsz (%u) is out of range, reasonable range (%d - %u)",
3890 : : mb->tso_segsz, ICE_MIN_TSO_MSS, ICE_MAX_TSO_MSS);
3891 : : pkt_error = true;
3892 : : break;
3893 : : }
3894 [ # # ]: 0 : if (mb->nb_segs > ((struct ci_tx_queue *)tx_queue)->nb_tx_desc) {
3895 : : PMD_TX_LOG(ERR, "INVALID mbuf: nb_segs out of ring length");
3896 : : pkt_error = true;
3897 : : break;
3898 : : }
3899 : : }
3900 : : }
3901 : :
3902 [ # # ]: 0 : if (adapter->devargs.mbuf_check & ICE_MBUF_CHECK_F_TX_OFFLOAD) {
3903 [ # # ]: 0 : if (ol_flags & ICE_TX_OFFLOAD_NOTSUP_MASK) {
3904 : : PMD_TX_LOG(ERR, "INVALID mbuf: TX offload is not supported");
3905 : : pkt_error = true;
3906 : : break;
3907 : : }
3908 : :
3909 [ # # ]: 0 : if (!rte_validate_tx_offload(mb)) {
3910 : : PMD_TX_LOG(ERR, "INVALID mbuf: TX offload setup error");
3911 : : pkt_error = true;
3912 : : break;
3913 : : }
3914 : : }
3915 : : }
3916 : :
3917 [ # # ]: 0 : if (pkt_error) {
3918 : 0 : txq->mbuf_errors++;
3919 : : good_pkts = idx;
3920 [ # # ]: 0 : if (good_pkts == 0)
3921 : : return 0;
3922 : : }
3923 : :
3924 : 0 : return adapter->tx_pkt_burst(tx_queue, tx_pkts, good_pkts);
3925 : : }
3926 : :
3927 : : uint16_t
3928 : 0 : ice_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
3929 : : uint16_t nb_pkts)
3930 : : {
3931 : : int i, ret;
3932 : : uint64_t ol_flags;
3933 : : struct rte_mbuf *m;
3934 : :
3935 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
3936 : 0 : m = tx_pkts[i];
3937 : 0 : ol_flags = m->ol_flags;
3938 : :
3939 [ # # ]: 0 : if (!(ol_flags & RTE_MBUF_F_TX_TCP_SEG) &&
3940 : : /**
3941 : : * No TSO case: nb->segs, pkt_len to not exceed
3942 : : * the limites.
3943 : : */
3944 [ # # ]: 0 : (m->nb_segs > ICE_TX_MTU_SEG_MAX ||
3945 [ # # ]: 0 : m->pkt_len > ICE_FRAME_SIZE_MAX)) {
3946 : 0 : rte_errno = EINVAL;
3947 : 0 : return i;
3948 [ # # ]: 0 : } else if (ol_flags & RTE_MBUF_F_TX_TCP_SEG &&
3949 : : /** TSO case: tso_segsz, nb_segs, pkt_len not exceed
3950 : : * the limits.
3951 : : */
3952 [ # # ]: 0 : (m->tso_segsz < ICE_MIN_TSO_MSS ||
3953 : 0 : m->tso_segsz > ICE_MAX_TSO_MSS ||
3954 : 0 : m->nb_segs >
3955 [ # # ]: 0 : ((struct ci_tx_queue *)tx_queue)->nb_tx_desc ||
3956 [ # # ]: 0 : m->pkt_len > ICE_MAX_TSO_FRAME_SIZE)) {
3957 : : /**
3958 : : * MSS outside the range are considered malicious
3959 : : */
3960 : 0 : rte_errno = EINVAL;
3961 : 0 : return i;
3962 : : }
3963 : :
3964 [ # # ]: 0 : if (m->pkt_len < ICE_TX_MIN_PKT_LEN) {
3965 : 0 : rte_errno = EINVAL;
3966 : 0 : return i;
3967 : : }
3968 : :
3969 : : #ifdef RTE_ETHDEV_DEBUG_TX
3970 : : ret = rte_validate_tx_offload(m);
3971 : : if (ret != 0) {
3972 : : rte_errno = -ret;
3973 : : return i;
3974 : : }
3975 : : #endif
3976 : : ret = rte_net_intel_cksum_prepare(m);
3977 [ # # ]: 0 : if (ret != 0) {
3978 : 0 : rte_errno = -ret;
3979 : 0 : return i;
3980 : : }
3981 : :
3982 [ # # ]: 0 : if (ice_check_empty_mbuf(m) != 0) {
3983 : 0 : rte_errno = EINVAL;
3984 : 0 : return i;
3985 : : }
3986 : : }
3987 : 0 : return i;
3988 : : }
3989 : :
3990 : : void __rte_cold
3991 : 0 : ice_set_tx_function(struct rte_eth_dev *dev)
3992 : : {
3993 : 0 : struct ice_adapter *ad =
3994 : 0 : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3995 : 0 : int mbuf_check = ad->devargs.mbuf_check;
3996 : : #ifdef RTE_ARCH_X86
3997 : : struct ci_tx_queue *txq;
3998 : : int i;
3999 : : int tx_check_ret = -1;
4000 : :
4001 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
4002 : 0 : ad->tx_simd_width = RTE_VECT_SIMD_DISABLED;
4003 : 0 : tx_check_ret = ice_tx_vec_dev_check(dev);
4004 : 0 : ad->tx_simd_width = ice_get_max_simd_bitwidth();
4005 [ # # # # ]: 0 : if (tx_check_ret >= 0 &&
4006 : 0 : rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
4007 : 0 : ad->tx_vec_allowed = true;
4008 : :
4009 [ # # # # ]: 0 : if (ad->tx_simd_width < RTE_VECT_SIMD_256 &&
4010 : : tx_check_ret == ICE_VECTOR_OFFLOAD_PATH)
4011 : 0 : ad->tx_vec_allowed = false;
4012 : :
4013 [ # # ]: 0 : if (ad->tx_vec_allowed) {
4014 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
4015 : 0 : txq = dev->data->tx_queues[i];
4016 [ # # # # ]: 0 : if (txq && ice_txq_vec_setup(txq)) {
4017 : 0 : ad->tx_vec_allowed = false;
4018 : 0 : break;
4019 : : }
4020 : : }
4021 : : }
4022 : : } else {
4023 : 0 : ad->tx_vec_allowed = false;
4024 : : }
4025 : : }
4026 : :
4027 [ # # ]: 0 : if (ad->tx_vec_allowed) {
4028 : 0 : dev->tx_pkt_prepare = NULL;
4029 [ # # ]: 0 : if (ad->tx_simd_width == RTE_VECT_SIMD_512) {
4030 : : #ifdef CC_AVX512_SUPPORT
4031 [ # # ]: 0 : if (tx_check_ret == ICE_VECTOR_OFFLOAD_PATH) {
4032 : 0 : PMD_DRV_LOG(NOTICE,
4033 : : "Using AVX512 OFFLOAD Vector Tx (port %d).",
4034 : : dev->data->port_id);
4035 : 0 : dev->tx_pkt_burst =
4036 : : ice_xmit_pkts_vec_avx512_offload;
4037 : 0 : dev->tx_pkt_prepare = ice_prep_pkts;
4038 : : } else {
4039 : 0 : PMD_DRV_LOG(NOTICE,
4040 : : "Using AVX512 Vector Tx (port %d).",
4041 : : dev->data->port_id);
4042 : 0 : dev->tx_pkt_burst = ice_xmit_pkts_vec_avx512;
4043 : : }
4044 : : #endif
4045 : : } else {
4046 [ # # ]: 0 : if (tx_check_ret == ICE_VECTOR_OFFLOAD_PATH) {
4047 : 0 : PMD_DRV_LOG(NOTICE,
4048 : : "Using AVX2 OFFLOAD Vector Tx (port %d).",
4049 : : dev->data->port_id);
4050 : 0 : dev->tx_pkt_burst =
4051 : : ice_xmit_pkts_vec_avx2_offload;
4052 : 0 : dev->tx_pkt_prepare = ice_prep_pkts;
4053 : : } else {
4054 [ # # ]: 0 : PMD_DRV_LOG(DEBUG, "Using %sVector Tx (port %d).",
4055 : : ad->tx_simd_width == RTE_VECT_SIMD_256 ? "avx2 " : "",
4056 : : dev->data->port_id);
4057 : 0 : dev->tx_pkt_burst = ad->tx_simd_width == RTE_VECT_SIMD_256 ?
4058 [ # # ]: 0 : ice_xmit_pkts_vec_avx2 :
4059 : : ice_xmit_pkts_vec;
4060 : : }
4061 : : }
4062 : :
4063 [ # # ]: 0 : if (mbuf_check) {
4064 : 0 : ad->tx_pkt_burst = dev->tx_pkt_burst;
4065 : 0 : dev->tx_pkt_burst = ice_xmit_pkts_check;
4066 : : }
4067 : 0 : return;
4068 : : }
4069 : : #endif
4070 : :
4071 [ # # ]: 0 : if (ad->tx_simple_allowed) {
4072 : 0 : PMD_INIT_LOG(DEBUG, "Simple tx finally be used.");
4073 : 0 : dev->tx_pkt_burst = ice_xmit_pkts_simple;
4074 : 0 : dev->tx_pkt_prepare = NULL;
4075 : : } else {
4076 : 0 : PMD_INIT_LOG(DEBUG, "Normal tx finally be used.");
4077 : 0 : dev->tx_pkt_burst = ice_xmit_pkts;
4078 : 0 : dev->tx_pkt_prepare = ice_prep_pkts;
4079 : : }
4080 : :
4081 [ # # ]: 0 : if (mbuf_check) {
4082 : 0 : ad->tx_pkt_burst = dev->tx_pkt_burst;
4083 : 0 : dev->tx_pkt_burst = ice_xmit_pkts_check;
4084 : : }
4085 : : }
4086 : :
4087 : : static const struct {
4088 : : eth_tx_burst_t pkt_burst;
4089 : : const char *info;
4090 : : } ice_tx_burst_infos[] = {
4091 : : { ice_xmit_pkts_simple, "Scalar Simple" },
4092 : : { ice_xmit_pkts, "Scalar" },
4093 : : #ifdef RTE_ARCH_X86
4094 : : #ifdef CC_AVX512_SUPPORT
4095 : : { ice_xmit_pkts_vec_avx512, "Vector AVX512" },
4096 : : { ice_xmit_pkts_vec_avx512_offload, "Offload Vector AVX512" },
4097 : : #endif
4098 : : { ice_xmit_pkts_vec_avx2, "Vector AVX2" },
4099 : : { ice_xmit_pkts_vec_avx2_offload, "Offload Vector AVX2" },
4100 : : { ice_xmit_pkts_vec, "Vector SSE" },
4101 : : #endif
4102 : : };
4103 : :
4104 : : int
4105 : 0 : ice_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
4106 : : struct rte_eth_burst_mode *mode)
4107 : : {
4108 : 0 : eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
4109 : : int ret = -EINVAL;
4110 : : unsigned int i;
4111 : :
4112 [ # # ]: 0 : for (i = 0; i < RTE_DIM(ice_tx_burst_infos); ++i) {
4113 [ # # ]: 0 : if (pkt_burst == ice_tx_burst_infos[i].pkt_burst) {
4114 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
4115 : 0 : ice_tx_burst_infos[i].info);
4116 : : ret = 0;
4117 : 0 : break;
4118 : : }
4119 : : }
4120 : :
4121 : 0 : return ret;
4122 : : }
4123 : :
4124 : : /* For each value it means, datasheet of hardware can tell more details
4125 : : *
4126 : : * @note: fix ice_dev_supported_ptypes_get() if any change here.
4127 : : */
4128 : : static inline uint32_t
4129 : : ice_get_default_pkt_type(uint16_t ptype)
4130 : : {
4131 : : static const alignas(RTE_CACHE_LINE_SIZE) uint32_t type_table[ICE_MAX_PKT_TYPE] = {
4132 : : /* L2 types */
4133 : : /* [0] reserved */
4134 : : [1] = RTE_PTYPE_L2_ETHER,
4135 : : [2] = RTE_PTYPE_L2_ETHER_TIMESYNC,
4136 : : /* [3] - [5] reserved */
4137 : : [6] = RTE_PTYPE_L2_ETHER_LLDP,
4138 : : /* [7] - [10] reserved */
4139 : : [11] = RTE_PTYPE_L2_ETHER_ARP,
4140 : : /* [12] - [21] reserved */
4141 : :
4142 : : /* Non tunneled IPv4 */
4143 : : [22] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4144 : : RTE_PTYPE_L4_FRAG,
4145 : : [23] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4146 : : RTE_PTYPE_L4_NONFRAG,
4147 : : [24] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4148 : : RTE_PTYPE_L4_UDP,
4149 : : /* [25] reserved */
4150 : : [26] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4151 : : RTE_PTYPE_L4_TCP,
4152 : : [27] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4153 : : RTE_PTYPE_L4_SCTP,
4154 : : [28] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4155 : : RTE_PTYPE_L4_ICMP,
4156 : :
4157 : : /* IPv4 --> IPv4 */
4158 : : [29] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4159 : : RTE_PTYPE_TUNNEL_IP |
4160 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4161 : : RTE_PTYPE_INNER_L4_FRAG,
4162 : : [30] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4163 : : RTE_PTYPE_TUNNEL_IP |
4164 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4165 : : RTE_PTYPE_INNER_L4_NONFRAG,
4166 : : [31] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4167 : : RTE_PTYPE_TUNNEL_IP |
4168 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4169 : : RTE_PTYPE_INNER_L4_UDP,
4170 : : /* [32] reserved */
4171 : : [33] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4172 : : RTE_PTYPE_TUNNEL_IP |
4173 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4174 : : RTE_PTYPE_INNER_L4_TCP,
4175 : : [34] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4176 : : RTE_PTYPE_TUNNEL_IP |
4177 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4178 : : RTE_PTYPE_INNER_L4_SCTP,
4179 : : [35] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4180 : : RTE_PTYPE_TUNNEL_IP |
4181 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4182 : : RTE_PTYPE_INNER_L4_ICMP,
4183 : :
4184 : : /* IPv4 --> IPv6 */
4185 : : [36] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4186 : : RTE_PTYPE_TUNNEL_IP |
4187 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4188 : : RTE_PTYPE_INNER_L4_FRAG,
4189 : : [37] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4190 : : RTE_PTYPE_TUNNEL_IP |
4191 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4192 : : RTE_PTYPE_INNER_L4_NONFRAG,
4193 : : [38] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4194 : : RTE_PTYPE_TUNNEL_IP |
4195 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4196 : : RTE_PTYPE_INNER_L4_UDP,
4197 : : /* [39] reserved */
4198 : : [40] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4199 : : RTE_PTYPE_TUNNEL_IP |
4200 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4201 : : RTE_PTYPE_INNER_L4_TCP,
4202 : : [41] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4203 : : RTE_PTYPE_TUNNEL_IP |
4204 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4205 : : RTE_PTYPE_INNER_L4_SCTP,
4206 : : [42] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4207 : : RTE_PTYPE_TUNNEL_IP |
4208 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4209 : : RTE_PTYPE_INNER_L4_ICMP,
4210 : :
4211 : : /* IPv4 --> GRE/Teredo/VXLAN */
4212 : : [43] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4213 : : RTE_PTYPE_TUNNEL_GRENAT,
4214 : :
4215 : : /* IPv4 --> GRE/Teredo/VXLAN --> IPv4 */
4216 : : [44] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4217 : : RTE_PTYPE_TUNNEL_GRENAT |
4218 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4219 : : RTE_PTYPE_INNER_L4_FRAG,
4220 : : [45] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4221 : : RTE_PTYPE_TUNNEL_GRENAT |
4222 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4223 : : RTE_PTYPE_INNER_L4_NONFRAG,
4224 : : [46] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4225 : : RTE_PTYPE_TUNNEL_GRENAT |
4226 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4227 : : RTE_PTYPE_INNER_L4_UDP,
4228 : : /* [47] reserved */
4229 : : [48] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4230 : : RTE_PTYPE_TUNNEL_GRENAT |
4231 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4232 : : RTE_PTYPE_INNER_L4_TCP,
4233 : : [49] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4234 : : RTE_PTYPE_TUNNEL_GRENAT |
4235 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4236 : : RTE_PTYPE_INNER_L4_SCTP,
4237 : : [50] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4238 : : RTE_PTYPE_TUNNEL_GRENAT |
4239 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4240 : : RTE_PTYPE_INNER_L4_ICMP,
4241 : :
4242 : : /* IPv4 --> GRE/Teredo/VXLAN --> IPv6 */
4243 : : [51] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4244 : : RTE_PTYPE_TUNNEL_GRENAT |
4245 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4246 : : RTE_PTYPE_INNER_L4_FRAG,
4247 : : [52] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4248 : : RTE_PTYPE_TUNNEL_GRENAT |
4249 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4250 : : RTE_PTYPE_INNER_L4_NONFRAG,
4251 : : [53] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4252 : : RTE_PTYPE_TUNNEL_GRENAT |
4253 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4254 : : RTE_PTYPE_INNER_L4_UDP,
4255 : : /* [54] reserved */
4256 : : [55] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4257 : : RTE_PTYPE_TUNNEL_GRENAT |
4258 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4259 : : RTE_PTYPE_INNER_L4_TCP,
4260 : : [56] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4261 : : RTE_PTYPE_TUNNEL_GRENAT |
4262 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4263 : : RTE_PTYPE_INNER_L4_SCTP,
4264 : : [57] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4265 : : RTE_PTYPE_TUNNEL_GRENAT |
4266 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4267 : : RTE_PTYPE_INNER_L4_ICMP,
4268 : :
4269 : : /* IPv4 --> GRE/Teredo/VXLAN --> MAC */
4270 : : [58] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4271 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER,
4272 : :
4273 : : /* IPv4 --> GRE/Teredo/VXLAN --> MAC --> IPv4 */
4274 : : [59] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4275 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4276 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4277 : : RTE_PTYPE_INNER_L4_FRAG,
4278 : : [60] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4279 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4280 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4281 : : RTE_PTYPE_INNER_L4_NONFRAG,
4282 : : [61] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4283 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4284 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4285 : : RTE_PTYPE_INNER_L4_UDP,
4286 : : /* [62] reserved */
4287 : : [63] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4288 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4289 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4290 : : RTE_PTYPE_INNER_L4_TCP,
4291 : : [64] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4292 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4293 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4294 : : RTE_PTYPE_INNER_L4_SCTP,
4295 : : [65] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4296 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4297 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4298 : : RTE_PTYPE_INNER_L4_ICMP,
4299 : :
4300 : : /* IPv4 --> GRE/Teredo/VXLAN --> MAC --> IPv6 */
4301 : : [66] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4302 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4303 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4304 : : RTE_PTYPE_INNER_L4_FRAG,
4305 : : [67] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4306 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4307 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4308 : : RTE_PTYPE_INNER_L4_NONFRAG,
4309 : : [68] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4310 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4311 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4312 : : RTE_PTYPE_INNER_L4_UDP,
4313 : : /* [69] reserved */
4314 : : [70] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4315 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4316 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4317 : : RTE_PTYPE_INNER_L4_TCP,
4318 : : [71] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4319 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4320 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4321 : : RTE_PTYPE_INNER_L4_SCTP,
4322 : : [72] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4323 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4324 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4325 : : RTE_PTYPE_INNER_L4_ICMP,
4326 : : /* [73] - [87] reserved */
4327 : :
4328 : : /* Non tunneled IPv6 */
4329 : : [88] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4330 : : RTE_PTYPE_L4_FRAG,
4331 : : [89] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4332 : : RTE_PTYPE_L4_NONFRAG,
4333 : : [90] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4334 : : RTE_PTYPE_L4_UDP,
4335 : : /* [91] reserved */
4336 : : [92] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4337 : : RTE_PTYPE_L4_TCP,
4338 : : [93] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4339 : : RTE_PTYPE_L4_SCTP,
4340 : : [94] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4341 : : RTE_PTYPE_L4_ICMP,
4342 : :
4343 : : /* IPv6 --> IPv4 */
4344 : : [95] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4345 : : RTE_PTYPE_TUNNEL_IP |
4346 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4347 : : RTE_PTYPE_INNER_L4_FRAG,
4348 : : [96] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4349 : : RTE_PTYPE_TUNNEL_IP |
4350 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4351 : : RTE_PTYPE_INNER_L4_NONFRAG,
4352 : : [97] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4353 : : RTE_PTYPE_TUNNEL_IP |
4354 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4355 : : RTE_PTYPE_INNER_L4_UDP,
4356 : : /* [98] reserved */
4357 : : [99] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4358 : : RTE_PTYPE_TUNNEL_IP |
4359 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4360 : : RTE_PTYPE_INNER_L4_TCP,
4361 : : [100] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4362 : : RTE_PTYPE_TUNNEL_IP |
4363 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4364 : : RTE_PTYPE_INNER_L4_SCTP,
4365 : : [101] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4366 : : RTE_PTYPE_TUNNEL_IP |
4367 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4368 : : RTE_PTYPE_INNER_L4_ICMP,
4369 : :
4370 : : /* IPv6 --> IPv6 */
4371 : : [102] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4372 : : RTE_PTYPE_TUNNEL_IP |
4373 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4374 : : RTE_PTYPE_INNER_L4_FRAG,
4375 : : [103] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4376 : : RTE_PTYPE_TUNNEL_IP |
4377 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4378 : : RTE_PTYPE_INNER_L4_NONFRAG,
4379 : : [104] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4380 : : RTE_PTYPE_TUNNEL_IP |
4381 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4382 : : RTE_PTYPE_INNER_L4_UDP,
4383 : : /* [105] reserved */
4384 : : [106] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4385 : : RTE_PTYPE_TUNNEL_IP |
4386 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4387 : : RTE_PTYPE_INNER_L4_TCP,
4388 : : [107] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4389 : : RTE_PTYPE_TUNNEL_IP |
4390 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4391 : : RTE_PTYPE_INNER_L4_SCTP,
4392 : : [108] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4393 : : RTE_PTYPE_TUNNEL_IP |
4394 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4395 : : RTE_PTYPE_INNER_L4_ICMP,
4396 : :
4397 : : /* IPv6 --> GRE/Teredo/VXLAN */
4398 : : [109] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4399 : : RTE_PTYPE_TUNNEL_GRENAT,
4400 : :
4401 : : /* IPv6 --> GRE/Teredo/VXLAN --> IPv4 */
4402 : : [110] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4403 : : RTE_PTYPE_TUNNEL_GRENAT |
4404 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4405 : : RTE_PTYPE_INNER_L4_FRAG,
4406 : : [111] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4407 : : RTE_PTYPE_TUNNEL_GRENAT |
4408 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4409 : : RTE_PTYPE_INNER_L4_NONFRAG,
4410 : : [112] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4411 : : RTE_PTYPE_TUNNEL_GRENAT |
4412 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4413 : : RTE_PTYPE_INNER_L4_UDP,
4414 : : /* [113] reserved */
4415 : : [114] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4416 : : RTE_PTYPE_TUNNEL_GRENAT |
4417 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4418 : : RTE_PTYPE_INNER_L4_TCP,
4419 : : [115] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4420 : : RTE_PTYPE_TUNNEL_GRENAT |
4421 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4422 : : RTE_PTYPE_INNER_L4_SCTP,
4423 : : [116] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4424 : : RTE_PTYPE_TUNNEL_GRENAT |
4425 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4426 : : RTE_PTYPE_INNER_L4_ICMP,
4427 : :
4428 : : /* IPv6 --> GRE/Teredo/VXLAN --> IPv6 */
4429 : : [117] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4430 : : RTE_PTYPE_TUNNEL_GRENAT |
4431 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4432 : : RTE_PTYPE_INNER_L4_FRAG,
4433 : : [118] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4434 : : RTE_PTYPE_TUNNEL_GRENAT |
4435 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4436 : : RTE_PTYPE_INNER_L4_NONFRAG,
4437 : : [119] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4438 : : RTE_PTYPE_TUNNEL_GRENAT |
4439 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4440 : : RTE_PTYPE_INNER_L4_UDP,
4441 : : /* [120] reserved */
4442 : : [121] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4443 : : RTE_PTYPE_TUNNEL_GRENAT |
4444 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4445 : : RTE_PTYPE_INNER_L4_TCP,
4446 : : [122] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4447 : : RTE_PTYPE_TUNNEL_GRENAT |
4448 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4449 : : RTE_PTYPE_INNER_L4_SCTP,
4450 : : [123] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4451 : : RTE_PTYPE_TUNNEL_GRENAT |
4452 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4453 : : RTE_PTYPE_INNER_L4_ICMP,
4454 : :
4455 : : /* IPv6 --> GRE/Teredo/VXLAN --> MAC */
4456 : : [124] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4457 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER,
4458 : :
4459 : : /* IPv6 --> GRE/Teredo/VXLAN --> MAC --> IPv4 */
4460 : : [125] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4461 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4462 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4463 : : RTE_PTYPE_INNER_L4_FRAG,
4464 : : [126] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4465 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4466 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4467 : : RTE_PTYPE_INNER_L4_NONFRAG,
4468 : : [127] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4469 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4470 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4471 : : RTE_PTYPE_INNER_L4_UDP,
4472 : : /* [128] reserved */
4473 : : [129] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4474 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4475 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4476 : : RTE_PTYPE_INNER_L4_TCP,
4477 : : [130] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4478 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4479 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4480 : : RTE_PTYPE_INNER_L4_SCTP,
4481 : : [131] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4482 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4483 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4484 : : RTE_PTYPE_INNER_L4_ICMP,
4485 : :
4486 : : /* IPv6 --> GRE/Teredo/VXLAN --> MAC --> IPv6 */
4487 : : [132] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4488 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4489 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4490 : : RTE_PTYPE_INNER_L4_FRAG,
4491 : : [133] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4492 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4493 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4494 : : RTE_PTYPE_INNER_L4_NONFRAG,
4495 : : [134] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4496 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4497 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4498 : : RTE_PTYPE_INNER_L4_UDP,
4499 : : /* [135] reserved */
4500 : : [136] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4501 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4502 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4503 : : RTE_PTYPE_INNER_L4_TCP,
4504 : : [137] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4505 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4506 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4507 : : RTE_PTYPE_INNER_L4_SCTP,
4508 : : [138] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4509 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
4510 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4511 : : RTE_PTYPE_INNER_L4_ICMP,
4512 : : /* [139] - [299] reserved */
4513 : :
4514 : : /* PPPoE */
4515 : : [300] = RTE_PTYPE_L2_ETHER_PPPOE,
4516 : : [301] = RTE_PTYPE_L2_ETHER_PPPOE,
4517 : :
4518 : : /* PPPoE --> IPv4 */
4519 : : [302] = RTE_PTYPE_L2_ETHER_PPPOE |
4520 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4521 : : RTE_PTYPE_L4_FRAG,
4522 : : [303] = RTE_PTYPE_L2_ETHER_PPPOE |
4523 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4524 : : RTE_PTYPE_L4_NONFRAG,
4525 : : [304] = RTE_PTYPE_L2_ETHER_PPPOE |
4526 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4527 : : RTE_PTYPE_L4_UDP,
4528 : : [305] = RTE_PTYPE_L2_ETHER_PPPOE |
4529 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4530 : : RTE_PTYPE_L4_TCP,
4531 : : [306] = RTE_PTYPE_L2_ETHER_PPPOE |
4532 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4533 : : RTE_PTYPE_L4_SCTP,
4534 : : [307] = RTE_PTYPE_L2_ETHER_PPPOE |
4535 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4536 : : RTE_PTYPE_L4_ICMP,
4537 : :
4538 : : /* PPPoE --> IPv6 */
4539 : : [308] = RTE_PTYPE_L2_ETHER_PPPOE |
4540 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4541 : : RTE_PTYPE_L4_FRAG,
4542 : : [309] = RTE_PTYPE_L2_ETHER_PPPOE |
4543 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4544 : : RTE_PTYPE_L4_NONFRAG,
4545 : : [310] = RTE_PTYPE_L2_ETHER_PPPOE |
4546 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4547 : : RTE_PTYPE_L4_UDP,
4548 : : [311] = RTE_PTYPE_L2_ETHER_PPPOE |
4549 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4550 : : RTE_PTYPE_L4_TCP,
4551 : : [312] = RTE_PTYPE_L2_ETHER_PPPOE |
4552 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4553 : : RTE_PTYPE_L4_SCTP,
4554 : : [313] = RTE_PTYPE_L2_ETHER_PPPOE |
4555 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4556 : : RTE_PTYPE_L4_ICMP,
4557 : : /* [314] - [324] reserved */
4558 : :
4559 : : /* IPv4/IPv6 --> GTPC/GTPU */
4560 : : [325] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4561 : : RTE_PTYPE_TUNNEL_GTPC,
4562 : : [326] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4563 : : RTE_PTYPE_TUNNEL_GTPC,
4564 : : [327] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4565 : : RTE_PTYPE_TUNNEL_GTPC,
4566 : : [328] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4567 : : RTE_PTYPE_TUNNEL_GTPC,
4568 : : [329] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4569 : : RTE_PTYPE_TUNNEL_GTPU,
4570 : : [330] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4571 : : RTE_PTYPE_TUNNEL_GTPU,
4572 : :
4573 : : /* IPv4 --> GTPU --> IPv4 */
4574 : : [331] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4575 : : RTE_PTYPE_TUNNEL_GTPU |
4576 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4577 : : RTE_PTYPE_INNER_L4_FRAG,
4578 : : [332] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4579 : : RTE_PTYPE_TUNNEL_GTPU |
4580 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4581 : : RTE_PTYPE_INNER_L4_NONFRAG,
4582 : : [333] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4583 : : RTE_PTYPE_TUNNEL_GTPU |
4584 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4585 : : RTE_PTYPE_INNER_L4_UDP,
4586 : : [334] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4587 : : RTE_PTYPE_TUNNEL_GTPU |
4588 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4589 : : RTE_PTYPE_INNER_L4_TCP,
4590 : : [335] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4591 : : RTE_PTYPE_TUNNEL_GTPU |
4592 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4593 : : RTE_PTYPE_INNER_L4_ICMP,
4594 : :
4595 : : /* IPv6 --> GTPU --> IPv4 */
4596 : : [336] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4597 : : RTE_PTYPE_TUNNEL_GTPU |
4598 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4599 : : RTE_PTYPE_INNER_L4_FRAG,
4600 : : [337] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4601 : : RTE_PTYPE_TUNNEL_GTPU |
4602 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4603 : : RTE_PTYPE_INNER_L4_NONFRAG,
4604 : : [338] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4605 : : RTE_PTYPE_TUNNEL_GTPU |
4606 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4607 : : RTE_PTYPE_INNER_L4_UDP,
4608 : : [339] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4609 : : RTE_PTYPE_TUNNEL_GTPU |
4610 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4611 : : RTE_PTYPE_INNER_L4_TCP,
4612 : : [340] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4613 : : RTE_PTYPE_TUNNEL_GTPU |
4614 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
4615 : : RTE_PTYPE_INNER_L4_ICMP,
4616 : :
4617 : : /* IPv4 --> GTPU --> IPv6 */
4618 : : [341] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4619 : : RTE_PTYPE_TUNNEL_GTPU |
4620 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4621 : : RTE_PTYPE_INNER_L4_FRAG,
4622 : : [342] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4623 : : RTE_PTYPE_TUNNEL_GTPU |
4624 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4625 : : RTE_PTYPE_INNER_L4_NONFRAG,
4626 : : [343] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4627 : : RTE_PTYPE_TUNNEL_GTPU |
4628 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4629 : : RTE_PTYPE_INNER_L4_UDP,
4630 : : [344] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4631 : : RTE_PTYPE_TUNNEL_GTPU |
4632 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4633 : : RTE_PTYPE_INNER_L4_TCP,
4634 : : [345] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4635 : : RTE_PTYPE_TUNNEL_GTPU |
4636 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4637 : : RTE_PTYPE_INNER_L4_ICMP,
4638 : :
4639 : : /* IPv6 --> GTPU --> IPv6 */
4640 : : [346] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4641 : : RTE_PTYPE_TUNNEL_GTPU |
4642 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4643 : : RTE_PTYPE_INNER_L4_FRAG,
4644 : : [347] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4645 : : RTE_PTYPE_TUNNEL_GTPU |
4646 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4647 : : RTE_PTYPE_INNER_L4_NONFRAG,
4648 : : [348] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4649 : : RTE_PTYPE_TUNNEL_GTPU |
4650 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4651 : : RTE_PTYPE_INNER_L4_UDP,
4652 : : [349] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4653 : : RTE_PTYPE_TUNNEL_GTPU |
4654 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4655 : : RTE_PTYPE_INNER_L4_TCP,
4656 : : [350] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4657 : : RTE_PTYPE_TUNNEL_GTPU |
4658 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
4659 : : RTE_PTYPE_INNER_L4_ICMP,
4660 : :
4661 : : /* IPv4 --> UDP ECPRI */
4662 : : [372] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4663 : : RTE_PTYPE_L4_UDP,
4664 : : [373] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4665 : : RTE_PTYPE_L4_UDP,
4666 : : [374] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4667 : : RTE_PTYPE_L4_UDP,
4668 : : [375] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4669 : : RTE_PTYPE_L4_UDP,
4670 : : [376] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4671 : : RTE_PTYPE_L4_UDP,
4672 : : [377] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4673 : : RTE_PTYPE_L4_UDP,
4674 : : [378] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4675 : : RTE_PTYPE_L4_UDP,
4676 : : [379] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4677 : : RTE_PTYPE_L4_UDP,
4678 : : [380] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4679 : : RTE_PTYPE_L4_UDP,
4680 : : [381] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
4681 : : RTE_PTYPE_L4_UDP,
4682 : :
4683 : : /* IPV6 --> UDP ECPRI */
4684 : : [382] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4685 : : RTE_PTYPE_L4_UDP,
4686 : : [383] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4687 : : RTE_PTYPE_L4_UDP,
4688 : : [384] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4689 : : RTE_PTYPE_L4_UDP,
4690 : : [385] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4691 : : RTE_PTYPE_L4_UDP,
4692 : : [386] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4693 : : RTE_PTYPE_L4_UDP,
4694 : : [387] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4695 : : RTE_PTYPE_L4_UDP,
4696 : : [388] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4697 : : RTE_PTYPE_L4_UDP,
4698 : : [389] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4699 : : RTE_PTYPE_L4_UDP,
4700 : : [390] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4701 : : RTE_PTYPE_L4_UDP,
4702 : : [391] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
4703 : : RTE_PTYPE_L4_UDP,
4704 : : /* All others reserved */
4705 : : };
4706 : :
4707 : 0 : return type_table[ptype];
4708 : : }
4709 : :
4710 : : void __rte_cold
4711 : 0 : ice_set_default_ptype_table(struct rte_eth_dev *dev)
4712 : : {
4713 : 0 : struct ice_adapter *ad =
4714 : 0 : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
4715 : : int i;
4716 : :
4717 [ # # ]: 0 : for (i = 0; i < ICE_MAX_PKT_TYPE; i++)
4718 : 0 : ad->ptype_tbl[i] = ice_get_default_pkt_type(i);
4719 : 0 : }
4720 : :
4721 : : #define ICE_RX_PROG_STATUS_DESC_WB_QW1_PROGID_S 1
4722 : : #define ICE_RX_PROG_STATUS_DESC_WB_QW1_PROGID_M \
4723 : : (0x3UL << ICE_RX_PROG_STATUS_DESC_WB_QW1_PROGID_S)
4724 : : #define ICE_RX_PROG_STATUS_DESC_WB_QW1_PROG_ADD 0
4725 : : #define ICE_RX_PROG_STATUS_DESC_WB_QW1_PROG_DEL 0x1
4726 : :
4727 : : #define ICE_RX_PROG_STATUS_DESC_WB_QW1_FAIL_S 4
4728 : : #define ICE_RX_PROG_STATUS_DESC_WB_QW1_FAIL_M \
4729 : : (1 << ICE_RX_PROG_STATUS_DESC_WB_QW1_FAIL_S)
4730 : : #define ICE_RX_PROG_STATUS_DESC_WB_QW1_FAIL_PROF_S 5
4731 : : #define ICE_RX_PROG_STATUS_DESC_WB_QW1_FAIL_PROF_M \
4732 : : (1 << ICE_RX_PROG_STATUS_DESC_WB_QW1_FAIL_PROF_S)
4733 : :
4734 : : /*
4735 : : * check the programming status descriptor in rx queue.
4736 : : * done after Programming Flow Director is programmed on
4737 : : * tx queue
4738 : : */
4739 : : static inline int
4740 : 0 : ice_check_fdir_programming_status(struct ci_rx_queue *rxq)
4741 : : {
4742 : : volatile union ice_32byte_rx_desc *rxdp;
4743 : : uint64_t qword1;
4744 : : uint32_t rx_status;
4745 : : uint32_t error;
4746 : : uint32_t id;
4747 : : int ret = -EAGAIN;
4748 : :
4749 : 0 : rxdp = (volatile union ice_32byte_rx_desc *)&rxq->rx_flex_ring[rxq->rx_tail];
4750 : 0 : qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
4751 : : rx_status = (qword1 & ICE_RXD_QW1_STATUS_M)
4752 : 0 : >> ICE_RXD_QW1_STATUS_S;
4753 : :
4754 [ # # ]: 0 : if (rx_status & (1 << ICE_RX_DESC_STATUS_DD_S)) {
4755 : : ret = 0;
4756 : 0 : error = (qword1 & ICE_RX_PROG_STATUS_DESC_WB_QW1_FAIL_M) >>
4757 : : ICE_RX_PROG_STATUS_DESC_WB_QW1_FAIL_S;
4758 : 0 : id = (qword1 & ICE_RX_PROG_STATUS_DESC_WB_QW1_PROGID_M) >>
4759 : : ICE_RX_PROG_STATUS_DESC_WB_QW1_PROGID_S;
4760 [ # # ]: 0 : if (error) {
4761 [ # # ]: 0 : if (id == ICE_RX_PROG_STATUS_DESC_WB_QW1_PROG_ADD)
4762 : 0 : PMD_DRV_LOG(ERR, "Failed to add FDIR rule.");
4763 [ # # ]: 0 : else if (id == ICE_RX_PROG_STATUS_DESC_WB_QW1_PROG_DEL)
4764 : 0 : PMD_DRV_LOG(ERR, "Failed to remove FDIR rule.");
4765 : : ret = -EINVAL;
4766 : 0 : goto err;
4767 : : }
4768 : 0 : error = (qword1 & ICE_RX_PROG_STATUS_DESC_WB_QW1_FAIL_PROF_M) >>
4769 : : ICE_RX_PROG_STATUS_DESC_WB_QW1_FAIL_PROF_S;
4770 [ # # ]: 0 : if (error) {
4771 : 0 : PMD_DRV_LOG(ERR, "Failed to create FDIR profile.");
4772 : : ret = -EINVAL;
4773 : : }
4774 : 0 : err:
4775 : 0 : rxdp->wb.qword1.status_error_len = 0;
4776 : 0 : rxq->rx_tail++;
4777 [ # # ]: 0 : if (unlikely(rxq->rx_tail == rxq->nb_rx_desc))
4778 : 0 : rxq->rx_tail = 0;
4779 [ # # ]: 0 : if (rxq->rx_tail == 0)
4780 : 0 : ICE_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
4781 : : else
4782 : 0 : ICE_PCI_REG_WRITE(rxq->qrx_tail, rxq->rx_tail - 1);
4783 : : }
4784 : :
4785 : 0 : return ret;
4786 : : }
4787 : :
4788 : : #define ICE_FDIR_MAX_WAIT_US 10000
4789 : :
4790 : : int
4791 : 0 : ice_fdir_programming(struct ice_pf *pf, struct ice_fltr_desc *fdir_desc)
4792 : : {
4793 : 0 : struct ci_tx_queue *txq = pf->fdir.txq;
4794 : 0 : struct ci_rx_queue *rxq = pf->fdir.rxq;
4795 : : volatile struct ice_fltr_desc *fdirdp;
4796 : : volatile struct ice_tx_desc *txdp;
4797 : : uint32_t td_cmd;
4798 : : uint16_t i;
4799 : :
4800 : 0 : fdirdp = (volatile struct ice_fltr_desc *)
4801 : 0 : (&txq->ice_tx_ring[txq->tx_tail]);
4802 : 0 : fdirdp->qidx_compq_space_stat = fdir_desc->qidx_compq_space_stat;
4803 : 0 : fdirdp->dtype_cmd_vsi_fdid = fdir_desc->dtype_cmd_vsi_fdid;
4804 : :
4805 : 0 : txdp = &txq->ice_tx_ring[txq->tx_tail + 1];
4806 : 0 : txdp->buf_addr = rte_cpu_to_le_64(pf->fdir.dma_addr);
4807 : : td_cmd = ICE_TX_DESC_CMD_EOP |
4808 : : ICE_TX_DESC_CMD_RS |
4809 : : ICE_TX_DESC_CMD_DUMMY;
4810 : :
4811 : 0 : txdp->cmd_type_offset_bsz =
4812 : : ice_build_ctob(td_cmd, 0, ICE_FDIR_PKT_LEN, 0);
4813 : :
4814 : 0 : txq->tx_tail += 2;
4815 [ # # ]: 0 : if (txq->tx_tail >= txq->nb_tx_desc)
4816 : 0 : txq->tx_tail = 0;
4817 : : /* Update the tx tail register */
4818 : 0 : ICE_PCI_REG_WRITE(txq->qtx_tail, txq->tx_tail);
4819 [ # # ]: 0 : for (i = 0; i < ICE_FDIR_MAX_WAIT_US; i++) {
4820 [ # # ]: 0 : if ((txdp->cmd_type_offset_bsz &
4821 : : rte_cpu_to_le_64(ICE_TXD_QW1_DTYPE_M)) ==
4822 : : rte_cpu_to_le_64(ICE_TX_DESC_DTYPE_DESC_DONE))
4823 : : break;
4824 : 0 : rte_delay_us(1);
4825 : : }
4826 [ # # ]: 0 : if (i >= ICE_FDIR_MAX_WAIT_US) {
4827 : 0 : PMD_DRV_LOG(ERR,
4828 : : "Failed to program FDIR filter: time out to get DD on tx queue.");
4829 : 0 : return -ETIMEDOUT;
4830 : : }
4831 : :
4832 [ # # ]: 0 : for (; i < ICE_FDIR_MAX_WAIT_US; i++) {
4833 : : int ret;
4834 : :
4835 : 0 : ret = ice_check_fdir_programming_status(rxq);
4836 [ # # ]: 0 : if (ret == -EAGAIN)
4837 : 0 : rte_delay_us(1);
4838 : : else
4839 : 0 : return ret;
4840 : : }
4841 : :
4842 : 0 : PMD_DRV_LOG(ERR,
4843 : : "Failed to program FDIR filter: programming status reported.");
4844 : 0 : return -ETIMEDOUT;
4845 : :
4846 : :
4847 : : }
|