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