Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright (c) 2014-2021 Netronome Systems, Inc. 3 : : * All rights reserved. 4 : : */ 5 : : 6 : : #ifndef __NFP_RXTX_H__ 7 : : #define __NFP_RXTX_H__ 8 : : 9 : : #include <ethdev_driver.h> 10 : : 11 : : /* Descriptor alignment */ 12 : : #define NFP_ALIGN_RING_DESC 128 13 : : 14 : : struct nfp_net_dp_buf { 15 : : struct rte_mbuf *mbuf; 16 : : }; 17 : : 18 : : struct nfp_tx_ipsec_desc_msg { 19 : : uint32_t sa_idx; /**< SA index in driver table */ 20 : : uint32_t enc; /**< IPsec enable flag */ 21 : : union { 22 : : uint64_t value; 23 : : struct { 24 : : uint32_t low; 25 : : uint32_t hi; 26 : : }; 27 : : } esn; /**< Extended Sequence Number */ 28 : : }; 29 : : 30 : : struct nfp_net_txq { 31 : : /** Backpointer to nfp_net structure */ 32 : : struct nfp_net_hw *hw; 33 : : 34 : : /** Point to the base of the queue structure on the NFP. */ 35 : : uint8_t *qcp_q; 36 : : 37 : : /** 38 : : * Host side read and write pointer, they are free running and 39 : : * have little relation to the QCP pointers. 40 : : */ 41 : : uint32_t wr_p; 42 : : uint32_t rd_p; 43 : : 44 : : /** The size of the queue in number of descriptors. */ 45 : : uint32_t tx_count; 46 : : 47 : : uint32_t tx_free_thresh; 48 : : 49 : : /** 50 : : * For each descriptor keep a reference to the mbuf and 51 : : * DMA address used until completion is signalled. 52 : : */ 53 : : struct nfp_net_dp_buf *txbufs; 54 : : 55 : : /** 56 : : * Information about the host side queue location. 57 : : * It is the virtual address for the queue. 58 : : */ 59 : : union { 60 : : struct nfp_net_nfd3_tx_desc *txds; 61 : : struct nfp_net_nfdk_tx_desc *ktxds; 62 : : }; 63 : : 64 : : /** The index of the QCP queue relative to the TX queue BAR. */ 65 : : uint32_t tx_qcidx; 66 : : 67 : : /** The queue index from Linux's perspective. */ 68 : : uint16_t qidx; 69 : : uint16_t port_id; 70 : : 71 : : /** Used by NFDk only */ 72 : : uint16_t data_pending; 73 : : 74 : : /** 75 : : * At this point 58 bytes have been used for all the fields in the 76 : : * TX critical path. We have room for 6 bytes and still all placed 77 : : * in a cache line. 78 : : */ 79 : : uint64_t dma; 80 : : } __rte_aligned(64); 81 : : 82 : : /* RX and freelist descriptor format */ 83 : : #define PCIE_DESC_RX_DD (1 << 7) 84 : : #define PCIE_DESC_RX_META_LEN_MASK (0x7f) 85 : : 86 : : /* Flags in the RX descriptor */ 87 : : #define PCIE_DESC_RX_RSS (1 << 15) 88 : : #define PCIE_DESC_RX_I_IP4_CSUM (1 << 14) 89 : : #define PCIE_DESC_RX_I_IP4_CSUM_OK (1 << 13) 90 : : #define PCIE_DESC_RX_I_TCP_CSUM (1 << 12) 91 : : #define PCIE_DESC_RX_I_TCP_CSUM_OK (1 << 11) 92 : : #define PCIE_DESC_RX_I_UDP_CSUM (1 << 10) 93 : : #define PCIE_DESC_RX_I_UDP_CSUM_OK (1 << 9) 94 : : #define PCIE_DESC_RX_SPARE (1 << 8) 95 : : #define PCIE_DESC_RX_EOP (1 << 7) 96 : : #define PCIE_DESC_RX_IP4_CSUM (1 << 6) 97 : : #define PCIE_DESC_RX_IP4_CSUM_OK (1 << 5) 98 : : #define PCIE_DESC_RX_TCP_CSUM (1 << 4) 99 : : #define PCIE_DESC_RX_TCP_CSUM_OK (1 << 3) 100 : : #define PCIE_DESC_RX_UDP_CSUM (1 << 2) 101 : : #define PCIE_DESC_RX_UDP_CSUM_OK (1 << 1) 102 : : #define PCIE_DESC_RX_VLAN (1 << 0) 103 : : 104 : : #define PCIE_DESC_RX_L4_CSUM_OK (PCIE_DESC_RX_TCP_CSUM_OK | \ 105 : : PCIE_DESC_RX_UDP_CSUM_OK) 106 : : 107 : : struct nfp_net_rx_desc { 108 : : union { 109 : : /** Freelist descriptor. */ 110 : : struct { 111 : : uint16_t dma_addr_hi; /**< High bits of buffer address. */ 112 : : uint8_t spare; /**< Reserved, must be zero. */ 113 : : uint8_t dd; /**< Whether descriptor available. */ 114 : : uint32_t dma_addr_lo; /**< Low bits of buffer address. */ 115 : : } __rte_packed fld; 116 : : 117 : : /** RX descriptor. */ 118 : : struct { 119 : : uint16_t data_len; /**< Length of frame + metadata. */ 120 : : uint8_t reserved; /**< Reserved, must be zero. */ 121 : : uint8_t meta_len_dd; /**< Length of metadata + done flag. */ 122 : : 123 : : uint16_t flags; /**< RX flags. */ 124 : : uint16_t offload_info; /**< Offloading info. */ 125 : : } __rte_packed rxd; 126 : : 127 : : /** Reserved. */ 128 : : uint32_t vals[2]; 129 : : }; 130 : : }; 131 : : 132 : : struct nfp_net_rxq { 133 : : /** Backpointer to nfp_net structure */ 134 : : struct nfp_net_hw *hw; 135 : : 136 : : /** 137 : : * Point to the base addresses of the freelist queue 138 : : * controller peripheral queue structures on the NFP. 139 : : */ 140 : : uint8_t *qcp_fl; 141 : : 142 : : /** 143 : : * Host side read pointer, free running and have little relation 144 : : * to the QCP pointers. It is where the driver start reading 145 : : * descriptors for newly arrive packets from. 146 : : */ 147 : : uint32_t rd_p; 148 : : 149 : : /** 150 : : * The index of the QCP queue relative to the RX queue BAR 151 : : * used for the freelist. 152 : : */ 153 : : uint32_t fl_qcidx; 154 : : 155 : : /** 156 : : * For each buffer placed on the freelist, record the 157 : : * associated mbuf. 158 : : */ 159 : : struct nfp_net_dp_buf *rxbufs; 160 : : 161 : : /** 162 : : * Information about the host side queue location. 163 : : * It is the virtual address for the queue. 164 : : */ 165 : : struct nfp_net_rx_desc *rxds; 166 : : 167 : : /** 168 : : * The mempool is created by the user specifying a mbuf size. 169 : : * We save here the reference of the mempool needed in the RX 170 : : * path and the mbuf size for checking received packets can be 171 : : * safely copied to the mbuf using the NFP_NET_RX_OFFSET. 172 : : */ 173 : : struct rte_mempool *mem_pool; 174 : : uint16_t mbuf_size; 175 : : 176 : : /** 177 : : * Next two fields are used for giving more free descriptors 178 : : * to the NFP. 179 : : */ 180 : : uint16_t rx_free_thresh; 181 : : uint16_t nb_rx_hold; 182 : : 183 : : /** The size of the queue in number of descriptors */ 184 : : uint16_t rx_count; 185 : : 186 : : /** Referencing dev->data->port_id */ 187 : : uint16_t port_id; 188 : : 189 : : /** The queue index from Linux's perspective */ 190 : : uint16_t qidx; 191 : : 192 : : /** 193 : : * At this point 60 bytes have been used for all the fields in the 194 : : * RX critical path. We have room for 4 bytes and still all placed 195 : : * in a cache line. 196 : : */ 197 : : 198 : : /** DMA address of the queue */ 199 : : uint64_t dma; 200 : : } __rte_aligned(64); 201 : : 202 : : static inline void 203 : : nfp_net_mbuf_alloc_failed(struct nfp_net_rxq *rxq) 204 : : { 205 : 0 : rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++; 206 : 0 : } 207 : : 208 : : void nfp_net_rx_cksum(struct nfp_net_rxq *rxq, struct nfp_net_rx_desc *rxd, 209 : : struct rte_mbuf *mb); 210 : : int nfp_net_rx_freelist_setup(struct rte_eth_dev *dev); 211 : : uint32_t nfp_net_rx_queue_count(void *rx_queue); 212 : : uint16_t nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, 213 : : uint16_t nb_pkts); 214 : : void nfp_net_rx_queue_release(struct rte_eth_dev *dev, uint16_t queue_idx); 215 : : void nfp_net_reset_rx_queue(struct nfp_net_rxq *rxq); 216 : : int nfp_net_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx, 217 : : uint16_t nb_desc, unsigned int socket_id, 218 : : const struct rte_eth_rxconf *rx_conf, 219 : : struct rte_mempool *mp); 220 : : void nfp_net_tx_queue_release(struct rte_eth_dev *dev, uint16_t queue_idx); 221 : : void nfp_net_reset_tx_queue(struct nfp_net_txq *txq); 222 : : 223 : : int nfp_net_tx_queue_setup(struct rte_eth_dev *dev, 224 : : uint16_t queue_idx, 225 : : uint16_t nb_desc, 226 : : unsigned int socket_id, 227 : : const struct rte_eth_txconf *tx_conf); 228 : : uint32_t nfp_net_tx_free_bufs(struct nfp_net_txq *txq); 229 : : 230 : : #endif /* __NFP_RXTX_H__ */