1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2014-2018 Netronome Systems, Inc.
7 * vim:shiftwidth=8:noexpandtab
9 * @file dpdk/pmd/nfp_net_pmd.h
11 * Netronome NFP_NET PMD driver
14 #ifndef _NFP_NET_PMD_H_
15 #define _NFP_NET_PMD_H_
17 #define NFP_NET_PMD_VERSION "0.1"
18 #define PCI_VENDOR_ID_NETRONOME 0x19ee
19 #define PCI_DEVICE_ID_NFP4000_PF_NIC 0x4000
20 #define PCI_DEVICE_ID_NFP6000_PF_NIC 0x6000
21 #define PCI_DEVICE_ID_NFP6000_VF_NIC 0x6003
23 /* Forward declaration */
24 struct nfp_net_adapter;
27 * The maximum number of descriptors is limited by design as
28 * DPDK uses uint16_t variables for these values
30 #define NFP_NET_MAX_TX_DESC (32 * 1024)
31 #define NFP_NET_MIN_TX_DESC 64
33 #define NFP_NET_MAX_RX_DESC (32 * 1024)
34 #define NFP_NET_MIN_RX_DESC 64
37 #define NFP_NET_CRTL_BAR 0
38 #define NFP_NET_TX_BAR 2
39 #define NFP_NET_RX_BAR 2
40 #define NFP_QCP_QUEUE_AREA_SZ 0x80000
42 /* Macros for accessing the Queue Controller Peripheral 'CSRs' */
43 #define NFP_QCP_QUEUE_OFF(_x) ((_x) * 0x800)
44 #define NFP_QCP_QUEUE_ADD_RPTR 0x0000
45 #define NFP_QCP_QUEUE_ADD_WPTR 0x0004
46 #define NFP_QCP_QUEUE_STS_LO 0x0008
47 #define NFP_QCP_QUEUE_STS_LO_READPTR_mask (0x3ffff)
48 #define NFP_QCP_QUEUE_STS_HI 0x000c
49 #define NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask (0x3ffff)
51 /* Interrupt definitions */
52 #define NFP_NET_IRQ_LSC_IDX 0
54 /* Default values for RX/TX configuration */
55 #define DEFAULT_RX_FREE_THRESH 32
56 #define DEFAULT_RX_PTHRESH 8
57 #define DEFAULT_RX_HTHRESH 8
58 #define DEFAULT_RX_WTHRESH 0
60 #define DEFAULT_TX_RS_THRESH 32
61 #define DEFAULT_TX_FREE_THRESH 32
62 #define DEFAULT_TX_PTHRESH 32
63 #define DEFAULT_TX_HTHRESH 0
64 #define DEFAULT_TX_WTHRESH 0
65 #define DEFAULT_TX_RSBIT_THRESH 32
67 /* Alignment for dma zones */
68 #define NFP_MEMZONE_ALIGN 128
71 * This is used by the reconfig protocol. It sets the maximum time waiting in
72 * milliseconds before a reconfig timeout happens.
74 #define NFP_NET_POLL_TIMEOUT 5000
76 #define NFP_QCP_QUEUE_ADDR_SZ (0x800)
78 #define NFP_NET_LINK_DOWN_CHECK_TIMEOUT 4000 /* ms */
79 #define NFP_NET_LINK_UP_CHECK_TIMEOUT 1000 /* ms */
81 /* Version number helper defines */
82 #define NFD_CFG_CLASS_VER_msk 0xff
83 #define NFD_CFG_CLASS_VER_shf 24
84 #define NFD_CFG_CLASS_VER(x) (((x) & 0xff) << 24)
85 #define NFD_CFG_CLASS_VER_of(x) (((x) >> 24) & 0xff)
86 #define NFD_CFG_CLASS_TYPE_msk 0xff
87 #define NFD_CFG_CLASS_TYPE_shf 16
88 #define NFD_CFG_CLASS_TYPE(x) (((x) & 0xff) << 16)
89 #define NFD_CFG_CLASS_TYPE_of(x) (((x) >> 16) & 0xff)
90 #define NFD_CFG_MAJOR_VERSION_msk 0xff
91 #define NFD_CFG_MAJOR_VERSION_shf 8
92 #define NFD_CFG_MAJOR_VERSION(x) (((x) & 0xff) << 8)
93 #define NFD_CFG_MAJOR_VERSION_of(x) (((x) >> 8) & 0xff)
94 #define NFD_CFG_MINOR_VERSION_msk 0xff
95 #define NFD_CFG_MINOR_VERSION_shf 0
96 #define NFD_CFG_MINOR_VERSION(x) (((x) & 0xff) << 0)
97 #define NFD_CFG_MINOR_VERSION_of(x) (((x) >> 0) & 0xff)
99 #include <linux/types.h>
102 static inline uint8_t nn_readb(volatile const void *addr)
104 return rte_read8(addr);
107 static inline void nn_writeb(uint8_t val, volatile void *addr)
109 rte_write8(val, addr);
112 static inline uint32_t nn_readl(volatile const void *addr)
114 return rte_read32(addr);
117 static inline void nn_writel(uint32_t val, volatile void *addr)
119 rte_write32(val, addr);
122 static inline void nn_writew(uint16_t val, volatile void *addr)
124 rte_write16(val, addr);
127 static inline uint64_t nn_readq(volatile void *addr)
129 const volatile uint32_t *p = addr;
132 high = nn_readl((volatile const void *)(p + 1));
133 low = nn_readl((volatile const void *)p);
135 return low + ((uint64_t)high << 32);
138 static inline void nn_writeq(uint64_t val, volatile void *addr)
140 nn_writel(val >> 32, (volatile char *)addr + 4);
141 nn_writel(val, addr);
144 /* TX descriptor format */
145 #define PCIE_DESC_TX_EOP (1 << 7)
146 #define PCIE_DESC_TX_OFFSET_MASK (0x7f)
148 /* Flags in the host TX descriptor */
149 #define PCIE_DESC_TX_CSUM (1 << 7)
150 #define PCIE_DESC_TX_IP4_CSUM (1 << 6)
151 #define PCIE_DESC_TX_TCP_CSUM (1 << 5)
152 #define PCIE_DESC_TX_UDP_CSUM (1 << 4)
153 #define PCIE_DESC_TX_VLAN (1 << 3)
154 #define PCIE_DESC_TX_LSO (1 << 2)
155 #define PCIE_DESC_TX_ENCAP_NONE (0)
156 #define PCIE_DESC_TX_ENCAP_VXLAN (1 << 1)
157 #define PCIE_DESC_TX_ENCAP_GRE (1 << 0)
159 struct nfp_net_tx_desc {
162 uint8_t dma_addr_hi; /* High bits of host buf address */
163 __le16 dma_len; /* Length to DMA for this desc */
164 uint8_t offset_eop; /* Offset in buf where pkt starts +
165 * highest bit is eop flag.
167 __le32 dma_addr_lo; /* Low 32bit of host buf addr */
169 __le16 mss; /* MSS to be used for LSO */
170 uint8_t lso_hdrlen; /* LSO, where the data starts */
171 uint8_t flags; /* TX Flags, see @PCIE_DESC_TX_* */
176 * L3 and L4 header offsets required
182 __le16 vlan; /* VLAN tag to add if indicated */
184 __le16 data_len; /* Length of frame + meta data */
191 struct nfp_net_hw *hw; /* Backpointer to nfp_net structure */
194 * Queue information: @qidx is the queue index from Linux's
195 * perspective. @tx_qcidx is the index of the Queue
196 * Controller Peripheral queue relative to the TX queue BAR.
197 * @cnt is the size of the queue in number of
198 * descriptors. @qcp_q is a pointer to the base of the queue
199 * structure on the NFP
204 * Read and Write pointers. @wr_p and @rd_p are host side pointer,
205 * they are free running and have little relation to the QCP pointers *
206 * @qcp_rd_p is a local copy queue controller peripheral read pointer
214 uint32_t tx_free_thresh;
217 * For each descriptor keep a reference to the mbuf and
218 * DMA address used until completion is signalled.
221 struct rte_mbuf *mbuf;
225 * Information about the host side queue location. @txds is
226 * the virtual address for the queue, @dma is the DMA address
227 * of the queue and @size is the size in bytes for the queue
230 struct nfp_net_tx_desc *txds;
233 * At this point 48 bytes have been used for all the fields in the
234 * TX critical path. We have room for 8 bytes and still all placed
235 * in a cache line. We are not using the threshold values below but
236 * if we need to, we can add the most used in the remaining bytes.
238 uint32_t tx_rs_thresh; /* not used by now. Future? */
239 uint32_t tx_pthresh; /* not used by now. Future? */
240 uint32_t tx_hthresh; /* not used by now. Future? */
241 uint32_t tx_wthresh; /* not used by now. Future? */
248 /* RX and freelist descriptor format */
249 #define PCIE_DESC_RX_DD (1 << 7)
250 #define PCIE_DESC_RX_META_LEN_MASK (0x7f)
252 /* Flags in the RX descriptor */
253 #define PCIE_DESC_RX_RSS (1 << 15)
254 #define PCIE_DESC_RX_I_IP4_CSUM (1 << 14)
255 #define PCIE_DESC_RX_I_IP4_CSUM_OK (1 << 13)
256 #define PCIE_DESC_RX_I_TCP_CSUM (1 << 12)
257 #define PCIE_DESC_RX_I_TCP_CSUM_OK (1 << 11)
258 #define PCIE_DESC_RX_I_UDP_CSUM (1 << 10)
259 #define PCIE_DESC_RX_I_UDP_CSUM_OK (1 << 9)
260 #define PCIE_DESC_RX_SPARE (1 << 8)
261 #define PCIE_DESC_RX_EOP (1 << 7)
262 #define PCIE_DESC_RX_IP4_CSUM (1 << 6)
263 #define PCIE_DESC_RX_IP4_CSUM_OK (1 << 5)
264 #define PCIE_DESC_RX_TCP_CSUM (1 << 4)
265 #define PCIE_DESC_RX_TCP_CSUM_OK (1 << 3)
266 #define PCIE_DESC_RX_UDP_CSUM (1 << 2)
267 #define PCIE_DESC_RX_UDP_CSUM_OK (1 << 1)
268 #define PCIE_DESC_RX_VLAN (1 << 0)
270 #define PCIE_DESC_RX_L4_CSUM_OK (PCIE_DESC_RX_TCP_CSUM_OK | \
271 PCIE_DESC_RX_UDP_CSUM_OK)
272 struct nfp_net_rx_desc {
274 /* Freelist descriptor */
297 struct nfp_net_rx_buff {
298 struct rte_mbuf *mbuf;
302 struct nfp_net_hw *hw; /* Backpointer to nfp_net structure */
305 * @qcp_fl and @qcp_rx are pointers to the base addresses of the
306 * freelist and RX queue controller peripheral queue structures on the
313 * Read and Write pointers. @wr_p and @rd_p are host side
314 * pointer, they are free running and have little relation to
315 * the QCP pointers. @wr_p is where the driver adds new
316 * freelist descriptors and @rd_p is where the driver start
317 * reading descriptors for newly arrive packets from.
322 * For each buffer placed on the freelist, record the
325 struct nfp_net_rx_buff *rxbufs;
328 * Information about the host side queue location. @rxds is
329 * the virtual address for the queue
331 struct nfp_net_rx_desc *rxds;
334 * The mempool is created by the user specifying a mbuf size.
335 * We save here the reference of the mempool needed in the RX
336 * path and the mbuf size for checking received packets can be
337 * safely copied to the mbuf using the NFP_NET_RX_OFFSET
339 struct rte_mempool *mem_pool;
343 * Next two fields are used for giving more free descriptors
346 uint16_t rx_free_thresh;
349 /* the size of the queue in number of descriptors */
353 * Fields above this point fit in a single cache line and are all used
354 * in the RX critical path. Fields below this point are just used
355 * during queue configuration or not used at all (yet)
358 /* referencing dev->data->port_id */
361 uint8_t crc_len; /* Not used by now */
362 uint8_t drop_en; /* Not used by now */
364 /* DMA address of the queue */
368 * Queue information: @qidx is the queue index from Linux's
369 * perspective. @fl_qcidx is the index of the Queue
370 * Controller peripheral queue relative to the RX queue BAR
371 * used for the freelist and @rx_qcidx is the Queue Controller
372 * Peripheral index for the RX queue.
380 /* Info from the firmware */
387 /* Current values for control */
398 rte_spinlock_t reconfig_lock;
400 uint32_t max_tx_queues;
401 uint32_t max_rx_queues;
405 uint16_t subsystem_device_id;
406 uint16_t subsystem_vendor_id;
407 #if defined(DSTQ_SELECTION)
409 uint16_t device_function;
413 uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
415 /* Records starting point for counters */
416 struct rte_eth_stats eth_stats_base;
419 struct nfp_cpp_area *ctrl_area;
420 struct nfp_cpp_area *hwqueues_area;
421 struct nfp_cpp_area *msix_area;
426 uint8_t pf_multiport_enabled;
429 union eth_table_entry *eth_table;
431 struct nfp_hwinfo *hwinfo;
432 struct nfp_rtsym_table *sym_tbl;
433 uint32_t nfp_cpp_service_id;
436 struct nfp_net_adapter {
437 struct nfp_net_hw hw;
440 #define NFP_NET_DEV_PRIVATE_TO_HW(adapter)\
441 (&((struct nfp_net_adapter *)adapter)->hw)
443 #endif /* _NFP_NET_PMD_H_ */
446 * c-file-style: "Linux"
447 * indent-tabs-mode: t