14c352362SJakub Kicinski /* 22633beb9SJakub Kicinski * Copyright (C) 2015-2017 Netronome Systems, Inc. 34c352362SJakub Kicinski * 44c352362SJakub Kicinski * This software is dual licensed under the GNU General License Version 2, 54c352362SJakub Kicinski * June 1991 as shown in the file COPYING in the top-level directory of this 64c352362SJakub Kicinski * source tree or the BSD 2-Clause License provided below. You have the 74c352362SJakub Kicinski * option to license this software under the complete terms of either license. 84c352362SJakub Kicinski * 94c352362SJakub Kicinski * The BSD 2-Clause License: 104c352362SJakub Kicinski * 114c352362SJakub Kicinski * Redistribution and use in source and binary forms, with or 124c352362SJakub Kicinski * without modification, are permitted provided that the following 134c352362SJakub Kicinski * conditions are met: 144c352362SJakub Kicinski * 154c352362SJakub Kicinski * 1. Redistributions of source code must retain the above 164c352362SJakub Kicinski * copyright notice, this list of conditions and the following 174c352362SJakub Kicinski * disclaimer. 184c352362SJakub Kicinski * 194c352362SJakub Kicinski * 2. Redistributions in binary form must reproduce the above 204c352362SJakub Kicinski * copyright notice, this list of conditions and the following 214c352362SJakub Kicinski * disclaimer in the documentation and/or other materials 224c352362SJakub Kicinski * provided with the distribution. 234c352362SJakub Kicinski * 244c352362SJakub Kicinski * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 254c352362SJakub Kicinski * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 264c352362SJakub Kicinski * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 274c352362SJakub Kicinski * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 284c352362SJakub Kicinski * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 294c352362SJakub Kicinski * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 304c352362SJakub Kicinski * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 314c352362SJakub Kicinski * SOFTWARE. 324c352362SJakub Kicinski */ 334c352362SJakub Kicinski 344c352362SJakub Kicinski /* 354c352362SJakub Kicinski * nfp_net.h 364c352362SJakub Kicinski * Declarations for Netronome network device driver. 374c352362SJakub Kicinski * Authors: Jakub Kicinski <jakub.kicinski@netronome.com> 384c352362SJakub Kicinski * Jason McMullan <jason.mcmullan@netronome.com> 394c352362SJakub Kicinski * Rolf Neugebauer <rolf.neugebauer@netronome.com> 404c352362SJakub Kicinski */ 414c352362SJakub Kicinski 424c352362SJakub Kicinski #ifndef _NFP_NET_H_ 434c352362SJakub Kicinski #define _NFP_NET_H_ 444c352362SJakub Kicinski 454c352362SJakub Kicinski #include <linux/interrupt.h> 4663461a02SJakub Kicinski #include <linux/list.h> 474c352362SJakub Kicinski #include <linux/netdevice.h> 484c352362SJakub Kicinski #include <linux/pci.h> 49a1cbaad7SArnd Bergmann #include <linux/io-64-nonatomic-hi-lo.h> 504c352362SJakub Kicinski 514c352362SJakub Kicinski #include "nfp_net_ctrl.h" 524c352362SJakub Kicinski 5379c12a75SJakub Kicinski #define nn_err(nn, fmt, args...) netdev_err((nn)->dp.netdev, fmt, ## args) 5479c12a75SJakub Kicinski #define nn_warn(nn, fmt, args...) netdev_warn((nn)->dp.netdev, fmt, ## args) 5579c12a75SJakub Kicinski #define nn_info(nn, fmt, args...) netdev_info((nn)->dp.netdev, fmt, ## args) 5679c12a75SJakub Kicinski #define nn_dbg(nn, fmt, args...) netdev_dbg((nn)->dp.netdev, fmt, ## args) 5779c12a75SJakub Kicinski #define nn_dp_warn(dp, fmt, args...) \ 584c352362SJakub Kicinski do { \ 594c352362SJakub Kicinski if (unlikely(net_ratelimit())) \ 6079c12a75SJakub Kicinski netdev_warn((dp)->netdev, fmt, ## args); \ 614c352362SJakub Kicinski } while (0) 624c352362SJakub Kicinski 633d780b92SJakub Kicinski /* Max time to wait for NFP to respond on updates (in seconds) */ 643d780b92SJakub Kicinski #define NFP_NET_POLL_TIMEOUT 5 654c352362SJakub Kicinski 6666860bebSJakub Kicinski /* Interval for reading offloaded filter stats */ 6766860bebSJakub Kicinski #define NFP_NET_STAT_POLL_IVL msecs_to_jiffies(100) 6866860bebSJakub Kicinski 694c352362SJakub Kicinski /* Bar allocation */ 70796312cdSJakub Kicinski #define NFP_NET_CTRL_BAR 0 714c352362SJakub Kicinski #define NFP_NET_Q0_BAR 2 724c352362SJakub Kicinski #define NFP_NET_Q1_BAR 4 /* OBSOLETE */ 734c352362SJakub Kicinski 744c352362SJakub Kicinski /* Max bits in DMA address */ 754c352362SJakub Kicinski #define NFP_NET_MAX_DMA_BITS 40 764c352362SJakub Kicinski 774c352362SJakub Kicinski /* Default size for MTU and freelist buffer sizes */ 784c352362SJakub Kicinski #define NFP_NET_DEFAULT_MTU 1500 794c352362SJakub Kicinski 804c352362SJakub Kicinski /* Maximum number of bytes prepended to a packet */ 814c352362SJakub Kicinski #define NFP_NET_MAX_PREPEND 64 824c352362SJakub Kicinski 834c352362SJakub Kicinski /* Interrupt definitions */ 844c352362SJakub Kicinski #define NFP_NET_NON_Q_VECTORS 2 854c352362SJakub Kicinski #define NFP_NET_IRQ_LSC_IDX 0 864c352362SJakub Kicinski #define NFP_NET_IRQ_EXN_IDX 1 87d4e7f092SJakub Kicinski #define NFP_NET_MIN_VNIC_IRQS (NFP_NET_NON_Q_VECTORS + 1) 884c352362SJakub Kicinski 894c352362SJakub Kicinski /* Queue/Ring definitions */ 904c352362SJakub Kicinski #define NFP_NET_MAX_TX_RINGS 64 /* Max. # of Tx rings per device */ 914c352362SJakub Kicinski #define NFP_NET_MAX_RX_RINGS 64 /* Max. # of Rx rings per device */ 9223a4e389SJakub Kicinski #define NFP_NET_MAX_R_VECS (NFP_NET_MAX_TX_RINGS > NFP_NET_MAX_RX_RINGS ? \ 9323a4e389SJakub Kicinski NFP_NET_MAX_TX_RINGS : NFP_NET_MAX_RX_RINGS) 9423a4e389SJakub Kicinski #define NFP_NET_MAX_IRQS (NFP_NET_NON_Q_VECTORS + NFP_NET_MAX_R_VECS) 954c352362SJakub Kicinski 964c352362SJakub Kicinski #define NFP_NET_MIN_TX_DESCS 256 /* Min. # of Tx descs per ring */ 974c352362SJakub Kicinski #define NFP_NET_MIN_RX_DESCS 256 /* Min. # of Rx descs per ring */ 984c352362SJakub Kicinski #define NFP_NET_MAX_TX_DESCS (256 * 1024) /* Max. # of Tx descs per ring */ 994c352362SJakub Kicinski #define NFP_NET_MAX_RX_DESCS (256 * 1024) /* Max. # of Rx descs per ring */ 1004c352362SJakub Kicinski 1014c352362SJakub Kicinski #define NFP_NET_TX_DESCS_DEFAULT 4096 /* Default # of Tx descs per ring */ 1024c352362SJakub Kicinski #define NFP_NET_RX_DESCS_DEFAULT 4096 /* Default # of Rx descs per ring */ 1034c352362SJakub Kicinski 1044c352362SJakub Kicinski #define NFP_NET_FL_BATCH 16 /* Add freelist in this Batch size */ 105abeeec4aSJakub Kicinski #define NFP_NET_XDP_MAX_COMPLETE 2048 /* XDP bufs to reclaim in NAPI poll */ 1064c352362SJakub Kicinski 1074c352362SJakub Kicinski /* Offload definitions */ 1084c352362SJakub Kicinski #define NFP_NET_N_VXLAN_PORTS (NFP_NET_CFG_VXLAN_SZ / sizeof(__be16)) 1094c352362SJakub Kicinski 110c0f031bcSJakub Kicinski #define NFP_NET_RX_BUF_HEADROOM (NET_SKB_PAD + NET_IP_ALIGN) 111c0f031bcSJakub Kicinski #define NFP_NET_RX_BUF_NON_DATA (NFP_NET_RX_BUF_HEADROOM + \ 112c0f031bcSJakub Kicinski SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) 113c0f031bcSJakub Kicinski 1144c352362SJakub Kicinski /* Forward declarations */ 115bd5ca062SJakub Kicinski struct nfp_cpp; 11647465aedSJakub Kicinski struct nfp_eth_table_port; 1174c352362SJakub Kicinski struct nfp_net; 1184c352362SJakub Kicinski struct nfp_net_r_vector; 1194c352362SJakub Kicinski 1204aa3b766SJakub Kicinski /* Convenience macro for wrapping descriptor index on ring size */ 1214aa3b766SJakub Kicinski #define D_IDX(ring, idx) ((idx) & ((ring)->cnt - 1)) 1224aa3b766SJakub Kicinski 1234c352362SJakub Kicinski /* Convenience macro for writing dma address into RX/TX descriptors */ 1244c352362SJakub Kicinski #define nfp_desc_set_dma_addr(desc, dma_addr) \ 1254c352362SJakub Kicinski do { \ 1264c352362SJakub Kicinski __typeof(desc) __d = (desc); \ 1274c352362SJakub Kicinski dma_addr_t __addr = (dma_addr); \ 1284c352362SJakub Kicinski \ 1294c352362SJakub Kicinski __d->dma_addr_lo = cpu_to_le32(lower_32_bits(__addr)); \ 1304c352362SJakub Kicinski __d->dma_addr_hi = upper_32_bits(__addr) & 0xff; \ 1314c352362SJakub Kicinski } while (0) 1324c352362SJakub Kicinski 1334c352362SJakub Kicinski /* TX descriptor format */ 1344c352362SJakub Kicinski 1354c352362SJakub Kicinski #define PCIE_DESC_TX_EOP BIT(7) 1364c352362SJakub Kicinski #define PCIE_DESC_TX_OFFSET_MASK GENMASK(6, 0) 1374c352362SJakub Kicinski #define PCIE_DESC_TX_MSS_MASK GENMASK(13, 0) 1384c352362SJakub Kicinski 1394c352362SJakub Kicinski /* Flags in the host TX descriptor */ 1404c352362SJakub Kicinski #define PCIE_DESC_TX_CSUM BIT(7) 1414c352362SJakub Kicinski #define PCIE_DESC_TX_IP4_CSUM BIT(6) 1424c352362SJakub Kicinski #define PCIE_DESC_TX_TCP_CSUM BIT(5) 1434c352362SJakub Kicinski #define PCIE_DESC_TX_UDP_CSUM BIT(4) 1444c352362SJakub Kicinski #define PCIE_DESC_TX_VLAN BIT(3) 1454c352362SJakub Kicinski #define PCIE_DESC_TX_LSO BIT(2) 1464c352362SJakub Kicinski #define PCIE_DESC_TX_ENCAP BIT(1) 1474c352362SJakub Kicinski #define PCIE_DESC_TX_O_IP4_CSUM BIT(0) 1484c352362SJakub Kicinski 1494c352362SJakub Kicinski struct nfp_net_tx_desc { 1504c352362SJakub Kicinski union { 1514c352362SJakub Kicinski struct { 1524c352362SJakub Kicinski u8 dma_addr_hi; /* High bits of host buf address */ 1534c352362SJakub Kicinski __le16 dma_len; /* Length to DMA for this desc */ 1544c352362SJakub Kicinski u8 offset_eop; /* Offset in buf where pkt starts + 1554c352362SJakub Kicinski * highest bit is eop flag. 1564c352362SJakub Kicinski */ 1574c352362SJakub Kicinski __le32 dma_addr_lo; /* Low 32bit of host buf addr */ 1584c352362SJakub Kicinski 1594c352362SJakub Kicinski __le16 mss; /* MSS to be used for LSO */ 160e53fc9faSEdwin Peer u8 lso_hdrlen; /* LSO, TCP payload offset */ 1614c352362SJakub Kicinski u8 flags; /* TX Flags, see @PCIE_DESC_TX_* */ 16228063be6SEdwin Peer union { 16328063be6SEdwin Peer struct { 16428063be6SEdwin Peer u8 l3_offset; /* L3 header offset */ 16528063be6SEdwin Peer u8 l4_offset; /* L4 header offset */ 16628063be6SEdwin Peer }; 1674c352362SJakub Kicinski __le16 vlan; /* VLAN tag to add if indicated */ 16828063be6SEdwin Peer }; 1694c352362SJakub Kicinski __le16 data_len; /* Length of frame + meta data */ 1704c352362SJakub Kicinski } __packed; 1714c352362SJakub Kicinski __le32 vals[4]; 1724c352362SJakub Kicinski }; 1734c352362SJakub Kicinski }; 1744c352362SJakub Kicinski 1754c352362SJakub Kicinski /** 1764c352362SJakub Kicinski * struct nfp_net_tx_buf - software TX buffer descriptor 1774c352362SJakub Kicinski * @skb: sk_buff associated with this buffer 1784c352362SJakub Kicinski * @dma_addr: DMA mapping address of the buffer 1794c352362SJakub Kicinski * @fidx: Fragment index (-1 for the head and [0..nr_frags-1] for frags) 1804c352362SJakub Kicinski * @pkt_cnt: Number of packets to be produced out of the skb associated 1814c352362SJakub Kicinski * with this buffer (valid only on the head's buffer). 1824c352362SJakub Kicinski * Will be 1 for all non-TSO packets. 1834c352362SJakub Kicinski * @real_len: Number of bytes which to be produced out of the skb (valid only 1844c352362SJakub Kicinski * on the head's buffer). Equal to skb->len for non-TSO packets. 1854c352362SJakub Kicinski */ 1864c352362SJakub Kicinski struct nfp_net_tx_buf { 187ecd63a02SJakub Kicinski union { 1884c352362SJakub Kicinski struct sk_buff *skb; 189ecd63a02SJakub Kicinski void *frag; 190ecd63a02SJakub Kicinski }; 1914c352362SJakub Kicinski dma_addr_t dma_addr; 1924c352362SJakub Kicinski short int fidx; 1934c352362SJakub Kicinski u16 pkt_cnt; 1944c352362SJakub Kicinski u32 real_len; 1954c352362SJakub Kicinski }; 1964c352362SJakub Kicinski 1974c352362SJakub Kicinski /** 1984c352362SJakub Kicinski * struct nfp_net_tx_ring - TX ring structure 1994c352362SJakub Kicinski * @r_vec: Back pointer to ring vector structure 2004c352362SJakub Kicinski * @idx: Ring index from Linux's perspective 2014c352362SJakub Kicinski * @qcidx: Queue Controller Peripheral (QCP) queue index for the TX queue 2024c352362SJakub Kicinski * @qcp_q: Pointer to base of the QCP TX queue 2034c352362SJakub Kicinski * @cnt: Size of the queue in number of descriptors 2044c352362SJakub Kicinski * @wr_p: TX ring write pointer (free running) 2054c352362SJakub Kicinski * @rd_p: TX ring read pointer (free running) 2064c352362SJakub Kicinski * @qcp_rd_p: Local copy of QCP TX queue read pointer 2074c352362SJakub Kicinski * @wr_ptr_add: Accumulated number of buffers to add to QCP write pointer 2084c352362SJakub Kicinski * (used for .xmit_more delayed kick) 2094c352362SJakub Kicinski * @txbufs: Array of transmitted TX buffers, to free on transmit 2104c352362SJakub Kicinski * @txds: Virtual address of TX ring in host memory 2114c352362SJakub Kicinski * @dma: DMA address of the TX ring 2124c352362SJakub Kicinski * @size: Size, in bytes, of the TX ring (needed to free) 21392e68195SJakub Kicinski * @is_xdp: Is this a XDP TX ring? 2144c352362SJakub Kicinski */ 2154c352362SJakub Kicinski struct nfp_net_tx_ring { 2164c352362SJakub Kicinski struct nfp_net_r_vector *r_vec; 2174c352362SJakub Kicinski 2184c352362SJakub Kicinski u32 idx; 2194c352362SJakub Kicinski int qcidx; 2204c352362SJakub Kicinski u8 __iomem *qcp_q; 2214c352362SJakub Kicinski 2224c352362SJakub Kicinski u32 cnt; 2234c352362SJakub Kicinski u32 wr_p; 2244c352362SJakub Kicinski u32 rd_p; 2254c352362SJakub Kicinski u32 qcp_rd_p; 2264c352362SJakub Kicinski 2274c352362SJakub Kicinski u32 wr_ptr_add; 2284c352362SJakub Kicinski 2294c352362SJakub Kicinski struct nfp_net_tx_buf *txbufs; 2304c352362SJakub Kicinski struct nfp_net_tx_desc *txds; 2314c352362SJakub Kicinski 2324c352362SJakub Kicinski dma_addr_t dma; 2334c352362SJakub Kicinski unsigned int size; 23492e68195SJakub Kicinski bool is_xdp; 2354c352362SJakub Kicinski } ____cacheline_aligned; 2364c352362SJakub Kicinski 2374c352362SJakub Kicinski /* RX and freelist descriptor format */ 2384c352362SJakub Kicinski 2394c352362SJakub Kicinski #define PCIE_DESC_RX_DD BIT(7) 2404c352362SJakub Kicinski #define PCIE_DESC_RX_META_LEN_MASK GENMASK(6, 0) 2414c352362SJakub Kicinski 2424c352362SJakub Kicinski /* Flags in the RX descriptor */ 2434c352362SJakub Kicinski #define PCIE_DESC_RX_RSS cpu_to_le16(BIT(15)) 2444c352362SJakub Kicinski #define PCIE_DESC_RX_I_IP4_CSUM cpu_to_le16(BIT(14)) 2454c352362SJakub Kicinski #define PCIE_DESC_RX_I_IP4_CSUM_OK cpu_to_le16(BIT(13)) 2464c352362SJakub Kicinski #define PCIE_DESC_RX_I_TCP_CSUM cpu_to_le16(BIT(12)) 2474c352362SJakub Kicinski #define PCIE_DESC_RX_I_TCP_CSUM_OK cpu_to_le16(BIT(11)) 2484c352362SJakub Kicinski #define PCIE_DESC_RX_I_UDP_CSUM cpu_to_le16(BIT(10)) 2494c352362SJakub Kicinski #define PCIE_DESC_RX_I_UDP_CSUM_OK cpu_to_le16(BIT(9)) 2507533fdc0SJakub Kicinski #define PCIE_DESC_RX_BPF cpu_to_le16(BIT(8)) 2514c352362SJakub Kicinski #define PCIE_DESC_RX_EOP cpu_to_le16(BIT(7)) 2524c352362SJakub Kicinski #define PCIE_DESC_RX_IP4_CSUM cpu_to_le16(BIT(6)) 2534c352362SJakub Kicinski #define PCIE_DESC_RX_IP4_CSUM_OK cpu_to_le16(BIT(5)) 2544c352362SJakub Kicinski #define PCIE_DESC_RX_TCP_CSUM cpu_to_le16(BIT(4)) 2554c352362SJakub Kicinski #define PCIE_DESC_RX_TCP_CSUM_OK cpu_to_le16(BIT(3)) 2564c352362SJakub Kicinski #define PCIE_DESC_RX_UDP_CSUM cpu_to_le16(BIT(2)) 2574c352362SJakub Kicinski #define PCIE_DESC_RX_UDP_CSUM_OK cpu_to_le16(BIT(1)) 2584c352362SJakub Kicinski #define PCIE_DESC_RX_VLAN cpu_to_le16(BIT(0)) 2594c352362SJakub Kicinski 2604c352362SJakub Kicinski #define PCIE_DESC_RX_CSUM_ALL (PCIE_DESC_RX_IP4_CSUM | \ 2614c352362SJakub Kicinski PCIE_DESC_RX_TCP_CSUM | \ 2624c352362SJakub Kicinski PCIE_DESC_RX_UDP_CSUM | \ 2634c352362SJakub Kicinski PCIE_DESC_RX_I_IP4_CSUM | \ 2644c352362SJakub Kicinski PCIE_DESC_RX_I_TCP_CSUM | \ 2654c352362SJakub Kicinski PCIE_DESC_RX_I_UDP_CSUM) 2664c352362SJakub Kicinski #define PCIE_DESC_RX_CSUM_OK_SHIFT 1 2674c352362SJakub Kicinski #define __PCIE_DESC_RX_CSUM_ALL le16_to_cpu(PCIE_DESC_RX_CSUM_ALL) 2684c352362SJakub Kicinski #define __PCIE_DESC_RX_CSUM_ALL_OK (__PCIE_DESC_RX_CSUM_ALL >> \ 2694c352362SJakub Kicinski PCIE_DESC_RX_CSUM_OK_SHIFT) 2704c352362SJakub Kicinski 2714c352362SJakub Kicinski struct nfp_net_rx_desc { 2724c352362SJakub Kicinski union { 2734c352362SJakub Kicinski struct { 2744c352362SJakub Kicinski u8 dma_addr_hi; /* High bits of the buf address */ 2754c352362SJakub Kicinski __le16 reserved; /* Must be zero */ 2764c352362SJakub Kicinski u8 meta_len_dd; /* Must be zero */ 2774c352362SJakub Kicinski 2784c352362SJakub Kicinski __le32 dma_addr_lo; /* Low bits of the buffer address */ 2794c352362SJakub Kicinski } __packed fld; 2804c352362SJakub Kicinski 2814c352362SJakub Kicinski struct { 2824c352362SJakub Kicinski __le16 data_len; /* Length of the frame + meta data */ 2834c352362SJakub Kicinski u8 reserved; 2844c352362SJakub Kicinski u8 meta_len_dd; /* Length of meta data prepended + 2854c352362SJakub Kicinski * descriptor done flag. 2864c352362SJakub Kicinski */ 2874c352362SJakub Kicinski 2884c352362SJakub Kicinski __le16 flags; /* RX flags. See @PCIE_DESC_RX_* */ 2894c352362SJakub Kicinski __le16 vlan; /* VLAN if stripped */ 2904c352362SJakub Kicinski } __packed rxd; 2914c352362SJakub Kicinski 2924c352362SJakub Kicinski __le32 vals[2]; 2934c352362SJakub Kicinski }; 2944c352362SJakub Kicinski }; 2954c352362SJakub Kicinski 29619d0f54eSJakub Kicinski #define NFP_NET_META_FIELD_MASK GENMASK(NFP_NET_META_FIELD_SIZE - 1, 0) 29719d0f54eSJakub Kicinski 298e524a6a9SJakub Kicinski struct nfp_meta_parsed { 299ddb98d94SJakub Kicinski u8 hash_type; 300ddb98d94SJakub Kicinski u8 csum_type; 301e524a6a9SJakub Kicinski u32 hash; 302e524a6a9SJakub Kicinski u32 mark; 303ddb98d94SJakub Kicinski __wsum csum; 304e524a6a9SJakub Kicinski }; 305e524a6a9SJakub Kicinski 3064c352362SJakub Kicinski struct nfp_net_rx_hash { 3074c352362SJakub Kicinski __be32 hash_type; 3084c352362SJakub Kicinski __be32 hash; 3094c352362SJakub Kicinski }; 3104c352362SJakub Kicinski 3114c352362SJakub Kicinski /** 3124c352362SJakub Kicinski * struct nfp_net_rx_buf - software RX buffer descriptor 313c0f031bcSJakub Kicinski * @frag: page fragment buffer 3144c352362SJakub Kicinski * @dma_addr: DMA mapping address of the buffer 3154c352362SJakub Kicinski */ 3164c352362SJakub Kicinski struct nfp_net_rx_buf { 317c0f031bcSJakub Kicinski void *frag; 3184c352362SJakub Kicinski dma_addr_t dma_addr; 3194c352362SJakub Kicinski }; 3204c352362SJakub Kicinski 3214c352362SJakub Kicinski /** 3224c352362SJakub Kicinski * struct nfp_net_rx_ring - RX ring structure 3234c352362SJakub Kicinski * @r_vec: Back pointer to ring vector structure 3244c352362SJakub Kicinski * @cnt: Size of the queue in number of descriptors 3254c352362SJakub Kicinski * @wr_p: FL/RX ring write pointer (free running) 3264c352362SJakub Kicinski * @rd_p: FL/RX ring read pointer (free running) 3274c352362SJakub Kicinski * @idx: Ring index from Linux's perspective 3284c352362SJakub Kicinski * @fl_qcidx: Queue Controller Peripheral (QCP) queue index for the freelist 3294c352362SJakub Kicinski * @qcp_fl: Pointer to base of the QCP freelist queue 3304c352362SJakub Kicinski * @wr_ptr_add: Accumulated number of buffers to add to QCP write pointer 3314c352362SJakub Kicinski * (used for free list batching) 3324c352362SJakub Kicinski * @rxbufs: Array of transmitted FL/RX buffers 3334c352362SJakub Kicinski * @rxds: Virtual address of FL/RX ring in host memory 3344c352362SJakub Kicinski * @dma: DMA address of the FL/RX ring 3354c352362SJakub Kicinski * @size: Size, in bytes, of the FL/RX ring (needed to free) 3364c352362SJakub Kicinski */ 3374c352362SJakub Kicinski struct nfp_net_rx_ring { 3384c352362SJakub Kicinski struct nfp_net_r_vector *r_vec; 3394c352362SJakub Kicinski 3404c352362SJakub Kicinski u32 cnt; 3414c352362SJakub Kicinski u32 wr_p; 3424c352362SJakub Kicinski u32 rd_p; 3434c352362SJakub Kicinski 34483d08a1dSJakub Kicinski u32 idx; 34583d08a1dSJakub Kicinski u32 wr_ptr_add; 3464c352362SJakub Kicinski 3474c352362SJakub Kicinski int fl_qcidx; 3484c352362SJakub Kicinski u8 __iomem *qcp_fl; 3494c352362SJakub Kicinski 3504c352362SJakub Kicinski struct nfp_net_rx_buf *rxbufs; 3514c352362SJakub Kicinski struct nfp_net_rx_desc *rxds; 3524c352362SJakub Kicinski 3534c352362SJakub Kicinski dma_addr_t dma; 3544c352362SJakub Kicinski unsigned int size; 3554c352362SJakub Kicinski } ____cacheline_aligned; 3564c352362SJakub Kicinski 3574c352362SJakub Kicinski /** 3584c352362SJakub Kicinski * struct nfp_net_r_vector - Per ring interrupt vector configuration 3594c352362SJakub Kicinski * @nfp_net: Backpointer to nfp_net structure 3604c352362SJakub Kicinski * @napi: NAPI structure for this ring vec 3614c352362SJakub Kicinski * @tx_ring: Pointer to TX ring 3624c352362SJakub Kicinski * @rx_ring: Pointer to RX ring 363ecd63a02SJakub Kicinski * @xdp_ring: Pointer to an extra TX ring for XDP 364fdace6c2SJakub Kicinski * @irq_entry: MSI-X table entry (use for talking to the device) 3654c352362SJakub Kicinski * @rx_sync: Seqlock for atomic updates of RX stats 3664c352362SJakub Kicinski * @rx_pkts: Number of received packets 3674c352362SJakub Kicinski * @rx_bytes: Number of received bytes 3684c352362SJakub Kicinski * @rx_drops: Number of packets dropped on RX due to lack of resources 3694c352362SJakub Kicinski * @hw_csum_rx_ok: Counter of packets where the HW checksum was OK 3704c352362SJakub Kicinski * @hw_csum_rx_inner_ok: Counter of packets where the inner HW checksum was OK 3714c352362SJakub Kicinski * @hw_csum_rx_error: Counter of packets with bad checksums 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 3794c352362SJakub Kicinski * @tx_errors: How many TX errors were encountered 3804c352362SJakub Kicinski * @tx_busy: How often was TX busy (no space)? 381fdace6c2SJakub Kicinski * @irq_vector: Interrupt vector number (use for talking to the OS) 3824c352362SJakub Kicinski * @handler: Interrupt handler for this ring vector 3834c352362SJakub Kicinski * @name: Name of the interrupt vector 3844c352362SJakub Kicinski * @affinity_mask: SMP affinity mask for this vector 3854c352362SJakub Kicinski * 3864c352362SJakub Kicinski * This structure ties RX and TX rings to interrupt vectors and a NAPI 3874c352362SJakub Kicinski * context. This currently only supports one RX and TX ring per 3884c352362SJakub Kicinski * interrupt vector but might be extended in the future to allow 3894c352362SJakub Kicinski * association of multiple rings per vector. 3904c352362SJakub Kicinski */ 3914c352362SJakub Kicinski struct nfp_net_r_vector { 3924c352362SJakub Kicinski struct nfp_net *nfp_net; 3934c352362SJakub Kicinski struct napi_struct napi; 3944c352362SJakub Kicinski 3954c352362SJakub Kicinski struct nfp_net_tx_ring *tx_ring; 3964c352362SJakub Kicinski struct nfp_net_rx_ring *rx_ring; 3974c352362SJakub Kicinski 398fdace6c2SJakub Kicinski u16 irq_entry; 3994c352362SJakub Kicinski 4004c352362SJakub Kicinski struct u64_stats_sync rx_sync; 4014c352362SJakub Kicinski u64 rx_pkts; 4024c352362SJakub Kicinski u64 rx_bytes; 4034c352362SJakub Kicinski u64 rx_drops; 4044c352362SJakub Kicinski u64 hw_csum_rx_ok; 4054c352362SJakub Kicinski u64 hw_csum_rx_inner_ok; 4064c352362SJakub Kicinski u64 hw_csum_rx_error; 4074c352362SJakub Kicinski 408ecd63a02SJakub Kicinski struct nfp_net_tx_ring *xdp_ring; 409ecd63a02SJakub Kicinski 4104c352362SJakub Kicinski struct u64_stats_sync tx_sync; 4114c352362SJakub Kicinski u64 tx_pkts; 4124c352362SJakub Kicinski u64 tx_bytes; 4134c352362SJakub Kicinski u64 hw_csum_tx; 4144c352362SJakub Kicinski u64 hw_csum_tx_inner; 4154c352362SJakub Kicinski u64 tx_gather; 4164c352362SJakub Kicinski u64 tx_lso; 4174c352362SJakub Kicinski u64 tx_errors; 4184c352362SJakub Kicinski u64 tx_busy; 4194c352362SJakub Kicinski 420fdace6c2SJakub Kicinski u32 irq_vector; 4214c352362SJakub Kicinski irq_handler_t handler; 4224c352362SJakub Kicinski char name[IFNAMSIZ + 8]; 4234c352362SJakub Kicinski cpumask_t affinity_mask; 4244c352362SJakub Kicinski } ____cacheline_aligned; 4254c352362SJakub Kicinski 4264c352362SJakub Kicinski /* Firmware version as it is written in the 32bit value in the BAR */ 4274c352362SJakub Kicinski struct nfp_net_fw_version { 4284c352362SJakub Kicinski u8 minor; 4294c352362SJakub Kicinski u8 major; 4304c352362SJakub Kicinski u8 class; 4314c352362SJakub Kicinski u8 resv; 4324c352362SJakub Kicinski } __packed; 4334c352362SJakub Kicinski 4344c352362SJakub Kicinski static inline bool nfp_net_fw_ver_eq(struct nfp_net_fw_version *fw_ver, 4354c352362SJakub Kicinski u8 resv, u8 class, u8 major, u8 minor) 4364c352362SJakub Kicinski { 4374c352362SJakub Kicinski return fw_ver->resv == resv && 4384c352362SJakub Kicinski fw_ver->class == class && 4394c352362SJakub Kicinski fw_ver->major == major && 4404c352362SJakub Kicinski fw_ver->minor == minor; 4414c352362SJakub Kicinski } 4424c352362SJakub Kicinski 44366860bebSJakub Kicinski struct nfp_stat_pair { 44466860bebSJakub Kicinski u64 pkts; 44566860bebSJakub Kicinski u64 bytes; 44666860bebSJakub Kicinski }; 44766860bebSJakub Kicinski 4484c352362SJakub Kicinski /** 44979c12a75SJakub Kicinski * struct nfp_net_dp - NFP network device datapath data structure 450fa43d2a8SJakub Kicinski * @dev: Backpointer to struct device 4514c352362SJakub Kicinski * @netdev: Backpointer to net_device structure 4524c352362SJakub Kicinski * @is_vf: Is the driver attached to a VF? 4537533fdc0SJakub Kicinski * @bpf_offload_skip_sw: Offloaded BPF program will not be rerun by cls_bpf 4546d677075SJakub Kicinski * @bpf_offload_xdp: Offloaded BPF program is XDP 455b9dcf88aSJakub Kicinski * @chained_metadata_format: Firemware will use new metadata format 456c487e6b1SJakub Kicinski * @rx_dma_dir: Mapping direction for RX buffers 4576fe0c3b4SJakub Kicinski * @rx_dma_off: Offset at which DMA packets (for XDP headroom) 45897717acaSJakub Kicinski * @rx_offset: Offset in the RX buffers where packet data starts 4594c352362SJakub Kicinski * @ctrl: Local copy of the control register/word. 4604c352362SJakub Kicinski * @fl_bufsz: Currently configured size of the freelist buffers 461ecd63a02SJakub Kicinski * @xdp_prog: Installed XDP program 46279c12a75SJakub Kicinski * @tx_rings: Array of pre-allocated TX ring structures 46379c12a75SJakub Kicinski * @rx_rings: Array of pre-allocated RX ring structures 464d2b84397SJakub Kicinski * @ctrl_bar: Pointer to mapped control BAR 46579c12a75SJakub Kicinski * 46679c12a75SJakub Kicinski * @txd_cnt: Size of the TX ring in number of descriptors 46779c12a75SJakub Kicinski * @rxd_cnt: Size of the RX ring in number of descriptors 46879c12a75SJakub Kicinski * @num_r_vecs: Number of used ring vectors 46979c12a75SJakub Kicinski * @num_tx_rings: Currently configured number of TX rings 47079c12a75SJakub Kicinski * @num_stack_tx_rings: Number of TX rings used by the stack (not XDP) 47179c12a75SJakub Kicinski * @num_rx_rings: Currently configured number of RX rings 47276e1e1a8SJakub Kicinski * @mtu: Device MTU 47379c12a75SJakub Kicinski */ 47479c12a75SJakub Kicinski struct nfp_net_dp { 47579c12a75SJakub Kicinski struct device *dev; 47679c12a75SJakub Kicinski struct net_device *netdev; 47779c12a75SJakub Kicinski 478c487e6b1SJakub Kicinski u8 is_vf:1; 479c487e6b1SJakub Kicinski u8 bpf_offload_skip_sw:1; 480c487e6b1SJakub Kicinski u8 bpf_offload_xdp:1; 481c487e6b1SJakub Kicinski u8 chained_metadata_format:1; 482c487e6b1SJakub Kicinski 483c487e6b1SJakub Kicinski u8 rx_dma_dir; 48497717acaSJakub Kicinski u8 rx_offset; 48597717acaSJakub Kicinski 486dbf637ffSJakub Kicinski u32 rx_dma_off; 487dbf637ffSJakub Kicinski 48879c12a75SJakub Kicinski u32 ctrl; 48979c12a75SJakub Kicinski u32 fl_bufsz; 49079c12a75SJakub Kicinski 49179c12a75SJakub Kicinski struct bpf_prog *xdp_prog; 49279c12a75SJakub Kicinski 49379c12a75SJakub Kicinski struct nfp_net_tx_ring *tx_rings; 49479c12a75SJakub Kicinski struct nfp_net_rx_ring *rx_rings; 49579c12a75SJakub Kicinski 496d2b84397SJakub Kicinski u8 __iomem *ctrl_bar; 497d2b84397SJakub Kicinski 49879c12a75SJakub Kicinski /* Cold data follows */ 49979c12a75SJakub Kicinski 50079c12a75SJakub Kicinski unsigned int txd_cnt; 50179c12a75SJakub Kicinski unsigned int rxd_cnt; 50279c12a75SJakub Kicinski 50379c12a75SJakub Kicinski unsigned int num_r_vecs; 50479c12a75SJakub Kicinski 50579c12a75SJakub Kicinski unsigned int num_tx_rings; 50679c12a75SJakub Kicinski unsigned int num_stack_tx_rings; 50779c12a75SJakub Kicinski unsigned int num_rx_rings; 50876e1e1a8SJakub Kicinski 50976e1e1a8SJakub Kicinski unsigned int mtu; 51079c12a75SJakub Kicinski }; 51179c12a75SJakub Kicinski 51279c12a75SJakub Kicinski /** 51379c12a75SJakub Kicinski * struct nfp_net - NFP network device structure 51479c12a75SJakub Kicinski * @dp: Datapath structure 5154c352362SJakub Kicinski * @fw_ver: Firmware version 5164c352362SJakub Kicinski * @cap: Capabilities advertised by the Firmware 5174c352362SJakub Kicinski * @max_mtu: Maximum support MTU advertised by the Firmware 5189ff304bfSJakub Kicinski * @rss_hfunc: RSS selected hash function 5194c352362SJakub Kicinski * @rss_cfg: RSS configuration 5204c352362SJakub Kicinski * @rss_key: RSS secret key 5214c352362SJakub Kicinski * @rss_itbl: RSS indirection table 52266860bebSJakub Kicinski * @rx_filter: Filter offload statistics - dropped packets/bytes 52366860bebSJakub Kicinski * @rx_filter_prev: Filter offload statistics - values from previous update 52466860bebSJakub Kicinski * @rx_filter_change: Jiffies when statistics last changed 52566860bebSJakub Kicinski * @rx_filter_stats_timer: Timer for polling filter offload statistics 52666860bebSJakub Kicinski * @rx_filter_lock: Lock protecting timer state changes (teardown) 52779c12a75SJakub Kicinski * @max_r_vecs: Number of allocated interrupt vectors for RX/TX 5284c352362SJakub Kicinski * @max_tx_rings: Maximum number of TX rings supported by the Firmware 5294c352362SJakub Kicinski * @max_rx_rings: Maximum number of RX rings supported by the Firmware 5304c352362SJakub Kicinski * @r_vecs: Pre-allocated array of ring vectors 5314c352362SJakub Kicinski * @irq_entries: Pre-allocated array of MSI-X entries 5324c352362SJakub Kicinski * @lsc_handler: Handler for Link State Change interrupt 5334c352362SJakub Kicinski * @lsc_name: Name for Link State Change interrupt 5344c352362SJakub Kicinski * @exn_handler: Handler for Exception interrupt 5354c352362SJakub Kicinski * @exn_name: Name for Exception interrupt 5364c352362SJakub Kicinski * @shared_handler: Handler for shared interrupts 5374c352362SJakub Kicinski * @shared_name: Name for shared interrupt 5384c352362SJakub Kicinski * @me_freq_mhz: ME clock_freq (MHz) 5394c352362SJakub Kicinski * @reconfig_lock: Protects HW reconfiguration request regs/machinery 5403d780b92SJakub Kicinski * @reconfig_posted: Pending reconfig bits coming from async sources 5413d780b92SJakub Kicinski * @reconfig_timer_active: Timer for reading reconfiguration results is pending 5423d780b92SJakub Kicinski * @reconfig_sync_present: Some thread is performing synchronous reconfig 5433d780b92SJakub Kicinski * @reconfig_timer: Timer for async reading of reconfig results 5444c352362SJakub Kicinski * @link_up: Is the link up? 545cee42951SJakub Kicinski * @link_changed: Has link state changes since last port refresh? 546cee42951SJakub Kicinski * @link_status_lock: Protects @link_* and ensures atomicity with BAR reading 5474c352362SJakub Kicinski * @rx_coalesce_usecs: RX interrupt moderation usecs delay parameter 5484c352362SJakub Kicinski * @rx_coalesce_max_frames: RX interrupt moderation frame count parameter 5494c352362SJakub Kicinski * @tx_coalesce_usecs: TX interrupt moderation usecs delay parameter 5504c352362SJakub Kicinski * @tx_coalesce_max_frames: TX interrupt moderation frame count parameter 5514c352362SJakub Kicinski * @vxlan_ports: VXLAN ports for RX inner csum offload communicated to HW 5524c352362SJakub Kicinski * @vxlan_usecnt: IPv4/IPv6 VXLAN port use counts 5534c352362SJakub Kicinski * @qcp_cfg: Pointer to QCP queue used for configuration notification 5544c352362SJakub Kicinski * @tx_bar: Pointer to mapped TX queues 5554c352362SJakub Kicinski * @rx_bar: Pointer to mapped FL/RX queues 5564c352362SJakub Kicinski * @debugfs_dir: Device directory in debugfs 557af623682SJakub Kicinski * @ethtool_dump_flag: Ethtool dump flag 558d4e7f092SJakub Kicinski * @vnic_list: Entry on device vNIC list 559fa43d2a8SJakub Kicinski * @pdev: Backpointer to PCI device 560bd5ca062SJakub Kicinski * @cpp: CPP device handle if available 56147465aedSJakub Kicinski * @eth_port: Translated ETH Table port entry 5624c352362SJakub Kicinski */ 5634c352362SJakub Kicinski struct nfp_net { 56479c12a75SJakub Kicinski struct nfp_net_dp dp; 56573725d9dSJakub Kicinski 5664c352362SJakub Kicinski struct nfp_net_fw_version fw_ver; 56779c12a75SJakub Kicinski 5684c352362SJakub Kicinski u32 cap; 5694c352362SJakub Kicinski u32 max_mtu; 5704c352362SJakub Kicinski 5719ff304bfSJakub Kicinski u8 rss_hfunc; 5724c352362SJakub Kicinski u32 rss_cfg; 5734c352362SJakub Kicinski u8 rss_key[NFP_NET_CFG_RSS_KEY_SZ]; 5744c352362SJakub Kicinski u8 rss_itbl[NFP_NET_CFG_RSS_ITBL_SZ]; 5754c352362SJakub Kicinski 57666860bebSJakub Kicinski struct nfp_stat_pair rx_filter, rx_filter_prev; 57766860bebSJakub Kicinski unsigned long rx_filter_change; 57866860bebSJakub Kicinski struct timer_list rx_filter_stats_timer; 57966860bebSJakub Kicinski spinlock_t rx_filter_lock; 58066860bebSJakub Kicinski 581a4b562bbSJakub Kicinski unsigned int max_tx_rings; 582a4b562bbSJakub Kicinski unsigned int max_rx_rings; 5834c352362SJakub Kicinski 5844c352362SJakub Kicinski int stride_tx; 5854c352362SJakub Kicinski int stride_rx; 5864c352362SJakub Kicinski 587b33ae997SJakub Kicinski unsigned int max_r_vecs; 58823a4e389SJakub Kicinski struct nfp_net_r_vector r_vecs[NFP_NET_MAX_R_VECS]; 58923a4e389SJakub Kicinski struct msix_entry irq_entries[NFP_NET_MAX_IRQS]; 5904c352362SJakub Kicinski 5914c352362SJakub Kicinski irq_handler_t lsc_handler; 5924c352362SJakub Kicinski char lsc_name[IFNAMSIZ + 8]; 5934c352362SJakub Kicinski 5944c352362SJakub Kicinski irq_handler_t exn_handler; 5954c352362SJakub Kicinski char exn_name[IFNAMSIZ + 8]; 5964c352362SJakub Kicinski 5974c352362SJakub Kicinski irq_handler_t shared_handler; 5984c352362SJakub Kicinski char shared_name[IFNAMSIZ + 8]; 5994c352362SJakub Kicinski 6004c352362SJakub Kicinski u32 me_freq_mhz; 6014c352362SJakub Kicinski 6024c352362SJakub Kicinski bool link_up; 603cee42951SJakub Kicinski bool link_changed; 6044c352362SJakub Kicinski spinlock_t link_status_lock; 6054c352362SJakub Kicinski 6064c352362SJakub Kicinski spinlock_t reconfig_lock; 6073d780b92SJakub Kicinski u32 reconfig_posted; 6083d780b92SJakub Kicinski bool reconfig_timer_active; 6093d780b92SJakub Kicinski bool reconfig_sync_present; 6103d780b92SJakub Kicinski struct timer_list reconfig_timer; 6114c352362SJakub Kicinski 6124c352362SJakub Kicinski u32 rx_coalesce_usecs; 6134c352362SJakub Kicinski u32 rx_coalesce_max_frames; 6144c352362SJakub Kicinski u32 tx_coalesce_usecs; 6154c352362SJakub Kicinski u32 tx_coalesce_max_frames; 6164c352362SJakub Kicinski 6174c352362SJakub Kicinski __be16 vxlan_ports[NFP_NET_N_VXLAN_PORTS]; 6184c352362SJakub Kicinski u8 vxlan_usecnt[NFP_NET_N_VXLAN_PORTS]; 6194c352362SJakub Kicinski 6204c352362SJakub Kicinski u8 __iomem *qcp_cfg; 6214c352362SJakub Kicinski 6224c352362SJakub Kicinski u8 __iomem *tx_bar; 6234c352362SJakub Kicinski u8 __iomem *rx_bar; 6244c352362SJakub Kicinski 6254c352362SJakub Kicinski struct dentry *debugfs_dir; 626af623682SJakub Kicinski u32 ethtool_dump_flag; 62763461a02SJakub Kicinski 628d4e7f092SJakub Kicinski struct list_head vnic_list; 629bd5ca062SJakub Kicinski 630fa43d2a8SJakub Kicinski struct pci_dev *pdev; 631bd5ca062SJakub Kicinski struct nfp_cpp *cpp; 63247465aedSJakub Kicinski 63347465aedSJakub Kicinski struct nfp_eth_table_port *eth_port; 6344c352362SJakub Kicinski }; 6354c352362SJakub Kicinski 6364c352362SJakub Kicinski /* Functions to read/write from/to a BAR 6374c352362SJakub Kicinski * Performs any endian conversion necessary. 6384c352362SJakub Kicinski */ 6397533fdc0SJakub Kicinski static inline u16 nn_readb(struct nfp_net *nn, int off) 6407533fdc0SJakub Kicinski { 641d2b84397SJakub Kicinski return readb(nn->dp.ctrl_bar + off); 6427533fdc0SJakub Kicinski } 6437533fdc0SJakub Kicinski 6444c352362SJakub Kicinski static inline void nn_writeb(struct nfp_net *nn, int off, u8 val) 6454c352362SJakub Kicinski { 646d2b84397SJakub Kicinski writeb(val, nn->dp.ctrl_bar + off); 6474c352362SJakub Kicinski } 6484c352362SJakub Kicinski 6497533fdc0SJakub Kicinski static inline u16 nn_readw(struct nfp_net *nn, int off) 6507533fdc0SJakub Kicinski { 651d2b84397SJakub Kicinski return readw(nn->dp.ctrl_bar + off); 6527533fdc0SJakub Kicinski } 6537533fdc0SJakub Kicinski 6547533fdc0SJakub Kicinski static inline void nn_writew(struct nfp_net *nn, int off, u16 val) 6557533fdc0SJakub Kicinski { 656d2b84397SJakub Kicinski writew(val, nn->dp.ctrl_bar + off); 6577533fdc0SJakub Kicinski } 6584c352362SJakub Kicinski 6594c352362SJakub Kicinski static inline u32 nn_readl(struct nfp_net *nn, int off) 6604c352362SJakub Kicinski { 661d2b84397SJakub Kicinski return readl(nn->dp.ctrl_bar + off); 6624c352362SJakub Kicinski } 6634c352362SJakub Kicinski 6644c352362SJakub Kicinski static inline void nn_writel(struct nfp_net *nn, int off, u32 val) 6654c352362SJakub Kicinski { 666d2b84397SJakub Kicinski writel(val, nn->dp.ctrl_bar + off); 6674c352362SJakub Kicinski } 6684c352362SJakub Kicinski 6694c352362SJakub Kicinski static inline u64 nn_readq(struct nfp_net *nn, int off) 6704c352362SJakub Kicinski { 671d2b84397SJakub Kicinski return readq(nn->dp.ctrl_bar + off); 6724c352362SJakub Kicinski } 6734c352362SJakub Kicinski 6744c352362SJakub Kicinski static inline void nn_writeq(struct nfp_net *nn, int off, u64 val) 6754c352362SJakub Kicinski { 676d2b84397SJakub Kicinski writeq(val, nn->dp.ctrl_bar + off); 6774c352362SJakub Kicinski } 6784c352362SJakub Kicinski 6794c352362SJakub Kicinski /* Flush posted PCI writes by reading something without side effects */ 6804c352362SJakub Kicinski static inline void nn_pci_flush(struct nfp_net *nn) 6814c352362SJakub Kicinski { 6824c352362SJakub Kicinski nn_readl(nn, NFP_NET_CFG_VERSION); 6834c352362SJakub Kicinski } 6844c352362SJakub Kicinski 6854c352362SJakub Kicinski /* Queue Controller Peripheral access functions and definitions. 6864c352362SJakub Kicinski * 6874c352362SJakub Kicinski * Some of the BARs of the NFP are mapped to portions of the Queue 6884c352362SJakub Kicinski * Controller Peripheral (QCP) address space on the NFP. A QCP queue 6894c352362SJakub Kicinski * has a read and a write pointer (as well as a size and flags, 6904c352362SJakub Kicinski * indicating overflow etc). The QCP offers a number of different 6914c352362SJakub Kicinski * operation on queue pointers, but here we only offer function to 6924c352362SJakub Kicinski * either add to a pointer or to read the pointer value. 6934c352362SJakub Kicinski */ 6944c352362SJakub Kicinski #define NFP_QCP_QUEUE_ADDR_SZ 0x800 6954c352362SJakub Kicinski #define NFP_QCP_QUEUE_OFF(_x) ((_x) * NFP_QCP_QUEUE_ADDR_SZ) 6964c352362SJakub Kicinski #define NFP_QCP_QUEUE_ADD_RPTR 0x0000 6974c352362SJakub Kicinski #define NFP_QCP_QUEUE_ADD_WPTR 0x0004 6984c352362SJakub Kicinski #define NFP_QCP_QUEUE_STS_LO 0x0008 6994c352362SJakub Kicinski #define NFP_QCP_QUEUE_STS_LO_READPTR_mask 0x3ffff 7004c352362SJakub Kicinski #define NFP_QCP_QUEUE_STS_HI 0x000c 7014c352362SJakub Kicinski #define NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask 0x3ffff 7024c352362SJakub Kicinski 703416db5c1SJakub Kicinski /* The offset of a QCP queues in the PCIe Target */ 7044c352362SJakub Kicinski #define NFP_PCIE_QUEUE(_q) (0x80000 + (NFP_QCP_QUEUE_ADDR_SZ * ((_q) & 0xff))) 7054c352362SJakub Kicinski 7064c352362SJakub Kicinski /* nfp_qcp_ptr - Read or Write Pointer of a queue */ 7074c352362SJakub Kicinski enum nfp_qcp_ptr { 7084c352362SJakub Kicinski NFP_QCP_READ_PTR = 0, 7094c352362SJakub Kicinski NFP_QCP_WRITE_PTR 7104c352362SJakub Kicinski }; 7114c352362SJakub Kicinski 7124c352362SJakub Kicinski /* There appear to be an *undocumented* upper limit on the value which 7134c352362SJakub Kicinski * one can add to a queue and that value is either 0x3f or 0x7f. We 7144c352362SJakub Kicinski * go with 0x3f as a conservative measure. 7154c352362SJakub Kicinski */ 7164c352362SJakub Kicinski #define NFP_QCP_MAX_ADD 0x3f 7174c352362SJakub Kicinski 7184c352362SJakub Kicinski static inline void _nfp_qcp_ptr_add(u8 __iomem *q, 7194c352362SJakub Kicinski enum nfp_qcp_ptr ptr, u32 val) 7204c352362SJakub Kicinski { 7214c352362SJakub Kicinski u32 off; 7224c352362SJakub Kicinski 7234c352362SJakub Kicinski if (ptr == NFP_QCP_READ_PTR) 7244c352362SJakub Kicinski off = NFP_QCP_QUEUE_ADD_RPTR; 7254c352362SJakub Kicinski else 7264c352362SJakub Kicinski off = NFP_QCP_QUEUE_ADD_WPTR; 7274c352362SJakub Kicinski 7284c352362SJakub Kicinski while (val > NFP_QCP_MAX_ADD) { 7294c352362SJakub Kicinski writel(NFP_QCP_MAX_ADD, q + off); 7304c352362SJakub Kicinski val -= NFP_QCP_MAX_ADD; 7314c352362SJakub Kicinski } 7324c352362SJakub Kicinski 7334c352362SJakub Kicinski writel(val, q + off); 7344c352362SJakub Kicinski } 7354c352362SJakub Kicinski 7364c352362SJakub Kicinski /** 7374c352362SJakub Kicinski * nfp_qcp_rd_ptr_add() - Add the value to the read pointer of a queue 7384c352362SJakub Kicinski * 7394c352362SJakub Kicinski * @q: Base address for queue structure 7404c352362SJakub Kicinski * @val: Value to add to the queue pointer 7414c352362SJakub Kicinski * 7424c352362SJakub Kicinski * If @val is greater than @NFP_QCP_MAX_ADD multiple writes are performed. 7434c352362SJakub Kicinski */ 7444c352362SJakub Kicinski static inline void nfp_qcp_rd_ptr_add(u8 __iomem *q, u32 val) 7454c352362SJakub Kicinski { 7464c352362SJakub Kicinski _nfp_qcp_ptr_add(q, NFP_QCP_READ_PTR, val); 7474c352362SJakub Kicinski } 7484c352362SJakub Kicinski 7494c352362SJakub Kicinski /** 7504c352362SJakub Kicinski * nfp_qcp_wr_ptr_add() - Add the value to the write pointer of a queue 7514c352362SJakub Kicinski * 7524c352362SJakub Kicinski * @q: Base address for queue structure 7534c352362SJakub Kicinski * @val: Value to add to the queue pointer 7544c352362SJakub Kicinski * 7554c352362SJakub Kicinski * If @val is greater than @NFP_QCP_MAX_ADD multiple writes are performed. 7564c352362SJakub Kicinski */ 7574c352362SJakub Kicinski static inline void nfp_qcp_wr_ptr_add(u8 __iomem *q, u32 val) 7584c352362SJakub Kicinski { 7594c352362SJakub Kicinski _nfp_qcp_ptr_add(q, NFP_QCP_WRITE_PTR, val); 7604c352362SJakub Kicinski } 7614c352362SJakub Kicinski 7624c352362SJakub Kicinski static inline u32 _nfp_qcp_read(u8 __iomem *q, enum nfp_qcp_ptr ptr) 7634c352362SJakub Kicinski { 7644c352362SJakub Kicinski u32 off; 7654c352362SJakub Kicinski u32 val; 7664c352362SJakub Kicinski 7674c352362SJakub Kicinski if (ptr == NFP_QCP_READ_PTR) 7684c352362SJakub Kicinski off = NFP_QCP_QUEUE_STS_LO; 7694c352362SJakub Kicinski else 7704c352362SJakub Kicinski off = NFP_QCP_QUEUE_STS_HI; 7714c352362SJakub Kicinski 7724c352362SJakub Kicinski val = readl(q + off); 7734c352362SJakub Kicinski 7744c352362SJakub Kicinski if (ptr == NFP_QCP_READ_PTR) 7754c352362SJakub Kicinski return val & NFP_QCP_QUEUE_STS_LO_READPTR_mask; 7764c352362SJakub Kicinski else 7774c352362SJakub Kicinski return val & NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask; 7784c352362SJakub Kicinski } 7794c352362SJakub Kicinski 7804c352362SJakub Kicinski /** 7814c352362SJakub Kicinski * nfp_qcp_rd_ptr_read() - Read the current read pointer value for a queue 7824c352362SJakub Kicinski * @q: Base address for queue structure 7834c352362SJakub Kicinski * 7844c352362SJakub Kicinski * Return: Value read. 7854c352362SJakub Kicinski */ 7864c352362SJakub Kicinski static inline u32 nfp_qcp_rd_ptr_read(u8 __iomem *q) 7874c352362SJakub Kicinski { 7884c352362SJakub Kicinski return _nfp_qcp_read(q, NFP_QCP_READ_PTR); 7894c352362SJakub Kicinski } 7904c352362SJakub Kicinski 7914c352362SJakub Kicinski /** 7924c352362SJakub Kicinski * nfp_qcp_wr_ptr_read() - Read the current write pointer value for a queue 7934c352362SJakub Kicinski * @q: Base address for queue structure 7944c352362SJakub Kicinski * 7954c352362SJakub Kicinski * Return: Value read. 7964c352362SJakub Kicinski */ 7974c352362SJakub Kicinski static inline u32 nfp_qcp_wr_ptr_read(u8 __iomem *q) 7984c352362SJakub Kicinski { 7994c352362SJakub Kicinski return _nfp_qcp_read(q, NFP_QCP_WRITE_PTR); 8004c352362SJakub Kicinski } 8014c352362SJakub Kicinski 8024c352362SJakub Kicinski /* Globals */ 8032633beb9SJakub Kicinski extern const char nfp_driver_version[]; 8044c352362SJakub Kicinski 8054c352362SJakub Kicinski /* Prototypes */ 8064c352362SJakub Kicinski void nfp_net_get_fw_version(struct nfp_net_fw_version *fw_ver, 8074c352362SJakub Kicinski void __iomem *ctrl_bar); 8084c352362SJakub Kicinski 809a4b562bbSJakub Kicinski struct nfp_net * 810beba69caSJakub Kicinski nfp_net_alloc(struct pci_dev *pdev, 811a4b562bbSJakub Kicinski unsigned int max_tx_rings, unsigned int max_rx_rings); 812beba69caSJakub Kicinski void nfp_net_free(struct nfp_net *nn); 813beba69caSJakub Kicinski 814beba69caSJakub Kicinski int nfp_net_init(struct nfp_net *nn); 815beba69caSJakub Kicinski void nfp_net_clean(struct nfp_net *nn); 816beba69caSJakub Kicinski 8174c352362SJakub Kicinski void nfp_net_set_ethtool_ops(struct net_device *netdev); 8184c352362SJakub Kicinski void nfp_net_info(struct nfp_net *nn); 8194c352362SJakub Kicinski int nfp_net_reconfig(struct nfp_net *nn, u32 update); 8209ff304bfSJakub Kicinski unsigned int nfp_net_rss_key_sz(struct nfp_net *nn); 8214c352362SJakub Kicinski void nfp_net_rss_write_itbl(struct nfp_net *nn); 8224c352362SJakub Kicinski void nfp_net_rss_write_key(struct nfp_net *nn); 8234c352362SJakub Kicinski void nfp_net_coalesce_write_cfg(struct nfp_net *nn); 824fdace6c2SJakub Kicinski 825fdace6c2SJakub Kicinski unsigned int 826fdace6c2SJakub Kicinski nfp_net_irqs_alloc(struct pci_dev *pdev, struct msix_entry *irq_entries, 827fdace6c2SJakub Kicinski unsigned int min_irqs, unsigned int want_irqs); 828fdace6c2SJakub Kicinski void nfp_net_irqs_disable(struct pci_dev *pdev); 829fdace6c2SJakub Kicinski void 830fdace6c2SJakub Kicinski nfp_net_irqs_assign(struct nfp_net *nn, struct msix_entry *irq_entries, 831fdace6c2SJakub Kicinski unsigned int n); 832783496b0SJakub Kicinski 833783496b0SJakub Kicinski struct nfp_net_dp *nfp_net_clone_dp(struct nfp_net *nn); 834d957c0f7SJakub Kicinski int nfp_net_ring_reconfig(struct nfp_net *nn, struct nfp_net_dp *new, 835d957c0f7SJakub Kicinski struct netlink_ext_ack *extack); 8364c352362SJakub Kicinski 837cee42951SJakub Kicinski bool nfp_net_link_changed_read_clear(struct nfp_net *nn); 83890fdc561SJakub Kicinski int nfp_net_refresh_eth_port(struct nfp_net *nn); 83990fdc561SJakub Kicinski void nfp_net_refresh_port_table(struct nfp_net *nn); 840cee42951SJakub Kicinski 8412633beb9SJakub Kicinski #ifdef CONFIG_NFP_DEBUG 8424c352362SJakub Kicinski void nfp_net_debugfs_create(void); 8434c352362SJakub Kicinski void nfp_net_debugfs_destroy(void); 8446f1cd5caSJakub Kicinski struct dentry *nfp_net_debugfs_device_add(struct pci_dev *pdev); 845d4e7f092SJakub Kicinski void nfp_net_debugfs_vnic_add(struct nfp_net *nn, struct dentry *ddir, int id); 8466f1cd5caSJakub Kicinski void nfp_net_debugfs_dir_clean(struct dentry **dir); 8474c352362SJakub Kicinski #else 8484c352362SJakub Kicinski static inline void nfp_net_debugfs_create(void) 8494c352362SJakub Kicinski { 8504c352362SJakub Kicinski } 8514c352362SJakub Kicinski 8524c352362SJakub Kicinski static inline void nfp_net_debugfs_destroy(void) 8534c352362SJakub Kicinski { 8544c352362SJakub Kicinski } 8554c352362SJakub Kicinski 8566f1cd5caSJakub Kicinski static inline struct dentry *nfp_net_debugfs_device_add(struct pci_dev *pdev) 8576f1cd5caSJakub Kicinski { 8586f1cd5caSJakub Kicinski return NULL; 8596f1cd5caSJakub Kicinski } 8606f1cd5caSJakub Kicinski 8616f1cd5caSJakub Kicinski static inline void 862d4e7f092SJakub Kicinski nfp_net_debugfs_vnic_add(struct nfp_net *nn, struct dentry *ddir, int id) 8634c352362SJakub Kicinski { 8644c352362SJakub Kicinski } 8654c352362SJakub Kicinski 8666f1cd5caSJakub Kicinski static inline void nfp_net_debugfs_dir_clean(struct dentry **dir) 8674c352362SJakub Kicinski { 8684c352362SJakub Kicinski } 8692633beb9SJakub Kicinski #endif /* CONFIG_NFP_DEBUG */ 8704c352362SJakub Kicinski 87166860bebSJakub Kicinski void nfp_net_filter_stats_timer(unsigned long data); 8722e9d594dSJakub Kicinski int nfp_net_bpf_offload(struct nfp_net *nn, struct tc_cls_bpf_offload *cls_bpf); 8737533fdc0SJakub Kicinski 8744c352362SJakub Kicinski #endif /* _NFP_NET_H_ */ 875