196de2506SJakub Kicinski /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ 296de2506SJakub Kicinski /* Copyright (C) 2015-2018 Netronome Systems, Inc. */ 34c352362SJakub Kicinski 44c352362SJakub Kicinski /* 54c352362SJakub Kicinski * nfp_net.h 64c352362SJakub Kicinski * Declarations for Netronome network device driver. 74c352362SJakub Kicinski * Authors: Jakub Kicinski <jakub.kicinski@netronome.com> 84c352362SJakub Kicinski * Jason McMullan <jason.mcmullan@netronome.com> 94c352362SJakub Kicinski * Rolf Neugebauer <rolf.neugebauer@netronome.com> 104c352362SJakub Kicinski */ 114c352362SJakub Kicinski 124c352362SJakub Kicinski #ifndef _NFP_NET_H_ 134c352362SJakub Kicinski #define _NFP_NET_H_ 144c352362SJakub Kicinski 1551a5e563SJakub Kicinski #include <linux/atomic.h> 164c352362SJakub Kicinski #include <linux/interrupt.h> 1763461a02SJakub Kicinski #include <linux/list.h> 184c352362SJakub Kicinski #include <linux/netdevice.h> 194c352362SJakub Kicinski #include <linux/pci.h> 20a1cbaad7SArnd Bergmann #include <linux/io-64-nonatomic-hi-lo.h> 213ed77bf7SJakub Kicinski #include <linux/semaphore.h> 22e2c7114aSJakub Kicinski #include <linux/workqueue.h> 237f1c684aSJesper Dangaard Brouer #include <net/xdp.h> 244c352362SJakub Kicinski 254c352362SJakub Kicinski #include "nfp_net_ctrl.h" 264c352362SJakub Kicinski 27c821e617SJakub Kicinski #define nn_pr(nn, lvl, fmt, args...) \ 28c821e617SJakub Kicinski ({ \ 29c821e617SJakub Kicinski struct nfp_net *__nn = (nn); \ 30c821e617SJakub Kicinski \ 31c821e617SJakub Kicinski if (__nn->dp.netdev) \ 32c821e617SJakub Kicinski netdev_printk(lvl, __nn->dp.netdev, fmt, ## args); \ 33c821e617SJakub Kicinski else \ 34c821e617SJakub Kicinski dev_printk(lvl, __nn->dp.dev, "ctrl: " fmt, ## args); \ 35c821e617SJakub Kicinski }) 36c821e617SJakub Kicinski 37c821e617SJakub Kicinski #define nn_err(nn, fmt, args...) nn_pr(nn, KERN_ERR, fmt, ## args) 38c821e617SJakub Kicinski #define nn_warn(nn, fmt, args...) nn_pr(nn, KERN_WARNING, fmt, ## args) 39c821e617SJakub Kicinski #define nn_info(nn, fmt, args...) nn_pr(nn, KERN_INFO, fmt, ## args) 40c821e617SJakub Kicinski #define nn_dbg(nn, fmt, args...) nn_pr(nn, KERN_DEBUG, fmt, ## args) 41c821e617SJakub Kicinski 4279c12a75SJakub Kicinski #define nn_dp_warn(dp, fmt, args...) \ 43c821e617SJakub Kicinski ({ \ 44c821e617SJakub Kicinski struct nfp_net_dp *__dp = (dp); \ 45c821e617SJakub Kicinski \ 46c821e617SJakub Kicinski if (unlikely(net_ratelimit())) { \ 47c821e617SJakub Kicinski if (__dp->netdev) \ 48c821e617SJakub Kicinski netdev_warn(__dp->netdev, fmt, ## args); \ 49c821e617SJakub Kicinski else \ 50c821e617SJakub Kicinski dev_warn(__dp->dev, fmt, ## args); \ 51c821e617SJakub Kicinski } \ 52c821e617SJakub Kicinski }) 534c352362SJakub Kicinski 543d780b92SJakub Kicinski /* Max time to wait for NFP to respond on updates (in seconds) */ 553d780b92SJakub Kicinski #define NFP_NET_POLL_TIMEOUT 5 564c352362SJakub Kicinski 5766860bebSJakub Kicinski /* Interval for reading offloaded filter stats */ 5866860bebSJakub Kicinski #define NFP_NET_STAT_POLL_IVL msecs_to_jiffies(100) 5966860bebSJakub Kicinski 604c352362SJakub Kicinski /* Bar allocation */ 61796312cdSJakub Kicinski #define NFP_NET_CTRL_BAR 0 624c352362SJakub Kicinski #define NFP_NET_Q0_BAR 2 634c352362SJakub Kicinski #define NFP_NET_Q1_BAR 4 /* OBSOLETE */ 644c352362SJakub Kicinski 654c352362SJakub Kicinski /* Max bits in DMA address */ 664c352362SJakub Kicinski #define NFP_NET_MAX_DMA_BITS 40 674c352362SJakub Kicinski 684c352362SJakub Kicinski /* Default size for MTU and freelist buffer sizes */ 694c352362SJakub Kicinski #define NFP_NET_DEFAULT_MTU 1500 704c352362SJakub Kicinski 714c352362SJakub Kicinski /* Maximum number of bytes prepended to a packet */ 724c352362SJakub Kicinski #define NFP_NET_MAX_PREPEND 64 734c352362SJakub Kicinski 744c352362SJakub Kicinski /* Interrupt definitions */ 754c352362SJakub Kicinski #define NFP_NET_NON_Q_VECTORS 2 764c352362SJakub Kicinski #define NFP_NET_IRQ_LSC_IDX 0 774c352362SJakub Kicinski #define NFP_NET_IRQ_EXN_IDX 1 78d4e7f092SJakub Kicinski #define NFP_NET_MIN_VNIC_IRQS (NFP_NET_NON_Q_VECTORS + 1) 794c352362SJakub Kicinski 804c352362SJakub Kicinski /* Queue/Ring definitions */ 814c352362SJakub Kicinski #define NFP_NET_MAX_TX_RINGS 64 /* Max. # of Tx rings per device */ 824c352362SJakub Kicinski #define NFP_NET_MAX_RX_RINGS 64 /* Max. # of Rx rings per device */ 8323a4e389SJakub Kicinski #define NFP_NET_MAX_R_VECS (NFP_NET_MAX_TX_RINGS > NFP_NET_MAX_RX_RINGS ? \ 8423a4e389SJakub Kicinski NFP_NET_MAX_TX_RINGS : NFP_NET_MAX_RX_RINGS) 8523a4e389SJakub Kicinski #define NFP_NET_MAX_IRQS (NFP_NET_NON_Q_VECTORS + NFP_NET_MAX_R_VECS) 864c352362SJakub Kicinski 874c352362SJakub Kicinski #define NFP_NET_MIN_TX_DESCS 256 /* Min. # of Tx descs per ring */ 884c352362SJakub Kicinski #define NFP_NET_MIN_RX_DESCS 256 /* Min. # of Rx descs per ring */ 894c352362SJakub Kicinski #define NFP_NET_MAX_TX_DESCS (256 * 1024) /* Max. # of Tx descs per ring */ 904c352362SJakub Kicinski #define NFP_NET_MAX_RX_DESCS (256 * 1024) /* Max. # of Rx descs per ring */ 914c352362SJakub Kicinski 924c352362SJakub Kicinski #define NFP_NET_TX_DESCS_DEFAULT 4096 /* Default # of Tx descs per ring */ 934c352362SJakub Kicinski #define NFP_NET_RX_DESCS_DEFAULT 4096 /* Default # of Rx descs per ring */ 944c352362SJakub Kicinski 954c352362SJakub Kicinski #define NFP_NET_FL_BATCH 16 /* Add freelist in this Batch size */ 96abeeec4aSJakub Kicinski #define NFP_NET_XDP_MAX_COMPLETE 2048 /* XDP bufs to reclaim in NAPI poll */ 974c352362SJakub Kicinski 984c352362SJakub Kicinski /* Offload definitions */ 994c352362SJakub Kicinski #define NFP_NET_N_VXLAN_PORTS (NFP_NET_CFG_VXLAN_SZ / sizeof(__be16)) 1004c352362SJakub Kicinski 101c0f031bcSJakub Kicinski #define NFP_NET_RX_BUF_HEADROOM (NET_SKB_PAD + NET_IP_ALIGN) 102c0f031bcSJakub Kicinski #define NFP_NET_RX_BUF_NON_DATA (NFP_NET_RX_BUF_HEADROOM + \ 103c0f031bcSJakub Kicinski SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) 104c0f031bcSJakub Kicinski 1054c352362SJakub Kicinski /* Forward declarations */ 106bd5ca062SJakub Kicinski struct nfp_cpp; 10747465aedSJakub Kicinski struct nfp_eth_table_port; 1084c352362SJakub Kicinski struct nfp_net; 1094c352362SJakub Kicinski struct nfp_net_r_vector; 110eb488c26SJakub Kicinski struct nfp_port; 1114c352362SJakub Kicinski 1124aa3b766SJakub Kicinski /* Convenience macro for wrapping descriptor index on ring size */ 1134aa3b766SJakub Kicinski #define D_IDX(ring, idx) ((idx) & ((ring)->cnt - 1)) 1144aa3b766SJakub Kicinski 1154c352362SJakub Kicinski /* Convenience macro for writing dma address into RX/TX descriptors */ 1164c352362SJakub Kicinski #define nfp_desc_set_dma_addr(desc, dma_addr) \ 1174c352362SJakub Kicinski do { \ 1184c352362SJakub Kicinski __typeof(desc) __d = (desc); \ 1194c352362SJakub Kicinski dma_addr_t __addr = (dma_addr); \ 1204c352362SJakub Kicinski \ 1214c352362SJakub Kicinski __d->dma_addr_lo = cpu_to_le32(lower_32_bits(__addr)); \ 1224c352362SJakub Kicinski __d->dma_addr_hi = upper_32_bits(__addr) & 0xff; \ 1234c352362SJakub Kicinski } while (0) 1244c352362SJakub Kicinski 1254c352362SJakub Kicinski /* TX descriptor format */ 1264c352362SJakub Kicinski 1274c352362SJakub Kicinski #define PCIE_DESC_TX_EOP BIT(7) 1284c352362SJakub Kicinski #define PCIE_DESC_TX_OFFSET_MASK GENMASK(6, 0) 1294c352362SJakub Kicinski #define PCIE_DESC_TX_MSS_MASK GENMASK(13, 0) 1304c352362SJakub Kicinski 1314c352362SJakub Kicinski /* Flags in the host TX descriptor */ 1324c352362SJakub Kicinski #define PCIE_DESC_TX_CSUM BIT(7) 1334c352362SJakub Kicinski #define PCIE_DESC_TX_IP4_CSUM BIT(6) 1344c352362SJakub Kicinski #define PCIE_DESC_TX_TCP_CSUM BIT(5) 1354c352362SJakub Kicinski #define PCIE_DESC_TX_UDP_CSUM BIT(4) 1364c352362SJakub Kicinski #define PCIE_DESC_TX_VLAN BIT(3) 1374c352362SJakub Kicinski #define PCIE_DESC_TX_LSO BIT(2) 1384c352362SJakub Kicinski #define PCIE_DESC_TX_ENCAP BIT(1) 1394c352362SJakub Kicinski #define PCIE_DESC_TX_O_IP4_CSUM BIT(0) 1404c352362SJakub Kicinski 1414c352362SJakub Kicinski struct nfp_net_tx_desc { 1424c352362SJakub Kicinski union { 1434c352362SJakub Kicinski struct { 1444c352362SJakub Kicinski u8 dma_addr_hi; /* High bits of host buf address */ 1454c352362SJakub Kicinski __le16 dma_len; /* Length to DMA for this desc */ 1464c352362SJakub Kicinski u8 offset_eop; /* Offset in buf where pkt starts + 1474c352362SJakub Kicinski * highest bit is eop flag. 1484c352362SJakub Kicinski */ 1494c352362SJakub Kicinski __le32 dma_addr_lo; /* Low 32bit of host buf addr */ 1504c352362SJakub Kicinski 1514c352362SJakub Kicinski __le16 mss; /* MSS to be used for LSO */ 152e53fc9faSEdwin Peer u8 lso_hdrlen; /* LSO, TCP payload offset */ 1534c352362SJakub Kicinski u8 flags; /* TX Flags, see @PCIE_DESC_TX_* */ 15428063be6SEdwin Peer union { 15528063be6SEdwin Peer struct { 15628063be6SEdwin Peer u8 l3_offset; /* L3 header offset */ 15728063be6SEdwin Peer u8 l4_offset; /* L4 header offset */ 15828063be6SEdwin Peer }; 1594c352362SJakub Kicinski __le16 vlan; /* VLAN tag to add if indicated */ 16028063be6SEdwin Peer }; 1614c352362SJakub Kicinski __le16 data_len; /* Length of frame + meta data */ 1624c352362SJakub Kicinski } __packed; 1634c352362SJakub Kicinski __le32 vals[4]; 16495862749SJakub Kicinski __le64 vals8[2]; 1654c352362SJakub Kicinski }; 1664c352362SJakub Kicinski }; 1674c352362SJakub Kicinski 1684c352362SJakub Kicinski /** 1694c352362SJakub Kicinski * struct nfp_net_tx_buf - software TX buffer descriptor 170703f578aSJakub Kicinski * @skb: normal ring, sk_buff associated with this buffer 171703f578aSJakub Kicinski * @frag: XDP ring, page frag associated with this buffer 1724c352362SJakub Kicinski * @dma_addr: DMA mapping address of the buffer 1734c352362SJakub Kicinski * @fidx: Fragment index (-1 for the head and [0..nr_frags-1] for frags) 1744c352362SJakub Kicinski * @pkt_cnt: Number of packets to be produced out of the skb associated 1754c352362SJakub Kicinski * with this buffer (valid only on the head's buffer). 1764c352362SJakub Kicinski * Will be 1 for all non-TSO packets. 1774c352362SJakub Kicinski * @real_len: Number of bytes which to be produced out of the skb (valid only 1784c352362SJakub Kicinski * on the head's buffer). Equal to skb->len for non-TSO packets. 1794c352362SJakub Kicinski */ 1804c352362SJakub Kicinski struct nfp_net_tx_buf { 181ecd63a02SJakub Kicinski union { 1824c352362SJakub Kicinski struct sk_buff *skb; 183ecd63a02SJakub Kicinski void *frag; 184ecd63a02SJakub Kicinski }; 1854c352362SJakub Kicinski dma_addr_t dma_addr; 1864c352362SJakub Kicinski short int fidx; 1874c352362SJakub Kicinski u16 pkt_cnt; 1884c352362SJakub Kicinski u32 real_len; 1894c352362SJakub Kicinski }; 1904c352362SJakub Kicinski 1914c352362SJakub Kicinski /** 1924c352362SJakub Kicinski * struct nfp_net_tx_ring - TX ring structure 1934c352362SJakub Kicinski * @r_vec: Back pointer to ring vector structure 1944c352362SJakub Kicinski * @idx: Ring index from Linux's perspective 1954c352362SJakub Kicinski * @qcidx: Queue Controller Peripheral (QCP) queue index for the TX queue 1964c352362SJakub Kicinski * @qcp_q: Pointer to base of the QCP TX queue 1974c352362SJakub Kicinski * @cnt: Size of the queue in number of descriptors 1984c352362SJakub Kicinski * @wr_p: TX ring write pointer (free running) 1994c352362SJakub Kicinski * @rd_p: TX ring read pointer (free running) 2004c352362SJakub Kicinski * @qcp_rd_p: Local copy of QCP TX queue read pointer 2014c352362SJakub Kicinski * @wr_ptr_add: Accumulated number of buffers to add to QCP write pointer 2024c352362SJakub Kicinski * (used for .xmit_more delayed kick) 2034c352362SJakub Kicinski * @txbufs: Array of transmitted TX buffers, to free on transmit 2044c352362SJakub Kicinski * @txds: Virtual address of TX ring in host memory 2054c352362SJakub Kicinski * @dma: DMA address of the TX ring 2064c352362SJakub Kicinski * @size: Size, in bytes, of the TX ring (needed to free) 20792e68195SJakub Kicinski * @is_xdp: Is this a XDP TX ring? 2084c352362SJakub Kicinski */ 2094c352362SJakub Kicinski struct nfp_net_tx_ring { 2104c352362SJakub Kicinski struct nfp_net_r_vector *r_vec; 2114c352362SJakub Kicinski 2124c352362SJakub Kicinski u32 idx; 2134c352362SJakub Kicinski int qcidx; 2144c352362SJakub Kicinski u8 __iomem *qcp_q; 2154c352362SJakub Kicinski 2164c352362SJakub Kicinski u32 cnt; 2174c352362SJakub Kicinski u32 wr_p; 2184c352362SJakub Kicinski u32 rd_p; 2194c352362SJakub Kicinski u32 qcp_rd_p; 2204c352362SJakub Kicinski 2214c352362SJakub Kicinski u32 wr_ptr_add; 2224c352362SJakub Kicinski 2234c352362SJakub Kicinski struct nfp_net_tx_buf *txbufs; 2244c352362SJakub Kicinski struct nfp_net_tx_desc *txds; 2254c352362SJakub Kicinski 2264c352362SJakub Kicinski dma_addr_t dma; 2275ea14712SJakub Kicinski size_t size; 22892e68195SJakub Kicinski bool is_xdp; 2294c352362SJakub Kicinski } ____cacheline_aligned; 2304c352362SJakub Kicinski 2314c352362SJakub Kicinski /* RX and freelist descriptor format */ 2324c352362SJakub Kicinski 2334c352362SJakub Kicinski #define PCIE_DESC_RX_DD BIT(7) 2344c352362SJakub Kicinski #define PCIE_DESC_RX_META_LEN_MASK GENMASK(6, 0) 2354c352362SJakub Kicinski 2364c352362SJakub Kicinski /* Flags in the RX descriptor */ 2374c352362SJakub Kicinski #define PCIE_DESC_RX_RSS cpu_to_le16(BIT(15)) 2384c352362SJakub Kicinski #define PCIE_DESC_RX_I_IP4_CSUM cpu_to_le16(BIT(14)) 2394c352362SJakub Kicinski #define PCIE_DESC_RX_I_IP4_CSUM_OK cpu_to_le16(BIT(13)) 2404c352362SJakub Kicinski #define PCIE_DESC_RX_I_TCP_CSUM cpu_to_le16(BIT(12)) 2414c352362SJakub Kicinski #define PCIE_DESC_RX_I_TCP_CSUM_OK cpu_to_le16(BIT(11)) 2424c352362SJakub Kicinski #define PCIE_DESC_RX_I_UDP_CSUM cpu_to_le16(BIT(10)) 2434c352362SJakub Kicinski #define PCIE_DESC_RX_I_UDP_CSUM_OK cpu_to_le16(BIT(9)) 2445bcb5c7eSDirk van der Merwe #define PCIE_DESC_RX_DECRYPTED cpu_to_le16(BIT(8)) 2454c352362SJakub Kicinski #define PCIE_DESC_RX_EOP cpu_to_le16(BIT(7)) 2464c352362SJakub Kicinski #define PCIE_DESC_RX_IP4_CSUM cpu_to_le16(BIT(6)) 2474c352362SJakub Kicinski #define PCIE_DESC_RX_IP4_CSUM_OK cpu_to_le16(BIT(5)) 2484c352362SJakub Kicinski #define PCIE_DESC_RX_TCP_CSUM cpu_to_le16(BIT(4)) 2494c352362SJakub Kicinski #define PCIE_DESC_RX_TCP_CSUM_OK cpu_to_le16(BIT(3)) 2504c352362SJakub Kicinski #define PCIE_DESC_RX_UDP_CSUM cpu_to_le16(BIT(2)) 2514c352362SJakub Kicinski #define PCIE_DESC_RX_UDP_CSUM_OK cpu_to_le16(BIT(1)) 2524c352362SJakub Kicinski #define PCIE_DESC_RX_VLAN cpu_to_le16(BIT(0)) 2534c352362SJakub Kicinski 2544c352362SJakub Kicinski #define PCIE_DESC_RX_CSUM_ALL (PCIE_DESC_RX_IP4_CSUM | \ 2554c352362SJakub Kicinski PCIE_DESC_RX_TCP_CSUM | \ 2564c352362SJakub Kicinski PCIE_DESC_RX_UDP_CSUM | \ 2574c352362SJakub Kicinski PCIE_DESC_RX_I_IP4_CSUM | \ 2584c352362SJakub Kicinski PCIE_DESC_RX_I_TCP_CSUM | \ 2594c352362SJakub Kicinski PCIE_DESC_RX_I_UDP_CSUM) 2604c352362SJakub Kicinski #define PCIE_DESC_RX_CSUM_OK_SHIFT 1 2614c352362SJakub Kicinski #define __PCIE_DESC_RX_CSUM_ALL le16_to_cpu(PCIE_DESC_RX_CSUM_ALL) 2624c352362SJakub Kicinski #define __PCIE_DESC_RX_CSUM_ALL_OK (__PCIE_DESC_RX_CSUM_ALL >> \ 2634c352362SJakub Kicinski PCIE_DESC_RX_CSUM_OK_SHIFT) 2644c352362SJakub Kicinski 2654c352362SJakub Kicinski struct nfp_net_rx_desc { 2664c352362SJakub Kicinski union { 2674c352362SJakub Kicinski struct { 2684c352362SJakub Kicinski u8 dma_addr_hi; /* High bits of the buf address */ 2694c352362SJakub Kicinski __le16 reserved; /* Must be zero */ 2704c352362SJakub Kicinski u8 meta_len_dd; /* Must be zero */ 2714c352362SJakub Kicinski 2724c352362SJakub Kicinski __le32 dma_addr_lo; /* Low bits of the buffer address */ 2734c352362SJakub Kicinski } __packed fld; 2744c352362SJakub Kicinski 2754c352362SJakub Kicinski struct { 2764c352362SJakub Kicinski __le16 data_len; /* Length of the frame + meta data */ 2774c352362SJakub Kicinski u8 reserved; 2784c352362SJakub Kicinski u8 meta_len_dd; /* Length of meta data prepended + 2794c352362SJakub Kicinski * descriptor done flag. 2804c352362SJakub Kicinski */ 2814c352362SJakub Kicinski 2824c352362SJakub Kicinski __le16 flags; /* RX flags. See @PCIE_DESC_RX_* */ 2834c352362SJakub Kicinski __le16 vlan; /* VLAN if stripped */ 2844c352362SJakub Kicinski } __packed rxd; 2854c352362SJakub Kicinski 2864c352362SJakub Kicinski __le32 vals[2]; 2874c352362SJakub Kicinski }; 2884c352362SJakub Kicinski }; 2894c352362SJakub Kicinski 29019d0f54eSJakub Kicinski #define NFP_NET_META_FIELD_MASK GENMASK(NFP_NET_META_FIELD_SIZE - 1, 0) 29119d0f54eSJakub Kicinski 292e524a6a9SJakub Kicinski struct nfp_meta_parsed { 293ddb98d94SJakub Kicinski u8 hash_type; 294ddb98d94SJakub Kicinski u8 csum_type; 295e524a6a9SJakub Kicinski u32 hash; 296e524a6a9SJakub Kicinski u32 mark; 29791bf82caSSimon Horman u32 portid; 298ddb98d94SJakub Kicinski __wsum csum; 299e524a6a9SJakub Kicinski }; 300e524a6a9SJakub Kicinski 3014c352362SJakub Kicinski struct nfp_net_rx_hash { 3024c352362SJakub Kicinski __be32 hash_type; 3034c352362SJakub Kicinski __be32 hash; 3044c352362SJakub Kicinski }; 3054c352362SJakub Kicinski 3064c352362SJakub Kicinski /** 3074c352362SJakub Kicinski * struct nfp_net_rx_buf - software RX buffer descriptor 308c0f031bcSJakub Kicinski * @frag: page fragment buffer 3094c352362SJakub Kicinski * @dma_addr: DMA mapping address of the buffer 3104c352362SJakub Kicinski */ 3114c352362SJakub Kicinski struct nfp_net_rx_buf { 312c0f031bcSJakub Kicinski void *frag; 3134c352362SJakub Kicinski dma_addr_t dma_addr; 3144c352362SJakub Kicinski }; 3154c352362SJakub Kicinski 3164c352362SJakub Kicinski /** 3174c352362SJakub Kicinski * struct nfp_net_rx_ring - RX ring structure 3184c352362SJakub Kicinski * @r_vec: Back pointer to ring vector structure 3194c352362SJakub Kicinski * @cnt: Size of the queue in number of descriptors 3204c352362SJakub Kicinski * @wr_p: FL/RX ring write pointer (free running) 3214c352362SJakub Kicinski * @rd_p: FL/RX ring read pointer (free running) 3224c352362SJakub Kicinski * @idx: Ring index from Linux's perspective 3234c352362SJakub Kicinski * @fl_qcidx: Queue Controller Peripheral (QCP) queue index for the freelist 3244c352362SJakub Kicinski * @qcp_fl: Pointer to base of the QCP freelist queue 3254c352362SJakub Kicinski * @rxbufs: Array of transmitted FL/RX buffers 3264c352362SJakub Kicinski * @rxds: Virtual address of FL/RX ring in host memory 327e76c1d3dSJakub Kicinski * @xdp_rxq: RX-ring info avail for XDP 3284c352362SJakub Kicinski * @dma: DMA address of the FL/RX ring 3294c352362SJakub Kicinski * @size: Size, in bytes, of the FL/RX ring (needed to free) 3304c352362SJakub Kicinski */ 3314c352362SJakub Kicinski struct nfp_net_rx_ring { 3324c352362SJakub Kicinski struct nfp_net_r_vector *r_vec; 3334c352362SJakub Kicinski 3344c352362SJakub Kicinski u32 cnt; 3354c352362SJakub Kicinski u32 wr_p; 3364c352362SJakub Kicinski u32 rd_p; 3374c352362SJakub Kicinski 33883d08a1dSJakub Kicinski u32 idx; 3394c352362SJakub Kicinski 3404c352362SJakub Kicinski int fl_qcidx; 3414c352362SJakub Kicinski u8 __iomem *qcp_fl; 3424c352362SJakub Kicinski 3434c352362SJakub Kicinski struct nfp_net_rx_buf *rxbufs; 3444c352362SJakub Kicinski struct nfp_net_rx_desc *rxds; 3454c352362SJakub Kicinski 3467f1c684aSJesper Dangaard Brouer struct xdp_rxq_info xdp_rxq; 347e76c1d3dSJakub Kicinski 348e76c1d3dSJakub Kicinski dma_addr_t dma; 3495ea14712SJakub Kicinski size_t size; 3504c352362SJakub Kicinski } ____cacheline_aligned; 3514c352362SJakub Kicinski 3524c352362SJakub Kicinski /** 3534c352362SJakub Kicinski * struct nfp_net_r_vector - Per ring interrupt vector configuration 3544c352362SJakub Kicinski * @nfp_net: Backpointer to nfp_net structure 3554c352362SJakub Kicinski * @napi: NAPI structure for this ring vec 356703f578aSJakub Kicinski * @tasklet: ctrl vNIC, tasklet for servicing the r_vec 357703f578aSJakub Kicinski * @queue: ctrl vNIC, send queue 358703f578aSJakub Kicinski * @lock: ctrl vNIC, r_vec lock protects @queue 3594c352362SJakub Kicinski * @tx_ring: Pointer to TX ring 3604c352362SJakub Kicinski * @rx_ring: Pointer to RX ring 361ecd63a02SJakub Kicinski * @xdp_ring: Pointer to an extra TX ring for XDP 362fdace6c2SJakub Kicinski * @irq_entry: MSI-X table entry (use for talking to the device) 3634c352362SJakub Kicinski * @rx_sync: Seqlock for atomic updates of RX stats 3644c352362SJakub Kicinski * @rx_pkts: Number of received packets 3654c352362SJakub Kicinski * @rx_bytes: Number of received bytes 3664c352362SJakub Kicinski * @rx_drops: Number of packets dropped on RX due to lack of resources 3674c352362SJakub Kicinski * @hw_csum_rx_ok: Counter of packets where the HW checksum was OK 3684c352362SJakub Kicinski * @hw_csum_rx_inner_ok: Counter of packets where the inner HW checksum was OK 3690df57e60SJakub Kicinski * @hw_csum_rx_complete: Counter of packets with CHECKSUM_COMPLETE reported 3704c352362SJakub Kicinski * @hw_csum_rx_error: Counter of packets with bad checksums 3715bcb5c7eSDirk van der Merwe * @hw_tls_rx: Number of packets with TLS decrypted by hardware 3724c352362SJakub Kicinski * @tx_sync: Seqlock for atomic updates of TX stats 3734c352362SJakub Kicinski * @tx_pkts: Number of Transmitted packets 3744c352362SJakub Kicinski * @tx_bytes: Number of Transmitted bytes 3754c352362SJakub Kicinski * @hw_csum_tx: Counter of packets with TX checksum offload requested 3764c352362SJakub Kicinski * @hw_csum_tx_inner: Counter of inner TX checksum offload requests 3774c352362SJakub Kicinski * @tx_gather: Counter of packets with Gather DMA 3784c352362SJakub Kicinski * @tx_lso: Counter of LSO packets sent 37951a5e563SJakub Kicinski * @hw_tls_tx: Counter of TLS packets sent with crypto offloaded to HW 38051a5e563SJakub Kicinski * @tls_tx_fallback: Counter of TLS packets sent which had to be encrypted 38151a5e563SJakub Kicinski * by the fallback path because packets came out of order 38251a5e563SJakub Kicinski * @tls_tx_no_fallback: Counter of TLS packets not sent because the fallback 38351a5e563SJakub Kicinski * path could not encrypt them 3844c352362SJakub Kicinski * @tx_errors: How many TX errors were encountered 3854c352362SJakub Kicinski * @tx_busy: How often was TX busy (no space)? 38616f50cdaSJakub Kicinski * @rx_replace_buf_alloc_fail: Counter of RX buffer allocation failures 387fdace6c2SJakub Kicinski * @irq_vector: Interrupt vector number (use for talking to the OS) 3884c352362SJakub Kicinski * @handler: Interrupt handler for this ring vector 3894c352362SJakub Kicinski * @name: Name of the interrupt vector 3904c352362SJakub Kicinski * @affinity_mask: SMP affinity mask for this vector 3914c352362SJakub Kicinski * 3924c352362SJakub Kicinski * This structure ties RX and TX rings to interrupt vectors and a NAPI 3934c352362SJakub Kicinski * context. This currently only supports one RX and TX ring per 3944c352362SJakub Kicinski * interrupt vector but might be extended in the future to allow 3954c352362SJakub Kicinski * association of multiple rings per vector. 3964c352362SJakub Kicinski */ 3974c352362SJakub Kicinski struct nfp_net_r_vector { 3984c352362SJakub Kicinski struct nfp_net *nfp_net; 39977ece8d5SJakub Kicinski union { 4004c352362SJakub Kicinski struct napi_struct napi; 40177ece8d5SJakub Kicinski struct { 40277ece8d5SJakub Kicinski struct tasklet_struct tasklet; 40377ece8d5SJakub Kicinski struct sk_buff_head queue; 404f654e676SSebastian Andrzej Siewior spinlock_t lock; 40577ece8d5SJakub Kicinski }; 40677ece8d5SJakub Kicinski }; 4074c352362SJakub Kicinski 4084c352362SJakub Kicinski struct nfp_net_tx_ring *tx_ring; 4094c352362SJakub Kicinski struct nfp_net_rx_ring *rx_ring; 4104c352362SJakub Kicinski 411fdace6c2SJakub Kicinski u16 irq_entry; 4124c352362SJakub Kicinski 4134c352362SJakub Kicinski struct u64_stats_sync rx_sync; 4144c352362SJakub Kicinski u64 rx_pkts; 4154c352362SJakub Kicinski u64 rx_bytes; 4164c352362SJakub Kicinski u64 rx_drops; 4174c352362SJakub Kicinski u64 hw_csum_rx_ok; 4184c352362SJakub Kicinski u64 hw_csum_rx_inner_ok; 4190df57e60SJakub Kicinski u64 hw_csum_rx_complete; 4205bcb5c7eSDirk van der Merwe u64 hw_tls_rx; 4214c352362SJakub Kicinski 42251a5e563SJakub Kicinski u64 hw_csum_rx_error; 42351a5e563SJakub Kicinski u64 rx_replace_buf_alloc_fail; 42451a5e563SJakub Kicinski 425ecd63a02SJakub Kicinski struct nfp_net_tx_ring *xdp_ring; 426ecd63a02SJakub Kicinski 4274c352362SJakub Kicinski struct u64_stats_sync tx_sync; 4284c352362SJakub Kicinski u64 tx_pkts; 4294c352362SJakub Kicinski u64 tx_bytes; 43051a5e563SJakub Kicinski 43151a5e563SJakub Kicinski u64 ____cacheline_aligned_in_smp hw_csum_tx; 4324c352362SJakub Kicinski u64 hw_csum_tx_inner; 4334c352362SJakub Kicinski u64 tx_gather; 4344c352362SJakub Kicinski u64 tx_lso; 43551a5e563SJakub Kicinski u64 hw_tls_tx; 43616f50cdaSJakub Kicinski 43751a5e563SJakub Kicinski u64 tls_tx_fallback; 43851a5e563SJakub Kicinski u64 tls_tx_no_fallback; 4394c352362SJakub Kicinski u64 tx_errors; 4404c352362SJakub Kicinski u64 tx_busy; 4414c352362SJakub Kicinski 44251a5e563SJakub Kicinski /* Cold data follows */ 44351a5e563SJakub Kicinski 444fdace6c2SJakub Kicinski u32 irq_vector; 4454c352362SJakub Kicinski irq_handler_t handler; 4464c352362SJakub Kicinski char name[IFNAMSIZ + 8]; 4474c352362SJakub Kicinski cpumask_t affinity_mask; 4484c352362SJakub Kicinski } ____cacheline_aligned; 4494c352362SJakub Kicinski 4504c352362SJakub Kicinski /* Firmware version as it is written in the 32bit value in the BAR */ 4514c352362SJakub Kicinski struct nfp_net_fw_version { 4524c352362SJakub Kicinski u8 minor; 4534c352362SJakub Kicinski u8 major; 4544c352362SJakub Kicinski u8 class; 4554c352362SJakub Kicinski u8 resv; 4564c352362SJakub Kicinski } __packed; 4574c352362SJakub Kicinski 4584c352362SJakub Kicinski static inline bool nfp_net_fw_ver_eq(struct nfp_net_fw_version *fw_ver, 4594c352362SJakub Kicinski u8 resv, u8 class, u8 major, u8 minor) 4604c352362SJakub Kicinski { 4614c352362SJakub Kicinski return fw_ver->resv == resv && 4624c352362SJakub Kicinski fw_ver->class == class && 4634c352362SJakub Kicinski fw_ver->major == major && 4644c352362SJakub Kicinski fw_ver->minor == minor; 4654c352362SJakub Kicinski } 4664c352362SJakub Kicinski 46766860bebSJakub Kicinski struct nfp_stat_pair { 46866860bebSJakub Kicinski u64 pkts; 46966860bebSJakub Kicinski u64 bytes; 47066860bebSJakub Kicinski }; 47166860bebSJakub Kicinski 4724c352362SJakub Kicinski /** 47379c12a75SJakub Kicinski * struct nfp_net_dp - NFP network device datapath data structure 474fa43d2a8SJakub Kicinski * @dev: Backpointer to struct device 4754c352362SJakub Kicinski * @netdev: Backpointer to net_device structure 4764c352362SJakub Kicinski * @is_vf: Is the driver attached to a VF? 477b9dcf88aSJakub Kicinski * @chained_metadata_format: Firemware will use new metadata format 478c3991d39SDirk van der Merwe * @ktls_tx: Is kTLS TX enabled? 479c487e6b1SJakub Kicinski * @rx_dma_dir: Mapping direction for RX buffers 4806fe0c3b4SJakub Kicinski * @rx_dma_off: Offset at which DMA packets (for XDP headroom) 48197717acaSJakub Kicinski * @rx_offset: Offset in the RX buffers where packet data starts 4824c352362SJakub Kicinski * @ctrl: Local copy of the control register/word. 4834c352362SJakub Kicinski * @fl_bufsz: Currently configured size of the freelist buffers 484ecd63a02SJakub Kicinski * @xdp_prog: Installed XDP program 48579c12a75SJakub Kicinski * @tx_rings: Array of pre-allocated TX ring structures 48679c12a75SJakub Kicinski * @rx_rings: Array of pre-allocated RX ring structures 487d2b84397SJakub Kicinski * @ctrl_bar: Pointer to mapped control BAR 48879c12a75SJakub Kicinski * 48979c12a75SJakub Kicinski * @txd_cnt: Size of the TX ring in number of descriptors 49079c12a75SJakub Kicinski * @rxd_cnt: Size of the RX ring in number of descriptors 49179c12a75SJakub Kicinski * @num_r_vecs: Number of used ring vectors 49279c12a75SJakub Kicinski * @num_tx_rings: Currently configured number of TX rings 49379c12a75SJakub Kicinski * @num_stack_tx_rings: Number of TX rings used by the stack (not XDP) 49479c12a75SJakub Kicinski * @num_rx_rings: Currently configured number of RX rings 49576e1e1a8SJakub Kicinski * @mtu: Device MTU 49679c12a75SJakub Kicinski */ 49779c12a75SJakub Kicinski struct nfp_net_dp { 49879c12a75SJakub Kicinski struct device *dev; 49979c12a75SJakub Kicinski struct net_device *netdev; 50079c12a75SJakub Kicinski 501c487e6b1SJakub Kicinski u8 is_vf:1; 502c487e6b1SJakub Kicinski u8 chained_metadata_format:1; 503c3991d39SDirk van der Merwe u8 ktls_tx:1; 504c487e6b1SJakub Kicinski 505c487e6b1SJakub Kicinski u8 rx_dma_dir; 50697717acaSJakub Kicinski u8 rx_offset; 50797717acaSJakub Kicinski 508dbf637ffSJakub Kicinski u32 rx_dma_off; 509dbf637ffSJakub Kicinski 51079c12a75SJakub Kicinski u32 ctrl; 51179c12a75SJakub Kicinski u32 fl_bufsz; 51279c12a75SJakub Kicinski 51379c12a75SJakub Kicinski struct bpf_prog *xdp_prog; 51479c12a75SJakub Kicinski 51579c12a75SJakub Kicinski struct nfp_net_tx_ring *tx_rings; 51679c12a75SJakub Kicinski struct nfp_net_rx_ring *rx_rings; 51779c12a75SJakub Kicinski 518d2b84397SJakub Kicinski u8 __iomem *ctrl_bar; 519d2b84397SJakub Kicinski 52079c12a75SJakub Kicinski /* Cold data follows */ 52179c12a75SJakub Kicinski 52279c12a75SJakub Kicinski unsigned int txd_cnt; 52379c12a75SJakub Kicinski unsigned int rxd_cnt; 52479c12a75SJakub Kicinski 52579c12a75SJakub Kicinski unsigned int num_r_vecs; 52679c12a75SJakub Kicinski 52779c12a75SJakub Kicinski unsigned int num_tx_rings; 52879c12a75SJakub Kicinski unsigned int num_stack_tx_rings; 52979c12a75SJakub Kicinski unsigned int num_rx_rings; 53076e1e1a8SJakub Kicinski 53176e1e1a8SJakub Kicinski unsigned int mtu; 53279c12a75SJakub Kicinski }; 53379c12a75SJakub Kicinski 53479c12a75SJakub Kicinski /** 53579c12a75SJakub Kicinski * struct nfp_net - NFP network device structure 53679c12a75SJakub Kicinski * @dp: Datapath structure 53751c1df83SJakub Kicinski * @id: vNIC id within the PF (0 for VFs) 5384c352362SJakub Kicinski * @fw_ver: Firmware version 5394c352362SJakub Kicinski * @cap: Capabilities advertised by the Firmware 5404c352362SJakub Kicinski * @max_mtu: Maximum support MTU advertised by the Firmware 5419ff304bfSJakub Kicinski * @rss_hfunc: RSS selected hash function 5424c352362SJakub Kicinski * @rss_cfg: RSS configuration 5434c352362SJakub Kicinski * @rss_key: RSS secret key 5444c352362SJakub Kicinski * @rss_itbl: RSS indirection table 5455f428401SJakub Kicinski * @xdp: Information about the driver XDP program 5465f428401SJakub Kicinski * @xdp_hw: Information about the HW XDP program 54779c12a75SJakub Kicinski * @max_r_vecs: Number of allocated interrupt vectors for RX/TX 5484c352362SJakub Kicinski * @max_tx_rings: Maximum number of TX rings supported by the Firmware 5494c352362SJakub Kicinski * @max_rx_rings: Maximum number of RX rings supported by the Firmware 550a646c9b2SJakub Kicinski * @stride_rx: Queue controller RX queue spacing 551a646c9b2SJakub Kicinski * @stride_tx: Queue controller TX queue spacing 5524c352362SJakub Kicinski * @r_vecs: Pre-allocated array of ring vectors 5534c352362SJakub Kicinski * @irq_entries: Pre-allocated array of MSI-X entries 5544c352362SJakub Kicinski * @lsc_handler: Handler for Link State Change interrupt 5554c352362SJakub Kicinski * @lsc_name: Name for Link State Change interrupt 5564c352362SJakub Kicinski * @exn_handler: Handler for Exception interrupt 5574c352362SJakub Kicinski * @exn_name: Name for Exception interrupt 5584c352362SJakub Kicinski * @shared_handler: Handler for shared interrupts 5594c352362SJakub Kicinski * @shared_name: Name for shared interrupt 5604c352362SJakub Kicinski * @me_freq_mhz: ME clock_freq (MHz) 561dd5b2498SJakub Kicinski * @reconfig_lock: Protects @reconfig_posted, @reconfig_timer_active, 562dd5b2498SJakub Kicinski * @reconfig_sync_present and HW reconfiguration request 563dd5b2498SJakub Kicinski * regs/machinery from async requests (sync must take 564dd5b2498SJakub Kicinski * @bar_lock) 5653d780b92SJakub Kicinski * @reconfig_posted: Pending reconfig bits coming from async sources 5663d780b92SJakub Kicinski * @reconfig_timer_active: Timer for reading reconfiguration results is pending 5673d780b92SJakub Kicinski * @reconfig_sync_present: Some thread is performing synchronous reconfig 5683d780b92SJakub Kicinski * @reconfig_timer: Timer for async reading of reconfig results 5696db3a9dcSJakub Kicinski * @reconfig_in_progress_update: Update FW is processing now (debug only) 570dd5b2498SJakub Kicinski * @bar_lock: vNIC config BAR access lock, protects: update, 5711f35a56cSDirk van der Merwe * mailbox area, crypto TLV 5724c352362SJakub Kicinski * @link_up: Is the link up? 573cee42951SJakub Kicinski * @link_status_lock: Protects @link_* and ensures atomicity with BAR reading 5744c352362SJakub Kicinski * @rx_coalesce_usecs: RX interrupt moderation usecs delay parameter 5754c352362SJakub Kicinski * @rx_coalesce_max_frames: RX interrupt moderation frame count parameter 5764c352362SJakub Kicinski * @tx_coalesce_usecs: TX interrupt moderation usecs delay parameter 5774c352362SJakub Kicinski * @tx_coalesce_max_frames: TX interrupt moderation frame count parameter 5784c352362SJakub Kicinski * @vxlan_ports: VXLAN ports for RX inner csum offload communicated to HW 5794c352362SJakub Kicinski * @vxlan_usecnt: IPv4/IPv6 VXLAN port use counts 5804c352362SJakub Kicinski * @qcp_cfg: Pointer to QCP queue used for configuration notification 5814c352362SJakub Kicinski * @tx_bar: Pointer to mapped TX queues 5824c352362SJakub Kicinski * @rx_bar: Pointer to mapped FL/RX queues 58373a0329bSJakub Kicinski * @tlv_caps: Parsed TLV capabilities 5841f35a56cSDirk van der Merwe * @ktls_tx_conn_cnt: Number of offloaded kTLS TX connections 585c0a4948eSJakub Kicinski * @ktls_rx_conn_cnt: Number of offloaded kTLS RX connections 58653601c68SJakub Kicinski * @ktls_conn_id_gen: Trivial generator for kTLS connection ids (for TX) 58751a5e563SJakub Kicinski * @ktls_no_space: Counter of firmware rejecting kTLS connection due to 58851a5e563SJakub Kicinski * lack of space 589d3e4dfe0SJakub Kicinski * @mbox_cmsg: Common Control Message via vNIC mailbox state 590d3e4dfe0SJakub Kicinski * @mbox_cmsg.queue: CCM mbox queue of pending messages 591d3e4dfe0SJakub Kicinski * @mbox_cmsg.wq: CCM mbox wait queue of waiting processes 592e2c7114aSJakub Kicinski * @mbox_cmsg.workq: CCM mbox work queue for @wait_work and @runq_work 593e2c7114aSJakub Kicinski * @mbox_cmsg.wait_work: CCM mbox posted msg reconfig wait work 594e2c7114aSJakub Kicinski * @mbox_cmsg.runq_work: CCM mbox posted msg queue runner work 595d3e4dfe0SJakub Kicinski * @mbox_cmsg.tag: CCM mbox message tag allocator 5964c352362SJakub Kicinski * @debugfs_dir: Device directory in debugfs 597d4e7f092SJakub Kicinski * @vnic_list: Entry on device vNIC list 598fa43d2a8SJakub Kicinski * @pdev: Backpointer to PCI device 5997ac9ebd5SJakub Kicinski * @app: APP handle if available 600fe06a64eSJakub Kicinski * @vnic_no_name: For non-port PF vNIC make ndo_get_phys_port_name return 601fe06a64eSJakub Kicinski * -EOPNOTSUPP to keep backwards compatibility (set by app) 602eb488c26SJakub Kicinski * @port: Pointer to nfp_port structure if vNIC is a port 603c66a9cf4SJakub Kicinski * @app_priv: APP private data for this vNIC 6044c352362SJakub Kicinski */ 6054c352362SJakub Kicinski struct nfp_net { 60679c12a75SJakub Kicinski struct nfp_net_dp dp; 60773725d9dSJakub Kicinski 6084c352362SJakub Kicinski struct nfp_net_fw_version fw_ver; 60979c12a75SJakub Kicinski 61051c1df83SJakub Kicinski u32 id; 61151c1df83SJakub Kicinski 6124c352362SJakub Kicinski u32 cap; 6134c352362SJakub Kicinski u32 max_mtu; 6144c352362SJakub Kicinski 6159ff304bfSJakub Kicinski u8 rss_hfunc; 6164c352362SJakub Kicinski u32 rss_cfg; 6174c352362SJakub Kicinski u8 rss_key[NFP_NET_CFG_RSS_KEY_SZ]; 6184c352362SJakub Kicinski u8 rss_itbl[NFP_NET_CFG_RSS_ITBL_SZ]; 6194c352362SJakub Kicinski 62005296620SJakub Kicinski struct xdp_attachment_info xdp; 6215f428401SJakub Kicinski struct xdp_attachment_info xdp_hw; 6229f82fca9SJakub Kicinski 623a4b562bbSJakub Kicinski unsigned int max_tx_rings; 624a4b562bbSJakub Kicinski unsigned int max_rx_rings; 6254c352362SJakub Kicinski 6264c352362SJakub Kicinski int stride_tx; 6274c352362SJakub Kicinski int stride_rx; 6284c352362SJakub Kicinski 629b33ae997SJakub Kicinski unsigned int max_r_vecs; 63023a4e389SJakub Kicinski struct nfp_net_r_vector r_vecs[NFP_NET_MAX_R_VECS]; 63123a4e389SJakub Kicinski struct msix_entry irq_entries[NFP_NET_MAX_IRQS]; 6324c352362SJakub Kicinski 6334c352362SJakub Kicinski irq_handler_t lsc_handler; 6344c352362SJakub Kicinski char lsc_name[IFNAMSIZ + 8]; 6354c352362SJakub Kicinski 6364c352362SJakub Kicinski irq_handler_t exn_handler; 6374c352362SJakub Kicinski char exn_name[IFNAMSIZ + 8]; 6384c352362SJakub Kicinski 6394c352362SJakub Kicinski irq_handler_t shared_handler; 6404c352362SJakub Kicinski char shared_name[IFNAMSIZ + 8]; 6414c352362SJakub Kicinski 6424c352362SJakub Kicinski u32 me_freq_mhz; 6434c352362SJakub Kicinski 6444c352362SJakub Kicinski bool link_up; 6454c352362SJakub Kicinski spinlock_t link_status_lock; 6464c352362SJakub Kicinski 6474c352362SJakub Kicinski spinlock_t reconfig_lock; 6483d780b92SJakub Kicinski u32 reconfig_posted; 6493d780b92SJakub Kicinski bool reconfig_timer_active; 6503d780b92SJakub Kicinski bool reconfig_sync_present; 6513d780b92SJakub Kicinski struct timer_list reconfig_timer; 6526db3a9dcSJakub Kicinski u32 reconfig_in_progress_update; 6534c352362SJakub Kicinski 6543ed77bf7SJakub Kicinski struct semaphore bar_lock; 655dd5b2498SJakub Kicinski 6564c352362SJakub Kicinski u32 rx_coalesce_usecs; 6574c352362SJakub Kicinski u32 rx_coalesce_max_frames; 6584c352362SJakub Kicinski u32 tx_coalesce_usecs; 6594c352362SJakub Kicinski u32 tx_coalesce_max_frames; 6604c352362SJakub Kicinski 6614c352362SJakub Kicinski __be16 vxlan_ports[NFP_NET_N_VXLAN_PORTS]; 6624c352362SJakub Kicinski u8 vxlan_usecnt[NFP_NET_N_VXLAN_PORTS]; 6634c352362SJakub Kicinski 6644c352362SJakub Kicinski u8 __iomem *qcp_cfg; 6654c352362SJakub Kicinski 6664c352362SJakub Kicinski u8 __iomem *tx_bar; 6674c352362SJakub Kicinski u8 __iomem *rx_bar; 6684c352362SJakub Kicinski 66973a0329bSJakub Kicinski struct nfp_net_tlv_caps tlv_caps; 67073a0329bSJakub Kicinski 6711f35a56cSDirk van der Merwe unsigned int ktls_tx_conn_cnt; 672c0a4948eSJakub Kicinski unsigned int ktls_rx_conn_cnt; 6731f35a56cSDirk van der Merwe 67453601c68SJakub Kicinski atomic64_t ktls_conn_id_gen; 67553601c68SJakub Kicinski 67651a5e563SJakub Kicinski atomic_t ktls_no_space; 67751a5e563SJakub Kicinski 678d3e4dfe0SJakub Kicinski struct { 679d3e4dfe0SJakub Kicinski struct sk_buff_head queue; 680d3e4dfe0SJakub Kicinski wait_queue_head_t wq; 681e2c7114aSJakub Kicinski struct workqueue_struct *workq; 682e2c7114aSJakub Kicinski struct work_struct wait_work; 683e2c7114aSJakub Kicinski struct work_struct runq_work; 684d3e4dfe0SJakub Kicinski u16 tag; 685d3e4dfe0SJakub Kicinski } mbox_cmsg; 686d3e4dfe0SJakub Kicinski 6874c352362SJakub Kicinski struct dentry *debugfs_dir; 68863461a02SJakub Kicinski 689d4e7f092SJakub Kicinski struct list_head vnic_list; 690bd5ca062SJakub Kicinski 691fa43d2a8SJakub Kicinski struct pci_dev *pdev; 6927ac9ebd5SJakub Kicinski struct nfp_app *app; 69347465aedSJakub Kicinski 694fe06a64eSJakub Kicinski bool vnic_no_name; 695fe06a64eSJakub Kicinski 696eb488c26SJakub Kicinski struct nfp_port *port; 697c66a9cf4SJakub Kicinski 698c66a9cf4SJakub Kicinski void *app_priv; 6994c352362SJakub Kicinski }; 7004c352362SJakub Kicinski 7014c352362SJakub Kicinski /* Functions to read/write from/to a BAR 7024c352362SJakub Kicinski * Performs any endian conversion necessary. 7034c352362SJakub Kicinski */ 7047533fdc0SJakub Kicinski static inline u16 nn_readb(struct nfp_net *nn, int off) 7057533fdc0SJakub Kicinski { 706d2b84397SJakub Kicinski return readb(nn->dp.ctrl_bar + off); 7077533fdc0SJakub Kicinski } 7087533fdc0SJakub Kicinski 7094c352362SJakub Kicinski static inline void nn_writeb(struct nfp_net *nn, int off, u8 val) 7104c352362SJakub Kicinski { 711d2b84397SJakub Kicinski writeb(val, nn->dp.ctrl_bar + off); 7124c352362SJakub Kicinski } 7134c352362SJakub Kicinski 7147533fdc0SJakub Kicinski static inline u16 nn_readw(struct nfp_net *nn, int off) 7157533fdc0SJakub Kicinski { 716d2b84397SJakub Kicinski return readw(nn->dp.ctrl_bar + off); 7177533fdc0SJakub Kicinski } 7187533fdc0SJakub Kicinski 7197533fdc0SJakub Kicinski static inline void nn_writew(struct nfp_net *nn, int off, u16 val) 7207533fdc0SJakub Kicinski { 721d2b84397SJakub Kicinski writew(val, nn->dp.ctrl_bar + off); 7227533fdc0SJakub Kicinski } 7234c352362SJakub Kicinski 7244c352362SJakub Kicinski static inline u32 nn_readl(struct nfp_net *nn, int off) 7254c352362SJakub Kicinski { 726d2b84397SJakub Kicinski return readl(nn->dp.ctrl_bar + off); 7274c352362SJakub Kicinski } 7284c352362SJakub Kicinski 7294c352362SJakub Kicinski static inline void nn_writel(struct nfp_net *nn, int off, u32 val) 7304c352362SJakub Kicinski { 731d2b84397SJakub Kicinski writel(val, nn->dp.ctrl_bar + off); 7324c352362SJakub Kicinski } 7334c352362SJakub Kicinski 7344c352362SJakub Kicinski static inline u64 nn_readq(struct nfp_net *nn, int off) 7354c352362SJakub Kicinski { 736d2b84397SJakub Kicinski return readq(nn->dp.ctrl_bar + off); 7374c352362SJakub Kicinski } 7384c352362SJakub Kicinski 7394c352362SJakub Kicinski static inline void nn_writeq(struct nfp_net *nn, int off, u64 val) 7404c352362SJakub Kicinski { 741d2b84397SJakub Kicinski writeq(val, nn->dp.ctrl_bar + off); 7424c352362SJakub Kicinski } 7434c352362SJakub Kicinski 7444c352362SJakub Kicinski /* Flush posted PCI writes by reading something without side effects */ 7454c352362SJakub Kicinski static inline void nn_pci_flush(struct nfp_net *nn) 7464c352362SJakub Kicinski { 7474c352362SJakub Kicinski nn_readl(nn, NFP_NET_CFG_VERSION); 7484c352362SJakub Kicinski } 7494c352362SJakub Kicinski 7504c352362SJakub Kicinski /* Queue Controller Peripheral access functions and definitions. 7514c352362SJakub Kicinski * 7524c352362SJakub Kicinski * Some of the BARs of the NFP are mapped to portions of the Queue 7534c352362SJakub Kicinski * Controller Peripheral (QCP) address space on the NFP. A QCP queue 7544c352362SJakub Kicinski * has a read and a write pointer (as well as a size and flags, 7554c352362SJakub Kicinski * indicating overflow etc). The QCP offers a number of different 7564c352362SJakub Kicinski * operation on queue pointers, but here we only offer function to 7574c352362SJakub Kicinski * either add to a pointer or to read the pointer value. 7584c352362SJakub Kicinski */ 7594c352362SJakub Kicinski #define NFP_QCP_QUEUE_ADDR_SZ 0x800 76073e253f0SJakub Kicinski #define NFP_QCP_QUEUE_AREA_SZ 0x80000 7614c352362SJakub Kicinski #define NFP_QCP_QUEUE_OFF(_x) ((_x) * NFP_QCP_QUEUE_ADDR_SZ) 7624c352362SJakub Kicinski #define NFP_QCP_QUEUE_ADD_RPTR 0x0000 7634c352362SJakub Kicinski #define NFP_QCP_QUEUE_ADD_WPTR 0x0004 7644c352362SJakub Kicinski #define NFP_QCP_QUEUE_STS_LO 0x0008 7654c352362SJakub Kicinski #define NFP_QCP_QUEUE_STS_LO_READPTR_mask 0x3ffff 7664c352362SJakub Kicinski #define NFP_QCP_QUEUE_STS_HI 0x000c 7674c352362SJakub Kicinski #define NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask 0x3ffff 7684c352362SJakub Kicinski 769416db5c1SJakub Kicinski /* The offset of a QCP queues in the PCIe Target */ 7704c352362SJakub Kicinski #define NFP_PCIE_QUEUE(_q) (0x80000 + (NFP_QCP_QUEUE_ADDR_SZ * ((_q) & 0xff))) 7714c352362SJakub Kicinski 7724c352362SJakub Kicinski /* nfp_qcp_ptr - Read or Write Pointer of a queue */ 7734c352362SJakub Kicinski enum nfp_qcp_ptr { 7744c352362SJakub Kicinski NFP_QCP_READ_PTR = 0, 7754c352362SJakub Kicinski NFP_QCP_WRITE_PTR 7764c352362SJakub Kicinski }; 7774c352362SJakub Kicinski 7784c352362SJakub Kicinski /* There appear to be an *undocumented* upper limit on the value which 7794c352362SJakub Kicinski * one can add to a queue and that value is either 0x3f or 0x7f. We 7804c352362SJakub Kicinski * go with 0x3f as a conservative measure. 7814c352362SJakub Kicinski */ 7824c352362SJakub Kicinski #define NFP_QCP_MAX_ADD 0x3f 7834c352362SJakub Kicinski 7844c352362SJakub Kicinski static inline void _nfp_qcp_ptr_add(u8 __iomem *q, 7854c352362SJakub Kicinski enum nfp_qcp_ptr ptr, u32 val) 7864c352362SJakub Kicinski { 7874c352362SJakub Kicinski u32 off; 7884c352362SJakub Kicinski 7894c352362SJakub Kicinski if (ptr == NFP_QCP_READ_PTR) 7904c352362SJakub Kicinski off = NFP_QCP_QUEUE_ADD_RPTR; 7914c352362SJakub Kicinski else 7924c352362SJakub Kicinski off = NFP_QCP_QUEUE_ADD_WPTR; 7934c352362SJakub Kicinski 7944c352362SJakub Kicinski while (val > NFP_QCP_MAX_ADD) { 7954c352362SJakub Kicinski writel(NFP_QCP_MAX_ADD, q + off); 7964c352362SJakub Kicinski val -= NFP_QCP_MAX_ADD; 7974c352362SJakub Kicinski } 7984c352362SJakub Kicinski 7994c352362SJakub Kicinski writel(val, q + off); 8004c352362SJakub Kicinski } 8014c352362SJakub Kicinski 8024c352362SJakub Kicinski /** 8034c352362SJakub Kicinski * nfp_qcp_rd_ptr_add() - Add the value to the read pointer of a queue 8044c352362SJakub Kicinski * 8054c352362SJakub Kicinski * @q: Base address for queue structure 8064c352362SJakub Kicinski * @val: Value to add to the queue pointer 8074c352362SJakub Kicinski * 8084c352362SJakub Kicinski * If @val is greater than @NFP_QCP_MAX_ADD multiple writes are performed. 8094c352362SJakub Kicinski */ 8104c352362SJakub Kicinski static inline void nfp_qcp_rd_ptr_add(u8 __iomem *q, u32 val) 8114c352362SJakub Kicinski { 8124c352362SJakub Kicinski _nfp_qcp_ptr_add(q, NFP_QCP_READ_PTR, val); 8134c352362SJakub Kicinski } 8144c352362SJakub Kicinski 8154c352362SJakub Kicinski /** 8164c352362SJakub Kicinski * nfp_qcp_wr_ptr_add() - Add the value to the write pointer of a queue 8174c352362SJakub Kicinski * 8184c352362SJakub Kicinski * @q: Base address for queue structure 8194c352362SJakub Kicinski * @val: Value to add to the queue pointer 8204c352362SJakub Kicinski * 8214c352362SJakub Kicinski * If @val is greater than @NFP_QCP_MAX_ADD multiple writes are performed. 8224c352362SJakub Kicinski */ 8234c352362SJakub Kicinski static inline void nfp_qcp_wr_ptr_add(u8 __iomem *q, u32 val) 8244c352362SJakub Kicinski { 8254c352362SJakub Kicinski _nfp_qcp_ptr_add(q, NFP_QCP_WRITE_PTR, val); 8264c352362SJakub Kicinski } 8274c352362SJakub Kicinski 8284c352362SJakub Kicinski static inline u32 _nfp_qcp_read(u8 __iomem *q, enum nfp_qcp_ptr ptr) 8294c352362SJakub Kicinski { 8304c352362SJakub Kicinski u32 off; 8314c352362SJakub Kicinski u32 val; 8324c352362SJakub Kicinski 8334c352362SJakub Kicinski if (ptr == NFP_QCP_READ_PTR) 8344c352362SJakub Kicinski off = NFP_QCP_QUEUE_STS_LO; 8354c352362SJakub Kicinski else 8364c352362SJakub Kicinski off = NFP_QCP_QUEUE_STS_HI; 8374c352362SJakub Kicinski 8384c352362SJakub Kicinski val = readl(q + off); 8394c352362SJakub Kicinski 8404c352362SJakub Kicinski if (ptr == NFP_QCP_READ_PTR) 8414c352362SJakub Kicinski return val & NFP_QCP_QUEUE_STS_LO_READPTR_mask; 8424c352362SJakub Kicinski else 8434c352362SJakub Kicinski return val & NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask; 8444c352362SJakub Kicinski } 8454c352362SJakub Kicinski 8464c352362SJakub Kicinski /** 8474c352362SJakub Kicinski * nfp_qcp_rd_ptr_read() - Read the current read pointer value for a queue 8484c352362SJakub Kicinski * @q: Base address for queue structure 8494c352362SJakub Kicinski * 8504c352362SJakub Kicinski * Return: Value read. 8514c352362SJakub Kicinski */ 8524c352362SJakub Kicinski static inline u32 nfp_qcp_rd_ptr_read(u8 __iomem *q) 8534c352362SJakub Kicinski { 8544c352362SJakub Kicinski return _nfp_qcp_read(q, NFP_QCP_READ_PTR); 8554c352362SJakub Kicinski } 8564c352362SJakub Kicinski 8574c352362SJakub Kicinski /** 8584c352362SJakub Kicinski * nfp_qcp_wr_ptr_read() - Read the current write pointer value for a queue 8594c352362SJakub Kicinski * @q: Base address for queue structure 8604c352362SJakub Kicinski * 8614c352362SJakub Kicinski * Return: Value read. 8624c352362SJakub Kicinski */ 8634c352362SJakub Kicinski static inline u32 nfp_qcp_wr_ptr_read(u8 __iomem *q) 8644c352362SJakub Kicinski { 8654c352362SJakub Kicinski return _nfp_qcp_read(q, NFP_QCP_WRITE_PTR); 8664c352362SJakub Kicinski } 8674c352362SJakub Kicinski 868042f4ba6SJakub Kicinski static inline bool nfp_net_is_data_vnic(struct nfp_net *nn) 869042f4ba6SJakub Kicinski { 870042f4ba6SJakub Kicinski WARN_ON_ONCE(!nn->dp.netdev && nn->port); 871042f4ba6SJakub Kicinski return !!nn->dp.netdev; 872042f4ba6SJakub Kicinski } 873042f4ba6SJakub Kicinski 874042f4ba6SJakub Kicinski static inline bool nfp_net_running(struct nfp_net *nn) 875042f4ba6SJakub Kicinski { 876042f4ba6SJakub Kicinski return nn->dp.ctrl & NFP_NET_CFG_CTRL_ENABLE; 877042f4ba6SJakub Kicinski } 878042f4ba6SJakub Kicinski 87977ece8d5SJakub Kicinski static inline const char *nfp_net_name(struct nfp_net *nn) 88077ece8d5SJakub Kicinski { 88177ece8d5SJakub Kicinski return nn->dp.netdev ? nn->dp.netdev->name : "ctrl"; 88277ece8d5SJakub Kicinski } 88377ece8d5SJakub Kicinski 884d48ae231SJakub Kicinski static inline void nfp_ctrl_lock(struct nfp_net *nn) 885d48ae231SJakub Kicinski __acquires(&nn->r_vecs[0].lock) 886d48ae231SJakub Kicinski { 887d48ae231SJakub Kicinski spin_lock_bh(&nn->r_vecs[0].lock); 888d48ae231SJakub Kicinski } 889d48ae231SJakub Kicinski 890d48ae231SJakub Kicinski static inline void nfp_ctrl_unlock(struct nfp_net *nn) 891d48ae231SJakub Kicinski __releases(&nn->r_vecs[0].lock) 892d48ae231SJakub Kicinski { 893d48ae231SJakub Kicinski spin_unlock_bh(&nn->r_vecs[0].lock); 894d48ae231SJakub Kicinski } 895d48ae231SJakub Kicinski 896dd5b2498SJakub Kicinski static inline void nn_ctrl_bar_lock(struct nfp_net *nn) 897dd5b2498SJakub Kicinski { 8983ed77bf7SJakub Kicinski down(&nn->bar_lock); 899dd5b2498SJakub Kicinski } 900dd5b2498SJakub Kicinski 901e2c7114aSJakub Kicinski static inline bool nn_ctrl_bar_trylock(struct nfp_net *nn) 902e2c7114aSJakub Kicinski { 903e2c7114aSJakub Kicinski return !down_trylock(&nn->bar_lock); 904e2c7114aSJakub Kicinski } 905e2c7114aSJakub Kicinski 906dd5b2498SJakub Kicinski static inline void nn_ctrl_bar_unlock(struct nfp_net *nn) 907dd5b2498SJakub Kicinski { 9083ed77bf7SJakub Kicinski up(&nn->bar_lock); 909dd5b2498SJakub Kicinski } 910dd5b2498SJakub Kicinski 9114c352362SJakub Kicinski /* Globals */ 9122633beb9SJakub Kicinski extern const char nfp_driver_version[]; 9134c352362SJakub Kicinski 914eb488c26SJakub Kicinski extern const struct net_device_ops nfp_net_netdev_ops; 915eb488c26SJakub Kicinski 916eb488c26SJakub Kicinski static inline bool nfp_netdev_is_nfp_net(struct net_device *netdev) 917eb488c26SJakub Kicinski { 918eb488c26SJakub Kicinski return netdev->netdev_ops == &nfp_net_netdev_ops; 919eb488c26SJakub Kicinski } 920eb488c26SJakub Kicinski 9214c352362SJakub Kicinski /* Prototypes */ 9224c352362SJakub Kicinski void nfp_net_get_fw_version(struct nfp_net_fw_version *fw_ver, 9234c352362SJakub Kicinski void __iomem *ctrl_bar); 9244c352362SJakub Kicinski 925a4b562bbSJakub Kicinski struct nfp_net * 926e38f5d11SJakub Kicinski nfp_net_alloc(struct pci_dev *pdev, void __iomem *ctrl_bar, bool needs_netdev, 927a4b562bbSJakub Kicinski unsigned int max_tx_rings, unsigned int max_rx_rings); 928beba69caSJakub Kicinski void nfp_net_free(struct nfp_net *nn); 929beba69caSJakub Kicinski 930beba69caSJakub Kicinski int nfp_net_init(struct nfp_net *nn); 931beba69caSJakub Kicinski void nfp_net_clean(struct nfp_net *nn); 932beba69caSJakub Kicinski 93377ece8d5SJakub Kicinski int nfp_ctrl_open(struct nfp_net *nn); 93477ece8d5SJakub Kicinski void nfp_ctrl_close(struct nfp_net *nn); 93577ece8d5SJakub Kicinski 9364c352362SJakub Kicinski void nfp_net_set_ethtool_ops(struct net_device *netdev); 9374c352362SJakub Kicinski void nfp_net_info(struct nfp_net *nn); 938232eeb1fSJakub Kicinski int __nfp_net_reconfig(struct nfp_net *nn, u32 update); 9394c352362SJakub Kicinski int nfp_net_reconfig(struct nfp_net *nn, u32 update); 9409ff304bfSJakub Kicinski unsigned int nfp_net_rss_key_sz(struct nfp_net *nn); 9414c352362SJakub Kicinski void nfp_net_rss_write_itbl(struct nfp_net *nn); 9424c352362SJakub Kicinski void nfp_net_rss_write_key(struct nfp_net *nn); 9434c352362SJakub Kicinski void nfp_net_coalesce_write_cfg(struct nfp_net *nn); 944dd5b2498SJakub Kicinski int nfp_net_mbox_lock(struct nfp_net *nn, unsigned int data_size); 945dd5b2498SJakub Kicinski int nfp_net_mbox_reconfig(struct nfp_net *nn, u32 mbox_cmd); 946dd5b2498SJakub Kicinski int nfp_net_mbox_reconfig_and_unlock(struct nfp_net *nn, u32 mbox_cmd); 947e2c7114aSJakub Kicinski void nfp_net_mbox_reconfig_post(struct nfp_net *nn, u32 update); 948e2c7114aSJakub Kicinski int nfp_net_mbox_reconfig_wait_posted(struct nfp_net *nn); 949fdace6c2SJakub Kicinski 950fdace6c2SJakub Kicinski unsigned int 951fdace6c2SJakub Kicinski nfp_net_irqs_alloc(struct pci_dev *pdev, struct msix_entry *irq_entries, 952fdace6c2SJakub Kicinski unsigned int min_irqs, unsigned int want_irqs); 953fdace6c2SJakub Kicinski void nfp_net_irqs_disable(struct pci_dev *pdev); 954fdace6c2SJakub Kicinski void 955fdace6c2SJakub Kicinski nfp_net_irqs_assign(struct nfp_net *nn, struct msix_entry *irq_entries, 956fdace6c2SJakub Kicinski unsigned int n); 957783496b0SJakub Kicinski 958783496b0SJakub Kicinski struct nfp_net_dp *nfp_net_clone_dp(struct nfp_net *nn); 959d957c0f7SJakub Kicinski int nfp_net_ring_reconfig(struct nfp_net *nn, struct nfp_net_dp *new, 960d957c0f7SJakub Kicinski struct netlink_ext_ack *extack); 9614c352362SJakub Kicinski 9622633beb9SJakub Kicinski #ifdef CONFIG_NFP_DEBUG 9634c352362SJakub Kicinski void nfp_net_debugfs_create(void); 9644c352362SJakub Kicinski void nfp_net_debugfs_destroy(void); 9656f1cd5caSJakub Kicinski struct dentry *nfp_net_debugfs_device_add(struct pci_dev *pdev); 96651c1df83SJakub Kicinski void nfp_net_debugfs_vnic_add(struct nfp_net *nn, struct dentry *ddir); 9676f1cd5caSJakub Kicinski void nfp_net_debugfs_dir_clean(struct dentry **dir); 9684c352362SJakub Kicinski #else 9694c352362SJakub Kicinski static inline void nfp_net_debugfs_create(void) 9704c352362SJakub Kicinski { 9714c352362SJakub Kicinski } 9724c352362SJakub Kicinski 9734c352362SJakub Kicinski static inline void nfp_net_debugfs_destroy(void) 9744c352362SJakub Kicinski { 9754c352362SJakub Kicinski } 9764c352362SJakub Kicinski 9776f1cd5caSJakub Kicinski static inline struct dentry *nfp_net_debugfs_device_add(struct pci_dev *pdev) 9786f1cd5caSJakub Kicinski { 9796f1cd5caSJakub Kicinski return NULL; 9806f1cd5caSJakub Kicinski } 9816f1cd5caSJakub Kicinski 9826f1cd5caSJakub Kicinski static inline void 98351c1df83SJakub Kicinski nfp_net_debugfs_vnic_add(struct nfp_net *nn, struct dentry *ddir) 9844c352362SJakub Kicinski { 9854c352362SJakub Kicinski } 9864c352362SJakub Kicinski 9876f1cd5caSJakub Kicinski static inline void nfp_net_debugfs_dir_clean(struct dentry **dir) 9884c352362SJakub Kicinski { 9894c352362SJakub Kicinski } 9902633beb9SJakub Kicinski #endif /* CONFIG_NFP_DEBUG */ 9914c352362SJakub Kicinski 9924c352362SJakub Kicinski #endif /* _NFP_NET_H_ */ 993