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