1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2020 Broadcom
6 #ifndef _BNXT_RXTX_VEC_COMMON_H_
7 #define _BNXT_RXTX_VEC_COMMON_H_
8 #include "hsi_struct_def_dpdk.h"
12 #define TX_BD_FLAGS_CMPL ((1 << TX_BD_LONG_FLAGS_BD_CNT_SFT) | \
13 TX_BD_SHORT_FLAGS_COAL_NOW | \
14 TX_BD_SHORT_TYPE_TX_BD_SHORT | \
15 TX_BD_LONG_FLAGS_PACKET_END)
17 #define TX_BD_FLAGS_NOCMPL (TX_BD_FLAGS_CMPL | TX_BD_LONG_FLAGS_NO_CMPL)
19 static inline uint32_t
20 bnxt_xmit_flags_len(uint16_t len, uint16_t flags)
24 return flags | TX_BD_LONG_FLAGS_LHINT_LT512;
26 return flags | TX_BD_LONG_FLAGS_LHINT_LT1K;
28 return flags | TX_BD_LONG_FLAGS_LHINT_LT2K;
30 return flags | TX_BD_LONG_FLAGS_LHINT_LT2K;
32 return flags | TX_BD_LONG_FLAGS_LHINT_GTE2K;
37 bnxt_rxq_vec_setup_common(struct bnxt_rx_queue *rxq)
40 struct rte_mbuf mb_def = { .buf_addr = 0 }; /* zeroed mbuf */
43 mb_def.data_off = RTE_PKTMBUF_HEADROOM;
44 mb_def.port = rxq->port_id;
45 rte_mbuf_refcnt_set(&mb_def, 1);
47 /* prevent compiler reordering: rearm_data covers previous fields */
48 rte_compiler_barrier();
49 p = (uintptr_t)&mb_def.rearm_data;
50 rxq->mbuf_initializer = *(uint64_t *)p;
52 rxq->rxrearm_start = 0;
57 bnxt_rxq_rearm(struct bnxt_rx_queue *rxq, struct bnxt_rx_ring_info *rxr)
59 struct rx_prod_pkt_bd *rxbds = &rxr->rx_desc_ring[rxq->rxrearm_start];
60 struct rte_mbuf **rx_bufs = &rxr->rx_buf_ring[rxq->rxrearm_start];
64 * Number of mbufs to allocate must be a multiple of four. The
65 * allocation must not go past the end of the ring.
67 nb = RTE_MIN(rxq->rxrearm_nb & ~0x3,
68 rxq->nb_rx_desc - rxq->rxrearm_start);
70 /* Allocate new mbufs into the software ring. */
71 if (rte_mempool_get_bulk(rxq->mb_pool, (void *)rx_bufs, nb) < 0) {
72 rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed += nb;
74 for (i = 0; i < nb; i++)
75 rx_bufs[i] = &rxq->fake_mbuf;
79 /* Initialize the mbufs in vector, process 4 mbufs per loop. */
80 for (i = 0; i < nb; i += 4) {
81 rxbds[0].address = rte_mbuf_data_iova_default(rx_bufs[0]);
82 rxbds[1].address = rte_mbuf_data_iova_default(rx_bufs[1]);
83 rxbds[2].address = rte_mbuf_data_iova_default(rx_bufs[2]);
84 rxbds[3].address = rte_mbuf_data_iova_default(rx_bufs[3]);
90 rxq->rxrearm_start += nb;
91 bnxt_db_write(&rxr->rx_db, rxq->rxrearm_start - 1);
92 if (rxq->rxrearm_start >= rxq->nb_rx_desc)
93 rxq->rxrearm_start = 0;
95 rxq->rxrearm_nb -= nb;
99 * Transmit completion function for use when DEV_TX_OFFLOAD_MBUF_FAST_FREE
103 bnxt_tx_cmp_vec_fast(struct bnxt_tx_queue *txq, int nr_pkts)
105 struct bnxt_tx_ring_info *txr = txq->tx_ring;
106 uint32_t ring_mask = txr->tx_ring_struct->ring_mask;
107 struct rte_mbuf **free = txq->free;
108 uint16_t cons = txr->tx_cons;
109 unsigned int blk = 0;
112 struct bnxt_sw_tx_bd *tx_buf;
114 tx_buf = &txr->tx_buf_ring[cons];
115 cons = (cons + 1) & ring_mask;
116 free[blk++] = tx_buf->mbuf;
120 rte_mempool_put_bulk(free[0]->pool, (void **)free, blk);
126 bnxt_tx_cmp_vec(struct bnxt_tx_queue *txq, int nr_pkts)
128 struct bnxt_tx_ring_info *txr = txq->tx_ring;
129 struct rte_mbuf **free = txq->free;
130 uint16_t cons = txr->tx_cons;
131 unsigned int blk = 0;
132 uint32_t ring_mask = txr->tx_ring_struct->ring_mask;
135 struct bnxt_sw_tx_bd *tx_buf;
136 struct rte_mbuf *mbuf;
138 tx_buf = &txr->tx_buf_ring[cons];
139 cons = (cons + 1) & ring_mask;
140 mbuf = rte_pktmbuf_prefree_seg(tx_buf->mbuf);
141 if (unlikely(mbuf == NULL))
145 if (blk && mbuf->pool != free[0]->pool) {
146 rte_mempool_put_bulk(free[0]->pool, (void **)free, blk);
152 rte_mempool_put_bulk(free[0]->pool, (void **)free, blk);
156 #endif /* _BNXT_RXTX_VEC_COMMON_H_ */