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 /* Default size for MTU and freelist buffer sizes */
67 #define NFP_NET_DEFAULT_MTU 1500U
69 /* Maximum number of bytes prepended to a packet */
70 #define NFP_NET_MAX_PREPEND 64
72 /* Interrupt definitions */
73 #define NFP_NET_NON_Q_VECTORS 2
74 #define NFP_NET_IRQ_LSC_IDX 0
75 #define NFP_NET_IRQ_EXN_IDX 1
76 #define NFP_NET_MIN_VNIC_IRQS (NFP_NET_NON_Q_VECTORS + 1)
78 /* Queue/Ring definitions */
79 #define NFP_NET_MAX_TX_RINGS 64 /* Max. # of Tx rings per device */
80 #define NFP_NET_MAX_RX_RINGS 64 /* Max. # of Rx rings per device */
81 #define NFP_NET_MAX_R_VECS (NFP_NET_MAX_TX_RINGS > NFP_NET_MAX_RX_RINGS ? \
82 NFP_NET_MAX_TX_RINGS : NFP_NET_MAX_RX_RINGS)
83 #define NFP_NET_MAX_IRQS (NFP_NET_NON_Q_VECTORS + NFP_NET_MAX_R_VECS)
85 #define NFP_NET_TX_DESCS_DEFAULT 4096 /* Default # of Tx descs per ring */
86 #define NFP_NET_RX_DESCS_DEFAULT 4096 /* Default # of Rx descs per ring */
88 #define NFP_NET_FL_BATCH 16 /* Add freelist in this Batch size */
89 #define NFP_NET_XDP_MAX_COMPLETE 2048 /* XDP bufs to reclaim in NAPI poll */
91 /* Offload definitions */
92 #define NFP_NET_N_VXLAN_PORTS (NFP_NET_CFG_VXLAN_SZ / sizeof(__be16))
94 #define NFP_NET_RX_BUF_HEADROOM (NET_SKB_PAD + NET_IP_ALIGN)
95 #define NFP_NET_RX_BUF_NON_DATA (NFP_NET_RX_BUF_HEADROOM + \
96 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
98 /* Forward declarations */
102 struct nfp_eth_table_port;
104 struct nfp_net_r_vector;
106 struct xsk_buff_pool;
108 struct nfp_nfd3_tx_desc;
109 struct nfp_nfd3_tx_buf;
111 /* Convenience macro for wrapping descriptor index on ring size */
112 #define D_IDX(ring, idx) ((idx) & ((ring)->cnt - 1))
114 /* Convenience macro for writing dma address into RX/TX descriptors */
115 #define nfp_desc_set_dma_addr(desc, dma_addr) \
117 __typeof(desc) __d = (desc); \
118 dma_addr_t __addr = (dma_addr); \
120 __d->dma_addr_lo = cpu_to_le32(lower_32_bits(__addr)); \
121 __d->dma_addr_hi = upper_32_bits(__addr) & 0xff; \
125 * struct nfp_net_tx_ring - TX ring structure
126 * @r_vec: Back pointer to ring vector structure
127 * @idx: Ring index from Linux's perspective
128 * @qcp_q: Pointer to base of the QCP TX queue
129 * @txrwb: TX pointer write back area
130 * @cnt: Size of the queue in number of descriptors
131 * @wr_p: TX ring write pointer (free running)
132 * @rd_p: TX ring read pointer (free running)
133 * @qcp_rd_p: Local copy of QCP TX queue read pointer
134 * @wr_ptr_add: Accumulated number of buffers to add to QCP write pointer
135 * (used for .xmit_more delayed kick)
136 * @txbufs: Array of transmitted TX buffers, to free on transmit
137 * @txds: Virtual address of TX ring in host memory
139 * @qcidx: Queue Controller Peripheral (QCP) queue index for the TX queue
140 * @dma: DMA address of the TX ring
141 * @size: Size, in bytes, of the TX ring (needed to free)
142 * @is_xdp: Is this a XDP TX ring?
144 struct nfp_net_tx_ring {
145 struct nfp_net_r_vector *r_vec;
158 struct nfp_nfd3_tx_buf *txbufs;
159 struct nfp_nfd3_tx_desc *txds;
161 /* Cold data follows */
167 } ____cacheline_aligned;
169 /* RX and freelist descriptor format */
171 #define PCIE_DESC_RX_DD BIT(7)
172 #define PCIE_DESC_RX_META_LEN_MASK GENMASK(6, 0)
174 /* Flags in the RX descriptor */
175 #define PCIE_DESC_RX_RSS cpu_to_le16(BIT(15))
176 #define PCIE_DESC_RX_I_IP4_CSUM cpu_to_le16(BIT(14))
177 #define PCIE_DESC_RX_I_IP4_CSUM_OK cpu_to_le16(BIT(13))
178 #define PCIE_DESC_RX_I_TCP_CSUM cpu_to_le16(BIT(12))
179 #define PCIE_DESC_RX_I_TCP_CSUM_OK cpu_to_le16(BIT(11))
180 #define PCIE_DESC_RX_I_UDP_CSUM cpu_to_le16(BIT(10))
181 #define PCIE_DESC_RX_I_UDP_CSUM_OK cpu_to_le16(BIT(9))
182 #define PCIE_DESC_RX_DECRYPTED cpu_to_le16(BIT(8))
183 #define PCIE_DESC_RX_EOP cpu_to_le16(BIT(7))
184 #define PCIE_DESC_RX_IP4_CSUM cpu_to_le16(BIT(6))
185 #define PCIE_DESC_RX_IP4_CSUM_OK cpu_to_le16(BIT(5))
186 #define PCIE_DESC_RX_TCP_CSUM cpu_to_le16(BIT(4))
187 #define PCIE_DESC_RX_TCP_CSUM_OK cpu_to_le16(BIT(3))
188 #define PCIE_DESC_RX_UDP_CSUM cpu_to_le16(BIT(2))
189 #define PCIE_DESC_RX_UDP_CSUM_OK cpu_to_le16(BIT(1))
190 #define PCIE_DESC_RX_VLAN cpu_to_le16(BIT(0))
192 #define PCIE_DESC_RX_CSUM_ALL (PCIE_DESC_RX_IP4_CSUM | \
193 PCIE_DESC_RX_TCP_CSUM | \
194 PCIE_DESC_RX_UDP_CSUM | \
195 PCIE_DESC_RX_I_IP4_CSUM | \
196 PCIE_DESC_RX_I_TCP_CSUM | \
197 PCIE_DESC_RX_I_UDP_CSUM)
198 #define PCIE_DESC_RX_CSUM_OK_SHIFT 1
199 #define __PCIE_DESC_RX_CSUM_ALL le16_to_cpu(PCIE_DESC_RX_CSUM_ALL)
200 #define __PCIE_DESC_RX_CSUM_ALL_OK (__PCIE_DESC_RX_CSUM_ALL >> \
201 PCIE_DESC_RX_CSUM_OK_SHIFT)
203 struct nfp_net_rx_desc {
206 u8 dma_addr_hi; /* High bits of the buf address */
207 __le16 reserved; /* Must be zero */
208 u8 meta_len_dd; /* Must be zero */
210 __le32 dma_addr_lo; /* Low bits of the buffer address */
214 __le16 data_len; /* Length of the frame + meta data */
216 u8 meta_len_dd; /* Length of meta data prepended +
217 * descriptor done flag.
220 __le16 flags; /* RX flags. See @PCIE_DESC_RX_* */
221 __le16 vlan; /* VLAN if stripped */
228 #define NFP_NET_META_FIELD_MASK GENMASK(NFP_NET_META_FIELD_SIZE - 1, 0)
230 struct nfp_meta_parsed {
239 struct nfp_net_rx_hash {
245 * struct nfp_net_rx_buf - software RX buffer descriptor
246 * @frag: page fragment buffer
247 * @dma_addr: DMA mapping address of the buffer
249 struct nfp_net_rx_buf {
255 * struct nfp_net_xsk_rx_buf - software RX XSK buffer descriptor
256 * @dma_addr: DMA mapping address of the buffer
257 * @xdp: XSK buffer pool handle (for AF_XDP)
259 struct nfp_net_xsk_rx_buf {
261 struct xdp_buff *xdp;
265 * struct nfp_net_rx_ring - RX ring structure
266 * @r_vec: Back pointer to ring vector structure
267 * @cnt: Size of the queue in number of descriptors
268 * @wr_p: FL/RX ring write pointer (free running)
269 * @rd_p: FL/RX ring read pointer (free running)
270 * @idx: Ring index from Linux's perspective
271 * @fl_qcidx: Queue Controller Peripheral (QCP) queue index for the freelist
272 * @qcp_fl: Pointer to base of the QCP freelist queue
273 * @rxbufs: Array of transmitted FL/RX buffers
274 * @xsk_rxbufs: Array of transmitted FL/RX buffers (for AF_XDP)
275 * @rxds: Virtual address of FL/RX ring in host memory
276 * @xdp_rxq: RX-ring info avail for XDP
277 * @dma: DMA address of the FL/RX ring
278 * @size: Size, in bytes, of the FL/RX ring (needed to free)
280 struct nfp_net_rx_ring {
281 struct nfp_net_r_vector *r_vec;
292 struct nfp_net_rx_buf *rxbufs;
293 struct nfp_net_xsk_rx_buf *xsk_rxbufs;
294 struct nfp_net_rx_desc *rxds;
296 struct xdp_rxq_info xdp_rxq;
300 } ____cacheline_aligned;
303 * struct nfp_net_r_vector - Per ring interrupt vector configuration
304 * @nfp_net: Backpointer to nfp_net structure
305 * @napi: NAPI structure for this ring vec
306 * @tasklet: ctrl vNIC, tasklet for servicing the r_vec
307 * @queue: ctrl vNIC, send queue
308 * @lock: ctrl vNIC, r_vec lock protects @queue
309 * @tx_ring: Pointer to TX ring
310 * @rx_ring: Pointer to RX ring
311 * @xdp_ring: Pointer to an extra TX ring for XDP
312 * @xsk_pool: XSK buffer pool active on vector queue pair (for AF_XDP)
313 * @irq_entry: MSI-X table entry (use for talking to the device)
314 * @event_ctr: Number of interrupt
315 * @rx_dim: Dynamic interrupt moderation structure for RX
316 * @tx_dim: Dynamic interrupt moderation structure for TX
317 * @rx_sync: Seqlock for atomic updates of RX stats
318 * @rx_pkts: Number of received packets
319 * @rx_bytes: Number of received bytes
320 * @rx_drops: Number of packets dropped on RX due to lack of resources
321 * @hw_csum_rx_ok: Counter of packets where the HW checksum was OK
322 * @hw_csum_rx_inner_ok: Counter of packets where the inner HW checksum was OK
323 * @hw_csum_rx_complete: Counter of packets with CHECKSUM_COMPLETE reported
324 * @hw_csum_rx_error: Counter of packets with bad checksums
325 * @hw_tls_rx: Number of packets with TLS decrypted by hardware
326 * @tx_sync: Seqlock for atomic updates of TX stats
327 * @tx_pkts: Number of Transmitted packets
328 * @tx_bytes: Number of Transmitted bytes
329 * @hw_csum_tx: Counter of packets with TX checksum offload requested
330 * @hw_csum_tx_inner: Counter of inner TX checksum offload requests
331 * @tx_gather: Counter of packets with Gather DMA
332 * @tx_lso: Counter of LSO packets sent
333 * @hw_tls_tx: Counter of TLS packets sent with crypto offloaded to HW
334 * @tls_tx_fallback: Counter of TLS packets sent which had to be encrypted
335 * by the fallback path because packets came out of order
336 * @tls_tx_no_fallback: Counter of TLS packets not sent because the fallback
337 * path could not encrypt them
338 * @tx_errors: How many TX errors were encountered
339 * @tx_busy: How often was TX busy (no space)?
340 * @rx_replace_buf_alloc_fail: Counter of RX buffer allocation failures
341 * @irq_vector: Interrupt vector number (use for talking to the OS)
342 * @handler: Interrupt handler for this ring vector
343 * @name: Name of the interrupt vector
344 * @affinity_mask: SMP affinity mask for this vector
346 * This structure ties RX and TX rings to interrupt vectors and a NAPI
347 * context. This currently only supports one RX and TX ring per
348 * interrupt vector but might be extended in the future to allow
349 * association of multiple rings per vector.
351 struct nfp_net_r_vector {
352 struct nfp_net *nfp_net;
354 struct napi_struct napi;
356 struct tasklet_struct tasklet;
357 struct sk_buff_head queue;
362 struct nfp_net_tx_ring *tx_ring;
363 struct nfp_net_rx_ring *rx_ring;
371 struct u64_stats_sync rx_sync;
376 u64 hw_csum_rx_inner_ok;
377 u64 hw_csum_rx_complete;
380 u64 hw_csum_rx_error;
381 u64 rx_replace_buf_alloc_fail;
383 struct nfp_net_tx_ring *xdp_ring;
384 struct xsk_buff_pool *xsk_pool;
386 struct u64_stats_sync tx_sync;
390 u64 ____cacheline_aligned_in_smp hw_csum_tx;
391 u64 hw_csum_tx_inner;
397 u64 tls_tx_no_fallback;
401 /* Cold data follows */
404 irq_handler_t handler;
405 char name[IFNAMSIZ + 8];
406 cpumask_t affinity_mask;
407 } ____cacheline_aligned;
409 /* Firmware version as it is written in the 32bit value in the BAR */
410 struct nfp_net_fw_version {
417 static inline bool nfp_net_fw_ver_eq(struct nfp_net_fw_version *fw_ver,
418 u8 resv, u8 class, u8 major, u8 minor)
420 return fw_ver->resv == resv &&
421 fw_ver->class == class &&
422 fw_ver->major == major &&
423 fw_ver->minor == minor;
426 struct nfp_stat_pair {
432 * struct nfp_net_dp - NFP network device datapath data structure
433 * @dev: Backpointer to struct device
434 * @netdev: Backpointer to net_device structure
435 * @is_vf: Is the driver attached to a VF?
436 * @chained_metadata_format: Firemware will use new metadata format
437 * @ktls_tx: Is kTLS TX enabled?
438 * @rx_dma_dir: Mapping direction for RX buffers
439 * @rx_dma_off: Offset at which DMA packets (for XDP headroom)
440 * @rx_offset: Offset in the RX buffers where packet data starts
441 * @ctrl: Local copy of the control register/word.
442 * @fl_bufsz: Currently configured size of the freelist buffers
443 * @xdp_prog: Installed XDP program
444 * @tx_rings: Array of pre-allocated TX ring structures
445 * @rx_rings: Array of pre-allocated RX ring structures
446 * @ctrl_bar: Pointer to mapped control BAR
448 * @ops: Callbacks and parameters for this vNIC's NFD version
449 * @txrwb: TX pointer write back area (indexed by queue id)
450 * @txrwb_dma: TX pointer write back area DMA address
451 * @txd_cnt: Size of the TX ring in number of min size packets
452 * @rxd_cnt: Size of the RX ring in number of min size packets
453 * @num_r_vecs: Number of used ring vectors
454 * @num_tx_rings: Currently configured number of TX rings
455 * @num_stack_tx_rings: Number of TX rings used by the stack (not XDP)
456 * @num_rx_rings: Currently configured number of RX rings
458 * @xsk_pools: XSK buffer pools, @max_r_vecs in size (for AF_XDP).
462 struct net_device *netdev;
465 u8 chained_metadata_format:1;
476 struct bpf_prog *xdp_prog;
478 struct nfp_net_tx_ring *tx_rings;
479 struct nfp_net_rx_ring *rx_rings;
481 u8 __iomem *ctrl_bar;
483 /* Cold data follows */
485 const struct nfp_dp_ops *ops;
488 dma_addr_t txrwb_dma;
490 unsigned int txd_cnt;
491 unsigned int rxd_cnt;
493 unsigned int num_r_vecs;
495 unsigned int num_tx_rings;
496 unsigned int num_stack_tx_rings;
497 unsigned int num_rx_rings;
501 struct xsk_buff_pool **xsk_pools;
505 * struct nfp_net - NFP network device structure
506 * @dp: Datapath structure
507 * @dev_info: NFP ASIC params
508 * @id: vNIC id within the PF (0 for VFs)
509 * @fw_ver: Firmware version
510 * @cap: Capabilities advertised by the Firmware
511 * @max_mtu: Maximum support MTU advertised by the Firmware
512 * @rss_hfunc: RSS selected hash function
513 * @rss_cfg: RSS configuration
514 * @rss_key: RSS secret key
515 * @rss_itbl: RSS indirection table
516 * @xdp: Information about the driver XDP program
517 * @xdp_hw: Information about the HW XDP program
518 * @max_r_vecs: Number of allocated interrupt vectors for RX/TX
519 * @max_tx_rings: Maximum number of TX rings supported by the Firmware
520 * @max_rx_rings: Maximum number of RX rings supported by the Firmware
521 * @stride_rx: Queue controller RX queue spacing
522 * @stride_tx: Queue controller TX queue spacing
523 * @r_vecs: Pre-allocated array of ring vectors
524 * @irq_entries: Pre-allocated array of MSI-X entries
525 * @lsc_handler: Handler for Link State Change interrupt
526 * @lsc_name: Name for Link State Change interrupt
527 * @exn_handler: Handler for Exception interrupt
528 * @exn_name: Name for Exception interrupt
529 * @shared_handler: Handler for shared interrupts
530 * @shared_name: Name for shared interrupt
531 * @reconfig_lock: Protects @reconfig_posted, @reconfig_timer_active,
532 * @reconfig_sync_present and HW reconfiguration request
533 * regs/machinery from async requests (sync must take
535 * @reconfig_posted: Pending reconfig bits coming from async sources
536 * @reconfig_timer_active: Timer for reading reconfiguration results is pending
537 * @reconfig_sync_present: Some thread is performing synchronous reconfig
538 * @reconfig_timer: Timer for async reading of reconfig results
539 * @reconfig_in_progress_update: Update FW is processing now (debug only)
540 * @bar_lock: vNIC config BAR access lock, protects: update,
541 * mailbox area, crypto TLV
542 * @link_up: Is the link up?
543 * @link_status_lock: Protects @link_* and ensures atomicity with BAR reading
544 * @rx_coalesce_adapt_on: Is RX interrupt moderation adaptive?
545 * @tx_coalesce_adapt_on: Is TX interrupt moderation adaptive?
546 * @rx_coalesce_usecs: RX interrupt moderation usecs delay parameter
547 * @rx_coalesce_max_frames: RX interrupt moderation frame count parameter
548 * @tx_coalesce_usecs: TX interrupt moderation usecs delay parameter
549 * @tx_coalesce_max_frames: TX interrupt moderation frame count parameter
550 * @qcp_cfg: Pointer to QCP queue used for configuration notification
551 * @tx_bar: Pointer to mapped TX queues
552 * @rx_bar: Pointer to mapped FL/RX queues
553 * @tlv_caps: Parsed TLV capabilities
554 * @ktls_tx_conn_cnt: Number of offloaded kTLS TX connections
555 * @ktls_rx_conn_cnt: Number of offloaded kTLS RX connections
556 * @ktls_conn_id_gen: Trivial generator for kTLS connection ids (for TX)
557 * @ktls_no_space: Counter of firmware rejecting kTLS connection due to
559 * @ktls_rx_resync_req: Counter of TLS RX resync requested
560 * @ktls_rx_resync_ign: Counter of TLS RX resync requests ignored
561 * @ktls_rx_resync_sent: Counter of TLS RX resync completed
562 * @mbox_cmsg: Common Control Message via vNIC mailbox state
563 * @mbox_cmsg.queue: CCM mbox queue of pending messages
564 * @mbox_cmsg.wq: CCM mbox wait queue of waiting processes
565 * @mbox_cmsg.workq: CCM mbox work queue for @wait_work and @runq_work
566 * @mbox_cmsg.wait_work: CCM mbox posted msg reconfig wait work
567 * @mbox_cmsg.runq_work: CCM mbox posted msg queue runner work
568 * @mbox_cmsg.tag: CCM mbox message tag allocator
569 * @debugfs_dir: Device directory in debugfs
570 * @vnic_list: Entry on device vNIC list
571 * @pdev: Backpointer to PCI device
572 * @app: APP handle if available
573 * @vnic_no_name: For non-port PF vNIC make ndo_get_phys_port_name return
574 * -EOPNOTSUPP to keep backwards compatibility (set by app)
575 * @port: Pointer to nfp_port structure if vNIC is a port
576 * @app_priv: APP private data for this vNIC
579 struct nfp_net_dp dp;
581 const struct nfp_dev_info *dev_info;
582 struct nfp_net_fw_version fw_ver;
591 u8 rss_key[NFP_NET_CFG_RSS_KEY_SZ];
592 u8 rss_itbl[NFP_NET_CFG_RSS_ITBL_SZ];
594 struct xdp_attachment_info xdp;
595 struct xdp_attachment_info xdp_hw;
597 unsigned int max_tx_rings;
598 unsigned int max_rx_rings;
603 unsigned int max_r_vecs;
604 struct nfp_net_r_vector r_vecs[NFP_NET_MAX_R_VECS];
605 struct msix_entry irq_entries[NFP_NET_MAX_IRQS];
607 irq_handler_t lsc_handler;
608 char lsc_name[IFNAMSIZ + 8];
610 irq_handler_t exn_handler;
611 char exn_name[IFNAMSIZ + 8];
613 irq_handler_t shared_handler;
614 char shared_name[IFNAMSIZ + 8];
617 spinlock_t link_status_lock;
619 spinlock_t reconfig_lock;
621 bool reconfig_timer_active;
622 bool reconfig_sync_present;
623 struct timer_list reconfig_timer;
624 u32 reconfig_in_progress_update;
626 struct semaphore bar_lock;
628 bool rx_coalesce_adapt_on;
629 bool tx_coalesce_adapt_on;
630 u32 rx_coalesce_usecs;
631 u32 rx_coalesce_max_frames;
632 u32 tx_coalesce_usecs;
633 u32 tx_coalesce_max_frames;
640 struct nfp_net_tlv_caps tlv_caps;
642 unsigned int ktls_tx_conn_cnt;
643 unsigned int ktls_rx_conn_cnt;
645 atomic64_t ktls_conn_id_gen;
647 atomic_t ktls_no_space;
648 atomic_t ktls_rx_resync_req;
649 atomic_t ktls_rx_resync_ign;
650 atomic_t ktls_rx_resync_sent;
653 struct sk_buff_head queue;
654 wait_queue_head_t wq;
655 struct workqueue_struct *workq;
656 struct work_struct wait_work;
657 struct work_struct runq_work;
661 struct dentry *debugfs_dir;
663 struct list_head vnic_list;
665 struct pci_dev *pdev;
670 struct nfp_port *port;
675 /* Functions to read/write from/to a BAR
676 * Performs any endian conversion necessary.
678 static inline u16 nn_readb(struct nfp_net *nn, int off)
680 return readb(nn->dp.ctrl_bar + off);
683 static inline void nn_writeb(struct nfp_net *nn, int off, u8 val)
685 writeb(val, nn->dp.ctrl_bar + off);
688 static inline u16 nn_readw(struct nfp_net *nn, int off)
690 return readw(nn->dp.ctrl_bar + off);
693 static inline void nn_writew(struct nfp_net *nn, int off, u16 val)
695 writew(val, nn->dp.ctrl_bar + off);
698 static inline u32 nn_readl(struct nfp_net *nn, int off)
700 return readl(nn->dp.ctrl_bar + off);
703 static inline void nn_writel(struct nfp_net *nn, int off, u32 val)
705 writel(val, nn->dp.ctrl_bar + off);
708 static inline u64 nn_readq(struct nfp_net *nn, int off)
710 return readq(nn->dp.ctrl_bar + off);
713 static inline void nn_writeq(struct nfp_net *nn, int off, u64 val)
715 writeq(val, nn->dp.ctrl_bar + off);
718 /* Flush posted PCI writes by reading something without side effects */
719 static inline void nn_pci_flush(struct nfp_net *nn)
721 nn_readl(nn, NFP_NET_CFG_VERSION);
724 /* Queue Controller Peripheral access functions and definitions.
726 * Some of the BARs of the NFP are mapped to portions of the Queue
727 * Controller Peripheral (QCP) address space on the NFP. A QCP queue
728 * has a read and a write pointer (as well as a size and flags,
729 * indicating overflow etc). The QCP offers a number of different
730 * operation on queue pointers, but here we only offer function to
731 * either add to a pointer or to read the pointer value.
733 #define NFP_QCP_QUEUE_ADDR_SZ 0x800
734 #define NFP_QCP_QUEUE_OFF(_x) ((_x) * NFP_QCP_QUEUE_ADDR_SZ)
735 #define NFP_QCP_QUEUE_ADD_RPTR 0x0000
736 #define NFP_QCP_QUEUE_ADD_WPTR 0x0004
737 #define NFP_QCP_QUEUE_STS_LO 0x0008
738 #define NFP_QCP_QUEUE_STS_LO_READPTR_mask 0x3ffff
739 #define NFP_QCP_QUEUE_STS_HI 0x000c
740 #define NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask 0x3ffff
742 /* nfp_qcp_ptr - Read or Write Pointer of a queue */
744 NFP_QCP_READ_PTR = 0,
749 * nfp_qcp_rd_ptr_add() - Add the value to the read pointer of a queue
751 * @q: Base address for queue structure
752 * @val: Value to add to the queue pointer
754 static inline void nfp_qcp_rd_ptr_add(u8 __iomem *q, u32 val)
756 writel(val, q + NFP_QCP_QUEUE_ADD_RPTR);
760 * nfp_qcp_wr_ptr_add() - Add the value to the write pointer of a queue
762 * @q: Base address for queue structure
763 * @val: Value to add to the queue pointer
765 static inline void nfp_qcp_wr_ptr_add(u8 __iomem *q, u32 val)
767 writel(val, q + NFP_QCP_QUEUE_ADD_WPTR);
770 static inline u32 _nfp_qcp_read(u8 __iomem *q, enum nfp_qcp_ptr ptr)
775 if (ptr == NFP_QCP_READ_PTR)
776 off = NFP_QCP_QUEUE_STS_LO;
778 off = NFP_QCP_QUEUE_STS_HI;
780 val = readl(q + off);
782 if (ptr == NFP_QCP_READ_PTR)
783 return val & NFP_QCP_QUEUE_STS_LO_READPTR_mask;
785 return val & NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask;
789 * nfp_qcp_rd_ptr_read() - Read the current read pointer value for a queue
790 * @q: Base address for queue structure
792 * Return: Value read.
794 static inline u32 nfp_qcp_rd_ptr_read(u8 __iomem *q)
796 return _nfp_qcp_read(q, NFP_QCP_READ_PTR);
800 * nfp_qcp_wr_ptr_read() - Read the current write pointer value for a queue
801 * @q: Base address for queue structure
803 * Return: Value read.
805 static inline u32 nfp_qcp_wr_ptr_read(u8 __iomem *q)
807 return _nfp_qcp_read(q, NFP_QCP_WRITE_PTR);
810 u32 nfp_qcp_queue_offset(const struct nfp_dev_info *dev_info, u16 queue);
812 static inline bool nfp_net_is_data_vnic(struct nfp_net *nn)
814 WARN_ON_ONCE(!nn->dp.netdev && nn->port);
815 return !!nn->dp.netdev;
818 static inline bool nfp_net_running(struct nfp_net *nn)
820 return nn->dp.ctrl & NFP_NET_CFG_CTRL_ENABLE;
823 static inline const char *nfp_net_name(struct nfp_net *nn)
825 return nn->dp.netdev ? nn->dp.netdev->name : "ctrl";
828 static inline void nfp_ctrl_lock(struct nfp_net *nn)
829 __acquires(&nn->r_vecs[0].lock)
831 spin_lock_bh(&nn->r_vecs[0].lock);
834 static inline void nfp_ctrl_unlock(struct nfp_net *nn)
835 __releases(&nn->r_vecs[0].lock)
837 spin_unlock_bh(&nn->r_vecs[0].lock);
840 static inline void nn_ctrl_bar_lock(struct nfp_net *nn)
845 static inline bool nn_ctrl_bar_trylock(struct nfp_net *nn)
847 return !down_trylock(&nn->bar_lock);
850 static inline void nn_ctrl_bar_unlock(struct nfp_net *nn)
856 extern const char nfp_driver_version[];
858 extern const struct net_device_ops nfp_net_netdev_ops;
860 static inline bool nfp_netdev_is_nfp_net(struct net_device *netdev)
862 return netdev->netdev_ops == &nfp_net_netdev_ops;
865 static inline int nfp_net_coalesce_para_check(u32 usecs, u32 pkts)
867 if ((usecs >= ((1 << 16) - 1)) || (pkts >= ((1 << 16) - 1)))
874 void nfp_net_get_fw_version(struct nfp_net_fw_version *fw_ver,
875 void __iomem *ctrl_bar);
878 nfp_net_alloc(struct pci_dev *pdev, const struct nfp_dev_info *dev_info,
879 void __iomem *ctrl_bar, bool needs_netdev,
880 unsigned int max_tx_rings, unsigned int max_rx_rings);
881 void nfp_net_free(struct nfp_net *nn);
883 int nfp_net_init(struct nfp_net *nn);
884 void nfp_net_clean(struct nfp_net *nn);
886 int nfp_ctrl_open(struct nfp_net *nn);
887 void nfp_ctrl_close(struct nfp_net *nn);
889 void nfp_net_set_ethtool_ops(struct net_device *netdev);
890 void nfp_net_info(struct nfp_net *nn);
891 int __nfp_net_reconfig(struct nfp_net *nn, u32 update);
892 int nfp_net_reconfig(struct nfp_net *nn, u32 update);
893 unsigned int nfp_net_rss_key_sz(struct nfp_net *nn);
894 void nfp_net_rss_write_itbl(struct nfp_net *nn);
895 void nfp_net_rss_write_key(struct nfp_net *nn);
896 void nfp_net_coalesce_write_cfg(struct nfp_net *nn);
897 int nfp_net_mbox_lock(struct nfp_net *nn, unsigned int data_size);
898 int nfp_net_mbox_reconfig(struct nfp_net *nn, u32 mbox_cmd);
899 int nfp_net_mbox_reconfig_and_unlock(struct nfp_net *nn, u32 mbox_cmd);
900 void nfp_net_mbox_reconfig_post(struct nfp_net *nn, u32 update);
901 int nfp_net_mbox_reconfig_wait_posted(struct nfp_net *nn);
904 nfp_net_irqs_alloc(struct pci_dev *pdev, struct msix_entry *irq_entries,
905 unsigned int min_irqs, unsigned int want_irqs);
906 void nfp_net_irqs_disable(struct pci_dev *pdev);
908 nfp_net_irqs_assign(struct nfp_net *nn, struct msix_entry *irq_entries,
911 nfp_net_tls_tx(struct nfp_net_dp *dp, struct nfp_net_r_vector *r_vec,
912 struct sk_buff *skb, u64 *tls_handle, int *nr_frags);
913 void nfp_net_tls_tx_undo(struct sk_buff *skb, u64 tls_handle);
915 struct nfp_net_dp *nfp_net_clone_dp(struct nfp_net *nn);
916 int nfp_net_ring_reconfig(struct nfp_net *nn, struct nfp_net_dp *new,
917 struct netlink_ext_ack *extack);
919 #ifdef CONFIG_NFP_DEBUG
920 void nfp_net_debugfs_create(void);
921 void nfp_net_debugfs_destroy(void);
922 struct dentry *nfp_net_debugfs_device_add(struct pci_dev *pdev);
923 void nfp_net_debugfs_vnic_add(struct nfp_net *nn, struct dentry *ddir);
924 void nfp_net_debugfs_dir_clean(struct dentry **dir);
926 static inline void nfp_net_debugfs_create(void)
930 static inline void nfp_net_debugfs_destroy(void)
934 static inline struct dentry *nfp_net_debugfs_device_add(struct pci_dev *pdev)
940 nfp_net_debugfs_vnic_add(struct nfp_net *nn, struct dentry *ddir)
944 static inline void nfp_net_debugfs_dir_clean(struct dentry **dir)
947 #endif /* CONFIG_NFP_DEBUG */
949 #endif /* _NFP_NET_H_ */