Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright (c) 2023 Corigine, Inc. 3 : : * All rights reserved. 4 : : */ 5 : : 6 : : #ifndef __NFP_NFDK_H__ 7 : : #define __NFP_NFDK_H__ 8 : : 9 : : #include <nfp_platform.h> 10 : : 11 : : #include "../nfp_rxtx.h" 12 : : #include "nfp_net_common.h" 13 : : 14 : : #define NFDK_TX_DESC_PER_SIMPLE_PKT 2 15 : : 16 : : #define NFDK_TX_MAX_DATA_PER_HEAD 0x00001000 /* 4K */ 17 : : #define NFDK_TX_MAX_DATA_PER_DESC 0x00004000 /* 16K */ 18 : : #define NFDK_TX_MAX_DATA_PER_BLOCK 0x00010000 /* 64K */ 19 : : 20 : : /* The mask of 'dma_len_xx' of address descriptor */ 21 : : #define NFDK_DESC_TX_DMA_LEN_HEAD 0x0FFF /* [0,11] */ 22 : : #define NFDK_DESC_TX_DMA_LEN 0x3FFF /* [0,13] */ 23 : : 24 : : /* The mask of upper 4 bit of first address descriptor */ 25 : : #define NFDK_DESC_TX_TYPE_HEAD 0xF000 /* [12,15] */ 26 : : 27 : : /* The value of upper 4 bit of first address descriptor */ 28 : : #define NFDK_DESC_TX_TYPE_GATHER 1 29 : : #define NFDK_DESC_TX_TYPE_TSO 2 30 : : #define NFDK_DESC_TX_TYPE_SIMPLE 8 31 : : 32 : : /* The 'end of chain' flag of address descriptor */ 33 : : #define NFDK_DESC_TX_EOP RTE_BIT32(14) 34 : : 35 : : /* Flags in the host metadata descriptor */ 36 : : #define NFDK_DESC_TX_CHAIN_META RTE_BIT32(3) 37 : : #define NFDK_DESC_TX_ENCAP RTE_BIT32(2) 38 : : #define NFDK_DESC_TX_L4_CSUM RTE_BIT32(1) 39 : : #define NFDK_DESC_TX_L3_CSUM RTE_BIT32(0) 40 : : 41 : : #define NFDK_TX_DESC_BLOCK_SZ 256 42 : : #define NFDK_TX_DESC_BLOCK_CNT (NFDK_TX_DESC_BLOCK_SZ / \ 43 : : sizeof(struct nfp_net_nfdk_tx_desc)) 44 : : #define NFDK_TX_DESC_STOP_CNT (NFDK_TX_DESC_BLOCK_CNT * \ 45 : : NFDK_TX_DESC_PER_SIMPLE_PKT) 46 : : #define D_BLOCK_CPL(idx) (NFDK_TX_DESC_BLOCK_CNT - \ 47 : : (idx) % NFDK_TX_DESC_BLOCK_CNT) 48 : : /* Convenience macro for wrapping descriptor index on ring size */ 49 : : #define D_IDX(ring, idx) ((idx) & ((ring)->tx_count - 1)) 50 : : 51 : : /* 52 : : * A full TX descriptor consists of one or more address descriptors, 53 : : * followed by a TX metadata descriptor, and finally a TSO descriptor for 54 : : * TSO packets. 55 : : * 56 : : * --> Header address descriptor: 57 : : * Bit 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 58 : : * -----\ 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 59 : : * Word +-+-+---+-----------------------+-------------------------------+ 60 : : * 0 |S|E| TP| dma_len_12 | dma_addr_hi | 61 : : * +-+-+---+-----------------------+-------------------------------+ 62 : : * 1 | dma_addr_lo | 63 : : * +---------------------------------------------------------------+ 64 : : * 65 : : * --> Subsequent address descriptor(s): 66 : : * Bit 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 67 : : * -----\ 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 68 : : * Word +-+-+---------------------------+-------------------------------+ 69 : : * 0 |S|E| dma_len_14 | dma_addr_hi | 70 : : * +-+-+---------------------------+-------------------------------+ 71 : : * 1 | dma_addr_lo | 72 : : * +---------------------------------------------------------------+ 73 : : * 74 : : * S - Simple Packet descriptor 75 : : * TP - Type of descriptor 76 : : * E - End of chain 77 : : * dma_len - length of the host memory in bytes -1 78 : : * dma_addr_hi - bits [47:32] of host memory address 79 : : * dma_addr_lo - bits [31:0] of host memory address 80 : : * 81 : : * --> Metadata descriptor 82 : : * Bit 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 83 : : * -----\ 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 84 : : * Word +-------+-----------------------+---------------------+---+-----+ 85 : : * 0 | ZERO | Rsvd (64b support) | TBD meta | MT| CSUM| 86 : : * +-------+-----------------------+---------------------+---+-----+ 87 : : * 1 | TBD meta | 88 : : * +---------------------------------------------------------------+ 89 : : * 90 : : * --> TSO descriptor 91 : : * The following is only present if TP above indicates LSO: 92 : : * Bit 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 93 : : * -----\ 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 94 : : * Word +---------------+---------------+---+---------------------------+ 95 : : * 0 | total_segments| header_len |sp0| mss | 96 : : * +---------------+---------------+---+---------------------------+ 97 : : * 1 | sp1 | L4 | L3 | 98 : : * +---------------------------------------------------------------+ 99 : : * 100 : : * total_segments - LSO: Total number of segments 101 : : * header_len - LSO: length of the LSO header in bytes 102 : : * sp0 - Spare Bits (ZERO) 103 : : * mss - LSO: TCP MSS, maximum segment size of TCP payload 104 : : * sp1 - Spare Bits (ZERO) 105 : : * L4 - Layer 4 data 106 : : * L3 - Layer 3 data 107 : : */ 108 : : struct nfp_net_nfdk_tx_desc { 109 : : union { 110 : : /** Address descriptor */ 111 : : struct { 112 : : uint16_t dma_addr_hi; /**< High bits of host buf address */ 113 : : uint16_t dma_len_type; /**< Length to DMA for this desc */ 114 : : uint32_t dma_addr_lo; /**< Low 32bit of host buf addr */ 115 : : }; 116 : : 117 : : /** TSO descriptor */ 118 : : struct { 119 : : uint16_t mss; /**< MSS to be used for LSO */ 120 : : uint8_t lso_hdrlen; /**< LSO, TCP payload offset */ 121 : : uint8_t lso_totsegs; /**< LSO, total segments */ 122 : : uint8_t l3_offset; /**< L3 header offset */ 123 : : uint8_t l4_offset; /**< L4 header offset */ 124 : : uint16_t lso_meta_res; /**< Rsvd bits in TSO metadata */ 125 : : }; 126 : : 127 : : /** Metadata descriptor */ 128 : : struct { 129 : : uint8_t flags; /**< TX Flags, see @NFDK_DESC_TX_* */ 130 : : uint8_t reserved[7]; /**< Meta byte place holder */ 131 : : }; 132 : : 133 : : uint32_t vals[2]; 134 : : uint64_t raw; 135 : : }; 136 : : }; 137 : : 138 : : static inline uint32_t 139 : : nfp_net_nfdk_free_tx_desc(struct nfp_net_txq *txq) 140 : : { 141 : : uint32_t free_desc; 142 : : 143 [ # # # # : 0 : if (txq->wr_p >= txq->rd_p) # # ] 144 : 0 : free_desc = txq->tx_count - (txq->wr_p - txq->rd_p); 145 : : else 146 : 0 : free_desc = txq->rd_p - txq->wr_p; 147 : : 148 : : return (free_desc > NFDK_TX_DESC_STOP_CNT) ? 149 [ # # # # ]: 0 : (free_desc - NFDK_TX_DESC_STOP_CNT) : 0; 150 : : } 151 : : 152 : : /** 153 : : * Check if the TX queue free descriptors is below tx_free_threshold 154 : : * for firmware of nfdk 155 : : * 156 : : * This function uses the host copy* of read/write pointers. 157 : : * 158 : : * @param txq 159 : : * TX queue to check 160 : : */ 161 : : static inline bool 162 : : nfp_net_nfdk_txq_full(struct nfp_net_txq *txq) 163 : : { 164 [ # # ]: 0 : return (nfp_net_nfdk_free_tx_desc(txq) < txq->tx_free_thresh); 165 : : } 166 : : 167 : : static inline uint16_t 168 : : nfp_net_nfdk_headlen_to_segs(uint16_t headlen) 169 : : { 170 : : /* First descriptor fits less data, so adjust for that */ 171 : 0 : return DIV_ROUND_UP(headlen + NFDK_TX_MAX_DATA_PER_DESC - NFDK_TX_MAX_DATA_PER_HEAD, 172 : : NFDK_TX_MAX_DATA_PER_DESC); 173 : : } 174 : : 175 : : /* Set TX CSUM offload flags in TX descriptor of nfdk */ 176 : : static inline uint64_t 177 : 0 : nfp_net_nfdk_tx_cksum(struct nfp_net_txq *txq, 178 : : struct rte_mbuf *mb, 179 : : uint64_t flags) 180 : : { 181 : : uint64_t ol_flags; 182 : 0 : struct nfp_net_hw *hw = txq->hw; 183 : : 184 [ # # ]: 0 : if ((hw->super.cap & NFP_NET_CFG_CTRL_TXCSUM) == 0) 185 : : return flags; 186 : : 187 : 0 : ol_flags = mb->ol_flags; 188 : : 189 : : /* Set TCP csum offload if TSO enabled. */ 190 [ # # ]: 0 : if ((ol_flags & RTE_MBUF_F_TX_TCP_SEG) != 0) 191 : 0 : flags |= NFDK_DESC_TX_L4_CSUM; 192 : : 193 [ # # ]: 0 : if ((ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) != 0) 194 : 0 : flags |= NFDK_DESC_TX_ENCAP; 195 : : 196 : : /* IPv6 does not need checksum */ 197 [ # # ]: 0 : if ((ol_flags & RTE_MBUF_F_TX_IP_CKSUM) != 0) 198 : 0 : flags |= NFDK_DESC_TX_L3_CSUM; 199 : : 200 [ # # ]: 0 : if ((ol_flags & RTE_MBUF_F_TX_L4_MASK) != 0) 201 : 0 : flags |= NFDK_DESC_TX_L4_CSUM; 202 : : 203 : : return flags; 204 : : } 205 : : 206 : : uint32_t nfp_flower_nfdk_pkt_add_metadata(struct rte_mbuf *mbuf, 207 : : uint32_t port_id); 208 : : uint16_t nfp_net_nfdk_xmit_pkts_common(void *tx_queue, 209 : : struct rte_mbuf **tx_pkts, 210 : : uint16_t nb_pkts, 211 : : bool repr_flag); 212 : : uint16_t nfp_net_nfdk_xmit_pkts(void *tx_queue, 213 : : struct rte_mbuf **tx_pkts, 214 : : uint16_t nb_pkts); 215 : : int nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev, 216 : : uint16_t queue_idx, 217 : : uint16_t nb_desc, 218 : : unsigned int socket_id, 219 : : const struct rte_eth_txconf *tx_conf); 220 : : int nfp_net_nfdk_tx_maybe_close_block(struct nfp_net_txq *txq, 221 : : struct rte_mbuf *pkt); 222 : : int nfp_net_nfdk_set_meta_data(struct rte_mbuf *pkt, 223 : : struct nfp_net_txq *txq, 224 : : uint64_t *metadata); 225 : : void nfp_net_nfdk_xmit_pkts_set(struct rte_eth_dev *eth_dev); 226 : : 227 : : #endif /* __NFP_NFDK_H__ */