1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 /* Copyright (C) 2015-2018 Netronome Systems, Inc. */
6 * Declarations for Netronome network device driver.
7 * Authors: Jakub Kicinski <jakub.kicinski@netronome.com>
8 * Jason McMullan <jason.mcmullan@netronome.com>
9 * Rolf Neugebauer <rolf.neugebauer@netronome.com>
15 #include <linux/atomic.h>
16 #include <linux/interrupt.h>
17 #include <linux/list.h>
18 #include <linux/netdevice.h>
19 #include <linux/pci.h>
20 #include <linux/dim.h>
21 #include <linux/io-64-nonatomic-hi-lo.h>
22 #include <linux/semaphore.h>
23 #include <linux/workqueue.h>
26 #include "nfp_net_ctrl.h"
28 #define nn_pr(nn, lvl, fmt, args...) \
30 struct nfp_net *__nn = (nn); \
32 if (__nn->dp.netdev) \
33 netdev_printk(lvl, __nn->dp.netdev, fmt, ## args); \
35 dev_printk(lvl, __nn->dp.dev, "ctrl: " fmt, ## args); \
38 #define nn_err(nn, fmt, args...) nn_pr(nn, KERN_ERR, fmt, ## args)
39 #define nn_warn(nn, fmt, args...) nn_pr(nn, KERN_WARNING, fmt, ## args)
40 #define nn_info(nn, fmt, args...) nn_pr(nn, KERN_INFO, fmt, ## args)
41 #define nn_dbg(nn, fmt, args...) nn_pr(nn, KERN_DEBUG, fmt, ## args)
43 #define nn_dp_warn(dp, fmt, args...) \
45 struct nfp_net_dp *__dp = (dp); \
47 if (unlikely(net_ratelimit())) { \
49 netdev_warn(__dp->netdev, fmt, ## args); \
51 dev_warn(__dp->dev, fmt, ## args); \
55 /* Max time to wait for NFP to respond on updates (in seconds) */
56 #define NFP_NET_POLL_TIMEOUT 5
58 /* Interval for reading offloaded filter stats */
59 #define NFP_NET_STAT_POLL_IVL msecs_to_jiffies(100)
62 #define NFP_NET_CTRL_BAR 0
63 #define NFP_NET_Q0_BAR 2
64 #define NFP_NET_Q1_BAR 4 /* OBSOLETE */
66 /* Max bits in DMA address */
67 #define NFP_NET_MAX_DMA_BITS 40
69 /* Default size for MTU and freelist buffer sizes */
70 #define NFP_NET_DEFAULT_MTU 1500U
72 /* Maximum number of bytes prepended to a packet */
73 #define NFP_NET_MAX_PREPEND 64
75 /* Interrupt definitions */
76 #define NFP_NET_NON_Q_VECTORS 2
77 #define NFP_NET_IRQ_LSC_IDX 0
78 #define NFP_NET_IRQ_EXN_IDX 1
79 #define NFP_NET_MIN_VNIC_IRQS (NFP_NET_NON_Q_VECTORS + 1)
81 /* Queue/Ring definitions */
82 #define NFP_NET_MAX_TX_RINGS 64 /* Max. # of Tx rings per device */
83 #define NFP_NET_MAX_RX_RINGS 64 /* Max. # of Rx rings per device */
84 #define NFP_NET_MAX_R_VECS (NFP_NET_MAX_TX_RINGS > NFP_NET_MAX_RX_RINGS ? \
85 NFP_NET_MAX_TX_RINGS : NFP_NET_MAX_RX_RINGS)
86 #define NFP_NET_MAX_IRQS (NFP_NET_NON_Q_VECTORS + NFP_NET_MAX_R_VECS)
88 #define NFP_NET_MIN_TX_DESCS 256 /* Min. # of Tx descs per ring */
89 #define NFP_NET_MIN_RX_DESCS 256 /* Min. # of Rx descs per ring */
90 #define NFP_NET_MAX_TX_DESCS (256 * 1024) /* Max. # of Tx descs per ring */
91 #define NFP_NET_MAX_RX_DESCS (256 * 1024) /* Max. # of Rx descs per ring */
93 #define NFP_NET_TX_DESCS_DEFAULT 4096 /* Default # of Tx descs per ring */
94 #define NFP_NET_RX_DESCS_DEFAULT 4096 /* Default # of Rx descs per ring */
96 #define NFP_NET_FL_BATCH 16 /* Add freelist in this Batch size */
97 #define NFP_NET_XDP_MAX_COMPLETE 2048 /* XDP bufs to reclaim in NAPI poll */
99 /* Offload definitions */
100 #define NFP_NET_N_VXLAN_PORTS (NFP_NET_CFG_VXLAN_SZ / sizeof(__be16))
102 #define NFP_NET_RX_BUF_HEADROOM (NET_SKB_PAD + NET_IP_ALIGN)
103 #define NFP_NET_RX_BUF_NON_DATA (NFP_NET_RX_BUF_HEADROOM + \
104 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
106 /* Forward declarations */
109 struct nfp_eth_table_port;
111 struct nfp_net_r_vector;
113 struct xsk_buff_pool;
115 /* Convenience macro for wrapping descriptor index on ring size */
116 #define D_IDX(ring, idx) ((idx) & ((ring)->cnt - 1))
118 /* Convenience macro for writing dma address into RX/TX descriptors */
119 #define nfp_desc_set_dma_addr(desc, dma_addr) \
121 __typeof(desc) __d = (desc); \
122 dma_addr_t __addr = (dma_addr); \
124 __d->dma_addr_lo = cpu_to_le32(lower_32_bits(__addr)); \
125 __d->dma_addr_hi = upper_32_bits(__addr) & 0xff; \
128 /* TX descriptor format */
130 #define PCIE_DESC_TX_EOP BIT(7)
131 #define PCIE_DESC_TX_OFFSET_MASK GENMASK(6, 0)
132 #define PCIE_DESC_TX_MSS_MASK GENMASK(13, 0)
134 /* Flags in the host TX descriptor */
135 #define PCIE_DESC_TX_CSUM BIT(7)
136 #define PCIE_DESC_TX_IP4_CSUM BIT(6)
137 #define PCIE_DESC_TX_TCP_CSUM BIT(5)
138 #define PCIE_DESC_TX_UDP_CSUM BIT(4)
139 #define PCIE_DESC_TX_VLAN BIT(3)
140 #define PCIE_DESC_TX_LSO BIT(2)
141 #define PCIE_DESC_TX_ENCAP BIT(1)
142 #define PCIE_DESC_TX_O_IP4_CSUM BIT(0)
144 struct nfp_net_tx_desc {
147 u8 dma_addr_hi; /* High bits of host buf address */
148 __le16 dma_len; /* Length to DMA for this desc */
149 u8 offset_eop; /* Offset in buf where pkt starts +
150 * highest bit is eop flag.
152 __le32 dma_addr_lo; /* Low 32bit of host buf addr */
154 __le16 mss; /* MSS to be used for LSO */
155 u8 lso_hdrlen; /* LSO, TCP payload offset */
156 u8 flags; /* TX Flags, see @PCIE_DESC_TX_* */
159 u8 l3_offset; /* L3 header offset */
160 u8 l4_offset; /* L4 header offset */
162 __le16 vlan; /* VLAN tag to add if indicated */
164 __le16 data_len; /* Length of frame + meta data */
172 * struct nfp_net_tx_buf - software TX buffer descriptor
173 * @skb: normal ring, sk_buff associated with this buffer
174 * @frag: XDP ring, page frag associated with this buffer
175 * @xdp: XSK buffer pool handle (for AF_XDP)
176 * @dma_addr: DMA mapping address of the buffer
177 * @fidx: Fragment index (-1 for the head and [0..nr_frags-1] for frags)
178 * @pkt_cnt: Number of packets to be produced out of the skb associated
179 * with this buffer (valid only on the head's buffer).
180 * Will be 1 for all non-TSO packets.
181 * @is_xsk_tx: Flag if buffer is a RX buffer after a XDP_TX action and not a
182 * buffer from the TX queue (for AF_XDP).
183 * @real_len: Number of bytes which to be produced out of the skb (valid only
184 * on the head's buffer). Equal to skb->len for non-TSO packets.
186 struct nfp_net_tx_buf {
190 struct xdp_buff *xdp;
206 * struct nfp_net_tx_ring - TX ring structure
207 * @r_vec: Back pointer to ring vector structure
208 * @idx: Ring index from Linux's perspective
209 * @qcidx: Queue Controller Peripheral (QCP) queue index for the TX queue
210 * @qcp_q: Pointer to base of the QCP TX queue
211 * @cnt: Size of the queue in number of descriptors
212 * @wr_p: TX ring write pointer (free running)
213 * @rd_p: TX ring read pointer (free running)
214 * @qcp_rd_p: Local copy of QCP TX queue read pointer
215 * @wr_ptr_add: Accumulated number of buffers to add to QCP write pointer
216 * (used for .xmit_more delayed kick)
217 * @txbufs: Array of transmitted TX buffers, to free on transmit
218 * @txds: Virtual address of TX ring in host memory
219 * @dma: DMA address of the TX ring
220 * @size: Size, in bytes, of the TX ring (needed to free)
221 * @is_xdp: Is this a XDP TX ring?
223 struct nfp_net_tx_ring {
224 struct nfp_net_r_vector *r_vec;
237 struct nfp_net_tx_buf *txbufs;
238 struct nfp_net_tx_desc *txds;
243 } ____cacheline_aligned;
245 /* RX and freelist descriptor format */
247 #define PCIE_DESC_RX_DD BIT(7)
248 #define PCIE_DESC_RX_META_LEN_MASK GENMASK(6, 0)
250 /* Flags in the RX descriptor */
251 #define PCIE_DESC_RX_RSS cpu_to_le16(BIT(15))
252 #define PCIE_DESC_RX_I_IP4_CSUM cpu_to_le16(BIT(14))
253 #define PCIE_DESC_RX_I_IP4_CSUM_OK cpu_to_le16(BIT(13))
254 #define PCIE_DESC_RX_I_TCP_CSUM cpu_to_le16(BIT(12))
255 #define PCIE_DESC_RX_I_TCP_CSUM_OK cpu_to_le16(BIT(11))
256 #define PCIE_DESC_RX_I_UDP_CSUM cpu_to_le16(BIT(10))
257 #define PCIE_DESC_RX_I_UDP_CSUM_OK cpu_to_le16(BIT(9))
258 #define PCIE_DESC_RX_DECRYPTED cpu_to_le16(BIT(8))
259 #define PCIE_DESC_RX_EOP cpu_to_le16(BIT(7))
260 #define PCIE_DESC_RX_IP4_CSUM cpu_to_le16(BIT(6))
261 #define PCIE_DESC_RX_IP4_CSUM_OK cpu_to_le16(BIT(5))
262 #define PCIE_DESC_RX_TCP_CSUM cpu_to_le16(BIT(4))
263 #define PCIE_DESC_RX_TCP_CSUM_OK cpu_to_le16(BIT(3))
264 #define PCIE_DESC_RX_UDP_CSUM cpu_to_le16(BIT(2))
265 #define PCIE_DESC_RX_UDP_CSUM_OK cpu_to_le16(BIT(1))
266 #define PCIE_DESC_RX_VLAN cpu_to_le16(BIT(0))
268 #define PCIE_DESC_RX_CSUM_ALL (PCIE_DESC_RX_IP4_CSUM | \
269 PCIE_DESC_RX_TCP_CSUM | \
270 PCIE_DESC_RX_UDP_CSUM | \
271 PCIE_DESC_RX_I_IP4_CSUM | \
272 PCIE_DESC_RX_I_TCP_CSUM | \
273 PCIE_DESC_RX_I_UDP_CSUM)
274 #define PCIE_DESC_RX_CSUM_OK_SHIFT 1
275 #define __PCIE_DESC_RX_CSUM_ALL le16_to_cpu(PCIE_DESC_RX_CSUM_ALL)
276 #define __PCIE_DESC_RX_CSUM_ALL_OK (__PCIE_DESC_RX_CSUM_ALL >> \
277 PCIE_DESC_RX_CSUM_OK_SHIFT)
279 struct nfp_net_rx_desc {
282 u8 dma_addr_hi; /* High bits of the buf address */
283 __le16 reserved; /* Must be zero */
284 u8 meta_len_dd; /* Must be zero */
286 __le32 dma_addr_lo; /* Low bits of the buffer address */
290 __le16 data_len; /* Length of the frame + meta data */
292 u8 meta_len_dd; /* Length of meta data prepended +
293 * descriptor done flag.
296 __le16 flags; /* RX flags. See @PCIE_DESC_RX_* */
297 __le16 vlan; /* VLAN if stripped */
304 #define NFP_NET_META_FIELD_MASK GENMASK(NFP_NET_META_FIELD_SIZE - 1, 0)
306 struct nfp_meta_parsed {
315 struct nfp_net_rx_hash {
321 * struct nfp_net_rx_buf - software RX buffer descriptor
322 * @frag: page fragment buffer
323 * @dma_addr: DMA mapping address of the buffer
325 struct nfp_net_rx_buf {
331 * struct nfp_net_xsk_rx_buf - software RX XSK buffer descriptor
332 * @dma_addr: DMA mapping address of the buffer
333 * @xdp: XSK buffer pool handle (for AF_XDP)
335 struct nfp_net_xsk_rx_buf {
337 struct xdp_buff *xdp;
341 * struct nfp_net_rx_ring - RX ring structure
342 * @r_vec: Back pointer to ring vector structure
343 * @cnt: Size of the queue in number of descriptors
344 * @wr_p: FL/RX ring write pointer (free running)
345 * @rd_p: FL/RX ring read pointer (free running)
346 * @idx: Ring index from Linux's perspective
347 * @fl_qcidx: Queue Controller Peripheral (QCP) queue index for the freelist
348 * @qcp_fl: Pointer to base of the QCP freelist queue
349 * @rxbufs: Array of transmitted FL/RX buffers
350 * @xsk_rxbufs: Array of transmitted FL/RX buffers (for AF_XDP)
351 * @rxds: Virtual address of FL/RX ring in host memory
352 * @xdp_rxq: RX-ring info avail for XDP
353 * @dma: DMA address of the FL/RX ring
354 * @size: Size, in bytes, of the FL/RX ring (needed to free)
356 struct nfp_net_rx_ring {
357 struct nfp_net_r_vector *r_vec;
368 struct nfp_net_rx_buf *rxbufs;
369 struct nfp_net_xsk_rx_buf *xsk_rxbufs;
370 struct nfp_net_rx_desc *rxds;
372 struct xdp_rxq_info xdp_rxq;
376 } ____cacheline_aligned;
379 * struct nfp_net_r_vector - Per ring interrupt vector configuration
380 * @nfp_net: Backpointer to nfp_net structure
381 * @napi: NAPI structure for this ring vec
382 * @tasklet: ctrl vNIC, tasklet for servicing the r_vec
383 * @queue: ctrl vNIC, send queue
384 * @lock: ctrl vNIC, r_vec lock protects @queue
385 * @tx_ring: Pointer to TX ring
386 * @rx_ring: Pointer to RX ring
387 * @xdp_ring: Pointer to an extra TX ring for XDP
388 * @xsk_pool: XSK buffer pool active on vector queue pair (for AF_XDP)
389 * @irq_entry: MSI-X table entry (use for talking to the device)
390 * @event_ctr: Number of interrupt
391 * @rx_dim: Dynamic interrupt moderation structure for RX
392 * @tx_dim: Dynamic interrupt moderation structure for TX
393 * @rx_sync: Seqlock for atomic updates of RX stats
394 * @rx_pkts: Number of received packets
395 * @rx_bytes: Number of received bytes
396 * @rx_drops: Number of packets dropped on RX due to lack of resources
397 * @hw_csum_rx_ok: Counter of packets where the HW checksum was OK
398 * @hw_csum_rx_inner_ok: Counter of packets where the inner HW checksum was OK
399 * @hw_csum_rx_complete: Counter of packets with CHECKSUM_COMPLETE reported
400 * @hw_csum_rx_error: Counter of packets with bad checksums
401 * @hw_tls_rx: Number of packets with TLS decrypted by hardware
402 * @tx_sync: Seqlock for atomic updates of TX stats
403 * @tx_pkts: Number of Transmitted packets
404 * @tx_bytes: Number of Transmitted bytes
405 * @hw_csum_tx: Counter of packets with TX checksum offload requested
406 * @hw_csum_tx_inner: Counter of inner TX checksum offload requests
407 * @tx_gather: Counter of packets with Gather DMA
408 * @tx_lso: Counter of LSO packets sent
409 * @hw_tls_tx: Counter of TLS packets sent with crypto offloaded to HW
410 * @tls_tx_fallback: Counter of TLS packets sent which had to be encrypted
411 * by the fallback path because packets came out of order
412 * @tls_tx_no_fallback: Counter of TLS packets not sent because the fallback
413 * path could not encrypt them
414 * @tx_errors: How many TX errors were encountered
415 * @tx_busy: How often was TX busy (no space)?
416 * @rx_replace_buf_alloc_fail: Counter of RX buffer allocation failures
417 * @irq_vector: Interrupt vector number (use for talking to the OS)
418 * @handler: Interrupt handler for this ring vector
419 * @name: Name of the interrupt vector
420 * @affinity_mask: SMP affinity mask for this vector
422 * This structure ties RX and TX rings to interrupt vectors and a NAPI
423 * context. This currently only supports one RX and TX ring per
424 * interrupt vector but might be extended in the future to allow
425 * association of multiple rings per vector.
427 struct nfp_net_r_vector {
428 struct nfp_net *nfp_net;
430 struct napi_struct napi;
432 struct tasklet_struct tasklet;
433 struct sk_buff_head queue;
438 struct nfp_net_tx_ring *tx_ring;
439 struct nfp_net_rx_ring *rx_ring;
447 struct u64_stats_sync rx_sync;
452 u64 hw_csum_rx_inner_ok;
453 u64 hw_csum_rx_complete;
456 u64 hw_csum_rx_error;
457 u64 rx_replace_buf_alloc_fail;
459 struct nfp_net_tx_ring *xdp_ring;
460 struct xsk_buff_pool *xsk_pool;
462 struct u64_stats_sync tx_sync;
466 u64 ____cacheline_aligned_in_smp hw_csum_tx;
467 u64 hw_csum_tx_inner;
473 u64 tls_tx_no_fallback;
477 /* Cold data follows */
480 irq_handler_t handler;
481 char name[IFNAMSIZ + 8];
482 cpumask_t affinity_mask;
483 } ____cacheline_aligned;
485 /* Firmware version as it is written in the 32bit value in the BAR */
486 struct nfp_net_fw_version {
493 static inline bool nfp_net_fw_ver_eq(struct nfp_net_fw_version *fw_ver,
494 u8 resv, u8 class, u8 major, u8 minor)
496 return fw_ver->resv == resv &&
497 fw_ver->class == class &&
498 fw_ver->major == major &&
499 fw_ver->minor == minor;
502 struct nfp_stat_pair {
508 * struct nfp_net_dp - NFP network device datapath data structure
509 * @dev: Backpointer to struct device
510 * @netdev: Backpointer to net_device structure
511 * @is_vf: Is the driver attached to a VF?
512 * @chained_metadata_format: Firemware will use new metadata format
513 * @ktls_tx: Is kTLS TX enabled?
514 * @rx_dma_dir: Mapping direction for RX buffers
515 * @rx_dma_off: Offset at which DMA packets (for XDP headroom)
516 * @rx_offset: Offset in the RX buffers where packet data starts
517 * @ctrl: Local copy of the control register/word.
518 * @fl_bufsz: Currently configured size of the freelist buffers
519 * @xdp_prog: Installed XDP program
520 * @tx_rings: Array of pre-allocated TX ring structures
521 * @rx_rings: Array of pre-allocated RX ring structures
522 * @ctrl_bar: Pointer to mapped control BAR
524 * @txd_cnt: Size of the TX ring in number of descriptors
525 * @rxd_cnt: Size of the RX ring in number of descriptors
526 * @num_r_vecs: Number of used ring vectors
527 * @num_tx_rings: Currently configured number of TX rings
528 * @num_stack_tx_rings: Number of TX rings used by the stack (not XDP)
529 * @num_rx_rings: Currently configured number of RX rings
531 * @xsk_pools: XSK buffer pools, @max_r_vecs in size (for AF_XDP).
535 struct net_device *netdev;
538 u8 chained_metadata_format:1;
549 struct bpf_prog *xdp_prog;
551 struct nfp_net_tx_ring *tx_rings;
552 struct nfp_net_rx_ring *rx_rings;
554 u8 __iomem *ctrl_bar;
556 /* Cold data follows */
558 unsigned int txd_cnt;
559 unsigned int rxd_cnt;
561 unsigned int num_r_vecs;
563 unsigned int num_tx_rings;
564 unsigned int num_stack_tx_rings;
565 unsigned int num_rx_rings;
569 struct xsk_buff_pool **xsk_pools;
573 * struct nfp_net - NFP network device structure
574 * @dp: Datapath structure
575 * @dev_info: NFP ASIC params
576 * @id: vNIC id within the PF (0 for VFs)
577 * @fw_ver: Firmware version
578 * @cap: Capabilities advertised by the Firmware
579 * @max_mtu: Maximum support MTU advertised by the Firmware
580 * @rss_hfunc: RSS selected hash function
581 * @rss_cfg: RSS configuration
582 * @rss_key: RSS secret key
583 * @rss_itbl: RSS indirection table
584 * @xdp: Information about the driver XDP program
585 * @xdp_hw: Information about the HW XDP program
586 * @max_r_vecs: Number of allocated interrupt vectors for RX/TX
587 * @max_tx_rings: Maximum number of TX rings supported by the Firmware
588 * @max_rx_rings: Maximum number of RX rings supported by the Firmware
589 * @stride_rx: Queue controller RX queue spacing
590 * @stride_tx: Queue controller TX queue spacing
591 * @r_vecs: Pre-allocated array of ring vectors
592 * @irq_entries: Pre-allocated array of MSI-X entries
593 * @lsc_handler: Handler for Link State Change interrupt
594 * @lsc_name: Name for Link State Change interrupt
595 * @exn_handler: Handler for Exception interrupt
596 * @exn_name: Name for Exception interrupt
597 * @shared_handler: Handler for shared interrupts
598 * @shared_name: Name for shared interrupt
599 * @reconfig_lock: Protects @reconfig_posted, @reconfig_timer_active,
600 * @reconfig_sync_present and HW reconfiguration request
601 * regs/machinery from async requests (sync must take
603 * @reconfig_posted: Pending reconfig bits coming from async sources
604 * @reconfig_timer_active: Timer for reading reconfiguration results is pending
605 * @reconfig_sync_present: Some thread is performing synchronous reconfig
606 * @reconfig_timer: Timer for async reading of reconfig results
607 * @reconfig_in_progress_update: Update FW is processing now (debug only)
608 * @bar_lock: vNIC config BAR access lock, protects: update,
609 * mailbox area, crypto TLV
610 * @link_up: Is the link up?
611 * @link_status_lock: Protects @link_* and ensures atomicity with BAR reading
612 * @rx_coalesce_adapt_on: Is RX interrupt moderation adaptive?
613 * @tx_coalesce_adapt_on: Is TX interrupt moderation adaptive?
614 * @rx_coalesce_usecs: RX interrupt moderation usecs delay parameter
615 * @rx_coalesce_max_frames: RX interrupt moderation frame count parameter
616 * @tx_coalesce_usecs: TX interrupt moderation usecs delay parameter
617 * @tx_coalesce_max_frames: TX interrupt moderation frame count parameter
618 * @qcp_cfg: Pointer to QCP queue used for configuration notification
619 * @tx_bar: Pointer to mapped TX queues
620 * @rx_bar: Pointer to mapped FL/RX queues
621 * @tlv_caps: Parsed TLV capabilities
622 * @ktls_tx_conn_cnt: Number of offloaded kTLS TX connections
623 * @ktls_rx_conn_cnt: Number of offloaded kTLS RX connections
624 * @ktls_conn_id_gen: Trivial generator for kTLS connection ids (for TX)
625 * @ktls_no_space: Counter of firmware rejecting kTLS connection due to
627 * @ktls_rx_resync_req: Counter of TLS RX resync requested
628 * @ktls_rx_resync_ign: Counter of TLS RX resync requests ignored
629 * @ktls_rx_resync_sent: Counter of TLS RX resync completed
630 * @mbox_cmsg: Common Control Message via vNIC mailbox state
631 * @mbox_cmsg.queue: CCM mbox queue of pending messages
632 * @mbox_cmsg.wq: CCM mbox wait queue of waiting processes
633 * @mbox_cmsg.workq: CCM mbox work queue for @wait_work and @runq_work
634 * @mbox_cmsg.wait_work: CCM mbox posted msg reconfig wait work
635 * @mbox_cmsg.runq_work: CCM mbox posted msg queue runner work
636 * @mbox_cmsg.tag: CCM mbox message tag allocator
637 * @debugfs_dir: Device directory in debugfs
638 * @vnic_list: Entry on device vNIC list
639 * @pdev: Backpointer to PCI device
640 * @app: APP handle if available
641 * @vnic_no_name: For non-port PF vNIC make ndo_get_phys_port_name return
642 * -EOPNOTSUPP to keep backwards compatibility (set by app)
643 * @port: Pointer to nfp_port structure if vNIC is a port
644 * @app_priv: APP private data for this vNIC
647 struct nfp_net_dp dp;
649 const struct nfp_dev_info *dev_info;
650 struct nfp_net_fw_version fw_ver;
659 u8 rss_key[NFP_NET_CFG_RSS_KEY_SZ];
660 u8 rss_itbl[NFP_NET_CFG_RSS_ITBL_SZ];
662 struct xdp_attachment_info xdp;
663 struct xdp_attachment_info xdp_hw;
665 unsigned int max_tx_rings;
666 unsigned int max_rx_rings;
671 unsigned int max_r_vecs;
672 struct nfp_net_r_vector r_vecs[NFP_NET_MAX_R_VECS];
673 struct msix_entry irq_entries[NFP_NET_MAX_IRQS];
675 irq_handler_t lsc_handler;
676 char lsc_name[IFNAMSIZ + 8];
678 irq_handler_t exn_handler;
679 char exn_name[IFNAMSIZ + 8];
681 irq_handler_t shared_handler;
682 char shared_name[IFNAMSIZ + 8];
685 spinlock_t link_status_lock;
687 spinlock_t reconfig_lock;
689 bool reconfig_timer_active;
690 bool reconfig_sync_present;
691 struct timer_list reconfig_timer;
692 u32 reconfig_in_progress_update;
694 struct semaphore bar_lock;
696 bool rx_coalesce_adapt_on;
697 bool tx_coalesce_adapt_on;
698 u32 rx_coalesce_usecs;
699 u32 rx_coalesce_max_frames;
700 u32 tx_coalesce_usecs;
701 u32 tx_coalesce_max_frames;
708 struct nfp_net_tlv_caps tlv_caps;
710 unsigned int ktls_tx_conn_cnt;
711 unsigned int ktls_rx_conn_cnt;
713 atomic64_t ktls_conn_id_gen;
715 atomic_t ktls_no_space;
716 atomic_t ktls_rx_resync_req;
717 atomic_t ktls_rx_resync_ign;
718 atomic_t ktls_rx_resync_sent;
721 struct sk_buff_head queue;
722 wait_queue_head_t wq;
723 struct workqueue_struct *workq;
724 struct work_struct wait_work;
725 struct work_struct runq_work;
729 struct dentry *debugfs_dir;
731 struct list_head vnic_list;
733 struct pci_dev *pdev;
738 struct nfp_port *port;
743 /* Functions to read/write from/to a BAR
744 * Performs any endian conversion necessary.
746 static inline u16 nn_readb(struct nfp_net *nn, int off)
748 return readb(nn->dp.ctrl_bar + off);
751 static inline void nn_writeb(struct nfp_net *nn, int off, u8 val)
753 writeb(val, nn->dp.ctrl_bar + off);
756 static inline u16 nn_readw(struct nfp_net *nn, int off)
758 return readw(nn->dp.ctrl_bar + off);
761 static inline void nn_writew(struct nfp_net *nn, int off, u16 val)
763 writew(val, nn->dp.ctrl_bar + off);
766 static inline u32 nn_readl(struct nfp_net *nn, int off)
768 return readl(nn->dp.ctrl_bar + off);
771 static inline void nn_writel(struct nfp_net *nn, int off, u32 val)
773 writel(val, nn->dp.ctrl_bar + off);
776 static inline u64 nn_readq(struct nfp_net *nn, int off)
778 return readq(nn->dp.ctrl_bar + off);
781 static inline void nn_writeq(struct nfp_net *nn, int off, u64 val)
783 writeq(val, nn->dp.ctrl_bar + off);
786 /* Flush posted PCI writes by reading something without side effects */
787 static inline void nn_pci_flush(struct nfp_net *nn)
789 nn_readl(nn, NFP_NET_CFG_VERSION);
792 /* Queue Controller Peripheral access functions and definitions.
794 * Some of the BARs of the NFP are mapped to portions of the Queue
795 * Controller Peripheral (QCP) address space on the NFP. A QCP queue
796 * has a read and a write pointer (as well as a size and flags,
797 * indicating overflow etc). The QCP offers a number of different
798 * operation on queue pointers, but here we only offer function to
799 * either add to a pointer or to read the pointer value.
801 #define NFP_QCP_QUEUE_ADDR_SZ 0x800
802 #define NFP_QCP_QUEUE_AREA_SZ 0x80000
803 #define NFP_QCP_QUEUE_OFF(_x) ((_x) * NFP_QCP_QUEUE_ADDR_SZ)
804 #define NFP_QCP_QUEUE_ADD_RPTR 0x0000
805 #define NFP_QCP_QUEUE_ADD_WPTR 0x0004
806 #define NFP_QCP_QUEUE_STS_LO 0x0008
807 #define NFP_QCP_QUEUE_STS_LO_READPTR_mask 0x3ffff
808 #define NFP_QCP_QUEUE_STS_HI 0x000c
809 #define NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask 0x3ffff
811 /* The offset of a QCP queues in the PCIe Target */
812 #define NFP_PCIE_QUEUE(_q) (0x80000 + (NFP_QCP_QUEUE_ADDR_SZ * ((_q) & 0xff)))
814 /* nfp_qcp_ptr - Read or Write Pointer of a queue */
816 NFP_QCP_READ_PTR = 0,
821 * nfp_qcp_rd_ptr_add() - Add the value to the read pointer of a queue
823 * @q: Base address for queue structure
824 * @val: Value to add to the queue pointer
826 static inline void nfp_qcp_rd_ptr_add(u8 __iomem *q, u32 val)
828 writel(val, q + NFP_QCP_QUEUE_ADD_RPTR);
832 * nfp_qcp_wr_ptr_add() - Add the value to the write pointer of a queue
834 * @q: Base address for queue structure
835 * @val: Value to add to the queue pointer
837 static inline void nfp_qcp_wr_ptr_add(u8 __iomem *q, u32 val)
839 writel(val, q + NFP_QCP_QUEUE_ADD_WPTR);
842 static inline u32 _nfp_qcp_read(u8 __iomem *q, enum nfp_qcp_ptr ptr)
847 if (ptr == NFP_QCP_READ_PTR)
848 off = NFP_QCP_QUEUE_STS_LO;
850 off = NFP_QCP_QUEUE_STS_HI;
852 val = readl(q + off);
854 if (ptr == NFP_QCP_READ_PTR)
855 return val & NFP_QCP_QUEUE_STS_LO_READPTR_mask;
857 return val & NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask;
861 * nfp_qcp_rd_ptr_read() - Read the current read pointer value for a queue
862 * @q: Base address for queue structure
864 * Return: Value read.
866 static inline u32 nfp_qcp_rd_ptr_read(u8 __iomem *q)
868 return _nfp_qcp_read(q, NFP_QCP_READ_PTR);
872 * nfp_qcp_wr_ptr_read() - Read the current write pointer value for a queue
873 * @q: Base address for queue structure
875 * Return: Value read.
877 static inline u32 nfp_qcp_wr_ptr_read(u8 __iomem *q)
879 return _nfp_qcp_read(q, NFP_QCP_WRITE_PTR);
882 static inline bool nfp_net_is_data_vnic(struct nfp_net *nn)
884 WARN_ON_ONCE(!nn->dp.netdev && nn->port);
885 return !!nn->dp.netdev;
888 static inline bool nfp_net_running(struct nfp_net *nn)
890 return nn->dp.ctrl & NFP_NET_CFG_CTRL_ENABLE;
893 static inline const char *nfp_net_name(struct nfp_net *nn)
895 return nn->dp.netdev ? nn->dp.netdev->name : "ctrl";
898 static inline void nfp_ctrl_lock(struct nfp_net *nn)
899 __acquires(&nn->r_vecs[0].lock)
901 spin_lock_bh(&nn->r_vecs[0].lock);
904 static inline void nfp_ctrl_unlock(struct nfp_net *nn)
905 __releases(&nn->r_vecs[0].lock)
907 spin_unlock_bh(&nn->r_vecs[0].lock);
910 static inline void nn_ctrl_bar_lock(struct nfp_net *nn)
915 static inline bool nn_ctrl_bar_trylock(struct nfp_net *nn)
917 return !down_trylock(&nn->bar_lock);
920 static inline void nn_ctrl_bar_unlock(struct nfp_net *nn)
926 extern const char nfp_driver_version[];
928 extern const struct net_device_ops nfp_net_netdev_ops;
930 static inline bool nfp_netdev_is_nfp_net(struct net_device *netdev)
932 return netdev->netdev_ops == &nfp_net_netdev_ops;
935 static inline int nfp_net_coalesce_para_check(u32 usecs, u32 pkts)
937 if ((usecs >= ((1 << 16) - 1)) || (pkts >= ((1 << 16) - 1)))
944 void nfp_net_get_fw_version(struct nfp_net_fw_version *fw_ver,
945 void __iomem *ctrl_bar);
948 nfp_net_alloc(struct pci_dev *pdev, const struct nfp_dev_info *dev_info,
949 void __iomem *ctrl_bar, bool needs_netdev,
950 unsigned int max_tx_rings, unsigned int max_rx_rings);
951 void nfp_net_free(struct nfp_net *nn);
953 int nfp_net_init(struct nfp_net *nn);
954 void nfp_net_clean(struct nfp_net *nn);
956 int nfp_ctrl_open(struct nfp_net *nn);
957 void nfp_ctrl_close(struct nfp_net *nn);
959 void nfp_net_set_ethtool_ops(struct net_device *netdev);
960 void nfp_net_info(struct nfp_net *nn);
961 int __nfp_net_reconfig(struct nfp_net *nn, u32 update);
962 int nfp_net_reconfig(struct nfp_net *nn, u32 update);
963 unsigned int nfp_net_rss_key_sz(struct nfp_net *nn);
964 void nfp_net_rss_write_itbl(struct nfp_net *nn);
965 void nfp_net_rss_write_key(struct nfp_net *nn);
966 void nfp_net_coalesce_write_cfg(struct nfp_net *nn);
967 int nfp_net_mbox_lock(struct nfp_net *nn, unsigned int data_size);
968 int nfp_net_mbox_reconfig(struct nfp_net *nn, u32 mbox_cmd);
969 int nfp_net_mbox_reconfig_and_unlock(struct nfp_net *nn, u32 mbox_cmd);
970 void nfp_net_mbox_reconfig_post(struct nfp_net *nn, u32 update);
971 int nfp_net_mbox_reconfig_wait_posted(struct nfp_net *nn);
973 void nfp_net_irq_unmask(struct nfp_net *nn, unsigned int entry_nr);
975 nfp_net_irqs_alloc(struct pci_dev *pdev, struct msix_entry *irq_entries,
976 unsigned int min_irqs, unsigned int want_irqs);
977 void nfp_net_irqs_disable(struct pci_dev *pdev);
979 nfp_net_irqs_assign(struct nfp_net *nn, struct msix_entry *irq_entries,
982 void nfp_net_tx_xmit_more_flush(struct nfp_net_tx_ring *tx_ring);
983 void nfp_net_tx_complete(struct nfp_net_tx_ring *tx_ring, int budget);
986 nfp_net_parse_meta(struct net_device *netdev, struct nfp_meta_parsed *meta,
987 void *data, void *pkt, unsigned int pkt_len, int meta_len);
989 void nfp_net_rx_csum(const struct nfp_net_dp *dp,
990 struct nfp_net_r_vector *r_vec,
991 const struct nfp_net_rx_desc *rxd,
992 const struct nfp_meta_parsed *meta,
993 struct sk_buff *skb);
995 struct nfp_net_dp *nfp_net_clone_dp(struct nfp_net *nn);
996 int nfp_net_ring_reconfig(struct nfp_net *nn, struct nfp_net_dp *new,
997 struct netlink_ext_ack *extack);
999 #ifdef CONFIG_NFP_DEBUG
1000 void nfp_net_debugfs_create(void);
1001 void nfp_net_debugfs_destroy(void);
1002 struct dentry *nfp_net_debugfs_device_add(struct pci_dev *pdev);
1003 void nfp_net_debugfs_vnic_add(struct nfp_net *nn, struct dentry *ddir);
1004 void nfp_net_debugfs_dir_clean(struct dentry **dir);
1006 static inline void nfp_net_debugfs_create(void)
1010 static inline void nfp_net_debugfs_destroy(void)
1014 static inline struct dentry *nfp_net_debugfs_device_add(struct pci_dev *pdev)
1020 nfp_net_debugfs_vnic_add(struct nfp_net *nn, struct dentry *ddir)
1024 static inline void nfp_net_debugfs_dir_clean(struct dentry **dir)
1027 #endif /* CONFIG_NFP_DEBUG */
1029 #endif /* _NFP_NET_H_ */