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