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