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