Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
3 : : * Copyright(c) 2010-2017 Intel Corporation
4 : : */
5 : :
6 : : #include <sys/queue.h>
7 : :
8 : : #include <stdio.h>
9 : : #include <stdlib.h>
10 : : #include <string.h>
11 : : #include <errno.h>
12 : : #include <stdint.h>
13 : : #include <stdarg.h>
14 : : #include <unistd.h>
15 : : #include <inttypes.h>
16 : :
17 : : #include <rte_byteorder.h>
18 : : #include <rte_common.h>
19 : : #include <rte_cycles.h>
20 : : #include <rte_log.h>
21 : : #include <rte_debug.h>
22 : : #include <rte_ethdev.h>
23 : : #include <ethdev_driver.h>
24 : : #include <rte_security_driver.h>
25 : : #include <rte_memzone.h>
26 : : #include <rte_atomic.h>
27 : : #include <rte_mempool.h>
28 : : #include <rte_malloc.h>
29 : : #include <rte_mbuf.h>
30 : : #include <rte_ether.h>
31 : : #include <rte_prefetch.h>
32 : : #include <rte_udp.h>
33 : : #include <rte_tcp.h>
34 : : #include <rte_sctp.h>
35 : : #include <rte_string_fns.h>
36 : : #include <rte_errno.h>
37 : : #include <rte_ip.h>
38 : : #include <rte_net.h>
39 : : #include <rte_vect.h>
40 : :
41 : : #include "txgbe_logs.h"
42 : : #include "base/txgbe.h"
43 : : #include "txgbe_ethdev.h"
44 : : #include "txgbe_rxtx.h"
45 : :
46 : : #ifdef RTE_LIBRTE_IEEE1588
47 : : #define TXGBE_TX_IEEE1588_TMST RTE_MBUF_F_TX_IEEE1588_TMST
48 : : #else
49 : : #define TXGBE_TX_IEEE1588_TMST 0
50 : : #endif
51 : :
52 : : /* Bit Mask to indicate what bits required for building TX context */
53 : : static const u64 TXGBE_TX_OFFLOAD_MASK = (RTE_MBUF_F_TX_IP_CKSUM |
54 : : RTE_MBUF_F_TX_OUTER_IPV6 |
55 : : RTE_MBUF_F_TX_OUTER_IPV4 |
56 : : RTE_MBUF_F_TX_IPV6 |
57 : : RTE_MBUF_F_TX_IPV4 |
58 : : RTE_MBUF_F_TX_VLAN |
59 : : RTE_MBUF_F_TX_L4_MASK |
60 : : RTE_MBUF_F_TX_TCP_SEG |
61 : : RTE_MBUF_F_TX_UDP_SEG |
62 : : RTE_MBUF_F_TX_TUNNEL_MASK |
63 : : RTE_MBUF_F_TX_OUTER_IP_CKSUM |
64 : : #ifdef RTE_LIB_SECURITY
65 : : RTE_MBUF_F_TX_SEC_OFFLOAD |
66 : : #endif
67 : : TXGBE_TX_IEEE1588_TMST);
68 : :
69 : : #define TXGBE_TX_OFFLOAD_NOTSUP_MASK \
70 : : (RTE_MBUF_F_TX_OFFLOAD_MASK ^ TXGBE_TX_OFFLOAD_MASK)
71 : :
72 : : /*
73 : : * Prefetch a cache line into all cache levels.
74 : : */
75 : : #define rte_txgbe_prefetch(p) rte_prefetch0(p)
76 : :
77 : : /*********************************************************************
78 : : *
79 : : * TX functions
80 : : *
81 : : **********************************************************************/
82 : :
83 : : /*
84 : : * Check for descriptors with their DD bit set and free mbufs.
85 : : * Return the total number of buffers freed.
86 : : */
87 : : static __rte_always_inline int
88 : : txgbe_tx_free_bufs(struct txgbe_tx_queue *txq)
89 : : {
90 : : struct txgbe_tx_entry *txep;
91 : : uint32_t status;
92 : : int i, nb_free = 0;
93 : : struct rte_mbuf *m, *free[RTE_TXGBE_TX_MAX_FREE_BUF_SZ];
94 : :
95 [ # # # # ]: 0 : if (txq->headwb_mem) {
96 : 0 : uint16_t tx_last_dd = txq->nb_tx_desc +
97 : 0 : txq->tx_next_dd - txq->tx_free_thresh;
98 [ # # # # ]: 0 : if (tx_last_dd >= txq->nb_tx_desc)
99 : 0 : tx_last_dd -= txq->nb_tx_desc;
100 : :
101 : 0 : uint32_t h = rte_atomic_load_explicit(txq->headwb_mem,
102 : : rte_memory_order_acquire);
103 : : const uint16_t head = (uint16_t)h;
104 : :
105 [ # # # # ]: 0 : if (!txgbe_tx_headwb_desc_done(head, tx_last_dd, txq->tx_next_dd))
106 : : return 0;
107 : : } else {
108 : : /* check DD bit on threshold descriptor */
109 : 0 : status = txq->tx_ring[txq->tx_next_dd].dw3;
110 [ # # # # ]: 0 : if (!(status & rte_cpu_to_le_32(TXGBE_TXD_DD))) {
111 [ # # # # ]: 0 : if (txq->nb_tx_free >> 1 < txq->tx_free_thresh)
112 : 0 : txgbe_set32_masked(txq->tdc_reg_addr,
113 : : TXGBE_TXCFG_FLUSH, TXGBE_TXCFG_FLUSH);
114 : : return 0;
115 : : }
116 : : }
117 : :
118 : : /*
119 : : * first buffer to free from S/W ring is at index
120 : : * tx_next_dd - (tx_free_thresh-1)
121 : : */
122 : 0 : txep = &txq->sw_ring[txq->tx_next_dd - (txq->tx_free_thresh - 1)];
123 [ # # # # ]: 0 : for (i = 0; i < txq->tx_free_thresh; ++i, ++txep) {
124 : : /* free buffers one at a time */
125 : 0 : m = rte_pktmbuf_prefree_seg(txep->mbuf);
126 : 0 : txep->mbuf = NULL;
127 : :
128 [ # # # # ]: 0 : if (unlikely(m == NULL))
129 : 0 : continue;
130 : :
131 [ # # # # : 0 : if (nb_free >= RTE_TXGBE_TX_MAX_FREE_BUF_SZ ||
# # # # ]
132 [ # # # # ]: 0 : (nb_free > 0 && m->pool != free[0]->pool)) {
133 [ # # # # ]: 0 : rte_mempool_put_bulk(free[0]->pool,
134 : : (void **)free, nb_free);
135 : : nb_free = 0;
136 : : }
137 : :
138 : 0 : free[nb_free++] = m;
139 : : }
140 : :
141 [ # # # # ]: 0 : if (nb_free > 0)
142 [ # # # # ]: 0 : rte_mempool_put_bulk(free[0]->pool, (void **)free, nb_free);
143 : :
144 : : /* buffers were freed, update counters */
145 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_free_thresh);
146 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_free_thresh);
147 [ # # # # ]: 0 : if (txq->tx_next_dd >= txq->nb_tx_desc)
148 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_free_thresh - 1);
149 : :
150 : 0 : return txq->tx_free_thresh;
151 : : }
152 : :
153 : : /* Populate 4 descriptors with data from 4 mbufs */
154 : : static inline void
155 : 0 : tx4(volatile struct txgbe_tx_desc *txdp, struct rte_mbuf **pkts)
156 : : {
157 : : uint64_t buf_dma_addr;
158 : : uint32_t pkt_len;
159 : : int i;
160 : :
161 [ # # ]: 0 : for (i = 0; i < 4; ++i, ++txdp, ++pkts) {
162 [ # # ]: 0 : buf_dma_addr = rte_mbuf_data_iova(*pkts);
163 : 0 : pkt_len = (*pkts)->data_len;
164 [ # # ]: 0 : if (pkt_len < RTE_ETHER_HDR_LEN)
165 : : pkt_len = TXGBE_FRAME_SIZE_DFT;
166 : :
167 : : /* write data to descriptor */
168 : 0 : txdp->qw0 = rte_cpu_to_le_64(buf_dma_addr);
169 : 0 : txdp->dw2 = cpu_to_le32(TXGBE_TXD_FLAGS |
170 : : TXGBE_TXD_DATLEN(pkt_len));
171 : 0 : txdp->dw3 = cpu_to_le32(TXGBE_TXD_PAYLEN(pkt_len));
172 : :
173 : 0 : rte_prefetch0(&(*pkts)->pool);
174 : : }
175 : 0 : }
176 : :
177 : : /* Populate 1 descriptor with data from 1 mbuf */
178 : : static inline void
179 : : tx1(volatile struct txgbe_tx_desc *txdp, struct rte_mbuf **pkts)
180 : : {
181 : : uint64_t buf_dma_addr;
182 : : uint32_t pkt_len;
183 : :
184 : : buf_dma_addr = rte_mbuf_data_iova(*pkts);
185 : 0 : pkt_len = (*pkts)->data_len;
186 [ # # ]: 0 : if (pkt_len < RTE_ETHER_HDR_LEN)
187 : : pkt_len = TXGBE_FRAME_SIZE_DFT;
188 : :
189 : : /* write data to descriptor */
190 : 0 : txdp->qw0 = cpu_to_le64(buf_dma_addr);
191 : 0 : txdp->dw2 = cpu_to_le32(TXGBE_TXD_FLAGS |
192 : : TXGBE_TXD_DATLEN(pkt_len));
193 : 0 : txdp->dw3 = cpu_to_le32(TXGBE_TXD_PAYLEN(pkt_len));
194 : :
195 : 0 : rte_prefetch0(&(*pkts)->pool);
196 : : }
197 : :
198 : : /*
199 : : * Fill H/W descriptor ring with mbuf data.
200 : : * Copy mbuf pointers to the S/W ring.
201 : : */
202 : : static inline void
203 : 0 : txgbe_tx_fill_hw_ring(struct txgbe_tx_queue *txq, struct rte_mbuf **pkts,
204 : : uint16_t nb_pkts)
205 : : {
206 : 0 : volatile struct txgbe_tx_desc *txdp = &txq->tx_ring[txq->tx_tail];
207 : 0 : struct txgbe_tx_entry *txep = &txq->sw_ring[txq->tx_tail];
208 : : const int N_PER_LOOP = 4;
209 : : const int N_PER_LOOP_MASK = N_PER_LOOP - 1;
210 : : int mainpart, leftover;
211 : : int i, j;
212 : :
213 : : /*
214 : : * Process most of the packets in chunks of N pkts. Any
215 : : * leftover packets will get processed one at a time.
216 : : */
217 : 0 : mainpart = (nb_pkts & ((uint32_t)~N_PER_LOOP_MASK));
218 : 0 : leftover = (nb_pkts & ((uint32_t)N_PER_LOOP_MASK));
219 [ # # ]: 0 : for (i = 0; i < mainpart; i += N_PER_LOOP) {
220 : : /* Copy N mbuf pointers to the S/W ring */
221 [ # # ]: 0 : for (j = 0; j < N_PER_LOOP; ++j)
222 : 0 : (txep + i + j)->mbuf = *(pkts + i + j);
223 : 0 : tx4(txdp + i, pkts + i);
224 : : }
225 : :
226 [ # # ]: 0 : if (unlikely(leftover > 0)) {
227 [ # # ]: 0 : for (i = 0; i < leftover; ++i) {
228 : 0 : (txep + mainpart + i)->mbuf = *(pkts + mainpart + i);
229 [ # # ]: 0 : tx1(txdp + mainpart + i, pkts + mainpart + i);
230 : : }
231 : : }
232 : 0 : }
233 : :
234 : : static inline uint16_t
235 : 0 : tx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
236 : : uint16_t nb_pkts)
237 : : {
238 : : struct txgbe_tx_queue *txq = (struct txgbe_tx_queue *)tx_queue;
239 : : uint16_t n = 0;
240 : :
241 : : /*
242 : : * Begin scanning the H/W ring for done descriptors when the
243 : : * number of available descriptors drops below tx_free_thresh. For
244 : : * each done descriptor, free the associated buffer.
245 : : */
246 [ # # ]: 0 : if (txq->nb_tx_free < txq->tx_free_thresh)
247 : : txgbe_tx_free_bufs(txq);
248 : :
249 : : /* Only use descriptors that are available */
250 : 0 : nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
251 [ # # ]: 0 : if (unlikely(nb_pkts == 0))
252 : : return 0;
253 : :
254 : : /* Use exactly nb_pkts descriptors */
255 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
256 : :
257 : : /*
258 : : * At this point, we know there are enough descriptors in the
259 : : * ring to transmit all the packets. This assumes that each
260 : : * mbuf contains a single segment, and that no new offloads
261 : : * are expected, which would require a new context descriptor.
262 : : */
263 : :
264 : : /*
265 : : * See if we're going to wrap-around. If so, handle the top
266 : : * of the descriptor ring first, then do the bottom. If not,
267 : : * the processing looks just like the "bottom" part anyway...
268 : : */
269 [ # # ]: 0 : if ((txq->tx_tail + nb_pkts) > txq->nb_tx_desc) {
270 : 0 : n = (uint16_t)(txq->nb_tx_desc - txq->tx_tail);
271 : 0 : txgbe_tx_fill_hw_ring(txq, tx_pkts, n);
272 : 0 : txq->tx_tail = 0;
273 : : }
274 : :
275 : : /* Fill H/W descriptor ring with mbuf data */
276 : 0 : txgbe_tx_fill_hw_ring(txq, tx_pkts + n, (uint16_t)(nb_pkts - n));
277 : 0 : txq->tx_tail = (uint16_t)(txq->tx_tail + (nb_pkts - n));
278 : :
279 : : /*
280 : : * Check for wrap-around. This would only happen if we used
281 : : * up to the last descriptor in the ring, no more, no less.
282 : : */
283 [ # # ]: 0 : if (txq->tx_tail >= txq->nb_tx_desc)
284 : 0 : txq->tx_tail = 0;
285 : :
286 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
287 : : (uint16_t)txq->port_id, (uint16_t)txq->queue_id,
288 : : (uint16_t)txq->tx_tail, (uint16_t)nb_pkts);
289 : :
290 : : /* update tail pointer */
291 : : rte_wmb();
292 : 0 : txgbe_set32_relaxed(txq->tdt_reg_addr, txq->tx_tail);
293 : :
294 : 0 : return nb_pkts;
295 : : }
296 : :
297 : : uint16_t
298 : 0 : txgbe_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
299 : : uint16_t nb_pkts)
300 : : {
301 : : uint16_t nb_tx;
302 : :
303 : : /* Try to transmit at least chunks of TX_MAX_BURST pkts */
304 [ # # ]: 0 : if (likely(nb_pkts <= RTE_PMD_TXGBE_TX_MAX_BURST))
305 : 0 : return tx_xmit_pkts(tx_queue, tx_pkts, nb_pkts);
306 : :
307 : : /* transmit more than the max burst, in chunks of TX_MAX_BURST */
308 : : nb_tx = 0;
309 [ # # ]: 0 : while (nb_pkts) {
310 : : uint16_t ret, n;
311 : :
312 : 0 : n = (uint16_t)RTE_MIN(nb_pkts, RTE_PMD_TXGBE_TX_MAX_BURST);
313 : 0 : ret = tx_xmit_pkts(tx_queue, &tx_pkts[nb_tx], n);
314 : 0 : nb_tx = (uint16_t)(nb_tx + ret);
315 : 0 : nb_pkts = (uint16_t)(nb_pkts - ret);
316 [ # # ]: 0 : if (ret < n)
317 : : break;
318 : : }
319 : :
320 : : return nb_tx;
321 : : }
322 : :
323 : : static uint16_t
324 : 0 : txgbe_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
325 : : uint16_t nb_pkts)
326 : : {
327 : : struct txgbe_tx_queue *txq = (struct txgbe_tx_queue *)tx_queue;
328 : : uint16_t nb_tx = 0;
329 : :
330 [ # # ]: 0 : while (nb_pkts) {
331 : : uint16_t ret, num;
332 : :
333 : 0 : num = (uint16_t)RTE_MIN(nb_pkts, txq->tx_free_thresh);
334 : 0 : ret = txgbe_xmit_fixed_burst_vec(tx_queue, &tx_pkts[nb_tx], num);
335 : 0 : nb_tx += ret;
336 : 0 : nb_pkts -= ret;
337 [ # # ]: 0 : if (ret < num)
338 : : break;
339 : : }
340 : :
341 : 0 : return nb_tx;
342 : : }
343 : :
344 : : static inline void
345 : 0 : txgbe_set_xmit_ctx(struct txgbe_tx_queue *txq,
346 : : volatile struct txgbe_tx_ctx_desc *ctx_txd,
347 : : uint64_t ol_flags, union txgbe_tx_offload tx_offload,
348 : : __rte_unused uint64_t *mdata)
349 : : {
350 : : union txgbe_tx_offload tx_offload_mask;
351 : : uint32_t type_tucmd_mlhl;
352 : : uint32_t mss_l4len_idx;
353 : : uint32_t ctx_idx;
354 : : uint32_t vlan_macip_lens;
355 : : uint32_t tunnel_seed;
356 : :
357 : 0 : ctx_idx = txq->ctx_curr;
358 : 0 : tx_offload_mask.data[0] = 0;
359 : 0 : tx_offload_mask.data[1] = 0;
360 : :
361 : : /* Specify which HW CTX to upload. */
362 : 0 : mss_l4len_idx = TXGBE_TXD_IDX(ctx_idx);
363 : : type_tucmd_mlhl = TXGBE_TXD_CTXT;
364 : :
365 : 0 : tx_offload_mask.ptid |= ~0;
366 : 0 : type_tucmd_mlhl |= TXGBE_TXD_PTID(tx_offload.ptid);
367 : :
368 : : /* check if TCP segmentation required for this packet */
369 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)) {
370 : 0 : tx_offload_mask.l2_len |= ~0;
371 : 0 : tx_offload_mask.l3_len |= ~0;
372 : 0 : tx_offload_mask.l4_len |= ~0;
373 : 0 : tx_offload_mask.tso_segsz |= ~0;
374 : 0 : mss_l4len_idx |= TXGBE_TXD_MSS(tx_offload.tso_segsz);
375 : 0 : mss_l4len_idx |= TXGBE_TXD_L4LEN(tx_offload.l4_len);
376 : : } else { /* no TSO, check if hardware checksum is needed */
377 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM) {
378 : 0 : tx_offload_mask.l2_len |= ~0;
379 : 0 : tx_offload_mask.l3_len |= ~0;
380 : : }
381 : :
382 [ # # # # ]: 0 : switch (ol_flags & RTE_MBUF_F_TX_L4_MASK) {
383 : 0 : case RTE_MBUF_F_TX_UDP_CKSUM:
384 : 0 : mss_l4len_idx |=
385 : : TXGBE_TXD_L4LEN(sizeof(struct rte_udp_hdr));
386 : 0 : tx_offload_mask.l2_len |= ~0;
387 : 0 : tx_offload_mask.l3_len |= ~0;
388 : 0 : break;
389 : 0 : case RTE_MBUF_F_TX_TCP_CKSUM:
390 : 0 : mss_l4len_idx |=
391 : : TXGBE_TXD_L4LEN(sizeof(struct rte_tcp_hdr));
392 : 0 : tx_offload_mask.l2_len |= ~0;
393 : 0 : tx_offload_mask.l3_len |= ~0;
394 : 0 : break;
395 : 0 : case RTE_MBUF_F_TX_SCTP_CKSUM:
396 : 0 : mss_l4len_idx |=
397 : : TXGBE_TXD_L4LEN(sizeof(struct rte_sctp_hdr));
398 : 0 : tx_offload_mask.l2_len |= ~0;
399 : 0 : tx_offload_mask.l3_len |= ~0;
400 : 0 : break;
401 : : default:
402 : : break;
403 : : }
404 : : }
405 : :
406 : 0 : vlan_macip_lens = TXGBE_TXD_IPLEN(tx_offload.l3_len >> 1);
407 : :
408 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) {
409 : 0 : tx_offload_mask.outer_tun_len |= ~0;
410 : 0 : tx_offload_mask.outer_l2_len |= ~0;
411 : 0 : tx_offload_mask.outer_l3_len |= ~0;
412 : 0 : tx_offload_mask.l2_len |= ~0;
413 : 0 : tunnel_seed = TXGBE_TXD_ETUNLEN(tx_offload.outer_tun_len >> 1);
414 : 0 : tunnel_seed |= TXGBE_TXD_EIPLEN(tx_offload.outer_l3_len >> 2);
415 : :
416 [ # # # ]: 0 : switch (ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) {
417 : : case RTE_MBUF_F_TX_TUNNEL_IPIP:
418 : : /* for non UDP / GRE tunneling, set to 0b */
419 : : break;
420 : : case RTE_MBUF_F_TX_TUNNEL_VXLAN:
421 : : case RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE:
422 : : case RTE_MBUF_F_TX_TUNNEL_GENEVE:
423 : : tunnel_seed |= TXGBE_TXD_ETYPE_UDP;
424 : : break;
425 : 0 : case RTE_MBUF_F_TX_TUNNEL_GRE:
426 : 0 : tunnel_seed |= TXGBE_TXD_ETYPE_GRE;
427 : 0 : break;
428 : 0 : default:
429 : : PMD_TX_LOG(ERR, "Tunnel type not supported");
430 : 0 : return;
431 : : }
432 : 0 : vlan_macip_lens |= TXGBE_TXD_MACLEN(tx_offload.outer_l2_len);
433 : : } else {
434 : : tunnel_seed = 0;
435 : 0 : vlan_macip_lens |= TXGBE_TXD_MACLEN(tx_offload.l2_len);
436 : : }
437 : :
438 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_VLAN) {
439 : 0 : tx_offload_mask.vlan_tci |= ~0;
440 : 0 : vlan_macip_lens |= TXGBE_TXD_VLAN(tx_offload.vlan_tci);
441 : : }
442 : :
443 : : #ifdef RTE_LIB_SECURITY
444 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD) {
445 : : union txgbe_crypto_tx_desc_md *md =
446 : : (union txgbe_crypto_tx_desc_md *)mdata;
447 : 0 : tunnel_seed |= TXGBE_TXD_IPSEC_SAIDX(md->sa_idx);
448 : 0 : type_tucmd_mlhl |= md->enc ?
449 [ # # ]: 0 : (TXGBE_TXD_IPSEC_ESP | TXGBE_TXD_IPSEC_ESPENC) : 0;
450 : 0 : type_tucmd_mlhl |= TXGBE_TXD_IPSEC_ESPLEN(md->pad_len);
451 : 0 : tx_offload_mask.sa_idx |= ~0;
452 : 0 : tx_offload_mask.sec_pad_len |= ~0;
453 : : }
454 : : #endif
455 : :
456 : 0 : txq->ctx_cache[ctx_idx].flags = ol_flags;
457 : 0 : txq->ctx_cache[ctx_idx].tx_offload.data[0] =
458 : 0 : tx_offload_mask.data[0] & tx_offload.data[0];
459 : 0 : txq->ctx_cache[ctx_idx].tx_offload.data[1] =
460 : 0 : tx_offload_mask.data[1] & tx_offload.data[1];
461 : 0 : txq->ctx_cache[ctx_idx].tx_offload_mask = tx_offload_mask;
462 : :
463 : 0 : ctx_txd->dw0 = rte_cpu_to_le_32(vlan_macip_lens);
464 : 0 : ctx_txd->dw1 = rte_cpu_to_le_32(tunnel_seed);
465 : 0 : ctx_txd->dw2 = rte_cpu_to_le_32(type_tucmd_mlhl);
466 : 0 : ctx_txd->dw3 = rte_cpu_to_le_32(mss_l4len_idx);
467 : : }
468 : :
469 : : /*
470 : : * Check which hardware context can be used. Use the existing match
471 : : * or create a new context descriptor.
472 : : */
473 : : static inline uint32_t
474 : 0 : what_ctx_update(struct txgbe_tx_queue *txq, uint64_t flags,
475 : : union txgbe_tx_offload tx_offload)
476 : : {
477 : : /* If match with the current used context */
478 [ # # # # : 0 : if (likely(txq->ctx_cache[txq->ctx_curr].flags == flags &&
# # ]
479 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data[0] ==
480 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[0]
481 : : & tx_offload.data[0])) &&
482 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data[1] ==
483 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[1]
484 : : & tx_offload.data[1]))))
485 : : return txq->ctx_curr;
486 : :
487 : : /* What if match with the next context */
488 : 0 : txq->ctx_curr ^= 1;
489 [ # # # # : 0 : if (likely(txq->ctx_cache[txq->ctx_curr].flags == flags &&
# # ]
490 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data[0] ==
491 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[0]
492 : : & tx_offload.data[0])) &&
493 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data[1] ==
494 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[1]
495 : : & tx_offload.data[1]))))
496 : 0 : return txq->ctx_curr;
497 : :
498 : : /* Mismatch, use the previous context */
499 : : return TXGBE_CTX_NUM;
500 : : }
501 : :
502 : : static inline uint32_t
503 : 0 : tx_desc_cksum_flags_to_olinfo(uint64_t ol_flags)
504 : : {
505 : : uint32_t tmp = 0;
506 : :
507 [ # # ]: 0 : if ((ol_flags & RTE_MBUF_F_TX_L4_MASK) != RTE_MBUF_F_TX_L4_NO_CKSUM) {
508 : : tmp |= TXGBE_TXD_CC;
509 : : tmp |= TXGBE_TXD_L4CS;
510 : : }
511 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM) {
512 : : tmp |= TXGBE_TXD_CC;
513 : 0 : tmp |= TXGBE_TXD_IPCS;
514 : : }
515 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) {
516 : : tmp |= TXGBE_TXD_CC;
517 : 0 : tmp |= TXGBE_TXD_EIPCS;
518 : : }
519 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)) {
520 : 0 : tmp |= TXGBE_TXD_CC;
521 : : /* implies IPv4 cksum */
522 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IPV4)
523 : 0 : tmp |= TXGBE_TXD_IPCS;
524 : 0 : tmp |= TXGBE_TXD_L4CS;
525 : : }
526 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_VLAN)
527 : 0 : tmp |= TXGBE_TXD_CC;
528 : :
529 : 0 : return tmp;
530 : : }
531 : :
532 : : static inline uint32_t
533 : : tx_desc_ol_flags_to_cmdtype(uint64_t ol_flags)
534 : : {
535 : : uint32_t cmdtype = 0;
536 : :
537 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_VLAN)
538 : : cmdtype |= TXGBE_TXD_VLE;
539 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG))
540 : 0 : cmdtype |= TXGBE_TXD_TSE;
541 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_MACSEC)
542 : 0 : cmdtype |= TXGBE_TXD_LINKSEC;
543 : : return cmdtype;
544 : : }
545 : :
546 : : static inline uint32_t
547 : 0 : tx_desc_ol_flags_to_ptype(uint64_t oflags)
548 : : {
549 : : uint32_t ptype;
550 : : bool tun;
551 : :
552 : : /* Only support flags in TXGBE_TX_OFFLOAD_MASK */
553 : 0 : tun = !!(oflags & RTE_MBUF_F_TX_TUNNEL_MASK);
554 : :
555 : : /* L2 level */
556 : : ptype = RTE_PTYPE_L2_ETHER;
557 [ # # ]: 0 : if (oflags & RTE_MBUF_F_TX_VLAN)
558 [ # # ]: 0 : ptype |= (tun ? RTE_PTYPE_INNER_L2_ETHER_VLAN : RTE_PTYPE_L2_ETHER_VLAN);
559 : :
560 [ # # ]: 0 : if (oflags & RTE_MBUF_F_TX_QINQ) /* tunnel + QINQ is not supported */
561 : 0 : ptype |= RTE_PTYPE_L2_ETHER_VLAN;
562 : :
563 : : /* L3 level */
564 [ # # ]: 0 : if (oflags & (RTE_MBUF_F_TX_OUTER_IPV4 | RTE_MBUF_F_TX_OUTER_IP_CKSUM))
565 : 0 : ptype |= RTE_PTYPE_L3_IPV4;
566 [ # # ]: 0 : else if (oflags & (RTE_MBUF_F_TX_OUTER_IPV6))
567 : 0 : ptype |= RTE_PTYPE_L3_IPV6;
568 : :
569 [ # # ]: 0 : if (oflags & (RTE_MBUF_F_TX_IPV4 | RTE_MBUF_F_TX_IP_CKSUM))
570 [ # # ]: 0 : ptype |= (tun ? RTE_PTYPE_INNER_L3_IPV4 : RTE_PTYPE_L3_IPV4);
571 [ # # ]: 0 : else if (oflags & (RTE_MBUF_F_TX_IPV6))
572 [ # # ]: 0 : ptype |= (tun ? RTE_PTYPE_INNER_L3_IPV6 : RTE_PTYPE_L3_IPV6);
573 : :
574 : : /* L4 level */
575 [ # # # # ]: 0 : switch (oflags & (RTE_MBUF_F_TX_L4_MASK)) {
576 : 0 : case RTE_MBUF_F_TX_TCP_CKSUM:
577 [ # # ]: 0 : ptype |= (tun ? RTE_PTYPE_INNER_L4_TCP : RTE_PTYPE_L4_TCP);
578 : 0 : break;
579 : 0 : case RTE_MBUF_F_TX_UDP_CKSUM:
580 [ # # ]: 0 : ptype |= (tun ? RTE_PTYPE_INNER_L4_UDP : RTE_PTYPE_L4_UDP);
581 : 0 : break;
582 : 0 : case RTE_MBUF_F_TX_SCTP_CKSUM:
583 [ # # ]: 0 : ptype |= (tun ? RTE_PTYPE_INNER_L4_SCTP : RTE_PTYPE_L4_SCTP);
584 : 0 : break;
585 : : }
586 : :
587 [ # # ]: 0 : if (oflags & RTE_MBUF_F_TX_TCP_SEG)
588 [ # # ]: 0 : ptype |= (tun ? RTE_PTYPE_INNER_L4_TCP : RTE_PTYPE_L4_TCP);
589 [ # # ]: 0 : else if (oflags & RTE_MBUF_F_TX_UDP_SEG)
590 [ # # ]: 0 : ptype |= (tun ? RTE_PTYPE_INNER_L4_UDP : RTE_PTYPE_L4_UDP);
591 : :
592 : : /* Tunnel */
593 [ # # # # : 0 : switch (oflags & RTE_MBUF_F_TX_TUNNEL_MASK) {
# ]
594 : 0 : case RTE_MBUF_F_TX_TUNNEL_VXLAN:
595 : : case RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE:
596 : 0 : ptype |= RTE_PTYPE_TUNNEL_GRENAT;
597 : 0 : break;
598 : 0 : case RTE_MBUF_F_TX_TUNNEL_GRE:
599 : 0 : ptype |= RTE_PTYPE_TUNNEL_GRE;
600 : 0 : break;
601 : 0 : case RTE_MBUF_F_TX_TUNNEL_GENEVE:
602 : 0 : ptype |= RTE_PTYPE_TUNNEL_GENEVE;
603 : 0 : break;
604 : 0 : case RTE_MBUF_F_TX_TUNNEL_IPIP:
605 : : case RTE_MBUF_F_TX_TUNNEL_IP:
606 : 0 : ptype |= RTE_PTYPE_TUNNEL_IP;
607 : 0 : break;
608 : : }
609 : :
610 : 0 : return ptype;
611 : : }
612 : :
613 : : static inline uint8_t
614 : : tx_desc_ol_flags_to_ptid(uint64_t oflags)
615 : : {
616 : : uint32_t ptype;
617 : :
618 : 0 : ptype = tx_desc_ol_flags_to_ptype(oflags);
619 : :
620 : 0 : return txgbe_encode_ptype(ptype);
621 : : }
622 : :
623 : : #ifndef DEFAULT_TX_FREE_THRESH
624 : : #define DEFAULT_TX_FREE_THRESH 32
625 : : #endif
626 : :
627 : : /* Reset transmit descriptors after they have been used */
628 : : static inline int
629 : 0 : txgbe_xmit_cleanup(struct txgbe_tx_queue *txq)
630 : : {
631 : 0 : struct txgbe_tx_entry *sw_ring = txq->sw_ring;
632 : 0 : volatile struct txgbe_tx_desc *txr = txq->tx_ring;
633 : 0 : uint16_t last_desc_cleaned = txq->last_desc_cleaned;
634 : 0 : uint16_t nb_tx_desc = txq->nb_tx_desc;
635 : : uint16_t desc_to_clean_to;
636 : : uint16_t nb_tx_to_clean;
637 : : uint32_t status;
638 : :
639 : : /* Determine the last descriptor needing to be cleaned */
640 : 0 : desc_to_clean_to = (uint16_t)(last_desc_cleaned + txq->tx_free_thresh);
641 [ # # ]: 0 : if (desc_to_clean_to >= nb_tx_desc)
642 : 0 : desc_to_clean_to = (uint16_t)(desc_to_clean_to - nb_tx_desc);
643 : :
644 : : /* Check to make sure the last descriptor to clean is done */
645 : 0 : desc_to_clean_to = sw_ring[desc_to_clean_to].last_id;
646 : 0 : status = txr[desc_to_clean_to].dw3;
647 : :
648 [ # # ]: 0 : if (txq->headwb_mem) {
649 : 0 : uint32_t h = rte_atomic_load_explicit(txq->headwb_mem,
650 : : rte_memory_order_acquire);
651 [ # # ]: 0 : const uint16_t head = (uint16_t)h;
652 : :
653 : : PMD_TX_FREE_LOG(DEBUG, "queue[%02d]: headwb_mem = %03d, desc_to_clean_to = %03d",
654 : : txq->reg_idx, head, desc_to_clean_to);
655 : : if (!txgbe_tx_headwb_desc_done(head, last_desc_cleaned, desc_to_clean_to))
656 : : return -(1);
657 : : } else {
658 [ # # ]: 0 : if (!(status & rte_cpu_to_le_32(TXGBE_TXD_DD))) {
659 : : PMD_TX_FREE_LOG(DEBUG,
660 : : "TX descriptor %4u is not done"
661 : : "(port=%d queue=%d)",
662 : : desc_to_clean_to,
663 : : txq->port_id, txq->queue_id);
664 [ # # ]: 0 : if (txq->nb_tx_free >> 1 < txq->tx_free_thresh)
665 : 0 : txgbe_set32_masked(txq->tdc_reg_addr,
666 : : TXGBE_TXCFG_FLUSH, TXGBE_TXCFG_FLUSH);
667 : : /* Failed to clean any descriptors, better luck next time */
668 : 0 : return -(1);
669 : : }
670 : : }
671 : :
672 : : /* Figure out how many descriptors will be cleaned */
673 [ # # ]: 0 : if (last_desc_cleaned > desc_to_clean_to)
674 : 0 : nb_tx_to_clean = (uint16_t)((nb_tx_desc - last_desc_cleaned) +
675 : : desc_to_clean_to);
676 : : else
677 : 0 : nb_tx_to_clean = (uint16_t)(desc_to_clean_to -
678 : : last_desc_cleaned);
679 : :
680 : : PMD_TX_FREE_LOG(DEBUG,
681 : : "Cleaning %4u TX descriptors: %4u to %4u "
682 : : "(port=%d queue=%d)",
683 : : nb_tx_to_clean, last_desc_cleaned, desc_to_clean_to,
684 : : txq->port_id, txq->queue_id);
685 : :
686 : : /*
687 : : * The last descriptor to clean is done, so that means all the
688 : : * descriptors from the last descriptor that was cleaned
689 : : * up to the last descriptor with the RS bit set
690 : : * are done. Only reset the threshold descriptor.
691 : : */
692 : 0 : txr[desc_to_clean_to].dw3 = 0;
693 : :
694 : : /* Update the txq to reflect the last descriptor that was cleaned */
695 : 0 : txq->last_desc_cleaned = desc_to_clean_to;
696 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + nb_tx_to_clean);
697 : :
698 : : /* No Error */
699 : 0 : return 0;
700 : : }
701 : :
702 : : #define GRE_CHECKSUM_PRESENT 0x8000
703 : : #define GRE_KEY_PRESENT 0x2000
704 : : #define GRE_SEQUENCE_PRESENT 0x1000
705 : : #define GRE_EXT_LEN 4
706 : : #define GRE_SUPPORTED_FIELDS (GRE_CHECKSUM_PRESENT | GRE_KEY_PRESENT |\
707 : : GRE_SEQUENCE_PRESENT)
708 : :
709 : : static inline uint8_t
710 : 0 : txgbe_get_tun_len(struct rte_mbuf *mbuf)
711 : : {
712 : : struct txgbe_genevehdr genevehdr;
713 : : const struct txgbe_genevehdr *gh;
714 : : const struct txgbe_grehdr *grh;
715 : : struct txgbe_grehdr grehdr;
716 : : uint8_t tun_len;
717 : :
718 [ # # # # ]: 0 : switch (mbuf->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) {
719 : : case RTE_MBUF_F_TX_TUNNEL_IPIP:
720 : : tun_len = 0;
721 : : break;
722 : 0 : case RTE_MBUF_F_TX_TUNNEL_VXLAN:
723 : : case RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE:
724 : : tun_len = sizeof(struct txgbe_udphdr)
725 : : + sizeof(struct txgbe_vxlanhdr);
726 : 0 : break;
727 : 0 : case RTE_MBUF_F_TX_TUNNEL_GRE:
728 : : tun_len = sizeof(struct txgbe_grehdr);
729 : 0 : grh = rte_pktmbuf_read(mbuf,
730 [ # # ]: 0 : mbuf->outer_l2_len + mbuf->outer_l3_len,
731 : : sizeof(grehdr), &grehdr);
732 [ # # ]: 0 : if (grh->flags & rte_cpu_to_be_16(GRE_SUPPORTED_FIELDS))
733 : : tun_len += GRE_EXT_LEN;
734 : : break;
735 : 0 : case RTE_MBUF_F_TX_TUNNEL_GENEVE:
736 : 0 : gh = rte_pktmbuf_read(mbuf, mbuf->outer_l2_len +
737 [ # # ]: 0 : mbuf->outer_l3_len + sizeof(struct txgbe_udphdr),
738 : : sizeof(genevehdr), &genevehdr);
739 : 0 : tun_len = sizeof(struct txgbe_udphdr)
740 : : + sizeof(struct txgbe_genevehdr)
741 : 0 : + (gh->opt_len << 2);
742 : 0 : break;
743 : : default:
744 : : tun_len = 0;
745 : : }
746 : :
747 : 0 : return tun_len;
748 : : }
749 : :
750 : : static inline void
751 : 0 : txgbe_fix_offload_len(union txgbe_tx_offload *ol)
752 : : {
753 : 0 : uint8_t ptid = ol->ptid;
754 : :
755 [ # # ]: 0 : if (ptid & TXGBE_PTID_PKT_TUN) {
756 [ # # ]: 0 : if (ol->outer_l2_len == 0)
757 : 0 : ol->outer_l2_len = sizeof(struct rte_ether_hdr);
758 [ # # ]: 0 : if (ol->outer_l3_len == 0) {
759 [ # # ]: 0 : if (ptid & TXGBE_PTID_TUN_IPV6)
760 : 0 : ol->outer_l3_len = sizeof(struct rte_ipv6_hdr);
761 : : else
762 : 0 : ol->outer_l3_len = sizeof(struct rte_ipv4_hdr);
763 : : }
764 [ # # ]: 0 : if ((ptid & 0xF) == 0) {
765 : 0 : ol->l3_len = 0;
766 : 0 : ol->l4_len = 0;
767 : : } else {
768 : 0 : goto inner;
769 : : }
770 : : }
771 : :
772 [ # # ]: 0 : if ((ptid & 0xF0) == TXGBE_PTID_PKT_MAC) {
773 [ # # ]: 0 : if (ol->l2_len == 0)
774 : 0 : ol->l2_len = sizeof(struct rte_ether_hdr);
775 : 0 : ol->l3_len = 0;
776 : 0 : ol->l4_len = 0;
777 [ # # ]: 0 : } else if ((ptid & 0xF0) == TXGBE_PTID_PKT_IP) {
778 [ # # ]: 0 : if (ol->l2_len == 0)
779 : 0 : ol->l2_len = sizeof(struct rte_ether_hdr);
780 : 0 : inner:
781 [ # # ]: 0 : if (ol->l3_len == 0) {
782 [ # # ]: 0 : if (ptid & TXGBE_PTID_PKT_IPV6)
783 : 0 : ol->l3_len = sizeof(struct rte_ipv6_hdr);
784 : : else
785 : 0 : ol->l3_len = sizeof(struct rte_ipv4_hdr);
786 : : }
787 [ # # # # : 0 : switch (ptid & 0x7) {
# ]
788 : 0 : case 0x1:
789 : : case 0x2:
790 : 0 : ol->l4_len = 0;
791 : 0 : break;
792 : 0 : case 0x3:
793 [ # # ]: 0 : if (ol->l4_len == 0)
794 : 0 : ol->l4_len = sizeof(struct rte_udp_hdr);
795 : : break;
796 : 0 : case 0x4:
797 [ # # ]: 0 : if (ol->l4_len == 0)
798 : 0 : ol->l4_len = sizeof(struct rte_tcp_hdr);
799 : : break;
800 : 0 : case 0x5:
801 [ # # ]: 0 : if (ol->l4_len == 0)
802 : 0 : ol->l4_len = sizeof(struct rte_sctp_hdr);
803 : : break;
804 : : default:
805 : : break;
806 : : }
807 : : }
808 : 0 : }
809 : :
810 : : static inline uint8_t
811 : : txgbe_parse_tun_ptid(struct rte_mbuf *tx_pkt, uint8_t tun_len)
812 : : {
813 : : uint64_t inner_l2_len;
814 : : uint8_t ptid = 0;
815 : :
816 : 0 : inner_l2_len = tx_pkt->l2_len - tun_len;
817 : :
818 : : switch (inner_l2_len) {
819 : : case 0:
820 : : ptid = TXGBE_PTID_TUN_EIG;
821 : : break;
822 : : case sizeof(struct rte_ether_hdr):
823 : : ptid = TXGBE_PTID_TUN_EIGM;
824 : : break;
825 : : case sizeof(struct rte_ether_hdr) + sizeof(struct rte_vlan_hdr):
826 : : ptid = TXGBE_PTID_TUN_EIGMV;
827 : : break;
828 : : default:
829 : : ptid = TXGBE_PTID_TUN_EI;
830 : : }
831 : :
832 : : return ptid;
833 : : }
834 : :
835 : : static inline bool
836 : : txgbe_check_pkt_err(struct rte_mbuf *tx_pkt)
837 : : {
838 : : uint32_t total_len = 0, nb_seg = 0;
839 : : struct rte_mbuf *mseg;
840 : :
841 : : mseg = tx_pkt;
842 : : do {
843 [ # # ]: 0 : if (mseg->data_len == 0)
844 : : return true;
845 : 0 : total_len += mseg->data_len;
846 : 0 : nb_seg++;
847 : 0 : mseg = mseg->next;
848 [ # # ]: 0 : } while (mseg != NULL);
849 : :
850 [ # # # # ]: 0 : if (tx_pkt->pkt_len != total_len || tx_pkt->pkt_len == 0)
851 : : return true;
852 : :
853 [ # # # # ]: 0 : if (tx_pkt->nb_segs != nb_seg || tx_pkt->nb_segs > 64)
854 : : return true;
855 : :
856 : : return false;
857 : : }
858 : :
859 : : uint16_t
860 : 0 : txgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
861 : : uint16_t nb_pkts)
862 : : {
863 : : struct txgbe_tx_queue *txq;
864 : : struct txgbe_tx_entry *sw_ring;
865 : : struct txgbe_tx_entry *txe, *txn;
866 : : volatile struct txgbe_tx_desc *txr;
867 : : volatile struct txgbe_tx_desc *txd;
868 : : struct rte_mbuf *tx_pkt;
869 : : struct rte_mbuf *m_seg;
870 : : uint64_t buf_dma_addr;
871 : : uint32_t olinfo_status;
872 : : uint32_t cmd_type_len;
873 : : uint32_t pkt_len;
874 : : uint16_t slen;
875 : : uint64_t ol_flags;
876 : : uint16_t tx_id;
877 : : uint16_t tx_last;
878 : : uint16_t nb_tx;
879 : : uint16_t nb_used;
880 : : uint64_t tx_ol_req;
881 : : uint32_t ctx = 0;
882 : : uint32_t new_ctx;
883 : : union txgbe_tx_offload tx_offload;
884 : : #ifdef RTE_LIB_SECURITY
885 : : uint8_t use_ipsec;
886 : : #endif
887 : :
888 : : txq = tx_queue;
889 [ # # ]: 0 : if (txq->resetting)
890 : : return 0;
891 : :
892 : 0 : tx_offload.data[0] = 0;
893 : 0 : tx_offload.data[1] = 0;
894 : 0 : sw_ring = txq->sw_ring;
895 : 0 : txr = txq->tx_ring;
896 : 0 : tx_id = txq->tx_tail;
897 : 0 : txe = &sw_ring[tx_id];
898 : :
899 : : /* Determine if the descriptor ring needs to be cleaned. */
900 [ # # ]: 0 : if (txq->nb_tx_free < txq->tx_free_thresh)
901 : 0 : txgbe_xmit_cleanup(txq);
902 : :
903 : 0 : rte_prefetch0(&txe->mbuf->pool);
904 : :
905 : : /* TX loop */
906 [ # # ]: 0 : for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
907 : : new_ctx = 0;
908 : 0 : tx_pkt = *tx_pkts++;
909 : 0 : if (txgbe_check_pkt_err(tx_pkt)) {
910 : 0 : rte_pktmbuf_free(tx_pkt);
911 : 0 : txq->desc_error++;
912 : 0 : continue;
913 : : }
914 : :
915 : 0 : pkt_len = tx_pkt->pkt_len;
916 : :
917 : : /*
918 : : * Determine how many (if any) context descriptors
919 : : * are needed for offload functionality.
920 : : */
921 : 0 : ol_flags = tx_pkt->ol_flags;
922 : : #ifdef RTE_LIB_SECURITY
923 [ # # # # ]: 0 : use_ipsec = txq->using_ipsec && (ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD);
924 : : #endif
925 : :
926 : : /* If hardware offload required */
927 : 0 : tx_ol_req = ol_flags & TXGBE_TX_OFFLOAD_MASK;
928 [ # # ]: 0 : if (tx_ol_req) {
929 : 0 : tx_offload.ptid = tx_desc_ol_flags_to_ptid(tx_ol_req);
930 : 0 : tx_offload.l2_len = tx_pkt->l2_len;
931 : 0 : tx_offload.l3_len = tx_pkt->l3_len;
932 : 0 : tx_offload.l4_len = tx_pkt->l4_len;
933 : 0 : tx_offload.vlan_tci = tx_pkt->vlan_tci;
934 : 0 : tx_offload.tso_segsz = tx_pkt->tso_segsz;
935 : 0 : tx_offload.outer_l2_len = tx_pkt->outer_l2_len;
936 : 0 : tx_offload.outer_l3_len = tx_pkt->outer_l3_len;
937 : 0 : tx_offload.outer_tun_len = txgbe_get_tun_len(tx_pkt);
938 [ # # ]: 0 : if (tx_offload.ptid & TXGBE_PTID_PKT_TUN)
939 [ # # ]: 0 : tx_offload.ptid |= txgbe_parse_tun_ptid(tx_pkt,
940 : : tx_offload.outer_tun_len);
941 : 0 : txgbe_fix_offload_len(&tx_offload);
942 : :
943 : : #ifdef RTE_LIB_SECURITY
944 [ # # ]: 0 : if (use_ipsec) {
945 : : union txgbe_crypto_tx_desc_md *ipsec_mdata =
946 : : (union txgbe_crypto_tx_desc_md *)
947 : : rte_security_dynfield(tx_pkt);
948 : 0 : tx_offload.sa_idx = ipsec_mdata->sa_idx;
949 : 0 : tx_offload.sec_pad_len = ipsec_mdata->pad_len;
950 : : }
951 : : #endif
952 : :
953 : : /* If new context need be built or reuse the exist ctx*/
954 : 0 : ctx = what_ctx_update(txq, tx_ol_req, tx_offload);
955 : : /* Only allocate context descriptor if required */
956 : 0 : new_ctx = (ctx == TXGBE_CTX_NUM);
957 : 0 : ctx = txq->ctx_curr;
958 : : }
959 : :
960 : : /*
961 : : * Keep track of how many descriptors are used this loop
962 : : * This will always be the number of segments + the number of
963 : : * Context descriptors required to transmit the packet
964 : : */
965 : 0 : nb_used = (uint16_t)(tx_pkt->nb_segs + new_ctx);
966 : :
967 : : /*
968 : : * The number of descriptors that must be allocated for a
969 : : * packet is the number of segments of that packet, plus 1
970 : : * Context Descriptor for the hardware offload, if any.
971 : : * Determine the last TX descriptor to allocate in the TX ring
972 : : * for the packet, starting from the current position (tx_id)
973 : : * in the ring.
974 : : */
975 : 0 : tx_last = (uint16_t)(tx_id + nb_used - 1);
976 : :
977 : : /* Circular ring */
978 [ # # ]: 0 : if (tx_last >= txq->nb_tx_desc)
979 : 0 : tx_last = (uint16_t)(tx_last - txq->nb_tx_desc);
980 : :
981 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u pktlen=%u"
982 : : " tx_first=%u tx_last=%u",
983 : : (uint16_t)txq->port_id,
984 : : (uint16_t)txq->queue_id,
985 : : (uint32_t)pkt_len,
986 : : (uint16_t)tx_id,
987 : : (uint16_t)tx_last);
988 : :
989 : : /*
990 : : * Make sure there are enough TX descriptors available to
991 : : * transmit the entire packet.
992 : : * nb_used better be less than or equal to txq->tx_free_thresh
993 : : */
994 [ # # ]: 0 : if (nb_used > txq->nb_tx_free) {
995 : : PMD_TX_FREE_LOG(DEBUG,
996 : : "Not enough free TX descriptors "
997 : : "nb_used=%4u nb_free=%4u "
998 : : "(port=%d queue=%d)",
999 : : nb_used, txq->nb_tx_free,
1000 : : txq->port_id, txq->queue_id);
1001 : :
1002 [ # # ]: 0 : if (txgbe_xmit_cleanup(txq) != 0) {
1003 : : /* Could not clean any descriptors */
1004 [ # # ]: 0 : if (nb_tx == 0)
1005 : : return 0;
1006 : 0 : goto end_of_tx;
1007 : : }
1008 : :
1009 : : /* nb_used better be <= txq->tx_free_thresh */
1010 [ # # ]: 0 : if (unlikely(nb_used > txq->tx_free_thresh)) {
1011 : : PMD_TX_FREE_LOG(DEBUG,
1012 : : "The number of descriptors needed to "
1013 : : "transmit the packet exceeds the "
1014 : : "RS bit threshold. This will impact "
1015 : : "performance."
1016 : : "nb_used=%4u nb_free=%4u "
1017 : : "tx_free_thresh=%4u. "
1018 : : "(port=%d queue=%d)",
1019 : : nb_used, txq->nb_tx_free,
1020 : : txq->tx_free_thresh,
1021 : : txq->port_id, txq->queue_id);
1022 : : /*
1023 : : * Loop here until there are enough TX
1024 : : * descriptors or until the ring cannot be
1025 : : * cleaned.
1026 : : */
1027 [ # # ]: 0 : while (nb_used > txq->nb_tx_free) {
1028 [ # # ]: 0 : if (txgbe_xmit_cleanup(txq) != 0) {
1029 : : /*
1030 : : * Could not clean any
1031 : : * descriptors
1032 : : */
1033 [ # # ]: 0 : if (nb_tx == 0)
1034 : : return 0;
1035 : 0 : goto end_of_tx;
1036 : : }
1037 : : }
1038 : : }
1039 : : }
1040 : :
1041 : : /*
1042 : : * By now there are enough free TX descriptors to transmit
1043 : : * the packet.
1044 : : */
1045 : :
1046 : : /*
1047 : : * Set common flags of all TX Data Descriptors.
1048 : : *
1049 : : * The following bits must be set in all Data Descriptors:
1050 : : * - TXGBE_TXD_DTYP_DATA
1051 : : * - TXGBE_TXD_DCMD_DEXT
1052 : : *
1053 : : * The following bits must be set in the first Data Descriptor
1054 : : * and are ignored in the other ones:
1055 : : * - TXGBE_TXD_DCMD_IFCS
1056 : : * - TXGBE_TXD_MAC_1588
1057 : : * - TXGBE_TXD_DCMD_VLE
1058 : : *
1059 : : * The following bits must only be set in the last Data
1060 : : * Descriptor:
1061 : : * - TXGBE_TXD_CMD_EOP
1062 : : *
1063 : : * The following bits can be set in any Data Descriptor, but
1064 : : * are only set in the last Data Descriptor:
1065 : : * - TXGBE_TXD_CMD_RS
1066 : : */
1067 : : cmd_type_len = TXGBE_TXD_FCS;
1068 : :
1069 : : #ifdef RTE_LIBRTE_IEEE1588
1070 : : if (ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
1071 : : cmd_type_len |= TXGBE_TXD_1588;
1072 : : #endif
1073 : :
1074 : : olinfo_status = 0;
1075 [ # # ]: 0 : if (tx_ol_req) {
1076 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)) {
1077 : : /* when TSO is on, paylen in descriptor is the
1078 : : * not the packet len but the tcp payload len
1079 : : */
1080 : 0 : pkt_len -= (tx_offload.l2_len +
1081 : 0 : tx_offload.l3_len + tx_offload.l4_len);
1082 : 0 : pkt_len -=
1083 : 0 : (tx_pkt->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK)
1084 : 0 : ? tx_offload.outer_l2_len +
1085 [ # # ]: 0 : tx_offload.outer_l3_len : 0;
1086 : : }
1087 : :
1088 : : /*
1089 : : * Setup the TX Advanced Context Descriptor if required
1090 : : */
1091 [ # # ]: 0 : if (new_ctx) {
1092 : : volatile struct txgbe_tx_ctx_desc *ctx_txd;
1093 : :
1094 : 0 : ctx_txd = (volatile struct txgbe_tx_ctx_desc *)
1095 : 0 : &txr[tx_id];
1096 : :
1097 : 0 : txn = &sw_ring[txe->next_id];
1098 : 0 : rte_prefetch0(&txn->mbuf->pool);
1099 : :
1100 [ # # ]: 0 : if (txe->mbuf != NULL) {
1101 : : rte_pktmbuf_free_seg(txe->mbuf);
1102 : 0 : txe->mbuf = NULL;
1103 : : }
1104 : :
1105 : 0 : txgbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req,
1106 : : tx_offload,
1107 : : rte_security_dynfield(tx_pkt));
1108 : :
1109 : 0 : txe->last_id = tx_last;
1110 : 0 : tx_id = txe->next_id;
1111 : : txe = txn;
1112 : : }
1113 : :
1114 : : /*
1115 : : * Setup the TX Advanced Data Descriptor,
1116 : : * This path will go through
1117 : : * whatever new/reuse the context descriptor
1118 : : */
1119 : 0 : cmd_type_len |= tx_desc_ol_flags_to_cmdtype(ol_flags);
1120 : : olinfo_status |=
1121 : 0 : tx_desc_cksum_flags_to_olinfo(ol_flags);
1122 : 0 : olinfo_status |= TXGBE_TXD_IDX(ctx);
1123 : : }
1124 : :
1125 : 0 : olinfo_status |= TXGBE_TXD_PAYLEN(pkt_len);
1126 : : #ifdef RTE_LIB_SECURITY
1127 [ # # ]: 0 : if (use_ipsec)
1128 : 0 : olinfo_status |= TXGBE_TXD_IPSEC;
1129 : : #endif
1130 : :
1131 : : m_seg = tx_pkt;
1132 : : do {
1133 : 0 : txd = &txr[tx_id];
1134 : 0 : txn = &sw_ring[txe->next_id];
1135 : 0 : rte_prefetch0(&txn->mbuf->pool);
1136 : :
1137 [ # # ]: 0 : if (txe->mbuf != NULL)
1138 : : rte_pktmbuf_free_seg(txe->mbuf);
1139 : 0 : txe->mbuf = m_seg;
1140 : :
1141 : : /*
1142 : : * Set up Transmit Data Descriptor.
1143 : : */
1144 [ # # ]: 0 : slen = m_seg->data_len;
1145 : : buf_dma_addr = rte_mbuf_data_iova(m_seg);
1146 : 0 : txd->qw0 = rte_cpu_to_le_64(buf_dma_addr);
1147 : 0 : txd->dw2 = rte_cpu_to_le_32(cmd_type_len | slen);
1148 : 0 : txd->dw3 = rte_cpu_to_le_32(olinfo_status);
1149 : 0 : txe->last_id = tx_last;
1150 : 0 : tx_id = txe->next_id;
1151 : : txe = txn;
1152 : 0 : m_seg = m_seg->next;
1153 [ # # ]: 0 : } while (m_seg != NULL);
1154 : :
1155 : : /*
1156 : : * The last packet data descriptor needs End Of Packet (EOP)
1157 : : */
1158 : 0 : cmd_type_len |= TXGBE_TXD_EOP;
1159 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_used);
1160 : :
1161 : 0 : txd->dw2 |= rte_cpu_to_le_32(cmd_type_len);
1162 : : }
1163 : :
1164 : 0 : end_of_tx:
1165 : :
1166 : : rte_wmb();
1167 : :
1168 : : /*
1169 : : * Set the Transmit Descriptor Tail (TDT)
1170 : : */
1171 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
1172 : : (uint16_t)txq->port_id, (uint16_t)txq->queue_id,
1173 : : (uint16_t)tx_id, (uint16_t)nb_tx);
1174 : 0 : txgbe_set32_relaxed(txq->tdt_reg_addr, tx_id);
1175 : 0 : txq->tx_tail = tx_id;
1176 : :
1177 : 0 : return nb_tx;
1178 : : }
1179 : :
1180 : : /*********************************************************************
1181 : : *
1182 : : * TX prep functions
1183 : : *
1184 : : **********************************************************************/
1185 : : uint16_t
1186 : 0 : txgbe_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1187 : : {
1188 : : int i, ret;
1189 : : uint64_t ol_flags;
1190 : : struct rte_mbuf *m;
1191 : : struct txgbe_tx_queue *txq = (struct txgbe_tx_queue *)tx_queue;
1192 : :
1193 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
1194 : 0 : m = tx_pkts[i];
1195 : 0 : ol_flags = m->ol_flags;
1196 : :
1197 : : /**
1198 : : * Check if packet meets requirements for number of segments
1199 : : *
1200 : : * NOTE: for txgbe it's always (40 - WTHRESH) for both TSO and
1201 : : * non-TSO
1202 : : */
1203 : :
1204 [ # # ]: 0 : if (m->nb_segs > TXGBE_TX_MAX_SEG - txq->wthresh) {
1205 : 0 : rte_errno = -EINVAL;
1206 : 0 : return i;
1207 : : }
1208 : :
1209 [ # # ]: 0 : if (ol_flags & TXGBE_TX_OFFLOAD_NOTSUP_MASK) {
1210 : 0 : rte_errno = -ENOTSUP;
1211 : 0 : return i;
1212 : : }
1213 : :
1214 : : #ifdef RTE_LIBRTE_ETHDEV_DEBUG
1215 : : ret = rte_validate_tx_offload(m);
1216 : : if (ret != 0) {
1217 : : rte_errno = ret;
1218 : : return i;
1219 : : }
1220 : : #endif
1221 : : ret = rte_net_intel_cksum_prepare(m);
1222 [ # # ]: 0 : if (ret != 0) {
1223 : 0 : rte_errno = ret;
1224 : 0 : return i;
1225 : : }
1226 : : }
1227 : :
1228 : 0 : return i;
1229 : : }
1230 : :
1231 : : /*********************************************************************
1232 : : *
1233 : : * RX functions
1234 : : *
1235 : : **********************************************************************/
1236 : : /* @note: fix txgbe_dev_supported_ptypes_get() if any change here. */
1237 : : static inline uint32_t
1238 : : txgbe_rxd_pkt_info_to_pkt_type(uint32_t pkt_info, uint16_t ptid_mask)
1239 : : {
1240 : 0 : uint16_t ptid = TXGBE_RXD_PTID(pkt_info);
1241 : :
1242 : 0 : ptid &= ptid_mask;
1243 : :
1244 : 0 : return txgbe_decode_ptype(ptid);
1245 : : }
1246 : :
1247 : : static inline uint64_t
1248 : : txgbe_rxd_pkt_info_to_pkt_flags(uint32_t pkt_info)
1249 : : {
1250 : : static alignas(RTE_CACHE_LINE_SIZE) uint64_t ip_rss_types_map[16] = {
1251 : : 0, RTE_MBUF_F_RX_RSS_HASH, RTE_MBUF_F_RX_RSS_HASH, RTE_MBUF_F_RX_RSS_HASH,
1252 : : 0, RTE_MBUF_F_RX_RSS_HASH, 0, RTE_MBUF_F_RX_RSS_HASH,
1253 : : RTE_MBUF_F_RX_RSS_HASH, 0, 0, 0,
1254 : : 0, 0, 0, RTE_MBUF_F_RX_FDIR,
1255 : : };
1256 : : #ifdef RTE_LIBRTE_IEEE1588
1257 : : static uint64_t ip_pkt_etqf_map[8] = {
1258 : : 0, 0, 0, RTE_MBUF_F_RX_IEEE1588_PTP,
1259 : : 0, 0, 0, 0,
1260 : : };
1261 : : int etfid = txgbe_etflt_id(TXGBE_RXD_PTID(pkt_info));
1262 : : if (likely(-1 != etfid))
1263 : : return ip_pkt_etqf_map[etfid] |
1264 : : ip_rss_types_map[TXGBE_RXD_RSSTYPE(pkt_info)];
1265 : : else
1266 : : return ip_rss_types_map[TXGBE_RXD_RSSTYPE(pkt_info)];
1267 : : #else
1268 : 0 : return ip_rss_types_map[TXGBE_RXD_RSSTYPE(pkt_info)];
1269 : : #endif
1270 : : }
1271 : :
1272 : : static inline uint64_t
1273 : : rx_desc_status_to_pkt_flags(uint32_t rx_status, uint64_t vlan_flags)
1274 : : {
1275 : : uint64_t pkt_flags;
1276 : :
1277 : : /*
1278 : : * Check if VLAN present only.
1279 : : * Do not check whether L3/L4 rx checksum done by NIC or not,
1280 : : * That can be found from rte_eth_rxmode.offloads flag
1281 : : */
1282 : 0 : pkt_flags = (rx_status & TXGBE_RXD_STAT_VLAN &&
1283 [ # # # # : 0 : vlan_flags & RTE_MBUF_F_RX_VLAN_STRIPPED)
# # ]
1284 : 0 : ? vlan_flags : 0;
1285 : :
1286 : : #ifdef RTE_LIBRTE_IEEE1588
1287 : : if (rx_status & TXGBE_RXD_STAT_1588)
1288 : : pkt_flags = pkt_flags | RTE_MBUF_F_RX_IEEE1588_TMST;
1289 : : #endif
1290 : : return pkt_flags;
1291 : : }
1292 : :
1293 : : static inline uint64_t
1294 : 0 : rx_desc_error_to_pkt_flags(uint32_t rx_status, struct txgbe_rx_queue *rxq)
1295 : : {
1296 : : uint64_t pkt_flags = 0;
1297 : :
1298 : : /* checksum offload can't be disabled */
1299 [ # # ]: 0 : if (rx_status & TXGBE_RXD_STAT_IPCS) {
1300 : : pkt_flags |= (rx_status & TXGBE_RXD_ERR_IPCS
1301 [ # # ]: 0 : ? RTE_MBUF_F_RX_IP_CKSUM_BAD : RTE_MBUF_F_RX_IP_CKSUM_GOOD);
1302 : 0 : rxq->csum_err += !!(rx_status & TXGBE_RXD_ERR_IPCS);
1303 : : }
1304 : :
1305 [ # # ]: 0 : if (rx_status & TXGBE_RXD_STAT_L4CS) {
1306 : 0 : pkt_flags |= (rx_status & TXGBE_RXD_ERR_L4CS
1307 [ # # ]: 0 : ? RTE_MBUF_F_RX_L4_CKSUM_BAD : RTE_MBUF_F_RX_L4_CKSUM_GOOD);
1308 : 0 : rxq->csum_err += !!(rx_status & TXGBE_RXD_ERR_L4CS);
1309 : : }
1310 : :
1311 [ # # ]: 0 : if (rx_status & TXGBE_RXD_STAT_EIPCS &&
1312 : : rx_status & TXGBE_RXD_ERR_EIPCS) {
1313 : 0 : pkt_flags |= RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD;
1314 : 0 : rxq->csum_err += !!(rx_status & TXGBE_RXD_ERR_EIPCS);
1315 : : }
1316 : :
1317 : : #ifdef RTE_LIB_SECURITY
1318 [ # # ]: 0 : if (rx_status & TXGBE_RXD_STAT_SECP) {
1319 : 0 : pkt_flags |= RTE_MBUF_F_RX_SEC_OFFLOAD;
1320 [ # # ]: 0 : if (rx_status & TXGBE_RXD_ERR_SECERR)
1321 : 0 : pkt_flags |= RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED;
1322 : : }
1323 : : #endif
1324 : :
1325 : 0 : return pkt_flags;
1326 : : }
1327 : :
1328 : : /*
1329 : : * LOOK_AHEAD defines how many desc statuses to check beyond the
1330 : : * current descriptor.
1331 : : * It must be a pound define for optimal performance.
1332 : : * Do not change the value of LOOK_AHEAD, as the txgbe_rx_scan_hw_ring
1333 : : * function only works with LOOK_AHEAD=8.
1334 : : */
1335 : : #define LOOK_AHEAD 8
1336 : : #if (LOOK_AHEAD != 8)
1337 : : #error "PMD TXGBE: LOOK_AHEAD must be 8\n"
1338 : : #endif
1339 : : static inline int
1340 : 0 : txgbe_rx_scan_hw_ring(struct txgbe_rx_queue *rxq)
1341 : : {
1342 : : volatile struct txgbe_rx_desc *rxdp;
1343 : : struct txgbe_rx_entry *rxep;
1344 : : struct rte_mbuf *mb;
1345 : : uint16_t pkt_len;
1346 : : uint64_t pkt_flags;
1347 : : int nb_dd;
1348 : : uint32_t s[LOOK_AHEAD];
1349 : : uint32_t pkt_info[LOOK_AHEAD];
1350 : : int i, j, nb_rx = 0;
1351 : : uint32_t status;
1352 : :
1353 : : /* get references to current descriptor and S/W ring entry */
1354 : 0 : rxdp = &rxq->rx_ring[rxq->rx_tail];
1355 : 0 : rxep = &rxq->sw_ring[rxq->rx_tail];
1356 : :
1357 : 0 : status = rxdp->qw1.lo.status;
1358 : : /* check to make sure there is at least 1 packet to receive */
1359 [ # # ]: 0 : if (!(status & rte_cpu_to_le_32(TXGBE_RXD_STAT_DD)))
1360 : : return 0;
1361 : :
1362 : : /*
1363 : : * Scan LOOK_AHEAD descriptors at a time to determine which descriptors
1364 : : * reference packets that are ready to be received.
1365 : : */
1366 [ # # ]: 0 : for (i = 0; i < RTE_PMD_TXGBE_RX_MAX_BURST;
1367 : 0 : i += LOOK_AHEAD, rxdp += LOOK_AHEAD, rxep += LOOK_AHEAD) {
1368 : : /* Read desc statuses backwards to avoid race condition */
1369 [ # # ]: 0 : for (j = 0; j < LOOK_AHEAD; j++)
1370 : 0 : s[j] = rte_le_to_cpu_32(rxdp[j].qw1.lo.status);
1371 : :
1372 : : rte_atomic_thread_fence(rte_memory_order_acquire);
1373 : :
1374 : : /* Compute how many status bits were set */
1375 [ # # ]: 0 : for (nb_dd = 0; nb_dd < LOOK_AHEAD &&
1376 [ # # ]: 0 : (s[nb_dd] & TXGBE_RXD_STAT_DD); nb_dd++)
1377 : : ;
1378 : :
1379 [ # # ]: 0 : for (j = 0; j < nb_dd; j++)
1380 : 0 : pkt_info[j] = rte_le_to_cpu_32(rxdp[j].qw0.dw0);
1381 : :
1382 : 0 : nb_rx += nb_dd;
1383 : :
1384 : : /* Translate descriptor info to mbuf format */
1385 [ # # ]: 0 : for (j = 0; j < nb_dd; ++j) {
1386 : 0 : mb = rxep[j].mbuf;
1387 : 0 : pkt_len = rte_le_to_cpu_16(rxdp[j].qw1.hi.len) -
1388 : 0 : rxq->crc_len;
1389 : 0 : mb->data_len = pkt_len;
1390 : 0 : mb->pkt_len = pkt_len;
1391 : 0 : mb->vlan_tci = rte_le_to_cpu_16(rxdp[j].qw1.hi.tag);
1392 : :
1393 : : /* convert descriptor fields to rte mbuf flags */
1394 [ # # ]: 0 : pkt_flags = rx_desc_status_to_pkt_flags(s[j],
1395 : : rxq->vlan_flags);
1396 : 0 : pkt_flags |= rx_desc_error_to_pkt_flags(s[j], rxq);
1397 : 0 : pkt_flags |=
1398 : 0 : txgbe_rxd_pkt_info_to_pkt_flags(pkt_info[j]);
1399 : 0 : mb->ol_flags = pkt_flags;
1400 : 0 : mb->packet_type =
1401 : : txgbe_rxd_pkt_info_to_pkt_type(pkt_info[j],
1402 : 0 : rxq->pkt_type_mask);
1403 : :
1404 [ # # ]: 0 : if (likely(pkt_flags & RTE_MBUF_F_RX_RSS_HASH))
1405 : 0 : mb->hash.rss =
1406 : 0 : rte_le_to_cpu_32(rxdp[j].qw0.dw1);
1407 [ # # ]: 0 : else if (pkt_flags & RTE_MBUF_F_RX_FDIR) {
1408 : 0 : mb->hash.fdir.hash =
1409 : 0 : rte_le_to_cpu_16(rxdp[j].qw0.hi.csum) &
1410 : : TXGBE_ATR_HASH_MASK;
1411 : 0 : mb->hash.fdir.id =
1412 : 0 : rte_le_to_cpu_16(rxdp[j].qw0.hi.ipid);
1413 : : }
1414 : : }
1415 : :
1416 : : /* Move mbuf pointers from the S/W ring to the stage */
1417 [ # # ]: 0 : for (j = 0; j < LOOK_AHEAD; ++j)
1418 : 0 : rxq->rx_stage[i + j] = rxep[j].mbuf;
1419 : :
1420 : : /* stop if all requested packets could not be received */
1421 [ # # ]: 0 : if (nb_dd != LOOK_AHEAD)
1422 : : break;
1423 : : }
1424 : :
1425 : : /* clear software ring entries so we can cleanup correctly */
1426 [ # # ]: 0 : for (i = 0; i < nb_rx; ++i)
1427 : 0 : rxq->sw_ring[rxq->rx_tail + i].mbuf = NULL;
1428 : :
1429 : : return nb_rx;
1430 : : }
1431 : :
1432 : : static inline int
1433 : 0 : txgbe_rx_alloc_bufs(struct txgbe_rx_queue *rxq, bool reset_mbuf)
1434 : : {
1435 : : volatile struct txgbe_rx_desc *rxdp;
1436 : : struct txgbe_rx_entry *rxep;
1437 : : struct rte_mbuf *mb;
1438 : : uint16_t alloc_idx;
1439 : : __le64 dma_addr;
1440 : : int diag, i;
1441 : :
1442 : : /* allocate buffers in bulk directly into the S/W ring */
1443 : 0 : alloc_idx = rxq->rx_free_trigger - (rxq->rx_free_thresh - 1);
1444 : 0 : rxep = &rxq->sw_ring[alloc_idx];
1445 [ # # ]: 0 : diag = rte_mempool_get_bulk(rxq->mb_pool, (void *)rxep,
1446 : : rxq->rx_free_thresh);
1447 [ # # ]: 0 : if (unlikely(diag != 0))
1448 : : return -ENOMEM;
1449 : :
1450 : 0 : rxdp = &rxq->rx_ring[alloc_idx];
1451 [ # # ]: 0 : for (i = 0; i < rxq->rx_free_thresh; ++i) {
1452 : : /* populate the static rte mbuf fields */
1453 : 0 : mb = rxep[i].mbuf;
1454 [ # # ]: 0 : if (reset_mbuf)
1455 : 0 : mb->port = rxq->port_id;
1456 : :
1457 : : rte_mbuf_refcnt_set(mb, 1);
1458 : 0 : mb->data_off = RTE_PKTMBUF_HEADROOM;
1459 : :
1460 : : /* populate the descriptors */
1461 : : dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mb));
1462 : 0 : TXGBE_RXD_HDRADDR(&rxdp[i], 0);
1463 : 0 : TXGBE_RXD_PKTADDR(&rxdp[i], dma_addr);
1464 : : }
1465 : :
1466 : : /* update state of internal queue structure */
1467 : 0 : rxq->rx_free_trigger = rxq->rx_free_trigger + rxq->rx_free_thresh;
1468 [ # # ]: 0 : if (rxq->rx_free_trigger >= rxq->nb_rx_desc)
1469 : 0 : rxq->rx_free_trigger = rxq->rx_free_thresh - 1;
1470 : :
1471 : : /* no errors */
1472 : : return 0;
1473 : : }
1474 : :
1475 : : static inline uint16_t
1476 : : txgbe_rx_fill_from_stage(struct txgbe_rx_queue *rxq, struct rte_mbuf **rx_pkts,
1477 : : uint16_t nb_pkts)
1478 : : {
1479 : 0 : struct rte_mbuf **stage = &rxq->rx_stage[rxq->rx_next_avail];
1480 : : int i;
1481 : :
1482 : : /* how many packets are ready to return? */
1483 : 0 : nb_pkts = (uint16_t)RTE_MIN(nb_pkts, rxq->rx_nb_avail);
1484 : :
1485 : : /* copy mbuf pointers to the application's packet list */
1486 [ # # # # ]: 0 : for (i = 0; i < nb_pkts; ++i)
1487 : 0 : rx_pkts[i] = stage[i];
1488 : :
1489 : : /* update internal queue state */
1490 : 0 : rxq->rx_nb_avail = (uint16_t)(rxq->rx_nb_avail - nb_pkts);
1491 : 0 : rxq->rx_next_avail = (uint16_t)(rxq->rx_next_avail + nb_pkts);
1492 : :
1493 : : return nb_pkts;
1494 : : }
1495 : :
1496 : : static inline uint16_t
1497 : 0 : txgbe_rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1498 : : uint16_t nb_pkts)
1499 : : {
1500 : : struct txgbe_rx_queue *rxq = (struct txgbe_rx_queue *)rx_queue;
1501 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
1502 : : uint16_t nb_rx = 0;
1503 : :
1504 : : /* Any previously recv'd pkts will be returned from the Rx stage */
1505 [ # # ]: 0 : if (rxq->rx_nb_avail)
1506 : 0 : return txgbe_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
1507 : :
1508 : : /* Scan the H/W ring for packets to receive */
1509 : 0 : nb_rx = (uint16_t)txgbe_rx_scan_hw_ring(rxq);
1510 : :
1511 : : /* update internal queue state */
1512 : 0 : rxq->rx_next_avail = 0;
1513 : 0 : rxq->rx_nb_avail = nb_rx;
1514 : 0 : rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_rx);
1515 : :
1516 : : /* if required, allocate new buffers to replenish descriptors */
1517 [ # # ]: 0 : if (rxq->rx_tail > rxq->rx_free_trigger) {
1518 : : uint16_t cur_free_trigger = rxq->rx_free_trigger;
1519 : :
1520 [ # # ]: 0 : if (txgbe_rx_alloc_bufs(rxq, true) != 0) {
1521 : : int i, j;
1522 : :
1523 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1524 : : "queue_id=%u", (uint16_t)rxq->port_id,
1525 : : (uint16_t)rxq->queue_id);
1526 : :
1527 : 0 : dev->data->rx_mbuf_alloc_failed +=
1528 : 0 : rxq->rx_free_thresh;
1529 : :
1530 : : /*
1531 : : * Need to rewind any previous receives if we cannot
1532 : : * allocate new buffers to replenish the old ones.
1533 : : */
1534 : 0 : rxq->rx_nb_avail = 0;
1535 : 0 : rxq->rx_tail = (uint16_t)(rxq->rx_tail - nb_rx);
1536 [ # # ]: 0 : for (i = 0, j = rxq->rx_tail; i < nb_rx; ++i, ++j)
1537 : 0 : rxq->sw_ring[j].mbuf = rxq->rx_stage[i];
1538 : :
1539 : : return 0;
1540 : : }
1541 : :
1542 : : /* update tail pointer */
1543 : : rte_wmb();
1544 : 0 : txgbe_set32_relaxed(rxq->rdt_reg_addr, cur_free_trigger);
1545 : : }
1546 : :
1547 [ # # ]: 0 : if (rxq->rx_tail >= rxq->nb_rx_desc)
1548 : 0 : rxq->rx_tail = 0;
1549 : :
1550 : : /* received any packets this loop? */
1551 [ # # ]: 0 : if (rxq->rx_nb_avail)
1552 : 0 : return txgbe_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
1553 : :
1554 : : return 0;
1555 : : }
1556 : :
1557 : : /* split requests into chunks of size RTE_PMD_TXGBE_RX_MAX_BURST */
1558 : : uint16_t
1559 : 0 : txgbe_recv_pkts_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
1560 : : uint16_t nb_pkts)
1561 : : {
1562 : : uint16_t nb_rx;
1563 : :
1564 [ # # ]: 0 : if (unlikely(nb_pkts == 0))
1565 : : return 0;
1566 : :
1567 [ # # ]: 0 : if (likely(nb_pkts <= RTE_PMD_TXGBE_RX_MAX_BURST))
1568 : 0 : return txgbe_rx_recv_pkts(rx_queue, rx_pkts, nb_pkts);
1569 : :
1570 : : /* request is relatively large, chunk it up */
1571 : : nb_rx = 0;
1572 [ # # ]: 0 : while (nb_pkts) {
1573 : : uint16_t ret, n;
1574 : :
1575 : 0 : n = (uint16_t)RTE_MIN(nb_pkts, RTE_PMD_TXGBE_RX_MAX_BURST);
1576 : 0 : ret = txgbe_rx_recv_pkts(rx_queue, &rx_pkts[nb_rx], n);
1577 : 0 : nb_rx = (uint16_t)(nb_rx + ret);
1578 : 0 : nb_pkts = (uint16_t)(nb_pkts - ret);
1579 [ # # ]: 0 : if (ret < n)
1580 : : break;
1581 : : }
1582 : :
1583 : : return nb_rx;
1584 : : }
1585 : :
1586 : : uint16_t
1587 : 0 : txgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1588 : : uint16_t nb_pkts)
1589 : : {
1590 : : struct txgbe_rx_queue *rxq;
1591 : : volatile struct txgbe_rx_desc *rx_ring;
1592 : : volatile struct txgbe_rx_desc *rxdp;
1593 : : struct txgbe_rx_entry *sw_ring;
1594 : : struct txgbe_rx_entry *rxe;
1595 : : struct rte_mbuf *rxm;
1596 : : struct rte_mbuf *nmb;
1597 : : struct txgbe_rx_desc rxd;
1598 : : uint64_t dma_addr;
1599 : : uint32_t staterr;
1600 : : uint32_t pkt_info;
1601 : : uint16_t pkt_len;
1602 : : uint16_t rx_id;
1603 : : uint16_t nb_rx;
1604 : : uint16_t nb_hold;
1605 : : uint64_t pkt_flags;
1606 : :
1607 : : nb_rx = 0;
1608 : : nb_hold = 0;
1609 : : rxq = rx_queue;
1610 : 0 : rx_id = rxq->rx_tail;
1611 : 0 : rx_ring = rxq->rx_ring;
1612 : 0 : sw_ring = rxq->sw_ring;
1613 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
1614 [ # # ]: 0 : while (nb_rx < nb_pkts) {
1615 : : /*
1616 : : * The order of operations here is important as the DD status
1617 : : * bit must not be read after any other descriptor fields.
1618 : : * rx_ring and rxdp are pointing to volatile data so the order
1619 : : * of accesses cannot be reordered by the compiler. If they were
1620 : : * not volatile, they could be reordered which could lead to
1621 : : * using invalid descriptor fields when read from rxd.
1622 : : *
1623 : : * Meanwhile, to prevent the CPU from executing out of order, we
1624 : : * need to use a proper memory barrier to ensure the memory
1625 : : * ordering below.
1626 : : */
1627 : 0 : rxdp = &rx_ring[rx_id];
1628 : 0 : staterr = rxdp->qw1.lo.status;
1629 [ # # ]: 0 : if (!(staterr & rte_cpu_to_le_32(TXGBE_RXD_STAT_DD)))
1630 : : break;
1631 : :
1632 : : /*
1633 : : * Use acquire fence to ensure that status_error which includes
1634 : : * DD bit is loaded before loading of other descriptor words.
1635 : : */
1636 : : rte_atomic_thread_fence(rte_memory_order_acquire);
1637 : :
1638 : 0 : rxd = *rxdp;
1639 : :
1640 : : /*
1641 : : * End of packet.
1642 : : *
1643 : : * If the TXGBE_RXD_STAT_EOP flag is not set, the RX packet
1644 : : * is likely to be invalid and to be dropped by the various
1645 : : * validation checks performed by the network stack.
1646 : : *
1647 : : * Allocate a new mbuf to replenish the RX ring descriptor.
1648 : : * If the allocation fails:
1649 : : * - arrange for that RX descriptor to be the first one
1650 : : * being parsed the next time the receive function is
1651 : : * invoked [on the same queue].
1652 : : *
1653 : : * - Stop parsing the RX ring and return immediately.
1654 : : *
1655 : : * This policy do not drop the packet received in the RX
1656 : : * descriptor for which the allocation of a new mbuf failed.
1657 : : * Thus, it allows that packet to be later retrieved if
1658 : : * mbuf have been freed in the mean time.
1659 : : * As a side effect, holding RX descriptors instead of
1660 : : * systematically giving them back to the NIC may lead to
1661 : : * RX ring exhaustion situations.
1662 : : * However, the NIC can gracefully prevent such situations
1663 : : * to happen by sending specific "back-pressure" flow control
1664 : : * frames to its peer(s).
1665 : : */
1666 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
1667 : : "ext_err_stat=0x%08x pkt_len=%u",
1668 : : (uint16_t)rxq->port_id, (uint16_t)rxq->queue_id,
1669 : : (uint16_t)rx_id, (uint32_t)staterr,
1670 : : (uint16_t)rte_le_to_cpu_16(rxd.qw1.hi.len));
1671 : :
1672 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
1673 [ # # ]: 0 : if (nmb == NULL) {
1674 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1675 : : "queue_id=%u", (uint16_t)rxq->port_id,
1676 : : (uint16_t)rxq->queue_id);
1677 : 0 : dev->data->rx_mbuf_alloc_failed++;
1678 : 0 : break;
1679 : : }
1680 : :
1681 : 0 : nb_hold++;
1682 : 0 : rxe = &sw_ring[rx_id];
1683 : 0 : rx_id++;
1684 [ # # ]: 0 : if (rx_id == rxq->nb_rx_desc)
1685 : : rx_id = 0;
1686 : :
1687 : : /* Prefetch next mbuf while processing current one. */
1688 : 0 : rte_txgbe_prefetch(sw_ring[rx_id].mbuf);
1689 : :
1690 : : /*
1691 : : * When next RX descriptor is on a cache-line boundary,
1692 : : * prefetch the next 4 RX descriptors and the next 8 pointers
1693 : : * to mbufs.
1694 : : */
1695 [ # # ]: 0 : if ((rx_id & 0x3) == 0) {
1696 : 0 : rte_txgbe_prefetch(&rx_ring[rx_id]);
1697 : : rte_txgbe_prefetch(&sw_ring[rx_id]);
1698 : : }
1699 : :
1700 : 0 : rxm = rxe->mbuf;
1701 : 0 : rxe->mbuf = nmb;
1702 : : dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1703 : 0 : TXGBE_RXD_HDRADDR(rxdp, 0);
1704 : 0 : TXGBE_RXD_PKTADDR(rxdp, dma_addr);
1705 : :
1706 : : /*
1707 : : * Initialize the returned mbuf.
1708 : : * 1) setup generic mbuf fields:
1709 : : * - number of segments,
1710 : : * - next segment,
1711 : : * - packet length,
1712 : : * - RX port identifier.
1713 : : * 2) integrate hardware offload data, if any:
1714 : : * - RSS flag & hash,
1715 : : * - IP checksum flag,
1716 : : * - VLAN TCI, if any,
1717 : : * - error flags.
1718 : : */
1719 : 0 : pkt_len = (uint16_t)(rte_le_to_cpu_16(rxd.qw1.hi.len) -
1720 : 0 : rxq->crc_len);
1721 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
1722 : 0 : rte_packet_prefetch((char *)rxm->buf_addr + rxm->data_off);
1723 : 0 : rxm->nb_segs = 1;
1724 : 0 : rxm->next = NULL;
1725 : 0 : rxm->pkt_len = pkt_len;
1726 : 0 : rxm->data_len = pkt_len;
1727 : 0 : rxm->port = rxq->port_id;
1728 : :
1729 : : pkt_info = rte_le_to_cpu_32(rxd.qw0.dw0);
1730 : : /* Only valid if RTE_MBUF_F_RX_VLAN set in pkt_flags */
1731 : 0 : rxm->vlan_tci = rte_le_to_cpu_16(rxd.qw1.hi.tag);
1732 : :
1733 [ # # ]: 0 : pkt_flags = rx_desc_status_to_pkt_flags(staterr,
1734 : : rxq->vlan_flags);
1735 : 0 : pkt_flags |= rx_desc_error_to_pkt_flags(staterr, rxq);
1736 : 0 : pkt_flags |= txgbe_rxd_pkt_info_to_pkt_flags(pkt_info);
1737 : 0 : rxm->ol_flags = pkt_flags;
1738 : 0 : rxm->packet_type = txgbe_rxd_pkt_info_to_pkt_type(pkt_info,
1739 : 0 : rxq->pkt_type_mask);
1740 : :
1741 [ # # ]: 0 : if (likely(pkt_flags & RTE_MBUF_F_RX_RSS_HASH)) {
1742 : 0 : rxm->hash.rss = rte_le_to_cpu_32(rxd.qw0.dw1);
1743 [ # # ]: 0 : } else if (pkt_flags & RTE_MBUF_F_RX_FDIR) {
1744 : 0 : rxm->hash.fdir.hash =
1745 : 0 : rte_le_to_cpu_16(rxd.qw0.hi.csum) &
1746 : : TXGBE_ATR_HASH_MASK;
1747 : 0 : rxm->hash.fdir.id = rte_le_to_cpu_16(rxd.qw0.hi.ipid);
1748 : : }
1749 : : /*
1750 : : * Store the mbuf address into the next entry of the array
1751 : : * of returned packets.
1752 : : */
1753 : 0 : rx_pkts[nb_rx++] = rxm;
1754 : : }
1755 : 0 : rxq->rx_tail = rx_id;
1756 : :
1757 : : /*
1758 : : * If the number of free RX descriptors is greater than the RX free
1759 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
1760 : : * register.
1761 : : * Update the RDT with the value of the last processed RX descriptor
1762 : : * minus 1, to guarantee that the RDT register is never equal to the
1763 : : * RDH register, which creates a "full" ring situation from the
1764 : : * hardware point of view...
1765 : : */
1766 : 0 : nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
1767 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
1768 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
1769 : : "nb_hold=%u nb_rx=%u",
1770 : : (uint16_t)rxq->port_id, (uint16_t)rxq->queue_id,
1771 : : (uint16_t)rx_id, (uint16_t)nb_hold,
1772 : : (uint16_t)nb_rx);
1773 [ # # ]: 0 : rx_id = (uint16_t)((rx_id == 0) ?
1774 : 0 : (rxq->nb_rx_desc - 1) : (rx_id - 1));
1775 : 0 : txgbe_set32(rxq->rdt_reg_addr, rx_id);
1776 : : nb_hold = 0;
1777 : : }
1778 : 0 : rxq->nb_rx_hold = nb_hold;
1779 : 0 : return nb_rx;
1780 : : }
1781 : :
1782 : : /**
1783 : : * txgbe_fill_cluster_head_buf - fill the first mbuf of the returned packet
1784 : : *
1785 : : * Fill the following info in the HEAD buffer of the Rx cluster:
1786 : : * - RX port identifier
1787 : : * - hardware offload data, if any:
1788 : : * - RSS flag & hash
1789 : : * - IP checksum flag
1790 : : * - VLAN TCI, if any
1791 : : * - error flags
1792 : : * @head HEAD of the packet cluster
1793 : : * @desc HW descriptor to get data from
1794 : : * @rxq Pointer to the Rx queue
1795 : : */
1796 : : static inline void
1797 : 0 : txgbe_fill_cluster_head_buf(struct rte_mbuf *head, struct txgbe_rx_desc *desc,
1798 : : struct txgbe_rx_queue *rxq, uint32_t staterr)
1799 : : {
1800 : : uint32_t pkt_info;
1801 : : uint64_t pkt_flags;
1802 : :
1803 : 0 : head->port = rxq->port_id;
1804 : :
1805 : : /* The vlan_tci field is only valid when RTE_MBUF_F_RX_VLAN is
1806 : : * set in the pkt_flags field.
1807 : : */
1808 : 0 : head->vlan_tci = rte_le_to_cpu_16(desc->qw1.hi.tag);
1809 : 0 : pkt_info = rte_le_to_cpu_32(desc->qw0.dw0);
1810 [ # # ]: 0 : pkt_flags = rx_desc_status_to_pkt_flags(staterr, rxq->vlan_flags);
1811 : 0 : pkt_flags |= rx_desc_error_to_pkt_flags(staterr, rxq);
1812 : 0 : pkt_flags |= txgbe_rxd_pkt_info_to_pkt_flags(pkt_info);
1813 [ # # ]: 0 : if (TXGBE_RXD_RSCCNT(desc->qw0.dw0))
1814 : 0 : pkt_flags |= RTE_MBUF_F_RX_LRO;
1815 : 0 : head->ol_flags = pkt_flags;
1816 : 0 : head->packet_type = txgbe_rxd_pkt_info_to_pkt_type(pkt_info,
1817 : 0 : rxq->pkt_type_mask);
1818 : :
1819 [ # # ]: 0 : if (likely(pkt_flags & RTE_MBUF_F_RX_RSS_HASH)) {
1820 : 0 : head->hash.rss = rte_le_to_cpu_32(desc->qw0.dw1);
1821 [ # # ]: 0 : } else if (pkt_flags & RTE_MBUF_F_RX_FDIR) {
1822 : 0 : head->hash.fdir.hash = rte_le_to_cpu_16(desc->qw0.hi.csum)
1823 : 0 : & TXGBE_ATR_HASH_MASK;
1824 : 0 : head->hash.fdir.id = rte_le_to_cpu_16(desc->qw0.hi.ipid);
1825 : : }
1826 : 0 : }
1827 : :
1828 : : /**
1829 : : * txgbe_recv_pkts_lro - receive handler for and LRO case.
1830 : : *
1831 : : * @rx_queue Rx queue handle
1832 : : * @rx_pkts table of received packets
1833 : : * @nb_pkts size of rx_pkts table
1834 : : * @bulk_alloc if TRUE bulk allocation is used for a HW ring refilling
1835 : : *
1836 : : * Handles the Rx HW ring completions when RSC feature is configured. Uses an
1837 : : * additional ring of txgbe_rsc_entry's that will hold the relevant RSC info.
1838 : : *
1839 : : * We use the same logic as in Linux and in FreeBSD txgbe drivers:
1840 : : * 1) When non-EOP RSC completion arrives:
1841 : : * a) Update the HEAD of the current RSC aggregation cluster with the new
1842 : : * segment's data length.
1843 : : * b) Set the "next" pointer of the current segment to point to the segment
1844 : : * at the NEXTP index.
1845 : : * c) Pass the HEAD of RSC aggregation cluster on to the next NEXTP entry
1846 : : * in the sw_rsc_ring.
1847 : : * 2) When EOP arrives we just update the cluster's total length and offload
1848 : : * flags and deliver the cluster up to the upper layers. In our case - put it
1849 : : * in the rx_pkts table.
1850 : : *
1851 : : * Returns the number of received packets/clusters (according to the "bulk
1852 : : * receive" interface).
1853 : : */
1854 : : static inline uint16_t
1855 : 0 : txgbe_recv_pkts_lro(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts,
1856 : : bool bulk_alloc)
1857 : : {
1858 : : struct txgbe_rx_queue *rxq = rx_queue;
1859 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
1860 : 0 : volatile struct txgbe_rx_desc *rx_ring = rxq->rx_ring;
1861 : 0 : struct txgbe_rx_entry *sw_ring = rxq->sw_ring;
1862 : 0 : struct txgbe_scattered_rx_entry *sw_sc_ring = rxq->sw_sc_ring;
1863 : 0 : uint16_t rx_id = rxq->rx_tail;
1864 : : uint16_t nb_rx = 0;
1865 : 0 : uint16_t nb_hold = rxq->nb_rx_hold;
1866 : : uint16_t prev_id = rxq->rx_tail;
1867 : :
1868 [ # # ]: 0 : while (nb_rx < nb_pkts) {
1869 : : bool eop;
1870 : : struct txgbe_rx_entry *rxe;
1871 : : struct txgbe_scattered_rx_entry *sc_entry;
1872 : : struct txgbe_scattered_rx_entry *next_sc_entry = NULL;
1873 : : struct txgbe_rx_entry *next_rxe = NULL;
1874 : : struct rte_mbuf *first_seg;
1875 : : struct rte_mbuf *rxm;
1876 : : struct rte_mbuf *nmb = NULL;
1877 : : struct txgbe_rx_desc rxd;
1878 : : uint16_t data_len;
1879 : : uint16_t next_id;
1880 : : volatile struct txgbe_rx_desc *rxdp;
1881 : : uint32_t staterr;
1882 : :
1883 : 0 : next_desc:
1884 : : /*
1885 : : * "Volatile" only prevents caching of the variable marked
1886 : : * volatile. Most important, "volatile" cannot prevent the CPU
1887 : : * from executing out of order. So, it is necessary to use a
1888 : : * proper memory barrier to ensure the memory ordering below.
1889 : : */
1890 : 0 : rxdp = &rx_ring[rx_id];
1891 : 0 : staterr = rte_le_to_cpu_32(rxdp->qw1.lo.status);
1892 : :
1893 [ # # ]: 0 : if (!(staterr & TXGBE_RXD_STAT_DD))
1894 : : break;
1895 : :
1896 : : /*
1897 : : * Use acquire fence to ensure that status_error which includes
1898 : : * DD bit is loaded before loading of other descriptor words.
1899 : : */
1900 : : rte_atomic_thread_fence(rte_memory_order_acquire);
1901 : :
1902 : 0 : rxd = *rxdp;
1903 : :
1904 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
1905 : : "staterr=0x%x data_len=%u",
1906 : : rxq->port_id, rxq->queue_id, rx_id, staterr,
1907 : : rte_le_to_cpu_16(rxd.qw1.hi.len));
1908 : :
1909 [ # # ]: 0 : if (!bulk_alloc) {
1910 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
1911 [ # # ]: 0 : if (nmb == NULL) {
1912 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed "
1913 : : "port_id=%u queue_id=%u",
1914 : : rxq->port_id, rxq->queue_id);
1915 : :
1916 : 0 : dev->data->rx_mbuf_alloc_failed++;
1917 : 0 : break;
1918 : : }
1919 [ # # ]: 0 : } else if (nb_hold > rxq->rx_free_thresh) {
1920 : 0 : uint16_t next_rdt = rxq->rx_free_trigger;
1921 : :
1922 [ # # ]: 0 : if (!txgbe_rx_alloc_bufs(rxq, false)) {
1923 : : rte_wmb();
1924 : 0 : txgbe_set32_relaxed(rxq->rdt_reg_addr,
1925 : : next_rdt);
1926 : 0 : nb_hold -= rxq->rx_free_thresh;
1927 : : } else {
1928 : : PMD_RX_LOG(DEBUG, "RX bulk alloc failed "
1929 : : "port_id=%u queue_id=%u",
1930 : : rxq->port_id, rxq->queue_id);
1931 : :
1932 : 0 : dev->data->rx_mbuf_alloc_failed++;
1933 : 0 : break;
1934 : : }
1935 : : }
1936 : :
1937 : 0 : nb_hold++;
1938 : 0 : rxe = &sw_ring[rx_id];
1939 : 0 : eop = staterr & TXGBE_RXD_STAT_EOP;
1940 : :
1941 : 0 : next_id = rx_id + 1;
1942 [ # # ]: 0 : if (next_id == rxq->nb_rx_desc)
1943 : : next_id = 0;
1944 : :
1945 : : /* Prefetch next mbuf while processing current one. */
1946 : 0 : rte_txgbe_prefetch(sw_ring[next_id].mbuf);
1947 : :
1948 : : /*
1949 : : * When next RX descriptor is on a cache-line boundary,
1950 : : * prefetch the next 4 RX descriptors and the next 4 pointers
1951 : : * to mbufs.
1952 : : */
1953 [ # # ]: 0 : if ((next_id & 0x3) == 0) {
1954 : 0 : rte_txgbe_prefetch(&rx_ring[next_id]);
1955 : : rte_txgbe_prefetch(&sw_ring[next_id]);
1956 : : }
1957 : :
1958 : 0 : rxm = rxe->mbuf;
1959 : :
1960 [ # # ]: 0 : if (!bulk_alloc) {
1961 : : __le64 dma =
1962 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1963 : : /*
1964 : : * Update RX descriptor with the physical address of the
1965 : : * new data buffer of the new allocated mbuf.
1966 : : */
1967 : 0 : rxe->mbuf = nmb;
1968 : :
1969 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
1970 : 0 : TXGBE_RXD_HDRADDR(rxdp, 0);
1971 : 0 : TXGBE_RXD_PKTADDR(rxdp, dma);
1972 : : } else {
1973 : 0 : rxe->mbuf = NULL;
1974 : : }
1975 : :
1976 : : /*
1977 : : * Set data length & data buffer address of mbuf.
1978 : : */
1979 : 0 : data_len = rte_le_to_cpu_16(rxd.qw1.hi.len);
1980 : 0 : rxm->data_len = data_len;
1981 : :
1982 [ # # ]: 0 : if (!eop) {
1983 : : uint16_t nextp_id;
1984 : : /*
1985 : : * Get next descriptor index:
1986 : : * - For RSC it's in the NEXTP field.
1987 : : * - For a scattered packet - it's just a following
1988 : : * descriptor.
1989 : : */
1990 [ # # ]: 0 : if (TXGBE_RXD_RSCCNT(rxd.qw0.dw0))
1991 : 0 : nextp_id = TXGBE_RXD_NEXTP(staterr);
1992 : : else
1993 : : nextp_id = next_id;
1994 : :
1995 : 0 : next_sc_entry = &sw_sc_ring[nextp_id];
1996 : 0 : next_rxe = &sw_ring[nextp_id];
1997 : : rte_txgbe_prefetch(next_rxe);
1998 : : }
1999 : :
2000 : 0 : sc_entry = &sw_sc_ring[rx_id];
2001 : 0 : first_seg = sc_entry->fbuf;
2002 : 0 : sc_entry->fbuf = NULL;
2003 : :
2004 : : /*
2005 : : * If this is the first buffer of the received packet,
2006 : : * set the pointer to the first mbuf of the packet and
2007 : : * initialize its context.
2008 : : * Otherwise, update the total length and the number of segments
2009 : : * of the current scattered packet, and update the pointer to
2010 : : * the last mbuf of the current packet.
2011 : : */
2012 [ # # ]: 0 : if (first_seg == NULL) {
2013 : : first_seg = rxm;
2014 : 0 : first_seg->pkt_len = data_len;
2015 : 0 : first_seg->nb_segs = 1;
2016 : : } else {
2017 : 0 : first_seg->pkt_len += data_len;
2018 : 0 : first_seg->nb_segs++;
2019 : : }
2020 : :
2021 : : prev_id = rx_id;
2022 : : rx_id = next_id;
2023 : :
2024 : : /*
2025 : : * If this is not the last buffer of the received packet, update
2026 : : * the pointer to the first mbuf at the NEXTP entry in the
2027 : : * sw_sc_ring and continue to parse the RX ring.
2028 : : */
2029 [ # # ]: 0 : if (!eop && next_rxe) {
2030 : 0 : rxm->next = next_rxe->mbuf;
2031 : 0 : next_sc_entry->fbuf = first_seg;
2032 : 0 : goto next_desc;
2033 : : }
2034 : :
2035 : : /* Initialize the first mbuf of the returned packet */
2036 : 0 : txgbe_fill_cluster_head_buf(first_seg, &rxd, rxq, staterr);
2037 : :
2038 : : /*
2039 : : * Deal with the case, when HW CRC srip is disabled.
2040 : : * That can't happen when LRO is enabled, but still could
2041 : : * happen for scattered RX mode.
2042 : : */
2043 : 0 : first_seg->pkt_len -= rxq->crc_len;
2044 [ # # ]: 0 : if (unlikely(rxm->data_len <= rxq->crc_len)) {
2045 : : struct rte_mbuf *lp;
2046 : :
2047 [ # # ]: 0 : for (lp = first_seg; lp->next != rxm; lp = lp->next)
2048 : : ;
2049 : :
2050 : 0 : first_seg->nb_segs--;
2051 : 0 : lp->data_len -= rxq->crc_len - rxm->data_len;
2052 [ # # ]: 0 : lp->next = NULL;
2053 : : rte_pktmbuf_free_seg(rxm);
2054 : : } else {
2055 : 0 : rxm->data_len -= rxq->crc_len;
2056 : : }
2057 : :
2058 : : /* Prefetch data of first segment, if configured to do so. */
2059 : 0 : rte_packet_prefetch((char *)first_seg->buf_addr +
2060 : : first_seg->data_off);
2061 : :
2062 : : /*
2063 : : * Store the mbuf address into the next entry of the array
2064 : : * of returned packets.
2065 : : */
2066 : 0 : rx_pkts[nb_rx++] = first_seg;
2067 : : }
2068 : :
2069 : : /*
2070 : : * Record index of the next RX descriptor to probe.
2071 : : */
2072 : 0 : rxq->rx_tail = rx_id;
2073 : :
2074 : : /*
2075 : : * If the number of free RX descriptors is greater than the RX free
2076 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
2077 : : * register.
2078 : : * Update the RDT with the value of the last processed RX descriptor
2079 : : * minus 1, to guarantee that the RDT register is never equal to the
2080 : : * RDH register, which creates a "full" ring situation from the
2081 : : * hardware point of view...
2082 : : */
2083 [ # # # # ]: 0 : if (!bulk_alloc && nb_hold > rxq->rx_free_thresh) {
2084 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
2085 : : "nb_hold=%u nb_rx=%u",
2086 : : rxq->port_id, rxq->queue_id, rx_id, nb_hold, nb_rx);
2087 : :
2088 : : rte_wmb();
2089 : 0 : txgbe_set32_relaxed(rxq->rdt_reg_addr, prev_id);
2090 : : nb_hold = 0;
2091 : : }
2092 : :
2093 : 0 : rxq->nb_rx_hold = nb_hold;
2094 : 0 : return nb_rx;
2095 : : }
2096 : :
2097 : : uint16_t
2098 : 0 : txgbe_recv_pkts_lro_single_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
2099 : : uint16_t nb_pkts)
2100 : : {
2101 : 0 : return txgbe_recv_pkts_lro(rx_queue, rx_pkts, nb_pkts, false);
2102 : : }
2103 : :
2104 : : uint16_t
2105 : 0 : txgbe_recv_pkts_lro_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
2106 : : uint16_t nb_pkts)
2107 : : {
2108 : 0 : return txgbe_recv_pkts_lro(rx_queue, rx_pkts, nb_pkts, true);
2109 : : }
2110 : :
2111 : : uint64_t
2112 : 0 : txgbe_get_rx_queue_offloads(struct rte_eth_dev *dev __rte_unused)
2113 : : {
2114 : 0 : return RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
2115 : : }
2116 : :
2117 : : uint64_t
2118 : 0 : txgbe_get_rx_port_offloads(struct rte_eth_dev *dev)
2119 : : {
2120 : : uint64_t offloads;
2121 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2122 : : struct rte_eth_dev_sriov *sriov = &RTE_ETH_DEV_SRIOV(dev);
2123 : :
2124 : : offloads = RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
2125 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
2126 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
2127 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
2128 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
2129 : : RTE_ETH_RX_OFFLOAD_RSS_HASH |
2130 : : RTE_ETH_RX_OFFLOAD_SCATTER;
2131 : :
2132 [ # # ]: 0 : if (!txgbe_is_vf(hw))
2133 : : offloads |= (RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
2134 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
2135 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND);
2136 : :
2137 : : /*
2138 : : * RSC is only supported by PF devices in a non-SR-IOV
2139 : : * mode.
2140 : : */
2141 [ # # # # ]: 0 : if (txgbe_is_pf(hw) && !sriov->active)
2142 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_TCP_LRO;
2143 : :
2144 [ # # ]: 0 : if (txgbe_is_pf(hw))
2145 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_MACSEC_STRIP;
2146 : :
2147 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM;
2148 : :
2149 : : #ifdef RTE_LIB_SECURITY
2150 [ # # ]: 0 : if (dev->security_ctx)
2151 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_SECURITY;
2152 : : #endif
2153 : :
2154 : 0 : return offloads;
2155 : : }
2156 : :
2157 : : static void __rte_cold
2158 : 0 : txgbe_tx_queue_release_mbufs(struct txgbe_tx_queue *txq)
2159 : : {
2160 : : unsigned int i;
2161 : :
2162 [ # # ]: 0 : if (txq->sw_ring != NULL) {
2163 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
2164 [ # # ]: 0 : if (txq->sw_ring[i].mbuf != NULL) {
2165 : : rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
2166 : 0 : txq->sw_ring[i].mbuf = NULL;
2167 : : }
2168 : : }
2169 : : }
2170 : 0 : }
2171 : :
2172 : : static int
2173 : 0 : txgbe_tx_done_cleanup_full(struct txgbe_tx_queue *txq, uint32_t free_cnt)
2174 : : {
2175 : 0 : struct txgbe_tx_entry *swr_ring = txq->sw_ring;
2176 : : uint16_t i, tx_last, tx_id;
2177 : : uint16_t nb_tx_free_last;
2178 : : uint16_t nb_tx_to_clean;
2179 : : uint32_t pkt_cnt;
2180 : :
2181 : : /* Start free mbuf from the next of tx_tail */
2182 : 0 : tx_last = txq->tx_tail;
2183 : 0 : tx_id = swr_ring[tx_last].next_id;
2184 : :
2185 [ # # # # ]: 0 : if (txq->nb_tx_free == 0 && txgbe_xmit_cleanup(txq))
2186 : : return 0;
2187 : :
2188 : 0 : nb_tx_to_clean = txq->nb_tx_free;
2189 : : nb_tx_free_last = txq->nb_tx_free;
2190 [ # # ]: 0 : if (!free_cnt)
2191 : 0 : free_cnt = txq->nb_tx_desc;
2192 : :
2193 : : /* Loop through swr_ring to count the amount of
2194 : : * freeable mubfs and packets.
2195 : : */
2196 [ # # ]: 0 : for (pkt_cnt = 0; pkt_cnt < free_cnt; ) {
2197 : 0 : for (i = 0; i < nb_tx_to_clean &&
2198 [ # # # # ]: 0 : pkt_cnt < free_cnt &&
2199 : 0 : tx_id != tx_last; i++) {
2200 [ # # ]: 0 : if (swr_ring[tx_id].mbuf != NULL) {
2201 : : rte_pktmbuf_free_seg(swr_ring[tx_id].mbuf);
2202 : 0 : swr_ring[tx_id].mbuf = NULL;
2203 : :
2204 : : /*
2205 : : * last segment in the packet,
2206 : : * increment packet count
2207 : : */
2208 : 0 : pkt_cnt += (swr_ring[tx_id].last_id == tx_id);
2209 : : }
2210 : :
2211 : 0 : tx_id = swr_ring[tx_id].next_id;
2212 : : }
2213 : :
2214 [ # # ]: 0 : if (pkt_cnt < free_cnt) {
2215 [ # # ]: 0 : if (txgbe_xmit_cleanup(txq))
2216 : : break;
2217 : :
2218 : 0 : nb_tx_to_clean = txq->nb_tx_free - nb_tx_free_last;
2219 : : nb_tx_free_last = txq->nb_tx_free;
2220 : : }
2221 : : }
2222 : :
2223 : 0 : return (int)pkt_cnt;
2224 : : }
2225 : :
2226 : : static int
2227 : 0 : txgbe_tx_done_cleanup_simple(struct txgbe_tx_queue *txq,
2228 : : uint32_t free_cnt)
2229 : : {
2230 : : int i, n, cnt;
2231 : :
2232 [ # # # # ]: 0 : if (free_cnt == 0 || free_cnt > txq->nb_tx_desc)
2233 : 0 : free_cnt = txq->nb_tx_desc;
2234 : :
2235 : 0 : cnt = free_cnt - free_cnt % txq->tx_free_thresh;
2236 : :
2237 [ # # ]: 0 : for (i = 0; i < cnt; i += n) {
2238 [ # # ]: 0 : if (txq->nb_tx_desc - txq->nb_tx_free < txq->tx_free_thresh)
2239 : : break;
2240 : :
2241 : : n = txgbe_tx_free_bufs(txq);
2242 : :
2243 [ # # ]: 0 : if (n == 0)
2244 : : break;
2245 : : }
2246 : :
2247 : 0 : return i;
2248 : : }
2249 : :
2250 : : int
2251 : 0 : txgbe_dev_tx_done_cleanup(void *tx_queue, uint32_t free_cnt)
2252 : : {
2253 : : struct txgbe_tx_queue *txq = (struct txgbe_tx_queue *)tx_queue;
2254 [ # # ]: 0 : if (txq->offloads == 0 &&
2255 : : #ifdef RTE_LIB_SECURITY
2256 [ # # ]: 0 : !(txq->using_ipsec) &&
2257 : : #endif
2258 [ # # ]: 0 : txq->tx_free_thresh >= RTE_PMD_TXGBE_TX_MAX_BURST)
2259 : 0 : return txgbe_tx_done_cleanup_simple(txq, free_cnt);
2260 : :
2261 : 0 : return txgbe_tx_done_cleanup_full(txq, free_cnt);
2262 : : }
2263 : :
2264 : : static void __rte_cold
2265 : 0 : txgbe_tx_free_swring(struct txgbe_tx_queue *txq)
2266 : : {
2267 [ # # ]: 0 : if (txq != NULL &&
2268 [ # # ]: 0 : txq->sw_ring != NULL)
2269 : 0 : rte_free(txq->sw_ring);
2270 : 0 : }
2271 : :
2272 : : static void __rte_cold
2273 : 0 : txgbe_tx_queue_release(struct txgbe_tx_queue *txq)
2274 : : {
2275 [ # # # # ]: 0 : if (txq != NULL && txq->ops != NULL) {
2276 : 0 : txq->ops->release_mbufs(txq);
2277 : 0 : txq->ops->free_swring(txq);
2278 : 0 : rte_memzone_free(txq->mz);
2279 [ # # ]: 0 : if (txq->headwb_mem)
2280 : 0 : rte_memzone_free(txq->headwb);
2281 : 0 : rte_free(txq);
2282 : : }
2283 : 0 : }
2284 : :
2285 : : void __rte_cold
2286 : 0 : txgbe_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2287 : : {
2288 : 0 : txgbe_tx_queue_release(dev->data->tx_queues[qid]);
2289 : 0 : }
2290 : :
2291 : : /* (Re)set dynamic txgbe_tx_queue fields to defaults */
2292 : : static void __rte_cold
2293 : 0 : txgbe_reset_tx_queue(struct txgbe_tx_queue *txq)
2294 : : {
2295 : : static const struct txgbe_tx_desc zeroed_desc = {0};
2296 : 0 : struct txgbe_tx_entry *txe = txq->sw_ring;
2297 : : uint16_t prev, i;
2298 : :
2299 : : /* Zero out HW ring memory */
2300 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++)
2301 : 0 : txq->tx_ring[i] = zeroed_desc;
2302 : :
2303 : : /* Initialize SW ring entries */
2304 : 0 : prev = (uint16_t)(txq->nb_tx_desc - 1);
2305 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
2306 : 0 : volatile struct txgbe_tx_desc *txd = &txq->tx_ring[i];
2307 : :
2308 : 0 : txd->dw3 = rte_cpu_to_le_32(TXGBE_TXD_DD);
2309 : 0 : txe[i].mbuf = NULL;
2310 : 0 : txe[i].last_id = i;
2311 : 0 : txe[prev].next_id = i;
2312 : : prev = i;
2313 : : }
2314 : :
2315 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_free_thresh - 1);
2316 : 0 : txq->tx_tail = 0;
2317 : :
2318 : : /* Zero out headwb_mem memory */
2319 [ # # ]: 0 : if (txq->headwb_mem) {
2320 [ # # ]: 0 : for (i = 0; i < txq->headwb_size; i++)
2321 : 0 : txq->headwb_mem[i] = 0;
2322 : : }
2323 : :
2324 : : /*
2325 : : * Always allow 1 descriptor to be un-allocated to avoid
2326 : : * a H/W race condition
2327 : : */
2328 : 0 : txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
2329 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
2330 : 0 : txq->ctx_curr = 0;
2331 : 0 : memset((void *)&txq->ctx_cache, 0,
2332 : : TXGBE_CTX_NUM * sizeof(struct txgbe_ctx_info));
2333 : 0 : }
2334 : :
2335 : : static const struct txgbe_txq_ops def_txq_ops = {
2336 : : .release_mbufs = txgbe_tx_queue_release_mbufs,
2337 : : .free_swring = txgbe_tx_free_swring,
2338 : : .reset = txgbe_reset_tx_queue,
2339 : : };
2340 : :
2341 : : /* Takes an ethdev and a queue and sets up the tx function to be used based on
2342 : : * the queue parameters. Used in tx_queue_setup by primary process and then
2343 : : * in dev_init by secondary process when attaching to an existing ethdev.
2344 : : */
2345 : : void __rte_cold
2346 : 0 : txgbe_set_tx_function(struct rte_eth_dev *dev, struct txgbe_tx_queue *txq)
2347 : : {
2348 : : /* Use a simple Tx queue (no offloads, no multi segs) if possible */
2349 [ # # ]: 0 : if (txq->offloads == 0 &&
2350 : : #ifdef RTE_LIB_SECURITY
2351 [ # # ]: 0 : !(txq->using_ipsec) &&
2352 : : #endif
2353 [ # # ]: 0 : txq->tx_free_thresh >= RTE_PMD_TXGBE_TX_MAX_BURST) {
2354 : 0 : PMD_INIT_LOG(DEBUG, "Using simple tx code path");
2355 : 0 : dev->tx_pkt_prepare = rte_eth_tx_pkt_prepare_dummy;
2356 [ # # # # ]: 0 : if (txq->tx_free_thresh <= RTE_TXGBE_TX_MAX_FREE_BUF_SZ &&
2357 [ # # ]: 0 : rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128 &&
2358 [ # # ]: 0 : (rte_eal_process_type() != RTE_PROC_PRIMARY ||
2359 : 0 : txgbe_txq_vec_setup(txq) == 0)) {
2360 : 0 : PMD_INIT_LOG(DEBUG, "Vector tx enabled.");
2361 : 0 : dev->tx_pkt_burst = txgbe_xmit_pkts_vec;
2362 : : } else {
2363 : 0 : dev->tx_pkt_burst = txgbe_xmit_pkts_simple;
2364 : : }
2365 : : } else {
2366 : 0 : PMD_INIT_LOG(DEBUG, "Using full-featured tx code path");
2367 : 0 : PMD_INIT_LOG(DEBUG,
2368 : : " - offloads = 0x%" PRIx64,
2369 : : txq->offloads);
2370 : 0 : PMD_INIT_LOG(DEBUG,
2371 : : " - tx_free_thresh = %lu [RTE_PMD_TXGBE_TX_MAX_BURST=%lu]",
2372 : : (unsigned long)txq->tx_free_thresh,
2373 : : (unsigned long)RTE_PMD_TXGBE_TX_MAX_BURST);
2374 : 0 : dev->tx_pkt_burst = txgbe_xmit_pkts;
2375 : 0 : dev->tx_pkt_prepare = txgbe_prep_pkts;
2376 : : }
2377 : 0 : }
2378 : :
2379 : : uint64_t
2380 : 0 : txgbe_get_tx_queue_offloads(struct rte_eth_dev *dev)
2381 : : {
2382 : : RTE_SET_USED(dev);
2383 : :
2384 : 0 : return 0;
2385 : : }
2386 : :
2387 : : uint64_t
2388 : 0 : txgbe_get_tx_port_offloads(struct rte_eth_dev *dev)
2389 : : {
2390 : : uint64_t tx_offload_capa;
2391 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2392 : :
2393 : : tx_offload_capa =
2394 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
2395 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
2396 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
2397 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
2398 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
2399 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
2400 : : RTE_ETH_TX_OFFLOAD_UDP_TSO |
2401 : : RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO |
2402 : : RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
2403 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
2404 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
2405 : : RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
2406 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
2407 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
2408 : :
2409 [ # # ]: 0 : if (!txgbe_is_vf(hw))
2410 : : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_QINQ_INSERT;
2411 : :
2412 : : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
2413 : :
2414 : 0 : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
2415 : :
2416 : : #ifdef RTE_LIB_SECURITY
2417 [ # # ]: 0 : if (dev->security_ctx)
2418 : 0 : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_SECURITY;
2419 : : #endif
2420 : 0 : return tx_offload_capa;
2421 : : }
2422 : :
2423 : : static void
2424 : 0 : txgbe_setup_headwb_resources(struct rte_eth_dev *dev,
2425 : : void *tx_queue,
2426 : : unsigned int socket_id)
2427 : : {
2428 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2429 : : const struct rte_memzone *headwb;
2430 : : struct txgbe_tx_queue *txq = tx_queue;
2431 : : u8 headwb_size = 0;
2432 : :
2433 [ # # ]: 0 : if (hw->mac.type != txgbe_mac_aml && hw->mac.type != txgbe_mac_aml40)
2434 : 0 : goto out;
2435 : :
2436 [ # # ]: 0 : if (!hw->devarg.tx_headwb)
2437 : 0 : goto out;
2438 : :
2439 : 0 : headwb_size = txq->headwb_size;
2440 : 0 : headwb = rte_eth_dma_zone_reserve(dev, "tx_headwb_mem", txq->queue_id,
2441 : : sizeof(u32) * headwb_size,
2442 : : TXGBE_ALIGN, socket_id);
2443 : :
2444 [ # # ]: 0 : if (headwb == NULL) {
2445 : 0 : PMD_DRV_LOG(INFO,
2446 : : "Failed to allocate headwb memory for Tx queue %u, change to SP mode",
2447 : : txq->queue_id);
2448 : 0 : goto out;
2449 : : }
2450 : :
2451 : 0 : txq->headwb = headwb;
2452 : 0 : txq->headwb_dma = TMZ_PADDR(headwb);
2453 : 0 : txq->headwb_mem = (RTE_ATOMIC(uint32_t) *)TMZ_VADDR(headwb);
2454 : 0 : return;
2455 : :
2456 : 0 : out:
2457 : 0 : txq->headwb_mem = NULL;
2458 : : }
2459 : :
2460 : : int __rte_cold
2461 : 0 : txgbe_dev_tx_queue_setup(struct rte_eth_dev *dev,
2462 : : uint16_t queue_idx,
2463 : : uint16_t nb_desc,
2464 : : unsigned int socket_id,
2465 : : const struct rte_eth_txconf *tx_conf)
2466 : : {
2467 : : const struct rte_memzone *tz;
2468 : : struct txgbe_tx_queue *txq;
2469 : : struct txgbe_hw *hw;
2470 : : uint16_t tx_free_thresh;
2471 : : uint64_t offloads;
2472 : : s32 err = 0;
2473 : :
2474 : 0 : PMD_INIT_FUNC_TRACE();
2475 : 0 : hw = TXGBE_DEV_HW(dev);
2476 : :
2477 : 0 : offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
2478 : :
2479 : : /*
2480 : : * Validate number of transmit descriptors.
2481 : : * It must not exceed hardware maximum, and must be multiple
2482 : : * of TXGBE_ALIGN.
2483 : : */
2484 [ # # ]: 0 : if (nb_desc % TXGBE_TXD_ALIGN != 0 ||
2485 [ # # ]: 0 : nb_desc > TXGBE_RING_DESC_MAX ||
2486 : : nb_desc < TXGBE_RING_DESC_MIN) {
2487 : : return -EINVAL;
2488 : : }
2489 : :
2490 : : /*
2491 : : * The TX descriptor ring will be cleaned after txq->tx_free_thresh
2492 : : * descriptors are used or if the number of descriptors required
2493 : : * to transmit a packet is greater than the number of free TX
2494 : : * descriptors.
2495 : : * One descriptor in the TX ring is used as a sentinel to avoid a
2496 : : * H/W race condition, hence the maximum threshold constraints.
2497 : : * When set to zero use default values.
2498 : : */
2499 [ # # ]: 0 : tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
2500 : : tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH);
2501 [ # # ]: 0 : if (tx_free_thresh >= (nb_desc - 3)) {
2502 : 0 : PMD_INIT_LOG(ERR, "tx_free_thresh must be less than the number of "
2503 : : "TX descriptors minus 3. (tx_free_thresh=%u "
2504 : : "port=%d queue=%d)",
2505 : : (unsigned int)tx_free_thresh,
2506 : : (int)dev->data->port_id, (int)queue_idx);
2507 : 0 : return -(EINVAL);
2508 : : }
2509 : :
2510 [ # # ]: 0 : if ((nb_desc % tx_free_thresh) != 0) {
2511 : 0 : PMD_INIT_LOG(ERR, "tx_free_thresh must be a divisor of the "
2512 : : "number of TX descriptors. (tx_free_thresh=%u "
2513 : : "port=%d queue=%d)", (unsigned int)tx_free_thresh,
2514 : : (int)dev->data->port_id, (int)queue_idx);
2515 : 0 : return -(EINVAL);
2516 : : }
2517 : :
2518 : : /* Free memory prior to re-allocation if needed... */
2519 [ # # ]: 0 : if (dev->data->tx_queues[queue_idx] != NULL) {
2520 : 0 : txgbe_tx_queue_release(dev->data->tx_queues[queue_idx]);
2521 : 0 : dev->data->tx_queues[queue_idx] = NULL;
2522 : : }
2523 : :
2524 : : /* First allocate the tx queue data structure */
2525 : 0 : txq = rte_zmalloc_socket("ethdev TX queue",
2526 : : sizeof(struct txgbe_tx_queue),
2527 : : RTE_CACHE_LINE_SIZE, socket_id);
2528 [ # # ]: 0 : if (txq == NULL)
2529 : : return -ENOMEM;
2530 : :
2531 : : /* Allocate TX ring hardware descriptors. */
2532 : 0 : tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx,
2533 : : sizeof(struct txgbe_tx_desc) * nb_desc,
2534 : : TXGBE_ALIGN, socket_id);
2535 [ # # ]: 0 : if (tz == NULL) {
2536 : 0 : txgbe_tx_queue_release(txq);
2537 : 0 : return -ENOMEM;
2538 : : }
2539 : :
2540 : 0 : txq->mz = tz;
2541 : 0 : txq->nb_tx_desc = nb_desc;
2542 : 0 : txq->tx_free_thresh = tx_free_thresh;
2543 : 0 : txq->pthresh = tx_conf->tx_thresh.pthresh;
2544 : 0 : txq->hthresh = tx_conf->tx_thresh.hthresh;
2545 : 0 : txq->wthresh = tx_conf->tx_thresh.wthresh;
2546 : 0 : txq->queue_id = queue_idx;
2547 [ # # ]: 0 : txq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
2548 : 0 : queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
2549 : 0 : txq->port_id = dev->data->port_id;
2550 : 0 : txq->offloads = offloads;
2551 : 0 : txq->ops = &def_txq_ops;
2552 : 0 : txq->tx_deferred_start = tx_conf->tx_deferred_start;
2553 : 0 : txq->headwb_size = hw->devarg.tx_headwb_size;
2554 : : #ifdef RTE_LIB_SECURITY
2555 : 0 : txq->using_ipsec = !!(dev->data->dev_conf.txmode.offloads &
2556 : : RTE_ETH_TX_OFFLOAD_SECURITY);
2557 : : #endif
2558 : :
2559 : : /* Modification to set tail pointer for virtual function
2560 : : * if vf is detected.
2561 : : */
2562 [ # # ]: 0 : if (txgbe_is_vf(hw)) {
2563 : 0 : txq->tdt_reg_addr = TXGBE_REG_ADDR(hw, TXGBE_TXWP(queue_idx));
2564 : 0 : txq->tdc_reg_addr = TXGBE_REG_ADDR(hw, TXGBE_TXCFG(queue_idx));
2565 : : } else {
2566 : 0 : txq->tdt_reg_addr = TXGBE_REG_ADDR(hw,
2567 : : TXGBE_TXWP(txq->reg_idx));
2568 : 0 : txq->tdc_reg_addr = TXGBE_REG_ADDR(hw,
2569 : : TXGBE_TXCFG(txq->reg_idx));
2570 : : }
2571 : :
2572 : 0 : txq->tx_ring_phys_addr = TMZ_PADDR(tz);
2573 : 0 : txq->tx_ring = (struct txgbe_tx_desc *)TMZ_VADDR(tz);
2574 : :
2575 : : /* Allocate software ring */
2576 : 0 : txq->sw_ring = rte_zmalloc_socket("txq->sw_ring",
2577 : : sizeof(struct txgbe_tx_entry) * nb_desc,
2578 : : RTE_CACHE_LINE_SIZE, socket_id);
2579 [ # # ]: 0 : if (txq->sw_ring == NULL) {
2580 : 0 : txgbe_tx_queue_release(txq);
2581 : 0 : return -ENOMEM;
2582 : : }
2583 : 0 : PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%" PRIx64,
2584 : : txq->sw_ring, txq->tx_ring, txq->tx_ring_phys_addr);
2585 : :
2586 : : /* set up scalar TX function as appropriate */
2587 : 0 : txgbe_set_tx_function(dev, txq);
2588 : :
2589 : 0 : txgbe_setup_headwb_resources(dev, txq, socket_id);
2590 : :
2591 : 0 : txq->ops->reset(txq);
2592 : 0 : txq->desc_error = 0;
2593 : :
2594 : 0 : dev->data->tx_queues[queue_idx] = txq;
2595 : :
2596 : 0 : return err;
2597 : : }
2598 : :
2599 : : /**
2600 : : * txgbe_free_sc_cluster - free the not-yet-completed scattered cluster
2601 : : *
2602 : : * The "next" pointer of the last segment of (not-yet-completed) RSC clusters
2603 : : * in the sw_rsc_ring is not set to NULL but rather points to the next
2604 : : * mbuf of this RSC aggregation (that has not been completed yet and still
2605 : : * resides on the HW ring). So, instead of calling for rte_pktmbuf_free() we
2606 : : * will just free first "nb_segs" segments of the cluster explicitly by calling
2607 : : * an rte_pktmbuf_free_seg().
2608 : : *
2609 : : * @m scattered cluster head
2610 : : */
2611 : : static void __rte_cold
2612 : 0 : txgbe_free_sc_cluster(struct rte_mbuf *m)
2613 : : {
2614 : 0 : uint16_t i, nb_segs = m->nb_segs;
2615 : : struct rte_mbuf *next_seg;
2616 : :
2617 [ # # ]: 0 : for (i = 0; i < nb_segs; i++) {
2618 : 0 : next_seg = m->next;
2619 : : rte_pktmbuf_free_seg(m);
2620 : : m = next_seg;
2621 : : }
2622 : 0 : }
2623 : :
2624 : : static void __rte_cold
2625 : 0 : txgbe_rx_queue_release_mbufs(struct txgbe_rx_queue *rxq)
2626 : : {
2627 : : unsigned int i;
2628 : :
2629 : : /* SSE Vector driver has a different way of releasing mbufs. */
2630 [ # # ]: 0 : if (rxq->rx_using_sse) {
2631 : 0 : txgbe_rx_queue_release_mbufs_vec(rxq);
2632 : 0 : return;
2633 : : }
2634 : :
2635 [ # # ]: 0 : if (rxq->sw_ring != NULL) {
2636 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
2637 [ # # ]: 0 : if (rxq->sw_ring[i].mbuf != NULL) {
2638 : : rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
2639 : 0 : rxq->sw_ring[i].mbuf = NULL;
2640 : : }
2641 : : }
2642 [ # # ]: 0 : if (rxq->rx_nb_avail) {
2643 [ # # ]: 0 : for (i = 0; i < rxq->rx_nb_avail; ++i) {
2644 : : struct rte_mbuf *mb;
2645 : :
2646 [ # # ]: 0 : mb = rxq->rx_stage[rxq->rx_next_avail + i];
2647 : : rte_pktmbuf_free_seg(mb);
2648 : : }
2649 : 0 : rxq->rx_nb_avail = 0;
2650 : : }
2651 : : }
2652 : :
2653 [ # # ]: 0 : if (rxq->sw_sc_ring)
2654 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++)
2655 [ # # ]: 0 : if (rxq->sw_sc_ring[i].fbuf) {
2656 : 0 : txgbe_free_sc_cluster(rxq->sw_sc_ring[i].fbuf);
2657 : 0 : rxq->sw_sc_ring[i].fbuf = NULL;
2658 : : }
2659 : : }
2660 : :
2661 : : static void __rte_cold
2662 : 0 : txgbe_rx_queue_release(struct txgbe_rx_queue *rxq)
2663 : : {
2664 [ # # ]: 0 : if (rxq != NULL) {
2665 : 0 : txgbe_rx_queue_release_mbufs(rxq);
2666 : 0 : rte_free(rxq->sw_ring);
2667 : 0 : rte_free(rxq->sw_sc_ring);
2668 : 0 : rte_memzone_free(rxq->mz);
2669 : 0 : rte_free(rxq);
2670 : : }
2671 : 0 : }
2672 : :
2673 : : void __rte_cold
2674 : 0 : txgbe_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2675 : : {
2676 : 0 : txgbe_rx_queue_release(dev->data->rx_queues[qid]);
2677 : 0 : }
2678 : :
2679 : : /*
2680 : : * Check if Rx Burst Bulk Alloc function can be used.
2681 : : * Return
2682 : : * 0: the preconditions are satisfied and the bulk allocation function
2683 : : * can be used.
2684 : : * -EINVAL: the preconditions are NOT satisfied and the default Rx burst
2685 : : * function must be used.
2686 : : */
2687 : : static inline int __rte_cold
2688 : 0 : check_rx_burst_bulk_alloc_preconditions(struct txgbe_rx_queue *rxq)
2689 : : {
2690 : : int ret = 0;
2691 : :
2692 : : /*
2693 : : * Make sure the following pre-conditions are satisfied:
2694 : : * rxq->rx_free_thresh >= RTE_PMD_TXGBE_RX_MAX_BURST
2695 : : * rxq->rx_free_thresh < rxq->nb_rx_desc
2696 : : * (rxq->nb_rx_desc % rxq->rx_free_thresh) == 0
2697 : : * Scattered packets are not supported. This should be checked
2698 : : * outside of this function.
2699 : : */
2700 [ # # ]: 0 : if (!(rxq->rx_free_thresh >= RTE_PMD_TXGBE_RX_MAX_BURST)) {
2701 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
2702 : : "rxq->rx_free_thresh=%d, "
2703 : : "RTE_PMD_TXGBE_RX_MAX_BURST=%d",
2704 : : rxq->rx_free_thresh, RTE_PMD_TXGBE_RX_MAX_BURST);
2705 : : ret = -EINVAL;
2706 [ # # ]: 0 : } else if (!(rxq->rx_free_thresh < rxq->nb_rx_desc)) {
2707 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
2708 : : "rxq->rx_free_thresh=%d, "
2709 : : "rxq->nb_rx_desc=%d",
2710 : : rxq->rx_free_thresh, rxq->nb_rx_desc);
2711 : : ret = -EINVAL;
2712 [ # # ]: 0 : } else if (!((rxq->nb_rx_desc % rxq->rx_free_thresh) == 0)) {
2713 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
2714 : : "rxq->nb_rx_desc=%d, "
2715 : : "rxq->rx_free_thresh=%d",
2716 : : rxq->nb_rx_desc, rxq->rx_free_thresh);
2717 : : ret = -EINVAL;
2718 : : }
2719 : :
2720 : 0 : return ret;
2721 : : }
2722 : :
2723 : : /* Reset dynamic txgbe_rx_queue fields back to defaults */
2724 : : static void __rte_cold
2725 : 0 : txgbe_reset_rx_queue(struct txgbe_adapter *adapter, struct txgbe_rx_queue *rxq)
2726 : : {
2727 : : static const struct txgbe_rx_desc zeroed_desc = {
2728 : : {{0}, {0} }, {{0}, {0} } };
2729 : : unsigned int i;
2730 : 0 : uint16_t len = rxq->nb_rx_desc;
2731 : :
2732 : : /*
2733 : : * By default, the Rx queue setup function allocates enough memory for
2734 : : * TXGBE_RING_DESC_MAX. The Rx Burst bulk allocation function requires
2735 : : * extra memory at the end of the descriptor ring to be zero'd out.
2736 : : */
2737 [ # # ]: 0 : if (adapter->rx_bulk_alloc_allowed)
2738 : : /* zero out extra memory */
2739 : 0 : len += RTE_PMD_TXGBE_RX_MAX_BURST;
2740 : :
2741 : : /*
2742 : : * Zero out HW ring memory. Zero out extra memory at the end of
2743 : : * the H/W ring so look-ahead logic in Rx Burst bulk alloc function
2744 : : * reads extra memory as zeros.
2745 : : */
2746 [ # # ]: 0 : for (i = 0; i < len; i++)
2747 : 0 : rxq->rx_ring[i] = zeroed_desc;
2748 : :
2749 : : /*
2750 : : * initialize extra software ring entries. Space for these extra
2751 : : * entries is always allocated
2752 : : */
2753 : 0 : memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
2754 [ # # ]: 0 : for (i = rxq->nb_rx_desc; i < len; ++i)
2755 : 0 : rxq->sw_ring[i].mbuf = &rxq->fake_mbuf;
2756 : :
2757 : 0 : rxq->rx_nb_avail = 0;
2758 : 0 : rxq->rx_next_avail = 0;
2759 : 0 : rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
2760 : 0 : rxq->rx_tail = 0;
2761 : 0 : rxq->nb_rx_hold = 0;
2762 : 0 : rxq->csum_err = 0;
2763 : 0 : rte_pktmbuf_free(rxq->pkt_first_seg);
2764 : 0 : rxq->pkt_first_seg = NULL;
2765 : 0 : rxq->pkt_last_seg = NULL;
2766 : :
2767 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM)
2768 : 0 : rxq->rxrearm_start = 0;
2769 : 0 : rxq->rxrearm_nb = 0;
2770 : : #endif
2771 : 0 : }
2772 : :
2773 : : int __rte_cold
2774 : 0 : txgbe_dev_rx_queue_setup(struct rte_eth_dev *dev,
2775 : : uint16_t queue_idx,
2776 : : uint16_t nb_desc,
2777 : : unsigned int socket_id,
2778 : : const struct rte_eth_rxconf *rx_conf,
2779 : : struct rte_mempool *mp)
2780 : : {
2781 : : const struct rte_memzone *rz;
2782 : : struct txgbe_rx_queue *rxq;
2783 : : struct txgbe_hw *hw;
2784 : : uint16_t len;
2785 : 0 : struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
2786 : : uint64_t offloads;
2787 : : uint32_t size;
2788 : :
2789 : 0 : PMD_INIT_FUNC_TRACE();
2790 : 0 : hw = TXGBE_DEV_HW(dev);
2791 : :
2792 : 0 : offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
2793 : :
2794 : : /*
2795 : : * Validate number of receive descriptors.
2796 : : * It must not exceed hardware maximum, and must be multiple
2797 : : * of TXGBE_ALIGN.
2798 : : */
2799 [ # # ]: 0 : if (nb_desc % TXGBE_RXD_ALIGN != 0 ||
2800 [ # # ]: 0 : nb_desc > TXGBE_RING_DESC_MAX ||
2801 : : nb_desc < TXGBE_RING_DESC_MIN) {
2802 : : return -EINVAL;
2803 : : }
2804 : :
2805 : : /* Free memory prior to re-allocation if needed... */
2806 [ # # ]: 0 : if (dev->data->rx_queues[queue_idx] != NULL) {
2807 : 0 : txgbe_rx_queue_release(dev->data->rx_queues[queue_idx]);
2808 : 0 : dev->data->rx_queues[queue_idx] = NULL;
2809 : : }
2810 : :
2811 : : /* First allocate the rx queue data structure */
2812 : 0 : rxq = rte_zmalloc_socket("ethdev RX queue",
2813 : : sizeof(struct txgbe_rx_queue),
2814 : : RTE_CACHE_LINE_SIZE, socket_id);
2815 [ # # ]: 0 : if (rxq == NULL)
2816 : : return -ENOMEM;
2817 : 0 : rxq->mb_pool = mp;
2818 : 0 : rxq->nb_rx_desc = nb_desc;
2819 : 0 : rxq->rx_free_thresh = rx_conf->rx_free_thresh;
2820 : 0 : rxq->queue_id = queue_idx;
2821 [ # # ]: 0 : rxq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
2822 : 0 : queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
2823 : 0 : rxq->port_id = dev->data->port_id;
2824 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
2825 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
2826 : : else
2827 : 0 : rxq->crc_len = 0;
2828 : 0 : rxq->drop_en = rx_conf->rx_drop_en;
2829 : 0 : rxq->rx_deferred_start = rx_conf->rx_deferred_start;
2830 : 0 : rxq->offloads = offloads;
2831 : :
2832 : : /*
2833 : : * The packet type in RX descriptor is different for different NICs.
2834 : : * So set different masks for different NICs.
2835 : : */
2836 : 0 : rxq->pkt_type_mask = TXGBE_PTID_MASK;
2837 : :
2838 : : /* Allocate RX ring hardware descriptors. */
2839 : 0 : size = (nb_desc + RTE_PMD_TXGBE_RX_MAX_BURST) * sizeof(struct txgbe_rx_desc);
2840 : 0 : rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
2841 : : size, TXGBE_ALIGN, socket_id);
2842 [ # # ]: 0 : if (rz == NULL) {
2843 : 0 : txgbe_rx_queue_release(rxq);
2844 : 0 : return -ENOMEM;
2845 : : }
2846 : :
2847 : 0 : rxq->mz = rz;
2848 : : /*
2849 : : * Zero init all the descriptors in the ring.
2850 : : */
2851 : 0 : memset(rz->addr, 0, size);
2852 : :
2853 : : /*
2854 : : * Modified to setup VFRDT for Virtual Function
2855 : : */
2856 [ # # ]: 0 : if (txgbe_is_vf(hw)) {
2857 : 0 : rxq->rdt_reg_addr =
2858 : 0 : TXGBE_REG_ADDR(hw, TXGBE_RXWP(queue_idx));
2859 : 0 : rxq->rdh_reg_addr =
2860 : 0 : TXGBE_REG_ADDR(hw, TXGBE_RXRP(queue_idx));
2861 : : } else {
2862 : 0 : rxq->rdt_reg_addr =
2863 : 0 : TXGBE_REG_ADDR(hw, TXGBE_RXWP(rxq->reg_idx));
2864 : 0 : rxq->rdh_reg_addr =
2865 : 0 : TXGBE_REG_ADDR(hw, TXGBE_RXRP(rxq->reg_idx));
2866 : : }
2867 : :
2868 : 0 : rxq->rx_ring_phys_addr = TMZ_PADDR(rz);
2869 : 0 : rxq->rx_ring = (struct txgbe_rx_desc *)TMZ_VADDR(rz);
2870 : :
2871 : : /*
2872 : : * Certain constraints must be met in order to use the bulk buffer
2873 : : * allocation Rx burst function. If any of Rx queues doesn't meet them
2874 : : * the feature should be disabled for the whole port.
2875 : : */
2876 [ # # ]: 0 : if (check_rx_burst_bulk_alloc_preconditions(rxq)) {
2877 : 0 : PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Rx Bulk Alloc "
2878 : : "preconditions - canceling the feature for "
2879 : : "the whole port[%d]",
2880 : : rxq->queue_id, rxq->port_id);
2881 : 0 : adapter->rx_bulk_alloc_allowed = false;
2882 : : }
2883 : :
2884 : : /*
2885 : : * Allocate software ring. Allow for space at the end of the
2886 : : * S/W ring to make sure look-ahead logic in bulk alloc Rx burst
2887 : : * function does not access an invalid memory region.
2888 : : */
2889 : : len = nb_desc;
2890 [ # # ]: 0 : if (adapter->rx_bulk_alloc_allowed)
2891 : 0 : len += RTE_PMD_TXGBE_RX_MAX_BURST;
2892 : :
2893 : 0 : rxq->sw_ring = rte_zmalloc_socket("rxq->sw_ring",
2894 : : sizeof(struct txgbe_rx_entry) * len,
2895 : : RTE_CACHE_LINE_SIZE, socket_id);
2896 [ # # ]: 0 : if (!rxq->sw_ring) {
2897 : 0 : txgbe_rx_queue_release(rxq);
2898 : 0 : return -ENOMEM;
2899 : : }
2900 : :
2901 : : /*
2902 : : * Always allocate even if it's not going to be needed in order to
2903 : : * simplify the code.
2904 : : *
2905 : : * This ring is used in LRO and Scattered Rx cases and Scattered Rx may
2906 : : * be requested in txgbe_dev_rx_init(), which is called later from
2907 : : * dev_start() flow.
2908 : : */
2909 : 0 : rxq->sw_sc_ring =
2910 : 0 : rte_zmalloc_socket("rxq->sw_sc_ring",
2911 : : sizeof(struct txgbe_scattered_rx_entry) * len,
2912 : : RTE_CACHE_LINE_SIZE, socket_id);
2913 [ # # ]: 0 : if (!rxq->sw_sc_ring) {
2914 : 0 : txgbe_rx_queue_release(rxq);
2915 : 0 : return -ENOMEM;
2916 : : }
2917 : :
2918 : 0 : PMD_INIT_LOG(DEBUG, "sw_ring=%p sw_sc_ring=%p hw_ring=%p "
2919 : : "dma_addr=0x%" PRIx64,
2920 : : rxq->sw_ring, rxq->sw_sc_ring, rxq->rx_ring,
2921 : : rxq->rx_ring_phys_addr);
2922 : :
2923 [ # # ]: 0 : if (!rte_is_power_of_2(nb_desc)) {
2924 : 0 : PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Vector Rx "
2925 : : "preconditions - canceling the feature for "
2926 : : "the whole port[%d]",
2927 : : rxq->queue_id, rxq->port_id);
2928 : 0 : adapter->rx_vec_allowed = false;
2929 : : } else {
2930 : 0 : txgbe_rxq_vec_setup(rxq);
2931 : : }
2932 : :
2933 : 0 : dev->data->rx_queues[queue_idx] = rxq;
2934 : :
2935 : 0 : txgbe_reset_rx_queue(adapter, rxq);
2936 : :
2937 : 0 : return 0;
2938 : : }
2939 : :
2940 : : int
2941 : 0 : txgbe_dev_rx_queue_count(void *rx_queue)
2942 : : {
2943 : : #define TXGBE_RXQ_SCAN_INTERVAL 4
2944 : : volatile struct txgbe_rx_desc *rxdp;
2945 : : struct txgbe_rx_queue *rxq;
2946 : : uint32_t desc = 0;
2947 : :
2948 : : rxq = rx_queue;
2949 : 0 : rxdp = &rxq->rx_ring[rxq->rx_tail];
2950 : :
2951 [ # # ]: 0 : while ((desc < rxq->nb_rx_desc) &&
2952 [ # # ]: 0 : (rxdp->qw1.lo.status &
2953 : : rte_cpu_to_le_32(TXGBE_RXD_STAT_DD))) {
2954 : 0 : desc += TXGBE_RXQ_SCAN_INTERVAL;
2955 : 0 : rxdp += TXGBE_RXQ_SCAN_INTERVAL;
2956 [ # # ]: 0 : if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
2957 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail +
2958 : 0 : desc - rxq->nb_rx_desc]);
2959 : : }
2960 : :
2961 : 0 : return desc;
2962 : : }
2963 : :
2964 : : int
2965 : 0 : txgbe_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
2966 : : {
2967 : : struct txgbe_rx_queue *rxq = rx_queue;
2968 : : volatile uint32_t *status;
2969 : : uint32_t nb_hold, desc;
2970 : :
2971 [ # # ]: 0 : if (unlikely(offset >= rxq->nb_rx_desc))
2972 : : return -EINVAL;
2973 : :
2974 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM)
2975 [ # # ]: 0 : if (rxq->rx_using_sse)
2976 : 0 : nb_hold = rxq->rxrearm_nb;
2977 : : else
2978 : : #endif
2979 : 0 : nb_hold = rxq->nb_rx_hold;
2980 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - nb_hold)
2981 : : return RTE_ETH_RX_DESC_UNAVAIL;
2982 : :
2983 : 0 : desc = rxq->rx_tail + offset;
2984 [ # # ]: 0 : if (desc >= rxq->nb_rx_desc)
2985 : 0 : desc -= rxq->nb_rx_desc;
2986 : :
2987 : 0 : status = &rxq->rx_ring[desc].qw1.lo.status;
2988 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(TXGBE_RXD_STAT_DD))
2989 : 0 : return RTE_ETH_RX_DESC_DONE;
2990 : :
2991 : : return RTE_ETH_RX_DESC_AVAIL;
2992 : : }
2993 : :
2994 : : int
2995 : 0 : txgbe_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
2996 : : {
2997 : : struct txgbe_tx_queue *txq = tx_queue;
2998 : : volatile uint32_t *status;
2999 : : uint32_t desc;
3000 : :
3001 [ # # ]: 0 : if (unlikely(offset >= txq->nb_tx_desc))
3002 : : return -EINVAL;
3003 : :
3004 : 0 : desc = txq->tx_tail + offset;
3005 [ # # ]: 0 : if (desc >= txq->nb_tx_desc) {
3006 : 0 : desc -= txq->nb_tx_desc;
3007 [ # # ]: 0 : if (desc >= txq->nb_tx_desc)
3008 : 0 : desc -= txq->nb_tx_desc;
3009 : : }
3010 : :
3011 : 0 : status = &txq->tx_ring[desc].dw3;
3012 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(TXGBE_TXD_DD))
3013 : 0 : return RTE_ETH_TX_DESC_DONE;
3014 : :
3015 : : return RTE_ETH_TX_DESC_FULL;
3016 : : }
3017 : :
3018 : : void __rte_cold
3019 : 0 : txgbe_dev_clear_queues(struct rte_eth_dev *dev)
3020 : : {
3021 : : unsigned int i;
3022 : 0 : struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
3023 : :
3024 : 0 : PMD_INIT_FUNC_TRACE();
3025 : :
3026 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3027 : 0 : struct txgbe_tx_queue *txq = dev->data->tx_queues[i];
3028 : :
3029 [ # # ]: 0 : if (txq != NULL) {
3030 : 0 : txq->ops->release_mbufs(txq);
3031 : 0 : txq->ops->reset(txq);
3032 : : }
3033 : :
3034 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
3035 : : }
3036 : :
3037 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3038 : 0 : struct txgbe_rx_queue *rxq = dev->data->rx_queues[i];
3039 : :
3040 [ # # ]: 0 : if (rxq != NULL) {
3041 : 0 : txgbe_rx_queue_release_mbufs(rxq);
3042 : 0 : txgbe_reset_rx_queue(adapter, rxq);
3043 : : }
3044 : :
3045 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
3046 : : }
3047 : 0 : }
3048 : :
3049 : : void
3050 : 0 : txgbe_dev_free_queues(struct rte_eth_dev *dev)
3051 : : {
3052 : : unsigned int i;
3053 : :
3054 : 0 : PMD_INIT_FUNC_TRACE();
3055 : :
3056 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3057 : 0 : txgbe_dev_rx_queue_release(dev, i);
3058 : 0 : dev->data->rx_queues[i] = NULL;
3059 : : }
3060 : 0 : dev->data->nb_rx_queues = 0;
3061 : :
3062 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3063 : 0 : txgbe_dev_tx_queue_release(dev, i);
3064 : 0 : dev->data->tx_queues[i] = NULL;
3065 : : }
3066 : 0 : dev->data->nb_tx_queues = 0;
3067 : 0 : }
3068 : :
3069 : : /**
3070 : : * Receive Side Scaling (RSS)
3071 : : *
3072 : : * Principles:
3073 : : * The source and destination IP addresses of the IP header and the source
3074 : : * and destination ports of TCP/UDP headers, if any, of received packets are
3075 : : * hashed against a configurable random key to compute a 32-bit RSS hash result.
3076 : : * The seven (7) LSBs of the 32-bit hash result are used as an index into a
3077 : : * 128-entry redirection table (RETA). Each entry of the RETA provides a 3-bit
3078 : : * RSS output index which is used as the RX queue index where to store the
3079 : : * received packets.
3080 : : * The following output is supplied in the RX write-back descriptor:
3081 : : * - 32-bit result of the Microsoft RSS hash function,
3082 : : * - 4-bit RSS type field.
3083 : : */
3084 : :
3085 : : /*
3086 : : * Used as the default key.
3087 : : */
3088 : : static uint8_t rss_intel_key[40] = {
3089 : : 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
3090 : : 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
3091 : : 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
3092 : : 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
3093 : : 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
3094 : : };
3095 : :
3096 : : static void
3097 : 0 : txgbe_rss_disable(struct rte_eth_dev *dev)
3098 : : {
3099 : : struct txgbe_hw *hw;
3100 : :
3101 : 0 : hw = TXGBE_DEV_HW(dev);
3102 [ # # ]: 0 : if (txgbe_is_vf(hw))
3103 : : wr32m(hw, TXGBE_VFPLCFG, TXGBE_VFPLCFG_RSSENA, 0);
3104 : : else
3105 : : wr32m(hw, TXGBE_RACTL, TXGBE_RACTL_RSSENA, 0);
3106 : 0 : }
3107 : :
3108 : : int
3109 : 0 : txgbe_dev_rss_hash_update(struct rte_eth_dev *dev,
3110 : : struct rte_eth_rss_conf *rss_conf)
3111 : : {
3112 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3113 : : uint8_t *hash_key;
3114 : : uint32_t mrqc;
3115 : : uint32_t rss_key;
3116 : : uint64_t rss_hf;
3117 : : uint16_t i;
3118 : :
3119 [ # # ]: 0 : if (!txgbe_rss_update(hw->mac.type)) {
3120 : 0 : PMD_DRV_LOG(ERR, "RSS hash update is not supported on this "
3121 : : "NIC.");
3122 : 0 : return -ENOTSUP;
3123 : : }
3124 : :
3125 : 0 : hash_key = rss_conf->rss_key;
3126 [ # # ]: 0 : if (hash_key) {
3127 : : /* Fill in RSS hash key */
3128 [ # # ]: 0 : for (i = 0; i < 10; i++) {
3129 : 0 : rss_key = LS32(hash_key[(i * 4) + 0], 0, 0xFF);
3130 : 0 : rss_key |= LS32(hash_key[(i * 4) + 1], 8, 0xFF);
3131 : 0 : rss_key |= LS32(hash_key[(i * 4) + 2], 16, 0xFF);
3132 [ # # ]: 0 : rss_key |= LS32(hash_key[(i * 4) + 3], 24, 0xFF);
3133 : 0 : wr32at(hw, TXGBE_REG_RSSKEY, i, rss_key);
3134 : : }
3135 : : }
3136 : :
3137 : : /* Set configured hashing protocols */
3138 : 0 : rss_hf = rss_conf->rss_hf & TXGBE_RSS_OFFLOAD_ALL;
3139 [ # # ]: 0 : if (txgbe_is_vf(hw)) {
3140 : : mrqc = rd32(hw, TXGBE_VFPLCFG);
3141 : 0 : mrqc &= ~TXGBE_VFPLCFG_RSSMASK;
3142 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV4)
3143 : 0 : mrqc |= TXGBE_VFPLCFG_RSSIPV4;
3144 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
3145 : 0 : mrqc |= TXGBE_VFPLCFG_RSSIPV4TCP;
3146 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6 ||
3147 : : rss_hf & RTE_ETH_RSS_IPV6_EX)
3148 : 0 : mrqc |= TXGBE_VFPLCFG_RSSIPV6;
3149 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP ||
3150 : : rss_hf & RTE_ETH_RSS_IPV6_TCP_EX)
3151 : 0 : mrqc |= TXGBE_VFPLCFG_RSSIPV6TCP;
3152 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
3153 : 0 : mrqc |= TXGBE_VFPLCFG_RSSIPV4UDP;
3154 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP ||
3155 : : rss_hf & RTE_ETH_RSS_IPV6_UDP_EX)
3156 : 0 : mrqc |= TXGBE_VFPLCFG_RSSIPV6UDP;
3157 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_SCTP)
3158 : 0 : mrqc |= TXGBE_VFPLCFG_RSSIPV4SCTP;
3159 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_SCTP)
3160 : 0 : mrqc |= TXGBE_VFPLCFG_RSSIPV6SCTP;
3161 : :
3162 [ # # ]: 0 : if (rss_hf)
3163 : 0 : mrqc |= TXGBE_VFPLCFG_RSSENA;
3164 : : else
3165 : 0 : mrqc &= ~TXGBE_VFPLCFG_RSSENA;
3166 : :
3167 [ # # ]: 0 : if (dev->data->nb_rx_queues > 3)
3168 : 0 : mrqc |= TXGBE_VFPLCFG_RSSHASH(2);
3169 [ # # ]: 0 : else if (dev->data->nb_rx_queues > 1)
3170 : 0 : mrqc |= TXGBE_VFPLCFG_RSSHASH(1);
3171 : :
3172 : : wr32(hw, TXGBE_VFPLCFG, mrqc);
3173 : : } else {
3174 : : mrqc = rd32(hw, TXGBE_RACTL);
3175 : 0 : mrqc &= ~TXGBE_RACTL_RSSMASK;
3176 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV4)
3177 : 0 : mrqc |= TXGBE_RACTL_RSSIPV4;
3178 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
3179 : 0 : mrqc |= TXGBE_RACTL_RSSIPV4TCP;
3180 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6 ||
3181 : : rss_hf & RTE_ETH_RSS_IPV6_EX)
3182 : 0 : mrqc |= TXGBE_RACTL_RSSIPV6;
3183 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP ||
3184 : : rss_hf & RTE_ETH_RSS_IPV6_TCP_EX)
3185 : 0 : mrqc |= TXGBE_RACTL_RSSIPV6TCP;
3186 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
3187 : 0 : mrqc |= TXGBE_RACTL_RSSIPV4UDP;
3188 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP ||
3189 : : rss_hf & RTE_ETH_RSS_IPV6_UDP_EX)
3190 : 0 : mrqc |= TXGBE_RACTL_RSSIPV6UDP;
3191 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_SCTP)
3192 : 0 : mrqc |= TXGBE_RACTL_RSSIPV4SCTP;
3193 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_SCTP)
3194 : 0 : mrqc |= TXGBE_RACTL_RSSIPV6SCTP;
3195 : :
3196 [ # # ]: 0 : if (rss_hf)
3197 : 0 : mrqc |= TXGBE_RACTL_RSSENA;
3198 : : else
3199 : 0 : mrqc &= ~TXGBE_RACTL_RSSENA;
3200 : :
3201 : : wr32(hw, TXGBE_RACTL, mrqc);
3202 : : }
3203 : :
3204 : : return 0;
3205 : : }
3206 : :
3207 : : int
3208 : 0 : txgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
3209 : : struct rte_eth_rss_conf *rss_conf)
3210 : : {
3211 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3212 : : uint8_t *hash_key;
3213 : : uint32_t mrqc;
3214 : : uint32_t rss_key;
3215 : : uint64_t rss_hf;
3216 : : uint16_t i;
3217 : :
3218 : 0 : hash_key = rss_conf->rss_key;
3219 [ # # ]: 0 : if (hash_key) {
3220 : : /* Return RSS hash key */
3221 [ # # ]: 0 : for (i = 0; i < 10; i++) {
3222 : 0 : rss_key = rd32at(hw, TXGBE_REG_RSSKEY, i);
3223 : 0 : hash_key[(i * 4) + 0] = RS32(rss_key, 0, 0xFF);
3224 : 0 : hash_key[(i * 4) + 1] = RS32(rss_key, 8, 0xFF);
3225 : 0 : hash_key[(i * 4) + 2] = RS32(rss_key, 16, 0xFF);
3226 : 0 : hash_key[(i * 4) + 3] = RS32(rss_key, 24, 0xFF);
3227 : : }
3228 : : }
3229 : :
3230 : : rss_hf = 0;
3231 [ # # ]: 0 : if (txgbe_is_vf(hw)) {
3232 : : mrqc = rd32(hw, TXGBE_VFPLCFG);
3233 [ # # ]: 0 : if (mrqc & TXGBE_VFPLCFG_RSSIPV4)
3234 : : rss_hf |= RTE_ETH_RSS_IPV4;
3235 [ # # ]: 0 : if (mrqc & TXGBE_VFPLCFG_RSSIPV4TCP)
3236 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_TCP;
3237 [ # # ]: 0 : if (mrqc & TXGBE_VFPLCFG_RSSIPV6)
3238 : 0 : rss_hf |= RTE_ETH_RSS_IPV6 |
3239 : : RTE_ETH_RSS_IPV6_EX;
3240 [ # # ]: 0 : if (mrqc & TXGBE_VFPLCFG_RSSIPV6TCP)
3241 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_TCP |
3242 : : RTE_ETH_RSS_IPV6_TCP_EX;
3243 [ # # ]: 0 : if (mrqc & TXGBE_VFPLCFG_RSSIPV4UDP)
3244 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_UDP;
3245 [ # # ]: 0 : if (mrqc & TXGBE_VFPLCFG_RSSIPV6UDP)
3246 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_UDP |
3247 : : RTE_ETH_RSS_IPV6_UDP_EX;
3248 [ # # ]: 0 : if (mrqc & TXGBE_VFPLCFG_RSSIPV4SCTP)
3249 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_SCTP;
3250 [ # # ]: 0 : if (mrqc & TXGBE_VFPLCFG_RSSIPV6SCTP)
3251 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_SCTP;
3252 [ # # ]: 0 : if (!(mrqc & TXGBE_VFPLCFG_RSSENA))
3253 : : rss_hf = 0;
3254 : : } else {
3255 : : mrqc = rd32(hw, TXGBE_RACTL);
3256 [ # # ]: 0 : if (mrqc & TXGBE_RACTL_RSSIPV4)
3257 : : rss_hf |= RTE_ETH_RSS_IPV4;
3258 [ # # ]: 0 : if (mrqc & TXGBE_RACTL_RSSIPV4TCP)
3259 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_TCP;
3260 [ # # ]: 0 : if (mrqc & TXGBE_RACTL_RSSIPV6)
3261 : 0 : rss_hf |= RTE_ETH_RSS_IPV6 |
3262 : : RTE_ETH_RSS_IPV6_EX;
3263 [ # # ]: 0 : if (mrqc & TXGBE_RACTL_RSSIPV6TCP)
3264 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_TCP |
3265 : : RTE_ETH_RSS_IPV6_TCP_EX;
3266 [ # # ]: 0 : if (mrqc & TXGBE_RACTL_RSSIPV4UDP)
3267 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_UDP;
3268 [ # # ]: 0 : if (mrqc & TXGBE_RACTL_RSSIPV6UDP)
3269 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_UDP |
3270 : : RTE_ETH_RSS_IPV6_UDP_EX;
3271 [ # # ]: 0 : if (mrqc & TXGBE_RACTL_RSSIPV4SCTP)
3272 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_SCTP;
3273 [ # # ]: 0 : if (mrqc & TXGBE_RACTL_RSSIPV6SCTP)
3274 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_SCTP;
3275 [ # # ]: 0 : if (!(mrqc & TXGBE_RACTL_RSSENA))
3276 : : rss_hf = 0;
3277 : : }
3278 : :
3279 : : rss_hf &= TXGBE_RSS_OFFLOAD_ALL;
3280 : :
3281 : 0 : rss_conf->rss_hf = rss_hf;
3282 : 0 : return 0;
3283 : : }
3284 : :
3285 : : static void
3286 : 0 : txgbe_rss_configure(struct rte_eth_dev *dev)
3287 : : {
3288 : : struct rte_eth_rss_conf rss_conf;
3289 : 0 : struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
3290 : : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3291 : : uint32_t reta;
3292 : : uint16_t i;
3293 : : uint16_t j;
3294 : :
3295 : 0 : PMD_INIT_FUNC_TRACE();
3296 : :
3297 : : /*
3298 : : * Fill in redirection table
3299 : : * The byte-swap is needed because NIC registers are in
3300 : : * little-endian order.
3301 : : */
3302 [ # # ]: 0 : if (adapter->rss_reta_updated == 0) {
3303 : : reta = 0;
3304 [ # # ]: 0 : for (i = 0, j = 0; i < RTE_ETH_RSS_RETA_SIZE_128; i++, j++) {
3305 [ # # ]: 0 : if (j == dev->data->nb_rx_queues)
3306 : : j = 0;
3307 : 0 : reta = (reta >> 8) | LS32(j, 24, 0xFF);
3308 [ # # ]: 0 : if ((i & 3) == 3)
3309 : 0 : wr32at(hw, TXGBE_REG_RSSTBL, i >> 2, reta);
3310 : : }
3311 : : }
3312 : : /*
3313 : : * Configure the RSS key and the RSS protocols used to compute
3314 : : * the RSS hash of input packets.
3315 : : */
3316 : 0 : rss_conf = dev->data->dev_conf.rx_adv_conf.rss_conf;
3317 [ # # ]: 0 : if (rss_conf.rss_key == NULL)
3318 : 0 : rss_conf.rss_key = rss_intel_key; /* Default hash key */
3319 : 0 : txgbe_dev_rss_hash_update(dev, &rss_conf);
3320 : 0 : }
3321 : :
3322 : : #define NUM_VFTA_REGISTERS 128
3323 : : #define NIC_RX_BUFFER_SIZE 0x200
3324 : :
3325 : : static void
3326 : 0 : txgbe_vmdq_dcb_configure(struct rte_eth_dev *dev)
3327 : : {
3328 : : struct rte_eth_vmdq_dcb_conf *cfg;
3329 : : struct txgbe_hw *hw;
3330 : : enum rte_eth_nb_pools num_pools;
3331 : : uint32_t mrqc, vt_ctl, queue_mapping, vlanctrl;
3332 : : uint16_t pbsize;
3333 : : uint8_t nb_tcs; /* number of traffic classes */
3334 : : int i;
3335 : :
3336 : 0 : PMD_INIT_FUNC_TRACE();
3337 : 0 : hw = TXGBE_DEV_HW(dev);
3338 : : cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
3339 : 0 : num_pools = cfg->nb_queue_pools;
3340 : : /* Check we have a valid number of pools */
3341 [ # # ]: 0 : if (num_pools != RTE_ETH_16_POOLS && num_pools != RTE_ETH_32_POOLS) {
3342 : 0 : txgbe_rss_disable(dev);
3343 : 0 : return;
3344 : : }
3345 : : /* 16 pools -> 8 traffic classes, 32 pools -> 4 traffic classes */
3346 : 0 : nb_tcs = (uint8_t)(RTE_ETH_VMDQ_DCB_NUM_QUEUES / (int)num_pools);
3347 : :
3348 : : /*
3349 : : * split rx buffer up into sections, each for 1 traffic class
3350 : : */
3351 : 0 : pbsize = (uint16_t)(NIC_RX_BUFFER_SIZE / nb_tcs);
3352 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
3353 : 0 : uint32_t rxpbsize = rd32(hw, TXGBE_PBRXSIZE(i));
3354 : :
3355 : 0 : rxpbsize &= (~(0x3FF << 10));
3356 : : /* clear 10 bits. */
3357 : 0 : rxpbsize |= (pbsize << 10); /* set value */
3358 : : wr32(hw, TXGBE_PBRXSIZE(i), rxpbsize);
3359 : : }
3360 : : /* zero alloc all unused TCs */
3361 [ # # ]: 0 : for (i = nb_tcs; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
3362 : 0 : uint32_t rxpbsize = rd32(hw, TXGBE_PBRXSIZE(i));
3363 : :
3364 : 0 : rxpbsize &= (~(0x3FF << 10));
3365 : : /* clear 10 bits. */
3366 : : wr32(hw, TXGBE_PBRXSIZE(i), rxpbsize);
3367 : : }
3368 : :
3369 [ # # ]: 0 : if (num_pools == RTE_ETH_16_POOLS) {
3370 : : mrqc = TXGBE_PORTCTL_NUMTC_8;
3371 : : mrqc |= TXGBE_PORTCTL_NUMVT_16;
3372 : : } else {
3373 : : mrqc = TXGBE_PORTCTL_NUMTC_4;
3374 : : mrqc |= TXGBE_PORTCTL_NUMVT_32;
3375 : : }
3376 : : wr32m(hw, TXGBE_PORTCTL,
3377 : : TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK, mrqc);
3378 : :
3379 : : vt_ctl = TXGBE_POOLCTL_RPLEN;
3380 [ # # ]: 0 : if (cfg->enable_default_pool)
3381 : 0 : vt_ctl |= TXGBE_POOLCTL_DEFPL(cfg->default_pool);
3382 : : else
3383 : : vt_ctl |= TXGBE_POOLCTL_DEFDSA;
3384 : :
3385 : : wr32(hw, TXGBE_POOLCTL, vt_ctl);
3386 : :
3387 : : queue_mapping = 0;
3388 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++)
3389 : 0 : queue_mapping |= ((cfg->dcb_tc[i] & TXGBE_RPUP2TC_UP_MASK) <<
3390 : 0 : (i * TXGBE_RPUP2TC_UP_SHIFT));
3391 : :
3392 : : wr32(hw, TXGBE_RPUP2TC, queue_mapping);
3393 : :
3394 : : wr32(hw, TXGBE_ARBRXCTL, TXGBE_ARBRXCTL_RRM);
3395 : :
3396 : : /* enable vlan filtering and allow all vlan tags through */
3397 : : vlanctrl = rd32(hw, TXGBE_VLANCTL);
3398 : 0 : vlanctrl |= TXGBE_VLANCTL_VFE; /* enable vlan filters */
3399 : : wr32(hw, TXGBE_VLANCTL, vlanctrl);
3400 : :
3401 : : /* enable all vlan filters */
3402 [ # # ]: 0 : for (i = 0; i < NUM_VFTA_REGISTERS; i++)
3403 : 0 : wr32(hw, TXGBE_VLANTBL(i), 0xFFFFFFFF);
3404 : :
3405 [ # # ]: 0 : wr32(hw, TXGBE_POOLRXENA(0),
3406 : : num_pools == RTE_ETH_16_POOLS ? 0xFFFF : 0xFFFFFFFF);
3407 : :
3408 : : wr32(hw, TXGBE_ETHADDRIDX, 0);
3409 : : wr32(hw, TXGBE_ETHADDRASSL, 0xFFFFFFFF);
3410 : : wr32(hw, TXGBE_ETHADDRASSH, 0xFFFFFFFF);
3411 : :
3412 : : /* set up filters for vlan tags as configured */
3413 [ # # ]: 0 : for (i = 0; i < cfg->nb_pool_maps; i++) {
3414 : : /* set vlan id in VF register and set the valid bit */
3415 : 0 : wr32(hw, TXGBE_PSRVLANIDX, i);
3416 : 0 : wr32(hw, TXGBE_PSRVLAN, (TXGBE_PSRVLAN_EA |
3417 : 0 : (cfg->pool_map[i].vlan_id & 0xFFF)));
3418 : :
3419 : 0 : wr32(hw, TXGBE_PSRVLANPLM(0), cfg->pool_map[i].pools);
3420 : : }
3421 : : }
3422 : :
3423 : : /**
3424 : : * txgbe_dcb_config_tx_hw_config - Configure general DCB TX parameters
3425 : : * @dev: pointer to eth_dev structure
3426 : : * @dcb_config: pointer to txgbe_dcb_config structure
3427 : : */
3428 : : static void
3429 : 0 : txgbe_dcb_tx_hw_config(struct rte_eth_dev *dev,
3430 : : struct txgbe_dcb_config *dcb_config)
3431 : : {
3432 : : uint32_t reg;
3433 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3434 : :
3435 : 0 : PMD_INIT_FUNC_TRACE();
3436 : :
3437 : : /* Disable the Tx desc arbiter */
3438 : : reg = rd32(hw, TXGBE_ARBTXCTL);
3439 : 0 : reg |= TXGBE_ARBTXCTL_DIA;
3440 : : wr32(hw, TXGBE_ARBTXCTL, reg);
3441 : :
3442 : : /* Enable DCB for Tx with 8 TCs */
3443 : : reg = rd32(hw, TXGBE_PORTCTL);
3444 : 0 : reg &= TXGBE_PORTCTL_NUMTC_MASK;
3445 : 0 : reg |= TXGBE_PORTCTL_DCB;
3446 [ # # ]: 0 : if (dcb_config->num_tcs.pg_tcs == 8)
3447 : : reg |= TXGBE_PORTCTL_NUMTC_8;
3448 : : else
3449 : : reg |= TXGBE_PORTCTL_NUMTC_4;
3450 : :
3451 : : wr32(hw, TXGBE_PORTCTL, reg);
3452 : :
3453 : : /* Enable the Tx desc arbiter */
3454 : : reg = rd32(hw, TXGBE_ARBTXCTL);
3455 : 0 : reg &= ~TXGBE_ARBTXCTL_DIA;
3456 : : wr32(hw, TXGBE_ARBTXCTL, reg);
3457 : 0 : }
3458 : :
3459 : : /**
3460 : : * txgbe_vmdq_dcb_hw_tx_config - Configure general VMDQ+DCB TX parameters
3461 : : * @dev: pointer to rte_eth_dev structure
3462 : : * @dcb_config: pointer to txgbe_dcb_config structure
3463 : : */
3464 : : static void
3465 : 0 : txgbe_vmdq_dcb_hw_tx_config(struct rte_eth_dev *dev,
3466 : : struct txgbe_dcb_config *dcb_config)
3467 : : {
3468 : : struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
3469 : 0 : &dev->data->dev_conf.tx_adv_conf.vmdq_dcb_tx_conf;
3470 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3471 : :
3472 : 0 : PMD_INIT_FUNC_TRACE();
3473 : : /*PF VF Transmit Enable*/
3474 : 0 : wr32(hw, TXGBE_POOLTXENA(0),
3475 [ # # ]: 0 : vmdq_tx_conf->nb_queue_pools ==
3476 : : RTE_ETH_16_POOLS ? 0xFFFF : 0xFFFFFFFF);
3477 : :
3478 : : /*Configure general DCB TX parameters*/
3479 : 0 : txgbe_dcb_tx_hw_config(dev, dcb_config);
3480 : 0 : }
3481 : :
3482 : : static void
3483 : 0 : txgbe_vmdq_dcb_rx_config(struct rte_eth_dev *dev,
3484 : : struct txgbe_dcb_config *dcb_config)
3485 : : {
3486 : : struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
3487 : 0 : &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
3488 : : struct txgbe_dcb_tc_config *tc;
3489 : : uint8_t i, j;
3490 : :
3491 : : /* convert rte_eth_conf.rx_adv_conf to struct txgbe_dcb_config */
3492 [ # # ]: 0 : if (vmdq_rx_conf->nb_queue_pools == RTE_ETH_16_POOLS) {
3493 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_8_TCS;
3494 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_8_TCS;
3495 : : } else {
3496 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_4_TCS;
3497 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_4_TCS;
3498 : : }
3499 : :
3500 : : /* Initialize User Priority to Traffic Class mapping */
3501 [ # # ]: 0 : for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
3502 : 0 : tc = &dcb_config->tc_config[j];
3503 : 0 : tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0;
3504 : : }
3505 : :
3506 : : /* User Priority to Traffic Class mapping */
3507 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
3508 : 0 : j = vmdq_rx_conf->dcb_tc[i];
3509 : 0 : tc = &dcb_config->tc_config[j];
3510 : 0 : tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap |=
3511 : 0 : (uint8_t)(1 << i);
3512 : : }
3513 : 0 : }
3514 : :
3515 : : static void
3516 : 0 : txgbe_dcb_vt_tx_config(struct rte_eth_dev *dev,
3517 : : struct txgbe_dcb_config *dcb_config)
3518 : : {
3519 : : struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
3520 : 0 : &dev->data->dev_conf.tx_adv_conf.vmdq_dcb_tx_conf;
3521 : : struct txgbe_dcb_tc_config *tc;
3522 : : uint8_t i, j;
3523 : :
3524 : : /* convert rte_eth_conf.rx_adv_conf to struct txgbe_dcb_config */
3525 [ # # ]: 0 : if (vmdq_tx_conf->nb_queue_pools == RTE_ETH_16_POOLS) {
3526 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_8_TCS;
3527 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_8_TCS;
3528 : : } else {
3529 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_4_TCS;
3530 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_4_TCS;
3531 : : }
3532 : :
3533 : : /* Initialize User Priority to Traffic Class mapping */
3534 [ # # ]: 0 : for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
3535 : 0 : tc = &dcb_config->tc_config[j];
3536 : 0 : tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0;
3537 : : }
3538 : :
3539 : : /* User Priority to Traffic Class mapping */
3540 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
3541 : 0 : j = vmdq_tx_conf->dcb_tc[i];
3542 : 0 : tc = &dcb_config->tc_config[j];
3543 : 0 : tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap |=
3544 : 0 : (uint8_t)(1 << i);
3545 : : }
3546 : 0 : }
3547 : :
3548 : : static void
3549 : : txgbe_dcb_rx_config(struct rte_eth_dev *dev,
3550 : : struct txgbe_dcb_config *dcb_config)
3551 : : {
3552 : : struct rte_eth_dcb_rx_conf *rx_conf =
3553 : : &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
3554 : : struct txgbe_dcb_tc_config *tc;
3555 : : uint8_t i, j;
3556 : :
3557 : 0 : dcb_config->num_tcs.pg_tcs = (uint8_t)rx_conf->nb_tcs;
3558 : 0 : dcb_config->num_tcs.pfc_tcs = (uint8_t)rx_conf->nb_tcs;
3559 : :
3560 : : /* Initialize User Priority to Traffic Class mapping */
3561 [ # # ]: 0 : for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
3562 : 0 : tc = &dcb_config->tc_config[j];
3563 : 0 : tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0;
3564 : : }
3565 : :
3566 : : /* User Priority to Traffic Class mapping */
3567 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
3568 : 0 : j = rx_conf->dcb_tc[i];
3569 : 0 : tc = &dcb_config->tc_config[j];
3570 : 0 : tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap |=
3571 : 0 : (uint8_t)(1 << i);
3572 : : }
3573 : : }
3574 : :
3575 : : static void
3576 : : txgbe_dcb_tx_config(struct rte_eth_dev *dev,
3577 : : struct txgbe_dcb_config *dcb_config)
3578 : : {
3579 : : struct rte_eth_dcb_tx_conf *tx_conf =
3580 : : &dev->data->dev_conf.tx_adv_conf.dcb_tx_conf;
3581 : : struct txgbe_dcb_tc_config *tc;
3582 : : uint8_t i, j;
3583 : :
3584 : 0 : dcb_config->num_tcs.pg_tcs = (uint8_t)tx_conf->nb_tcs;
3585 : 0 : dcb_config->num_tcs.pfc_tcs = (uint8_t)tx_conf->nb_tcs;
3586 : :
3587 : : /* Initialize User Priority to Traffic Class mapping */
3588 [ # # ]: 0 : for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
3589 : 0 : tc = &dcb_config->tc_config[j];
3590 : 0 : tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0;
3591 : : }
3592 : :
3593 : : /* User Priority to Traffic Class mapping */
3594 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
3595 : 0 : j = tx_conf->dcb_tc[i];
3596 : 0 : tc = &dcb_config->tc_config[j];
3597 : 0 : tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap |=
3598 : 0 : (uint8_t)(1 << i);
3599 : : }
3600 : : }
3601 : :
3602 : : /**
3603 : : * txgbe_dcb_rx_hw_config - Configure general DCB RX HW parameters
3604 : : * @dev: pointer to eth_dev structure
3605 : : * @dcb_config: pointer to txgbe_dcb_config structure
3606 : : */
3607 : : static void
3608 : 0 : txgbe_dcb_rx_hw_config(struct rte_eth_dev *dev,
3609 : : struct txgbe_dcb_config *dcb_config)
3610 : : {
3611 : : uint32_t reg;
3612 : : uint32_t vlanctrl;
3613 : : uint8_t i;
3614 : : uint32_t q;
3615 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3616 : :
3617 : 0 : PMD_INIT_FUNC_TRACE();
3618 : : /*
3619 : : * Disable the arbiter before changing parameters
3620 : : * (always enable recycle mode; WSP)
3621 : : */
3622 : : reg = TXGBE_ARBRXCTL_RRM | TXGBE_ARBRXCTL_WSP | TXGBE_ARBRXCTL_DIA;
3623 : : wr32(hw, TXGBE_ARBRXCTL, reg);
3624 : :
3625 : : reg = rd32(hw, TXGBE_PORTCTL);
3626 : 0 : reg &= ~(TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK);
3627 [ # # ]: 0 : if (dcb_config->num_tcs.pg_tcs == 4) {
3628 : : reg |= TXGBE_PORTCTL_NUMTC_4;
3629 [ # # ]: 0 : if (dcb_config->vt_mode)
3630 : 0 : reg |= TXGBE_PORTCTL_NUMVT_32;
3631 : : else
3632 : : wr32(hw, TXGBE_POOLCTL, 0);
3633 : : }
3634 : :
3635 [ # # ]: 0 : if (dcb_config->num_tcs.pg_tcs == 8) {
3636 : 0 : reg |= TXGBE_PORTCTL_NUMTC_8;
3637 [ # # ]: 0 : if (dcb_config->vt_mode)
3638 : 0 : reg |= TXGBE_PORTCTL_NUMVT_16;
3639 : : else
3640 : : wr32(hw, TXGBE_POOLCTL, 0);
3641 : : }
3642 : :
3643 : : wr32(hw, TXGBE_PORTCTL, reg);
3644 : :
3645 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
3646 : : /* Disable drop for all queues in VMDQ mode*/
3647 [ # # ]: 0 : for (q = 0; q < TXGBE_MAX_RX_QUEUE_NUM; q++) {
3648 : 0 : u32 val = 1 << (q % 32);
3649 : 0 : wr32m(hw, TXGBE_QPRXDROP(q / 32), val, val);
3650 : : }
3651 : : } else {
3652 : : /* Enable drop for all queues in SRIOV mode */
3653 [ # # ]: 0 : for (q = 0; q < TXGBE_MAX_RX_QUEUE_NUM; q++) {
3654 : 0 : u32 val = 1 << (q % 32);
3655 : 0 : wr32m(hw, TXGBE_QPRXDROP(q / 32), val, val);
3656 : : }
3657 : : }
3658 : :
3659 : : /* VLNCTL: enable vlan filtering and allow all vlan tags through */
3660 : : vlanctrl = rd32(hw, TXGBE_VLANCTL);
3661 : 0 : vlanctrl |= TXGBE_VLANCTL_VFE; /* enable vlan filters */
3662 : : wr32(hw, TXGBE_VLANCTL, vlanctrl);
3663 : :
3664 : : /* VLANTBL - enable all vlan filters */
3665 [ # # ]: 0 : for (i = 0; i < NUM_VFTA_REGISTERS; i++)
3666 : 0 : wr32(hw, TXGBE_VLANTBL(i), 0xFFFFFFFF);
3667 : :
3668 : : /*
3669 : : * Configure Rx packet plane (recycle mode; WSP) and
3670 : : * enable arbiter
3671 : : */
3672 : : reg = TXGBE_ARBRXCTL_RRM | TXGBE_ARBRXCTL_WSP;
3673 : : wr32(hw, TXGBE_ARBRXCTL, reg);
3674 : 0 : }
3675 : :
3676 : : static void
3677 : : txgbe_dcb_hw_arbite_rx_config(struct txgbe_hw *hw, uint16_t *refill,
3678 : : uint16_t *max, uint8_t *bwg_id, uint8_t *tsa, uint8_t *map)
3679 : : {
3680 : 0 : txgbe_dcb_config_rx_arbiter_raptor(hw, refill, max, bwg_id,
3681 : : tsa, map);
3682 : 0 : }
3683 : :
3684 : : static void
3685 : 0 : txgbe_dcb_hw_arbite_tx_config(struct txgbe_hw *hw, uint16_t *refill,
3686 : : uint16_t *max, uint8_t *bwg_id, uint8_t *tsa, uint8_t *map)
3687 : : {
3688 [ # # ]: 0 : switch (hw->mac.type) {
3689 : 0 : case txgbe_mac_sp:
3690 : : case txgbe_mac_aml:
3691 : : case txgbe_mac_aml40:
3692 : 0 : txgbe_dcb_config_tx_desc_arbiter_raptor(hw, refill,
3693 : : max, bwg_id, tsa);
3694 : 0 : txgbe_dcb_config_tx_data_arbiter_raptor(hw, refill,
3695 : : max, bwg_id, tsa, map);
3696 : 0 : break;
3697 : : default:
3698 : : break;
3699 : : }
3700 : 0 : }
3701 : :
3702 : : #define DCB_RX_CONFIG 1
3703 : : #define DCB_TX_CONFIG 1
3704 : : #define DCB_TX_PB 1024
3705 : : /**
3706 : : * txgbe_dcb_hw_configure - Enable DCB and configure
3707 : : * general DCB in VT mode and non-VT mode parameters
3708 : : * @dev: pointer to rte_eth_dev structure
3709 : : * @dcb_config: pointer to txgbe_dcb_config structure
3710 : : */
3711 : : static int
3712 : 0 : txgbe_dcb_hw_configure(struct rte_eth_dev *dev,
3713 : : struct txgbe_dcb_config *dcb_config)
3714 : : {
3715 : : int ret = 0;
3716 : : uint8_t i, pfc_en, nb_tcs;
3717 : : uint16_t pbsize, rx_buffer_size;
3718 : : uint8_t config_dcb_rx = 0;
3719 : : uint8_t config_dcb_tx = 0;
3720 : 0 : uint8_t tsa[TXGBE_DCB_TC_MAX] = {0};
3721 : 0 : uint8_t bwgid[TXGBE_DCB_TC_MAX] = {0};
3722 : 0 : uint16_t refill[TXGBE_DCB_TC_MAX] = {0};
3723 : 0 : uint16_t max[TXGBE_DCB_TC_MAX] = {0};
3724 : 0 : uint8_t map[TXGBE_DCB_TC_MAX] = {0};
3725 : : struct txgbe_dcb_tc_config *tc;
3726 : 0 : uint32_t max_frame = dev->data->mtu +
3727 : 0 : RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
3728 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3729 : : struct txgbe_bw_conf *bw_conf = TXGBE_DEV_BW_CONF(dev);
3730 : :
3731 [ # # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
3732 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB:
3733 : 0 : dcb_config->vt_mode = true;
3734 : : config_dcb_rx = DCB_RX_CONFIG;
3735 : : /*
3736 : : * get dcb and VT rx configuration parameters
3737 : : * from rte_eth_conf
3738 : : */
3739 : 0 : txgbe_vmdq_dcb_rx_config(dev, dcb_config);
3740 : : /*Configure general VMDQ and DCB RX parameters*/
3741 : 0 : txgbe_vmdq_dcb_configure(dev);
3742 : 0 : break;
3743 : 0 : case RTE_ETH_MQ_RX_DCB:
3744 : : case RTE_ETH_MQ_RX_DCB_RSS:
3745 : 0 : dcb_config->vt_mode = false;
3746 : : config_dcb_rx = DCB_RX_CONFIG;
3747 : : /* Get dcb TX configuration parameters from rte_eth_conf */
3748 : : txgbe_dcb_rx_config(dev, dcb_config);
3749 : : /*Configure general DCB RX parameters*/
3750 : 0 : txgbe_dcb_rx_hw_config(dev, dcb_config);
3751 : 0 : break;
3752 : 0 : default:
3753 : 0 : PMD_INIT_LOG(ERR, "Incorrect DCB RX mode configuration");
3754 : 0 : break;
3755 : : }
3756 [ # # # ]: 0 : switch (dev->data->dev_conf.txmode.mq_mode) {
3757 : 0 : case RTE_ETH_MQ_TX_VMDQ_DCB:
3758 : 0 : dcb_config->vt_mode = true;
3759 : : config_dcb_tx = DCB_TX_CONFIG;
3760 : : /* get DCB and VT TX configuration parameters
3761 : : * from rte_eth_conf
3762 : : */
3763 : 0 : txgbe_dcb_vt_tx_config(dev, dcb_config);
3764 : : /* Configure general VMDQ and DCB TX parameters */
3765 : 0 : txgbe_vmdq_dcb_hw_tx_config(dev, dcb_config);
3766 : 0 : break;
3767 : :
3768 : 0 : case RTE_ETH_MQ_TX_DCB:
3769 : 0 : dcb_config->vt_mode = false;
3770 : : config_dcb_tx = DCB_TX_CONFIG;
3771 : : /* get DCB TX configuration parameters from rte_eth_conf */
3772 : : txgbe_dcb_tx_config(dev, dcb_config);
3773 : : /* Configure general DCB TX parameters */
3774 : 0 : txgbe_dcb_tx_hw_config(dev, dcb_config);
3775 : 0 : break;
3776 : 0 : default:
3777 : 0 : PMD_INIT_LOG(ERR, "Incorrect DCB TX mode configuration");
3778 : 0 : break;
3779 : : }
3780 : :
3781 : 0 : nb_tcs = dcb_config->num_tcs.pfc_tcs;
3782 : : /* Unpack map */
3783 : 0 : txgbe_dcb_unpack_map_cee(dcb_config, TXGBE_DCB_RX_CONFIG, map);
3784 [ # # ]: 0 : if (nb_tcs == RTE_ETH_4_TCS) {
3785 : : /* Avoid un-configured priority mapping to TC0 */
3786 : : uint8_t j = 4;
3787 : : uint8_t mask = 0xFF;
3788 : :
3789 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES - 4; i++)
3790 : 0 : mask = (uint8_t)(mask & (~(1 << map[i])));
3791 [ # # ]: 0 : for (i = 0; mask && (i < TXGBE_DCB_TC_MAX); i++) {
3792 [ # # # # ]: 0 : if ((mask & 0x1) && j < RTE_ETH_DCB_NUM_USER_PRIORITIES)
3793 : 0 : map[j++] = i;
3794 : 0 : mask >>= 1;
3795 : : }
3796 : : /* Re-configure 4 TCs BW */
3797 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
3798 : 0 : tc = &dcb_config->tc_config[i];
3799 [ # # ]: 0 : if (bw_conf->tc_num != nb_tcs)
3800 : 0 : tc->path[TXGBE_DCB_TX_CONFIG].bwg_percent =
3801 : : (uint8_t)(100 / nb_tcs);
3802 : 0 : tc->path[TXGBE_DCB_RX_CONFIG].bwg_percent =
3803 : : (uint8_t)(100 / nb_tcs);
3804 : : }
3805 [ # # ]: 0 : for (; i < TXGBE_DCB_TC_MAX; i++) {
3806 : 0 : tc = &dcb_config->tc_config[i];
3807 : 0 : tc->path[TXGBE_DCB_TX_CONFIG].bwg_percent = 0;
3808 : 0 : tc->path[TXGBE_DCB_RX_CONFIG].bwg_percent = 0;
3809 : : }
3810 : : } else {
3811 : : /* Re-configure 8 TCs BW */
3812 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
3813 : 0 : tc = &dcb_config->tc_config[i];
3814 [ # # ]: 0 : if (bw_conf->tc_num != nb_tcs)
3815 : 0 : tc->path[TXGBE_DCB_TX_CONFIG].bwg_percent =
3816 : 0 : (uint8_t)(100 / nb_tcs + (i & 1));
3817 : 0 : tc->path[TXGBE_DCB_RX_CONFIG].bwg_percent =
3818 : 0 : (uint8_t)(100 / nb_tcs + (i & 1));
3819 : : }
3820 : : }
3821 : :
3822 : : rx_buffer_size = NIC_RX_BUFFER_SIZE;
3823 : :
3824 [ # # ]: 0 : if (config_dcb_rx) {
3825 : : /* Set RX buffer size */
3826 : 0 : pbsize = (uint16_t)(rx_buffer_size / nb_tcs);
3827 : 0 : uint32_t rxpbsize = pbsize << 10;
3828 : :
3829 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++)
3830 : 0 : wr32(hw, TXGBE_PBRXSIZE(i), rxpbsize);
3831 : :
3832 : : /* zero alloc all unused TCs */
3833 [ # # ]: 0 : for (; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++)
3834 : 0 : wr32(hw, TXGBE_PBRXSIZE(i), 0);
3835 : : }
3836 [ # # ]: 0 : if (config_dcb_tx) {
3837 : : /* Only support an equally distributed
3838 : : * Tx packet buffer strategy.
3839 : : */
3840 : 0 : uint32_t txpktsize = TXGBE_PBTXSIZE_MAX / nb_tcs;
3841 : 0 : uint32_t txpbthresh = (txpktsize / DCB_TX_PB) -
3842 : : TXGBE_TXPKT_SIZE_MAX;
3843 : :
3844 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
3845 : 0 : wr32(hw, TXGBE_PBTXSIZE(i), txpktsize);
3846 : 0 : wr32(hw, TXGBE_PBTXDMATH(i), txpbthresh);
3847 : : }
3848 : : /* Clear unused TCs, if any, to zero buffer size*/
3849 [ # # ]: 0 : for (; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
3850 : 0 : wr32(hw, TXGBE_PBTXSIZE(i), 0);
3851 : 0 : wr32(hw, TXGBE_PBTXDMATH(i), 0);
3852 : : }
3853 : : }
3854 : :
3855 : : /*Calculates traffic class credits*/
3856 : 0 : txgbe_dcb_calculate_tc_credits_cee(hw, dcb_config, max_frame,
3857 : : TXGBE_DCB_TX_CONFIG);
3858 : 0 : txgbe_dcb_calculate_tc_credits_cee(hw, dcb_config, max_frame,
3859 : : TXGBE_DCB_RX_CONFIG);
3860 : :
3861 [ # # ]: 0 : if (config_dcb_rx) {
3862 : : /* Unpack CEE standard containers */
3863 : 0 : txgbe_dcb_unpack_refill_cee(dcb_config,
3864 : : TXGBE_DCB_RX_CONFIG, refill);
3865 : 0 : txgbe_dcb_unpack_max_cee(dcb_config, max);
3866 : 0 : txgbe_dcb_unpack_bwgid_cee(dcb_config,
3867 : : TXGBE_DCB_RX_CONFIG, bwgid);
3868 : 0 : txgbe_dcb_unpack_tsa_cee(dcb_config,
3869 : : TXGBE_DCB_RX_CONFIG, tsa);
3870 : : /* Configure PG(ETS) RX */
3871 : : txgbe_dcb_hw_arbite_rx_config(hw, refill, max, bwgid, tsa, map);
3872 : : }
3873 : :
3874 [ # # ]: 0 : if (config_dcb_tx) {
3875 : : /* Unpack CEE standard containers */
3876 : 0 : txgbe_dcb_unpack_refill_cee(dcb_config,
3877 : : TXGBE_DCB_TX_CONFIG, refill);
3878 : 0 : txgbe_dcb_unpack_max_cee(dcb_config, max);
3879 : 0 : txgbe_dcb_unpack_bwgid_cee(dcb_config,
3880 : : TXGBE_DCB_TX_CONFIG, bwgid);
3881 : 0 : txgbe_dcb_unpack_tsa_cee(dcb_config,
3882 : : TXGBE_DCB_TX_CONFIG, tsa);
3883 : : /* Configure PG(ETS) TX */
3884 : 0 : txgbe_dcb_hw_arbite_tx_config(hw, refill, max, bwgid, tsa, map);
3885 : : }
3886 : :
3887 : : /* Configure queue statistics registers */
3888 : 0 : txgbe_dcb_config_tc_stats_raptor(hw, dcb_config);
3889 : :
3890 : : /* Check if the PFC is supported */
3891 [ # # ]: 0 : if (dev->data->dev_conf.dcb_capability_en & RTE_ETH_DCB_PFC_SUPPORT) {
3892 : 0 : pbsize = (uint16_t)(rx_buffer_size / nb_tcs);
3893 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
3894 : : /* If the TC count is 8,
3895 : : * and the default high_water is 48,
3896 : : * the low_water is 16 as default.
3897 : : */
3898 : 0 : hw->fc.high_water[i] = (pbsize * 3) / 4;
3899 : 0 : hw->fc.low_water[i] = pbsize / 4;
3900 : : /* Enable pfc for this TC */
3901 : : tc = &dcb_config->tc_config[i];
3902 : 0 : tc->pfc = txgbe_dcb_pfc_enabled;
3903 : : }
3904 : 0 : txgbe_dcb_unpack_pfc_cee(dcb_config, map, &pfc_en);
3905 [ # # ]: 0 : if (dcb_config->num_tcs.pfc_tcs == RTE_ETH_4_TCS)
3906 : 0 : pfc_en &= 0x0F;
3907 : 0 : ret = txgbe_dcb_config_pfc(hw, pfc_en, map);
3908 : : }
3909 : :
3910 : 0 : return ret;
3911 : : }
3912 : :
3913 : 0 : void txgbe_configure_pb(struct rte_eth_dev *dev)
3914 : : {
3915 : 0 : struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
3916 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3917 : :
3918 : : int hdrm;
3919 : 0 : int tc = dev_conf->rx_adv_conf.dcb_rx_conf.nb_tcs;
3920 : :
3921 : : /* Reserve 256KB(/512KB) rx buffer for fdir */
3922 : : hdrm = 256; /*KB*/
3923 : :
3924 : 0 : hw->mac.setup_pba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
3925 : 0 : }
3926 : :
3927 : 0 : void txgbe_configure_port(struct rte_eth_dev *dev)
3928 : : {
3929 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3930 : : int i = 0;
3931 : 0 : uint16_t tpids[8] = {RTE_ETHER_TYPE_VLAN, RTE_ETHER_TYPE_QINQ,
3932 : : 0x9100, 0x9200,
3933 : : 0x0000, 0x0000,
3934 : : 0x0000, 0x0000};
3935 : :
3936 : 0 : PMD_INIT_FUNC_TRACE();
3937 : :
3938 : : /* default outer vlan tpid */
3939 : : wr32(hw, TXGBE_EXTAG,
3940 : : TXGBE_EXTAG_ETAG(RTE_ETHER_TYPE_ETAG) |
3941 : : TXGBE_EXTAG_VLAN(RTE_ETHER_TYPE_QINQ));
3942 : :
3943 : : /* default inner vlan tpid */
3944 : : wr32m(hw, TXGBE_VLANCTL,
3945 : : TXGBE_VLANCTL_TPID_MASK,
3946 : : TXGBE_VLANCTL_TPID(RTE_ETHER_TYPE_VLAN));
3947 : : wr32m(hw, TXGBE_DMATXCTRL,
3948 : : TXGBE_DMATXCTRL_TPID_MASK,
3949 : : TXGBE_DMATXCTRL_TPID(RTE_ETHER_TYPE_VLAN));
3950 : :
3951 : : /* default vlan tpid filters */
3952 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3953 [ # # ]: 0 : wr32m(hw, TXGBE_TAGTPID(i / 2),
3954 : : (i % 2 ? TXGBE_TAGTPID_MSB_MASK
3955 : : : TXGBE_TAGTPID_LSB_MASK),
3956 [ # # ]: 0 : (i % 2 ? TXGBE_TAGTPID_MSB(tpids[i])
3957 : 0 : : TXGBE_TAGTPID_LSB(tpids[i])));
3958 : : }
3959 : :
3960 : : /* default vxlan port */
3961 : : wr32(hw, TXGBE_VXLANPORT, 4789);
3962 : 0 : }
3963 : :
3964 : : /**
3965 : : * txgbe_configure_dcb - Configure DCB Hardware
3966 : : * @dev: pointer to rte_eth_dev
3967 : : */
3968 : 0 : void txgbe_configure_dcb(struct rte_eth_dev *dev)
3969 : : {
3970 : 0 : struct txgbe_dcb_config *dcb_cfg = TXGBE_DEV_DCB_CONFIG(dev);
3971 : : struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
3972 : :
3973 : 0 : PMD_INIT_FUNC_TRACE();
3974 : :
3975 : : /* check support mq_mode for DCB */
3976 [ # # ]: 0 : if (dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_VMDQ_DCB &&
3977 [ # # ]: 0 : dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_DCB &&
3978 : : dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_DCB_RSS)
3979 : : return;
3980 : :
3981 [ # # ]: 0 : if (dev->data->nb_rx_queues > RTE_ETH_DCB_NUM_QUEUES)
3982 : : return;
3983 : :
3984 : : /** Configure DCB hardware **/
3985 : 0 : txgbe_dcb_hw_configure(dev, dcb_cfg);
3986 : : }
3987 : :
3988 : : /*
3989 : : * VMDq only support for 10 GbE NIC.
3990 : : */
3991 : : static void
3992 : 0 : txgbe_vmdq_rx_hw_configure(struct rte_eth_dev *dev)
3993 : : {
3994 : : struct rte_eth_vmdq_rx_conf *cfg;
3995 : : struct txgbe_hw *hw;
3996 : : enum rte_eth_nb_pools num_pools;
3997 : : uint32_t mrqc, vt_ctl, vlanctrl;
3998 : : uint32_t vmolr = 0;
3999 : : int i;
4000 : :
4001 : 0 : PMD_INIT_FUNC_TRACE();
4002 : 0 : hw = TXGBE_DEV_HW(dev);
4003 : : cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
4004 : 0 : num_pools = cfg->nb_queue_pools;
4005 : :
4006 : 0 : txgbe_rss_disable(dev);
4007 : :
4008 : : /* enable vmdq */
4009 : : mrqc = TXGBE_PORTCTL_NUMVT_64;
4010 : : wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK, mrqc);
4011 : :
4012 : : /* turn on virtualisation and set the default pool */
4013 : : vt_ctl = TXGBE_POOLCTL_RPLEN;
4014 [ # # ]: 0 : if (cfg->enable_default_pool)
4015 : 0 : vt_ctl |= TXGBE_POOLCTL_DEFPL(cfg->default_pool);
4016 : : else
4017 : : vt_ctl |= TXGBE_POOLCTL_DEFDSA;
4018 : :
4019 : : wr32(hw, TXGBE_POOLCTL, vt_ctl);
4020 : :
4021 [ # # ]: 0 : for (i = 0; i < (int)num_pools; i++) {
4022 : 0 : vmolr = txgbe_convert_vm_rx_mask_to_val(cfg->rx_mode, vmolr);
4023 : 0 : wr32(hw, TXGBE_POOLETHCTL(i), vmolr);
4024 : : }
4025 : :
4026 : : /* enable vlan filtering and allow all vlan tags through */
4027 : : vlanctrl = rd32(hw, TXGBE_VLANCTL);
4028 : 0 : vlanctrl |= TXGBE_VLANCTL_VFE; /* enable vlan filters */
4029 : : wr32(hw, TXGBE_VLANCTL, vlanctrl);
4030 : :
4031 : : /* enable all vlan filters */
4032 [ # # ]: 0 : for (i = 0; i < NUM_VFTA_REGISTERS; i++)
4033 : 0 : wr32(hw, TXGBE_VLANTBL(i), UINT32_MAX);
4034 : :
4035 : : /* pool enabling for receive - 64 */
4036 : : wr32(hw, TXGBE_POOLRXENA(0), UINT32_MAX);
4037 [ # # ]: 0 : if (num_pools == RTE_ETH_64_POOLS)
4038 : : wr32(hw, TXGBE_POOLRXENA(1), UINT32_MAX);
4039 : :
4040 : : /*
4041 : : * allow pools to read specific mac addresses
4042 : : * In this case, all pools should be able to read from mac addr 0
4043 : : */
4044 : : wr32(hw, TXGBE_ETHADDRIDX, 0);
4045 : : wr32(hw, TXGBE_ETHADDRASSL, 0xFFFFFFFF);
4046 : : wr32(hw, TXGBE_ETHADDRASSH, 0xFFFFFFFF);
4047 : :
4048 : : /* set up filters for vlan tags as configured */
4049 [ # # ]: 0 : for (i = 0; i < cfg->nb_pool_maps; i++) {
4050 : : /* set vlan id in VF register and set the valid bit */
4051 : 0 : wr32(hw, TXGBE_PSRVLANIDX, i);
4052 : 0 : wr32(hw, TXGBE_PSRVLAN, (TXGBE_PSRVLAN_EA |
4053 : 0 : TXGBE_PSRVLAN_VID(cfg->pool_map[i].vlan_id)));
4054 : : /*
4055 : : * Put the allowed pools in VFB reg. As we only have 16 or 64
4056 : : * pools, we only need to use the first half of the register
4057 : : * i.e. bits 0-31
4058 : : */
4059 [ # # ]: 0 : if (((cfg->pool_map[i].pools >> 32) & UINT32_MAX) == 0)
4060 : 0 : wr32(hw, TXGBE_PSRVLANPLM(0),
4061 : : (cfg->pool_map[i].pools & UINT32_MAX));
4062 : : else
4063 : 0 : wr32(hw, TXGBE_PSRVLANPLM(1),
4064 : : ((cfg->pool_map[i].pools >> 32) & UINT32_MAX));
4065 : : }
4066 : :
4067 : : /* Tx General Switch Control Enables VMDQ loopback */
4068 [ # # ]: 0 : if (cfg->enable_loop_back) {
4069 : : wr32(hw, TXGBE_PSRCTL, TXGBE_PSRCTL_LBENA);
4070 [ # # ]: 0 : for (i = 0; i < 64; i++)
4071 : 0 : wr32m(hw, TXGBE_POOLETHCTL(i),
4072 : : TXGBE_POOLETHCTL_LLB, TXGBE_POOLETHCTL_LLB);
4073 : : }
4074 : :
4075 : : txgbe_flush(hw);
4076 : 0 : }
4077 : :
4078 : : /*
4079 : : * txgbe_vmdq_tx_hw_configure - Configure general VMDq TX parameters
4080 : : * @hw: pointer to hardware structure
4081 : : */
4082 : : static void
4083 : 0 : txgbe_vmdq_tx_hw_configure(struct txgbe_hw *hw)
4084 : : {
4085 : : uint32_t reg;
4086 : : uint32_t q;
4087 : :
4088 : 0 : PMD_INIT_FUNC_TRACE();
4089 : : /*PF VF Transmit Enable*/
4090 : : wr32(hw, TXGBE_POOLTXENA(0), UINT32_MAX);
4091 : : wr32(hw, TXGBE_POOLTXENA(1), UINT32_MAX);
4092 : :
4093 : : /* Disable the Tx desc arbiter */
4094 : : reg = rd32(hw, TXGBE_ARBTXCTL);
4095 : 0 : reg |= TXGBE_ARBTXCTL_DIA;
4096 : : wr32(hw, TXGBE_ARBTXCTL, reg);
4097 : :
4098 : : wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK,
4099 : : TXGBE_PORTCTL_NUMVT_64);
4100 : :
4101 : : /* Disable drop for all queues */
4102 [ # # ]: 0 : for (q = 0; q < 128; q++) {
4103 : 0 : u32 val = 1 << (q % 32);
4104 : 0 : wr32m(hw, TXGBE_QPRXDROP(q / 32), val, val);
4105 : : }
4106 : :
4107 : : /* Enable the Tx desc arbiter */
4108 : : reg = rd32(hw, TXGBE_ARBTXCTL);
4109 : 0 : reg &= ~TXGBE_ARBTXCTL_DIA;
4110 : : wr32(hw, TXGBE_ARBTXCTL, reg);
4111 : :
4112 : : txgbe_flush(hw);
4113 : 0 : }
4114 : :
4115 : : static int __rte_cold
4116 : 0 : txgbe_alloc_rx_queue_mbufs(struct txgbe_rx_queue *rxq)
4117 : : {
4118 : 0 : struct txgbe_rx_entry *rxe = rxq->sw_ring;
4119 : : uint64_t dma_addr;
4120 : : unsigned int i;
4121 : :
4122 : : /* Initialize software ring entries */
4123 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
4124 : : volatile struct txgbe_rx_desc *rxd;
4125 : 0 : struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
4126 : :
4127 [ # # ]: 0 : if (mbuf == NULL) {
4128 : 0 : PMD_INIT_LOG(ERR, "RX mbuf alloc failed queue_id=%u",
4129 : : (unsigned int)rxq->queue_id);
4130 : 0 : return -ENOMEM;
4131 : : }
4132 : :
4133 : 0 : mbuf->data_off = RTE_PKTMBUF_HEADROOM;
4134 : 0 : mbuf->port = rxq->port_id;
4135 : :
4136 : : dma_addr =
4137 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
4138 : 0 : rxd = &rxq->rx_ring[i];
4139 : 0 : TXGBE_RXD_HDRADDR(rxd, 0);
4140 : 0 : TXGBE_RXD_PKTADDR(rxd, dma_addr);
4141 : 0 : rxe[i].mbuf = mbuf;
4142 : : }
4143 : :
4144 : : return 0;
4145 : : }
4146 : :
4147 : : static int
4148 : 0 : txgbe_config_vf_rss(struct rte_eth_dev *dev)
4149 : : {
4150 : : struct txgbe_hw *hw;
4151 : : uint32_t mrqc;
4152 : :
4153 : 0 : txgbe_rss_configure(dev);
4154 : :
4155 : 0 : hw = TXGBE_DEV_HW(dev);
4156 : :
4157 : : /* enable VF RSS */
4158 : : mrqc = rd32(hw, TXGBE_PORTCTL);
4159 : 0 : mrqc &= ~(TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK);
4160 [ # # # ]: 0 : switch (RTE_ETH_DEV_SRIOV(dev).active) {
4161 : 0 : case RTE_ETH_64_POOLS:
4162 : 0 : mrqc |= TXGBE_PORTCTL_NUMVT_64;
4163 : 0 : break;
4164 : :
4165 : 0 : case RTE_ETH_32_POOLS:
4166 : 0 : mrqc |= TXGBE_PORTCTL_NUMVT_32;
4167 : 0 : break;
4168 : :
4169 : 0 : default:
4170 : 0 : PMD_INIT_LOG(ERR, "Invalid pool number in IOV mode with VMDQ RSS");
4171 : 0 : return -EINVAL;
4172 : : }
4173 : :
4174 : : wr32(hw, TXGBE_PORTCTL, mrqc);
4175 : :
4176 : 0 : return 0;
4177 : : }
4178 : :
4179 : : static int
4180 : 0 : txgbe_config_vf_default(struct rte_eth_dev *dev)
4181 : : {
4182 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4183 : : uint32_t mrqc;
4184 : :
4185 : : mrqc = rd32(hw, TXGBE_PORTCTL);
4186 : 0 : mrqc &= ~(TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK);
4187 [ # # # # ]: 0 : switch (RTE_ETH_DEV_SRIOV(dev).active) {
4188 : 0 : case RTE_ETH_64_POOLS:
4189 : 0 : mrqc |= TXGBE_PORTCTL_NUMVT_64;
4190 : 0 : break;
4191 : :
4192 : 0 : case RTE_ETH_32_POOLS:
4193 : 0 : mrqc |= TXGBE_PORTCTL_NUMVT_32;
4194 : 0 : break;
4195 : :
4196 : 0 : case RTE_ETH_16_POOLS:
4197 : 0 : mrqc |= TXGBE_PORTCTL_NUMVT_16;
4198 : 0 : break;
4199 : 0 : default:
4200 : 0 : PMD_INIT_LOG(ERR,
4201 : : "invalid pool number in IOV mode");
4202 : 0 : return 0;
4203 : : }
4204 : :
4205 : : wr32(hw, TXGBE_PORTCTL, mrqc);
4206 : :
4207 : 0 : return 0;
4208 : : }
4209 : :
4210 : : static int
4211 : 0 : txgbe_dev_mq_rx_configure(struct rte_eth_dev *dev)
4212 : : {
4213 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
4214 : : /*
4215 : : * SRIOV inactive scheme
4216 : : * any DCB/RSS w/o VMDq multi-queue setting
4217 : : */
4218 [ # # # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
4219 : 0 : case RTE_ETH_MQ_RX_RSS:
4220 : : case RTE_ETH_MQ_RX_DCB_RSS:
4221 : : case RTE_ETH_MQ_RX_VMDQ_RSS:
4222 : 0 : txgbe_rss_configure(dev);
4223 : 0 : break;
4224 : :
4225 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB:
4226 : 0 : txgbe_vmdq_dcb_configure(dev);
4227 : 0 : break;
4228 : :
4229 : 0 : case RTE_ETH_MQ_RX_VMDQ_ONLY:
4230 : 0 : txgbe_vmdq_rx_hw_configure(dev);
4231 : 0 : break;
4232 : :
4233 : 0 : case RTE_ETH_MQ_RX_NONE:
4234 : : default:
4235 : : /* if mq_mode is none, disable rss mode.*/
4236 : 0 : txgbe_rss_disable(dev);
4237 : 0 : break;
4238 : : }
4239 : : } else {
4240 : : /* SRIOV active scheme
4241 : : * Support RSS together with SRIOV.
4242 : : */
4243 [ # # # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
4244 : 0 : case RTE_ETH_MQ_RX_RSS:
4245 : : case RTE_ETH_MQ_RX_VMDQ_RSS:
4246 : 0 : txgbe_config_vf_rss(dev);
4247 : 0 : break;
4248 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB:
4249 : : case RTE_ETH_MQ_RX_DCB:
4250 : : /* In SRIOV, the configuration is the same as VMDq case */
4251 : 0 : txgbe_vmdq_dcb_configure(dev);
4252 : 0 : break;
4253 : : /* DCB/RSS together with SRIOV is not supported */
4254 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB_RSS:
4255 : : case RTE_ETH_MQ_RX_DCB_RSS:
4256 : 0 : PMD_INIT_LOG(ERR,
4257 : : "Could not support DCB/RSS with VMDq & SRIOV");
4258 : 0 : return -1;
4259 : 0 : default:
4260 : 0 : txgbe_config_vf_default(dev);
4261 : 0 : break;
4262 : : }
4263 : : }
4264 : :
4265 : : return 0;
4266 : : }
4267 : :
4268 : : static int
4269 : 0 : txgbe_dev_mq_tx_configure(struct rte_eth_dev *dev)
4270 : : {
4271 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4272 : : uint32_t mtqc;
4273 : : uint32_t rttdcs;
4274 : :
4275 : : /* disable arbiter */
4276 : : rttdcs = rd32(hw, TXGBE_ARBTXCTL);
4277 : 0 : rttdcs |= TXGBE_ARBTXCTL_DIA;
4278 : : wr32(hw, TXGBE_ARBTXCTL, rttdcs);
4279 : :
4280 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
4281 : : /*
4282 : : * SRIOV inactive scheme
4283 : : * any DCB w/o VMDq multi-queue setting
4284 : : */
4285 [ # # ]: 0 : if (dev->data->dev_conf.txmode.mq_mode == RTE_ETH_MQ_TX_VMDQ_ONLY)
4286 : 0 : txgbe_vmdq_tx_hw_configure(hw);
4287 : : else
4288 : : wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK, 0);
4289 : : } else {
4290 [ # # # # ]: 0 : switch (RTE_ETH_DEV_SRIOV(dev).active) {
4291 : : /*
4292 : : * SRIOV active scheme
4293 : : * FIXME if support DCB together with VMDq & SRIOV
4294 : : */
4295 : : case RTE_ETH_64_POOLS:
4296 : : mtqc = TXGBE_PORTCTL_NUMVT_64;
4297 : : break;
4298 : 0 : case RTE_ETH_32_POOLS:
4299 : : mtqc = TXGBE_PORTCTL_NUMVT_32;
4300 : 0 : break;
4301 : 0 : case RTE_ETH_16_POOLS:
4302 : : mtqc = TXGBE_PORTCTL_NUMVT_16;
4303 : 0 : break;
4304 : 0 : default:
4305 : : mtqc = 0;
4306 : 0 : PMD_INIT_LOG(ERR, "invalid pool number in IOV mode");
4307 : : }
4308 : : wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK, mtqc);
4309 : : }
4310 : :
4311 : : /* re-enable arbiter */
4312 : : rttdcs &= ~TXGBE_ARBTXCTL_DIA;
4313 : : wr32(hw, TXGBE_ARBTXCTL, rttdcs);
4314 : :
4315 : 0 : return 0;
4316 : : }
4317 : :
4318 : : /**
4319 : : * txgbe_get_rscctl_maxdesc
4320 : : *
4321 : : * @pool Memory pool of the Rx queue
4322 : : */
4323 : : static inline uint32_t
4324 : : txgbe_get_rscctl_maxdesc(struct rte_mempool *pool)
4325 : : {
4326 : : struct rte_pktmbuf_pool_private *mp_priv = rte_mempool_get_priv(pool);
4327 : :
4328 : 0 : uint16_t maxdesc =
4329 : 0 : RTE_IPV4_MAX_PKT_LEN /
4330 : 0 : (mp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM);
4331 : :
4332 : 0 : if (maxdesc >= 16)
4333 : : return TXGBE_RXCFG_RSCMAX_16;
4334 [ # # ]: 0 : else if (maxdesc >= 8)
4335 : : return TXGBE_RXCFG_RSCMAX_8;
4336 [ # # ]: 0 : else if (maxdesc >= 4)
4337 : : return TXGBE_RXCFG_RSCMAX_4;
4338 : : else
4339 : 0 : return TXGBE_RXCFG_RSCMAX_1;
4340 : : }
4341 : :
4342 : : /**
4343 : : * txgbe_set_rsc - configure RSC related port HW registers
4344 : : *
4345 : : * Configures the port's RSC related registers.
4346 : : *
4347 : : * @dev port handle
4348 : : *
4349 : : * Returns 0 in case of success or a non-zero error code
4350 : : */
4351 : : static int
4352 : 0 : txgbe_set_rsc(struct rte_eth_dev *dev)
4353 : : {
4354 : 0 : struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
4355 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
4356 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
4357 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4358 : 0 : struct rte_eth_dev_info dev_info = { 0 };
4359 : : bool rsc_capable = false;
4360 : : uint16_t i;
4361 : : uint32_t rdrxctl;
4362 : : uint32_t rfctl;
4363 : :
4364 : : /* Sanity check */
4365 : 0 : dev->dev_ops->dev_infos_get(dev, &dev_info);
4366 [ # # ]: 0 : if (dev_info.rx_offload_capa & RTE_ETH_RX_OFFLOAD_TCP_LRO)
4367 : : rsc_capable = true;
4368 : :
4369 [ # # ]: 0 : if (!rsc_capable && (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO)) {
4370 : 0 : PMD_INIT_LOG(CRIT, "LRO is requested on HW that doesn't "
4371 : : "support it");
4372 : 0 : return -EINVAL;
4373 : : }
4374 : :
4375 : : /* RSC global configuration */
4376 : :
4377 [ # # ]: 0 : if ((rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) &&
4378 : : (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO)) {
4379 : 0 : PMD_INIT_LOG(CRIT, "LRO can't be enabled when HW CRC "
4380 : : "is disabled");
4381 : 0 : return -EINVAL;
4382 : : }
4383 : :
4384 : : rfctl = rd32(hw, TXGBE_PSRCTL);
4385 [ # # # # ]: 0 : if (rsc_capable && (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO))
4386 : 0 : rfctl &= ~TXGBE_PSRCTL_RSCDIA;
4387 : : else
4388 : 0 : rfctl |= TXGBE_PSRCTL_RSCDIA;
4389 : : wr32(hw, TXGBE_PSRCTL, rfctl);
4390 : :
4391 : : /* If LRO hasn't been requested - we are done here. */
4392 [ # # ]: 0 : if (!(rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO))
4393 : : return 0;
4394 : :
4395 : : /* Set PSRCTL.RSCACK bit */
4396 : : rdrxctl = rd32(hw, TXGBE_PSRCTL);
4397 : 0 : rdrxctl |= TXGBE_PSRCTL_RSCACK;
4398 : : wr32(hw, TXGBE_PSRCTL, rdrxctl);
4399 : :
4400 : : /* Per-queue RSC configuration */
4401 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
4402 : 0 : struct txgbe_rx_queue *rxq = dev->data->rx_queues[i];
4403 : : uint32_t srrctl =
4404 : 0 : rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
4405 : : uint32_t psrtype =
4406 : 0 : rd32(hw, TXGBE_POOLRSS(rxq->reg_idx));
4407 : :
4408 : : /*
4409 : : * txgbe PMD doesn't support header-split at the moment.
4410 : : */
4411 : : srrctl &= ~TXGBE_RXCFG_HDRLEN_MASK;
4412 : : srrctl |= TXGBE_RXCFG_HDRLEN(128);
4413 : :
4414 : : /*
4415 : : * TODO: Consider setting the Receive Descriptor Minimum
4416 : : * Threshold Size for an RSC case. This is not an obviously
4417 : : * beneficiary option but the one worth considering...
4418 : : */
4419 : :
4420 : : srrctl |= TXGBE_RXCFG_RSCENA;
4421 : 0 : srrctl &= ~TXGBE_RXCFG_RSCMAX_MASK;
4422 [ # # ]: 0 : srrctl |= txgbe_get_rscctl_maxdesc(rxq->mb_pool);
4423 : 0 : psrtype |= TXGBE_POOLRSS_L4HDR;
4424 : :
4425 : 0 : wr32(hw, TXGBE_RXCFG(rxq->reg_idx), srrctl);
4426 : 0 : wr32(hw, TXGBE_POOLRSS(rxq->reg_idx), psrtype);
4427 : :
4428 : : /*
4429 : : * RSC: Set ITR interval corresponding to 2K ints/s.
4430 : : *
4431 : : * Full-sized RSC aggregations for a 10Gb/s link will
4432 : : * arrive at about 20K aggregation/s rate.
4433 : : *
4434 : : * 2K inst/s rate will make only 10% of the
4435 : : * aggregations to be closed due to the interrupt timer
4436 : : * expiration for a streaming at wire-speed case.
4437 : : *
4438 : : * For a sparse streaming case this setting will yield
4439 : : * at most 500us latency for a single RSC aggregation.
4440 : : */
4441 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
4442 : 0 : uint32_t eitr = rd32(hw, TXGBE_ITR(rxq->reg_idx));
4443 : :
4444 : 0 : eitr &= ~TXGBE_ITR_IVAL_MASK;
4445 : : eitr |= TXGBE_ITR_IVAL_10G(TXGBE_QUEUE_ITR_INTERVAL_DEFAULT);
4446 : 0 : eitr |= TXGBE_ITR_WRDSA;
4447 : 0 : wr32(hw, TXGBE_ITR(rxq->reg_idx), eitr);
4448 : :
4449 : : /*
4450 : : * RSC requires the mapping of the queue to the
4451 : : * interrupt vector.
4452 : : */
4453 : 0 : txgbe_set_ivar_map(hw, 0, rxq->reg_idx, i);
4454 : : }
4455 : : }
4456 : :
4457 : 0 : dev->data->lro = 1;
4458 : :
4459 : 0 : PMD_INIT_LOG(DEBUG, "enabling LRO mode");
4460 : :
4461 : 0 : return 0;
4462 : : }
4463 : :
4464 : : void __rte_cold
4465 : 0 : txgbe_set_rx_function(struct rte_eth_dev *dev)
4466 : : {
4467 : : uint16_t i, rx_using_sse;
4468 : 0 : struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
4469 : :
4470 : : /*
4471 : : * In order to allow Vector Rx there are a few configuration
4472 : : * conditions to be met and Rx Bulk Allocation should be allowed.
4473 : : */
4474 [ # # ]: 0 : if (txgbe_rx_vec_dev_conf_condition_check(dev) ||
4475 [ # # # # ]: 0 : !adapter->rx_bulk_alloc_allowed ||
4476 : 0 : rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128) {
4477 : 0 : PMD_INIT_LOG(DEBUG, "Port[%d] doesn't meet Vector Rx "
4478 : : "preconditions",
4479 : : dev->data->port_id);
4480 : :
4481 : 0 : adapter->rx_vec_allowed = false;
4482 : : }
4483 : :
4484 : : /*
4485 : : * Initialize the appropriate LRO callback.
4486 : : *
4487 : : * If all queues satisfy the bulk allocation preconditions
4488 : : * (adapter->rx_bulk_alloc_allowed is TRUE) then we may use
4489 : : * bulk allocation. Otherwise use a single allocation version.
4490 : : */
4491 [ # # ]: 0 : if (dev->data->lro) {
4492 [ # # ]: 0 : if (adapter->rx_bulk_alloc_allowed) {
4493 : 0 : PMD_INIT_LOG(DEBUG, "LRO is requested. Using a bulk "
4494 : : "allocation version");
4495 : 0 : dev->rx_pkt_burst = txgbe_recv_pkts_lro_bulk_alloc;
4496 : : } else {
4497 : 0 : PMD_INIT_LOG(DEBUG, "LRO is requested. Using a single "
4498 : : "allocation version");
4499 : 0 : dev->rx_pkt_burst = txgbe_recv_pkts_lro_single_alloc;
4500 : : }
4501 [ # # ]: 0 : } else if (dev->data->scattered_rx) {
4502 : : /*
4503 : : * Set the non-LRO scattered callback: there are bulk and
4504 : : * single allocation versions.
4505 : : */
4506 [ # # ]: 0 : if (adapter->rx_vec_allowed) {
4507 : 0 : PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx "
4508 : : "callback (port=%d).",
4509 : : dev->data->port_id);
4510 : 0 : dev->rx_pkt_burst = txgbe_recv_scattered_pkts_vec;
4511 [ # # ]: 0 : } else if (adapter->rx_bulk_alloc_allowed) {
4512 : 0 : PMD_INIT_LOG(DEBUG, "Using a Scattered with bulk "
4513 : : "allocation callback (port=%d).",
4514 : : dev->data->port_id);
4515 : 0 : dev->rx_pkt_burst = txgbe_recv_pkts_lro_bulk_alloc;
4516 : : } else {
4517 : 0 : PMD_INIT_LOG(DEBUG, "Using Regular (non-vector, "
4518 : : "single allocation) "
4519 : : "Scattered Rx callback "
4520 : : "(port=%d).",
4521 : : dev->data->port_id);
4522 : :
4523 : 0 : dev->rx_pkt_burst = txgbe_recv_pkts_lro_single_alloc;
4524 : : }
4525 : : /*
4526 : : * Below we set "simple" callbacks according to port/queues parameters.
4527 : : * If parameters allow we are going to choose between the following
4528 : : * callbacks:
4529 : : * - Vector
4530 : : * - Bulk Allocation
4531 : : * - Single buffer allocation (the simplest one)
4532 : : */
4533 [ # # ]: 0 : } else if (adapter->rx_vec_allowed) {
4534 : 0 : PMD_INIT_LOG(DEBUG, "Vector rx enabled, please make sure RX "
4535 : : "burst size no less than %d (port=%d).",
4536 : : RTE_TXGBE_DESCS_PER_LOOP,
4537 : : dev->data->port_id);
4538 : 0 : dev->rx_pkt_burst = txgbe_recv_pkts_vec;
4539 [ # # ]: 0 : } else if (adapter->rx_bulk_alloc_allowed) {
4540 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
4541 : : "satisfied. Rx Burst Bulk Alloc function "
4542 : : "will be used on port=%d.",
4543 : : dev->data->port_id);
4544 : :
4545 : 0 : dev->rx_pkt_burst = txgbe_recv_pkts_bulk_alloc;
4546 : : } else {
4547 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are not "
4548 : : "satisfied, or Scattered Rx is requested "
4549 : : "(port=%d).",
4550 : : dev->data->port_id);
4551 : :
4552 : 0 : dev->rx_pkt_burst = txgbe_recv_pkts;
4553 : : }
4554 : :
4555 [ # # # # ]: 0 : rx_using_sse = (dev->rx_pkt_burst == txgbe_recv_scattered_pkts_vec ||
4556 : : dev->rx_pkt_burst == txgbe_recv_pkts_vec);
4557 : :
4558 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
4559 : 0 : struct txgbe_rx_queue *rxq = dev->data->rx_queues[i];
4560 : :
4561 : 0 : rxq->rx_using_sse = rx_using_sse;
4562 : : #ifdef RTE_LIB_SECURITY
4563 : 0 : rxq->using_ipsec = !!(dev->data->dev_conf.rxmode.offloads &
4564 : : RTE_ETH_RX_OFFLOAD_SECURITY);
4565 : : #endif
4566 : : }
4567 : 0 : }
4568 : :
4569 : : /*
4570 : : * Initializes Receive Unit.
4571 : : */
4572 : : int __rte_cold
4573 : 0 : txgbe_dev_rx_init(struct rte_eth_dev *dev)
4574 : : {
4575 : : struct txgbe_hw *hw;
4576 : : struct txgbe_rx_queue *rxq;
4577 : : uint64_t bus_addr;
4578 : : uint32_t fctrl;
4579 : : uint32_t hlreg0;
4580 : : uint32_t srrctl;
4581 : : uint32_t rdrxctl;
4582 : : uint32_t rxcsum;
4583 : : uint16_t buf_size;
4584 : : uint16_t i;
4585 : 0 : struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
4586 : : int rc;
4587 : :
4588 : 0 : PMD_INIT_FUNC_TRACE();
4589 : 0 : hw = TXGBE_DEV_HW(dev);
4590 : :
4591 : : /*
4592 : : * Make sure receives are disabled while setting
4593 : : * up the RX context (registers, descriptor rings, etc.).
4594 : : */
4595 : : wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_ENA, 0);
4596 : : wr32m(hw, TXGBE_PBRXCTL, TXGBE_PBRXCTL_ENA, 0);
4597 : :
4598 : : /* Enable receipt of broadcasted frames */
4599 : : fctrl = rd32(hw, TXGBE_PSRCTL);
4600 : 0 : fctrl |= TXGBE_PSRCTL_BCA;
4601 : : wr32(hw, TXGBE_PSRCTL, fctrl);
4602 : :
4603 : : /*
4604 : : * Configure CRC stripping, if any.
4605 : : */
4606 : : hlreg0 = rd32(hw, TXGBE_SECRXCTL);
4607 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
4608 : 0 : hlreg0 &= ~TXGBE_SECRXCTL_CRCSTRIP;
4609 : : else
4610 : 0 : hlreg0 |= TXGBE_SECRXCTL_CRCSTRIP;
4611 : : wr32(hw, TXGBE_SECRXCTL, hlreg0);
4612 : :
4613 : : /*
4614 : : * Configure jumbo frame support, if any.
4615 : : */
4616 : 0 : wr32m(hw, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK,
4617 : 0 : TXGBE_FRMSZ_MAX(dev->data->mtu + TXGBE_ETH_OVERHEAD));
4618 : :
4619 : : /*
4620 : : * If loopback mode is configured, set LPBK bit.
4621 : : */
4622 : : hlreg0 = rd32(hw, TXGBE_PSRCTL);
4623 [ # # ]: 0 : if (txgbe_is_pf(hw) &&
4624 [ # # ]: 0 : dev->data->dev_conf.lpbk_mode)
4625 : 0 : hlreg0 |= TXGBE_PSRCTL_LBENA;
4626 : : else
4627 : 0 : hlreg0 &= ~TXGBE_PSRCTL_LBENA;
4628 : :
4629 : : wr32(hw, TXGBE_PSRCTL, hlreg0);
4630 : :
4631 : : /*
4632 : : * Assume no header split and no VLAN strip support
4633 : : * on any Rx queue first .
4634 : : */
4635 : 0 : rx_conf->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
4636 : :
4637 : : /* Setup RX queues */
4638 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
4639 : 0 : rxq = dev->data->rx_queues[i];
4640 : :
4641 : : /*
4642 : : * Reset crc_len in case it was changed after queue setup by a
4643 : : * call to configure.
4644 : : */
4645 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
4646 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
4647 : : else
4648 : 0 : rxq->crc_len = 0;
4649 : :
4650 : : /* Setup the Base and Length of the Rx Descriptor Rings */
4651 : 0 : bus_addr = rxq->rx_ring_phys_addr;
4652 : 0 : wr32(hw, TXGBE_RXBAL(rxq->reg_idx),
4653 : : (uint32_t)(bus_addr & BIT_MASK32));
4654 : 0 : wr32(hw, TXGBE_RXBAH(rxq->reg_idx),
4655 : 0 : (uint32_t)(bus_addr >> 32));
4656 : 0 : wr32(hw, TXGBE_RXRP(rxq->reg_idx), 0);
4657 : 0 : wr32(hw, TXGBE_RXWP(rxq->reg_idx), 0);
4658 : :
4659 [ # # ]: 0 : srrctl = TXGBE_RXCFG_RNGLEN(rxq->nb_rx_desc);
4660 : :
4661 : : /* Set if packets are dropped when no descriptors available */
4662 [ # # ]: 0 : if (rxq->drop_en)
4663 : 0 : srrctl |= TXGBE_RXCFG_DROP;
4664 : :
4665 : : /*
4666 : : * Configure the RX buffer size in the PKTLEN field of
4667 : : * the RXCFG register of the queue.
4668 : : * The value is in 1 KB resolution. Valid values can be from
4669 : : * 1 KB to 16 KB.
4670 : : */
4671 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
4672 : : RTE_PKTMBUF_HEADROOM);
4673 : 0 : buf_size = ROUND_DOWN(buf_size, 0x1 << 10);
4674 [ # # ]: 0 : srrctl |= TXGBE_RXCFG_PKTLEN(buf_size);
4675 : :
4676 [ # # ]: 0 : if ((hw->mac.type == txgbe_mac_aml ||
4677 [ # # ]: 0 : hw->mac.type == txgbe_mac_aml40) && hw->devarg.rx_desc_merge == 1) {
4678 : 0 : srrctl |= TXGBE_RXCFG_DESC_MERGE;
4679 : :
4680 : : wr32(hw, TXGBE_RDM_DCACHE_CTL, TXGBE_RDM_DCACHE_CTL_EN);
4681 : : wr32m(hw, TXGBE_RDM_RSC_CTL, TXGBE_RDM_RSC_CTL_FREE_CTL,
4682 : : TXGBE_RDM_RSC_CTL_FREE_CTL);
4683 : : wr32m(hw, TXGBE_RDM_RSC_CTL, TXGBE_RDM_RSC_CTL_FREE_CNT_DIS,
4684 : : ~TXGBE_RDM_RSC_CTL_FREE_CNT_DIS);
4685 : : }
4686 : :
4687 : 0 : wr32(hw, TXGBE_RXCFG(rxq->reg_idx), srrctl);
4688 : :
4689 : : /* It adds dual VLAN length for supporting dual VLAN */
4690 : 0 : if (dev->data->mtu + TXGBE_ETH_OVERHEAD +
4691 [ # # ]: 0 : 2 * RTE_VLAN_HLEN > buf_size)
4692 : 0 : dev->data->scattered_rx = 1;
4693 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
4694 : 0 : rx_conf->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
4695 : : }
4696 : :
4697 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_SCATTER)
4698 : 0 : dev->data->scattered_rx = 1;
4699 : :
4700 : : /*
4701 : : * Device configured with multiple RX queues.
4702 : : */
4703 : 0 : txgbe_dev_mq_rx_configure(dev);
4704 : :
4705 : : /*
4706 : : * Setup the Checksum Register.
4707 : : * Disable Full-Packet Checksum which is mutually exclusive with RSS.
4708 : : * Enable IP/L4 checksum computation by hardware if requested to do so.
4709 : : */
4710 : : rxcsum = rd32(hw, TXGBE_PSRCTL);
4711 : : rxcsum |= TXGBE_PSRCTL_PCSD;
4712 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM)
4713 : 0 : rxcsum |= TXGBE_PSRCTL_L4CSUM;
4714 : : else
4715 : 0 : rxcsum &= ~TXGBE_PSRCTL_L4CSUM;
4716 : :
4717 : : wr32(hw, TXGBE_PSRCTL, rxcsum);
4718 : :
4719 [ # # ]: 0 : if (txgbe_is_pf(hw)) {
4720 : : rdrxctl = rd32(hw, TXGBE_SECRXCTL);
4721 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
4722 : 0 : rdrxctl &= ~TXGBE_SECRXCTL_CRCSTRIP;
4723 : : else
4724 : 0 : rdrxctl |= TXGBE_SECRXCTL_CRCSTRIP;
4725 : : wr32(hw, TXGBE_SECRXCTL, rdrxctl);
4726 : : }
4727 : :
4728 : 0 : rc = txgbe_set_rsc(dev);
4729 [ # # ]: 0 : if (rc)
4730 : : return rc;
4731 : :
4732 : 0 : txgbe_set_rx_function(dev);
4733 : :
4734 : 0 : return 0;
4735 : : }
4736 : :
4737 : : /*
4738 : : * Initializes Transmit Unit.
4739 : : */
4740 : : void __rte_cold
4741 : 0 : txgbe_dev_tx_init(struct rte_eth_dev *dev)
4742 : : {
4743 : : struct txgbe_hw *hw;
4744 : : struct txgbe_tx_queue *txq;
4745 : : uint64_t bus_addr;
4746 : : uint16_t i;
4747 : :
4748 : 0 : PMD_INIT_FUNC_TRACE();
4749 : 0 : hw = TXGBE_DEV_HW(dev);
4750 : :
4751 : : /* Setup the Base and Length of the Tx Descriptor Rings */
4752 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
4753 : 0 : txq = dev->data->tx_queues[i];
4754 : :
4755 : 0 : bus_addr = txq->tx_ring_phys_addr;
4756 : 0 : wr32(hw, TXGBE_TXBAL(txq->reg_idx),
4757 : : (uint32_t)(bus_addr & BIT_MASK32));
4758 : 0 : wr32(hw, TXGBE_TXBAH(txq->reg_idx),
4759 : 0 : (uint32_t)(bus_addr >> 32));
4760 : 0 : wr32m(hw, TXGBE_TXCFG(txq->reg_idx), TXGBE_TXCFG_BUFLEN_MASK,
4761 [ # # ]: 0 : TXGBE_TXCFG_BUFLEN(txq->nb_tx_desc));
4762 : : /* Setup the HW Tx Head and TX Tail descriptor pointers */
4763 : 0 : wr32(hw, TXGBE_TXRP(txq->reg_idx), 0);
4764 : 0 : wr32(hw, TXGBE_TXWP(txq->reg_idx), 0);
4765 : :
4766 : : #ifdef RTE_LIB_SECURITY
4767 [ # # ]: 0 : if (!txq->using_ipsec)
4768 : : #endif
4769 : 0 : wr32m(hw, TXGBE_TDM_DESC_CHK(txq->reg_idx / 32),
4770 : 0 : RTE_BIT32(txq->reg_idx % 32), RTE_BIT32(txq->reg_idx % 32));
4771 : :
4772 [ # # ]: 0 : if (txq->headwb_mem) {
4773 : : uint32_t txdctl;
4774 : :
4775 : 0 : wr32(hw, TXGBE_PX_TR_HEAD_ADDRL(txq->reg_idx),
4776 : 0 : (uint32_t)(txq->headwb_dma & BIT_MASK32));
4777 : 0 : wr32(hw, TXGBE_PX_TR_HEAD_ADDRH(txq->reg_idx),
4778 : 0 : (uint32_t)(txq->headwb_dma >> 32));
4779 [ # # ]: 0 : if (txq->headwb_size == 16)
4780 : : txdctl = TXGBE_PX_TR_CFG_HEAD_WB |
4781 : : TXGBE_PX_TR_CFG_HEAD_WB_64BYTE;
4782 : : else
4783 : : txdctl = TXGBE_PX_TR_CFG_HEAD_WB;
4784 : 0 : wr32m(hw, TXGBE_TXCFG(txq->reg_idx),
4785 : : TXGBE_PX_TR_CFG_HEAD_WB_MASK, txdctl);
4786 : : }
4787 : : }
4788 : :
4789 : : /* Device configured with multiple TX queues. */
4790 : 0 : txgbe_dev_mq_tx_configure(dev);
4791 : 0 : }
4792 : :
4793 : : /*
4794 : : * Set up link loopback mode Tx->Rx.
4795 : : */
4796 : : static inline void __rte_cold
4797 : 0 : txgbe_setup_loopback_link_raptor(struct txgbe_hw *hw)
4798 : : {
4799 : 0 : PMD_INIT_FUNC_TRACE();
4800 : :
4801 : : wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_LB, TXGBE_MACRXCFG_LB);
4802 : :
4803 : : msec_delay(50);
4804 : 0 : }
4805 : :
4806 : : /*
4807 : : * Start Transmit and Receive Units.
4808 : : */
4809 : : int __rte_cold
4810 : 0 : txgbe_dev_rxtx_start(struct rte_eth_dev *dev)
4811 : : {
4812 : : struct txgbe_hw *hw;
4813 : : struct txgbe_tx_queue *txq;
4814 : : struct txgbe_rx_queue *rxq;
4815 : : uint32_t dmatxctl;
4816 : : uint32_t rxctrl;
4817 : : uint16_t i;
4818 : : int ret = 0;
4819 : :
4820 : 0 : PMD_INIT_FUNC_TRACE();
4821 : 0 : hw = TXGBE_DEV_HW(dev);
4822 : :
4823 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
4824 : 0 : txq = dev->data->tx_queues[i];
4825 : : /* Setup Transmit Threshold Registers */
4826 [ # # ]: 0 : if (hw->mac.type == txgbe_mac_aml || hw->mac.type == txgbe_mac_aml40)
4827 : 0 : wr32m(hw, TXGBE_TXCFG(txq->reg_idx),
4828 : : TXGBE_TXCFG_HTHRESH_MASK |
4829 : : TXGBE_TXCFG_WTHRESH_MASK_AML,
4830 : 0 : TXGBE_TXCFG_HTHRESH(txq->hthresh) |
4831 : 0 : TXGBE_TXCFG_WTHRESH_AML(txq->wthresh));
4832 : : else
4833 : 0 : wr32m(hw, TXGBE_TXCFG(txq->reg_idx),
4834 : : TXGBE_TXCFG_HTHRESH_MASK |
4835 : : TXGBE_TXCFG_WTHRESH_MASK,
4836 : 0 : TXGBE_TXCFG_HTHRESH(txq->hthresh) |
4837 : 0 : TXGBE_TXCFG_WTHRESH(txq->wthresh));
4838 : : }
4839 : :
4840 : : dmatxctl = rd32(hw, TXGBE_DMATXCTRL);
4841 : 0 : dmatxctl |= TXGBE_DMATXCTRL_ENA;
4842 : : wr32(hw, TXGBE_DMATXCTRL, dmatxctl);
4843 : :
4844 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
4845 : 0 : txq = dev->data->tx_queues[i];
4846 [ # # ]: 0 : if (!txq->tx_deferred_start) {
4847 : 0 : ret = txgbe_dev_tx_queue_start(dev, i);
4848 [ # # ]: 0 : if (ret < 0)
4849 : 0 : return ret;
4850 : : }
4851 : : }
4852 : :
4853 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
4854 : 0 : rxq = dev->data->rx_queues[i];
4855 [ # # ]: 0 : if (!rxq->rx_deferred_start) {
4856 : 0 : ret = txgbe_dev_rx_queue_start(dev, i);
4857 [ # # ]: 0 : if (ret < 0)
4858 : 0 : return ret;
4859 : : }
4860 : : }
4861 : :
4862 : : /* enable mac transmitter */
4863 [ # # ]: 0 : if (hw->mac.type == txgbe_mac_aml || hw->mac.type == txgbe_mac_aml40) {
4864 : : wr32(hw, TXGBE_SECTXCTL, 0);
4865 : : wr32m(hw, TXGBE_MACTXCFG,
4866 : : TXGBE_MACTXCFG_TXE, TXGBE_MACTXCFG_TXE);
4867 : : }
4868 : :
4869 : : /* Enable Receive engine */
4870 : : rxctrl = rd32(hw, TXGBE_PBRXCTL);
4871 : 0 : rxctrl |= TXGBE_PBRXCTL_ENA;
4872 : 0 : hw->mac.enable_rx_dma(hw, rxctrl);
4873 : :
4874 : : /* If loopback mode is enabled, set up the link accordingly */
4875 [ # # ]: 0 : if (txgbe_is_pf(hw) &&
4876 [ # # ]: 0 : dev->data->dev_conf.lpbk_mode)
4877 : 0 : txgbe_setup_loopback_link_raptor(hw);
4878 : :
4879 : : #ifdef RTE_LIB_SECURITY
4880 [ # # ]: 0 : if ((dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SECURITY) ||
4881 [ # # ]: 0 : (dev->data->dev_conf.txmode.offloads & RTE_ETH_TX_OFFLOAD_SECURITY)) {
4882 : 0 : ret = txgbe_crypto_enable_ipsec(dev);
4883 [ # # ]: 0 : if (ret != 0) {
4884 : 0 : PMD_DRV_LOG(ERR,
4885 : : "txgbe_crypto_enable_ipsec fails with %d.",
4886 : : ret);
4887 : 0 : return ret;
4888 : : }
4889 : : }
4890 : : #endif
4891 : :
4892 : : return 0;
4893 : : }
4894 : :
4895 : : void
4896 : 0 : txgbe_dev_save_rx_queue(struct txgbe_hw *hw, uint16_t rx_queue_id)
4897 : : {
4898 : 0 : u32 *reg = &hw->q_rx_regs[rx_queue_id * 8];
4899 : 0 : *(reg++) = rd32(hw, TXGBE_RXBAL(rx_queue_id));
4900 : 0 : *(reg++) = rd32(hw, TXGBE_RXBAH(rx_queue_id));
4901 : 0 : *(reg++) = rd32(hw, TXGBE_RXCFG(rx_queue_id));
4902 : 0 : }
4903 : :
4904 : : void
4905 : 0 : txgbe_dev_store_rx_queue(struct txgbe_hw *hw, uint16_t rx_queue_id)
4906 : : {
4907 : 0 : u32 *reg = &hw->q_rx_regs[rx_queue_id * 8];
4908 : 0 : wr32(hw, TXGBE_RXBAL(rx_queue_id), *(reg++));
4909 : 0 : wr32(hw, TXGBE_RXBAH(rx_queue_id), *(reg++));
4910 : 0 : wr32(hw, TXGBE_RXCFG(rx_queue_id), *(reg++) & ~TXGBE_RXCFG_ENA);
4911 : 0 : }
4912 : :
4913 : : void
4914 : 0 : txgbe_dev_save_tx_queue(struct txgbe_hw *hw, uint16_t tx_queue_id)
4915 : : {
4916 : 0 : u32 *reg = &hw->q_tx_regs[tx_queue_id * 8];
4917 : 0 : *(reg++) = rd32(hw, TXGBE_TXBAL(tx_queue_id));
4918 : 0 : *(reg++) = rd32(hw, TXGBE_TXBAH(tx_queue_id));
4919 : 0 : *(reg++) = rd32(hw, TXGBE_TXCFG(tx_queue_id));
4920 : 0 : }
4921 : :
4922 : : void
4923 : 0 : txgbe_dev_store_tx_queue(struct txgbe_hw *hw, uint16_t tx_queue_id)
4924 : : {
4925 : 0 : u32 *reg = &hw->q_tx_regs[tx_queue_id * 8];
4926 : 0 : wr32(hw, TXGBE_TXBAL(tx_queue_id), *(reg++));
4927 : 0 : wr32(hw, TXGBE_TXBAH(tx_queue_id), *(reg++));
4928 : 0 : wr32(hw, TXGBE_TXCFG(tx_queue_id), *(reg++) & ~TXGBE_TXCFG_ENA);
4929 : 0 : }
4930 : :
4931 : : /*
4932 : : * Start Receive Units for specified queue.
4933 : : */
4934 : : int __rte_cold
4935 : 0 : txgbe_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
4936 : : {
4937 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4938 : : struct txgbe_rx_queue *rxq;
4939 : : uint32_t rxdctl;
4940 : : int poll_ms;
4941 : :
4942 : 0 : PMD_INIT_FUNC_TRACE();
4943 : :
4944 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
4945 : :
4946 : : /* Allocate buffers for descriptor rings */
4947 [ # # ]: 0 : if (txgbe_alloc_rx_queue_mbufs(rxq) != 0) {
4948 : 0 : PMD_INIT_LOG(ERR, "Could not alloc mbuf for queue:%d",
4949 : : rx_queue_id);
4950 : 0 : return -1;
4951 : : }
4952 : 0 : rxdctl = rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
4953 : 0 : rxdctl |= TXGBE_RXCFG_ENA;
4954 : 0 : wr32(hw, TXGBE_RXCFG(rxq->reg_idx), rxdctl);
4955 : :
4956 : : /* Wait until RX Enable ready */
4957 : : poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
4958 : : do {
4959 : : rte_delay_ms(1);
4960 : 0 : rxdctl = rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
4961 [ # # # # ]: 0 : } while (--poll_ms && !(rxdctl & TXGBE_RXCFG_ENA));
4962 [ # # ]: 0 : if (!poll_ms)
4963 : 0 : PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", rx_queue_id);
4964 : : rte_wmb();
4965 : 0 : wr32(hw, TXGBE_RXRP(rxq->reg_idx), 0);
4966 : 0 : wr32(hw, TXGBE_RXWP(rxq->reg_idx), rxq->nb_rx_desc - 1);
4967 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
4968 : :
4969 : 0 : return 0;
4970 : : }
4971 : :
4972 : : /*
4973 : : * Stop Receive Units for specified queue.
4974 : : */
4975 : : int __rte_cold
4976 : 0 : txgbe_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
4977 : : {
4978 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4979 : : struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
4980 : : struct txgbe_rx_queue *rxq;
4981 : : uint32_t rxdctl;
4982 : : int poll_ms;
4983 : :
4984 : 0 : PMD_INIT_FUNC_TRACE();
4985 : :
4986 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
4987 : :
4988 : 0 : txgbe_dev_save_rx_queue(hw, rxq->reg_idx);
4989 : 0 : wr32m(hw, TXGBE_RXCFG(rxq->reg_idx), TXGBE_RXCFG_ENA, 0);
4990 : :
4991 : : /* Wait until RX Enable bit clear */
4992 : : poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
4993 : : do {
4994 : : rte_delay_ms(1);
4995 : 0 : rxdctl = rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
4996 [ # # # # ]: 0 : } while (--poll_ms && (rxdctl & TXGBE_RXCFG_ENA));
4997 [ # # ]: 0 : if (!poll_ms)
4998 : 0 : PMD_INIT_LOG(ERR, "Could not disable Rx Queue %d", rx_queue_id);
4999 : :
5000 : 0 : rte_delay_us(RTE_TXGBE_WAIT_100_US);
5001 : 0 : txgbe_dev_store_rx_queue(hw, rxq->reg_idx);
5002 : :
5003 : 0 : txgbe_rx_queue_release_mbufs(rxq);
5004 : 0 : txgbe_reset_rx_queue(adapter, rxq);
5005 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
5006 : :
5007 : 0 : return 0;
5008 : : }
5009 : :
5010 : : /*
5011 : : * Start Transmit Units for specified queue.
5012 : : */
5013 : : int __rte_cold
5014 : 0 : txgbe_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
5015 : : {
5016 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
5017 : : struct txgbe_tx_queue *txq;
5018 : : uint32_t txdctl;
5019 : : int poll_ms;
5020 : :
5021 : 0 : PMD_INIT_FUNC_TRACE();
5022 : :
5023 : 0 : txq = dev->data->tx_queues[tx_queue_id];
5024 : 0 : wr32m(hw, TXGBE_TXCFG(txq->reg_idx), TXGBE_TXCFG_ENA, TXGBE_TXCFG_ENA);
5025 : :
5026 : : /* Wait until TX Enable ready */
5027 : : poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
5028 : : do {
5029 : : rte_delay_ms(1);
5030 : 0 : txdctl = rd32(hw, TXGBE_TXCFG(txq->reg_idx));
5031 [ # # # # ]: 0 : } while (--poll_ms && !(txdctl & TXGBE_TXCFG_ENA));
5032 [ # # ]: 0 : if (!poll_ms)
5033 : 0 : PMD_INIT_LOG(ERR, "Could not enable "
5034 : : "Tx Queue %d", tx_queue_id);
5035 : :
5036 : : rte_wmb();
5037 : 0 : wr32(hw, TXGBE_TXWP(txq->reg_idx), txq->tx_tail);
5038 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
5039 : 0 : txq->resetting = false;
5040 : :
5041 : 0 : return 0;
5042 : : }
5043 : :
5044 : : /*
5045 : : * Stop Transmit Units for specified queue.
5046 : : */
5047 : : int __rte_cold
5048 : 0 : txgbe_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
5049 : : {
5050 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
5051 : : struct txgbe_tx_queue *txq;
5052 : : uint32_t txdctl;
5053 : : uint32_t txtdh, txtdt;
5054 : : int poll_ms;
5055 : :
5056 : 0 : PMD_INIT_FUNC_TRACE();
5057 : :
5058 : 0 : txq = dev->data->tx_queues[tx_queue_id];
5059 : :
5060 : : /* Wait until TX queue is empty */
5061 : : poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
5062 : : do {
5063 : 0 : rte_delay_us(RTE_TXGBE_WAIT_100_US);
5064 : 0 : txtdh = rd32(hw, TXGBE_TXRP(txq->reg_idx));
5065 : 0 : txtdt = rd32(hw, TXGBE_TXWP(txq->reg_idx));
5066 [ # # # # ]: 0 : } while (--poll_ms && (txtdh != txtdt));
5067 [ # # ]: 0 : if (!poll_ms)
5068 : 0 : PMD_INIT_LOG(ERR,
5069 : : "Tx Queue %d is not empty when stopping.",
5070 : : tx_queue_id);
5071 : :
5072 : 0 : txgbe_dev_save_tx_queue(hw, txq->reg_idx);
5073 : 0 : wr32m(hw, TXGBE_TXCFG(txq->reg_idx), TXGBE_TXCFG_ENA, 0);
5074 : :
5075 : : /* Wait until TX Enable bit clear */
5076 : : poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
5077 : : do {
5078 : : rte_delay_ms(1);
5079 : 0 : txdctl = rd32(hw, TXGBE_TXCFG(txq->reg_idx));
5080 [ # # # # ]: 0 : } while (--poll_ms && (txdctl & TXGBE_TXCFG_ENA));
5081 [ # # ]: 0 : if (!poll_ms)
5082 : 0 : PMD_INIT_LOG(ERR, "Could not disable Tx Queue %d",
5083 : : tx_queue_id);
5084 : :
5085 : 0 : rte_delay_us(RTE_TXGBE_WAIT_100_US);
5086 : 0 : txgbe_dev_store_tx_queue(hw, txq->reg_idx);
5087 : :
5088 [ # # ]: 0 : if (txq->ops != NULL) {
5089 : 0 : txq->ops->release_mbufs(txq);
5090 : 0 : txq->ops->reset(txq);
5091 : : }
5092 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
5093 : :
5094 : 0 : return 0;
5095 : : }
5096 : :
5097 : : void
5098 : 0 : txgbe_tx_queue_clear_error(void *param)
5099 : : {
5100 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
5101 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
5102 : : struct txgbe_tx_queue *txq;
5103 : : u32 i;
5104 : :
5105 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5106 : 0 : txq = dev->data->tx_queues[i];
5107 [ # # ]: 0 : if (!txq->resetting)
5108 : 0 : continue;
5109 : :
5110 : : /* Increase the count of Tx desc error since
5111 : : * it causes the queue reset.
5112 : : */
5113 : 0 : txq->desc_error++;
5114 : 0 : txgbe_dev_save_tx_queue(hw, i);
5115 : :
5116 : : /* tx ring reset */
5117 : 0 : wr32(hw, TXGBE_TDM_DESC_NONFATAL(i / 32),
5118 : 0 : TXGBE_TDM_DESC_MASK(i % 32));
5119 : :
5120 [ # # ]: 0 : if (txq->ops != NULL) {
5121 : 0 : txq->ops->release_mbufs(txq);
5122 : 0 : txq->ops->reset(txq);
5123 : : }
5124 : :
5125 : 0 : txgbe_dev_store_tx_queue(hw, i);
5126 : 0 : txgbe_dev_tx_queue_start(dev, i);
5127 : : }
5128 : 0 : }
5129 : :
5130 : : void
5131 : 0 : txgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
5132 : : struct rte_eth_rxq_info *qinfo)
5133 : : {
5134 : : struct txgbe_rx_queue *rxq;
5135 : :
5136 : 0 : rxq = dev->data->rx_queues[queue_id];
5137 : :
5138 : 0 : qinfo->mp = rxq->mb_pool;
5139 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
5140 : 0 : qinfo->nb_desc = rxq->nb_rx_desc;
5141 : :
5142 : 0 : qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
5143 : 0 : qinfo->conf.rx_drop_en = rxq->drop_en;
5144 : 0 : qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
5145 : 0 : qinfo->conf.offloads = rxq->offloads;
5146 : 0 : }
5147 : :
5148 : : void
5149 : 0 : txgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
5150 : : struct rte_eth_txq_info *qinfo)
5151 : : {
5152 : : struct txgbe_tx_queue *txq;
5153 : :
5154 : 0 : txq = dev->data->tx_queues[queue_id];
5155 : :
5156 : 0 : qinfo->nb_desc = txq->nb_tx_desc;
5157 : :
5158 : 0 : qinfo->conf.tx_thresh.pthresh = txq->pthresh;
5159 : 0 : qinfo->conf.tx_thresh.hthresh = txq->hthresh;
5160 : 0 : qinfo->conf.tx_thresh.wthresh = txq->wthresh;
5161 : :
5162 : 0 : qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
5163 : 0 : qinfo->conf.offloads = txq->offloads;
5164 : 0 : qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
5165 : 0 : }
5166 : :
5167 : : /*
5168 : : * [VF] Initializes Receive Unit.
5169 : : */
5170 : : int __rte_cold
5171 : 0 : txgbevf_dev_rx_init(struct rte_eth_dev *dev)
5172 : : {
5173 : : struct txgbe_hw *hw;
5174 : : struct txgbe_rx_queue *rxq;
5175 : 0 : struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
5176 : : uint64_t bus_addr;
5177 : : uint32_t srrctl, psrtype;
5178 : : uint16_t buf_size;
5179 : : uint16_t i;
5180 : : int ret;
5181 : :
5182 : 0 : PMD_INIT_FUNC_TRACE();
5183 : 0 : hw = TXGBE_DEV_HW(dev);
5184 : :
5185 [ # # ]: 0 : if (rte_is_power_of_2(dev->data->nb_rx_queues) == 0) {
5186 : 0 : PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
5187 : : "it should be power of 2");
5188 : 0 : return -1;
5189 : : }
5190 : :
5191 [ # # ]: 0 : if (dev->data->nb_rx_queues > hw->mac.max_rx_queues) {
5192 : 0 : PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
5193 : : "it should be equal to or less than %d",
5194 : : hw->mac.max_rx_queues);
5195 : 0 : return -1;
5196 : : }
5197 : :
5198 : : /*
5199 : : * When the VF driver issues a TXGBE_VF_RESET request, the PF driver
5200 : : * disables the VF receipt of packets if the PF MTU is > 1500.
5201 : : * This is done to deal with limitations that imposes
5202 : : * the PF and all VFs to share the same MTU.
5203 : : * Then, the PF driver enables again the VF receipt of packet when
5204 : : * the VF driver issues a TXGBE_VF_SET_LPE request.
5205 : : * In the meantime, the VF device cannot be used, even if the VF driver
5206 : : * and the Guest VM network stack are ready to accept packets with a
5207 : : * size up to the PF MTU.
5208 : : * As a work-around to this PF behaviour, force the call to
5209 : : * txgbevf_rlpml_set_vf even if jumbo frames are not used. This way,
5210 : : * VF packets received can work in all cases.
5211 : : */
5212 [ # # ]: 0 : if (txgbevf_rlpml_set_vf(hw,
5213 : 0 : (uint16_t)dev->data->mtu + TXGBE_ETH_OVERHEAD)) {
5214 : 0 : PMD_INIT_LOG(ERR, "Set max packet length to %d failed.",
5215 : : dev->data->mtu + TXGBE_ETH_OVERHEAD);
5216 : 0 : return -EINVAL;
5217 : : }
5218 : :
5219 : : /*
5220 : : * Assume no header split and no VLAN strip support
5221 : : * on any Rx queue first .
5222 : : */
5223 : 0 : rxmode->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5224 : :
5225 : : /* Set PSR type for VF RSS according to max Rx queue */
5226 : : psrtype = TXGBE_VFPLCFG_PSRL4HDR |
5227 : : TXGBE_VFPLCFG_PSRL4HDR |
5228 : : TXGBE_VFPLCFG_PSRL2HDR |
5229 : : TXGBE_VFPLCFG_PSRTUNHDR |
5230 : : TXGBE_VFPLCFG_PSRTUNMAC;
5231 : : wr32(hw, TXGBE_VFPLCFG, TXGBE_VFPLCFG_PSR(psrtype));
5232 : :
5233 : : /* Setup RX queues */
5234 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5235 : 0 : rxq = dev->data->rx_queues[i];
5236 : :
5237 : : /* Allocate buffers for descriptor rings */
5238 : 0 : ret = txgbe_alloc_rx_queue_mbufs(rxq);
5239 [ # # ]: 0 : if (ret)
5240 : 0 : return ret;
5241 : :
5242 : : /* Setup the Base and Length of the Rx Descriptor Rings */
5243 : 0 : bus_addr = rxq->rx_ring_phys_addr;
5244 : :
5245 : 0 : wr32(hw, TXGBE_RXBAL(i),
5246 : : (uint32_t)(bus_addr & BIT_MASK32));
5247 : 0 : wr32(hw, TXGBE_RXBAH(i),
5248 : 0 : (uint32_t)(bus_addr >> 32));
5249 : 0 : wr32(hw, TXGBE_RXRP(i), 0);
5250 : 0 : wr32(hw, TXGBE_RXWP(i), 0);
5251 : :
5252 : : /* Configure the RXCFG register */
5253 [ # # ]: 0 : srrctl = TXGBE_RXCFG_RNGLEN(rxq->nb_rx_desc);
5254 : :
5255 : : /* Set if packets are dropped when no descriptors available */
5256 [ # # ]: 0 : if (rxq->drop_en)
5257 : 0 : srrctl |= TXGBE_RXCFG_DROP;
5258 : :
5259 : : /*
5260 : : * Configure the RX buffer size in the PKTLEN field of
5261 : : * the RXCFG register of the queue.
5262 : : * The value is in 1 KB resolution. Valid values can be from
5263 : : * 1 KB to 16 KB.
5264 : : */
5265 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
5266 : : RTE_PKTMBUF_HEADROOM);
5267 : 0 : buf_size = ROUND_DOWN(buf_size, 1 << 10);
5268 [ # # ]: 0 : srrctl |= TXGBE_RXCFG_PKTLEN(buf_size);
5269 : :
5270 : : /*
5271 : : * VF modification to write virtual function RXCFG register
5272 : : */
5273 : 0 : wr32(hw, TXGBE_RXCFG(i), srrctl);
5274 : :
5275 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_SCATTER ||
5276 : : /* It adds dual VLAN length for supporting dual VLAN */
5277 : 0 : (dev->data->mtu + TXGBE_ETH_OVERHEAD +
5278 [ # # ]: 0 : 2 * RTE_VLAN_HLEN) > buf_size) {
5279 [ # # ]: 0 : if (!dev->data->scattered_rx)
5280 : 0 : PMD_INIT_LOG(DEBUG, "forcing scatter mode");
5281 : 0 : dev->data->scattered_rx = 1;
5282 : : }
5283 : :
5284 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
5285 : 0 : rxmode->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5286 : : }
5287 : :
5288 : : /*
5289 : : * Device configured with multiple RX queues.
5290 : : */
5291 : 0 : txgbe_dev_mq_rx_configure(dev);
5292 : :
5293 : 0 : txgbe_set_rx_function(dev);
5294 : :
5295 : 0 : return 0;
5296 : : }
5297 : :
5298 : : /*
5299 : : * [VF] Initializes Transmit Unit.
5300 : : */
5301 : : void __rte_cold
5302 : 0 : txgbevf_dev_tx_init(struct rte_eth_dev *dev)
5303 : : {
5304 : : struct txgbe_hw *hw;
5305 : : struct txgbe_tx_queue *txq;
5306 : : uint64_t bus_addr;
5307 : : uint16_t i;
5308 : :
5309 : 0 : PMD_INIT_FUNC_TRACE();
5310 : 0 : hw = TXGBE_DEV_HW(dev);
5311 : :
5312 : : /* Setup the Base and Length of the Tx Descriptor Rings */
5313 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5314 : 0 : txq = dev->data->tx_queues[i];
5315 : 0 : bus_addr = txq->tx_ring_phys_addr;
5316 : 0 : wr32(hw, TXGBE_TXBAL(i),
5317 : : (uint32_t)(bus_addr & BIT_MASK32));
5318 : 0 : wr32(hw, TXGBE_TXBAH(i),
5319 : 0 : (uint32_t)(bus_addr >> 32));
5320 : 0 : wr32m(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_BUFLEN_MASK,
5321 [ # # ]: 0 : TXGBE_TXCFG_BUFLEN(txq->nb_tx_desc));
5322 : : /* Setup the HW Tx Head and TX Tail descriptor pointers */
5323 : 0 : wr32(hw, TXGBE_TXRP(i), 0);
5324 : 0 : wr32(hw, TXGBE_TXWP(i), 0);
5325 : : }
5326 : 0 : }
5327 : :
5328 : : /*
5329 : : * [VF] Start Transmit and Receive Units.
5330 : : */
5331 : : void __rte_cold
5332 : 0 : txgbevf_dev_rxtx_start(struct rte_eth_dev *dev)
5333 : : {
5334 : : struct txgbe_hw *hw;
5335 : : struct txgbe_tx_queue *txq;
5336 : : struct txgbe_rx_queue *rxq;
5337 : : uint32_t txdctl;
5338 : : uint32_t rxdctl;
5339 : : uint16_t i;
5340 : : int poll_ms;
5341 : :
5342 : 0 : PMD_INIT_FUNC_TRACE();
5343 : 0 : hw = TXGBE_DEV_HW(dev);
5344 : :
5345 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5346 : 0 : txq = dev->data->tx_queues[i];
5347 : : /* Setup Transmit Threshold Registers */
5348 : 0 : wr32m(hw, TXGBE_TXCFG(txq->reg_idx),
5349 : : TXGBE_TXCFG_HTHRESH_MASK |
5350 : : TXGBE_TXCFG_WTHRESH_MASK,
5351 : 0 : TXGBE_TXCFG_HTHRESH(txq->hthresh) |
5352 : 0 : TXGBE_TXCFG_WTHRESH(txq->wthresh));
5353 : : }
5354 : :
5355 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5356 : 0 : wr32m(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_ENA, TXGBE_TXCFG_ENA);
5357 : :
5358 : : poll_ms = 10;
5359 : : /* Wait until TX Enable ready */
5360 : : do {
5361 : : rte_delay_ms(1);
5362 : : txdctl = rd32(hw, TXGBE_TXCFG(i));
5363 [ # # # # ]: 0 : } while (--poll_ms && !(txdctl & TXGBE_TXCFG_ENA));
5364 [ # # ]: 0 : if (!poll_ms)
5365 : 0 : PMD_INIT_LOG(ERR, "Could not enable Tx Queue %d", i);
5366 : : else
5367 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
5368 : : }
5369 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5370 : 0 : rxq = dev->data->rx_queues[i];
5371 : :
5372 : 0 : wr32m(hw, TXGBE_RXCFG(i), TXGBE_RXCFG_ENA, TXGBE_RXCFG_ENA);
5373 : :
5374 : : /* Wait until RX Enable ready */
5375 : : poll_ms = 10;
5376 : : do {
5377 : : rte_delay_ms(1);
5378 : : rxdctl = rd32(hw, TXGBE_RXCFG(i));
5379 [ # # # # ]: 0 : } while (--poll_ms && !(rxdctl & TXGBE_RXCFG_ENA));
5380 [ # # ]: 0 : if (!poll_ms)
5381 : 0 : PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", i);
5382 : : else
5383 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
5384 : : rte_wmb();
5385 : 0 : wr32(hw, TXGBE_RXWP(i), rxq->nb_rx_desc - 1);
5386 : : }
5387 : 0 : }
5388 : :
5389 : : int
5390 : 0 : txgbe_rss_conf_init(struct txgbe_rte_flow_rss_conf *out,
5391 : : const struct rte_flow_action_rss *in)
5392 : : {
5393 [ # # ]: 0 : if (in->key_len > RTE_DIM(out->key) ||
5394 [ # # ]: 0 : in->queue_num > RTE_DIM(out->queue))
5395 : : return -EINVAL;
5396 : 0 : out->conf = (struct rte_flow_action_rss){
5397 : 0 : .func = in->func,
5398 : 0 : .level = in->level,
5399 : 0 : .types = in->types,
5400 : : .key_len = in->key_len,
5401 : : .queue_num = in->queue_num,
5402 : 0 : .key = memcpy(out->key, in->key, in->key_len),
5403 : 0 : .queue = memcpy(out->queue, in->queue,
5404 : 0 : sizeof(*in->queue) * in->queue_num),
5405 : : };
5406 : 0 : return 0;
5407 : : }
5408 : :
5409 : : int
5410 : 0 : txgbe_action_rss_same(const struct rte_flow_action_rss *comp,
5411 : : const struct rte_flow_action_rss *with)
5412 : : {
5413 : 0 : return (comp->func == with->func &&
5414 : 0 : comp->level == with->level &&
5415 [ # # ]: 0 : comp->types == with->types &&
5416 [ # # ]: 0 : comp->key_len == with->key_len &&
5417 : 0 : comp->queue_num == with->queue_num &&
5418 [ # # # # ]: 0 : !memcmp(comp->key, with->key, with->key_len) &&
5419 : 0 : !memcmp(comp->queue, with->queue,
5420 [ # # ]: 0 : sizeof(*with->queue) * with->queue_num));
5421 : : }
5422 : :
5423 : : int
5424 : 0 : txgbe_config_rss_filter(struct rte_eth_dev *dev,
5425 : : struct txgbe_rte_flow_rss_conf *conf, bool add)
5426 : : {
5427 : : struct txgbe_hw *hw;
5428 : : uint32_t reta;
5429 : : uint16_t i;
5430 : : uint16_t j;
5431 : : uint16_t queue;
5432 : 0 : struct rte_eth_rss_conf rss_conf = {
5433 : 0 : .rss_key = conf->conf.key_len ?
5434 [ # # ]: 0 : (void *)(uintptr_t)conf->conf.key : NULL,
5435 : : .rss_key_len = conf->conf.key_len,
5436 : 0 : .rss_hf = conf->conf.types,
5437 : : };
5438 : 0 : struct txgbe_filter_info *filter_info = TXGBE_DEV_FILTER(dev);
5439 : :
5440 : 0 : PMD_INIT_FUNC_TRACE();
5441 : 0 : hw = TXGBE_DEV_HW(dev);
5442 : :
5443 [ # # ]: 0 : if (!add) {
5444 [ # # ]: 0 : if (txgbe_action_rss_same(&filter_info->rss_info.conf,
5445 : 0 : &conf->conf)) {
5446 : 0 : txgbe_rss_disable(dev);
5447 : 0 : memset(&filter_info->rss_info, 0,
5448 : : sizeof(struct txgbe_rte_flow_rss_conf));
5449 : 0 : return 0;
5450 : : }
5451 : : return -EINVAL;
5452 : : }
5453 : :
5454 [ # # ]: 0 : if (filter_info->rss_info.conf.queue_num)
5455 : : return -EINVAL;
5456 : : /* Fill in redirection table
5457 : : * The byte-swap is needed because NIC registers are in
5458 : : * little-endian order.
5459 : : */
5460 : : reta = 0;
5461 [ # # ]: 0 : for (i = 0, j = 0; i < RTE_ETH_RSS_RETA_SIZE_128; i++, j++) {
5462 [ # # ]: 0 : if (j == conf->conf.queue_num)
5463 : : j = 0;
5464 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active)
5465 : 0 : queue = RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx +
5466 : 0 : conf->conf.queue[j];
5467 : : else
5468 : 0 : queue = conf->conf.queue[j];
5469 : 0 : reta = (reta >> 8) | LS32(queue, 24, 0xFF);
5470 [ # # ]: 0 : if ((i & 3) == 3)
5471 : 0 : wr32at(hw, TXGBE_REG_RSSTBL, i >> 2, reta);
5472 : : }
5473 : :
5474 : : /* Configure the RSS key and the RSS protocols used to compute
5475 : : * the RSS hash of input packets.
5476 : : */
5477 [ # # ]: 0 : if ((rss_conf.rss_hf & TXGBE_RSS_OFFLOAD_ALL) == 0) {
5478 : 0 : txgbe_rss_disable(dev);
5479 : 0 : return 0;
5480 : : }
5481 [ # # ]: 0 : if (rss_conf.rss_key == NULL)
5482 : 0 : rss_conf.rss_key = rss_intel_key; /* Default hash key */
5483 : 0 : txgbe_dev_rss_hash_update(dev, &rss_conf);
5484 : :
5485 [ # # ]: 0 : if (txgbe_rss_conf_init(&filter_info->rss_info, &conf->conf))
5486 : 0 : return -EINVAL;
5487 : :
5488 : : return 0;
5489 : : }
5490 : :
5491 : : /* Stubs needed for linkage when RTE_ARCH_PPC_64, RTE_ARCH_RISCV or
5492 : : * RTE_ARCH_LOONGARCH is set.
5493 : : */
5494 : : #if defined(RTE_ARCH_PPC_64) || defined(RTE_ARCH_RISCV) || \
5495 : : defined(RTE_ARCH_LOONGARCH)
5496 : : int
5497 : : txgbe_rx_vec_dev_conf_condition_check(__rte_unused struct rte_eth_dev *dev)
5498 : : {
5499 : : return -1;
5500 : : }
5501 : :
5502 : : uint16_t
5503 : : txgbe_recv_pkts_vec(__rte_unused void *rx_queue,
5504 : : __rte_unused struct rte_mbuf **rx_pkts,
5505 : : __rte_unused uint16_t nb_pkts)
5506 : : {
5507 : : return 0;
5508 : : }
5509 : :
5510 : : uint16_t
5511 : : txgbe_recv_scattered_pkts_vec(__rte_unused void *rx_queue,
5512 : : __rte_unused struct rte_mbuf **rx_pkts,
5513 : : __rte_unused uint16_t nb_pkts)
5514 : : {
5515 : : return 0;
5516 : : }
5517 : :
5518 : : int
5519 : : txgbe_rxq_vec_setup(__rte_unused struct txgbe_rx_queue *rxq)
5520 : : {
5521 : : return -1;
5522 : : }
5523 : :
5524 : : uint16_t
5525 : : txgbe_xmit_fixed_burst_vec(__rte_unused void *tx_queue,
5526 : : __rte_unused struct rte_mbuf **tx_pkts,
5527 : : __rte_unused uint16_t nb_pkts)
5528 : : {
5529 : : return 0;
5530 : : }
5531 : :
5532 : : int
5533 : : txgbe_txq_vec_setup(__rte_unused struct txgbe_tx_queue *txq)
5534 : : {
5535 : : return -1;
5536 : : }
5537 : :
5538 : : void
5539 : : txgbe_rx_queue_release_mbufs_vec(__rte_unused struct txgbe_rx_queue *rxq)
5540 : : {
5541 : : }
5542 : : #endif
|