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