Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(C) 2022 Marvell. 3 : : */ 4 : : #ifndef __CNXK_ETHDEV_DP_H__ 5 : : #define __CNXK_ETHDEV_DP_H__ 6 : : 7 : : #include <rte_mbuf.h> 8 : : 9 : : /* If PTP is enabled additional SEND MEM DESC is required which 10 : : * takes 2 words, hence max 7 iova address are possible 11 : : */ 12 : : #if defined(RTE_LIBRTE_IEEE1588) 13 : : #define CNXK_NIX_TX_NB_SEG_MAX 7 14 : : #else 15 : : #define CNXK_NIX_TX_NB_SEG_MAX 9 16 : : #endif 17 : : 18 : : #define CNXK_NIX_TX_MSEG_SG_DWORDS \ 19 : : ((RTE_ALIGN_MUL_CEIL(CNXK_NIX_TX_NB_SEG_MAX, 3) / 3) + \ 20 : : CNXK_NIX_TX_NB_SEG_MAX) 21 : : 22 : : /* Default mark value used when none is provided. */ 23 : : #define CNXK_FLOW_ACTION_FLAG_DEFAULT 0xffff 24 : : #define CNXK_NIX_TIMESYNC_RX_OFFSET 8 25 : : 26 : : #define PTYPE_NON_TUNNEL_WIDTH 16 27 : : #define PTYPE_TUNNEL_WIDTH 12 28 : : #define PTYPE_NON_TUNNEL_ARRAY_SZ BIT(PTYPE_NON_TUNNEL_WIDTH) 29 : : #define PTYPE_TUNNEL_ARRAY_SZ BIT(PTYPE_TUNNEL_WIDTH) 30 : : #define PTYPE_ARRAY_SZ \ 31 : : ((PTYPE_NON_TUNNEL_ARRAY_SZ + PTYPE_TUNNEL_ARRAY_SZ) * sizeof(uint16_t)) 32 : : 33 : : /* NIX_RX_PARSE_S's ERRCODE + ERRLEV (12 bits) */ 34 : : #define ERRCODE_ERRLEN_WIDTH 12 35 : : #define ERR_ARRAY_SZ ((BIT(ERRCODE_ERRLEN_WIDTH)) * sizeof(uint32_t)) 36 : : 37 : : #define SA_BASE_TBL_SZ (RTE_MAX_ETHPORTS * sizeof(uintptr_t)) 38 : : #define MEMPOOL_TBL_SZ (RTE_MAX_ETHPORTS * sizeof(uintptr_t)) 39 : : 40 : : #define CNXK_NIX_UDP_TUN_BITMASK \ 41 : : ((1ull << (RTE_MBUF_F_TX_TUNNEL_VXLAN >> 45)) | \ 42 : : (1ull << (RTE_MBUF_F_TX_TUNNEL_GENEVE >> 45))) 43 : : 44 : : /* Subtype from inline outbound error event */ 45 : : #define CNXK_ETHDEV_SEC_OUTB_EV_SUB 0xFFUL 46 : : 47 : : /* SPI will be in 20 bits of tag */ 48 : : #define CNXK_ETHDEV_SPI_TAG_MASK 0xFFFFFUL 49 : : 50 : : #define CNXK_NIX_PFC_CHAN_COUNT 16 51 : : 52 : : #define CNXK_TM_MARK_VLAN_DEI BIT_ULL(0) 53 : : #define CNXK_TM_MARK_IP_DSCP BIT_ULL(1) 54 : : #define CNXK_TM_MARK_IP_ECN BIT_ULL(2) 55 : : 56 : : #define CNXK_TM_MARK_MASK \ 57 : : (CNXK_TM_MARK_VLAN_DEI | CNXK_TM_MARK_IP_DSCP | CNXK_TM_MARK_IP_ECN) 58 : : 59 : : #define CNXK_TX_MARK_FMT_MASK (0xFFFFFFFFFFFFull) 60 : : 61 : : struct cnxk_eth_txq_comp { 62 : : uintptr_t desc_base; 63 : : uintptr_t cq_door; 64 : : int64_t *cq_status; 65 : : uint64_t wdata; 66 : : uint32_t head; 67 : : uint32_t qmask; 68 : : uint32_t nb_desc_mask; 69 : : uint32_t available; 70 : : uint32_t sqe_id; 71 : : bool ena; 72 : : struct rte_mbuf **ptr; 73 : : rte_spinlock_t ext_buf_lock; 74 : : }; 75 : : 76 : : struct cnxk_timesync_info { 77 : : uint8_t rx_ready; 78 : : uint64_t rx_tstamp; 79 : : uint64_t rx_tstamp_dynflag; 80 : : int tstamp_dynfield_offset; 81 : : rte_iova_t tx_tstamp_iova; 82 : : uint64_t *tx_tstamp; 83 : : } __plt_cache_aligned; 84 : : 85 : : /* Inlines */ 86 : : static __rte_always_inline uint64_t 87 : : cnxk_pktmbuf_detach(struct rte_mbuf *m) 88 : : { 89 : : struct rte_mempool *mp = m->pool; 90 : : uint32_t mbuf_size, buf_len; 91 : : struct rte_mbuf *md; 92 : : uint16_t priv_size; 93 : : uint16_t refcount; 94 : : 95 : : /* Update refcount of direct mbuf */ 96 : : md = rte_mbuf_from_indirect(m); 97 : : refcount = rte_mbuf_refcnt_update(md, -1); 98 : : 99 : : priv_size = rte_pktmbuf_priv_size(mp); 100 : : mbuf_size = (uint32_t)(sizeof(struct rte_mbuf) + priv_size); 101 : : buf_len = rte_pktmbuf_data_room_size(mp); 102 : : 103 : : m->priv_size = priv_size; 104 : : m->buf_addr = (char *)m + mbuf_size; 105 : : rte_mbuf_iova_set(m, rte_mempool_virt2iova(m) + mbuf_size); 106 : : m->buf_len = (uint16_t)buf_len; 107 : : rte_pktmbuf_reset_headroom(m); 108 : : m->data_len = 0; 109 : : m->ol_flags = 0; 110 : : m->next = NULL; 111 : : m->nb_segs = 1; 112 : : 113 : : /* Now indirect mbuf is safe to free */ 114 : : rte_pktmbuf_free(m); 115 : : 116 : : if (refcount == 0) { 117 : : rte_mbuf_refcnt_set(md, 1); 118 : : md->data_len = 0; 119 : : md->ol_flags = 0; 120 : : md->next = NULL; 121 : : md->nb_segs = 1; 122 : : return 0; 123 : : } else { 124 : : return 1; 125 : : } 126 : : } 127 : : 128 : : static __rte_always_inline uint64_t 129 : : cnxk_nix_prefree_seg(struct rte_mbuf *m) 130 : : { 131 : : if (likely(rte_mbuf_refcnt_read(m) == 1)) { 132 : : if (!RTE_MBUF_DIRECT(m)) 133 : : return cnxk_pktmbuf_detach(m); 134 : : 135 : : m->next = NULL; 136 : : m->nb_segs = 1; 137 : : return 0; 138 : : } else if (rte_mbuf_refcnt_update(m, -1) == 0) { 139 : : if (!RTE_MBUF_DIRECT(m)) 140 : : return cnxk_pktmbuf_detach(m); 141 : : 142 : : rte_mbuf_refcnt_set(m, 1); 143 : : m->next = NULL; 144 : : m->nb_segs = 1; 145 : : return 0; 146 : : } 147 : : 148 : : /* Mbuf is having refcount more than 1 so need not to be freed */ 149 : : return 1; 150 : : } 151 : : 152 : : static inline rte_mbuf_timestamp_t * 153 : : cnxk_nix_timestamp_dynfield(struct rte_mbuf *mbuf, 154 : : struct cnxk_timesync_info *info) 155 : : { 156 [ # # ]: 0 : return RTE_MBUF_DYNFIELD(mbuf, info->tstamp_dynfield_offset, 157 : : rte_mbuf_timestamp_t *); 158 : : } 159 : : 160 : : static __rte_always_inline uintptr_t 161 : : cnxk_nix_sa_base_get(uint16_t port, const void *lookup_mem) 162 : : { 163 : : uintptr_t sa_base_tbl; 164 : : 165 : 0 : sa_base_tbl = (uintptr_t)lookup_mem; 166 : 0 : sa_base_tbl += PTYPE_ARRAY_SZ + ERR_ARRAY_SZ; 167 [ # # # # : 0 : return *((const uintptr_t *)sa_base_tbl + port); # # ] 168 : : } 169 : : 170 : : static __rte_always_inline uintptr_t 171 : : cnxk_nix_inl_metapool_get(uint16_t port, const void *lookup_mem) 172 : : { 173 : : uintptr_t metapool_tbl; 174 : : 175 : 0 : metapool_tbl = (uintptr_t)lookup_mem; 176 : 0 : metapool_tbl += PTYPE_ARRAY_SZ + ERR_ARRAY_SZ + SA_BASE_TBL_SZ; 177 [ # # # # : 0 : return *((const uintptr_t *)metapool_tbl + port); # # # # # # # # ] 178 : : } 179 : : 180 : : #endif /* __CNXK_ETHDEV_DP_H__ */