Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2014-2023 Broadcom
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #include <inttypes.h>
7 : :
8 : : #include <rte_byteorder.h>
9 : : #include <rte_malloc.h>
10 : :
11 : : #include "bnxt.h"
12 : : #include "bnxt_hwrm.h"
13 : : #include "bnxt_ring.h"
14 : : #include "bnxt_txq.h"
15 : : #include "bnxt_txr.h"
16 : : #include "hsi_struct_def_dpdk.h"
17 : : #include <stdbool.h>
18 : :
19 : : /*
20 : : * TX Ring handling
21 : : */
22 : :
23 : 0 : void bnxt_free_tx_rings(struct bnxt *bp)
24 : : {
25 : : int i;
26 : :
27 [ # # # # ]: 0 : if (!bp->tx_queues || !bp->eth_dev->data->tx_queues)
28 : : return;
29 : :
30 [ # # ]: 0 : for (i = 0; i < (int)bp->tx_nr_rings; i++) {
31 : 0 : struct bnxt_tx_queue *txq = bp->tx_queues[i];
32 : :
33 [ # # ]: 0 : if (!txq)
34 : 0 : continue;
35 : :
36 : 0 : bnxt_free_ring(txq->tx_ring->tx_ring_struct);
37 : 0 : rte_free(txq->tx_ring->tx_ring_struct);
38 : 0 : rte_free(txq->tx_ring);
39 : :
40 : 0 : bnxt_free_ring(txq->cp_ring->cp_ring_struct);
41 : 0 : rte_free(txq->cp_ring->cp_ring_struct);
42 : 0 : rte_free(txq->cp_ring);
43 : :
44 : 0 : rte_memzone_free(txq->mz);
45 : 0 : txq->mz = NULL;
46 : :
47 : 0 : rte_free(txq);
48 : 0 : bp->tx_queues[i] = NULL;
49 : : }
50 : : }
51 : :
52 : 0 : int bnxt_init_one_tx_ring(struct bnxt_tx_queue *txq)
53 : : {
54 : 0 : struct bnxt_tx_ring_info *txr = txq->tx_ring;
55 : 0 : struct bnxt_ring *ring = txr->tx_ring_struct;
56 : :
57 : 0 : txq->tx_wake_thresh = ring->ring_size / 2;
58 : 0 : ring->fw_ring_id = INVALID_HW_RING_ID;
59 : :
60 : 0 : return 0;
61 : : }
62 : :
63 : 0 : int bnxt_init_tx_ring_struct(struct bnxt_tx_queue *txq, unsigned int socket_id)
64 : : {
65 : : struct bnxt_cp_ring_info *cpr;
66 : : struct bnxt_tx_ring_info *txr;
67 : : struct bnxt_ring *ring;
68 : :
69 : 0 : txr = rte_zmalloc_socket("bnxt_tx_ring",
70 : : sizeof(struct bnxt_tx_ring_info),
71 : : RTE_CACHE_LINE_SIZE, socket_id);
72 [ # # ]: 0 : if (txr == NULL)
73 : : return -ENOMEM;
74 : 0 : txq->tx_ring = txr;
75 : :
76 : 0 : ring = rte_zmalloc_socket("bnxt_tx_ring_struct",
77 : : sizeof(struct bnxt_ring),
78 : : RTE_CACHE_LINE_SIZE, socket_id);
79 [ # # ]: 0 : if (ring == NULL)
80 : : return -ENOMEM;
81 : 0 : txr->tx_ring_struct = ring;
82 : 0 : ring->ring_size = rte_align32pow2(txq->nb_tx_desc);
83 : 0 : ring->ring_mask = ring->ring_size - 1;
84 : 0 : ring->bd = (void *)txr->tx_desc_ring;
85 : 0 : ring->bd_dma = txr->tx_desc_mapping;
86 : 0 : ring->vmem_size = ring->ring_size * sizeof(struct rte_mbuf *);
87 : 0 : ring->vmem = (void **)&txr->tx_buf_ring;
88 : 0 : ring->fw_ring_id = INVALID_HW_RING_ID;
89 : :
90 : 0 : cpr = rte_zmalloc_socket("bnxt_tx_ring",
91 : : sizeof(struct bnxt_cp_ring_info),
92 : : RTE_CACHE_LINE_SIZE, socket_id);
93 [ # # ]: 0 : if (cpr == NULL)
94 : : return -ENOMEM;
95 : 0 : txq->cp_ring = cpr;
96 : :
97 : 0 : ring = rte_zmalloc_socket("bnxt_tx_ring_struct",
98 : : sizeof(struct bnxt_ring),
99 : : RTE_CACHE_LINE_SIZE, socket_id);
100 [ # # ]: 0 : if (ring == NULL)
101 : : return -ENOMEM;
102 : 0 : cpr->cp_ring_struct = ring;
103 : 0 : ring->ring_size = txr->tx_ring_struct->ring_size;
104 : 0 : ring->ring_mask = ring->ring_size - 1;
105 : 0 : ring->bd = (void *)cpr->cp_desc_ring;
106 : 0 : ring->bd_dma = cpr->cp_desc_mapping;
107 : 0 : ring->vmem_size = 0;
108 : 0 : ring->vmem = NULL;
109 : 0 : ring->fw_ring_id = INVALID_HW_RING_ID;
110 : :
111 : 0 : return 0;
112 : : }
113 : :
114 : : static bool
115 : : bnxt_xmit_need_long_bd(struct rte_mbuf *tx_pkt, struct bnxt_tx_queue *txq)
116 : : {
117 [ # # ]: 0 : if (tx_pkt->ol_flags & (RTE_MBUF_F_TX_TCP_SEG |
118 : : RTE_MBUF_F_TX_VLAN | RTE_MBUF_F_TX_OUTER_IP_CKSUM |
119 : : RTE_MBUF_F_TX_TUNNEL_GRE | RTE_MBUF_F_TX_TUNNEL_VXLAN |
120 : : RTE_MBUF_F_TX_TUNNEL_GENEVE | RTE_MBUF_F_TX_IEEE1588_TMST |
121 : : RTE_MBUF_F_TX_QINQ | RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE |
122 : 0 : RTE_MBUF_F_TX_UDP_SEG) ||
123 [ # # # # : 0 : (BNXT_TRUFLOW_EN(txq->bp) &&
# # # # #
# # # ]
124 [ # # # # : 0 : (txq->bp->tx_cfa_action || txq->vfr_tx_cfa_action)))
# # # # #
# # # ]
125 : 0 : return true;
126 : : return false;
127 : : }
128 : :
129 : : /* Used for verifying TSO segments during TCP Segmentation Offload or
130 : : * UDP Fragmentation Offload. tx_pkt->tso_segsz stores the number of
131 : : * segments or fragments in those cases.
132 : : */
133 : : static bool
134 : 0 : bnxt_zero_data_len_tso_segsz(struct rte_mbuf *tx_pkt, bool data_len_chk, bool tso_segsz_check)
135 : : {
136 : : const char *type_str;
137 : :
138 : : /* Minimum TSO seg_size should be 4 */
139 [ # # # # ]: 0 : if (tso_segsz_check && tx_pkt->tso_segsz < 4) {
140 : : type_str = "Unsupported TSO Seg size";
141 : 0 : goto dump_pkt;
142 : : }
143 : :
144 [ # # # # ]: 0 : if (data_len_chk && tx_pkt->data_len == 0) {
145 : : type_str = "Data len == 0";
146 : 0 : goto dump_pkt;
147 : : }
148 : : return false;
149 : 0 : dump_pkt:
150 : 0 : PMD_DRV_LOG_LINE(ERR, "Error! Tx pkt %s == 0", type_str);
151 : 0 : rte_pktmbuf_dump(stdout, tx_pkt, 64);
152 : 0 : rte_dump_stack();
153 : 0 : return true;
154 : : }
155 : :
156 : : static bool
157 [ # # ]: 0 : bnxt_check_pkt_needs_ts(struct rte_mbuf *m)
158 : : {
159 : : const struct rte_ether_hdr *eth_hdr;
160 : : struct rte_ether_hdr _eth_hdr;
161 : : uint16_t eth_type, proto;
162 : : uint32_t off = 0;
163 : : /*
164 : : * Check that the received packet is a eCPRI packet
165 : : */
166 : : eth_hdr = rte_pktmbuf_read(m, off, sizeof(_eth_hdr), &_eth_hdr);
167 [ # # ]: 0 : eth_type = rte_be_to_cpu_16(eth_hdr->ether_type);
168 : : off += sizeof(*eth_hdr);
169 [ # # ]: 0 : if (eth_type == RTE_ETHER_TYPE_ECPRI)
170 : : return true;
171 : : /* Check for single tagged and double tagged VLANs */
172 [ # # ]: 0 : if (eth_type == RTE_ETHER_TYPE_VLAN) {
173 : : const struct rte_vlan_hdr *vh;
174 : : struct rte_vlan_hdr vh_copy;
175 : :
176 : : vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy);
177 [ # # ]: 0 : if (unlikely(vh == NULL))
178 : 0 : return false;
179 : : off += sizeof(*vh);
180 [ # # ]: 0 : proto = rte_be_to_cpu_16(vh->eth_proto);
181 [ # # ]: 0 : if (proto == RTE_ETHER_TYPE_ECPRI)
182 : : return true;
183 [ # # ]: 0 : if (proto == RTE_ETHER_TYPE_VLAN) {
184 : : const struct rte_vlan_hdr *vh;
185 : : struct rte_vlan_hdr vh_copy;
186 : :
187 : : vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy);
188 [ # # ]: 0 : if (unlikely(vh == NULL))
189 : 0 : return false;
190 : : off += sizeof(*vh);
191 [ # # ]: 0 : proto = rte_be_to_cpu_16(vh->eth_proto);
192 [ # # ]: 0 : if (proto == RTE_ETHER_TYPE_ECPRI)
193 : : return true;
194 : : }
195 : : }
196 : : return false;
197 : : }
198 : :
199 : : static bool
200 : : bnxt_invalid_nb_segs(struct rte_mbuf *tx_pkt)
201 : : {
202 : : uint16_t nb_segs = 1;
203 : : struct rte_mbuf *m_seg;
204 : :
205 : 0 : m_seg = tx_pkt->next;
206 [ # # ]: 0 : while (m_seg) {
207 : 0 : nb_segs++;
208 : 0 : m_seg = m_seg->next;
209 : : }
210 : :
211 : 0 : return (nb_segs != tx_pkt->nb_segs);
212 : : }
213 : :
214 : 0 : static int bnxt_invalid_mbuf(struct rte_mbuf *mbuf)
215 : : {
216 : 0 : uint32_t mbuf_size = sizeof(struct rte_mbuf) + mbuf->priv_size;
217 : : const char *reason;
218 : :
219 [ # # # # ]: 0 : if (unlikely(rte_eal_iova_mode() != RTE_IOVA_VA &&
220 : : rte_eal_iova_mode() != RTE_IOVA_PA))
221 : : return 0;
222 : :
223 [ # # ]: 0 : if (unlikely(rte_mbuf_check(mbuf, 1, &reason)))
224 : : return -EINVAL;
225 : :
226 [ # # ]: 0 : if (unlikely(mbuf->ol_flags & RTE_MBUF_F_EXTERNAL))
227 : : return 0;
228 : :
229 [ # # # # ]: 0 : if (unlikely((mbuf->buf_iova < mbuf_size ||
230 : : (mbuf->buf_iova != rte_mempool_virt2iova(mbuf) + mbuf_size))))
231 : 0 : return -EINVAL;
232 : :
233 : : return 0;
234 : : }
235 : :
236 : 0 : static int bnxt_start_xmit(struct rte_mbuf *tx_pkt,
237 : : struct bnxt_tx_queue *txq,
238 : : uint16_t *coal_pkts,
239 : : struct tx_bd_long **last_txbd)
240 : : {
241 : 0 : struct tx_bd_long *last_txbd_save = *last_txbd;
242 : 0 : struct bnxt_tx_ring_info *txr = txq->tx_ring;
243 : 0 : struct bnxt_ring *ring = txr->tx_ring_struct;
244 : 0 : uint16_t tx_raw_prod_save = txr->tx_raw_prod;
245 : : uint32_t outer_tpid_bd = 0;
246 : : struct tx_bd_long *txbd;
247 : : struct tx_bd_long_hi *txbd1 = NULL;
248 : : uint32_t vlan_tag_flags;
249 : : bool long_bd = false;
250 : : unsigned short nr_bds;
251 : : uint16_t prod, idx;
252 : : bool pkt_needs_ts = 0;
253 : : struct rte_mbuf *m_seg;
254 : : struct rte_mbuf **tx_buf;
255 : : static const uint32_t lhint_arr[4] = {
256 : : TX_BD_LONG_FLAGS_LHINT_LT512,
257 : : TX_BD_LONG_FLAGS_LHINT_LT1K,
258 : : TX_BD_LONG_FLAGS_LHINT_LT2K,
259 : : TX_BD_LONG_FLAGS_LHINT_LT2K
260 : : };
261 : : int rc = 0;
262 : :
263 [ # # ]: 0 : if (unlikely(is_bnxt_in_error(txq->bp))) {
264 : : rc = -EIO;
265 : 0 : goto ret;
266 : : }
267 : :
268 [ # # ]: 0 : if (unlikely(bnxt_invalid_mbuf(tx_pkt))) {
269 : : rc = -EINVAL;
270 : 0 : goto drop;
271 : : }
272 : :
273 [ # # ]: 0 : if (unlikely(bnxt_invalid_nb_segs(tx_pkt))) {
274 : : rc = -EINVAL;
275 : 0 : goto drop;
276 : : }
277 : :
278 : : long_bd = bnxt_xmit_need_long_bd(tx_pkt, txq);
279 : 0 : nr_bds = long_bd + tx_pkt->nb_segs;
280 : :
281 [ # # ]: 0 : if (unlikely(bnxt_tx_avail(txq) < nr_bds)) {
282 : : rc = -ENOMEM;
283 : 0 : goto ret;
284 : : }
285 : :
286 : : /* Check if number of Tx descriptors is above HW limit */
287 [ # # ]: 0 : if (unlikely(nr_bds > BNXT_MAX_TSO_SEGS)) {
288 : 0 : PMD_DRV_LOG_LINE(ERR,
289 : : "Num descriptors %d exceeds HW limit", nr_bds);
290 : : rc = -EINVAL;
291 : 0 : goto drop;
292 : : }
293 : :
294 : : /* If packet length is less than minimum packet size, pad it */
295 [ # # ]: 0 : if (unlikely(rte_pktmbuf_pkt_len(tx_pkt) < BNXT_MIN_PKT_SIZE)) {
296 : 0 : uint8_t pad = BNXT_MIN_PKT_SIZE - rte_pktmbuf_pkt_len(tx_pkt);
297 : 0 : char *seg = rte_pktmbuf_append(tx_pkt, pad);
298 : :
299 [ # # ]: 0 : if (!seg) {
300 : 0 : PMD_DRV_LOG_LINE(ERR,
301 : : "Failed to pad mbuf by %d bytes",
302 : : pad);
303 : : rc = -ENOMEM;
304 : 0 : goto ret;
305 : : }
306 : :
307 : : /* Note: data_len, pkt len are updated in rte_pktmbuf_append */
308 : 0 : memset(seg, 0, pad);
309 : : }
310 : :
311 : : /* Check non zero data_len */
312 [ # # ]: 0 : if (unlikely(bnxt_zero_data_len_tso_segsz(tx_pkt, true, false))) {
313 : : rc = -EINVAL;
314 : 0 : goto drop;
315 : : }
316 : :
317 [ # # # # ]: 0 : if (unlikely(txq->bp->ptp_cfg != NULL && txq->bp->ptp_all_rx_tstamp == 1))
318 : 0 : pkt_needs_ts = bnxt_check_pkt_needs_ts(tx_pkt);
319 : :
320 : 0 : prod = RING_IDX(ring, txr->tx_raw_prod);
321 : 0 : tx_buf = &txr->tx_buf_ring[prod];
322 : 0 : *tx_buf = tx_pkt;
323 : 0 : txr->nr_bds[prod] = nr_bds;
324 : :
325 : 0 : txbd = &txr->tx_desc_ring[prod];
326 : 0 : txbd->opaque = *coal_pkts;
327 : 0 : txbd->flags_type = nr_bds << TX_BD_LONG_FLAGS_BD_CNT_SFT;
328 : 0 : txbd->flags_type |= TX_BD_SHORT_FLAGS_COAL_NOW;
329 : 0 : txbd->flags_type |= TX_BD_LONG_FLAGS_NO_CMPL;
330 : 0 : txbd->len = tx_pkt->data_len;
331 [ # # ]: 0 : if (tx_pkt->pkt_len >= 2048)
332 : 0 : txbd->flags_type |= TX_BD_LONG_FLAGS_LHINT_GTE2K;
333 : : else
334 : 0 : txbd->flags_type |= lhint_arr[tx_pkt->pkt_len >> 9];
335 [ # # ]: 0 : if (tx_pkt->ol_flags & RTE_MBUF_F_EXTERNAL)
336 : 0 : txbd->address = rte_cpu_to_le_64(rte_pktmbuf_mtod_offset(tx_pkt, uint64_t, 0));
337 : : else
338 : 0 : txbd->address = rte_cpu_to_le_64(rte_mbuf_data_iova(tx_pkt));
339 : 0 : *last_txbd = txbd;
340 : :
341 [ # # ]: 0 : if (long_bd) {
342 : 0 : txbd->flags_type |= TX_BD_LONG_TYPE_TX_BD_LONG;
343 : : vlan_tag_flags = 0;
344 : :
345 : : /* HW can accelerate only outer vlan in QinQ mode */
346 [ # # ]: 0 : if (tx_pkt->ol_flags & RTE_MBUF_F_TX_QINQ) {
347 : 0 : vlan_tag_flags = TX_BD_LONG_CFA_META_KEY_VLAN_TAG |
348 : 0 : tx_pkt->vlan_tci_outer;
349 : 0 : outer_tpid_bd = txq->bp->outer_tpid_bd &
350 : : BNXT_OUTER_TPID_BD_MASK;
351 : 0 : vlan_tag_flags |= outer_tpid_bd;
352 [ # # ]: 0 : } else if (tx_pkt->ol_flags & RTE_MBUF_F_TX_VLAN) {
353 : : /* shurd: Should this mask at
354 : : * TX_BD_LONG_CFA_META_VLAN_VID_MASK?
355 : : */
356 : : vlan_tag_flags = TX_BD_LONG_CFA_META_KEY_VLAN_TAG |
357 : 0 : tx_pkt->vlan_tci;
358 : : /* Currently supports 8021Q, 8021AD vlan offloads
359 : : * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
360 : : */
361 : : /* DPDK only supports 802.11q VLAN packets */
362 : 0 : vlan_tag_flags |=
363 : : TX_BD_LONG_CFA_META_VLAN_TPID_TPID8100;
364 : : }
365 : :
366 : 0 : txr->tx_raw_prod = RING_NEXT(txr->tx_raw_prod);
367 : :
368 : 0 : prod = RING_IDX(ring, txr->tx_raw_prod);
369 : 0 : txbd1 = (struct tx_bd_long_hi *)&txr->tx_desc_ring[prod];
370 : 0 : txbd1->lflags = 0;
371 : 0 : txbd1->cfa_meta = vlan_tag_flags;
372 : : /* Legacy tx_bd_long_hi->mss =
373 : : * tx_bd_long_hi->kid_or_ts_high_mss
374 : : */
375 : 0 : txbd1->kid_or_ts_high_mss = 0;
376 : :
377 [ # # ]: 0 : if (txq->vfr_tx_cfa_action) {
378 : 0 : txbd1->cfa_action = txq->vfr_tx_cfa_action & 0xffff;
379 : 0 : txbd1->cfa_action_high = (txq->vfr_tx_cfa_action >> 16) &
380 : : TX_BD_LONG_CFA_ACTION_HIGH_MASK;
381 : : } else {
382 : 0 : txbd1->cfa_action = txq->bp->tx_cfa_action & 0xffff;
383 : 0 : txbd1->cfa_action_high = (txq->bp->tx_cfa_action >> 16) &
384 : : TX_BD_LONG_CFA_ACTION_HIGH_MASK;
385 : : }
386 : :
387 [ # # ]: 0 : if (tx_pkt->ol_flags & RTE_MBUF_F_TX_TCP_SEG ||
388 : : tx_pkt->ol_flags & RTE_MBUF_F_TX_UDP_SEG) {
389 : : uint16_t hdr_size;
390 : :
391 : : /* TSO */
392 : 0 : txbd1->lflags |= TX_BD_LONG_LFLAGS_LSO |
393 : : TX_BD_LONG_LFLAGS_T_IPID |
394 : : TX_BD_LONG_LFLAGS_TCP_UDP_CHKSUM |
395 : : TX_BD_LONG_LFLAGS_T_IP_CHKSUM;
396 : 0 : hdr_size = tx_pkt->l2_len + tx_pkt->l3_len +
397 : 0 : tx_pkt->l4_len;
398 [ # # ]: 0 : hdr_size += (tx_pkt->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) ?
399 : 0 : tx_pkt->outer_l2_len +
400 : 0 : tx_pkt->outer_l3_len : 0;
401 : : /* The hdr_size is multiple of 16bit units not 8bit.
402 : : * Hence divide by 2.
403 : : * Also legacy hdr_size = kid_or_ts_low_hdr_size.
404 : : */
405 : 0 : txbd1->kid_or_ts_low_hdr_size = hdr_size >> 1;
406 : 0 : txbd1->kid_or_ts_high_mss = tx_pkt->tso_segsz;
407 [ # # ]: 0 : if (unlikely(bnxt_zero_data_len_tso_segsz(tx_pkt, false, true))) {
408 : : rc = -EINVAL;
409 : 0 : goto drop;
410 : : }
411 : :
412 [ # # ]: 0 : } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_TCP_UDP_CKSUM) ==
413 : : PKT_TX_OIP_IIP_TCP_UDP_CKSUM) {
414 : : /* Outer IP, Inner IP, Inner TCP/UDP CSO */
415 : 0 : txbd1->lflags |= TX_BD_FLG_TIP_IP_TCP_UDP_CHKSUM;
416 [ # # ]: 0 : } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_TCP_CKSUM) ==
417 : : PKT_TX_OIP_IIP_TCP_CKSUM) {
418 : : /* Outer IP, Inner IP, Inner TCP/UDP CSO */
419 : 0 : txbd1->lflags |= TX_BD_FLG_TIP_IP_TCP_UDP_CHKSUM;
420 : : } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_UDP_CKSUM) ==
421 : : PKT_TX_OIP_IIP_UDP_CKSUM) {
422 : : /* Outer IP, Inner IP, Inner TCP/UDP CSO */
423 : : txbd1->lflags |= TX_BD_FLG_TIP_IP_TCP_UDP_CHKSUM;
424 [ # # ]: 0 : } else if ((tx_pkt->ol_flags & PKT_TX_IIP_TCP_UDP_CKSUM) ==
425 : : PKT_TX_IIP_TCP_UDP_CKSUM) {
426 : : /* (Inner) IP, (Inner) TCP/UDP CSO */
427 : 0 : txbd1->lflags |= TX_BD_FLG_IP_TCP_UDP_CHKSUM;
428 : : } else if ((tx_pkt->ol_flags & PKT_TX_IIP_UDP_CKSUM) ==
429 : : PKT_TX_IIP_UDP_CKSUM) {
430 : : /* (Inner) IP, (Inner) TCP/UDP CSO */
431 : : txbd1->lflags |= TX_BD_FLG_IP_TCP_UDP_CHKSUM;
432 [ # # ]: 0 : } else if ((tx_pkt->ol_flags & PKT_TX_IIP_TCP_CKSUM) ==
433 : : PKT_TX_IIP_TCP_CKSUM) {
434 : : /* (Inner) IP, (Inner) TCP/UDP CSO */
435 : 0 : txbd1->lflags |= TX_BD_FLG_IP_TCP_UDP_CHKSUM;
436 [ # # ]: 0 : } else if ((tx_pkt->ol_flags & PKT_TX_OIP_TCP_UDP_CKSUM) ==
437 : : PKT_TX_OIP_TCP_UDP_CKSUM) {
438 : : /* Outer IP, (Inner) TCP/UDP CSO */
439 : 0 : txbd1->lflags |= TX_BD_FLG_TIP_TCP_UDP_CHKSUM;
440 : : } else if ((tx_pkt->ol_flags & PKT_TX_OIP_UDP_CKSUM) ==
441 : : PKT_TX_OIP_UDP_CKSUM) {
442 : : /* Outer IP, (Inner) TCP/UDP CSO */
443 : : txbd1->lflags |= TX_BD_FLG_TIP_TCP_UDP_CHKSUM;
444 [ # # ]: 0 : } else if ((tx_pkt->ol_flags & PKT_TX_OIP_TCP_CKSUM) ==
445 : : PKT_TX_OIP_TCP_CKSUM) {
446 : : /* Outer IP, (Inner) TCP/UDP CSO */
447 : 0 : txbd1->lflags |= TX_BD_FLG_TIP_TCP_UDP_CHKSUM;
448 [ # # ]: 0 : } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_CKSUM) ==
449 : : PKT_TX_OIP_IIP_CKSUM) {
450 : : /* Outer IP, Inner IP CSO */
451 : 0 : txbd1->lflags |= TX_BD_FLG_TIP_IP_CHKSUM;
452 [ # # ]: 0 : } else if ((tx_pkt->ol_flags & PKT_TX_TCP_UDP_CKSUM) ==
453 : : PKT_TX_TCP_UDP_CKSUM) {
454 : : /* TCP/UDP CSO */
455 : 0 : txbd1->lflags |= TX_BD_LONG_LFLAGS_TCP_UDP_CHKSUM;
456 [ # # ]: 0 : } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_TCP_CKSUM) ==
457 : : RTE_MBUF_F_TX_TCP_CKSUM) {
458 : : /* TCP/UDP CSO */
459 : 0 : txbd1->lflags |= TX_BD_LONG_LFLAGS_TCP_UDP_CHKSUM;
460 : : } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_UDP_CKSUM) ==
461 : : RTE_MBUF_F_TX_UDP_CKSUM) {
462 : : /* TCP/UDP CSO */
463 : : txbd1->lflags |= TX_BD_LONG_LFLAGS_TCP_UDP_CHKSUM;
464 [ # # ]: 0 : } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_IP_CKSUM) ==
465 : : RTE_MBUF_F_TX_IP_CKSUM) {
466 : : /* IP CSO */
467 : 0 : txbd1->lflags |= TX_BD_LONG_LFLAGS_IP_CHKSUM;
468 [ # # ]: 0 : } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) ==
469 : : RTE_MBUF_F_TX_OUTER_IP_CKSUM) {
470 : : /* IP CSO */
471 : 0 : txbd1->lflags |= TX_BD_LONG_LFLAGS_T_IP_CHKSUM;
472 [ # # ]: 0 : } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST) ==
473 [ # # ]: 0 : RTE_MBUF_F_TX_IEEE1588_TMST || pkt_needs_ts) {
474 : : /* PTP */
475 : 0 : txbd1->lflags |= TX_BD_LONG_LFLAGS_STAMP;
476 : : }
477 : : } else {
478 : 0 : txbd->flags_type |= TX_BD_SHORT_TYPE_TX_BD_SHORT;
479 : : }
480 : :
481 : 0 : m_seg = tx_pkt->next;
482 [ # # ]: 0 : while (m_seg) {
483 : : /* Check non zero data_len */
484 [ # # ]: 0 : if (unlikely(bnxt_zero_data_len_tso_segsz(m_seg, true, false))) {
485 : : rc = -EINVAL;
486 : 0 : goto drop;
487 : : }
488 : 0 : txr->tx_raw_prod = RING_NEXT(txr->tx_raw_prod);
489 : :
490 : 0 : prod = RING_IDX(ring, txr->tx_raw_prod);
491 : 0 : tx_buf = &txr->tx_buf_ring[prod];
492 : 0 : *tx_buf = m_seg;
493 : :
494 : 0 : txbd = &txr->tx_desc_ring[prod];
495 [ # # ]: 0 : if (m_seg->ol_flags & RTE_MBUF_F_EXTERNAL)
496 : 0 : txbd->address = rte_cpu_to_le_64(rte_pktmbuf_mtod_offset(m_seg,
497 : : uint64_t,
498 : : 0));
499 : : else
500 : 0 : txbd->address = rte_cpu_to_le_64(rte_mbuf_data_iova(m_seg));
501 : 0 : txbd->flags_type = TX_BD_SHORT_TYPE_TX_BD_SHORT;
502 : 0 : txbd->len = m_seg->data_len;
503 : :
504 : 0 : m_seg = m_seg->next;
505 : : }
506 : :
507 : 0 : txbd->flags_type |= TX_BD_LONG_FLAGS_PACKET_END;
508 : :
509 : 0 : txr->tx_raw_prod = RING_NEXT(txr->tx_raw_prod);
510 : :
511 : 0 : return 0;
512 : : drop:
513 : : /* Roll back any descriptors and tx_buf_ring slots that were written
514 : : * for this packet before the failure was detected. Walking from the
515 : : * saved producer index up to (but not including) the current one is
516 : : * safe because we hold the Tx lock and the HW has not been notified
517 : : * (the doorbell is only rung after bnxt_start_xmit() returns
518 : : * successfully).
519 : : */
520 : : idx = tx_raw_prod_save;
521 : :
522 [ # # ]: 0 : while (idx != txr->tx_raw_prod) {
523 : 0 : uint16_t slot = RING_IDX(ring, idx);
524 : :
525 : 0 : txr->tx_buf_ring[slot] = NULL;
526 : 0 : txr->tx_desc_ring[slot].address = 0;
527 : 0 : idx = RING_NEXT(idx);
528 : : }
529 : 0 : txr->tx_raw_prod = tx_raw_prod_save;
530 : 0 : *last_txbd = last_txbd_save;
531 : 0 : rte_pktmbuf_free(tx_pkt);
532 : : ret:
533 : : return rc;
534 : : }
535 : :
536 : 0 : static void bnxt_tx_coal_cmp_fast(struct bnxt_tx_queue *txq, int nr_cons)
537 : : {
538 : 0 : struct bnxt_tx_ring_info *txr = txq->tx_ring;
539 : 0 : struct bnxt_ring *ring = txr->tx_ring_struct;
540 : 0 : struct rte_mbuf **free = txq->free;
541 : 0 : uint16_t raw_cons = txr->tx_raw_cons;
542 : : unsigned int blk = 0;
543 : : int cons, bds;
544 : :
545 [ # # ]: 0 : for (cons = 0; cons < nr_cons; cons++) {
546 : : struct rte_mbuf **tx_buf;
547 : : unsigned short nr_bds;
548 : :
549 : 0 : tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
550 [ # # ]: 0 : nr_bds = (*tx_buf)->nb_segs +
551 : 0 : bnxt_xmit_need_long_bd(*tx_buf, txq);
552 [ # # ]: 0 : for (bds = 0; bds < nr_bds; bds++) {
553 [ # # ]: 0 : if (*tx_buf) {
554 : 0 : free[blk++] = *tx_buf;
555 : : /*
556 : : * Each BD also tracks a consumer index.
557 : : * Update cons, otherwise it will fall behind.
558 : : */
559 : 0 : cons++;
560 : 0 : *tx_buf = NULL;
561 : : }
562 : 0 : raw_cons = RING_NEXT(raw_cons);
563 : 0 : tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
564 : : }
565 : : }
566 [ # # ]: 0 : if (blk)
567 [ # # ]: 0 : rte_mempool_put_bulk(free[0]->pool, (void *)free, blk);
568 : :
569 : 0 : txr->tx_raw_cons = raw_cons;
570 : 0 : }
571 : :
572 : : /*
573 : : * Transmit completion function for use when RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE
574 : : * is enabled.
575 : : */
576 : 0 : static void bnxt_tx_cmp_fast(struct bnxt_tx_queue *txq, int nb_tx,
577 : : bool tx_coal_cmp)
578 : : {
579 : 0 : struct bnxt_tx_ring_info *txr = txq->tx_ring;
580 : 0 : struct bnxt_ring *ring = txr->tx_ring_struct;
581 : 0 : struct rte_mbuf **free = txq->free;
582 : 0 : uint16_t raw_cons = txr->tx_raw_cons;
583 : : unsigned int blk = 0;
584 : : int i, j;
585 : :
586 [ # # ]: 0 : if (tx_coal_cmp)
587 : 0 : return bnxt_tx_coal_cmp_fast(txq, nb_tx);
588 : :
589 [ # # ]: 0 : for (i = 0; i < nb_tx; i++) {
590 : : struct rte_mbuf **tx_buf;
591 : : unsigned short nr_bds;
592 : :
593 : 0 : tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
594 [ # # ]: 0 : nr_bds = (*tx_buf)->nb_segs +
595 : 0 : bnxt_xmit_need_long_bd(*tx_buf, txq);
596 [ # # ]: 0 : for (j = 0; j < nr_bds; j++) {
597 [ # # ]: 0 : if (*tx_buf) {
598 : : /* Add mbuf to the bulk free array */
599 : 0 : free[blk++] = *tx_buf;
600 : 0 : *tx_buf = NULL;
601 : : }
602 : 0 : raw_cons = RING_NEXT(raw_cons);
603 : 0 : tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
604 : : }
605 : : }
606 [ # # ]: 0 : if (blk)
607 [ # # ]: 0 : rte_mempool_put_bulk(free[0]->pool, (void *)free, blk);
608 : :
609 : 0 : txr->tx_raw_cons = raw_cons;
610 : : }
611 : :
612 : 0 : static void bnxt_tx_coal_cmp(struct bnxt_tx_queue *txq, int nr_cons)
613 : : {
614 : 0 : struct bnxt_tx_ring_info *txr = txq->tx_ring;
615 : 0 : struct bnxt_ring *ring = txr->tx_ring_struct;
616 : : struct rte_mempool *pool = NULL;
617 : 0 : struct rte_mbuf **free = txq->free;
618 : 0 : uint16_t raw_cons = txr->tx_raw_cons;
619 : : unsigned int blk = 0;
620 : : int cons, bds;
621 : :
622 [ # # ]: 0 : for (cons = 0; cons < nr_cons; cons++) {
623 : : struct rte_mbuf *mbuf;
624 : : struct rte_mbuf **tx_buf;
625 : : unsigned short nr_bds;
626 : :
627 : 0 : tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
628 : 0 : nr_bds = txr->nr_bds[RING_IDX(ring, raw_cons)];
629 : : /* Clear the now stale number of buffer descriptors */
630 : 0 : txr->nr_bds[RING_IDX(ring, raw_cons)] = 0;
631 : :
632 [ # # ]: 0 : for (bds = 0; bds < nr_bds; bds++) {
633 : 0 : mbuf = *tx_buf;
634 : 0 : *tx_buf = NULL;
635 : 0 : raw_cons = RING_NEXT(raw_cons);
636 : : /*
637 : : * Each BD also tracks a consumer index. So update the cons.
638 : : * Otherwise the cons will fall behind.
639 : : */
640 : 0 : cons++;
641 : 0 : tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
642 [ # # ]: 0 : if (!mbuf) /* long_bd's tx_buf ? */
643 : 0 : continue;
644 : :
645 : : mbuf = rte_pktmbuf_prefree_seg(mbuf);
646 [ # # ]: 0 : if (unlikely(!mbuf))
647 : 0 : continue;
648 : :
649 : : /* EW - no need to unmap DMA memory? */
650 : :
651 [ # # ]: 0 : if (likely(mbuf->pool == pool)) {
652 : : /* Add mbuf to the bulk free array */
653 : 0 : free[blk++] = mbuf;
654 : : } else {
655 : : /* Found an mbuf from a different pool. Free
656 : : * mbufs accumulated so far to the previous
657 : : * pool
658 : : */
659 [ # # ]: 0 : if (likely(pool != NULL))
660 : : rte_mempool_put_bulk(pool,
661 : : (void *)free,
662 : : blk);
663 : :
664 : : /* Start accumulating mbufs in a new pool */
665 : 0 : free[0] = mbuf;
666 : 0 : pool = mbuf->pool;
667 : : blk = 1;
668 : : }
669 : : }
670 : : }
671 [ # # ]: 0 : if (blk)
672 : : rte_mempool_put_bulk(pool, (void *)free, blk);
673 : :
674 : 0 : txr->tx_raw_cons = raw_cons;
675 : 0 : }
676 : :
677 : 0 : static void bnxt_tx_cmp(struct bnxt_tx_queue *txq, int nb_tx, bool tx_coal_cmp)
678 : : {
679 : 0 : struct bnxt_tx_ring_info *txr = txq->tx_ring;
680 : 0 : struct bnxt_ring *ring = txr->tx_ring_struct;
681 : : struct rte_mempool *pool = NULL;
682 : 0 : struct rte_mbuf **free = txq->free;
683 : 0 : uint16_t raw_cons = txr->tx_raw_cons;
684 : : unsigned int blk = 0;
685 : : int i, j;
686 : :
687 [ # # ]: 0 : if (tx_coal_cmp)
688 : 0 : return bnxt_tx_coal_cmp(txq, nb_tx);
689 : :
690 [ # # ]: 0 : for (i = 0; i < nb_tx; i++) {
691 : : struct rte_mbuf *mbuf;
692 : : struct rte_mbuf **tx_buf;
693 : : unsigned short nr_bds;
694 : :
695 : 0 : tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
696 : 0 : nr_bds = txr->nr_bds[RING_IDX(ring, raw_cons)];
697 : : /* Clear the now stale number of buffer descriptors */
698 : 0 : txr->nr_bds[RING_IDX(ring, raw_cons)] = 0;
699 : :
700 [ # # ]: 0 : for (j = 0; j < nr_bds; j++) {
701 : 0 : mbuf = *tx_buf;
702 : 0 : *tx_buf = NULL;
703 : 0 : raw_cons = RING_NEXT(raw_cons);
704 : 0 : tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
705 [ # # ]: 0 : if (!mbuf) /* long_bd's tx_buf ? */
706 : 0 : continue;
707 : :
708 : : mbuf = rte_pktmbuf_prefree_seg(mbuf);
709 [ # # ]: 0 : if (unlikely(!mbuf))
710 : 0 : continue;
711 : :
712 : : /* EW - no need to unmap DMA memory? */
713 : :
714 [ # # ]: 0 : if (likely(mbuf->pool == pool)) {
715 : : /* Add mbuf to the bulk free array */
716 : 0 : free[blk++] = mbuf;
717 : : } else {
718 : : /* Found an mbuf from a different pool. Free
719 : : * mbufs accumulated so far to the previous
720 : : * pool
721 : : */
722 [ # # ]: 0 : if (likely(pool != NULL))
723 : : rte_mempool_put_bulk(pool,
724 : : (void *)free,
725 : : blk);
726 : :
727 : : /* Start accumulating mbufs in a new pool */
728 : 0 : free[0] = mbuf;
729 : 0 : pool = mbuf->pool;
730 : : blk = 1;
731 : : }
732 : : }
733 : : }
734 [ # # ]: 0 : if (blk)
735 : : rte_mempool_put_bulk(pool, (void *)free, blk);
736 : :
737 : 0 : txr->tx_raw_cons = raw_cons;
738 : : }
739 : :
740 : : static bool bnxt_is_tx_cmpl_type(uint16_t type)
741 : : {
742 : : return (type == CMPL_BASE_TYPE_TX_L2_PKT_TS ||
743 : 0 : type == CMPL_BASE_TYPE_TX_L2_COAL ||
744 : : type == CMPL_BASE_TYPE_TX_L2);
745 : : }
746 : :
747 : : static void bnxt_get_tx_ts_p7(struct bnxt *bp, struct tx_cmpl_packet_timestamp *txcmp)
748 : : {
749 : : uint64_t tx_timestamp;
750 : :
751 : 0 : if (!(bp->fw_cap & BNXT_FW_CAP_TX_TS_CMP))
752 : : return;
753 : :
754 [ # # # # ]: 0 : if (!bp->ptp_cfg || !bp->ieee_1588)
755 : : return;
756 : :
757 : 0 : tx_timestamp = rte_le_to_cpu_16(txcmp->ts_ns_mid);
758 : 0 : bp->ptp_cfg->tx_timestamp = (tx_timestamp << 32) | rte_le_to_cpu_32(txcmp->ts_ns_lo);
759 : : }
760 : :
761 : 0 : static int bnxt_handle_tx_cp(struct bnxt_tx_queue *txq)
762 : : {
763 : : uint32_t nb_tx_pkts = 0, cons, ring_mask, opaque;
764 : 0 : struct bnxt_cp_ring_info *cpr = txq->cp_ring;
765 [ # # ]: 0 : uint32_t raw_cons = cpr->cp_raw_cons;
766 : : struct bnxt_ring *cp_ring_struct;
767 : : uint32_t tx_ring_mask;
768 : : bool tx_coal_cmp = false;
769 : : struct tx_cmpl *txcmp;
770 : :
771 [ # # ]: 0 : if (bnxt_tx_bds_in_hw(txq) < txq->tx_free_thresh)
772 : : return 0;
773 : :
774 : 0 : cp_ring_struct = cpr->cp_ring_struct;
775 : 0 : ring_mask = cp_ring_struct->ring_mask;
776 : : tx_ring_mask = txq->tx_ring->tx_ring_struct->ring_mask;
777 : :
778 : : do {
779 : 0 : cons = RING_CMPL(ring_mask, raw_cons);
780 : 0 : txcmp = (struct tx_cmpl *)&cpr->cp_desc_ring[cons];
781 : :
782 [ # # ]: 0 : if (!bnxt_cpr_cmp_valid(txcmp, raw_cons, ring_mask + 1))
783 : : break;
784 : :
785 [ # # ]: 0 : if (CMP_TYPE(txcmp) == CMPL_BASE_TYPE_TX_L2_COAL) {
786 : : struct tx_cmpl_coal *txcmp_c = (struct tx_cmpl_coal *)txcmp;
787 : :
788 : 0 : nb_tx_pkts = (rte_le_to_cpu_32(txcmp_c->sq_cons_idx) -
789 : 0 : (txq->tx_ring->tx_raw_cons & tx_ring_mask)) & tx_ring_mask;
790 : 0 : raw_cons = NEXT_RAW_CMP(raw_cons);
791 : : tx_coal_cmp = true;
792 : 0 : break;
793 : : }
794 : :
795 [ # # # ]: 0 : opaque = rte_le_to_cpu_32(txcmp->opaque);
796 : :
797 [ # # ]: 0 : if (bnxt_is_tx_cmpl_type(CMP_TYPE(txcmp)))
798 : 0 : nb_tx_pkts += opaque;
799 : : else
800 : 0 : RTE_LOG_DP_LINE(ERR, BNXT,
801 : : "Unhandled CMP type %02x",
802 : : CMP_TYPE(txcmp));
803 [ # # ]: 0 : if (CMP_TYPE(txcmp) == CMPL_BASE_TYPE_TX_L2_PKT_TS)
804 [ # # ]: 0 : bnxt_get_tx_ts_p7(txq->bp, (struct tx_cmpl_packet_timestamp *)txcmp);
805 : 0 : raw_cons = NEXT_RAW_CMP(raw_cons);
806 [ # # ]: 0 : } while (nb_tx_pkts < ring_mask);
807 : :
808 [ # # ]: 0 : if (nb_tx_pkts) {
809 [ # # ]: 0 : if (txq->offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
810 : 0 : bnxt_tx_cmp_fast(txq, nb_tx_pkts, tx_coal_cmp);
811 : : else
812 : 0 : bnxt_tx_cmp(txq, nb_tx_pkts, tx_coal_cmp);
813 : 0 : cpr->cp_raw_cons = raw_cons;
814 : 0 : bnxt_db_cq(cpr);
815 : : }
816 : :
817 : 0 : return nb_tx_pkts;
818 : : }
819 : :
820 : 0 : uint16_t bnxt_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
821 : : uint16_t nb_pkts)
822 : : {
823 : : struct bnxt_tx_queue *txq = tx_queue;
824 : : uint16_t rc;
825 : :
826 : 0 : pthread_mutex_lock(&txq->txq_lock);
827 : 0 : rc = _bnxt_xmit_pkts(tx_queue, tx_pkts, nb_pkts);
828 : 0 : pthread_mutex_unlock(&txq->txq_lock);
829 : :
830 : 0 : return rc;
831 : : }
832 : :
833 : 0 : uint16_t _bnxt_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
834 : : uint16_t nb_pkts)
835 : : {
836 : : int rc;
837 : : uint16_t nb_tx_pkts = 0;
838 : 0 : uint16_t coal_pkts = 0;
839 : : struct bnxt_tx_queue *txq = tx_queue;
840 : 0 : struct tx_bd_long *last_txbd = NULL;
841 : : uint8_t dropped = 0;
842 : :
843 : : /* Handle TX completions */
844 : 0 : bnxt_handle_tx_cp(txq);
845 : :
846 : : /* Tx queue was stopped; wait for it to be restarted */
847 [ # # ]: 0 : if (unlikely(!txq->tx_started)) {
848 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Tx q stopped;return");
849 : 0 : return 0;
850 : : }
851 : :
852 : : /* Handle TX burst request */
853 [ # # ]: 0 : for (nb_tx_pkts = 0; nb_tx_pkts < nb_pkts; nb_tx_pkts++) {
854 : 0 : coal_pkts++;
855 : 0 : rc = bnxt_start_xmit(tx_pkts[nb_tx_pkts], txq,
856 : : &coal_pkts, &last_txbd);
857 : :
858 [ # # ]: 0 : if (unlikely(rc)) {
859 [ # # ]: 0 : if (rc == -EINVAL) {
860 : 0 : coal_pkts--;
861 : 0 : rte_atomic_fetch_add_explicit(&txq->tx_mbuf_drop, 1,
862 : : rte_memory_order_relaxed);
863 : 0 : dropped++;
864 : 0 : continue;
865 : : }
866 : : break;
867 : : }
868 : : }
869 : :
870 : : /* last_txbd is used to check for if any packets have been sent in
871 : : * the burst as bnxt_start_xmit will update it to the most recent
872 : : * non-dropped buffer descriptor in the burst.
873 : : */
874 [ # # ]: 0 : if (likely(last_txbd != NULL)) {
875 : : /* Request a completion on the last packet */
876 : 0 : last_txbd->flags_type &= ~TX_BD_LONG_FLAGS_NO_CMPL;
877 [ # # ]: 0 : bnxt_db_write(&txq->tx_ring->tx_db, txq->tx_ring->tx_raw_prod);
878 : : }
879 : :
880 : 0 : return RTE_MIN((uint16_t)(nb_tx_pkts + dropped), nb_pkts);
881 : :
882 : : }
883 : :
884 : 0 : int bnxt_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
885 : : {
886 : 0 : struct bnxt *bp = dev->data->dev_private;
887 : 0 : struct bnxt_tx_queue *txq = bp->tx_queues[tx_queue_id];
888 : : int rc = 0;
889 : :
890 : 0 : rc = is_bnxt_in_error(bp);
891 [ # # ]: 0 : if (rc)
892 : : return rc;
893 : :
894 : : /* reset the previous stats for the tx_queue since the counters
895 : : * will be cleared when the queue is started.
896 : : */
897 : 0 : memset(&bp->prev_tx_ring_stats[tx_queue_id], 0,
898 : : sizeof(struct bnxt_ring_stats));
899 : :
900 : 0 : bnxt_free_hwrm_tx_ring(bp, tx_queue_id);
901 : 0 : rc = bnxt_alloc_hwrm_tx_ring(bp, tx_queue_id);
902 [ # # ]: 0 : if (rc)
903 : : return rc;
904 : :
905 : : /* reset the previous stats for the tx_queue since the counters
906 : : * will be cleared when the queue is started.
907 : : */
908 [ # # # # ]: 0 : if (BNXT_TPA_V2_P7(bp))
909 : 0 : memset(&bp->prev_tx_ring_stats_ext[tx_queue_id], 0,
910 : : sizeof(struct bnxt_ring_stats));
911 : : else
912 : 0 : memset(&bp->prev_tx_ring_stats[tx_queue_id], 0,
913 : : sizeof(struct bnxt_ring_stats));
914 : :
915 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
916 : 0 : txq->tx_started = true;
917 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Tx queue started");
918 : :
919 : 0 : return 0;
920 : : }
921 : :
922 : 0 : int bnxt_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
923 : : {
924 : 0 : struct bnxt *bp = dev->data->dev_private;
925 : 0 : struct bnxt_tx_queue *txq = bp->tx_queues[tx_queue_id];
926 : : int rc = 0;
927 : :
928 : 0 : rc = is_bnxt_in_error(bp);
929 [ # # ]: 0 : if (rc)
930 : : return rc;
931 : :
932 : : /* Handle TX completions */
933 : 0 : bnxt_handle_tx_cp(txq);
934 : :
935 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
936 : 0 : txq->tx_started = false;
937 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Tx queue stopped");
938 : :
939 : 0 : return 0;
940 : : }
941 : :
942 : : static bool bnxt_is_tx_mpc_flush_cmpl_type(uint16_t type)
943 : : {
944 : : return (type == CMPL_BASE_TYPE_TX_L2_PKT_TS ||
945 : : type == CMPL_BASE_TYPE_TX_L2_COAL ||
946 : : type == CMPL_BASE_TYPE_TX_L2 ||
947 : 0 : type == CMPL_BASE_TYPE_MID_PATH_SHORT ||
948 : : type == CMPL_BASE_TYPE_MID_PATH_LONG);
949 : : }
950 : :
951 : : /* Sweep the Tx completion queue till HWRM_DONE for ring flush is received.
952 : : * The mbufs will not be freed in this call.
953 : : * They will be freed during ring free as a part of mem cleanup.
954 : : */
955 : 0 : int bnxt_flush_tx_cmp(struct bnxt_cp_ring_info *cpr)
956 : : {
957 : 0 : uint32_t raw_cons = cpr->cp_raw_cons;
958 : : uint32_t cons;
959 : : uint32_t nb_tx_pkts = 0;
960 : : struct tx_cmpl *txcmp;
961 : 0 : struct cmpl_base *cp_desc_ring = cpr->cp_desc_ring;
962 : 0 : struct bnxt_ring *cp_ring_struct = cpr->cp_ring_struct;
963 : 0 : uint32_t ring_mask = cp_ring_struct->ring_mask;
964 : : uint32_t opaque = 0;
965 : :
966 : : do {
967 : 0 : cons = RING_CMPL(ring_mask, raw_cons);
968 : 0 : txcmp = (struct tx_cmpl *)&cp_desc_ring[cons];
969 : :
970 [ # # ]: 0 : if (!bnxt_cpr_cmp_valid(txcmp, raw_cons, ring_mask + 1))
971 : : break;
972 : :
973 : 0 : opaque = rte_cpu_to_le_32(txcmp->opaque);
974 : 0 : raw_cons = NEXT_RAW_CMP(raw_cons);
975 : :
976 [ # # # # ]: 0 : if (bnxt_is_tx_mpc_flush_cmpl_type(CMP_TYPE(txcmp)))
977 : 0 : nb_tx_pkts += opaque;
978 [ # # ]: 0 : else if (CMP_TYPE(txcmp) == HWRM_CMPL_TYPE_HWRM_DONE)
979 : : return 1;
980 [ # # ]: 0 : } while (nb_tx_pkts < ring_mask);
981 : :
982 [ # # ]: 0 : if (nb_tx_pkts) {
983 : 0 : cpr->cp_raw_cons = raw_cons;
984 : 0 : bnxt_db_cq(cpr);
985 : : }
986 : :
987 : : return 0;
988 : : }
|