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