9cf0126d228e5697c8711ffc8c6d1d1c7f170633
[dpdk.git] / drivers / net / bnxt / bnxt_txr.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2018 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_ring.h"
13 #include "bnxt_txq.h"
14 #include "bnxt_txr.h"
15 #include "hsi_struct_def_dpdk.h"
16 #include <stdbool.h>
17
18 /*
19  * TX Ring handling
20  */
21
22 void bnxt_free_tx_rings(struct bnxt *bp)
23 {
24         int i;
25
26         for (i = 0; i < (int)bp->tx_nr_rings; i++) {
27                 struct bnxt_tx_queue *txq = bp->tx_queues[i];
28
29                 if (!txq)
30                         continue;
31
32                 bnxt_free_ring(txq->tx_ring->tx_ring_struct);
33                 rte_free(txq->tx_ring->tx_ring_struct);
34                 rte_free(txq->tx_ring);
35
36                 bnxt_free_ring(txq->cp_ring->cp_ring_struct);
37                 rte_free(txq->cp_ring->cp_ring_struct);
38                 rte_free(txq->cp_ring);
39
40                 rte_free(txq);
41                 bp->tx_queues[i] = NULL;
42         }
43 }
44
45 int bnxt_init_one_tx_ring(struct bnxt_tx_queue *txq)
46 {
47         struct bnxt_tx_ring_info *txr = txq->tx_ring;
48         struct bnxt_ring *ring = txr->tx_ring_struct;
49
50         txq->tx_wake_thresh = ring->ring_size / 2;
51         ring->fw_ring_id = INVALID_HW_RING_ID;
52
53         return 0;
54 }
55
56 int bnxt_init_tx_ring_struct(struct bnxt_tx_queue *txq, unsigned int socket_id)
57 {
58         struct bnxt_cp_ring_info *cpr;
59         struct bnxt_tx_ring_info *txr;
60         struct bnxt_ring *ring;
61
62         txr = rte_zmalloc_socket("bnxt_tx_ring",
63                                  sizeof(struct bnxt_tx_ring_info),
64                                  RTE_CACHE_LINE_SIZE, socket_id);
65         if (txr == NULL)
66                 return -ENOMEM;
67         txq->tx_ring = txr;
68
69         ring = rte_zmalloc_socket("bnxt_tx_ring_struct",
70                                   sizeof(struct bnxt_ring),
71                                   RTE_CACHE_LINE_SIZE, socket_id);
72         if (ring == NULL)
73                 return -ENOMEM;
74         txr->tx_ring_struct = ring;
75         ring->ring_size = rte_align32pow2(txq->nb_tx_desc);
76         ring->ring_mask = ring->ring_size - 1;
77         ring->bd = (void *)txr->tx_desc_ring;
78         ring->bd_dma = txr->tx_desc_mapping;
79         ring->vmem_size = ring->ring_size * sizeof(struct bnxt_sw_tx_bd);
80         ring->vmem = (void **)&txr->tx_buf_ring;
81         ring->fw_ring_id = INVALID_HW_RING_ID;
82
83         cpr = rte_zmalloc_socket("bnxt_tx_ring",
84                                  sizeof(struct bnxt_cp_ring_info),
85                                  RTE_CACHE_LINE_SIZE, socket_id);
86         if (cpr == NULL)
87                 return -ENOMEM;
88         txq->cp_ring = cpr;
89
90         ring = rte_zmalloc_socket("bnxt_tx_ring_struct",
91                                   sizeof(struct bnxt_ring),
92                                   RTE_CACHE_LINE_SIZE, socket_id);
93         if (ring == NULL)
94                 return -ENOMEM;
95         cpr->cp_ring_struct = ring;
96         ring->ring_size = txr->tx_ring_struct->ring_size;
97         ring->ring_mask = ring->ring_size - 1;
98         ring->bd = (void *)cpr->cp_desc_ring;
99         ring->bd_dma = cpr->cp_desc_mapping;
100         ring->vmem_size = 0;
101         ring->vmem = NULL;
102         ring->fw_ring_id = INVALID_HW_RING_ID;
103
104         return 0;
105 }
106
107 static uint16_t bnxt_start_xmit(struct rte_mbuf *tx_pkt,
108                                 struct bnxt_tx_queue *txq,
109                                 uint16_t *coal_pkts,
110                                 struct tx_bd_long **last_txbd)
111 {
112         struct bnxt_tx_ring_info *txr = txq->tx_ring;
113         struct bnxt_ring *ring = txr->tx_ring_struct;
114         uint32_t outer_tpid_bd = 0;
115         struct tx_bd_long *txbd;
116         struct tx_bd_long_hi *txbd1 = NULL;
117         uint32_t vlan_tag_flags;
118         bool long_bd = false;
119         unsigned short nr_bds = 0;
120         uint16_t prod;
121         struct rte_mbuf *m_seg;
122         struct bnxt_sw_tx_bd *tx_buf;
123         static const uint32_t lhint_arr[4] = {
124                 TX_BD_LONG_FLAGS_LHINT_LT512,
125                 TX_BD_LONG_FLAGS_LHINT_LT1K,
126                 TX_BD_LONG_FLAGS_LHINT_LT2K,
127                 TX_BD_LONG_FLAGS_LHINT_LT2K
128         };
129
130         if (unlikely(is_bnxt_in_error(txq->bp)))
131                 return -EIO;
132
133         if (tx_pkt->ol_flags & (PKT_TX_TCP_SEG | PKT_TX_TCP_CKSUM |
134                                 PKT_TX_UDP_CKSUM | PKT_TX_IP_CKSUM |
135                                 PKT_TX_VLAN_PKT | PKT_TX_OUTER_IP_CKSUM |
136                                 PKT_TX_TUNNEL_GRE | PKT_TX_TUNNEL_VXLAN |
137                                 PKT_TX_TUNNEL_GENEVE | PKT_TX_IEEE1588_TMST |
138                                 PKT_TX_QINQ_PKT) ||
139              (BNXT_TRUFLOW_EN(txq->bp) &&
140               (txq->bp->tx_cfa_action || txq->vfr_tx_cfa_action)))
141                 long_bd = true;
142
143         nr_bds = long_bd + tx_pkt->nb_segs;
144         if (unlikely(bnxt_tx_avail(txq) < nr_bds))
145                 return -ENOMEM;
146
147         /* Check if number of Tx descriptors is above HW limit */
148         if (unlikely(nr_bds > BNXT_MAX_TSO_SEGS)) {
149                 PMD_DRV_LOG(ERR,
150                             "Num descriptors %d exceeds HW limit\n", nr_bds);
151                 return -ENOSPC;
152         }
153
154         /* If packet length is less than minimum packet size, pad it */
155         if (unlikely(rte_pktmbuf_pkt_len(tx_pkt) < BNXT_MIN_PKT_SIZE)) {
156                 uint8_t pad = BNXT_MIN_PKT_SIZE - rte_pktmbuf_pkt_len(tx_pkt);
157                 char *seg = rte_pktmbuf_append(tx_pkt, pad);
158
159                 if (!seg) {
160                         PMD_DRV_LOG(ERR,
161                                     "Failed to pad mbuf by %d bytes\n",
162                                     pad);
163                         return -ENOMEM;
164                 }
165
166                 /* Note: data_len, pkt len are updated in rte_pktmbuf_append */
167                 memset(seg, 0, pad);
168         }
169
170         /* Check non zero data_len */
171         RTE_VERIFY(tx_pkt->data_len);
172
173         prod = RING_IDX(ring, txr->tx_raw_prod);
174         tx_buf = &txr->tx_buf_ring[prod];
175         tx_buf->mbuf = tx_pkt;
176         tx_buf->nr_bds = nr_bds;
177
178         txbd = &txr->tx_desc_ring[prod];
179         txbd->opaque = *coal_pkts;
180         txbd->flags_type = nr_bds << TX_BD_LONG_FLAGS_BD_CNT_SFT;
181         txbd->flags_type |= TX_BD_SHORT_FLAGS_COAL_NOW;
182         txbd->flags_type |= TX_BD_LONG_FLAGS_NO_CMPL;
183         txbd->len = tx_pkt->data_len;
184         if (tx_pkt->pkt_len >= 2014)
185                 txbd->flags_type |= TX_BD_LONG_FLAGS_LHINT_GTE2K;
186         else
187                 txbd->flags_type |= lhint_arr[tx_pkt->pkt_len >> 9];
188         txbd->address = rte_cpu_to_le_64(rte_mbuf_data_iova(tx_buf->mbuf));
189         *last_txbd = txbd;
190
191         if (long_bd) {
192                 txbd->flags_type |= TX_BD_LONG_TYPE_TX_BD_LONG;
193                 vlan_tag_flags = 0;
194
195                 /* HW can accelerate only outer vlan in QinQ mode */
196                 if (tx_buf->mbuf->ol_flags & PKT_TX_QINQ_PKT) {
197                         vlan_tag_flags = TX_BD_LONG_CFA_META_KEY_VLAN_TAG |
198                                 tx_buf->mbuf->vlan_tci_outer;
199                         outer_tpid_bd = txq->bp->outer_tpid_bd &
200                                 BNXT_OUTER_TPID_BD_MASK;
201                         vlan_tag_flags |= outer_tpid_bd;
202                 } else if (tx_buf->mbuf->ol_flags & PKT_TX_VLAN_PKT) {
203                         /* shurd: Should this mask at
204                          * TX_BD_LONG_CFA_META_VLAN_VID_MASK?
205                          */
206                         vlan_tag_flags = TX_BD_LONG_CFA_META_KEY_VLAN_TAG |
207                                 tx_buf->mbuf->vlan_tci;
208                         /* Currently supports 8021Q, 8021AD vlan offloads
209                          * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
210                          */
211                         /* DPDK only supports 802.11q VLAN packets */
212                         vlan_tag_flags |=
213                                         TX_BD_LONG_CFA_META_VLAN_TPID_TPID8100;
214                 }
215
216                 txr->tx_raw_prod = RING_NEXT(txr->tx_raw_prod);
217
218                 prod = RING_IDX(ring, txr->tx_raw_prod);
219                 txbd1 = (struct tx_bd_long_hi *)&txr->tx_desc_ring[prod];
220                 txbd1->lflags = 0;
221                 txbd1->cfa_meta = vlan_tag_flags;
222                 /* Legacy tx_bd_long_hi->mss =
223                  * tx_bd_long_hi->kid_or_ts_high_mss
224                  */
225                 txbd1->kid_or_ts_high_mss = 0;
226
227                 if (txq->vfr_tx_cfa_action)
228                         txbd1->cfa_action = txq->vfr_tx_cfa_action;
229                 else
230                         txbd1->cfa_action = txq->bp->tx_cfa_action;
231
232                 if (tx_pkt->ol_flags & PKT_TX_TCP_SEG) {
233                         uint16_t hdr_size;
234
235                         /* TSO */
236                         txbd1->lflags |= TX_BD_LONG_LFLAGS_LSO |
237                                          TX_BD_LONG_LFLAGS_T_IPID;
238                         hdr_size = tx_pkt->l2_len + tx_pkt->l3_len +
239                                         tx_pkt->l4_len;
240                         hdr_size += (tx_pkt->ol_flags & PKT_TX_TUNNEL_MASK) ?
241                                     tx_pkt->outer_l2_len +
242                                     tx_pkt->outer_l3_len : 0;
243                         /* The hdr_size is multiple of 16bit units not 8bit.
244                          * Hence divide by 2.
245                          * Also legacy hdr_size = kid_or_ts_low_hdr_size.
246                          */
247                         txbd1->kid_or_ts_low_hdr_size = hdr_size >> 1;
248                         txbd1->kid_or_ts_high_mss = tx_pkt->tso_segsz;
249                         RTE_VERIFY(txbd1->kid_or_ts_high_mss);
250
251                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_TCP_UDP_CKSUM) ==
252                            PKT_TX_OIP_IIP_TCP_UDP_CKSUM) {
253                         /* Outer IP, Inner IP, Inner TCP/UDP CSO */
254                         txbd1->lflags |= TX_BD_FLG_TIP_IP_TCP_UDP_CHKSUM;
255                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_TCP_CKSUM) ==
256                            PKT_TX_OIP_IIP_TCP_CKSUM) {
257                         /* Outer IP, Inner IP, Inner TCP/UDP CSO */
258                         txbd1->lflags |= TX_BD_FLG_TIP_IP_TCP_UDP_CHKSUM;
259                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_UDP_CKSUM) ==
260                            PKT_TX_OIP_IIP_UDP_CKSUM) {
261                         /* Outer IP, Inner IP, Inner TCP/UDP CSO */
262                         txbd1->lflags |= TX_BD_FLG_TIP_IP_TCP_UDP_CHKSUM;
263                 } else if ((tx_pkt->ol_flags & PKT_TX_IIP_TCP_UDP_CKSUM) ==
264                            PKT_TX_IIP_TCP_UDP_CKSUM) {
265                         /* (Inner) IP, (Inner) TCP/UDP CSO */
266                         txbd1->lflags |= TX_BD_FLG_IP_TCP_UDP_CHKSUM;
267                 } else if ((tx_pkt->ol_flags & PKT_TX_IIP_UDP_CKSUM) ==
268                            PKT_TX_IIP_UDP_CKSUM) {
269                         /* (Inner) IP, (Inner) TCP/UDP CSO */
270                         txbd1->lflags |= TX_BD_FLG_IP_TCP_UDP_CHKSUM;
271                 } else if ((tx_pkt->ol_flags & PKT_TX_IIP_TCP_CKSUM) ==
272                            PKT_TX_IIP_TCP_CKSUM) {
273                         /* (Inner) IP, (Inner) TCP/UDP CSO */
274                         txbd1->lflags |= TX_BD_FLG_IP_TCP_UDP_CHKSUM;
275                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_TCP_UDP_CKSUM) ==
276                            PKT_TX_OIP_TCP_UDP_CKSUM) {
277                         /* Outer IP, (Inner) TCP/UDP CSO */
278                         txbd1->lflags |= TX_BD_FLG_TIP_TCP_UDP_CHKSUM;
279                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_UDP_CKSUM) ==
280                            PKT_TX_OIP_UDP_CKSUM) {
281                         /* Outer IP, (Inner) TCP/UDP CSO */
282                         txbd1->lflags |= TX_BD_FLG_TIP_TCP_UDP_CHKSUM;
283                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_TCP_CKSUM) ==
284                            PKT_TX_OIP_TCP_CKSUM) {
285                         /* Outer IP, (Inner) TCP/UDP CSO */
286                         txbd1->lflags |= TX_BD_FLG_TIP_TCP_UDP_CHKSUM;
287                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_CKSUM) ==
288                            PKT_TX_OIP_IIP_CKSUM) {
289                         /* Outer IP, Inner IP CSO */
290                         txbd1->lflags |= TX_BD_FLG_TIP_IP_CHKSUM;
291                 } else if ((tx_pkt->ol_flags & PKT_TX_TCP_UDP_CKSUM) ==
292                            PKT_TX_TCP_UDP_CKSUM) {
293                         /* TCP/UDP CSO */
294                         txbd1->lflags |= TX_BD_LONG_LFLAGS_TCP_UDP_CHKSUM;
295                 } else if ((tx_pkt->ol_flags & PKT_TX_TCP_CKSUM) ==
296                            PKT_TX_TCP_CKSUM) {
297                         /* TCP/UDP CSO */
298                         txbd1->lflags |= TX_BD_LONG_LFLAGS_TCP_UDP_CHKSUM;
299                 } else if ((tx_pkt->ol_flags & PKT_TX_UDP_CKSUM) ==
300                            PKT_TX_UDP_CKSUM) {
301                         /* TCP/UDP CSO */
302                         txbd1->lflags |= TX_BD_LONG_LFLAGS_TCP_UDP_CHKSUM;
303                 } else if ((tx_pkt->ol_flags & PKT_TX_IP_CKSUM) ==
304                            PKT_TX_IP_CKSUM) {
305                         /* IP CSO */
306                         txbd1->lflags |= TX_BD_LONG_LFLAGS_IP_CHKSUM;
307                 } else if ((tx_pkt->ol_flags & PKT_TX_OUTER_IP_CKSUM) ==
308                            PKT_TX_OUTER_IP_CKSUM) {
309                         /* IP CSO */
310                         txbd1->lflags |= TX_BD_LONG_LFLAGS_T_IP_CHKSUM;
311                 } else if ((tx_pkt->ol_flags & PKT_TX_IEEE1588_TMST) ==
312                            PKT_TX_IEEE1588_TMST) {
313                         /* PTP */
314                         txbd1->lflags |= TX_BD_LONG_LFLAGS_STAMP;
315                 }
316         } else {
317                 txbd->flags_type |= TX_BD_SHORT_TYPE_TX_BD_SHORT;
318         }
319
320         m_seg = tx_pkt->next;
321         while (m_seg) {
322                 /* Check non zero data_len */
323                 RTE_VERIFY(m_seg->data_len);
324                 txr->tx_raw_prod = RING_NEXT(txr->tx_raw_prod);
325
326                 prod = RING_IDX(ring, txr->tx_raw_prod);
327                 tx_buf = &txr->tx_buf_ring[prod];
328                 tx_buf->mbuf = m_seg;
329
330                 txbd = &txr->tx_desc_ring[prod];
331                 txbd->address = rte_cpu_to_le_64(rte_mbuf_data_iova(m_seg));
332                 txbd->flags_type = TX_BD_SHORT_TYPE_TX_BD_SHORT;
333                 txbd->len = m_seg->data_len;
334
335                 m_seg = m_seg->next;
336         }
337
338         txbd->flags_type |= TX_BD_LONG_FLAGS_PACKET_END;
339
340         txr->tx_raw_prod = RING_NEXT(txr->tx_raw_prod);
341
342         return 0;
343 }
344
345 /*
346  * Transmit completion function for use when DEV_TX_OFFLOAD_MBUF_FAST_FREE
347  * is enabled.
348  */
349 static void bnxt_tx_cmp_fast(struct bnxt_tx_queue *txq, int nr_pkts)
350 {
351         struct bnxt_tx_ring_info *txr = txq->tx_ring;
352         struct bnxt_ring *ring = txr->tx_ring_struct;
353         struct rte_mbuf **free = txq->free;
354         uint16_t raw_cons = txr->tx_raw_cons;
355         unsigned int blk = 0;
356         int i, j;
357
358         for (i = 0; i < nr_pkts; i++) {
359                 struct bnxt_sw_tx_bd *tx_buf;
360                 unsigned short nr_bds;
361
362                 tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
363                 nr_bds = tx_buf->nr_bds;
364                 for (j = 0; j < nr_bds; j++) {
365                         if (tx_buf->mbuf) {
366                                 /* Add mbuf to the bulk free array */
367                                 free[blk++] = tx_buf->mbuf;
368                                 tx_buf->mbuf = NULL;
369                         }
370                         raw_cons = RING_NEXT(raw_cons);
371                         tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
372                 }
373         }
374         if (blk)
375                 rte_mempool_put_bulk(free[0]->pool, (void *)free, blk);
376
377         txr->tx_raw_cons = raw_cons;
378 }
379
380 static void bnxt_tx_cmp(struct bnxt_tx_queue *txq, int nr_pkts)
381 {
382         struct bnxt_tx_ring_info *txr = txq->tx_ring;
383         struct bnxt_ring *ring = txr->tx_ring_struct;
384         struct rte_mempool *pool = NULL;
385         struct rte_mbuf **free = txq->free;
386         uint16_t raw_cons = txr->tx_raw_cons;
387         unsigned int blk = 0;
388         int i, j;
389
390         for (i = 0; i < nr_pkts; i++) {
391                 struct rte_mbuf *mbuf;
392                 struct bnxt_sw_tx_bd *tx_buf;
393                 unsigned short nr_bds;
394
395                 tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
396                 nr_bds = tx_buf->nr_bds;
397                 for (j = 0; j < nr_bds; j++) {
398                         mbuf = tx_buf->mbuf;
399                         tx_buf->mbuf = NULL;
400                         raw_cons = RING_NEXT(raw_cons);
401                         tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
402                         if (!mbuf)      /* long_bd's tx_buf ? */
403                                 continue;
404
405                         mbuf = rte_pktmbuf_prefree_seg(mbuf);
406                         if (unlikely(!mbuf))
407                                 continue;
408
409                         /* EW - no need to unmap DMA memory? */
410
411                         if (likely(mbuf->pool == pool)) {
412                                 /* Add mbuf to the bulk free array */
413                                 free[blk++] = mbuf;
414                         } else {
415                                 /* Found an mbuf from a different pool. Free
416                                  * mbufs accumulated so far to the previous
417                                  * pool
418                                  */
419                                 if (likely(pool != NULL))
420                                         rte_mempool_put_bulk(pool,
421                                                              (void *)free,
422                                                              blk);
423
424                                 /* Start accumulating mbufs in a new pool */
425                                 free[0] = mbuf;
426                                 pool = mbuf->pool;
427                                 blk = 1;
428                         }
429                 }
430         }
431         if (blk)
432                 rte_mempool_put_bulk(pool, (void *)free, blk);
433
434         txr->tx_raw_cons = raw_cons;
435 }
436
437 static int bnxt_handle_tx_cp(struct bnxt_tx_queue *txq)
438 {
439         struct bnxt_cp_ring_info *cpr = txq->cp_ring;
440         uint32_t raw_cons = cpr->cp_raw_cons;
441         uint32_t cons;
442         uint32_t nb_tx_pkts = 0;
443         struct tx_cmpl *txcmp;
444         struct cmpl_base *cp_desc_ring = cpr->cp_desc_ring;
445         struct bnxt_ring *cp_ring_struct = cpr->cp_ring_struct;
446         uint32_t ring_mask = cp_ring_struct->ring_mask;
447         uint32_t opaque = 0;
448
449         if (bnxt_tx_bds_in_hw(txq) < txq->tx_free_thresh)
450                 return 0;
451
452         do {
453                 cons = RING_CMPL(ring_mask, raw_cons);
454                 txcmp = (struct tx_cmpl *)&cpr->cp_desc_ring[cons];
455                 rte_prefetch_non_temporal(&cp_desc_ring[(cons + 2) &
456                                                         ring_mask]);
457
458                 if (!CMPL_VALID(txcmp, cpr->valid))
459                         break;
460                 opaque = rte_cpu_to_le_32(txcmp->opaque);
461                 NEXT_CMPL(cpr, cons, cpr->valid, 1);
462                 rte_prefetch0(&cp_desc_ring[cons]);
463
464                 if (CMP_TYPE(txcmp) == TX_CMPL_TYPE_TX_L2)
465                         nb_tx_pkts += opaque;
466                 else
467                         RTE_LOG_DP(ERR, PMD,
468                                         "Unhandled CMP type %02x\n",
469                                         CMP_TYPE(txcmp));
470                 raw_cons = cons;
471         } while (nb_tx_pkts < ring_mask);
472
473         if (nb_tx_pkts) {
474                 if (txq->offloads & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
475                         bnxt_tx_cmp_fast(txq, nb_tx_pkts);
476                 else
477                         bnxt_tx_cmp(txq, nb_tx_pkts);
478                 cpr->cp_raw_cons = raw_cons;
479                 bnxt_db_cq(cpr);
480         }
481
482         return nb_tx_pkts;
483 }
484
485 uint16_t bnxt_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
486                                uint16_t nb_pkts)
487 {
488         int rc;
489         uint16_t nb_tx_pkts = 0;
490         uint16_t coal_pkts = 0;
491         struct bnxt_tx_queue *txq = tx_queue;
492         struct tx_bd_long *last_txbd = NULL;
493
494         /* Handle TX completions */
495         bnxt_handle_tx_cp(txq);
496
497         /* Tx queue was stopped; wait for it to be restarted */
498         if (unlikely(!txq->tx_started)) {
499                 PMD_DRV_LOG(DEBUG, "Tx q stopped;return\n");
500                 return 0;
501         }
502
503         /* Handle TX burst request */
504         for (nb_tx_pkts = 0; nb_tx_pkts < nb_pkts; nb_tx_pkts++) {
505                 coal_pkts++;
506                 rc = bnxt_start_xmit(tx_pkts[nb_tx_pkts], txq,
507                                      &coal_pkts, &last_txbd);
508
509                 if (unlikely(rc))
510                         break;
511         }
512
513         if (likely(nb_tx_pkts)) {
514                 /* Request a completion on the last packet */
515                 last_txbd->flags_type &= ~TX_BD_LONG_FLAGS_NO_CMPL;
516                 bnxt_db_write(&txq->tx_ring->tx_db, txq->tx_ring->tx_raw_prod);
517         }
518
519         return nb_tx_pkts;
520 }
521
522 /*
523  * Dummy DPDK callback for TX.
524  *
525  * This function is used to temporarily replace the real callback during
526  * unsafe control operations on the queue, or in case of error.
527  */
528 uint16_t
529 bnxt_dummy_xmit_pkts(void *tx_queue __rte_unused,
530                      struct rte_mbuf **tx_pkts __rte_unused,
531                      uint16_t nb_pkts __rte_unused)
532 {
533         return 0;
534 }
535
536 int bnxt_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
537 {
538         struct bnxt *bp = dev->data->dev_private;
539         struct bnxt_tx_queue *txq = bp->tx_queues[tx_queue_id];
540         int rc = 0;
541
542         rc = is_bnxt_in_error(bp);
543         if (rc)
544                 return rc;
545
546         dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
547         txq->tx_started = true;
548         PMD_DRV_LOG(DEBUG, "Tx queue started\n");
549
550         return 0;
551 }
552
553 int bnxt_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
554 {
555         struct bnxt *bp = dev->data->dev_private;
556         struct bnxt_tx_queue *txq = bp->tx_queues[tx_queue_id];
557         int rc = 0;
558
559         rc = is_bnxt_in_error(bp);
560         if (rc)
561                 return rc;
562
563         /* Handle TX completions */
564         bnxt_handle_tx_cp(txq);
565
566         dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
567         txq->tx_started = false;
568         PMD_DRV_LOG(DEBUG, "Tx queue stopped\n");
569
570         return 0;
571 }