Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.
3 : : * Copyright(c) 2010-2017 Intel Corporation
4 : : */
5 : :
6 : : #include <sys/queue.h>
7 : :
8 : : #include <stdint.h>
9 : : #include <rte_ethdev.h>
10 : : #include <ethdev_driver.h>
11 : : #include <rte_malloc.h>
12 : : #include <rte_net.h>
13 : : #include <rte_vect.h>
14 : :
15 : : #include "ngbe_logs.h"
16 : : #include "base/ngbe.h"
17 : : #include "ngbe_ethdev.h"
18 : : #include "ngbe_rxtx.h"
19 : :
20 : : #ifdef RTE_LIBRTE_IEEE1588
21 : : #define NGBE_TX_IEEE1588_TMST RTE_MBUF_F_TX_IEEE1588_TMST
22 : : #else
23 : : #define NGBE_TX_IEEE1588_TMST 0
24 : : #endif
25 : :
26 : : /* Bit Mask to indicate what bits required for building Tx context */
27 : : static const u64 NGBE_TX_OFFLOAD_MASK = (RTE_MBUF_F_TX_IP_CKSUM |
28 : : RTE_MBUF_F_TX_IPV6 |
29 : : RTE_MBUF_F_TX_IPV4 |
30 : : RTE_MBUF_F_TX_VLAN |
31 : : RTE_MBUF_F_TX_L4_MASK |
32 : : RTE_MBUF_F_TX_TCP_SEG |
33 : : RTE_MBUF_F_TX_UDP_SEG |
34 : : NGBE_TX_IEEE1588_TMST);
35 : :
36 : : #define NGBE_TX_OFFLOAD_NOTSUP_MASK \
37 : : (RTE_MBUF_F_TX_OFFLOAD_MASK ^ NGBE_TX_OFFLOAD_MASK)
38 : :
39 : : /*
40 : : * Prefetch a cache line into all cache levels.
41 : : */
42 : : #define rte_ngbe_prefetch(p) rte_prefetch0(p)
43 : :
44 : : /*********************************************************************
45 : : *
46 : : * Tx functions
47 : : *
48 : : **********************************************************************/
49 : :
50 : : /*
51 : : * Check for descriptors with their DD bit set and free mbufs.
52 : : * Return the total number of buffers freed.
53 : : */
54 : : static __rte_always_inline int
55 : : ngbe_tx_free_bufs(struct ngbe_tx_queue *txq)
56 : : {
57 : : struct ngbe_tx_entry *txep;
58 : : uint32_t status;
59 : : int i, nb_free = 0;
60 : : struct rte_mbuf *m, *free[RTE_NGBE_TX_MAX_FREE_BUF_SZ];
61 : :
62 : : /* check DD bit on threshold descriptor */
63 : 0 : status = txq->tx_ring[txq->tx_next_dd].dw3;
64 [ # # # # ]: 0 : if (!(status & rte_cpu_to_le_32(NGBE_TXD_DD))) {
65 [ # # # # ]: 0 : if (txq->nb_tx_free >> 1 < txq->tx_free_thresh)
66 : 0 : ngbe_set32_masked(txq->tdc_reg_addr,
67 : : NGBE_TXCFG_FLUSH, NGBE_TXCFG_FLUSH);
68 : : return 0;
69 : : }
70 : :
71 : : /*
72 : : * first buffer to free from S/W ring is at index
73 : : * tx_next_dd - (tx_free_thresh-1)
74 : : */
75 : 0 : txep = &txq->sw_ring[txq->tx_next_dd - (txq->tx_free_thresh - 1)];
76 [ # # # # ]: 0 : for (i = 0; i < txq->tx_free_thresh; ++i, ++txep) {
77 : : /* free buffers one at a time */
78 : 0 : m = rte_pktmbuf_prefree_seg(txep->mbuf);
79 : 0 : txep->mbuf = NULL;
80 : :
81 [ # # # # ]: 0 : if (unlikely(m == NULL))
82 : 0 : continue;
83 : :
84 [ # # # # : 0 : if (nb_free >= RTE_NGBE_TX_MAX_FREE_BUF_SZ ||
# # # # ]
85 [ # # # # ]: 0 : (nb_free > 0 && m->pool != free[0]->pool)) {
86 [ # # # # ]: 0 : rte_mempool_put_bulk(free[0]->pool,
87 : : (void **)free, nb_free);
88 : : nb_free = 0;
89 : : }
90 : :
91 : 0 : free[nb_free++] = m;
92 : : }
93 : :
94 [ # # # # ]: 0 : if (nb_free > 0)
95 [ # # # # ]: 0 : rte_mempool_put_bulk(free[0]->pool, (void **)free, nb_free);
96 : :
97 : : /* buffers were freed, update counters */
98 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_free_thresh);
99 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_free_thresh);
100 [ # # # # ]: 0 : if (txq->tx_next_dd >= txq->nb_tx_desc)
101 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_free_thresh - 1);
102 : :
103 : 0 : return txq->tx_free_thresh;
104 : : }
105 : :
106 : : /* Populate 4 descriptors with data from 4 mbufs */
107 : : static inline void
108 : 0 : tx4(volatile struct ngbe_tx_desc *txdp, struct rte_mbuf **pkts)
109 : : {
110 : : uint64_t buf_dma_addr;
111 : : uint32_t pkt_len;
112 : : int i;
113 : :
114 [ # # ]: 0 : for (i = 0; i < 4; ++i, ++txdp, ++pkts) {
115 [ # # ]: 0 : buf_dma_addr = rte_mbuf_data_iova(*pkts);
116 : 0 : pkt_len = (*pkts)->data_len;
117 [ # # ]: 0 : if (pkt_len < RTE_ETHER_HDR_LEN)
118 : : pkt_len = NGBE_FRAME_SIZE_DFT;
119 : :
120 : : /* write data to descriptor */
121 : 0 : txdp->qw0 = rte_cpu_to_le_64(buf_dma_addr);
122 : 0 : txdp->dw2 = cpu_to_le32(NGBE_TXD_FLAGS |
123 : : NGBE_TXD_DATLEN(pkt_len));
124 : 0 : txdp->dw3 = cpu_to_le32(NGBE_TXD_PAYLEN(pkt_len));
125 : :
126 : 0 : rte_prefetch0(&(*pkts)->pool);
127 : : }
128 : 0 : }
129 : :
130 : : /* Populate 1 descriptor with data from 1 mbuf */
131 : : static inline void
132 : : tx1(volatile struct ngbe_tx_desc *txdp, struct rte_mbuf **pkts)
133 : : {
134 : : uint64_t buf_dma_addr;
135 : : uint32_t pkt_len;
136 : :
137 : : buf_dma_addr = rte_mbuf_data_iova(*pkts);
138 : 0 : pkt_len = (*pkts)->data_len;
139 [ # # ]: 0 : if (pkt_len < RTE_ETHER_HDR_LEN)
140 : : pkt_len = NGBE_FRAME_SIZE_DFT;
141 : :
142 : : /* write data to descriptor */
143 : 0 : txdp->qw0 = cpu_to_le64(buf_dma_addr);
144 : 0 : txdp->dw2 = cpu_to_le32(NGBE_TXD_FLAGS |
145 : : NGBE_TXD_DATLEN(pkt_len));
146 : 0 : txdp->dw3 = cpu_to_le32(NGBE_TXD_PAYLEN(pkt_len));
147 : :
148 : 0 : rte_prefetch0(&(*pkts)->pool);
149 : : }
150 : :
151 : : /*
152 : : * Fill H/W descriptor ring with mbuf data.
153 : : * Copy mbuf pointers to the S/W ring.
154 : : */
155 : : static inline void
156 : 0 : ngbe_tx_fill_hw_ring(struct ngbe_tx_queue *txq, struct rte_mbuf **pkts,
157 : : uint16_t nb_pkts)
158 : : {
159 : 0 : volatile struct ngbe_tx_desc *txdp = &txq->tx_ring[txq->tx_tail];
160 : 0 : struct ngbe_tx_entry *txep = &txq->sw_ring[txq->tx_tail];
161 : : const int N_PER_LOOP = 4;
162 : : const int N_PER_LOOP_MASK = N_PER_LOOP - 1;
163 : : int mainpart, leftover;
164 : : int i, j;
165 : :
166 : : /*
167 : : * Process most of the packets in chunks of N pkts. Any
168 : : * leftover packets will get processed one at a time.
169 : : */
170 : 0 : mainpart = (nb_pkts & ((uint32_t)~N_PER_LOOP_MASK));
171 : 0 : leftover = (nb_pkts & ((uint32_t)N_PER_LOOP_MASK));
172 [ # # ]: 0 : for (i = 0; i < mainpart; i += N_PER_LOOP) {
173 : : /* Copy N mbuf pointers to the S/W ring */
174 [ # # ]: 0 : for (j = 0; j < N_PER_LOOP; ++j)
175 : 0 : (txep + i + j)->mbuf = *(pkts + i + j);
176 : 0 : tx4(txdp + i, pkts + i);
177 : : }
178 : :
179 [ # # ]: 0 : if (unlikely(leftover > 0)) {
180 [ # # ]: 0 : for (i = 0; i < leftover; ++i) {
181 : 0 : (txep + mainpart + i)->mbuf = *(pkts + mainpart + i);
182 [ # # ]: 0 : tx1(txdp + mainpart + i, pkts + mainpart + i);
183 : : }
184 : : }
185 : 0 : }
186 : :
187 : : static inline uint16_t
188 : 0 : tx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
189 : : uint16_t nb_pkts)
190 : : {
191 : : struct ngbe_tx_queue *txq = (struct ngbe_tx_queue *)tx_queue;
192 : : uint16_t n = 0;
193 : :
194 : : /*
195 : : * Begin scanning the H/W ring for done descriptors when the
196 : : * number of available descriptors drops below tx_free_thresh.
197 : : * For each done descriptor, free the associated buffer.
198 : : */
199 [ # # ]: 0 : if (txq->nb_tx_free < txq->tx_free_thresh)
200 : : ngbe_tx_free_bufs(txq);
201 : :
202 : : /* Only use descriptors that are available */
203 : 0 : nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
204 [ # # ]: 0 : if (unlikely(nb_pkts == 0))
205 : : return 0;
206 : :
207 : : /* Use exactly nb_pkts descriptors */
208 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
209 : :
210 : : /*
211 : : * At this point, we know there are enough descriptors in the
212 : : * ring to transmit all the packets. This assumes that each
213 : : * mbuf contains a single segment, and that no new offloads
214 : : * are expected, which would require a new context descriptor.
215 : : */
216 : :
217 : : /*
218 : : * See if we're going to wrap-around. If so, handle the top
219 : : * of the descriptor ring first, then do the bottom. If not,
220 : : * the processing looks just like the "bottom" part anyway...
221 : : */
222 [ # # ]: 0 : if ((txq->tx_tail + nb_pkts) > txq->nb_tx_desc) {
223 : 0 : n = (uint16_t)(txq->nb_tx_desc - txq->tx_tail);
224 : 0 : ngbe_tx_fill_hw_ring(txq, tx_pkts, n);
225 : 0 : txq->tx_tail = 0;
226 : : }
227 : :
228 : : /* Fill H/W descriptor ring with mbuf data */
229 : 0 : ngbe_tx_fill_hw_ring(txq, tx_pkts + n, (uint16_t)(nb_pkts - n));
230 : 0 : txq->tx_tail = (uint16_t)(txq->tx_tail + (nb_pkts - n));
231 : :
232 : : /*
233 : : * Check for wrap-around. This would only happen if we used
234 : : * up to the last descriptor in the ring, no more, no less.
235 : : */
236 [ # # ]: 0 : if (txq->tx_tail >= txq->nb_tx_desc)
237 : 0 : txq->tx_tail = 0;
238 : :
239 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
240 : : (uint16_t)txq->port_id, (uint16_t)txq->queue_id,
241 : : (uint16_t)txq->tx_tail, (uint16_t)nb_pkts);
242 : :
243 : : /* update tail pointer */
244 : : rte_wmb();
245 : 0 : ngbe_set32_relaxed(txq->tdt_reg_addr, txq->tx_tail);
246 : :
247 : 0 : return nb_pkts;
248 : : }
249 : :
250 : : uint16_t
251 : 0 : ngbe_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
252 : : uint16_t nb_pkts)
253 : : {
254 : : uint16_t nb_tx;
255 : :
256 : : /* Try to transmit at least chunks of TX_MAX_BURST pkts */
257 [ # # ]: 0 : if (likely(nb_pkts <= RTE_PMD_NGBE_TX_MAX_BURST))
258 : 0 : return tx_xmit_pkts(tx_queue, tx_pkts, nb_pkts);
259 : :
260 : : /* transmit more than the max burst, in chunks of TX_MAX_BURST */
261 : : nb_tx = 0;
262 [ # # ]: 0 : while (nb_pkts != 0) {
263 : : uint16_t ret, n;
264 : :
265 : 0 : n = (uint16_t)RTE_MIN(nb_pkts, RTE_PMD_NGBE_TX_MAX_BURST);
266 : 0 : ret = tx_xmit_pkts(tx_queue, &tx_pkts[nb_tx], n);
267 : 0 : nb_tx = (uint16_t)(nb_tx + ret);
268 : 0 : nb_pkts = (uint16_t)(nb_pkts - ret);
269 [ # # ]: 0 : if (ret < n)
270 : : break;
271 : : }
272 : :
273 : : return nb_tx;
274 : : }
275 : :
276 : : static uint16_t
277 : 0 : ngbe_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
278 : : uint16_t nb_pkts)
279 : : {
280 : : struct ngbe_tx_queue *txq = (struct ngbe_tx_queue *)tx_queue;
281 : : uint16_t nb_tx = 0;
282 : :
283 [ # # ]: 0 : while (nb_pkts) {
284 : : uint16_t ret, num;
285 : :
286 : 0 : num = (uint16_t)RTE_MIN(nb_pkts, txq->tx_free_thresh);
287 : 0 : ret = ngbe_xmit_fixed_burst_vec(tx_queue, &tx_pkts[nb_tx], num);
288 : 0 : nb_tx += ret;
289 : 0 : nb_pkts -= ret;
290 [ # # ]: 0 : if (ret < num)
291 : : break;
292 : : }
293 : :
294 : 0 : return nb_tx;
295 : : }
296 : :
297 : : static inline void
298 : 0 : ngbe_set_xmit_ctx(struct ngbe_tx_queue *txq,
299 : : volatile struct ngbe_tx_ctx_desc *ctx_txd,
300 : : uint64_t ol_flags, union ngbe_tx_offload tx_offload)
301 : : {
302 : : union ngbe_tx_offload tx_offload_mask;
303 : : uint32_t type_tucmd_mlhl;
304 : : uint32_t mss_l4len_idx;
305 : : uint32_t ctx_idx;
306 : : uint32_t vlan_macip_lens;
307 : : uint32_t tunnel_seed;
308 : :
309 : 0 : ctx_idx = txq->ctx_curr;
310 : 0 : tx_offload_mask.data[0] = 0;
311 : : tx_offload_mask.data[1] = 0;
312 : :
313 : : /* Specify which HW CTX to upload. */
314 : 0 : mss_l4len_idx = NGBE_TXD_IDX(ctx_idx);
315 : : type_tucmd_mlhl = NGBE_TXD_CTXT;
316 : :
317 : 0 : tx_offload_mask.ptid |= ~0;
318 : 0 : type_tucmd_mlhl |= NGBE_TXD_PTID(tx_offload.ptid);
319 : :
320 : : /* check if TCP segmentation required for this packet */
321 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)) {
322 : 0 : tx_offload_mask.l2_len |= ~0;
323 : 0 : tx_offload_mask.l3_len |= ~0;
324 : 0 : tx_offload_mask.l4_len |= ~0;
325 : 0 : tx_offload_mask.tso_segsz |= ~0;
326 : 0 : mss_l4len_idx |= NGBE_TXD_MSS(tx_offload.tso_segsz);
327 : 0 : mss_l4len_idx |= NGBE_TXD_L4LEN(tx_offload.l4_len);
328 : : } else { /* no TSO, check if hardware checksum is needed */
329 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM) {
330 : 0 : tx_offload_mask.l2_len |= ~0;
331 : 0 : tx_offload_mask.l3_len |= ~0;
332 : : }
333 : :
334 [ # # # # ]: 0 : switch (ol_flags & RTE_MBUF_F_TX_L4_MASK) {
335 : 0 : case RTE_MBUF_F_TX_UDP_CKSUM:
336 : 0 : mss_l4len_idx |=
337 : : NGBE_TXD_L4LEN(sizeof(struct rte_udp_hdr));
338 : 0 : tx_offload_mask.l2_len |= ~0;
339 : 0 : tx_offload_mask.l3_len |= ~0;
340 : 0 : break;
341 : 0 : case RTE_MBUF_F_TX_TCP_CKSUM:
342 : 0 : mss_l4len_idx |=
343 : : NGBE_TXD_L4LEN(sizeof(struct rte_tcp_hdr));
344 : 0 : tx_offload_mask.l2_len |= ~0;
345 : 0 : tx_offload_mask.l3_len |= ~0;
346 : 0 : break;
347 : 0 : case RTE_MBUF_F_TX_SCTP_CKSUM:
348 : 0 : mss_l4len_idx |=
349 : : NGBE_TXD_L4LEN(sizeof(struct rte_sctp_hdr));
350 : 0 : tx_offload_mask.l2_len |= ~0;
351 : 0 : tx_offload_mask.l3_len |= ~0;
352 : 0 : break;
353 : : default:
354 : : break;
355 : : }
356 : : }
357 : :
358 : 0 : vlan_macip_lens = NGBE_TXD_IPLEN(tx_offload.l3_len >> 1);
359 : 0 : vlan_macip_lens |= NGBE_TXD_MACLEN(tx_offload.l2_len);
360 : :
361 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_VLAN) {
362 : 0 : tx_offload_mask.vlan_tci |= ~0;
363 : 0 : vlan_macip_lens |= NGBE_TXD_VLAN(tx_offload.vlan_tci);
364 : : }
365 : :
366 : : tunnel_seed = 0;
367 : :
368 : 0 : txq->ctx_cache[ctx_idx].flags = ol_flags;
369 : 0 : txq->ctx_cache[ctx_idx].tx_offload.data[0] =
370 : 0 : tx_offload_mask.data[0] & tx_offload.data[0];
371 : 0 : txq->ctx_cache[ctx_idx].tx_offload.data[1] =
372 : : tx_offload_mask.data[1] & tx_offload.data[1];
373 : 0 : txq->ctx_cache[ctx_idx].tx_offload_mask = tx_offload_mask;
374 : :
375 : 0 : ctx_txd->dw0 = rte_cpu_to_le_32(vlan_macip_lens);
376 : 0 : ctx_txd->dw1 = rte_cpu_to_le_32(tunnel_seed);
377 : 0 : ctx_txd->dw2 = rte_cpu_to_le_32(type_tucmd_mlhl);
378 : 0 : ctx_txd->dw3 = rte_cpu_to_le_32(mss_l4len_idx);
379 : 0 : }
380 : :
381 : : /*
382 : : * Check which hardware context can be used. Use the existing match
383 : : * or create a new context descriptor.
384 : : */
385 : : static inline uint32_t
386 : 0 : what_ctx_update(struct ngbe_tx_queue *txq, uint64_t flags,
387 : : union ngbe_tx_offload tx_offload)
388 : : {
389 : : /* If match with the current used context */
390 [ # # # # : 0 : if (likely(txq->ctx_cache[txq->ctx_curr].flags == flags &&
# # ]
391 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data[0] ==
392 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[0]
393 : : & tx_offload.data[0])) &&
394 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data[1] ==
395 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[1]
396 : : & tx_offload.data[1]))))
397 : : return txq->ctx_curr;
398 : :
399 : : /* What if match with the next context */
400 : 0 : txq->ctx_curr ^= 1;
401 [ # # # # : 0 : if (likely(txq->ctx_cache[txq->ctx_curr].flags == flags &&
# # ]
402 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data[0] ==
403 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[0]
404 : : & tx_offload.data[0])) &&
405 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data[1] ==
406 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[1]
407 : : & tx_offload.data[1]))))
408 : 0 : return txq->ctx_curr;
409 : :
410 : : /* Mismatch, use the previous context */
411 : : return NGBE_CTX_NUM;
412 : : }
413 : :
414 : : static inline uint32_t
415 : 0 : tx_desc_cksum_flags_to_olinfo(uint64_t ol_flags)
416 : : {
417 : : uint32_t tmp = 0;
418 : :
419 [ # # ]: 0 : if ((ol_flags & RTE_MBUF_F_TX_L4_MASK) != RTE_MBUF_F_TX_L4_NO_CKSUM) {
420 : : tmp |= NGBE_TXD_CC;
421 : : tmp |= NGBE_TXD_L4CS;
422 : : }
423 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM) {
424 : : tmp |= NGBE_TXD_CC;
425 : 0 : tmp |= NGBE_TXD_IPCS;
426 : : }
427 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) {
428 : : tmp |= NGBE_TXD_CC;
429 : 0 : tmp |= NGBE_TXD_EIPCS;
430 : : }
431 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)) {
432 : 0 : tmp |= NGBE_TXD_CC;
433 : : /* implies IPv4 cksum */
434 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IPV4)
435 : 0 : tmp |= NGBE_TXD_IPCS;
436 : 0 : tmp |= NGBE_TXD_L4CS;
437 : : }
438 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_VLAN)
439 : 0 : tmp |= NGBE_TXD_CC;
440 : :
441 : 0 : return tmp;
442 : : }
443 : :
444 : : static inline uint32_t
445 : : tx_desc_ol_flags_to_cmdtype(uint64_t ol_flags)
446 : : {
447 : : uint32_t cmdtype = 0;
448 : :
449 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_VLAN)
450 : : cmdtype |= NGBE_TXD_VLE;
451 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG))
452 : 0 : cmdtype |= NGBE_TXD_TSE;
453 : : return cmdtype;
454 : : }
455 : :
456 : : static inline uint32_t
457 : 0 : tx_desc_ol_flags_to_ptype(uint64_t oflags)
458 : : {
459 : : uint32_t ptype;
460 : :
461 : : /* L2 level */
462 : : ptype = RTE_PTYPE_L2_ETHER;
463 [ # # ]: 0 : if (oflags & RTE_MBUF_F_TX_VLAN)
464 : : ptype |= RTE_PTYPE_L2_ETHER_VLAN;
465 : :
466 : : /* L3 level */
467 [ # # ]: 0 : if (oflags & (RTE_MBUF_F_TX_IPV4 | RTE_MBUF_F_TX_IP_CKSUM))
468 : 0 : ptype |= RTE_PTYPE_L3_IPV4;
469 [ # # ]: 0 : else if (oflags & (RTE_MBUF_F_TX_IPV6))
470 : 0 : ptype |= RTE_PTYPE_L3_IPV6;
471 : :
472 : : /* L4 level */
473 [ # # # # ]: 0 : switch (oflags & (RTE_MBUF_F_TX_L4_MASK)) {
474 : 0 : case RTE_MBUF_F_TX_TCP_CKSUM:
475 : 0 : ptype |= RTE_PTYPE_L4_TCP;
476 : 0 : break;
477 : 0 : case RTE_MBUF_F_TX_UDP_CKSUM:
478 : 0 : ptype |= RTE_PTYPE_L4_UDP;
479 : 0 : break;
480 : 0 : case RTE_MBUF_F_TX_SCTP_CKSUM:
481 : 0 : ptype |= RTE_PTYPE_L4_SCTP;
482 : 0 : break;
483 : : }
484 : :
485 [ # # ]: 0 : if (oflags & RTE_MBUF_F_TX_TCP_SEG)
486 : 0 : ptype |= RTE_PTYPE_L4_TCP;
487 [ # # ]: 0 : else if (oflags & RTE_MBUF_F_TX_UDP_SEG)
488 : 0 : ptype |= RTE_PTYPE_L4_UDP;
489 : :
490 : 0 : return ptype;
491 : : }
492 : :
493 : : static inline uint8_t
494 : : tx_desc_ol_flags_to_ptid(uint64_t oflags)
495 : : {
496 : : uint32_t ptype;
497 : :
498 : 0 : ptype = tx_desc_ol_flags_to_ptype(oflags);
499 : :
500 : 0 : return ngbe_encode_ptype(ptype);
501 : : }
502 : :
503 : : /* Reset transmit descriptors after they have been used */
504 : : static inline int
505 : 0 : ngbe_xmit_cleanup(struct ngbe_tx_queue *txq)
506 : : {
507 : 0 : struct ngbe_tx_entry *sw_ring = txq->sw_ring;
508 : 0 : volatile struct ngbe_tx_desc *txr = txq->tx_ring;
509 : 0 : uint16_t last_desc_cleaned = txq->last_desc_cleaned;
510 : 0 : uint16_t nb_tx_desc = txq->nb_tx_desc;
511 : : uint16_t desc_to_clean_to;
512 : : uint16_t nb_tx_to_clean;
513 : : uint32_t status;
514 : :
515 : : /* Determine the last descriptor needing to be cleaned */
516 : 0 : desc_to_clean_to = (uint16_t)(last_desc_cleaned + txq->tx_free_thresh);
517 [ # # ]: 0 : if (desc_to_clean_to >= nb_tx_desc)
518 : 0 : desc_to_clean_to = (uint16_t)(desc_to_clean_to - nb_tx_desc);
519 : :
520 : : /* Check to make sure the last descriptor to clean is done */
521 : 0 : desc_to_clean_to = sw_ring[desc_to_clean_to].last_id;
522 : 0 : status = txr[desc_to_clean_to].dw3;
523 [ # # ]: 0 : if (!(status & rte_cpu_to_le_32(NGBE_TXD_DD))) {
524 : : PMD_TX_LOG(DEBUG,
525 : : "Tx descriptor %4u is not done"
526 : : "(port=%d queue=%d)",
527 : : desc_to_clean_to,
528 : : txq->port_id, txq->queue_id);
529 [ # # ]: 0 : if (txq->nb_tx_free >> 1 < txq->tx_free_thresh)
530 : 0 : ngbe_set32_masked(txq->tdc_reg_addr,
531 : : NGBE_TXCFG_FLUSH, NGBE_TXCFG_FLUSH);
532 : : /* Failed to clean any descriptors, better luck next time */
533 : 0 : return -(1);
534 : : }
535 : :
536 : : /* Figure out how many descriptors will be cleaned */
537 [ # # ]: 0 : if (last_desc_cleaned > desc_to_clean_to)
538 : 0 : nb_tx_to_clean = (uint16_t)((nb_tx_desc - last_desc_cleaned) +
539 : : desc_to_clean_to);
540 : : else
541 : 0 : nb_tx_to_clean = (uint16_t)(desc_to_clean_to -
542 : : last_desc_cleaned);
543 : :
544 : : PMD_TX_LOG(DEBUG,
545 : : "Cleaning %4u Tx descriptors: %4u to %4u (port=%d queue=%d)",
546 : : nb_tx_to_clean, last_desc_cleaned, desc_to_clean_to,
547 : : txq->port_id, txq->queue_id);
548 : :
549 : : /*
550 : : * The last descriptor to clean is done, so that means all the
551 : : * descriptors from the last descriptor that was cleaned
552 : : * up to the last descriptor with the RS bit set
553 : : * are done. Only reset the threshold descriptor.
554 : : */
555 : 0 : txr[desc_to_clean_to].dw3 = 0;
556 : :
557 : : /* Update the txq to reflect the last descriptor that was cleaned */
558 : 0 : txq->last_desc_cleaned = desc_to_clean_to;
559 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + nb_tx_to_clean);
560 : :
561 : : /* No Error */
562 : 0 : return 0;
563 : : }
564 : :
565 : : static inline bool
566 : : ngbe_check_pkt_err(struct rte_mbuf *tx_pkt)
567 : : {
568 : : uint32_t total_len = 0, nb_seg = 0;
569 : : struct rte_mbuf *mseg;
570 : :
571 : : mseg = tx_pkt;
572 : : do {
573 [ # # ]: 0 : if (mseg->data_len == 0)
574 : : return true;
575 : 0 : total_len += mseg->data_len;
576 : 0 : nb_seg++;
577 : 0 : mseg = mseg->next;
578 [ # # ]: 0 : } while (mseg != NULL);
579 : :
580 [ # # # # ]: 0 : if (tx_pkt->pkt_len != total_len || tx_pkt->pkt_len == 0)
581 : : return true;
582 : :
583 [ # # # # ]: 0 : if (tx_pkt->nb_segs != nb_seg || tx_pkt->nb_segs > 64)
584 : : return true;
585 : :
586 : : return false;
587 : : }
588 : :
589 : : uint16_t
590 : 0 : ngbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
591 : : uint16_t nb_pkts)
592 : : {
593 : : struct ngbe_tx_queue *txq;
594 : : struct ngbe_tx_entry *sw_ring;
595 : : struct ngbe_tx_entry *txe, *txn;
596 : : volatile struct ngbe_tx_desc *txr;
597 : : volatile struct ngbe_tx_desc *txd;
598 : : struct rte_mbuf *tx_pkt;
599 : : struct rte_mbuf *m_seg;
600 : : uint64_t buf_dma_addr;
601 : : uint32_t olinfo_status;
602 : : uint32_t cmd_type_len;
603 : : uint32_t pkt_len;
604 : : uint16_t slen;
605 : : uint64_t ol_flags;
606 : : uint16_t tx_id;
607 : : uint16_t tx_last;
608 : : uint16_t nb_tx;
609 : : uint16_t nb_used;
610 : : uint64_t tx_ol_req;
611 : : uint32_t ctx = 0;
612 : : uint32_t new_ctx;
613 : : union ngbe_tx_offload tx_offload;
614 : :
615 : 0 : tx_offload.data[0] = 0;
616 : 0 : tx_offload.data[1] = 0;
617 : : txq = tx_queue;
618 : 0 : sw_ring = txq->sw_ring;
619 : 0 : txr = txq->tx_ring;
620 : 0 : tx_id = txq->tx_tail;
621 : 0 : txe = &sw_ring[tx_id];
622 : :
623 : : /* Determine if the descriptor ring needs to be cleaned. */
624 [ # # ]: 0 : if (txq->nb_tx_free < txq->tx_free_thresh)
625 : 0 : ngbe_xmit_cleanup(txq);
626 : :
627 : 0 : rte_prefetch0(&txe->mbuf->pool);
628 : :
629 : : /* Tx loop */
630 [ # # ]: 0 : for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
631 : : new_ctx = 0;
632 : 0 : tx_pkt = *tx_pkts++;
633 : 0 : if (ngbe_check_pkt_err(tx_pkt)) {
634 : 0 : rte_pktmbuf_free(tx_pkt);
635 : 0 : txq->desc_error++;
636 : 0 : continue;
637 : : }
638 : :
639 : 0 : pkt_len = tx_pkt->pkt_len;
640 : :
641 : : /*
642 : : * Determine how many (if any) context descriptors
643 : : * are needed for offload functionality.
644 : : */
645 : 0 : ol_flags = tx_pkt->ol_flags;
646 : :
647 : : /* If hardware offload required */
648 : 0 : tx_ol_req = ol_flags & NGBE_TX_OFFLOAD_MASK;
649 [ # # ]: 0 : if (tx_ol_req) {
650 : 0 : tx_offload.ptid = tx_desc_ol_flags_to_ptid(tx_ol_req);
651 : 0 : tx_offload.l2_len = tx_pkt->l2_len;
652 : 0 : tx_offload.l3_len = tx_pkt->l3_len;
653 : 0 : tx_offload.l4_len = tx_pkt->l4_len;
654 : 0 : tx_offload.vlan_tci = tx_pkt->vlan_tci;
655 : 0 : tx_offload.tso_segsz = tx_pkt->tso_segsz;
656 : :
657 : : /* If new context need be built or reuse the exist ctx*/
658 : 0 : ctx = what_ctx_update(txq, tx_ol_req, tx_offload);
659 : : /* Only allocate context descriptor if required */
660 : 0 : new_ctx = (ctx == NGBE_CTX_NUM);
661 : 0 : ctx = txq->ctx_curr;
662 : : }
663 : :
664 : : /*
665 : : * Keep track of how many descriptors are used this loop
666 : : * This will always be the number of segments + the number of
667 : : * Context descriptors required to transmit the packet
668 : : */
669 : 0 : nb_used = (uint16_t)(tx_pkt->nb_segs + new_ctx);
670 : :
671 : : /*
672 : : * The number of descriptors that must be allocated for a
673 : : * packet is the number of segments of that packet, plus 1
674 : : * Context Descriptor for the hardware offload, if any.
675 : : * Determine the last Tx descriptor to allocate in the Tx ring
676 : : * for the packet, starting from the current position (tx_id)
677 : : * in the ring.
678 : : */
679 : 0 : tx_last = (uint16_t)(tx_id + nb_used - 1);
680 : :
681 : : /* Circular ring */
682 [ # # ]: 0 : if (tx_last >= txq->nb_tx_desc)
683 : 0 : tx_last = (uint16_t)(tx_last - txq->nb_tx_desc);
684 : :
685 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u pktlen=%u"
686 : : " tx_first=%u tx_last=%u",
687 : : (uint16_t)txq->port_id,
688 : : (uint16_t)txq->queue_id,
689 : : (uint32_t)pkt_len,
690 : : (uint16_t)tx_id,
691 : : (uint16_t)tx_last);
692 : :
693 : : /*
694 : : * Make sure there are enough Tx descriptors available to
695 : : * transmit the entire packet.
696 : : * nb_used better be less than or equal to txq->tx_free_thresh
697 : : */
698 [ # # ]: 0 : if (nb_used > txq->nb_tx_free) {
699 : : PMD_TX_LOG(DEBUG,
700 : : "Not enough free Tx descriptors "
701 : : "nb_used=%4u nb_free=%4u "
702 : : "(port=%d queue=%d)",
703 : : nb_used, txq->nb_tx_free,
704 : : txq->port_id, txq->queue_id);
705 : :
706 [ # # ]: 0 : if (ngbe_xmit_cleanup(txq) != 0) {
707 : : /* Could not clean any descriptors */
708 [ # # ]: 0 : if (nb_tx == 0)
709 : : return 0;
710 : 0 : goto end_of_tx;
711 : : }
712 : :
713 : : /* nb_used better be <= txq->tx_free_thresh */
714 [ # # ]: 0 : if (unlikely(nb_used > txq->tx_free_thresh)) {
715 : : PMD_TX_LOG(DEBUG,
716 : : "The number of descriptors needed to "
717 : : "transmit the packet exceeds the "
718 : : "RS bit threshold. This will impact "
719 : : "performance."
720 : : "nb_used=%4u nb_free=%4u "
721 : : "tx_free_thresh=%4u. "
722 : : "(port=%d queue=%d)",
723 : : nb_used, txq->nb_tx_free,
724 : : txq->tx_free_thresh,
725 : : txq->port_id, txq->queue_id);
726 : : /*
727 : : * Loop here until there are enough Tx
728 : : * descriptors or until the ring cannot be
729 : : * cleaned.
730 : : */
731 [ # # ]: 0 : while (nb_used > txq->nb_tx_free) {
732 [ # # ]: 0 : if (ngbe_xmit_cleanup(txq) != 0) {
733 : : /*
734 : : * Could not clean any
735 : : * descriptors
736 : : */
737 [ # # ]: 0 : if (nb_tx == 0)
738 : : return 0;
739 : 0 : goto end_of_tx;
740 : : }
741 : : }
742 : : }
743 : : }
744 : :
745 : : /*
746 : : * By now there are enough free Tx descriptors to transmit
747 : : * the packet.
748 : : */
749 : :
750 : : /*
751 : : * Set common flags of all Tx Data Descriptors.
752 : : *
753 : : * The following bits must be set in the first Data Descriptor
754 : : * and are ignored in the other ones:
755 : : * - NGBE_TXD_FCS
756 : : *
757 : : * The following bits must only be set in the last Data
758 : : * Descriptor:
759 : : * - NGBE_TXD_EOP
760 : : */
761 : : cmd_type_len = NGBE_TXD_FCS;
762 : :
763 : : #ifdef RTE_LIBRTE_IEEE1588
764 : : if (ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
765 : : cmd_type_len |= NGBE_TXD_1588;
766 : : #endif
767 : :
768 : : olinfo_status = 0;
769 [ # # ]: 0 : if (tx_ol_req) {
770 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)) {
771 : : /* when TSO is on, paylen in descriptor is the
772 : : * not the packet len but the tcp payload len
773 : : */
774 : 0 : pkt_len -= (tx_offload.l2_len +
775 : 0 : tx_offload.l3_len + tx_offload.l4_len);
776 : : }
777 : :
778 : : /*
779 : : * Setup the Tx Context Descriptor if required
780 : : */
781 [ # # ]: 0 : if (new_ctx) {
782 : : volatile struct ngbe_tx_ctx_desc *ctx_txd;
783 : :
784 : 0 : ctx_txd = (volatile struct ngbe_tx_ctx_desc *)
785 : 0 : &txr[tx_id];
786 : :
787 : 0 : txn = &sw_ring[txe->next_id];
788 : 0 : rte_prefetch0(&txn->mbuf->pool);
789 : :
790 [ # # ]: 0 : if (txe->mbuf != NULL) {
791 : : rte_pktmbuf_free_seg(txe->mbuf);
792 : 0 : txe->mbuf = NULL;
793 : : }
794 : :
795 : 0 : ngbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req,
796 : : tx_offload);
797 : :
798 : 0 : txe->last_id = tx_last;
799 : 0 : tx_id = txe->next_id;
800 : : txe = txn;
801 : : }
802 : :
803 : : /*
804 : : * Setup the Tx Data Descriptor,
805 : : * This path will go through
806 : : * whatever new/reuse the context descriptor
807 : : */
808 : 0 : cmd_type_len |= tx_desc_ol_flags_to_cmdtype(ol_flags);
809 : : olinfo_status |=
810 : 0 : tx_desc_cksum_flags_to_olinfo(ol_flags);
811 : 0 : olinfo_status |= NGBE_TXD_IDX(ctx);
812 : : }
813 : :
814 : 0 : olinfo_status |= NGBE_TXD_PAYLEN(pkt_len);
815 : :
816 : : m_seg = tx_pkt;
817 : : do {
818 : 0 : txd = &txr[tx_id];
819 : 0 : txn = &sw_ring[txe->next_id];
820 : 0 : rte_prefetch0(&txn->mbuf->pool);
821 : :
822 [ # # ]: 0 : if (txe->mbuf != NULL)
823 : : rte_pktmbuf_free_seg(txe->mbuf);
824 : 0 : txe->mbuf = m_seg;
825 : :
826 : : /*
827 : : * Set up Transmit Data Descriptor.
828 : : */
829 [ # # ]: 0 : slen = m_seg->data_len;
830 : : buf_dma_addr = rte_mbuf_data_iova(m_seg);
831 : 0 : txd->qw0 = rte_cpu_to_le_64(buf_dma_addr);
832 : 0 : txd->dw2 = rte_cpu_to_le_32(cmd_type_len | slen);
833 : 0 : txd->dw3 = rte_cpu_to_le_32(olinfo_status);
834 : 0 : txe->last_id = tx_last;
835 : 0 : tx_id = txe->next_id;
836 : : txe = txn;
837 : 0 : m_seg = m_seg->next;
838 [ # # ]: 0 : } while (m_seg != NULL);
839 : :
840 : : /*
841 : : * The last packet data descriptor needs End Of Packet (EOP)
842 : : */
843 : 0 : cmd_type_len |= NGBE_TXD_EOP;
844 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_used);
845 : :
846 : 0 : txd->dw2 |= rte_cpu_to_le_32(cmd_type_len);
847 : : }
848 : :
849 : 0 : end_of_tx:
850 : :
851 : : rte_wmb();
852 : :
853 : : /*
854 : : * Set the Transmit Descriptor Tail (TDT)
855 : : */
856 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
857 : : (uint16_t)txq->port_id, (uint16_t)txq->queue_id,
858 : : (uint16_t)tx_id, (uint16_t)nb_tx);
859 : 0 : ngbe_set32_relaxed(txq->tdt_reg_addr, tx_id);
860 : 0 : txq->tx_tail = tx_id;
861 : :
862 : 0 : return nb_tx;
863 : : }
864 : :
865 : : /*********************************************************************
866 : : *
867 : : * Tx prep functions
868 : : *
869 : : **********************************************************************/
870 : : uint16_t
871 : 0 : ngbe_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
872 : : {
873 : : int i, ret;
874 : : uint64_t ol_flags;
875 : : struct rte_mbuf *m;
876 : : struct ngbe_tx_queue *txq = (struct ngbe_tx_queue *)tx_queue;
877 : :
878 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
879 : 0 : m = tx_pkts[i];
880 : 0 : ol_flags = m->ol_flags;
881 : :
882 : : /**
883 : : * Check if packet meets requirements for number of segments
884 : : *
885 : : * NOTE: for ngbe it's always (40 - WTHRESH) for both TSO and
886 : : * non-TSO
887 : : */
888 : :
889 [ # # ]: 0 : if (m->nb_segs > NGBE_TX_MAX_SEG - txq->wthresh) {
890 : 0 : rte_errno = -EINVAL;
891 : 0 : return i;
892 : : }
893 : :
894 [ # # ]: 0 : if (ol_flags & NGBE_TX_OFFLOAD_NOTSUP_MASK) {
895 : 0 : rte_errno = -ENOTSUP;
896 : 0 : return i;
897 : : }
898 : :
899 : : #ifdef RTE_ETHDEV_DEBUG_TX
900 : : ret = rte_validate_tx_offload(m);
901 : : if (ret != 0) {
902 : : rte_errno = ret;
903 : : return i;
904 : : }
905 : : #endif
906 : : ret = rte_net_intel_cksum_prepare(m);
907 [ # # ]: 0 : if (ret != 0) {
908 : 0 : rte_errno = ret;
909 : 0 : return i;
910 : : }
911 : : }
912 : :
913 : 0 : return i;
914 : : }
915 : :
916 : : /*********************************************************************
917 : : *
918 : : * Rx functions
919 : : *
920 : : **********************************************************************/
921 : : static inline uint32_t
922 : : ngbe_rxd_pkt_info_to_pkt_type(uint32_t pkt_info, uint16_t ptid_mask)
923 : : {
924 : 0 : uint16_t ptid = NGBE_RXD_PTID(pkt_info);
925 : :
926 : : ptid &= ptid_mask;
927 : :
928 : 0 : return ngbe_decode_ptype(ptid);
929 : : }
930 : :
931 : : static inline uint64_t
932 : : ngbe_rxd_pkt_info_to_pkt_flags(uint32_t pkt_info)
933 : : {
934 : : static alignas(RTE_CACHE_LINE_SIZE) uint64_t ip_rss_types_map[16] = {
935 : : 0, RTE_MBUF_F_RX_RSS_HASH, RTE_MBUF_F_RX_RSS_HASH, RTE_MBUF_F_RX_RSS_HASH,
936 : : 0, RTE_MBUF_F_RX_RSS_HASH, 0, RTE_MBUF_F_RX_RSS_HASH,
937 : : RTE_MBUF_F_RX_RSS_HASH, 0, 0, 0,
938 : : 0, 0, 0, RTE_MBUF_F_RX_FDIR,
939 : : };
940 : : #ifdef RTE_LIBRTE_IEEE1588
941 : : static uint64_t ip_pkt_etqf_map[8] = {
942 : : 0, 0, 0, RTE_MBUF_F_RX_IEEE1588_PTP,
943 : : 0, 0, 0, 0,
944 : : };
945 : : int etfid = ngbe_etflt_id(NGBE_RXD_PTID(pkt_info));
946 : : if (likely(-1 != etfid))
947 : : return ip_pkt_etqf_map[etfid] |
948 : : ip_rss_types_map[NGBE_RXD_RSSTYPE(pkt_info)];
949 : : else
950 : : return ip_rss_types_map[NGBE_RXD_RSSTYPE(pkt_info)];
951 : : #else
952 : 0 : return ip_rss_types_map[NGBE_RXD_RSSTYPE(pkt_info)];
953 : : #endif
954 : : }
955 : :
956 : : static inline uint64_t
957 : : rx_desc_status_to_pkt_flags(uint32_t rx_status, uint64_t vlan_flags)
958 : : {
959 : : uint64_t pkt_flags;
960 : :
961 : : /*
962 : : * Check if VLAN present only.
963 : : * Do not check whether L3/L4 rx checksum done by NIC or not,
964 : : * That can be found from rte_eth_rxmode.offloads flag
965 : : */
966 : 0 : pkt_flags = (rx_status & NGBE_RXD_STAT_VLAN &&
967 [ # # # # : 0 : vlan_flags & RTE_MBUF_F_RX_VLAN_STRIPPED)
# # ]
968 : 0 : ? vlan_flags : 0;
969 : :
970 : : #ifdef RTE_LIBRTE_IEEE1588
971 : : if (rx_status & NGBE_RXD_STAT_1588)
972 : : pkt_flags = pkt_flags | RTE_MBUF_F_RX_IEEE1588_TMST;
973 : : #endif
974 : : return pkt_flags;
975 : : }
976 : :
977 : : static inline uint64_t
978 : 0 : rx_desc_error_to_pkt_flags(uint32_t rx_status, struct ngbe_rx_queue *rxq)
979 : : {
980 : : uint64_t pkt_flags = 0;
981 : :
982 : : /* checksum offload can't be disabled */
983 [ # # ]: 0 : if (rx_status & NGBE_RXD_STAT_IPCS) {
984 : : pkt_flags |= (rx_status & NGBE_RXD_ERR_IPCS
985 [ # # ]: 0 : ? RTE_MBUF_F_RX_IP_CKSUM_BAD : RTE_MBUF_F_RX_IP_CKSUM_GOOD);
986 : 0 : rxq->csum_err += !!(rx_status & NGBE_RXD_ERR_IPCS);
987 : : }
988 : :
989 [ # # ]: 0 : if (rx_status & NGBE_RXD_STAT_L4CS) {
990 : 0 : pkt_flags |= (rx_status & NGBE_RXD_ERR_L4CS
991 [ # # ]: 0 : ? RTE_MBUF_F_RX_L4_CKSUM_BAD : RTE_MBUF_F_RX_L4_CKSUM_GOOD);
992 : 0 : rxq->csum_err += !!(rx_status & NGBE_RXD_ERR_L4CS);
993 : : }
994 : :
995 [ # # ]: 0 : if (rx_status & NGBE_RXD_STAT_EIPCS &&
996 : : rx_status & NGBE_RXD_ERR_EIPCS) {
997 : 0 : pkt_flags |= RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD;
998 : 0 : rxq->csum_err += !!(rx_status & NGBE_RXD_ERR_EIPCS);
999 : : }
1000 : :
1001 : 0 : return pkt_flags;
1002 : : }
1003 : :
1004 : : /*
1005 : : * LOOK_AHEAD defines how many desc statuses to check beyond the
1006 : : * current descriptor.
1007 : : * It must be a pound define for optimal performance.
1008 : : * Do not change the value of LOOK_AHEAD, as the ngbe_rx_scan_hw_ring
1009 : : * function only works with LOOK_AHEAD=8.
1010 : : */
1011 : : #define LOOK_AHEAD 8
1012 : : #if (LOOK_AHEAD != 8)
1013 : : #error "PMD NGBE: LOOK_AHEAD must be 8\n"
1014 : : #endif
1015 : : static inline int
1016 : 0 : ngbe_rx_scan_hw_ring(struct ngbe_rx_queue *rxq)
1017 : : {
1018 : : volatile struct ngbe_rx_desc *rxdp;
1019 : : struct ngbe_rx_entry *rxep;
1020 : : struct rte_mbuf *mb;
1021 : : uint16_t pkt_len;
1022 : : uint64_t pkt_flags;
1023 : : int nb_dd;
1024 : : uint32_t s[LOOK_AHEAD];
1025 : : uint32_t pkt_info[LOOK_AHEAD];
1026 : : int i, j, nb_rx = 0;
1027 : : uint32_t status;
1028 : :
1029 : : /* get references to current descriptor and S/W ring entry */
1030 : 0 : rxdp = &rxq->rx_ring[rxq->rx_tail];
1031 : 0 : rxep = &rxq->sw_ring[rxq->rx_tail];
1032 : :
1033 : 0 : status = rxdp->qw1.lo.status;
1034 : : /* check to make sure there is at least 1 packet to receive */
1035 [ # # ]: 0 : if (!(status & rte_cpu_to_le_32(NGBE_RXD_STAT_DD)))
1036 : : return 0;
1037 : :
1038 : : /*
1039 : : * Scan LOOK_AHEAD descriptors at a time to determine which descriptors
1040 : : * reference packets that are ready to be received.
1041 : : */
1042 [ # # ]: 0 : for (i = 0; i < RTE_PMD_NGBE_RX_MAX_BURST;
1043 : 0 : i += LOOK_AHEAD, rxdp += LOOK_AHEAD, rxep += LOOK_AHEAD) {
1044 : : /* Read desc statuses backwards to avoid race condition */
1045 [ # # ]: 0 : for (j = 0; j < LOOK_AHEAD; j++)
1046 : 0 : s[j] = rte_le_to_cpu_32(rxdp[j].qw1.lo.status);
1047 : :
1048 : : rte_atomic_thread_fence(rte_memory_order_acquire);
1049 : :
1050 : : /* Compute how many status bits were set */
1051 [ # # ]: 0 : for (nb_dd = 0; nb_dd < LOOK_AHEAD &&
1052 [ # # ]: 0 : (s[nb_dd] & NGBE_RXD_STAT_DD); nb_dd++)
1053 : : ;
1054 : :
1055 [ # # ]: 0 : for (j = 0; j < nb_dd; j++)
1056 : 0 : pkt_info[j] = rte_le_to_cpu_32(rxdp[j].qw0.dw0);
1057 : :
1058 : 0 : nb_rx += nb_dd;
1059 : :
1060 : : /* Translate descriptor info to mbuf format */
1061 [ # # ]: 0 : for (j = 0; j < nb_dd; ++j) {
1062 : 0 : mb = rxep[j].mbuf;
1063 : 0 : pkt_len = rte_le_to_cpu_16(rxdp[j].qw1.hi.len) -
1064 : 0 : rxq->crc_len;
1065 : 0 : mb->data_len = pkt_len;
1066 : 0 : mb->pkt_len = pkt_len;
1067 : 0 : mb->vlan_tci = rte_le_to_cpu_16(rxdp[j].qw1.hi.tag);
1068 : :
1069 : : /* convert descriptor fields to rte mbuf flags */
1070 [ # # ]: 0 : pkt_flags = rx_desc_status_to_pkt_flags(s[j],
1071 : : rxq->vlan_flags);
1072 : 0 : pkt_flags |= rx_desc_error_to_pkt_flags(s[j], rxq);
1073 : 0 : pkt_flags |=
1074 : 0 : ngbe_rxd_pkt_info_to_pkt_flags(pkt_info[j]);
1075 : 0 : mb->ol_flags = pkt_flags;
1076 : 0 : mb->packet_type =
1077 : : ngbe_rxd_pkt_info_to_pkt_type(pkt_info[j],
1078 : : NGBE_PTID_MASK);
1079 : :
1080 [ # # ]: 0 : if (likely(pkt_flags & RTE_MBUF_F_RX_RSS_HASH))
1081 : 0 : mb->hash.rss =
1082 : 0 : rte_le_to_cpu_32(rxdp[j].qw0.dw1);
1083 : : }
1084 : :
1085 : : /* Move mbuf pointers from the S/W ring to the stage */
1086 [ # # ]: 0 : for (j = 0; j < LOOK_AHEAD; ++j)
1087 : 0 : rxq->rx_stage[i + j] = rxep[j].mbuf;
1088 : :
1089 : : /* stop if all requested packets could not be received */
1090 [ # # ]: 0 : if (nb_dd != LOOK_AHEAD)
1091 : : break;
1092 : : }
1093 : :
1094 : : /* clear software ring entries so we can cleanup correctly */
1095 [ # # ]: 0 : for (i = 0; i < nb_rx; ++i)
1096 : 0 : rxq->sw_ring[rxq->rx_tail + i].mbuf = NULL;
1097 : :
1098 : : return nb_rx;
1099 : : }
1100 : :
1101 : : static inline int
1102 : 0 : ngbe_rx_alloc_bufs(struct ngbe_rx_queue *rxq, bool reset_mbuf)
1103 : : {
1104 : : volatile struct ngbe_rx_desc *rxdp;
1105 : : struct ngbe_rx_entry *rxep;
1106 : : struct rte_mbuf *mb;
1107 : : uint16_t alloc_idx;
1108 : : __le64 dma_addr;
1109 : : int diag, i;
1110 : :
1111 : : /* allocate buffers in bulk directly into the S/W ring */
1112 : 0 : alloc_idx = rxq->rx_free_trigger - (rxq->rx_free_thresh - 1);
1113 : 0 : rxep = &rxq->sw_ring[alloc_idx];
1114 [ # # ]: 0 : diag = rte_mempool_get_bulk(rxq->mb_pool, (void *)rxep,
1115 : : rxq->rx_free_thresh);
1116 [ # # ]: 0 : if (unlikely(diag != 0))
1117 : : return -ENOMEM;
1118 : :
1119 : 0 : rxdp = &rxq->rx_ring[alloc_idx];
1120 [ # # ]: 0 : for (i = 0; i < rxq->rx_free_thresh; ++i) {
1121 : : /* populate the static rte mbuf fields */
1122 : 0 : mb = rxep[i].mbuf;
1123 [ # # ]: 0 : if (reset_mbuf)
1124 : 0 : mb->port = rxq->port_id;
1125 : :
1126 : : rte_mbuf_refcnt_set(mb, 1);
1127 : 0 : mb->data_off = RTE_PKTMBUF_HEADROOM;
1128 : :
1129 : : /* populate the descriptors */
1130 : : dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mb));
1131 : 0 : NGBE_RXD_HDRADDR(&rxdp[i], 0);
1132 : 0 : NGBE_RXD_PKTADDR(&rxdp[i], dma_addr);
1133 : : }
1134 : :
1135 : : /* update state of internal queue structure */
1136 : 0 : rxq->rx_free_trigger = rxq->rx_free_trigger + rxq->rx_free_thresh;
1137 [ # # ]: 0 : if (rxq->rx_free_trigger >= rxq->nb_rx_desc)
1138 : 0 : rxq->rx_free_trigger = rxq->rx_free_thresh - 1;
1139 : :
1140 : : /* no errors */
1141 : : return 0;
1142 : : }
1143 : :
1144 : : static inline uint16_t
1145 : : ngbe_rx_fill_from_stage(struct ngbe_rx_queue *rxq, struct rte_mbuf **rx_pkts,
1146 : : uint16_t nb_pkts)
1147 : : {
1148 : 0 : struct rte_mbuf **stage = &rxq->rx_stage[rxq->rx_next_avail];
1149 : : int i;
1150 : :
1151 : : /* how many packets are ready to return? */
1152 : 0 : nb_pkts = (uint16_t)RTE_MIN(nb_pkts, rxq->rx_nb_avail);
1153 : :
1154 : : /* copy mbuf pointers to the application's packet list */
1155 [ # # # # ]: 0 : for (i = 0; i < nb_pkts; ++i)
1156 : 0 : rx_pkts[i] = stage[i];
1157 : :
1158 : : /* update internal queue state */
1159 : 0 : rxq->rx_nb_avail = (uint16_t)(rxq->rx_nb_avail - nb_pkts);
1160 : 0 : rxq->rx_next_avail = (uint16_t)(rxq->rx_next_avail + nb_pkts);
1161 : :
1162 : : return nb_pkts;
1163 : : }
1164 : :
1165 : : static inline uint16_t
1166 : 0 : ngbe_rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1167 : : uint16_t nb_pkts)
1168 : : {
1169 : : struct ngbe_rx_queue *rxq = (struct ngbe_rx_queue *)rx_queue;
1170 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
1171 : : uint16_t nb_rx = 0;
1172 : :
1173 : : /* Any previously recv'd pkts will be returned from the Rx stage */
1174 [ # # ]: 0 : if (rxq->rx_nb_avail)
1175 : 0 : return ngbe_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
1176 : :
1177 : : /* Scan the H/W ring for packets to receive */
1178 : 0 : nb_rx = (uint16_t)ngbe_rx_scan_hw_ring(rxq);
1179 : :
1180 : : /* update internal queue state */
1181 : 0 : rxq->rx_next_avail = 0;
1182 : 0 : rxq->rx_nb_avail = nb_rx;
1183 : 0 : rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_rx);
1184 : :
1185 : : /* if required, allocate new buffers to replenish descriptors */
1186 [ # # ]: 0 : if (rxq->rx_tail > rxq->rx_free_trigger) {
1187 : : uint16_t cur_free_trigger = rxq->rx_free_trigger;
1188 : :
1189 [ # # ]: 0 : if (ngbe_rx_alloc_bufs(rxq, true) != 0) {
1190 : : int i, j;
1191 : :
1192 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1193 : : "queue_id=%u", (uint16_t)rxq->port_id,
1194 : : (uint16_t)rxq->queue_id);
1195 : :
1196 : 0 : dev->data->rx_mbuf_alloc_failed +=
1197 : 0 : rxq->rx_free_thresh;
1198 : :
1199 : : /*
1200 : : * Need to rewind any previous receives if we cannot
1201 : : * allocate new buffers to replenish the old ones.
1202 : : */
1203 : 0 : rxq->rx_nb_avail = 0;
1204 : 0 : rxq->rx_tail = (uint16_t)(rxq->rx_tail - nb_rx);
1205 [ # # ]: 0 : for (i = 0, j = rxq->rx_tail; i < nb_rx; ++i, ++j)
1206 : 0 : rxq->sw_ring[j].mbuf = rxq->rx_stage[i];
1207 : :
1208 : : return 0;
1209 : : }
1210 : :
1211 : : /* update tail pointer */
1212 : : rte_wmb();
1213 : 0 : ngbe_set32_relaxed(rxq->rdt_reg_addr, cur_free_trigger);
1214 : : }
1215 : :
1216 [ # # ]: 0 : if (rxq->rx_tail >= rxq->nb_rx_desc)
1217 : 0 : rxq->rx_tail = 0;
1218 : :
1219 : : /* received any packets this loop? */
1220 [ # # ]: 0 : if (rxq->rx_nb_avail)
1221 : 0 : return ngbe_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
1222 : :
1223 : : return 0;
1224 : : }
1225 : :
1226 : : /* split requests into chunks of size RTE_PMD_NGBE_RX_MAX_BURST */
1227 : : uint16_t
1228 : 0 : ngbe_recv_pkts_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
1229 : : uint16_t nb_pkts)
1230 : : {
1231 : : uint16_t nb_rx;
1232 : :
1233 [ # # ]: 0 : if (unlikely(nb_pkts == 0))
1234 : : return 0;
1235 : :
1236 [ # # ]: 0 : if (likely(nb_pkts <= RTE_PMD_NGBE_RX_MAX_BURST))
1237 : 0 : return ngbe_rx_recv_pkts(rx_queue, rx_pkts, nb_pkts);
1238 : :
1239 : : /* request is relatively large, chunk it up */
1240 : : nb_rx = 0;
1241 [ # # ]: 0 : while (nb_pkts) {
1242 : : uint16_t ret, n;
1243 : :
1244 : 0 : n = (uint16_t)RTE_MIN(nb_pkts, RTE_PMD_NGBE_RX_MAX_BURST);
1245 : 0 : ret = ngbe_rx_recv_pkts(rx_queue, &rx_pkts[nb_rx], n);
1246 : 0 : nb_rx = (uint16_t)(nb_rx + ret);
1247 : 0 : nb_pkts = (uint16_t)(nb_pkts - ret);
1248 [ # # ]: 0 : if (ret < n)
1249 : : break;
1250 : : }
1251 : :
1252 : : return nb_rx;
1253 : : }
1254 : :
1255 : : uint16_t
1256 : 0 : ngbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1257 : : uint16_t nb_pkts)
1258 : : {
1259 : : struct ngbe_rx_queue *rxq;
1260 : : volatile struct ngbe_rx_desc *rx_ring;
1261 : : volatile struct ngbe_rx_desc *rxdp;
1262 : : struct ngbe_rx_entry *sw_ring;
1263 : : struct ngbe_rx_entry *rxe;
1264 : : struct rte_mbuf *rxm;
1265 : : struct rte_mbuf *nmb;
1266 : : struct ngbe_rx_desc rxd;
1267 : : uint64_t dma_addr;
1268 : : uint32_t staterr;
1269 : : uint32_t pkt_info;
1270 : : uint16_t pkt_len;
1271 : : uint16_t rx_id;
1272 : : uint16_t nb_rx;
1273 : : uint16_t nb_hold;
1274 : : uint64_t pkt_flags;
1275 : :
1276 : : nb_rx = 0;
1277 : : nb_hold = 0;
1278 : : rxq = rx_queue;
1279 : 0 : rx_id = rxq->rx_tail;
1280 : 0 : rx_ring = rxq->rx_ring;
1281 : 0 : sw_ring = rxq->sw_ring;
1282 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
1283 [ # # ]: 0 : while (nb_rx < nb_pkts) {
1284 : : /*
1285 : : * The order of operations here is important as the DD status
1286 : : * bit must not be read after any other descriptor fields.
1287 : : * rx_ring and rxdp are pointing to volatile data so the order
1288 : : * of accesses cannot be reordered by the compiler. If they were
1289 : : * not volatile, they could be reordered which could lead to
1290 : : * using invalid descriptor fields when read from rxd.
1291 : : *
1292 : : * Meanwhile, to prevent the CPU from executing out of order, we
1293 : : * need to use a proper memory barrier to ensure the memory
1294 : : * ordering below.
1295 : : */
1296 : 0 : rxdp = &rx_ring[rx_id];
1297 : 0 : staterr = rxdp->qw1.lo.status;
1298 [ # # ]: 0 : if (!(staterr & rte_cpu_to_le_32(NGBE_RXD_STAT_DD)))
1299 : : break;
1300 : :
1301 : : /*
1302 : : * Use acquire fence to ensure that status_error which includes
1303 : : * DD bit is loaded before loading of other descriptor words.
1304 : : */
1305 : : rte_atomic_thread_fence(rte_memory_order_acquire);
1306 : :
1307 : 0 : rxd = *rxdp;
1308 : :
1309 : : /*
1310 : : * End of packet.
1311 : : *
1312 : : * If the NGBE_RXD_STAT_EOP flag is not set, the Rx packet
1313 : : * is likely to be invalid and to be dropped by the various
1314 : : * validation checks performed by the network stack.
1315 : : *
1316 : : * Allocate a new mbuf to replenish the RX ring descriptor.
1317 : : * If the allocation fails:
1318 : : * - arrange for that Rx descriptor to be the first one
1319 : : * being parsed the next time the receive function is
1320 : : * invoked [on the same queue].
1321 : : *
1322 : : * - Stop parsing the Rx ring and return immediately.
1323 : : *
1324 : : * This policy do not drop the packet received in the Rx
1325 : : * descriptor for which the allocation of a new mbuf failed.
1326 : : * Thus, it allows that packet to be later retrieved if
1327 : : * mbuf have been freed in the mean time.
1328 : : * As a side effect, holding Rx descriptors instead of
1329 : : * systematically giving them back to the NIC may lead to
1330 : : * Rx ring exhaustion situations.
1331 : : * However, the NIC can gracefully prevent such situations
1332 : : * to happen by sending specific "back-pressure" flow control
1333 : : * frames to its peer(s).
1334 : : */
1335 : : PMD_RX_LOG(DEBUG,
1336 : : "port_id=%u queue_id=%u rx_id=%u ext_err_stat=0x%08x pkt_len=%u",
1337 : : (uint16_t)rxq->port_id, (uint16_t)rxq->queue_id,
1338 : : (uint16_t)rx_id, (uint32_t)staterr,
1339 : : (uint16_t)rte_le_to_cpu_16(rxd.qw1.hi.len));
1340 : :
1341 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
1342 [ # # ]: 0 : if (nmb == NULL) {
1343 : : PMD_RX_LOG(DEBUG,
1344 : : "Rx mbuf alloc failed port_id=%u queue_id=%u",
1345 : : (uint16_t)rxq->port_id,
1346 : : (uint16_t)rxq->queue_id);
1347 : 0 : dev->data->rx_mbuf_alloc_failed++;
1348 : 0 : break;
1349 : : }
1350 : :
1351 : 0 : nb_hold++;
1352 : 0 : rxe = &sw_ring[rx_id];
1353 : 0 : rx_id++;
1354 [ # # ]: 0 : if (rx_id == rxq->nb_rx_desc)
1355 : : rx_id = 0;
1356 : :
1357 : : /* Prefetch next mbuf while processing current one. */
1358 : 0 : rte_ngbe_prefetch(sw_ring[rx_id].mbuf);
1359 : :
1360 : : /*
1361 : : * When next Rx descriptor is on a cache-line boundary,
1362 : : * prefetch the next 4 Rx descriptors and the next 8 pointers
1363 : : * to mbufs.
1364 : : */
1365 [ # # ]: 0 : if ((rx_id & 0x3) == 0) {
1366 : 0 : rte_ngbe_prefetch(&rx_ring[rx_id]);
1367 : : rte_ngbe_prefetch(&sw_ring[rx_id]);
1368 : : }
1369 : :
1370 : 0 : rxm = rxe->mbuf;
1371 : 0 : rxe->mbuf = nmb;
1372 : : dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1373 : 0 : NGBE_RXD_HDRADDR(rxdp, 0);
1374 : 0 : NGBE_RXD_PKTADDR(rxdp, dma_addr);
1375 : :
1376 : : /*
1377 : : * Initialize the returned mbuf.
1378 : : * 1) setup generic mbuf fields:
1379 : : * - number of segments,
1380 : : * - next segment,
1381 : : * - packet length,
1382 : : * - Rx port identifier.
1383 : : * 2) integrate hardware offload data, if any:
1384 : : * - RSS flag & hash,
1385 : : * - IP checksum flag,
1386 : : * - VLAN TCI, if any,
1387 : : * - error flags.
1388 : : */
1389 : 0 : pkt_len = (uint16_t)(rte_le_to_cpu_16(rxd.qw1.hi.len) -
1390 : 0 : rxq->crc_len);
1391 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
1392 : 0 : rte_packet_prefetch((char *)rxm->buf_addr + rxm->data_off);
1393 : 0 : rxm->nb_segs = 1;
1394 : 0 : rxm->next = NULL;
1395 : 0 : rxm->pkt_len = pkt_len;
1396 : 0 : rxm->data_len = pkt_len;
1397 : 0 : rxm->port = rxq->port_id;
1398 : :
1399 : : pkt_info = rte_le_to_cpu_32(rxd.qw0.dw0);
1400 : : /* Only valid if RTE_MBUF_F_RX_VLAN set in pkt_flags */
1401 : 0 : rxm->vlan_tci = rte_le_to_cpu_16(rxd.qw1.hi.tag);
1402 : :
1403 [ # # ]: 0 : pkt_flags = rx_desc_status_to_pkt_flags(staterr,
1404 : : rxq->vlan_flags);
1405 : 0 : pkt_flags |= rx_desc_error_to_pkt_flags(staterr, rxq);
1406 : 0 : pkt_flags |= ngbe_rxd_pkt_info_to_pkt_flags(pkt_info);
1407 : 0 : rxm->ol_flags = pkt_flags;
1408 : 0 : rxm->packet_type = ngbe_rxd_pkt_info_to_pkt_type(pkt_info,
1409 : : NGBE_PTID_MASK);
1410 : :
1411 [ # # ]: 0 : if (likely(pkt_flags & RTE_MBUF_F_RX_RSS_HASH))
1412 : 0 : rxm->hash.rss = rte_le_to_cpu_32(rxd.qw0.dw1);
1413 : :
1414 : : /*
1415 : : * Store the mbuf address into the next entry of the array
1416 : : * of returned packets.
1417 : : */
1418 : 0 : rx_pkts[nb_rx++] = rxm;
1419 : : }
1420 : 0 : rxq->rx_tail = rx_id;
1421 : :
1422 : : /*
1423 : : * If the number of free Rx descriptors is greater than the Rx free
1424 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
1425 : : * register.
1426 : : * Update the RDT with the value of the last processed Rx descriptor
1427 : : * minus 1, to guarantee that the RDT register is never equal to the
1428 : : * RDH register, which creates a "full" ring situation from the
1429 : : * hardware point of view...
1430 : : */
1431 : 0 : nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
1432 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
1433 : : PMD_RX_LOG(DEBUG,
1434 : : "port_id=%u queue_id=%u rx_tail=%u nb_hold=%u nb_rx=%u",
1435 : : (uint16_t)rxq->port_id, (uint16_t)rxq->queue_id,
1436 : : (uint16_t)rx_id, (uint16_t)nb_hold,
1437 : : (uint16_t)nb_rx);
1438 [ # # ]: 0 : rx_id = (uint16_t)((rx_id == 0) ?
1439 : 0 : (rxq->nb_rx_desc - 1) : (rx_id - 1));
1440 : 0 : ngbe_set32(rxq->rdt_reg_addr, rx_id);
1441 : : nb_hold = 0;
1442 : : }
1443 : 0 : rxq->nb_rx_hold = nb_hold;
1444 : 0 : return nb_rx;
1445 : : }
1446 : :
1447 : : /**
1448 : : * ngbe_fill_cluster_head_buf - fill the first mbuf of the returned packet
1449 : : *
1450 : : * Fill the following info in the HEAD buffer of the Rx cluster:
1451 : : * - RX port identifier
1452 : : * - hardware offload data, if any:
1453 : : * - RSS flag & hash
1454 : : * - IP checksum flag
1455 : : * - VLAN TCI, if any
1456 : : * - error flags
1457 : : * @head HEAD of the packet cluster
1458 : : * @desc HW descriptor to get data from
1459 : : * @rxq Pointer to the Rx queue
1460 : : */
1461 : : static inline void
1462 : 0 : ngbe_fill_cluster_head_buf(struct rte_mbuf *head, struct ngbe_rx_desc *desc,
1463 : : struct ngbe_rx_queue *rxq, uint32_t staterr)
1464 : : {
1465 : : uint32_t pkt_info;
1466 : : uint64_t pkt_flags;
1467 : :
1468 : 0 : head->port = rxq->port_id;
1469 : :
1470 : : /* The vlan_tci field is only valid when RTE_MBUF_F_RX_VLAN is
1471 : : * set in the pkt_flags field.
1472 : : */
1473 : 0 : head->vlan_tci = rte_le_to_cpu_16(desc->qw1.hi.tag);
1474 : 0 : pkt_info = rte_le_to_cpu_32(desc->qw0.dw0);
1475 [ # # ]: 0 : pkt_flags = rx_desc_status_to_pkt_flags(staterr, rxq->vlan_flags);
1476 : 0 : pkt_flags |= rx_desc_error_to_pkt_flags(staterr, rxq);
1477 : 0 : pkt_flags |= ngbe_rxd_pkt_info_to_pkt_flags(pkt_info);
1478 : 0 : head->ol_flags = pkt_flags;
1479 : 0 : head->packet_type = ngbe_rxd_pkt_info_to_pkt_type(pkt_info,
1480 : : NGBE_PTID_MASK);
1481 : :
1482 [ # # ]: 0 : if (likely(pkt_flags & RTE_MBUF_F_RX_RSS_HASH))
1483 : 0 : head->hash.rss = rte_le_to_cpu_32(desc->qw0.dw1);
1484 : 0 : }
1485 : :
1486 : : /**
1487 : : * ngbe_recv_pkts_sc - receive handler for scatter case.
1488 : : *
1489 : : * @rx_queue Rx queue handle
1490 : : * @rx_pkts table of received packets
1491 : : * @nb_pkts size of rx_pkts table
1492 : : * @bulk_alloc if TRUE bulk allocation is used for a HW ring refilling
1493 : : *
1494 : : * Returns the number of received packets/clusters (according to the "bulk
1495 : : * receive" interface).
1496 : : */
1497 : : static inline uint16_t
1498 : 0 : ngbe_recv_pkts_sc(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts,
1499 : : bool bulk_alloc)
1500 : : {
1501 : : struct ngbe_rx_queue *rxq = rx_queue;
1502 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
1503 : 0 : volatile struct ngbe_rx_desc *rx_ring = rxq->rx_ring;
1504 : 0 : struct ngbe_rx_entry *sw_ring = rxq->sw_ring;
1505 : 0 : struct ngbe_scattered_rx_entry *sw_sc_ring = rxq->sw_sc_ring;
1506 : 0 : uint16_t rx_id = rxq->rx_tail;
1507 : : uint16_t nb_rx = 0;
1508 : 0 : uint16_t nb_hold = rxq->nb_rx_hold;
1509 : : uint16_t prev_id = rxq->rx_tail;
1510 : :
1511 [ # # ]: 0 : while (nb_rx < nb_pkts) {
1512 : : bool eop;
1513 : : struct ngbe_rx_entry *rxe;
1514 : : struct ngbe_scattered_rx_entry *sc_entry;
1515 : : struct ngbe_scattered_rx_entry *next_sc_entry = NULL;
1516 : : struct ngbe_rx_entry *next_rxe = NULL;
1517 : : struct rte_mbuf *first_seg;
1518 : : struct rte_mbuf *rxm;
1519 : : struct rte_mbuf *nmb = NULL;
1520 : : struct ngbe_rx_desc rxd;
1521 : : uint16_t data_len;
1522 : : uint16_t next_id;
1523 : : volatile struct ngbe_rx_desc *rxdp;
1524 : : uint32_t staterr;
1525 : :
1526 : 0 : next_desc:
1527 : 0 : rxdp = &rx_ring[rx_id];
1528 : 0 : staterr = rte_le_to_cpu_32(rxdp->qw1.lo.status);
1529 : :
1530 [ # # ]: 0 : if (!(staterr & NGBE_RXD_STAT_DD))
1531 : : break;
1532 : :
1533 : : /*
1534 : : * Use acquire fence to ensure that status_error which includes
1535 : : * DD bit is loaded before loading of other descriptor words.
1536 : : */
1537 : : rte_atomic_thread_fence(rte_memory_order_acquire);
1538 : :
1539 : 0 : rxd = *rxdp;
1540 : :
1541 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
1542 : : "staterr=0x%x data_len=%u",
1543 : : rxq->port_id, rxq->queue_id, rx_id, staterr,
1544 : : rte_le_to_cpu_16(rxd.qw1.hi.len));
1545 : :
1546 [ # # ]: 0 : if (!bulk_alloc) {
1547 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
1548 [ # # ]: 0 : if (nmb == NULL) {
1549 : : PMD_RX_LOG(DEBUG, "Rx mbuf alloc failed "
1550 : : "port_id=%u queue_id=%u",
1551 : : rxq->port_id, rxq->queue_id);
1552 : :
1553 : 0 : dev->data->rx_mbuf_alloc_failed++;
1554 : 0 : break;
1555 : : }
1556 [ # # ]: 0 : } else if (nb_hold > rxq->rx_free_thresh) {
1557 : 0 : uint16_t next_rdt = rxq->rx_free_trigger;
1558 : :
1559 [ # # ]: 0 : if (!ngbe_rx_alloc_bufs(rxq, false)) {
1560 : : rte_wmb();
1561 : 0 : ngbe_set32_relaxed(rxq->rdt_reg_addr,
1562 : : next_rdt);
1563 : 0 : nb_hold -= rxq->rx_free_thresh;
1564 : : } else {
1565 : : PMD_RX_LOG(DEBUG, "Rx bulk alloc failed "
1566 : : "port_id=%u queue_id=%u",
1567 : : rxq->port_id, rxq->queue_id);
1568 : :
1569 : 0 : dev->data->rx_mbuf_alloc_failed++;
1570 : 0 : break;
1571 : : }
1572 : : }
1573 : :
1574 : 0 : nb_hold++;
1575 : 0 : rxe = &sw_ring[rx_id];
1576 : 0 : eop = staterr & NGBE_RXD_STAT_EOP;
1577 : :
1578 : 0 : next_id = rx_id + 1;
1579 [ # # ]: 0 : if (next_id == rxq->nb_rx_desc)
1580 : : next_id = 0;
1581 : :
1582 : : /* Prefetch next mbuf while processing current one. */
1583 : 0 : rte_ngbe_prefetch(sw_ring[next_id].mbuf);
1584 : :
1585 : : /*
1586 : : * When next Rx descriptor is on a cache-line boundary,
1587 : : * prefetch the next 4 RX descriptors and the next 4 pointers
1588 : : * to mbufs.
1589 : : */
1590 [ # # ]: 0 : if ((next_id & 0x3) == 0) {
1591 : 0 : rte_ngbe_prefetch(&rx_ring[next_id]);
1592 : : rte_ngbe_prefetch(&sw_ring[next_id]);
1593 : : }
1594 : :
1595 : 0 : rxm = rxe->mbuf;
1596 : :
1597 [ # # ]: 0 : if (!bulk_alloc) {
1598 : : __le64 dma =
1599 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1600 : : /*
1601 : : * Update Rx descriptor with the physical address of the
1602 : : * new data buffer of the new allocated mbuf.
1603 : : */
1604 : 0 : rxe->mbuf = nmb;
1605 : :
1606 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
1607 : 0 : NGBE_RXD_HDRADDR(rxdp, 0);
1608 : 0 : NGBE_RXD_PKTADDR(rxdp, dma);
1609 : : } else {
1610 : 0 : rxe->mbuf = NULL;
1611 : : }
1612 : :
1613 : : /*
1614 : : * Set data length & data buffer address of mbuf.
1615 : : */
1616 : 0 : data_len = rte_le_to_cpu_16(rxd.qw1.hi.len);
1617 : 0 : rxm->data_len = data_len;
1618 : :
1619 [ # # ]: 0 : if (!eop) {
1620 : : uint16_t nextp_id;
1621 : :
1622 : : nextp_id = next_id;
1623 : 0 : next_sc_entry = &sw_sc_ring[nextp_id];
1624 : : next_rxe = &sw_ring[nextp_id];
1625 : : rte_ngbe_prefetch(next_rxe);
1626 : : }
1627 : :
1628 : 0 : sc_entry = &sw_sc_ring[rx_id];
1629 : 0 : first_seg = sc_entry->fbuf;
1630 : 0 : sc_entry->fbuf = NULL;
1631 : :
1632 : : /*
1633 : : * If this is the first buffer of the received packet,
1634 : : * set the pointer to the first mbuf of the packet and
1635 : : * initialize its context.
1636 : : * Otherwise, update the total length and the number of segments
1637 : : * of the current scattered packet, and update the pointer to
1638 : : * the last mbuf of the current packet.
1639 : : */
1640 [ # # ]: 0 : if (first_seg == NULL) {
1641 : : first_seg = rxm;
1642 : 0 : first_seg->pkt_len = data_len;
1643 : 0 : first_seg->nb_segs = 1;
1644 : : } else {
1645 : 0 : first_seg->pkt_len += data_len;
1646 : 0 : first_seg->nb_segs++;
1647 : : }
1648 : :
1649 : : prev_id = rx_id;
1650 : : rx_id = next_id;
1651 : :
1652 : : /*
1653 : : * If this is not the last buffer of the received packet, update
1654 : : * the pointer to the first mbuf at the NEXTP entry in the
1655 : : * sw_sc_ring and continue to parse the Rx ring.
1656 : : */
1657 [ # # ]: 0 : if (!eop && next_rxe) {
1658 : 0 : rxm->next = next_rxe->mbuf;
1659 : 0 : next_sc_entry->fbuf = first_seg;
1660 : 0 : goto next_desc;
1661 : : }
1662 : :
1663 : : /* Initialize the first mbuf of the returned packet */
1664 : 0 : ngbe_fill_cluster_head_buf(first_seg, &rxd, rxq, staterr);
1665 : :
1666 : : /* Deal with the case, when HW CRC srip is disabled. */
1667 : 0 : first_seg->pkt_len -= rxq->crc_len;
1668 [ # # ]: 0 : if (unlikely(rxm->data_len <= rxq->crc_len)) {
1669 : : struct rte_mbuf *lp;
1670 : :
1671 [ # # ]: 0 : for (lp = first_seg; lp->next != rxm; lp = lp->next)
1672 : : ;
1673 : :
1674 : 0 : first_seg->nb_segs--;
1675 : 0 : lp->data_len -= rxq->crc_len - rxm->data_len;
1676 [ # # ]: 0 : lp->next = NULL;
1677 : : rte_pktmbuf_free_seg(rxm);
1678 : : } else {
1679 : 0 : rxm->data_len -= rxq->crc_len;
1680 : : }
1681 : :
1682 : : /* Prefetch data of first segment, if configured to do so. */
1683 : 0 : rte_packet_prefetch((char *)first_seg->buf_addr +
1684 : : first_seg->data_off);
1685 : :
1686 : : /*
1687 : : * Store the mbuf address into the next entry of the array
1688 : : * of returned packets.
1689 : : */
1690 : 0 : rx_pkts[nb_rx++] = first_seg;
1691 : : }
1692 : :
1693 : : /*
1694 : : * Record index of the next Rx descriptor to probe.
1695 : : */
1696 : 0 : rxq->rx_tail = rx_id;
1697 : :
1698 : : /*
1699 : : * If the number of free Rx descriptors is greater than the Rx free
1700 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
1701 : : * register.
1702 : : * Update the RDT with the value of the last processed Rx descriptor
1703 : : * minus 1, to guarantee that the RDT register is never equal to the
1704 : : * RDH register, which creates a "full" ring situation from the
1705 : : * hardware point of view...
1706 : : */
1707 [ # # # # ]: 0 : if (!bulk_alloc && nb_hold > rxq->rx_free_thresh) {
1708 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
1709 : : "nb_hold=%u nb_rx=%u",
1710 : : rxq->port_id, rxq->queue_id, rx_id, nb_hold, nb_rx);
1711 : :
1712 : : rte_wmb();
1713 : 0 : ngbe_set32_relaxed(rxq->rdt_reg_addr, prev_id);
1714 : : nb_hold = 0;
1715 : : }
1716 : :
1717 : 0 : rxq->nb_rx_hold = nb_hold;
1718 : 0 : return nb_rx;
1719 : : }
1720 : :
1721 : : uint16_t
1722 : 0 : ngbe_recv_pkts_sc_single_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
1723 : : uint16_t nb_pkts)
1724 : : {
1725 : 0 : return ngbe_recv_pkts_sc(rx_queue, rx_pkts, nb_pkts, false);
1726 : : }
1727 : :
1728 : : uint16_t
1729 : 0 : ngbe_recv_pkts_sc_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
1730 : : uint16_t nb_pkts)
1731 : : {
1732 : 0 : return ngbe_recv_pkts_sc(rx_queue, rx_pkts, nb_pkts, true);
1733 : : }
1734 : :
1735 : : /*********************************************************************
1736 : : *
1737 : : * Queue management functions
1738 : : *
1739 : : **********************************************************************/
1740 : :
1741 : : static void
1742 : 0 : ngbe_tx_queue_release_mbufs(struct ngbe_tx_queue *txq)
1743 : : {
1744 : : unsigned int i;
1745 : :
1746 [ # # ]: 0 : if (txq->sw_ring != NULL) {
1747 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
1748 [ # # ]: 0 : if (txq->sw_ring[i].mbuf != NULL) {
1749 : : rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
1750 : 0 : txq->sw_ring[i].mbuf = NULL;
1751 : : }
1752 : : }
1753 : : }
1754 : 0 : }
1755 : :
1756 : : static int
1757 : 0 : ngbe_tx_done_cleanup_full(struct ngbe_tx_queue *txq, uint32_t free_cnt)
1758 : : {
1759 : 0 : struct ngbe_tx_entry *swr_ring = txq->sw_ring;
1760 : : uint16_t i, tx_last, tx_id;
1761 : : uint16_t nb_tx_free_last;
1762 : : uint16_t nb_tx_to_clean;
1763 : : uint32_t pkt_cnt;
1764 : :
1765 : : /* Start free mbuf from the next of tx_tail */
1766 : 0 : tx_last = txq->tx_tail;
1767 : 0 : tx_id = swr_ring[tx_last].next_id;
1768 : :
1769 [ # # # # ]: 0 : if (txq->nb_tx_free == 0 && ngbe_xmit_cleanup(txq))
1770 : : return 0;
1771 : :
1772 : 0 : nb_tx_to_clean = txq->nb_tx_free;
1773 : : nb_tx_free_last = txq->nb_tx_free;
1774 [ # # ]: 0 : if (!free_cnt)
1775 : 0 : free_cnt = txq->nb_tx_desc;
1776 : :
1777 : : /* Loop through swr_ring to count the amount of
1778 : : * freeable mubfs and packets.
1779 : : */
1780 [ # # ]: 0 : for (pkt_cnt = 0; pkt_cnt < free_cnt; ) {
1781 : 0 : for (i = 0; i < nb_tx_to_clean &&
1782 [ # # # # ]: 0 : pkt_cnt < free_cnt &&
1783 : 0 : tx_id != tx_last; i++) {
1784 [ # # ]: 0 : if (swr_ring[tx_id].mbuf != NULL) {
1785 : : rte_pktmbuf_free_seg(swr_ring[tx_id].mbuf);
1786 : 0 : swr_ring[tx_id].mbuf = NULL;
1787 : :
1788 : : /*
1789 : : * last segment in the packet,
1790 : : * increment packet count
1791 : : */
1792 : 0 : pkt_cnt += (swr_ring[tx_id].last_id == tx_id);
1793 : : }
1794 : :
1795 : 0 : tx_id = swr_ring[tx_id].next_id;
1796 : : }
1797 : :
1798 [ # # ]: 0 : if (pkt_cnt < free_cnt) {
1799 [ # # ]: 0 : if (ngbe_xmit_cleanup(txq))
1800 : : break;
1801 : :
1802 : 0 : nb_tx_to_clean = txq->nb_tx_free - nb_tx_free_last;
1803 : : nb_tx_free_last = txq->nb_tx_free;
1804 : : }
1805 : : }
1806 : :
1807 : 0 : return (int)pkt_cnt;
1808 : : }
1809 : :
1810 : : static int
1811 : 0 : ngbe_tx_done_cleanup_simple(struct ngbe_tx_queue *txq,
1812 : : uint32_t free_cnt)
1813 : : {
1814 : : int i, n, cnt;
1815 : :
1816 [ # # # # ]: 0 : if (free_cnt == 0 || free_cnt > txq->nb_tx_desc)
1817 : 0 : free_cnt = txq->nb_tx_desc;
1818 : :
1819 : 0 : cnt = free_cnt - free_cnt % txq->tx_free_thresh;
1820 : :
1821 [ # # ]: 0 : for (i = 0; i < cnt; i += n) {
1822 [ # # ]: 0 : if (txq->nb_tx_desc - txq->nb_tx_free < txq->tx_free_thresh)
1823 : : break;
1824 : :
1825 : : n = ngbe_tx_free_bufs(txq);
1826 : :
1827 [ # # ]: 0 : if (n == 0)
1828 : : break;
1829 : : }
1830 : :
1831 : 0 : return i;
1832 : : }
1833 : :
1834 : : int
1835 : 0 : ngbe_dev_tx_done_cleanup(void *tx_queue, uint32_t free_cnt)
1836 : : {
1837 : : struct ngbe_tx_queue *txq = (struct ngbe_tx_queue *)tx_queue;
1838 [ # # ]: 0 : if (txq->offloads == 0 &&
1839 [ # # ]: 0 : txq->tx_free_thresh >= RTE_PMD_NGBE_TX_MAX_BURST)
1840 : 0 : return ngbe_tx_done_cleanup_simple(txq, free_cnt);
1841 : :
1842 : 0 : return ngbe_tx_done_cleanup_full(txq, free_cnt);
1843 : : }
1844 : :
1845 : : static void
1846 : 0 : ngbe_tx_free_swring(struct ngbe_tx_queue *txq)
1847 : : {
1848 [ # # ]: 0 : if (txq != NULL)
1849 : 0 : rte_free(txq->sw_ring);
1850 : 0 : }
1851 : :
1852 : : static void
1853 : 0 : ngbe_tx_queue_release(struct ngbe_tx_queue *txq)
1854 : : {
1855 [ # # ]: 0 : if (txq != NULL) {
1856 [ # # ]: 0 : if (txq->ops != NULL) {
1857 : 0 : txq->ops->release_mbufs(txq);
1858 : 0 : txq->ops->free_swring(txq);
1859 : 0 : rte_memzone_free(txq->mz);
1860 : : }
1861 : 0 : rte_free(txq);
1862 : : }
1863 : 0 : }
1864 : :
1865 : : void
1866 : 0 : ngbe_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1867 : : {
1868 : 0 : ngbe_tx_queue_release(dev->data->tx_queues[qid]);
1869 : 0 : }
1870 : :
1871 : : /* (Re)set dynamic ngbe_tx_queue fields to defaults */
1872 : : static void
1873 : 0 : ngbe_reset_tx_queue(struct ngbe_tx_queue *txq)
1874 : : {
1875 : : static const struct ngbe_tx_desc zeroed_desc = {0};
1876 : 0 : struct ngbe_tx_entry *txe = txq->sw_ring;
1877 : : uint16_t prev, i;
1878 : :
1879 : : /* Zero out HW ring memory */
1880 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++)
1881 : 0 : txq->tx_ring[i] = zeroed_desc;
1882 : :
1883 : : /* Initialize SW ring entries */
1884 : 0 : prev = (uint16_t)(txq->nb_tx_desc - 1);
1885 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
1886 : : /* the ring can also be modified by hardware */
1887 : 0 : volatile struct ngbe_tx_desc *txd = &txq->tx_ring[i];
1888 : :
1889 : 0 : txd->dw3 = rte_cpu_to_le_32(NGBE_TXD_DD);
1890 : 0 : txe[i].mbuf = NULL;
1891 : 0 : txe[i].last_id = i;
1892 : 0 : txe[prev].next_id = i;
1893 : : prev = i;
1894 : : }
1895 : :
1896 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_free_thresh - 1);
1897 : 0 : txq->tx_tail = 0;
1898 : :
1899 : : /*
1900 : : * Always allow 1 descriptor to be un-allocated to avoid
1901 : : * a H/W race condition
1902 : : */
1903 : 0 : txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
1904 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
1905 : 0 : txq->ctx_curr = 0;
1906 : 0 : memset((void *)&txq->ctx_cache, 0,
1907 : : NGBE_CTX_NUM * sizeof(struct ngbe_ctx_info));
1908 : 0 : }
1909 : :
1910 : : static const struct ngbe_txq_ops def_txq_ops = {
1911 : : .release_mbufs = ngbe_tx_queue_release_mbufs,
1912 : : .free_swring = ngbe_tx_free_swring,
1913 : : .reset = ngbe_reset_tx_queue,
1914 : : };
1915 : :
1916 : : /* Takes an ethdev and a queue and sets up the tx function to be used based on
1917 : : * the queue parameters. Used in tx_queue_setup by primary process and then
1918 : : * in dev_init by secondary process when attaching to an existing ethdev.
1919 : : */
1920 : : void
1921 : 0 : ngbe_set_tx_function(struct rte_eth_dev *dev, struct ngbe_tx_queue *txq)
1922 : : {
1923 : : /* Use a simple Tx queue (no offloads, no multi segs) if possible */
1924 [ # # ]: 0 : if (txq->offloads == 0 &&
1925 [ # # ]: 0 : txq->tx_free_thresh >= RTE_PMD_NGBE_TX_MAX_BURST) {
1926 : 0 : PMD_INIT_LOG(DEBUG, "Using simple tx code path");
1927 : 0 : dev->tx_pkt_prepare = rte_eth_tx_pkt_prepare_dummy;
1928 [ # # # # ]: 0 : if (txq->tx_free_thresh <= RTE_NGBE_TX_MAX_FREE_BUF_SZ &&
1929 [ # # ]: 0 : rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128 &&
1930 [ # # ]: 0 : (rte_eal_process_type() != RTE_PROC_PRIMARY ||
1931 : 0 : ngbe_txq_vec_setup(txq) == 0)) {
1932 : 0 : PMD_INIT_LOG(DEBUG, "Vector tx enabled.");
1933 : 0 : dev->tx_pkt_burst = ngbe_xmit_pkts_vec;
1934 : : } else {
1935 : 0 : dev->tx_pkt_burst = ngbe_xmit_pkts_simple;
1936 : : }
1937 : : } else {
1938 : 0 : PMD_INIT_LOG(DEBUG, "Using full-featured tx code path");
1939 : 0 : PMD_INIT_LOG(DEBUG,
1940 : : " - offloads = 0x%" PRIx64,
1941 : : txq->offloads);
1942 : 0 : PMD_INIT_LOG(DEBUG,
1943 : : " - tx_free_thresh = %lu [RTE_PMD_NGBE_TX_MAX_BURST=%lu]",
1944 : : (unsigned long)txq->tx_free_thresh,
1945 : : (unsigned long)RTE_PMD_NGBE_TX_MAX_BURST);
1946 : 0 : dev->tx_pkt_burst = ngbe_xmit_pkts;
1947 : 0 : dev->tx_pkt_prepare = ngbe_prep_pkts;
1948 : : }
1949 : 0 : }
1950 : :
1951 : : static const struct {
1952 : : eth_tx_burst_t pkt_burst;
1953 : : const char *info;
1954 : : } ngbe_tx_burst_infos[] = {
1955 : : { ngbe_xmit_pkts_simple, "Scalar Simple"},
1956 : : { ngbe_xmit_pkts, "Scalar"},
1957 : : #ifdef RTE_ARCH_X86
1958 : : { ngbe_xmit_pkts_vec, "Vector SSE" },
1959 : : #elif defined(RTE_ARCH_ARM)
1960 : : { ngbe_xmit_pkts_vec, "Vector Neon" },
1961 : : #endif
1962 : : };
1963 : :
1964 : : int
1965 : 0 : ngbe_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
1966 : : struct rte_eth_burst_mode *mode)
1967 : : {
1968 : 0 : eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
1969 : : int ret = -EINVAL;
1970 : : unsigned int i;
1971 : :
1972 [ # # ]: 0 : for (i = 0; i < RTE_DIM(ngbe_tx_burst_infos); ++i) {
1973 [ # # ]: 0 : if (pkt_burst == ngbe_tx_burst_infos[i].pkt_burst) {
1974 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
1975 : 0 : ngbe_tx_burst_infos[i].info);
1976 : : ret = 0;
1977 : 0 : break;
1978 : : }
1979 : : }
1980 : :
1981 : 0 : return ret;
1982 : : }
1983 : :
1984 : : uint64_t
1985 [ # # ]: 0 : ngbe_get_tx_port_offloads(struct rte_eth_dev *dev)
1986 : : {
1987 : : uint64_t tx_offload_capa;
1988 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1989 : :
1990 : : tx_offload_capa =
1991 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
1992 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
1993 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
1994 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
1995 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
1996 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
1997 : : RTE_ETH_TX_OFFLOAD_UDP_TSO |
1998 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
1999 : :
2000 [ # # ]: 0 : if (hw->is_pf)
2001 : : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_QINQ_INSERT;
2002 : :
2003 : 0 : return tx_offload_capa;
2004 : : }
2005 : :
2006 : : int
2007 : 0 : ngbe_dev_tx_queue_setup(struct rte_eth_dev *dev,
2008 : : uint16_t queue_idx,
2009 : : uint16_t nb_desc,
2010 : : unsigned int socket_id,
2011 : : const struct rte_eth_txconf *tx_conf)
2012 : : {
2013 : : const struct rte_memzone *tz;
2014 : : struct ngbe_tx_queue *txq;
2015 : : struct ngbe_hw *hw;
2016 : : uint16_t tx_free_thresh;
2017 : : uint64_t offloads;
2018 : :
2019 : 0 : PMD_INIT_FUNC_TRACE();
2020 : : hw = ngbe_dev_hw(dev);
2021 : :
2022 : 0 : offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
2023 : :
2024 : : /*
2025 : : * The Tx descriptor ring will be cleaned after txq->tx_free_thresh
2026 : : * descriptors are used or if the number of descriptors required
2027 : : * to transmit a packet is greater than the number of free Tx
2028 : : * descriptors.
2029 : : * One descriptor in the Tx ring is used as a sentinel to avoid a
2030 : : * H/W race condition, hence the maximum threshold constraints.
2031 : : * When set to zero use default values.
2032 : : */
2033 [ # # ]: 0 : tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
2034 : : tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH);
2035 [ # # ]: 0 : if (tx_free_thresh >= (nb_desc - 3)) {
2036 : 0 : PMD_INIT_LOG(ERR,
2037 : : "tx_free_thresh must be less than the number of TX descriptors minus 3. (tx_free_thresh=%u port=%d queue=%d)",
2038 : : (unsigned int)tx_free_thresh,
2039 : : (int)dev->data->port_id, (int)queue_idx);
2040 : 0 : return -(EINVAL);
2041 : : }
2042 : :
2043 [ # # ]: 0 : if (nb_desc % tx_free_thresh != 0) {
2044 : 0 : PMD_INIT_LOG(ERR,
2045 : : "tx_free_thresh must be a divisor of the number of Tx descriptors. (tx_free_thresh=%u port=%d queue=%d)",
2046 : : (unsigned int)tx_free_thresh,
2047 : : (int)dev->data->port_id, (int)queue_idx);
2048 : 0 : return -(EINVAL);
2049 : : }
2050 : :
2051 : : /* Free memory prior to re-allocation if needed... */
2052 [ # # ]: 0 : if (dev->data->tx_queues[queue_idx] != NULL) {
2053 : 0 : ngbe_tx_queue_release(dev->data->tx_queues[queue_idx]);
2054 : 0 : dev->data->tx_queues[queue_idx] = NULL;
2055 : : }
2056 : :
2057 : : /* First allocate the Tx queue data structure */
2058 : 0 : txq = rte_zmalloc_socket("ethdev Tx queue",
2059 : : sizeof(struct ngbe_tx_queue),
2060 : : RTE_CACHE_LINE_SIZE, socket_id);
2061 [ # # ]: 0 : if (txq == NULL)
2062 : : return -ENOMEM;
2063 : :
2064 : : /* Allocate Tx ring hardware descriptors. */
2065 : 0 : tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx,
2066 : : sizeof(struct ngbe_tx_desc) * nb_desc,
2067 : : NGBE_ALIGN, socket_id);
2068 [ # # ]: 0 : if (tz == NULL) {
2069 : 0 : ngbe_tx_queue_release(txq);
2070 : 0 : return -ENOMEM;
2071 : : }
2072 : :
2073 : 0 : txq->mz = tz;
2074 : 0 : txq->nb_tx_desc = nb_desc;
2075 : 0 : txq->tx_free_thresh = tx_free_thresh;
2076 : 0 : txq->pthresh = tx_conf->tx_thresh.pthresh;
2077 : 0 : txq->hthresh = tx_conf->tx_thresh.hthresh;
2078 : 0 : txq->wthresh = tx_conf->tx_thresh.wthresh;
2079 : 0 : txq->queue_id = queue_idx;
2080 [ # # ]: 0 : txq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
2081 : 0 : queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
2082 : 0 : txq->port_id = dev->data->port_id;
2083 : 0 : txq->offloads = offloads;
2084 : 0 : txq->ops = &def_txq_ops;
2085 : 0 : txq->tx_deferred_start = tx_conf->tx_deferred_start;
2086 : :
2087 : 0 : txq->tdt_reg_addr = NGBE_REG_ADDR(hw, NGBE_TXWP(txq->reg_idx));
2088 : 0 : txq->tdc_reg_addr = NGBE_REG_ADDR(hw, NGBE_TXCFG(txq->reg_idx));
2089 : :
2090 : 0 : txq->tx_ring_phys_addr = TMZ_PADDR(tz);
2091 : 0 : txq->tx_ring = (struct ngbe_tx_desc *)TMZ_VADDR(tz);
2092 : :
2093 : : /* Allocate software ring */
2094 : 0 : txq->sw_ring = rte_zmalloc_socket("txq->sw_ring",
2095 : : sizeof(struct ngbe_tx_entry) * nb_desc,
2096 : : RTE_CACHE_LINE_SIZE, socket_id);
2097 [ # # ]: 0 : if (txq->sw_ring == NULL) {
2098 : 0 : ngbe_tx_queue_release(txq);
2099 : 0 : return -ENOMEM;
2100 : : }
2101 : 0 : PMD_INIT_LOG(DEBUG,
2102 : : "sw_ring=%p hw_ring=%p dma_addr=0x%" PRIx64,
2103 : : txq->sw_ring, txq->tx_ring, txq->tx_ring_phys_addr);
2104 : :
2105 : : /* set up scalar Tx function as appropriate */
2106 : 0 : ngbe_set_tx_function(dev, txq);
2107 : :
2108 : 0 : txq->ops->reset(txq);
2109 : 0 : txq->desc_error = 0;
2110 : :
2111 : 0 : dev->data->tx_queues[queue_idx] = txq;
2112 : :
2113 : 0 : return 0;
2114 : : }
2115 : :
2116 : : /**
2117 : : * ngbe_free_sc_cluster - free the not-yet-completed scattered cluster
2118 : : *
2119 : : * The "next" pointer of the last segment of (not-yet-completed) RSC clusters
2120 : : * in the sw_sc_ring is not set to NULL but rather points to the next
2121 : : * mbuf of this RSC aggregation (that has not been completed yet and still
2122 : : * resides on the HW ring). So, instead of calling for rte_pktmbuf_free() we
2123 : : * will just free first "nb_segs" segments of the cluster explicitly by calling
2124 : : * an rte_pktmbuf_free_seg().
2125 : : *
2126 : : * @m scattered cluster head
2127 : : */
2128 : : static void
2129 : 0 : ngbe_free_sc_cluster(struct rte_mbuf *m)
2130 : : {
2131 : 0 : uint16_t i, nb_segs = m->nb_segs;
2132 : : struct rte_mbuf *next_seg;
2133 : :
2134 [ # # ]: 0 : for (i = 0; i < nb_segs; i++) {
2135 : 0 : next_seg = m->next;
2136 : : rte_pktmbuf_free_seg(m);
2137 : : m = next_seg;
2138 : : }
2139 : 0 : }
2140 : :
2141 : : static void
2142 : 0 : ngbe_rx_queue_release_mbufs(struct ngbe_rx_queue *rxq)
2143 : : {
2144 : : unsigned int i;
2145 : :
2146 : : /* SSE Vector driver has a different way of releasing mbufs. */
2147 [ # # ]: 0 : if (rxq->rx_using_sse) {
2148 : 0 : ngbe_rx_queue_release_mbufs_vec(rxq);
2149 : 0 : return;
2150 : : }
2151 : :
2152 [ # # ]: 0 : if (rxq->sw_ring != NULL) {
2153 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
2154 [ # # ]: 0 : if (rxq->sw_ring[i].mbuf != NULL) {
2155 : : rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
2156 : 0 : rxq->sw_ring[i].mbuf = NULL;
2157 : : }
2158 : : }
2159 [ # # ]: 0 : for (i = 0; i < rxq->rx_nb_avail; ++i) {
2160 : : struct rte_mbuf *mb;
2161 : :
2162 [ # # ]: 0 : mb = rxq->rx_stage[rxq->rx_next_avail + i];
2163 : : rte_pktmbuf_free_seg(mb);
2164 : : }
2165 : 0 : rxq->rx_nb_avail = 0;
2166 : : }
2167 : :
2168 [ # # ]: 0 : if (rxq->sw_sc_ring != NULL)
2169 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++)
2170 [ # # ]: 0 : if (rxq->sw_sc_ring[i].fbuf != NULL) {
2171 : 0 : ngbe_free_sc_cluster(rxq->sw_sc_ring[i].fbuf);
2172 : 0 : rxq->sw_sc_ring[i].fbuf = NULL;
2173 : : }
2174 : : }
2175 : :
2176 : : static void
2177 : 0 : ngbe_rx_queue_release(struct ngbe_rx_queue *rxq)
2178 : : {
2179 [ # # ]: 0 : if (rxq != NULL) {
2180 : 0 : ngbe_rx_queue_release_mbufs(rxq);
2181 : 0 : rte_free(rxq->sw_ring);
2182 : 0 : rte_free(rxq->sw_sc_ring);
2183 : 0 : rte_memzone_free(rxq->mz);
2184 : 0 : rte_free(rxq);
2185 : : }
2186 : 0 : }
2187 : :
2188 : : void
2189 : 0 : ngbe_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2190 : : {
2191 : 0 : ngbe_rx_queue_release(dev->data->rx_queues[qid]);
2192 : 0 : }
2193 : :
2194 : : /*
2195 : : * Check if Rx Burst Bulk Alloc function can be used.
2196 : : * Return
2197 : : * 0: the preconditions are satisfied and the bulk allocation function
2198 : : * can be used.
2199 : : * -EINVAL: the preconditions are NOT satisfied and the default Rx burst
2200 : : * function must be used.
2201 : : */
2202 : : static inline int
2203 : 0 : check_rx_burst_bulk_alloc_preconditions(struct ngbe_rx_queue *rxq)
2204 : : {
2205 : : int ret = 0;
2206 : :
2207 : : /*
2208 : : * Make sure the following pre-conditions are satisfied:
2209 : : * rxq->rx_free_thresh >= RTE_PMD_NGBE_RX_MAX_BURST
2210 : : * rxq->rx_free_thresh < rxq->nb_rx_desc
2211 : : * (rxq->nb_rx_desc % rxq->rx_free_thresh) == 0
2212 : : * Scattered packets are not supported. This should be checked
2213 : : * outside of this function.
2214 : : */
2215 [ # # ]: 0 : if (rxq->rx_free_thresh < RTE_PMD_NGBE_RX_MAX_BURST) {
2216 : 0 : PMD_INIT_LOG(DEBUG,
2217 : : "Rx Burst Bulk Alloc Preconditions: rxq->rx_free_thresh=%d, RTE_PMD_NGBE_RX_MAX_BURST=%d",
2218 : : rxq->rx_free_thresh, RTE_PMD_NGBE_RX_MAX_BURST);
2219 : : ret = -EINVAL;
2220 [ # # ]: 0 : } else if (rxq->rx_free_thresh >= rxq->nb_rx_desc) {
2221 : 0 : PMD_INIT_LOG(DEBUG,
2222 : : "Rx Burst Bulk Alloc Preconditions: rxq->rx_free_thresh=%d, rxq->nb_rx_desc=%d",
2223 : : rxq->rx_free_thresh, rxq->nb_rx_desc);
2224 : : ret = -EINVAL;
2225 [ # # ]: 0 : } else if ((rxq->nb_rx_desc % rxq->rx_free_thresh) != 0) {
2226 : 0 : PMD_INIT_LOG(DEBUG,
2227 : : "Rx Burst Bulk Alloc Preconditions: rxq->nb_rx_desc=%d, rxq->rx_free_thresh=%d",
2228 : : rxq->nb_rx_desc, rxq->rx_free_thresh);
2229 : : ret = -EINVAL;
2230 : : }
2231 : :
2232 : 0 : return ret;
2233 : : }
2234 : :
2235 : : /* Reset dynamic ngbe_rx_queue fields back to defaults */
2236 : : static void
2237 : 0 : ngbe_reset_rx_queue(struct ngbe_adapter *adapter, struct ngbe_rx_queue *rxq)
2238 : : {
2239 : : static const struct ngbe_rx_desc zeroed_desc = {
2240 : : {{0}, {0} }, {{0}, {0} } };
2241 : : unsigned int i;
2242 : 0 : uint16_t len = rxq->nb_rx_desc;
2243 : :
2244 : : /*
2245 : : * By default, the Rx queue setup function allocates enough memory for
2246 : : * NGBE_RING_DESC_MAX. The Rx Burst bulk allocation function requires
2247 : : * extra memory at the end of the descriptor ring to be zero'd out.
2248 : : */
2249 [ # # ]: 0 : if (adapter->rx_bulk_alloc_allowed)
2250 : : /* zero out extra memory */
2251 : 0 : len += RTE_PMD_NGBE_RX_MAX_BURST;
2252 : :
2253 : : /*
2254 : : * Zero out HW ring memory. Zero out extra memory at the end of
2255 : : * the H/W ring so look-ahead logic in Rx Burst bulk alloc function
2256 : : * reads extra memory as zeros.
2257 : : */
2258 [ # # ]: 0 : for (i = 0; i < len; i++)
2259 : 0 : rxq->rx_ring[i] = zeroed_desc;
2260 : :
2261 : : /*
2262 : : * initialize extra software ring entries. Space for these extra
2263 : : * entries is always allocated
2264 : : */
2265 : 0 : memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
2266 [ # # ]: 0 : for (i = rxq->nb_rx_desc; i < len; ++i)
2267 : 0 : rxq->sw_ring[i].mbuf = &rxq->fake_mbuf;
2268 : :
2269 : 0 : rxq->rx_nb_avail = 0;
2270 : 0 : rxq->rx_next_avail = 0;
2271 : 0 : rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
2272 : 0 : rxq->rx_tail = 0;
2273 : 0 : rxq->nb_rx_hold = 0;
2274 : 0 : rxq->csum_err = 0;
2275 : 0 : rte_pktmbuf_free(rxq->pkt_first_seg);
2276 : 0 : rxq->pkt_first_seg = NULL;
2277 : 0 : rxq->pkt_last_seg = NULL;
2278 : :
2279 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM)
2280 : 0 : rxq->rxrearm_start = 0;
2281 : 0 : rxq->rxrearm_nb = 0;
2282 : : #endif
2283 : 0 : }
2284 : :
2285 : : uint64_t
2286 : 0 : ngbe_get_rx_queue_offloads(struct rte_eth_dev *dev __rte_unused)
2287 : : {
2288 : 0 : return RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
2289 : : }
2290 : :
2291 : : uint64_t
2292 [ # # ]: 0 : ngbe_get_rx_port_offloads(struct rte_eth_dev *dev)
2293 : : {
2294 : : uint64_t offloads;
2295 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
2296 : :
2297 : : offloads = RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
2298 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
2299 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
2300 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
2301 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
2302 : : RTE_ETH_RX_OFFLOAD_RSS_HASH |
2303 : : RTE_ETH_RX_OFFLOAD_SCATTER;
2304 : :
2305 [ # # ]: 0 : if (hw->is_pf)
2306 : : offloads |= (RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
2307 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND);
2308 : :
2309 : 0 : return offloads;
2310 : : }
2311 : :
2312 : : int
2313 : 0 : ngbe_dev_rx_queue_setup(struct rte_eth_dev *dev,
2314 : : uint16_t queue_idx,
2315 : : uint16_t nb_desc,
2316 : : unsigned int socket_id,
2317 : : const struct rte_eth_rxconf *rx_conf,
2318 : : struct rte_mempool *mp)
2319 : : {
2320 : : const struct rte_memzone *rz;
2321 : : struct ngbe_rx_queue *rxq;
2322 : : struct ngbe_hw *hw;
2323 : : uint16_t len;
2324 : : struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2325 : : uint64_t offloads;
2326 : : uint32_t size;
2327 : :
2328 : 0 : PMD_INIT_FUNC_TRACE();
2329 : : hw = ngbe_dev_hw(dev);
2330 : :
2331 : 0 : offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
2332 : :
2333 : : /* Free memory prior to re-allocation if needed... */
2334 [ # # ]: 0 : if (dev->data->rx_queues[queue_idx] != NULL) {
2335 : 0 : ngbe_rx_queue_release(dev->data->rx_queues[queue_idx]);
2336 : 0 : dev->data->rx_queues[queue_idx] = NULL;
2337 : : }
2338 : :
2339 : : /* First allocate the Rx queue data structure */
2340 : 0 : rxq = rte_zmalloc_socket("ethdev RX queue",
2341 : : sizeof(struct ngbe_rx_queue),
2342 : : RTE_CACHE_LINE_SIZE, socket_id);
2343 [ # # ]: 0 : if (rxq == NULL)
2344 : : return -ENOMEM;
2345 : 0 : rxq->mb_pool = mp;
2346 : 0 : rxq->nb_rx_desc = nb_desc;
2347 : 0 : rxq->rx_free_thresh = rx_conf->rx_free_thresh;
2348 : 0 : rxq->queue_id = queue_idx;
2349 [ # # ]: 0 : rxq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
2350 : 0 : queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
2351 : 0 : rxq->port_id = dev->data->port_id;
2352 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
2353 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
2354 : : else
2355 : 0 : rxq->crc_len = 0;
2356 : 0 : rxq->drop_en = rx_conf->rx_drop_en;
2357 : 0 : rxq->rx_deferred_start = rx_conf->rx_deferred_start;
2358 : 0 : rxq->offloads = offloads;
2359 : :
2360 : : /* Allocate Rx ring hardware descriptors. */
2361 : 0 : size = (nb_desc + RTE_PMD_NGBE_RX_MAX_BURST) * sizeof(struct ngbe_rx_desc);
2362 : 0 : rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
2363 : : size, NGBE_ALIGN, socket_id);
2364 [ # # ]: 0 : if (rz == NULL) {
2365 : 0 : ngbe_rx_queue_release(rxq);
2366 : 0 : return -ENOMEM;
2367 : : }
2368 : :
2369 : 0 : rxq->mz = rz;
2370 : : /*
2371 : : * Zero init all the descriptors in the ring.
2372 : : */
2373 : 0 : memset(rz->addr, 0, size);
2374 : :
2375 : 0 : rxq->rdt_reg_addr = NGBE_REG_ADDR(hw, NGBE_RXWP(rxq->reg_idx));
2376 : 0 : rxq->rdh_reg_addr = NGBE_REG_ADDR(hw, NGBE_RXRP(rxq->reg_idx));
2377 : :
2378 : 0 : rxq->rx_ring_phys_addr = TMZ_PADDR(rz);
2379 : 0 : rxq->rx_ring = (struct ngbe_rx_desc *)TMZ_VADDR(rz);
2380 : :
2381 : : /*
2382 : : * Certain constraints must be met in order to use the bulk buffer
2383 : : * allocation Rx burst function. If any of Rx queues doesn't meet them
2384 : : * the feature should be disabled for the whole port.
2385 : : */
2386 [ # # ]: 0 : if (check_rx_burst_bulk_alloc_preconditions(rxq)) {
2387 : 0 : PMD_INIT_LOG(DEBUG,
2388 : : "queue[%d] doesn't meet Rx Bulk Alloc preconditions - canceling the feature for the whole port[%d]",
2389 : : rxq->queue_id, rxq->port_id);
2390 : 0 : adapter->rx_bulk_alloc_allowed = false;
2391 : : }
2392 : :
2393 : : /*
2394 : : * Allocate software ring. Allow for space at the end of the
2395 : : * S/W ring to make sure look-ahead logic in bulk alloc Rx burst
2396 : : * function does not access an invalid memory region.
2397 : : */
2398 : : len = nb_desc;
2399 [ # # ]: 0 : if (adapter->rx_bulk_alloc_allowed)
2400 : 0 : len += RTE_PMD_NGBE_RX_MAX_BURST;
2401 : :
2402 : 0 : rxq->sw_ring = rte_zmalloc_socket("rxq->sw_ring",
2403 : : sizeof(struct ngbe_rx_entry) * len,
2404 : : RTE_CACHE_LINE_SIZE, socket_id);
2405 [ # # ]: 0 : if (rxq->sw_ring == NULL) {
2406 : 0 : ngbe_rx_queue_release(rxq);
2407 : 0 : return -ENOMEM;
2408 : : }
2409 : :
2410 : : /*
2411 : : * Always allocate even if it's not going to be needed in order to
2412 : : * simplify the code.
2413 : : *
2414 : : * This ring is used in Scattered Rx cases and Scattered Rx may
2415 : : * be requested in ngbe_dev_rx_init(), which is called later from
2416 : : * dev_start() flow.
2417 : : */
2418 : 0 : rxq->sw_sc_ring =
2419 : 0 : rte_zmalloc_socket("rxq->sw_sc_ring",
2420 : : sizeof(struct ngbe_scattered_rx_entry) * len,
2421 : : RTE_CACHE_LINE_SIZE, socket_id);
2422 [ # # ]: 0 : if (rxq->sw_sc_ring == NULL) {
2423 : 0 : ngbe_rx_queue_release(rxq);
2424 : 0 : return -ENOMEM;
2425 : : }
2426 : :
2427 : 0 : PMD_INIT_LOG(DEBUG,
2428 : : "sw_ring=%p sw_sc_ring=%p hw_ring=%p dma_addr=0x%" PRIx64,
2429 : : rxq->sw_ring, rxq->sw_sc_ring, rxq->rx_ring,
2430 : : rxq->rx_ring_phys_addr);
2431 : :
2432 [ # # ]: 0 : if (!rte_is_power_of_2(nb_desc)) {
2433 : 0 : PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Vector Rx "
2434 : : "preconditions - canceling the feature for "
2435 : : "the whole port[%d]",
2436 : : rxq->queue_id, rxq->port_id);
2437 : 0 : adapter->rx_vec_allowed = false;
2438 : : } else {
2439 : 0 : ngbe_rxq_vec_setup(rxq);
2440 : : }
2441 : :
2442 : 0 : dev->data->rx_queues[queue_idx] = rxq;
2443 : :
2444 : 0 : ngbe_reset_rx_queue(adapter, rxq);
2445 : :
2446 : 0 : return 0;
2447 : : }
2448 : :
2449 : : int
2450 : 0 : ngbe_dev_rx_queue_count(void *rx_queue)
2451 : : {
2452 : : #define NGBE_RXQ_SCAN_INTERVAL 4
2453 : : volatile struct ngbe_rx_desc *rxdp;
2454 : : struct ngbe_rx_queue *rxq = rx_queue;
2455 : : uint32_t desc = 0;
2456 : :
2457 : 0 : rxdp = &rxq->rx_ring[rxq->rx_tail];
2458 : :
2459 [ # # ]: 0 : while ((desc < rxq->nb_rx_desc) &&
2460 [ # # ]: 0 : (rxdp->qw1.lo.status &
2461 : : rte_cpu_to_le_32(NGBE_RXD_STAT_DD))) {
2462 : 0 : desc += NGBE_RXQ_SCAN_INTERVAL;
2463 : 0 : rxdp += NGBE_RXQ_SCAN_INTERVAL;
2464 [ # # ]: 0 : if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
2465 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail +
2466 : 0 : desc - rxq->nb_rx_desc]);
2467 : : }
2468 : :
2469 : 0 : return desc;
2470 : : }
2471 : :
2472 : : int
2473 : 0 : ngbe_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
2474 : : {
2475 : : struct ngbe_rx_queue *rxq = rx_queue;
2476 : : volatile uint32_t *status;
2477 : : uint32_t nb_hold, desc;
2478 : :
2479 [ # # ]: 0 : if (unlikely(offset >= rxq->nb_rx_desc))
2480 : : return -EINVAL;
2481 : :
2482 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM)
2483 [ # # ]: 0 : if (rxq->rx_using_sse)
2484 : 0 : nb_hold = rxq->rxrearm_nb;
2485 : : else
2486 : : #endif
2487 : 0 : nb_hold = rxq->nb_rx_hold;
2488 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - nb_hold)
2489 : : return RTE_ETH_RX_DESC_UNAVAIL;
2490 : :
2491 : 0 : desc = rxq->rx_tail + offset;
2492 [ # # ]: 0 : if (desc >= rxq->nb_rx_desc)
2493 : 0 : desc -= rxq->nb_rx_desc;
2494 : :
2495 : 0 : status = &rxq->rx_ring[desc].qw1.lo.status;
2496 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(NGBE_RXD_STAT_DD))
2497 : 0 : return RTE_ETH_RX_DESC_DONE;
2498 : :
2499 : : return RTE_ETH_RX_DESC_AVAIL;
2500 : : }
2501 : :
2502 : : int
2503 : 0 : ngbe_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
2504 : : {
2505 : : struct ngbe_tx_queue *txq = tx_queue;
2506 : : volatile uint32_t *status;
2507 : : uint32_t desc;
2508 : :
2509 [ # # ]: 0 : if (unlikely(offset >= txq->nb_tx_desc))
2510 : : return -EINVAL;
2511 : :
2512 : 0 : desc = txq->tx_tail + offset;
2513 [ # # ]: 0 : if (desc >= txq->nb_tx_desc) {
2514 : 0 : desc -= txq->nb_tx_desc;
2515 [ # # ]: 0 : if (desc >= txq->nb_tx_desc)
2516 : 0 : desc -= txq->nb_tx_desc;
2517 : : }
2518 : :
2519 : 0 : status = &txq->tx_ring[desc].dw3;
2520 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(NGBE_TXD_DD))
2521 : 0 : return RTE_ETH_TX_DESC_DONE;
2522 : :
2523 : : return RTE_ETH_TX_DESC_FULL;
2524 : : }
2525 : :
2526 : : void
2527 : 0 : ngbe_dev_clear_queues(struct rte_eth_dev *dev)
2528 : : {
2529 : : unsigned int i;
2530 : : struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2531 : :
2532 : 0 : PMD_INIT_FUNC_TRACE();
2533 : :
2534 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
2535 : 0 : struct ngbe_tx_queue *txq = dev->data->tx_queues[i];
2536 : :
2537 [ # # ]: 0 : if (txq != NULL) {
2538 : 0 : txq->ops->release_mbufs(txq);
2539 : 0 : txq->ops->reset(txq);
2540 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
2541 : : }
2542 : : }
2543 : :
2544 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2545 : 0 : struct ngbe_rx_queue *rxq = dev->data->rx_queues[i];
2546 : :
2547 [ # # ]: 0 : if (rxq != NULL) {
2548 : 0 : ngbe_rx_queue_release_mbufs(rxq);
2549 : 0 : ngbe_reset_rx_queue(adapter, rxq);
2550 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
2551 : : }
2552 : : }
2553 : 0 : }
2554 : :
2555 : : void
2556 : 0 : ngbe_dev_free_queues(struct rte_eth_dev *dev)
2557 : : {
2558 : : unsigned int i;
2559 : :
2560 : 0 : PMD_INIT_FUNC_TRACE();
2561 : :
2562 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2563 : 0 : ngbe_dev_rx_queue_release(dev, i);
2564 : 0 : dev->data->rx_queues[i] = NULL;
2565 : : }
2566 : 0 : dev->data->nb_rx_queues = 0;
2567 : :
2568 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
2569 : 0 : ngbe_dev_tx_queue_release(dev, i);
2570 : 0 : dev->data->tx_queues[i] = NULL;
2571 : : }
2572 : 0 : dev->data->nb_tx_queues = 0;
2573 : 0 : }
2574 : :
2575 : : /**
2576 : : * Receive Side Scaling (RSS)
2577 : : *
2578 : : * Principles:
2579 : : * The source and destination IP addresses of the IP header and the source
2580 : : * and destination ports of TCP/UDP headers, if any, of received packets are
2581 : : * hashed against a configurable random key to compute a 32-bit RSS hash result.
2582 : : * The seven (7) LSBs of the 32-bit hash result are used as an index into a
2583 : : * 128-entry redirection table (RETA). Each entry of the RETA provides a 3-bit
2584 : : * RSS output index which is used as the Rx queue index where to store the
2585 : : * received packets.
2586 : : * The following output is supplied in the Rx write-back descriptor:
2587 : : * - 32-bit result of the Microsoft RSS hash function,
2588 : : * - 4-bit RSS type field.
2589 : : */
2590 : :
2591 : : /*
2592 : : * Used as the default key.
2593 : : */
2594 : : static uint8_t rss_intel_key[40] = {
2595 : : 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
2596 : : 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
2597 : : 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
2598 : : 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
2599 : : 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
2600 : : };
2601 : :
2602 : : static void
2603 : : ngbe_rss_disable(struct rte_eth_dev *dev)
2604 : : {
2605 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
2606 : :
2607 : : wr32m(hw, NGBE_RACTL, NGBE_RACTL_RSSENA, 0);
2608 : 0 : }
2609 : :
2610 : : int
2611 [ # # ]: 0 : ngbe_dev_rss_hash_update(struct rte_eth_dev *dev,
2612 : : struct rte_eth_rss_conf *rss_conf)
2613 : : {
2614 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
2615 : : uint8_t *hash_key;
2616 : : uint32_t mrqc;
2617 : : uint32_t rss_key;
2618 : : uint64_t rss_hf;
2619 : : uint16_t i;
2620 : :
2621 [ # # ]: 0 : if (!hw->is_pf) {
2622 : 0 : PMD_DRV_LOG(ERR, "RSS hash update is not supported on this "
2623 : : "NIC.");
2624 : 0 : return -ENOTSUP;
2625 : : }
2626 : :
2627 : 0 : hash_key = rss_conf->rss_key;
2628 [ # # ]: 0 : if (hash_key) {
2629 : : /* Fill in RSS hash key */
2630 [ # # ]: 0 : for (i = 0; i < 10; i++) {
2631 : 0 : rss_key = LS32(hash_key[(i * 4) + 0], 0, 0xFF);
2632 : 0 : rss_key |= LS32(hash_key[(i * 4) + 1], 8, 0xFF);
2633 : 0 : rss_key |= LS32(hash_key[(i * 4) + 2], 16, 0xFF);
2634 : 0 : rss_key |= LS32(hash_key[(i * 4) + 3], 24, 0xFF);
2635 : 0 : wr32a(hw, NGBE_REG_RSSKEY, i, rss_key);
2636 : : }
2637 : : }
2638 : :
2639 : : /* Set configured hashing protocols */
2640 : 0 : rss_hf = rss_conf->rss_hf & NGBE_RSS_OFFLOAD_ALL;
2641 : :
2642 : : mrqc = rd32(hw, NGBE_RACTL);
2643 : 0 : mrqc &= ~NGBE_RACTL_RSSMASK;
2644 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV4)
2645 : 0 : mrqc |= NGBE_RACTL_RSSIPV4;
2646 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
2647 : 0 : mrqc |= NGBE_RACTL_RSSIPV4TCP;
2648 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6 ||
2649 : : rss_hf & RTE_ETH_RSS_IPV6_EX)
2650 : 0 : mrqc |= NGBE_RACTL_RSSIPV6;
2651 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP ||
2652 : : rss_hf & RTE_ETH_RSS_IPV6_TCP_EX)
2653 : 0 : mrqc |= NGBE_RACTL_RSSIPV6TCP;
2654 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
2655 : 0 : mrqc |= NGBE_RACTL_RSSIPV4UDP;
2656 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP ||
2657 : : rss_hf & RTE_ETH_RSS_IPV6_UDP_EX)
2658 : 0 : mrqc |= NGBE_RACTL_RSSIPV6UDP;
2659 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_SCTP)
2660 : 0 : mrqc |= NGBE_RACTL_RSSIPV4SCTP;
2661 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_SCTP)
2662 : 0 : mrqc |= NGBE_RACTL_RSSIPV6SCTP;
2663 : :
2664 [ # # ]: 0 : if (rss_hf)
2665 : 0 : mrqc |= NGBE_RACTL_RSSENA;
2666 : : else
2667 : 0 : mrqc &= ~NGBE_RACTL_RSSENA;
2668 : :
2669 : : wr32(hw, NGBE_RACTL, mrqc);
2670 : :
2671 : 0 : return 0;
2672 : : }
2673 : :
2674 : : int
2675 [ # # ]: 0 : ngbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
2676 : : struct rte_eth_rss_conf *rss_conf)
2677 : : {
2678 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
2679 : : uint8_t *hash_key;
2680 : : uint32_t mrqc;
2681 : : uint32_t rss_key;
2682 : : uint64_t rss_hf;
2683 : : uint16_t i;
2684 : :
2685 : 0 : hash_key = rss_conf->rss_key;
2686 [ # # ]: 0 : if (hash_key) {
2687 : : /* Return RSS hash key */
2688 [ # # ]: 0 : for (i = 0; i < 10; i++) {
2689 : 0 : rss_key = rd32a(hw, NGBE_REG_RSSKEY, i);
2690 : 0 : hash_key[(i * 4) + 0] = RS32(rss_key, 0, 0xFF);
2691 : 0 : hash_key[(i * 4) + 1] = RS32(rss_key, 8, 0xFF);
2692 : 0 : hash_key[(i * 4) + 2] = RS32(rss_key, 16, 0xFF);
2693 : 0 : hash_key[(i * 4) + 3] = RS32(rss_key, 24, 0xFF);
2694 : : }
2695 : : }
2696 : :
2697 : : rss_hf = 0;
2698 : :
2699 : : mrqc = rd32(hw, NGBE_RACTL);
2700 [ # # ]: 0 : if (mrqc & NGBE_RACTL_RSSIPV4)
2701 : : rss_hf |= RTE_ETH_RSS_IPV4;
2702 [ # # ]: 0 : if (mrqc & NGBE_RACTL_RSSIPV4TCP)
2703 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_TCP;
2704 [ # # ]: 0 : if (mrqc & NGBE_RACTL_RSSIPV6)
2705 : 0 : rss_hf |= RTE_ETH_RSS_IPV6 |
2706 : : RTE_ETH_RSS_IPV6_EX;
2707 [ # # ]: 0 : if (mrqc & NGBE_RACTL_RSSIPV6TCP)
2708 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_TCP |
2709 : : RTE_ETH_RSS_IPV6_TCP_EX;
2710 [ # # ]: 0 : if (mrqc & NGBE_RACTL_RSSIPV4UDP)
2711 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_UDP;
2712 [ # # ]: 0 : if (mrqc & NGBE_RACTL_RSSIPV6UDP)
2713 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_UDP |
2714 : : RTE_ETH_RSS_IPV6_UDP_EX;
2715 [ # # ]: 0 : if (mrqc & NGBE_RACTL_RSSIPV4SCTP)
2716 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_SCTP;
2717 [ # # ]: 0 : if (mrqc & NGBE_RACTL_RSSIPV6SCTP)
2718 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_SCTP;
2719 [ # # ]: 0 : if (!(mrqc & NGBE_RACTL_RSSENA))
2720 : : rss_hf = 0;
2721 : :
2722 : : rss_hf &= NGBE_RSS_OFFLOAD_ALL;
2723 : :
2724 : 0 : rss_conf->rss_hf = rss_hf;
2725 : 0 : return 0;
2726 : : }
2727 : :
2728 : : static void
2729 : 0 : ngbe_rss_configure(struct rte_eth_dev *dev)
2730 : : {
2731 : : struct rte_eth_rss_conf rss_conf;
2732 : : struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2733 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
2734 : : uint32_t reta;
2735 : : uint16_t i;
2736 : : uint16_t j;
2737 : :
2738 : 0 : PMD_INIT_FUNC_TRACE();
2739 : :
2740 : : /*
2741 : : * Fill in redirection table
2742 : : * The byte-swap is needed because NIC registers are in
2743 : : * little-endian order.
2744 : : */
2745 [ # # ]: 0 : if (adapter->rss_reta_updated == 0) {
2746 : : reta = 0;
2747 [ # # ]: 0 : for (i = 0, j = 0; i < RTE_ETH_RSS_RETA_SIZE_128; i++, j++) {
2748 [ # # ]: 0 : if (j == dev->data->nb_rx_queues)
2749 : : j = 0;
2750 : 0 : reta = (reta >> 8) | LS32(j, 24, 0xFF);
2751 [ # # ]: 0 : if ((i & 3) == 3)
2752 : 0 : wr32a(hw, NGBE_REG_RSSTBL, i >> 2, reta);
2753 : : }
2754 : : }
2755 : : /*
2756 : : * Configure the RSS key and the RSS protocols used to compute
2757 : : * the RSS hash of input packets.
2758 : : */
2759 : 0 : rss_conf = dev->data->dev_conf.rx_adv_conf.rss_conf;
2760 [ # # ]: 0 : if (rss_conf.rss_key == NULL)
2761 : 0 : rss_conf.rss_key = rss_intel_key; /* Default hash key */
2762 : 0 : ngbe_dev_rss_hash_update(dev, &rss_conf);
2763 : 0 : }
2764 : :
2765 : 0 : void ngbe_configure_port(struct rte_eth_dev *dev)
2766 : : {
2767 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
2768 : : int i = 0;
2769 : 0 : uint16_t tpids[8] = {RTE_ETHER_TYPE_VLAN, RTE_ETHER_TYPE_QINQ,
2770 : : 0x9100, 0x9200,
2771 : : 0x0000, 0x0000,
2772 : : 0x0000, 0x0000};
2773 : :
2774 : 0 : PMD_INIT_FUNC_TRACE();
2775 : :
2776 : : /* default outer vlan tpid */
2777 : : wr32(hw, NGBE_EXTAG,
2778 : : NGBE_EXTAG_ETAG(RTE_ETHER_TYPE_ETAG) |
2779 : : NGBE_EXTAG_VLAN(RTE_ETHER_TYPE_QINQ));
2780 : :
2781 : : /* default inner vlan tpid */
2782 : : wr32m(hw, NGBE_VLANCTL,
2783 : : NGBE_VLANCTL_TPID_MASK,
2784 : : NGBE_VLANCTL_TPID(RTE_ETHER_TYPE_VLAN));
2785 : : wr32m(hw, NGBE_DMATXCTRL,
2786 : : NGBE_DMATXCTRL_TPID_MASK,
2787 : : NGBE_DMATXCTRL_TPID(RTE_ETHER_TYPE_VLAN));
2788 : :
2789 : : /* default vlan tpid filters */
2790 [ # # ]: 0 : for (i = 0; i < 8; i++) {
2791 [ # # ]: 0 : wr32m(hw, NGBE_TAGTPID(i / 2),
2792 : : (i % 2 ? NGBE_TAGTPID_MSB_MASK
2793 : : : NGBE_TAGTPID_LSB_MASK),
2794 [ # # ]: 0 : (i % 2 ? NGBE_TAGTPID_MSB(tpids[i])
2795 : 0 : : NGBE_TAGTPID_LSB(tpids[i])));
2796 : : }
2797 : 0 : }
2798 : :
2799 : : static int
2800 : 0 : ngbe_alloc_rx_queue_mbufs(struct ngbe_rx_queue *rxq)
2801 : : {
2802 : 0 : struct ngbe_rx_entry *rxe = rxq->sw_ring;
2803 : : uint64_t dma_addr;
2804 : : unsigned int i;
2805 : :
2806 : : /* Initialize software ring entries */
2807 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
2808 : : /* the ring can also be modified by hardware */
2809 : : volatile struct ngbe_rx_desc *rxd;
2810 : 0 : struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
2811 : :
2812 [ # # ]: 0 : if (mbuf == NULL) {
2813 : 0 : PMD_INIT_LOG(ERR, "Rx mbuf alloc failed queue_id=%u port_id=%u",
2814 : : (unsigned int)rxq->queue_id,
2815 : : (unsigned int)rxq->port_id);
2816 : 0 : return -ENOMEM;
2817 : : }
2818 : :
2819 : 0 : mbuf->data_off = RTE_PKTMBUF_HEADROOM;
2820 : 0 : mbuf->port = rxq->port_id;
2821 : :
2822 : : dma_addr =
2823 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
2824 : 0 : rxd = &rxq->rx_ring[i];
2825 : 0 : NGBE_RXD_HDRADDR(rxd, 0);
2826 : 0 : NGBE_RXD_PKTADDR(rxd, dma_addr);
2827 : 0 : rxe[i].mbuf = mbuf;
2828 : : }
2829 : :
2830 : : return 0;
2831 : : }
2832 : :
2833 : : static int
2834 : 0 : ngbe_dev_mq_rx_configure(struct rte_eth_dev *dev)
2835 : : {
2836 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
2837 [ # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
2838 : 0 : case RTE_ETH_MQ_RX_RSS:
2839 : 0 : ngbe_rss_configure(dev);
2840 : 0 : break;
2841 : :
2842 : : case RTE_ETH_MQ_RX_NONE:
2843 : : default:
2844 : : /* if mq_mode is none, disable rss mode.*/
2845 : : ngbe_rss_disable(dev);
2846 : : break;
2847 : : }
2848 : : }
2849 : :
2850 : 0 : return 0;
2851 : : }
2852 : :
2853 : : void
2854 : 0 : ngbe_set_rx_function(struct rte_eth_dev *dev)
2855 : : {
2856 : : uint16_t i, rx_using_sse;
2857 : : struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2858 : :
2859 : : /*
2860 : : * In order to allow Vector Rx there are a few configuration
2861 : : * conditions to be met and Rx Bulk Allocation should be allowed.
2862 : : */
2863 [ # # ]: 0 : if (ngbe_rx_vec_dev_conf_condition_check(dev) ||
2864 [ # # # # ]: 0 : !adapter->rx_bulk_alloc_allowed ||
2865 : 0 : rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128) {
2866 : 0 : PMD_INIT_LOG(DEBUG,
2867 : : "Port[%d] doesn't meet Vector Rx preconditions",
2868 : : dev->data->port_id);
2869 : 0 : adapter->rx_vec_allowed = false;
2870 : : }
2871 : :
2872 [ # # ]: 0 : if (dev->data->scattered_rx) {
2873 : : /*
2874 : : * Set the scattered callback: there are bulk and
2875 : : * single allocation versions.
2876 : : */
2877 [ # # ]: 0 : if (adapter->rx_vec_allowed) {
2878 : 0 : PMD_INIT_LOG(DEBUG,
2879 : : "Using Vector Scattered Rx callback (port=%d).",
2880 : : dev->data->port_id);
2881 : 0 : dev->rx_pkt_burst = ngbe_recv_scattered_pkts_vec;
2882 [ # # ]: 0 : } else if (adapter->rx_bulk_alloc_allowed) {
2883 : 0 : PMD_INIT_LOG(DEBUG, "Using a Scattered with bulk "
2884 : : "allocation callback (port=%d).",
2885 : : dev->data->port_id);
2886 : 0 : dev->rx_pkt_burst = ngbe_recv_pkts_sc_bulk_alloc;
2887 : : } else {
2888 : 0 : PMD_INIT_LOG(DEBUG, "Using Regular (non-vector, "
2889 : : "single allocation) "
2890 : : "Scattered Rx callback "
2891 : : "(port=%d).",
2892 : : dev->data->port_id);
2893 : :
2894 : 0 : dev->rx_pkt_burst = ngbe_recv_pkts_sc_single_alloc;
2895 : : }
2896 : : /*
2897 : : * Below we set "simple" callbacks according to port/queues parameters.
2898 : : * If parameters allow we are going to choose between the following
2899 : : * callbacks:
2900 : : * - Vector
2901 : : * - Bulk Allocation
2902 : : * - Single buffer allocation (the simplest one)
2903 : : */
2904 [ # # ]: 0 : } else if (adapter->rx_vec_allowed) {
2905 : 0 : PMD_INIT_LOG(DEBUG, "Vector rx enabled, please make sure Rx "
2906 : : "burst size no less than %d (port=%d).",
2907 : : RTE_NGBE_DESCS_PER_LOOP,
2908 : : dev->data->port_id);
2909 : 0 : dev->rx_pkt_burst = ngbe_recv_pkts_vec;
2910 [ # # ]: 0 : } else if (adapter->rx_bulk_alloc_allowed) {
2911 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
2912 : : "satisfied. Rx Burst Bulk Alloc function "
2913 : : "will be used on port=%d.",
2914 : : dev->data->port_id);
2915 : :
2916 : 0 : dev->rx_pkt_burst = ngbe_recv_pkts_bulk_alloc;
2917 : : } else {
2918 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are not "
2919 : : "satisfied, or Scattered Rx is requested "
2920 : : "(port=%d).",
2921 : : dev->data->port_id);
2922 : :
2923 : 0 : dev->rx_pkt_burst = ngbe_recv_pkts;
2924 : : }
2925 : :
2926 [ # # # # ]: 0 : rx_using_sse = (dev->rx_pkt_burst == ngbe_recv_scattered_pkts_vec ||
2927 : : dev->rx_pkt_burst == ngbe_recv_pkts_vec);
2928 : :
2929 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2930 : 0 : struct ngbe_rx_queue *rxq = dev->data->rx_queues[i];
2931 : :
2932 : 0 : rxq->rx_using_sse = rx_using_sse;
2933 : : }
2934 : 0 : }
2935 : :
2936 : : static const struct {
2937 : : eth_rx_burst_t pkt_burst;
2938 : : const char *info;
2939 : : } ngbe_rx_burst_infos[] = {
2940 : : { ngbe_recv_pkts_sc_single_alloc, "Scalar Scattered"},
2941 : : { ngbe_recv_pkts_sc_bulk_alloc, "Scalar Scattered Bulk Alloc"},
2942 : : { ngbe_recv_pkts_bulk_alloc, "Scalar Bulk Alloc"},
2943 : : { ngbe_recv_pkts, "Scalar"},
2944 : : #ifdef RTE_ARCH_X86
2945 : : { ngbe_recv_scattered_pkts_vec, "Vector SSE Scattered" },
2946 : : { ngbe_recv_pkts_vec, "Vector SSE" },
2947 : : #elif defined(RTE_ARCH_ARM64)
2948 : : { ngbe_recv_scattered_pkts_vec, "Vector Neon Scattered" },
2949 : : { ngbe_recv_pkts_vec, "Vector Neon" },
2950 : : #endif
2951 : : };
2952 : :
2953 : : int
2954 : 0 : ngbe_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
2955 : : struct rte_eth_burst_mode *mode)
2956 : : {
2957 : 0 : eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
2958 : : int ret = -EINVAL;
2959 : : unsigned int i;
2960 : :
2961 [ # # ]: 0 : for (i = 0; i < RTE_DIM(ngbe_rx_burst_infos); ++i) {
2962 [ # # ]: 0 : if (pkt_burst == ngbe_rx_burst_infos[i].pkt_burst) {
2963 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
2964 : 0 : ngbe_rx_burst_infos[i].info);
2965 : : ret = 0;
2966 : 0 : break;
2967 : : }
2968 : : }
2969 : :
2970 : 0 : return ret;
2971 : : }
2972 : :
2973 : : /*
2974 : : * Initializes Receive Unit.
2975 : : */
2976 : : int
2977 : 0 : ngbe_dev_rx_init(struct rte_eth_dev *dev)
2978 : : {
2979 : : struct ngbe_hw *hw;
2980 : : struct ngbe_rx_queue *rxq;
2981 : : uint64_t bus_addr;
2982 : : uint32_t fctrl;
2983 : : uint32_t hlreg0;
2984 : : uint32_t srrctl;
2985 : : uint32_t rdrxctl;
2986 : : uint32_t rxcsum;
2987 : : uint16_t buf_size;
2988 : : uint16_t i;
2989 : 0 : struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
2990 : :
2991 : 0 : PMD_INIT_FUNC_TRACE();
2992 : : hw = ngbe_dev_hw(dev);
2993 : :
2994 : : /*
2995 : : * Make sure receives are disabled while setting
2996 : : * up the Rx context (registers, descriptor rings, etc.).
2997 : : */
2998 : :
2999 [ # # # # ]: 0 : if (!(hw->ncsi_enabled || hw->wol_enabled))
3000 : : wr32m(hw, NGBE_MACRXCFG, NGBE_MACRXCFG_ENA, 0);
3001 : :
3002 : : wr32m(hw, NGBE_PBRXCTL, NGBE_PBRXCTL_ENA, 0);
3003 : :
3004 : : /* Enable receipt of broadcasted frames */
3005 : : fctrl = rd32(hw, NGBE_PSRCTL);
3006 : 0 : fctrl |= NGBE_PSRCTL_BCA;
3007 : : wr32(hw, NGBE_PSRCTL, fctrl);
3008 : :
3009 : : /*
3010 : : * Configure CRC stripping, if any.
3011 : : */
3012 : : hlreg0 = rd32(hw, NGBE_SECRXCTL);
3013 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
3014 : 0 : hlreg0 &= ~NGBE_SECRXCTL_CRCSTRIP;
3015 : : else
3016 : 0 : hlreg0 |= NGBE_SECRXCTL_CRCSTRIP;
3017 : 0 : hlreg0 &= ~NGBE_SECRXCTL_XDSA;
3018 : : wr32(hw, NGBE_SECRXCTL, hlreg0);
3019 : :
3020 : : /*
3021 : : * Configure jumbo frame support, if any.
3022 : : */
3023 : 0 : wr32m(hw, NGBE_FRMSZ, NGBE_FRMSZ_MAX_MASK,
3024 : 0 : NGBE_FRMSZ_MAX(dev->data->mtu + NGBE_ETH_OVERHEAD));
3025 : :
3026 : : /*
3027 : : * If loopback mode is configured, set LPBK bit.
3028 : : */
3029 : : hlreg0 = rd32(hw, NGBE_PSRCTL);
3030 [ # # # # ]: 0 : if (hw->is_pf && dev->data->dev_conf.lpbk_mode)
3031 : 0 : hlreg0 |= NGBE_PSRCTL_LBENA;
3032 : : else
3033 : 0 : hlreg0 &= ~NGBE_PSRCTL_LBENA;
3034 : :
3035 : : wr32(hw, NGBE_PSRCTL, hlreg0);
3036 : :
3037 : : /*
3038 : : * Assume no header split and no VLAN strip support
3039 : : * on any Rx queue first .
3040 : : */
3041 : 0 : rx_conf->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
3042 : :
3043 : : /* Setup Rx queues */
3044 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3045 : 0 : rxq = dev->data->rx_queues[i];
3046 : :
3047 : : /*
3048 : : * Reset crc_len in case it was changed after queue setup by a
3049 : : * call to configure.
3050 : : */
3051 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
3052 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
3053 : : else
3054 : 0 : rxq->crc_len = 0;
3055 : :
3056 : : /* Setup the Base and Length of the Rx Descriptor Rings */
3057 : 0 : bus_addr = rxq->rx_ring_phys_addr;
3058 : 0 : wr32(hw, NGBE_RXBAL(rxq->reg_idx),
3059 : : (uint32_t)(bus_addr & BIT_MASK32));
3060 : 0 : wr32(hw, NGBE_RXBAH(rxq->reg_idx),
3061 : 0 : (uint32_t)(bus_addr >> 32));
3062 : 0 : wr32(hw, NGBE_RXRP(rxq->reg_idx), 0);
3063 : 0 : wr32(hw, NGBE_RXWP(rxq->reg_idx), 0);
3064 : :
3065 [ # # ]: 0 : srrctl = NGBE_RXCFG_RNGLEN(rxq->nb_rx_desc);
3066 : :
3067 : : /* Set if packets are dropped when no descriptors available */
3068 [ # # ]: 0 : if (rxq->drop_en)
3069 : 0 : srrctl |= NGBE_RXCFG_DROP;
3070 : :
3071 : : /*
3072 : : * Configure the Rx buffer size in the PKTLEN field of
3073 : : * the RXCFG register of the queue.
3074 : : * The value is in 1 KB resolution. Valid values can be from
3075 : : * 1 KB to 16 KB.
3076 : : */
3077 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
3078 : : RTE_PKTMBUF_HEADROOM);
3079 : 0 : buf_size = ROUND_DOWN(buf_size, 0x1 << 10);
3080 [ # # ]: 0 : srrctl |= NGBE_RXCFG_PKTLEN(buf_size);
3081 : :
3082 : 0 : wr32(hw, NGBE_RXCFG(rxq->reg_idx), srrctl);
3083 : :
3084 : : /* It adds dual VLAN length for supporting dual VLAN */
3085 : 0 : if (dev->data->mtu + NGBE_ETH_OVERHEAD +
3086 [ # # ]: 0 : 2 * RTE_VLAN_HLEN > buf_size)
3087 : 0 : dev->data->scattered_rx = 1;
3088 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
3089 : 0 : rx_conf->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
3090 : : }
3091 : :
3092 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_SCATTER)
3093 : 0 : dev->data->scattered_rx = 1;
3094 : :
3095 : : /*
3096 : : * Device configured with multiple RX queues.
3097 : : */
3098 : 0 : ngbe_dev_mq_rx_configure(dev);
3099 : :
3100 : : /*
3101 : : * Setup the Checksum Register.
3102 : : * Disable Full-Packet Checksum which is mutually exclusive with RSS.
3103 : : * Enable IP/L4 checksum computation by hardware if requested to do so.
3104 : : */
3105 : : rxcsum = rd32(hw, NGBE_PSRCTL);
3106 : : rxcsum |= NGBE_PSRCTL_PCSD;
3107 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM)
3108 : 0 : rxcsum |= NGBE_PSRCTL_L4CSUM;
3109 : : else
3110 : 0 : rxcsum &= ~NGBE_PSRCTL_L4CSUM;
3111 : :
3112 : : wr32(hw, NGBE_PSRCTL, rxcsum);
3113 : :
3114 [ # # ]: 0 : if (hw->is_pf) {
3115 : : rdrxctl = rd32(hw, NGBE_SECRXCTL);
3116 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
3117 : 0 : rdrxctl &= ~NGBE_SECRXCTL_CRCSTRIP;
3118 : : else
3119 : 0 : rdrxctl |= NGBE_SECRXCTL_CRCSTRIP;
3120 : : wr32(hw, NGBE_SECRXCTL, rdrxctl);
3121 : : }
3122 : :
3123 : 0 : ngbe_set_rx_function(dev);
3124 : :
3125 : 0 : return 0;
3126 : : }
3127 : :
3128 : : /*
3129 : : * Initializes Transmit Unit.
3130 : : */
3131 : : void
3132 : 0 : ngbe_dev_tx_init(struct rte_eth_dev *dev)
3133 : : {
3134 : : struct ngbe_hw *hw;
3135 : : struct ngbe_tx_queue *txq;
3136 : : uint64_t bus_addr;
3137 : : uint16_t i;
3138 : :
3139 : 0 : PMD_INIT_FUNC_TRACE();
3140 : : hw = ngbe_dev_hw(dev);
3141 : :
3142 : : wr32m(hw, NGBE_SECTXCTL, NGBE_SECTXCTL_ODSA, NGBE_SECTXCTL_ODSA);
3143 : : wr32m(hw, NGBE_SECTXCTL, NGBE_SECTXCTL_XDSA, 0);
3144 : :
3145 : : /* Setup the Base and Length of the Tx Descriptor Rings */
3146 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3147 : 0 : txq = dev->data->tx_queues[i];
3148 : :
3149 : 0 : bus_addr = txq->tx_ring_phys_addr;
3150 : 0 : wr32(hw, NGBE_TXBAL(txq->reg_idx),
3151 : : (uint32_t)(bus_addr & BIT_MASK32));
3152 : 0 : wr32(hw, NGBE_TXBAH(txq->reg_idx),
3153 : 0 : (uint32_t)(bus_addr >> 32));
3154 : 0 : wr32m(hw, NGBE_TXCFG(txq->reg_idx), NGBE_TXCFG_BUFLEN_MASK,
3155 [ # # ]: 0 : NGBE_TXCFG_BUFLEN(txq->nb_tx_desc));
3156 : : /* Setup the HW Tx Head and TX Tail descriptor pointers */
3157 : 0 : wr32(hw, NGBE_TXRP(txq->reg_idx), 0);
3158 : 0 : wr32(hw, NGBE_TXWP(txq->reg_idx), 0);
3159 : : }
3160 : 0 : }
3161 : :
3162 : : /*
3163 : : * Set up link loopback mode Tx->Rx.
3164 : : */
3165 : : static inline void
3166 : 0 : ngbe_setup_loopback_link(struct ngbe_hw *hw)
3167 : : {
3168 : 0 : PMD_INIT_FUNC_TRACE();
3169 : :
3170 : : wr32m(hw, NGBE_MACRXCFG, NGBE_MACRXCFG_LB, NGBE_MACRXCFG_LB);
3171 : :
3172 : : msec_delay(50);
3173 : 0 : }
3174 : :
3175 : : /*
3176 : : * Start Transmit and Receive Units.
3177 : : */
3178 : : int
3179 : 0 : ngbe_dev_rxtx_start(struct rte_eth_dev *dev)
3180 : : {
3181 : : struct ngbe_hw *hw;
3182 : : struct ngbe_tx_queue *txq;
3183 : : struct ngbe_rx_queue *rxq;
3184 : : uint32_t dmatxctl;
3185 : : uint32_t rxctrl;
3186 : : uint16_t i;
3187 : : int ret = 0;
3188 : :
3189 : 0 : PMD_INIT_FUNC_TRACE();
3190 : : hw = ngbe_dev_hw(dev);
3191 : :
3192 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3193 : 0 : txq = dev->data->tx_queues[i];
3194 : : /* Setup Transmit Threshold Registers */
3195 : 0 : wr32m(hw, NGBE_TXCFG(txq->reg_idx),
3196 : : NGBE_TXCFG_HTHRESH_MASK |
3197 : : NGBE_TXCFG_WTHRESH_MASK,
3198 : 0 : NGBE_TXCFG_HTHRESH(txq->hthresh) |
3199 : 0 : NGBE_TXCFG_WTHRESH(txq->wthresh));
3200 : : }
3201 : :
3202 : : dmatxctl = rd32(hw, NGBE_DMATXCTRL);
3203 : 0 : dmatxctl |= NGBE_DMATXCTRL_ENA;
3204 : : wr32(hw, NGBE_DMATXCTRL, dmatxctl);
3205 : :
3206 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3207 : 0 : txq = dev->data->tx_queues[i];
3208 [ # # ]: 0 : if (txq->tx_deferred_start == 0) {
3209 : 0 : ret = ngbe_dev_tx_queue_start(dev, i);
3210 [ # # ]: 0 : if (ret < 0)
3211 : 0 : return ret;
3212 : : }
3213 : : }
3214 : :
3215 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3216 : 0 : rxq = dev->data->rx_queues[i];
3217 [ # # ]: 0 : if (rxq->rx_deferred_start == 0) {
3218 : 0 : ret = ngbe_dev_rx_queue_start(dev, i);
3219 [ # # ]: 0 : if (ret < 0)
3220 : 0 : return ret;
3221 : : }
3222 : : }
3223 : :
3224 : : /* Enable Receive engine */
3225 : : rxctrl = rd32(hw, NGBE_PBRXCTL);
3226 : 0 : rxctrl |= NGBE_PBRXCTL_ENA;
3227 : 0 : hw->mac.enable_rx_dma(hw, rxctrl);
3228 : :
3229 : : /* If loopback mode is enabled, set up the link accordingly */
3230 [ # # # # ]: 0 : if (hw->is_pf && dev->data->dev_conf.lpbk_mode)
3231 : 0 : ngbe_setup_loopback_link(hw);
3232 : :
3233 : : return 0;
3234 : : }
3235 : :
3236 : : void
3237 : 0 : ngbe_dev_save_rx_queue(struct ngbe_hw *hw, uint16_t rx_queue_id)
3238 : : {
3239 : 0 : u32 *reg = &hw->q_rx_regs[rx_queue_id * 8];
3240 : 0 : *(reg++) = rd32(hw, NGBE_RXBAL(rx_queue_id));
3241 : 0 : *(reg++) = rd32(hw, NGBE_RXBAH(rx_queue_id));
3242 : 0 : *(reg++) = rd32(hw, NGBE_RXCFG(rx_queue_id));
3243 : 0 : }
3244 : :
3245 : : void
3246 : 0 : ngbe_dev_store_rx_queue(struct ngbe_hw *hw, uint16_t rx_queue_id)
3247 : : {
3248 : 0 : u32 *reg = &hw->q_rx_regs[rx_queue_id * 8];
3249 : 0 : wr32(hw, NGBE_RXBAL(rx_queue_id), *(reg++));
3250 : 0 : wr32(hw, NGBE_RXBAH(rx_queue_id), *(reg++));
3251 : 0 : wr32(hw, NGBE_RXCFG(rx_queue_id), *(reg++) & ~NGBE_RXCFG_ENA);
3252 : 0 : }
3253 : :
3254 : : void
3255 : 0 : ngbe_dev_save_tx_queue(struct ngbe_hw *hw, uint16_t tx_queue_id)
3256 : : {
3257 : 0 : u32 *reg = &hw->q_tx_regs[tx_queue_id * 8];
3258 : 0 : *(reg++) = rd32(hw, NGBE_TXBAL(tx_queue_id));
3259 : 0 : *(reg++) = rd32(hw, NGBE_TXBAH(tx_queue_id));
3260 : 0 : *(reg++) = rd32(hw, NGBE_TXCFG(tx_queue_id));
3261 : 0 : }
3262 : :
3263 : : void
3264 : 0 : ngbe_dev_store_tx_queue(struct ngbe_hw *hw, uint16_t tx_queue_id)
3265 : : {
3266 : 0 : u32 *reg = &hw->q_tx_regs[tx_queue_id * 8];
3267 : 0 : wr32(hw, NGBE_TXBAL(tx_queue_id), *(reg++));
3268 : 0 : wr32(hw, NGBE_TXBAH(tx_queue_id), *(reg++));
3269 : 0 : wr32(hw, NGBE_TXCFG(tx_queue_id), *(reg++) & ~NGBE_TXCFG_ENA);
3270 : 0 : }
3271 : :
3272 : : /*
3273 : : * Start Receive Units for specified queue.
3274 : : */
3275 : : int
3276 : 0 : ngbe_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
3277 : : {
3278 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
3279 : : struct ngbe_rx_queue *rxq;
3280 : : uint32_t rxdctl;
3281 : : int poll_ms;
3282 : :
3283 : 0 : PMD_INIT_FUNC_TRACE();
3284 : :
3285 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
3286 : :
3287 : : /* Allocate buffers for descriptor rings */
3288 [ # # ]: 0 : if (ngbe_alloc_rx_queue_mbufs(rxq) != 0) {
3289 : 0 : PMD_INIT_LOG(ERR, "Could not alloc mbuf for queue:%d",
3290 : : rx_queue_id);
3291 : 0 : return -1;
3292 : : }
3293 : 0 : rxdctl = rd32(hw, NGBE_RXCFG(rxq->reg_idx));
3294 : 0 : rxdctl |= NGBE_RXCFG_ENA;
3295 : 0 : wr32(hw, NGBE_RXCFG(rxq->reg_idx), rxdctl);
3296 : :
3297 : : /* Wait until Rx Enable ready */
3298 : : poll_ms = RTE_NGBE_REGISTER_POLL_WAIT_10_MS;
3299 : : do {
3300 : : rte_delay_ms(1);
3301 : 0 : rxdctl = rd32(hw, NGBE_RXCFG(rxq->reg_idx));
3302 [ # # # # ]: 0 : } while (--poll_ms && !(rxdctl & NGBE_RXCFG_ENA));
3303 [ # # ]: 0 : if (poll_ms == 0)
3304 : 0 : PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", rx_queue_id);
3305 : : rte_wmb();
3306 : 0 : wr32(hw, NGBE_RXRP(rxq->reg_idx), 0);
3307 : 0 : wr32(hw, NGBE_RXWP(rxq->reg_idx), rxq->nb_rx_desc - 1);
3308 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
3309 : :
3310 : 0 : return 0;
3311 : : }
3312 : :
3313 : : /*
3314 : : * Stop Receive Units for specified queue.
3315 : : */
3316 : : int
3317 : 0 : ngbe_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
3318 : : {
3319 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
3320 : : struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
3321 : : struct ngbe_rx_queue *rxq;
3322 : : uint32_t rxdctl;
3323 : : int poll_ms;
3324 : :
3325 : 0 : PMD_INIT_FUNC_TRACE();
3326 : :
3327 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
3328 : :
3329 : 0 : ngbe_dev_save_rx_queue(hw, rxq->reg_idx);
3330 : 0 : wr32m(hw, NGBE_RXCFG(rxq->reg_idx), NGBE_RXCFG_ENA, 0);
3331 : :
3332 : : /* Wait until Rx Enable bit clear */
3333 : : poll_ms = RTE_NGBE_REGISTER_POLL_WAIT_10_MS;
3334 : : do {
3335 : : rte_delay_ms(1);
3336 : 0 : rxdctl = rd32(hw, NGBE_RXCFG(rxq->reg_idx));
3337 [ # # # # ]: 0 : } while (--poll_ms && (rxdctl & NGBE_RXCFG_ENA));
3338 [ # # ]: 0 : if (poll_ms == 0)
3339 : 0 : PMD_INIT_LOG(ERR, "Could not disable Rx Queue %d", rx_queue_id);
3340 : :
3341 : 0 : rte_delay_us(RTE_NGBE_WAIT_100_US);
3342 : 0 : ngbe_dev_store_rx_queue(hw, rxq->reg_idx);
3343 : :
3344 : 0 : ngbe_rx_queue_release_mbufs(rxq);
3345 : 0 : ngbe_reset_rx_queue(adapter, rxq);
3346 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
3347 : :
3348 : 0 : return 0;
3349 : : }
3350 : :
3351 : : /*
3352 : : * Start Transmit Units for specified queue.
3353 : : */
3354 : : int
3355 : 0 : ngbe_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
3356 : : {
3357 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
3358 : : struct ngbe_tx_queue *txq;
3359 : : uint32_t txdctl;
3360 : : int poll_ms;
3361 : :
3362 : 0 : PMD_INIT_FUNC_TRACE();
3363 : :
3364 : 0 : txq = dev->data->tx_queues[tx_queue_id];
3365 : 0 : wr32m(hw, NGBE_TXCFG(txq->reg_idx), NGBE_TXCFG_ENA, NGBE_TXCFG_ENA);
3366 : :
3367 : : /* Wait until Tx Enable ready */
3368 : : poll_ms = RTE_NGBE_REGISTER_POLL_WAIT_10_MS;
3369 : : do {
3370 : : rte_delay_ms(1);
3371 : 0 : txdctl = rd32(hw, NGBE_TXCFG(txq->reg_idx));
3372 [ # # # # ]: 0 : } while (--poll_ms && !(txdctl & NGBE_TXCFG_ENA));
3373 [ # # ]: 0 : if (poll_ms == 0)
3374 : 0 : PMD_INIT_LOG(ERR, "Could not enable Tx Queue %d",
3375 : : tx_queue_id);
3376 : :
3377 : : rte_wmb();
3378 : 0 : wr32(hw, NGBE_TXWP(txq->reg_idx), txq->tx_tail);
3379 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
3380 : :
3381 : 0 : return 0;
3382 : : }
3383 : :
3384 : : /*
3385 : : * Stop Transmit Units for specified queue.
3386 : : */
3387 : : int
3388 : 0 : ngbe_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
3389 : : {
3390 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
3391 : : struct ngbe_tx_queue *txq;
3392 : : uint32_t txdctl;
3393 : : uint32_t txtdh, txtdt;
3394 : : int poll_ms;
3395 : :
3396 : 0 : PMD_INIT_FUNC_TRACE();
3397 : :
3398 : 0 : txq = dev->data->tx_queues[tx_queue_id];
3399 : :
3400 : : /* Wait until Tx queue is empty */
3401 : : poll_ms = RTE_NGBE_REGISTER_POLL_WAIT_10_MS;
3402 : : do {
3403 : 0 : rte_delay_us(RTE_NGBE_WAIT_100_US);
3404 : 0 : txtdh = rd32(hw, NGBE_TXRP(txq->reg_idx));
3405 : 0 : txtdt = rd32(hw, NGBE_TXWP(txq->reg_idx));
3406 [ # # # # ]: 0 : } while (--poll_ms && (txtdh != txtdt));
3407 [ # # ]: 0 : if (poll_ms == 0)
3408 : 0 : PMD_INIT_LOG(ERR, "Tx Queue %d is not empty when stopping.",
3409 : : tx_queue_id);
3410 : :
3411 : 0 : ngbe_dev_save_tx_queue(hw, txq->reg_idx);
3412 : 0 : wr32m(hw, NGBE_TXCFG(txq->reg_idx), NGBE_TXCFG_ENA, 0);
3413 : :
3414 : : /* Wait until Tx Enable bit clear */
3415 : : poll_ms = RTE_NGBE_REGISTER_POLL_WAIT_10_MS;
3416 : : do {
3417 : : rte_delay_ms(1);
3418 : 0 : txdctl = rd32(hw, NGBE_TXCFG(txq->reg_idx));
3419 [ # # # # ]: 0 : } while (--poll_ms && (txdctl & NGBE_TXCFG_ENA));
3420 [ # # ]: 0 : if (poll_ms == 0)
3421 : 0 : PMD_INIT_LOG(ERR, "Could not disable Tx Queue %d",
3422 : : tx_queue_id);
3423 : :
3424 : 0 : rte_delay_us(RTE_NGBE_WAIT_100_US);
3425 : 0 : ngbe_dev_store_tx_queue(hw, txq->reg_idx);
3426 : :
3427 [ # # ]: 0 : if (txq->ops != NULL) {
3428 : 0 : txq->ops->release_mbufs(txq);
3429 : 0 : txq->ops->reset(txq);
3430 : : }
3431 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
3432 : :
3433 : 0 : return 0;
3434 : : }
3435 : :
3436 : : void
3437 : 0 : ngbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
3438 : : struct rte_eth_rxq_info *qinfo)
3439 : : {
3440 : : struct ngbe_rx_queue *rxq;
3441 : :
3442 : 0 : rxq = dev->data->rx_queues[queue_id];
3443 : :
3444 : 0 : qinfo->mp = rxq->mb_pool;
3445 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
3446 : 0 : qinfo->nb_desc = rxq->nb_rx_desc;
3447 : :
3448 : 0 : qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
3449 : 0 : qinfo->conf.rx_drop_en = rxq->drop_en;
3450 : 0 : qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
3451 : 0 : qinfo->conf.offloads = rxq->offloads;
3452 : 0 : }
3453 : :
3454 : : void
3455 : 0 : ngbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
3456 : : struct rte_eth_txq_info *qinfo)
3457 : : {
3458 : : struct ngbe_tx_queue *txq;
3459 : :
3460 : 0 : txq = dev->data->tx_queues[queue_id];
3461 : :
3462 : 0 : qinfo->nb_desc = txq->nb_tx_desc;
3463 : :
3464 : 0 : qinfo->conf.tx_thresh.pthresh = txq->pthresh;
3465 : 0 : qinfo->conf.tx_thresh.hthresh = txq->hthresh;
3466 : 0 : qinfo->conf.tx_thresh.wthresh = txq->wthresh;
3467 : :
3468 : 0 : qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
3469 : 0 : qinfo->conf.offloads = txq->offloads;
3470 : 0 : qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
3471 : 0 : }
3472 : :
3473 : : /*
3474 : : * [VF] Initializes Receive Unit.
3475 : : */
3476 : : int
3477 : 0 : ngbevf_dev_rx_init(struct rte_eth_dev *dev)
3478 : : {
3479 : : struct ngbe_hw *hw;
3480 : : struct ngbe_rx_queue *rxq;
3481 : 0 : struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
3482 : : uint64_t bus_addr;
3483 : : uint32_t srrctl;
3484 : : uint16_t buf_size;
3485 : : uint16_t i;
3486 : : int ret;
3487 : :
3488 : 0 : PMD_INIT_FUNC_TRACE();
3489 : : hw = ngbe_dev_hw(dev);
3490 : :
3491 [ # # ]: 0 : if (rte_is_power_of_2(dev->data->nb_rx_queues) == 0) {
3492 : 0 : PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
3493 : : "it should be power of 2");
3494 : 0 : return -1;
3495 : : }
3496 : :
3497 [ # # ]: 0 : if (dev->data->nb_rx_queues > hw->mac.max_rx_queues) {
3498 : 0 : PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
3499 : : "it should be equal to or less than %d",
3500 : : hw->mac.max_rx_queues);
3501 : 0 : return -1;
3502 : : }
3503 : :
3504 : : /*
3505 : : * When the VF driver issues a NGBE_VF_RESET request, the PF driver
3506 : : * disables the VF receipt of packets if the PF MTU is > 1500.
3507 : : * This is done to deal with limitations that imposes
3508 : : * the PF and all VFs to share the same MTU.
3509 : : * Then, the PF driver enables again the VF receipt of packet when
3510 : : * the VF driver issues a NGBE_VF_SET_LPE request.
3511 : : * In the meantime, the VF device cannot be used, even if the VF driver
3512 : : * and the Guest VM network stack are ready to accept packets with a
3513 : : * size up to the PF MTU.
3514 : : * As a work-around to this PF behaviour, force the call to
3515 : : * ngbevf_rlpml_set_vf even if jumbo frames are not used. This way,
3516 : : * VF packets received can work in all cases.
3517 : : */
3518 [ # # ]: 0 : if (ngbevf_rlpml_set_vf(hw,
3519 : 0 : (uint16_t)dev->data->mtu + NGBE_ETH_OVERHEAD)) {
3520 : 0 : PMD_INIT_LOG(ERR, "Set max packet length to %d failed.",
3521 : : dev->data->mtu + NGBE_ETH_OVERHEAD);
3522 : :
3523 : 0 : return -EINVAL;
3524 : : }
3525 : :
3526 : : /*
3527 : : * Assume no header split and no VLAN strip support
3528 : : * on any Rx queue first .
3529 : : */
3530 : 0 : rxmode->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
3531 : : /* Setup RX queues */
3532 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3533 : 0 : rxq = dev->data->rx_queues[i];
3534 : :
3535 : : /* Allocate buffers for descriptor rings */
3536 : 0 : ret = ngbe_alloc_rx_queue_mbufs(rxq);
3537 [ # # ]: 0 : if (ret)
3538 : 0 : return ret;
3539 : :
3540 : : /* Setup the Base and Length of the Rx Descriptor Rings */
3541 : 0 : bus_addr = rxq->rx_ring_phys_addr;
3542 : :
3543 : 0 : wr32(hw, NGBE_RXBAL(i),
3544 : : (uint32_t)(bus_addr & BIT_MASK32));
3545 : 0 : wr32(hw, NGBE_RXBAH(i),
3546 : 0 : (uint32_t)(bus_addr >> 32));
3547 : 0 : wr32(hw, NGBE_RXRP(i), 0);
3548 : 0 : wr32(hw, NGBE_RXWP(i), 0);
3549 : :
3550 : : /* Configure the RXCFG register */
3551 [ # # ]: 0 : srrctl = NGBE_RXCFG_RNGLEN(rxq->nb_rx_desc);
3552 : :
3553 : : /* Set if packets are dropped when no descriptors available */
3554 [ # # ]: 0 : if (rxq->drop_en)
3555 : 0 : srrctl |= NGBE_RXCFG_DROP;
3556 : :
3557 : : /*
3558 : : * Configure the RX buffer size in the PKTLEN field of
3559 : : * the RXCFG register of the queue.
3560 : : * The value is in 1 KB resolution. Valid values can be from
3561 : : * 1 KB to 16 KB.
3562 : : */
3563 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
3564 : : RTE_PKTMBUF_HEADROOM);
3565 : 0 : buf_size = ROUND_DOWN(buf_size, 1 << 10);
3566 [ # # ]: 0 : srrctl |= NGBE_RXCFG_PKTLEN(buf_size);
3567 : :
3568 : : /*
3569 : : * VF modification to write virtual function RXCFG register
3570 : : */
3571 : 0 : wr32(hw, NGBE_RXCFG(i), srrctl);
3572 : :
3573 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_SCATTER ||
3574 : : /* It adds dual VLAN length for supporting dual VLAN */
3575 : 0 : (dev->data->mtu + NGBE_ETH_OVERHEAD +
3576 [ # # ]: 0 : 2 * RTE_VLAN_HLEN) > buf_size) {
3577 [ # # ]: 0 : if (!dev->data->scattered_rx)
3578 : 0 : PMD_INIT_LOG(DEBUG, "forcing scatter mode");
3579 : 0 : dev->data->scattered_rx = 1;
3580 : : }
3581 : :
3582 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
3583 : 0 : rxmode->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
3584 : : }
3585 : :
3586 : 0 : ngbe_set_rx_function(dev);
3587 : :
3588 : 0 : return 0;
3589 : : }
3590 : :
3591 : : /*
3592 : : * [VF] Initializes Transmit Unit.
3593 : : */
3594 : : void
3595 : 0 : ngbevf_dev_tx_init(struct rte_eth_dev *dev)
3596 : : {
3597 : : struct ngbe_hw *hw;
3598 : : struct ngbe_tx_queue *txq;
3599 : : uint64_t bus_addr;
3600 : : uint16_t i;
3601 : :
3602 : 0 : PMD_INIT_FUNC_TRACE();
3603 : : hw = ngbe_dev_hw(dev);
3604 : :
3605 : : /* Setup the Base and Length of the Tx Descriptor Rings */
3606 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3607 : 0 : txq = dev->data->tx_queues[i];
3608 : 0 : bus_addr = txq->tx_ring_phys_addr;
3609 : 0 : wr32(hw, NGBE_TXBAL(i),
3610 : : (uint32_t)(bus_addr & BIT_MASK32));
3611 : 0 : wr32(hw, NGBE_TXBAH(i),
3612 : 0 : (uint32_t)(bus_addr >> 32));
3613 : 0 : wr32m(hw, NGBE_TXCFG(i), NGBE_TXCFG_BUFLEN_MASK,
3614 [ # # ]: 0 : NGBE_TXCFG_BUFLEN(txq->nb_tx_desc));
3615 : : /* Setup the HW Tx Head and TX Tail descriptor pointers */
3616 : 0 : wr32(hw, NGBE_TXRP(i), 0);
3617 : 0 : wr32(hw, NGBE_TXWP(i), 0);
3618 : : }
3619 : 0 : }
3620 : :
3621 : : /*
3622 : : * [VF] Start Transmit and Receive Units.
3623 : : */
3624 : : void
3625 : 0 : ngbevf_dev_rxtx_start(struct rte_eth_dev *dev)
3626 : : {
3627 : : struct ngbe_hw *hw;
3628 : : struct ngbe_tx_queue *txq;
3629 : : struct ngbe_rx_queue *rxq;
3630 : : uint32_t txdctl;
3631 : : uint32_t rxdctl;
3632 : : uint16_t i;
3633 : : int poll_ms;
3634 : :
3635 : 0 : PMD_INIT_FUNC_TRACE();
3636 : : hw = ngbe_dev_hw(dev);
3637 : :
3638 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3639 : 0 : txq = dev->data->tx_queues[i];
3640 : : /* Setup Transmit Threshold Registers */
3641 : 0 : wr32m(hw, NGBE_TXCFG(txq->reg_idx),
3642 : : NGBE_TXCFG_HTHRESH_MASK |
3643 : : NGBE_TXCFG_WTHRESH_MASK,
3644 : 0 : NGBE_TXCFG_HTHRESH(txq->hthresh) |
3645 : 0 : NGBE_TXCFG_WTHRESH(txq->wthresh));
3646 : : }
3647 : :
3648 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3649 : 0 : wr32m(hw, NGBE_TXCFG(i), NGBE_TXCFG_ENA, NGBE_TXCFG_ENA);
3650 : :
3651 : : poll_ms = 10;
3652 : : /* Wait until TX Enable ready */
3653 : : do {
3654 : : rte_delay_ms(1);
3655 : : txdctl = rd32(hw, NGBE_TXCFG(i));
3656 [ # # # # ]: 0 : } while (--poll_ms && !(txdctl & NGBE_TXCFG_ENA));
3657 [ # # ]: 0 : if (!poll_ms)
3658 : 0 : PMD_INIT_LOG(ERR, "Could not enable Tx Queue %d", i);
3659 : : else
3660 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
3661 : : }
3662 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3663 : 0 : rxq = dev->data->rx_queues[i];
3664 : :
3665 : 0 : wr32m(hw, NGBE_RXCFG(i), NGBE_RXCFG_ENA, NGBE_RXCFG_ENA);
3666 : :
3667 : : /* Wait until RX Enable ready */
3668 : : poll_ms = 10;
3669 : : do {
3670 : : rte_delay_ms(1);
3671 : : rxdctl = rd32(hw, NGBE_RXCFG(i));
3672 [ # # # # ]: 0 : } while (--poll_ms && !(rxdctl & NGBE_RXCFG_ENA));
3673 [ # # ]: 0 : if (!poll_ms)
3674 : 0 : PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", i);
3675 : : else
3676 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
3677 : : rte_wmb();
3678 : 0 : wr32(hw, NGBE_RXWP(i), rxq->nb_rx_desc - 1);
3679 : : }
3680 : 0 : }
3681 : :
3682 : : /* Stubs needed for linkage when RTE_ARCH_PPC_64, RTE_ARCH_RISCV or
3683 : : * RTE_ARCH_LOONGARCH is set.
3684 : : */
3685 : : #if defined(RTE_ARCH_PPC_64) || defined(RTE_ARCH_RISCV) || \
3686 : : defined(RTE_ARCH_LOONGARCH)
3687 : : int
3688 : : ngbe_rx_vec_dev_conf_condition_check(__rte_unused struct rte_eth_dev *dev)
3689 : : {
3690 : : return -1;
3691 : : }
3692 : :
3693 : : uint16_t
3694 : : ngbe_recv_pkts_vec(__rte_unused void *rx_queue,
3695 : : __rte_unused struct rte_mbuf **rx_pkts,
3696 : : __rte_unused uint16_t nb_pkts)
3697 : : {
3698 : : return 0;
3699 : : }
3700 : :
3701 : : uint16_t
3702 : : ngbe_recv_scattered_pkts_vec(__rte_unused void *rx_queue,
3703 : : __rte_unused struct rte_mbuf **rx_pkts,
3704 : : __rte_unused uint16_t nb_pkts)
3705 : : {
3706 : : return 0;
3707 : : }
3708 : :
3709 : : int
3710 : : ngbe_rxq_vec_setup(__rte_unused struct ngbe_rx_queue *rxq)
3711 : : {
3712 : : return -1;
3713 : : }
3714 : :
3715 : : uint16_t
3716 : : ngbe_xmit_fixed_burst_vec(__rte_unused void *tx_queue,
3717 : : __rte_unused struct rte_mbuf **tx_pkts,
3718 : : __rte_unused uint16_t nb_pkts)
3719 : : {
3720 : : return 0;
3721 : : }
3722 : :
3723 : : int
3724 : : ngbe_txq_vec_setup(__rte_unused struct ngbe_tx_queue *txq)
3725 : : {
3726 : : return -1;
3727 : : }
3728 : :
3729 : : void
3730 : : ngbe_rx_queue_release_mbufs_vec(__rte_unused struct ngbe_rx_queue *rxq)
3731 : : {
3732 : : }
3733 : : #endif
|