cae9c2458b4e5976d9e116671dc3682502636758
[dpdk.git] / drivers / net / bnxt / bnxt_rxtx_vec_common.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _BNXT_RXTX_VEC_COMMON_H_
7 #define _BNXT_RXTX_VEC_COMMON_H_
8 #include "hsi_struct_def_dpdk.h"
9 #include "bnxt_rxq.h"
10 #include "bnxt_rxr.h"
11
12 #define RTE_BNXT_DESCS_PER_LOOP         4U
13
14 #define TX_BD_FLAGS_CMPL ((1 << TX_BD_LONG_FLAGS_BD_CNT_SFT) | \
15                           TX_BD_SHORT_FLAGS_COAL_NOW | \
16                           TX_BD_SHORT_TYPE_TX_BD_SHORT | \
17                           TX_BD_LONG_FLAGS_PACKET_END)
18
19 #define TX_BD_FLAGS_NOCMPL (TX_BD_FLAGS_CMPL | TX_BD_LONG_FLAGS_NO_CMPL)
20
21 static inline uint32_t
22 bnxt_xmit_flags_len(uint16_t len, uint16_t flags)
23 {
24         switch (len >> 9) {
25         case 0:
26                 return flags | TX_BD_LONG_FLAGS_LHINT_LT512;
27         case 1:
28                 return flags | TX_BD_LONG_FLAGS_LHINT_LT1K;
29         case 2:
30                 return flags | TX_BD_LONG_FLAGS_LHINT_LT2K;
31         case 3:
32                 return flags | TX_BD_LONG_FLAGS_LHINT_LT2K;
33         default:
34                 return flags | TX_BD_LONG_FLAGS_LHINT_GTE2K;
35         }
36 }
37
38 static inline int
39 bnxt_rxq_vec_setup_common(struct bnxt_rx_queue *rxq)
40 {
41         uintptr_t p;
42         struct rte_mbuf mb_def = { .buf_addr = 0 }; /* zeroed mbuf */
43
44         mb_def.nb_segs = 1;
45         mb_def.data_off = RTE_PKTMBUF_HEADROOM;
46         mb_def.port = rxq->port_id;
47         rte_mbuf_refcnt_set(&mb_def, 1);
48
49         /* prevent compiler reordering: rearm_data covers previous fields */
50         rte_compiler_barrier();
51         p = (uintptr_t)&mb_def.rearm_data;
52         rxq->mbuf_initializer = *(uint64_t *)p;
53         rxq->rxrearm_nb = 0;
54         rxq->rxrearm_start = 0;
55         return 0;
56 }
57 #endif /* _BNXT_RXTX_VEC_COMMON_H_ */