162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/****************************************************************************
362306a36Sopenharmony_ci * Driver for Solarflare network controllers and boards
462306a36Sopenharmony_ci * Copyright 2005-2006 Fen Systems Ltd.
562306a36Sopenharmony_ci * Copyright 2005-2013 Solarflare Communications Inc.
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci/* Common definitions for all Efx net driver code */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifndef EFX_NET_DRIVER_H
1162306a36Sopenharmony_ci#define EFX_NET_DRIVER_H
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include <linux/netdevice.h>
1462306a36Sopenharmony_ci#include <linux/etherdevice.h>
1562306a36Sopenharmony_ci#include <linux/ethtool.h>
1662306a36Sopenharmony_ci#include <linux/if_vlan.h>
1762306a36Sopenharmony_ci#include <linux/timer.h>
1862306a36Sopenharmony_ci#include <linux/mdio.h>
1962306a36Sopenharmony_ci#include <linux/list.h>
2062306a36Sopenharmony_ci#include <linux/pci.h>
2162306a36Sopenharmony_ci#include <linux/device.h>
2262306a36Sopenharmony_ci#include <linux/highmem.h>
2362306a36Sopenharmony_ci#include <linux/workqueue.h>
2462306a36Sopenharmony_ci#include <linux/mutex.h>
2562306a36Sopenharmony_ci#include <linux/rwsem.h>
2662306a36Sopenharmony_ci#include <linux/vmalloc.h>
2762306a36Sopenharmony_ci#include <linux/mtd/mtd.h>
2862306a36Sopenharmony_ci#include <net/busy_poll.h>
2962306a36Sopenharmony_ci#include <net/xdp.h>
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#include "enum.h"
3262306a36Sopenharmony_ci#include "bitfield.h"
3362306a36Sopenharmony_ci#include "filter.h"
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci/**************************************************************************
3662306a36Sopenharmony_ci *
3762306a36Sopenharmony_ci * Build definitions
3862306a36Sopenharmony_ci *
3962306a36Sopenharmony_ci **************************************************************************/
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#ifdef DEBUG
4262306a36Sopenharmony_ci#define EFX_WARN_ON_ONCE_PARANOID(x) WARN_ON_ONCE(x)
4362306a36Sopenharmony_ci#define EFX_WARN_ON_PARANOID(x) WARN_ON(x)
4462306a36Sopenharmony_ci#else
4562306a36Sopenharmony_ci#define EFX_WARN_ON_ONCE_PARANOID(x) do {} while (0)
4662306a36Sopenharmony_ci#define EFX_WARN_ON_PARANOID(x) do {} while (0)
4762306a36Sopenharmony_ci#endif
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci/**************************************************************************
5062306a36Sopenharmony_ci *
5162306a36Sopenharmony_ci * Efx data structures
5262306a36Sopenharmony_ci *
5362306a36Sopenharmony_ci **************************************************************************/
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci#define EFX_MAX_CHANNELS 32U
5662306a36Sopenharmony_ci#define EFX_MAX_RX_QUEUES EFX_MAX_CHANNELS
5762306a36Sopenharmony_ci#define EFX_EXTRA_CHANNEL_IOV	0
5862306a36Sopenharmony_ci#define EFX_EXTRA_CHANNEL_PTP	1
5962306a36Sopenharmony_ci#define EFX_MAX_EXTRA_CHANNELS	2U
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci/* Checksum generation is a per-queue option in hardware, so each
6262306a36Sopenharmony_ci * queue visible to the networking core is backed by two hardware TX
6362306a36Sopenharmony_ci * queues. */
6462306a36Sopenharmony_ci#define EFX_MAX_TX_TC		2
6562306a36Sopenharmony_ci#define EFX_MAX_CORE_TX_QUEUES	(EFX_MAX_TX_TC * EFX_MAX_CHANNELS)
6662306a36Sopenharmony_ci#define EFX_TXQ_TYPE_OUTER_CSUM	1	/* Outer checksum offload */
6762306a36Sopenharmony_ci#define EFX_TXQ_TYPE_INNER_CSUM	2	/* Inner checksum offload */
6862306a36Sopenharmony_ci#define EFX_TXQ_TYPE_HIGHPRI	4	/* High-priority (for TC) */
6962306a36Sopenharmony_ci#define EFX_TXQ_TYPES		8
7062306a36Sopenharmony_ci/* HIGHPRI is Siena-only, and INNER_CSUM is EF10, so no need for both */
7162306a36Sopenharmony_ci#define EFX_MAX_TXQ_PER_CHANNEL	4
7262306a36Sopenharmony_ci#define EFX_MAX_TX_QUEUES	(EFX_MAX_TXQ_PER_CHANNEL * EFX_MAX_CHANNELS)
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci/* Maximum possible MTU the driver supports */
7562306a36Sopenharmony_ci#define EFX_MAX_MTU (9 * 1024)
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci/* Minimum MTU, from RFC791 (IP) */
7862306a36Sopenharmony_ci#define EFX_MIN_MTU 68
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci/* Maximum total header length for TSOv2 */
8162306a36Sopenharmony_ci#define EFX_TSO2_MAX_HDRLEN	208
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci/* Size of an RX scatter buffer.  Small enough to pack 2 into a 4K page,
8462306a36Sopenharmony_ci * and should be a multiple of the cache line size.
8562306a36Sopenharmony_ci */
8662306a36Sopenharmony_ci#define EFX_RX_USR_BUF_SIZE	(2048 - 256)
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci/* If possible, we should ensure cache line alignment at start and end
8962306a36Sopenharmony_ci * of every buffer.  Otherwise, we just need to ensure 4-byte
9062306a36Sopenharmony_ci * alignment of the network header.
9162306a36Sopenharmony_ci */
9262306a36Sopenharmony_ci#if NET_IP_ALIGN == 0
9362306a36Sopenharmony_ci#define EFX_RX_BUF_ALIGNMENT	L1_CACHE_BYTES
9462306a36Sopenharmony_ci#else
9562306a36Sopenharmony_ci#define EFX_RX_BUF_ALIGNMENT	4
9662306a36Sopenharmony_ci#endif
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci/* Non-standard XDP_PACKET_HEADROOM and tailroom to satisfy XDP_REDIRECT and
9962306a36Sopenharmony_ci * still fit two standard MTU size packets into a single 4K page.
10062306a36Sopenharmony_ci */
10162306a36Sopenharmony_ci#define EFX_XDP_HEADROOM	128
10262306a36Sopenharmony_ci#define EFX_XDP_TAILROOM	SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci/* Forward declare Precision Time Protocol (PTP) support structure. */
10562306a36Sopenharmony_cistruct efx_ptp_data;
10662306a36Sopenharmony_cistruct hwtstamp_config;
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_cistruct efx_self_tests;
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci/**
11162306a36Sopenharmony_ci * struct efx_buffer - A general-purpose DMA buffer
11262306a36Sopenharmony_ci * @addr: host base address of the buffer
11362306a36Sopenharmony_ci * @dma_addr: DMA base address of the buffer
11462306a36Sopenharmony_ci * @len: Buffer length, in bytes
11562306a36Sopenharmony_ci *
11662306a36Sopenharmony_ci * The NIC uses these buffers for its interrupt status registers and
11762306a36Sopenharmony_ci * MAC stats dumps.
11862306a36Sopenharmony_ci */
11962306a36Sopenharmony_cistruct efx_buffer {
12062306a36Sopenharmony_ci	void *addr;
12162306a36Sopenharmony_ci	dma_addr_t dma_addr;
12262306a36Sopenharmony_ci	unsigned int len;
12362306a36Sopenharmony_ci};
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci/**
12662306a36Sopenharmony_ci * struct efx_special_buffer - DMA buffer entered into buffer table
12762306a36Sopenharmony_ci * @buf: Standard &struct efx_buffer
12862306a36Sopenharmony_ci * @index: Buffer index within controller;s buffer table
12962306a36Sopenharmony_ci * @entries: Number of buffer table entries
13062306a36Sopenharmony_ci *
13162306a36Sopenharmony_ci * The NIC has a buffer table that maps buffers of size %EFX_BUF_SIZE.
13262306a36Sopenharmony_ci * Event and descriptor rings are addressed via one or more buffer
13362306a36Sopenharmony_ci * table entries (and so can be physically non-contiguous, although we
13462306a36Sopenharmony_ci * currently do not take advantage of that).  On Falcon and Siena we
13562306a36Sopenharmony_ci * have to take care of allocating and initialising the entries
13662306a36Sopenharmony_ci * ourselves.  On later hardware this is managed by the firmware and
13762306a36Sopenharmony_ci * @index and @entries are left as 0.
13862306a36Sopenharmony_ci */
13962306a36Sopenharmony_cistruct efx_special_buffer {
14062306a36Sopenharmony_ci	struct efx_buffer buf;
14162306a36Sopenharmony_ci	unsigned int index;
14262306a36Sopenharmony_ci	unsigned int entries;
14362306a36Sopenharmony_ci};
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci/**
14662306a36Sopenharmony_ci * struct efx_tx_buffer - buffer state for a TX descriptor
14762306a36Sopenharmony_ci * @skb: When @flags & %EFX_TX_BUF_SKB, the associated socket buffer to be
14862306a36Sopenharmony_ci *	freed when descriptor completes
14962306a36Sopenharmony_ci * @xdpf: When @flags & %EFX_TX_BUF_XDP, the XDP frame information; its @data
15062306a36Sopenharmony_ci *	member is the associated buffer to drop a page reference on.
15162306a36Sopenharmony_ci * @option: When @flags & %EFX_TX_BUF_OPTION, an EF10-specific option
15262306a36Sopenharmony_ci *	descriptor.
15362306a36Sopenharmony_ci * @dma_addr: DMA address of the fragment.
15462306a36Sopenharmony_ci * @flags: Flags for allocation and DMA mapping type
15562306a36Sopenharmony_ci * @len: Length of this fragment.
15662306a36Sopenharmony_ci *	This field is zero when the queue slot is empty.
15762306a36Sopenharmony_ci * @unmap_len: Length of this fragment to unmap
15862306a36Sopenharmony_ci * @dma_offset: Offset of @dma_addr from the address of the backing DMA mapping.
15962306a36Sopenharmony_ci * Only valid if @unmap_len != 0.
16062306a36Sopenharmony_ci */
16162306a36Sopenharmony_cistruct efx_tx_buffer {
16262306a36Sopenharmony_ci	union {
16362306a36Sopenharmony_ci		const struct sk_buff *skb;
16462306a36Sopenharmony_ci		struct xdp_frame *xdpf;
16562306a36Sopenharmony_ci	};
16662306a36Sopenharmony_ci	union {
16762306a36Sopenharmony_ci		efx_qword_t option;    /* EF10 */
16862306a36Sopenharmony_ci		dma_addr_t dma_addr;
16962306a36Sopenharmony_ci	};
17062306a36Sopenharmony_ci	unsigned short flags;
17162306a36Sopenharmony_ci	unsigned short len;
17262306a36Sopenharmony_ci	unsigned short unmap_len;
17362306a36Sopenharmony_ci	unsigned short dma_offset;
17462306a36Sopenharmony_ci};
17562306a36Sopenharmony_ci#define EFX_TX_BUF_CONT		1	/* not last descriptor of packet */
17662306a36Sopenharmony_ci#define EFX_TX_BUF_SKB		2	/* buffer is last part of skb */
17762306a36Sopenharmony_ci#define EFX_TX_BUF_MAP_SINGLE	8	/* buffer was mapped with dma_map_single() */
17862306a36Sopenharmony_ci#define EFX_TX_BUF_OPTION	0x10	/* empty buffer for option descriptor */
17962306a36Sopenharmony_ci#define EFX_TX_BUF_XDP		0x20	/* buffer was sent with XDP */
18062306a36Sopenharmony_ci#define EFX_TX_BUF_TSO_V3	0x40	/* empty buffer for a TSO_V3 descriptor */
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_ci/**
18362306a36Sopenharmony_ci * struct efx_tx_queue - An Efx TX queue
18462306a36Sopenharmony_ci *
18562306a36Sopenharmony_ci * This is a ring buffer of TX fragments.
18662306a36Sopenharmony_ci * Since the TX completion path always executes on the same
18762306a36Sopenharmony_ci * CPU and the xmit path can operate on different CPUs,
18862306a36Sopenharmony_ci * performance is increased by ensuring that the completion
18962306a36Sopenharmony_ci * path and the xmit path operate on different cache lines.
19062306a36Sopenharmony_ci * This is particularly important if the xmit path is always
19162306a36Sopenharmony_ci * executing on one CPU which is different from the completion
19262306a36Sopenharmony_ci * path.  There is also a cache line for members which are
19362306a36Sopenharmony_ci * read but not written on the fast path.
19462306a36Sopenharmony_ci *
19562306a36Sopenharmony_ci * @efx: The associated Efx NIC
19662306a36Sopenharmony_ci * @queue: DMA queue number
19762306a36Sopenharmony_ci * @label: Label for TX completion events.
19862306a36Sopenharmony_ci *	Is our index within @channel->tx_queue array.
19962306a36Sopenharmony_ci * @type: configuration type of this TX queue.  A bitmask of %EFX_TXQ_TYPE_* flags.
20062306a36Sopenharmony_ci * @tso_version: Version of TSO in use for this queue.
20162306a36Sopenharmony_ci * @tso_encap: Is encapsulated TSO supported? Supported in TSOv2 on 8000 series.
20262306a36Sopenharmony_ci * @channel: The associated channel
20362306a36Sopenharmony_ci * @core_txq: The networking core TX queue structure
20462306a36Sopenharmony_ci * @buffer: The software buffer ring
20562306a36Sopenharmony_ci * @cb_page: Array of pages of copy buffers.  Carved up according to
20662306a36Sopenharmony_ci *	%EFX_TX_CB_ORDER into %EFX_TX_CB_SIZE-sized chunks.
20762306a36Sopenharmony_ci * @txd: The hardware descriptor ring
20862306a36Sopenharmony_ci * @ptr_mask: The size of the ring minus 1.
20962306a36Sopenharmony_ci * @piobuf: PIO buffer region for this TX queue (shared with its partner).
21062306a36Sopenharmony_ci * @piobuf_offset: Buffer offset to be specified in PIO descriptors
21162306a36Sopenharmony_ci * @initialised: Has hardware queue been initialised?
21262306a36Sopenharmony_ci * @timestamping: Is timestamping enabled for this channel?
21362306a36Sopenharmony_ci * @xdp_tx: Is this an XDP tx queue?
21462306a36Sopenharmony_ci * @read_count: Current read pointer.
21562306a36Sopenharmony_ci *	This is the number of buffers that have been removed from both rings.
21662306a36Sopenharmony_ci * @old_write_count: The value of @write_count when last checked.
21762306a36Sopenharmony_ci *	This is here for performance reasons.  The xmit path will
21862306a36Sopenharmony_ci *	only get the up-to-date value of @write_count if this
21962306a36Sopenharmony_ci *	variable indicates that the queue is empty.  This is to
22062306a36Sopenharmony_ci *	avoid cache-line ping-pong between the xmit path and the
22162306a36Sopenharmony_ci *	completion path.
22262306a36Sopenharmony_ci * @merge_events: Number of TX merged completion events
22362306a36Sopenharmony_ci * @completed_timestamp_major: Top part of the most recent tx timestamp.
22462306a36Sopenharmony_ci * @completed_timestamp_minor: Low part of the most recent tx timestamp.
22562306a36Sopenharmony_ci * @insert_count: Current insert pointer
22662306a36Sopenharmony_ci *	This is the number of buffers that have been added to the
22762306a36Sopenharmony_ci *	software ring.
22862306a36Sopenharmony_ci * @write_count: Current write pointer
22962306a36Sopenharmony_ci *	This is the number of buffers that have been added to the
23062306a36Sopenharmony_ci *	hardware ring.
23162306a36Sopenharmony_ci * @packet_write_count: Completable write pointer
23262306a36Sopenharmony_ci *	This is the write pointer of the last packet written.
23362306a36Sopenharmony_ci *	Normally this will equal @write_count, but as option descriptors
23462306a36Sopenharmony_ci *	don't produce completion events, they won't update this.
23562306a36Sopenharmony_ci *	Filled in iff @efx->type->option_descriptors; only used for PIO.
23662306a36Sopenharmony_ci *	Thus, this is written and used on EF10, and neither on farch.
23762306a36Sopenharmony_ci * @old_read_count: The value of read_count when last checked.
23862306a36Sopenharmony_ci *	This is here for performance reasons.  The xmit path will
23962306a36Sopenharmony_ci *	only get the up-to-date value of read_count if this
24062306a36Sopenharmony_ci *	variable indicates that the queue is full.  This is to
24162306a36Sopenharmony_ci *	avoid cache-line ping-pong between the xmit path and the
24262306a36Sopenharmony_ci *	completion path.
24362306a36Sopenharmony_ci * @tso_bursts: Number of times TSO xmit invoked by kernel
24462306a36Sopenharmony_ci * @tso_long_headers: Number of packets with headers too long for standard
24562306a36Sopenharmony_ci *	blocks
24662306a36Sopenharmony_ci * @tso_packets: Number of packets via the TSO xmit path
24762306a36Sopenharmony_ci * @tso_fallbacks: Number of times TSO fallback used
24862306a36Sopenharmony_ci * @pushes: Number of times the TX push feature has been used
24962306a36Sopenharmony_ci * @pio_packets: Number of times the TX PIO feature has been used
25062306a36Sopenharmony_ci * @xmit_pending: Are any packets waiting to be pushed to the NIC
25162306a36Sopenharmony_ci * @cb_packets: Number of times the TX copybreak feature has been used
25262306a36Sopenharmony_ci * @notify_count: Count of notified descriptors to the NIC
25362306a36Sopenharmony_ci * @empty_read_count: If the completion path has seen the queue as empty
25462306a36Sopenharmony_ci *	and the transmission path has not yet checked this, the value of
25562306a36Sopenharmony_ci *	@read_count bitwise-added to %EFX_EMPTY_COUNT_VALID; otherwise 0.
25662306a36Sopenharmony_ci */
25762306a36Sopenharmony_cistruct efx_tx_queue {
25862306a36Sopenharmony_ci	/* Members which don't change on the fast path */
25962306a36Sopenharmony_ci	struct efx_nic *efx ____cacheline_aligned_in_smp;
26062306a36Sopenharmony_ci	unsigned int queue;
26162306a36Sopenharmony_ci	unsigned int label;
26262306a36Sopenharmony_ci	unsigned int type;
26362306a36Sopenharmony_ci	unsigned int tso_version;
26462306a36Sopenharmony_ci	bool tso_encap;
26562306a36Sopenharmony_ci	struct efx_channel *channel;
26662306a36Sopenharmony_ci	struct netdev_queue *core_txq;
26762306a36Sopenharmony_ci	struct efx_tx_buffer *buffer;
26862306a36Sopenharmony_ci	struct efx_buffer *cb_page;
26962306a36Sopenharmony_ci	struct efx_special_buffer txd;
27062306a36Sopenharmony_ci	unsigned int ptr_mask;
27162306a36Sopenharmony_ci	void __iomem *piobuf;
27262306a36Sopenharmony_ci	unsigned int piobuf_offset;
27362306a36Sopenharmony_ci	bool initialised;
27462306a36Sopenharmony_ci	bool timestamping;
27562306a36Sopenharmony_ci	bool xdp_tx;
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_ci	/* Members used mainly on the completion path */
27862306a36Sopenharmony_ci	unsigned int read_count ____cacheline_aligned_in_smp;
27962306a36Sopenharmony_ci	unsigned int old_write_count;
28062306a36Sopenharmony_ci	unsigned int merge_events;
28162306a36Sopenharmony_ci	unsigned int bytes_compl;
28262306a36Sopenharmony_ci	unsigned int pkts_compl;
28362306a36Sopenharmony_ci	u32 completed_timestamp_major;
28462306a36Sopenharmony_ci	u32 completed_timestamp_minor;
28562306a36Sopenharmony_ci
28662306a36Sopenharmony_ci	/* Members used only on the xmit path */
28762306a36Sopenharmony_ci	unsigned int insert_count ____cacheline_aligned_in_smp;
28862306a36Sopenharmony_ci	unsigned int write_count;
28962306a36Sopenharmony_ci	unsigned int packet_write_count;
29062306a36Sopenharmony_ci	unsigned int old_read_count;
29162306a36Sopenharmony_ci	unsigned int tso_bursts;
29262306a36Sopenharmony_ci	unsigned int tso_long_headers;
29362306a36Sopenharmony_ci	unsigned int tso_packets;
29462306a36Sopenharmony_ci	unsigned int tso_fallbacks;
29562306a36Sopenharmony_ci	unsigned int pushes;
29662306a36Sopenharmony_ci	unsigned int pio_packets;
29762306a36Sopenharmony_ci	bool xmit_pending;
29862306a36Sopenharmony_ci	unsigned int cb_packets;
29962306a36Sopenharmony_ci	unsigned int notify_count;
30062306a36Sopenharmony_ci	/* Statistics to supplement MAC stats */
30162306a36Sopenharmony_ci	unsigned long tx_packets;
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_ci	/* Members shared between paths and sometimes updated */
30462306a36Sopenharmony_ci	unsigned int empty_read_count ____cacheline_aligned_in_smp;
30562306a36Sopenharmony_ci#define EFX_EMPTY_COUNT_VALID 0x80000000
30662306a36Sopenharmony_ci	atomic_t flush_outstanding;
30762306a36Sopenharmony_ci};
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_ci#define EFX_TX_CB_ORDER	7
31062306a36Sopenharmony_ci#define EFX_TX_CB_SIZE	(1 << EFX_TX_CB_ORDER) - NET_IP_ALIGN
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_ci/**
31362306a36Sopenharmony_ci * struct efx_rx_buffer - An Efx RX data buffer
31462306a36Sopenharmony_ci * @dma_addr: DMA base address of the buffer
31562306a36Sopenharmony_ci * @page: The associated page buffer.
31662306a36Sopenharmony_ci *	Will be %NULL if the buffer slot is currently free.
31762306a36Sopenharmony_ci * @page_offset: If pending: offset in @page of DMA base address.
31862306a36Sopenharmony_ci *	If completed: offset in @page of Ethernet header.
31962306a36Sopenharmony_ci * @len: If pending: length for DMA descriptor.
32062306a36Sopenharmony_ci *	If completed: received length, excluding hash prefix.
32162306a36Sopenharmony_ci * @flags: Flags for buffer and packet state.  These are only set on the
32262306a36Sopenharmony_ci *	first buffer of a scattered packet.
32362306a36Sopenharmony_ci */
32462306a36Sopenharmony_cistruct efx_rx_buffer {
32562306a36Sopenharmony_ci	dma_addr_t dma_addr;
32662306a36Sopenharmony_ci	struct page *page;
32762306a36Sopenharmony_ci	u16 page_offset;
32862306a36Sopenharmony_ci	u16 len;
32962306a36Sopenharmony_ci	u16 flags;
33062306a36Sopenharmony_ci};
33162306a36Sopenharmony_ci#define EFX_RX_BUF_LAST_IN_PAGE	0x0001
33262306a36Sopenharmony_ci#define EFX_RX_PKT_CSUMMED	0x0002
33362306a36Sopenharmony_ci#define EFX_RX_PKT_DISCARD	0x0004
33462306a36Sopenharmony_ci#define EFX_RX_PKT_TCP		0x0040
33562306a36Sopenharmony_ci#define EFX_RX_PKT_PREFIX_LEN	0x0080	/* length is in prefix only */
33662306a36Sopenharmony_ci#define EFX_RX_PKT_CSUM_LEVEL	0x0200
33762306a36Sopenharmony_ci
33862306a36Sopenharmony_ci/**
33962306a36Sopenharmony_ci * struct efx_rx_page_state - Page-based rx buffer state
34062306a36Sopenharmony_ci *
34162306a36Sopenharmony_ci * Inserted at the start of every page allocated for receive buffers.
34262306a36Sopenharmony_ci * Used to facilitate sharing dma mappings between recycled rx buffers
34362306a36Sopenharmony_ci * and those passed up to the kernel.
34462306a36Sopenharmony_ci *
34562306a36Sopenharmony_ci * @dma_addr: The dma address of this page.
34662306a36Sopenharmony_ci */
34762306a36Sopenharmony_cistruct efx_rx_page_state {
34862306a36Sopenharmony_ci	dma_addr_t dma_addr;
34962306a36Sopenharmony_ci
35062306a36Sopenharmony_ci	unsigned int __pad[] ____cacheline_aligned;
35162306a36Sopenharmony_ci};
35262306a36Sopenharmony_ci
35362306a36Sopenharmony_ci/**
35462306a36Sopenharmony_ci * struct efx_rx_queue - An Efx RX queue
35562306a36Sopenharmony_ci * @efx: The associated Efx NIC
35662306a36Sopenharmony_ci * @core_index:  Index of network core RX queue.  Will be >= 0 iff this
35762306a36Sopenharmony_ci *	is associated with a real RX queue.
35862306a36Sopenharmony_ci * @buffer: The software buffer ring
35962306a36Sopenharmony_ci * @rxd: The hardware descriptor ring
36062306a36Sopenharmony_ci * @ptr_mask: The size of the ring minus 1.
36162306a36Sopenharmony_ci * @refill_enabled: Enable refill whenever fill level is low
36262306a36Sopenharmony_ci * @flush_pending: Set when a RX flush is pending. Has the same lifetime as
36362306a36Sopenharmony_ci *	@rxq_flush_pending.
36462306a36Sopenharmony_ci * @added_count: Number of buffers added to the receive queue.
36562306a36Sopenharmony_ci * @notified_count: Number of buffers given to NIC (<= @added_count).
36662306a36Sopenharmony_ci * @removed_count: Number of buffers removed from the receive queue.
36762306a36Sopenharmony_ci * @scatter_n: Used by NIC specific receive code.
36862306a36Sopenharmony_ci * @scatter_len: Used by NIC specific receive code.
36962306a36Sopenharmony_ci * @page_ring: The ring to store DMA mapped pages for reuse.
37062306a36Sopenharmony_ci * @page_add: Counter to calculate the write pointer for the recycle ring.
37162306a36Sopenharmony_ci * @page_remove: Counter to calculate the read pointer for the recycle ring.
37262306a36Sopenharmony_ci * @page_recycle_count: The number of pages that have been recycled.
37362306a36Sopenharmony_ci * @page_recycle_failed: The number of pages that couldn't be recycled because
37462306a36Sopenharmony_ci *      the kernel still held a reference to them.
37562306a36Sopenharmony_ci * @page_recycle_full: The number of pages that were released because the
37662306a36Sopenharmony_ci *      recycle ring was full.
37762306a36Sopenharmony_ci * @page_ptr_mask: The number of pages in the RX recycle ring minus 1.
37862306a36Sopenharmony_ci * @max_fill: RX descriptor maximum fill level (<= ring size)
37962306a36Sopenharmony_ci * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
38062306a36Sopenharmony_ci *	(<= @max_fill)
38162306a36Sopenharmony_ci * @min_fill: RX descriptor minimum non-zero fill level.
38262306a36Sopenharmony_ci *	This records the minimum fill level observed when a ring
38362306a36Sopenharmony_ci *	refill was triggered.
38462306a36Sopenharmony_ci * @recycle_count: RX buffer recycle counter.
38562306a36Sopenharmony_ci * @slow_fill: Timer used to defer efx_nic_generate_fill_event().
38662306a36Sopenharmony_ci * @xdp_rxq_info: XDP specific RX queue information.
38762306a36Sopenharmony_ci * @xdp_rxq_info_valid: Is xdp_rxq_info valid data?.
38862306a36Sopenharmony_ci */
38962306a36Sopenharmony_cistruct efx_rx_queue {
39062306a36Sopenharmony_ci	struct efx_nic *efx;
39162306a36Sopenharmony_ci	int core_index;
39262306a36Sopenharmony_ci	struct efx_rx_buffer *buffer;
39362306a36Sopenharmony_ci	struct efx_special_buffer rxd;
39462306a36Sopenharmony_ci	unsigned int ptr_mask;
39562306a36Sopenharmony_ci	bool refill_enabled;
39662306a36Sopenharmony_ci	bool flush_pending;
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_ci	unsigned int added_count;
39962306a36Sopenharmony_ci	unsigned int notified_count;
40062306a36Sopenharmony_ci	unsigned int removed_count;
40162306a36Sopenharmony_ci	unsigned int scatter_n;
40262306a36Sopenharmony_ci	unsigned int scatter_len;
40362306a36Sopenharmony_ci	struct page **page_ring;
40462306a36Sopenharmony_ci	unsigned int page_add;
40562306a36Sopenharmony_ci	unsigned int page_remove;
40662306a36Sopenharmony_ci	unsigned int page_recycle_count;
40762306a36Sopenharmony_ci	unsigned int page_recycle_failed;
40862306a36Sopenharmony_ci	unsigned int page_recycle_full;
40962306a36Sopenharmony_ci	unsigned int page_ptr_mask;
41062306a36Sopenharmony_ci	unsigned int max_fill;
41162306a36Sopenharmony_ci	unsigned int fast_fill_trigger;
41262306a36Sopenharmony_ci	unsigned int min_fill;
41362306a36Sopenharmony_ci	unsigned int min_overfill;
41462306a36Sopenharmony_ci	unsigned int recycle_count;
41562306a36Sopenharmony_ci	struct timer_list slow_fill;
41662306a36Sopenharmony_ci	unsigned int slow_fill_count;
41762306a36Sopenharmony_ci	/* Statistics to supplement MAC stats */
41862306a36Sopenharmony_ci	unsigned long rx_packets;
41962306a36Sopenharmony_ci	struct xdp_rxq_info xdp_rxq_info;
42062306a36Sopenharmony_ci	bool xdp_rxq_info_valid;
42162306a36Sopenharmony_ci};
42262306a36Sopenharmony_ci
42362306a36Sopenharmony_cienum efx_sync_events_state {
42462306a36Sopenharmony_ci	SYNC_EVENTS_DISABLED = 0,
42562306a36Sopenharmony_ci	SYNC_EVENTS_QUIESCENT,
42662306a36Sopenharmony_ci	SYNC_EVENTS_REQUESTED,
42762306a36Sopenharmony_ci	SYNC_EVENTS_VALID,
42862306a36Sopenharmony_ci};
42962306a36Sopenharmony_ci
43062306a36Sopenharmony_ci/**
43162306a36Sopenharmony_ci * struct efx_channel - An Efx channel
43262306a36Sopenharmony_ci *
43362306a36Sopenharmony_ci * A channel comprises an event queue, at least one TX queue, at least
43462306a36Sopenharmony_ci * one RX queue, and an associated tasklet for processing the event
43562306a36Sopenharmony_ci * queue.
43662306a36Sopenharmony_ci *
43762306a36Sopenharmony_ci * @efx: Associated Efx NIC
43862306a36Sopenharmony_ci * @channel: Channel instance number
43962306a36Sopenharmony_ci * @type: Channel type definition
44062306a36Sopenharmony_ci * @eventq_init: Event queue initialised flag
44162306a36Sopenharmony_ci * @enabled: Channel enabled indicator
44262306a36Sopenharmony_ci * @irq: IRQ number (MSI and MSI-X only)
44362306a36Sopenharmony_ci * @irq_moderation_us: IRQ moderation value (in microseconds)
44462306a36Sopenharmony_ci * @napi_dev: Net device used with NAPI
44562306a36Sopenharmony_ci * @napi_str: NAPI control structure
44662306a36Sopenharmony_ci * @state: state for NAPI vs busy polling
44762306a36Sopenharmony_ci * @state_lock: lock protecting @state
44862306a36Sopenharmony_ci * @eventq: Event queue buffer
44962306a36Sopenharmony_ci * @eventq_mask: Event queue pointer mask
45062306a36Sopenharmony_ci * @eventq_read_ptr: Event queue read pointer
45162306a36Sopenharmony_ci * @event_test_cpu: Last CPU to handle interrupt or test event for this channel
45262306a36Sopenharmony_ci * @irq_count: Number of IRQs since last adaptive moderation decision
45362306a36Sopenharmony_ci * @irq_mod_score: IRQ moderation score
45462306a36Sopenharmony_ci * @rfs_filter_count: number of accelerated RFS filters currently in place;
45562306a36Sopenharmony_ci *	equals the count of @rps_flow_id slots filled
45662306a36Sopenharmony_ci * @rfs_last_expiry: value of jiffies last time some accelerated RFS filters
45762306a36Sopenharmony_ci *	were checked for expiry
45862306a36Sopenharmony_ci * @rfs_expire_index: next accelerated RFS filter ID to check for expiry
45962306a36Sopenharmony_ci * @n_rfs_succeeded: number of successful accelerated RFS filter insertions
46062306a36Sopenharmony_ci * @n_rfs_failed: number of failed accelerated RFS filter insertions
46162306a36Sopenharmony_ci * @filter_work: Work item for efx_filter_rfs_expire()
46262306a36Sopenharmony_ci * @rps_flow_id: Flow IDs of filters allocated for accelerated RFS,
46362306a36Sopenharmony_ci *      indexed by filter ID
46462306a36Sopenharmony_ci * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
46562306a36Sopenharmony_ci * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
46662306a36Sopenharmony_ci * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
46762306a36Sopenharmony_ci * @n_rx_mcast_mismatch: Count of unmatched multicast frames
46862306a36Sopenharmony_ci * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
46962306a36Sopenharmony_ci * @n_rx_overlength: Count of RX_OVERLENGTH errors
47062306a36Sopenharmony_ci * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
47162306a36Sopenharmony_ci * @n_rx_nodesc_trunc: Number of RX packets truncated and then dropped due to
47262306a36Sopenharmony_ci *	lack of descriptors
47362306a36Sopenharmony_ci * @n_rx_merge_events: Number of RX merged completion events
47462306a36Sopenharmony_ci * @n_rx_merge_packets: Number of RX packets completed by merged events
47562306a36Sopenharmony_ci * @n_rx_xdp_drops: Count of RX packets intentionally dropped due to XDP
47662306a36Sopenharmony_ci * @n_rx_xdp_bad_drops: Count of RX packets dropped due to XDP errors
47762306a36Sopenharmony_ci * @n_rx_xdp_tx: Count of RX packets retransmitted due to XDP
47862306a36Sopenharmony_ci * @n_rx_xdp_redirect: Count of RX packets redirected to a different NIC by XDP
47962306a36Sopenharmony_ci * @rx_pkt_n_frags: Number of fragments in next packet to be delivered by
48062306a36Sopenharmony_ci *	__efx_siena_rx_packet(), or zero if there is none
48162306a36Sopenharmony_ci * @rx_pkt_index: Ring index of first buffer for next packet to be delivered
48262306a36Sopenharmony_ci *	by __efx_siena_rx_packet(), if @rx_pkt_n_frags != 0
48362306a36Sopenharmony_ci * @rx_list: list of SKBs from current RX, awaiting processing
48462306a36Sopenharmony_ci * @rx_queue: RX queue for this channel
48562306a36Sopenharmony_ci * @tx_queue: TX queues for this channel
48662306a36Sopenharmony_ci * @tx_queue_by_type: pointers into @tx_queue, or %NULL, indexed by txq type
48762306a36Sopenharmony_ci * @sync_events_state: Current state of sync events on this channel
48862306a36Sopenharmony_ci * @sync_timestamp_major: Major part of the last ptp sync event
48962306a36Sopenharmony_ci * @sync_timestamp_minor: Minor part of the last ptp sync event
49062306a36Sopenharmony_ci */
49162306a36Sopenharmony_cistruct efx_channel {
49262306a36Sopenharmony_ci	struct efx_nic *efx;
49362306a36Sopenharmony_ci	int channel;
49462306a36Sopenharmony_ci	const struct efx_channel_type *type;
49562306a36Sopenharmony_ci	bool eventq_init;
49662306a36Sopenharmony_ci	bool enabled;
49762306a36Sopenharmony_ci	int irq;
49862306a36Sopenharmony_ci	unsigned int irq_moderation_us;
49962306a36Sopenharmony_ci	struct net_device *napi_dev;
50062306a36Sopenharmony_ci	struct napi_struct napi_str;
50162306a36Sopenharmony_ci#ifdef CONFIG_NET_RX_BUSY_POLL
50262306a36Sopenharmony_ci	unsigned long busy_poll_state;
50362306a36Sopenharmony_ci#endif
50462306a36Sopenharmony_ci	struct efx_special_buffer eventq;
50562306a36Sopenharmony_ci	unsigned int eventq_mask;
50662306a36Sopenharmony_ci	unsigned int eventq_read_ptr;
50762306a36Sopenharmony_ci	int event_test_cpu;
50862306a36Sopenharmony_ci
50962306a36Sopenharmony_ci	unsigned int irq_count;
51062306a36Sopenharmony_ci	unsigned int irq_mod_score;
51162306a36Sopenharmony_ci#ifdef CONFIG_RFS_ACCEL
51262306a36Sopenharmony_ci	unsigned int rfs_filter_count;
51362306a36Sopenharmony_ci	unsigned int rfs_last_expiry;
51462306a36Sopenharmony_ci	unsigned int rfs_expire_index;
51562306a36Sopenharmony_ci	unsigned int n_rfs_succeeded;
51662306a36Sopenharmony_ci	unsigned int n_rfs_failed;
51762306a36Sopenharmony_ci	struct delayed_work filter_work;
51862306a36Sopenharmony_ci#define RPS_FLOW_ID_INVALID 0xFFFFFFFF
51962306a36Sopenharmony_ci	u32 *rps_flow_id;
52062306a36Sopenharmony_ci#endif
52162306a36Sopenharmony_ci
52262306a36Sopenharmony_ci	unsigned int n_rx_tobe_disc;
52362306a36Sopenharmony_ci	unsigned int n_rx_ip_hdr_chksum_err;
52462306a36Sopenharmony_ci	unsigned int n_rx_tcp_udp_chksum_err;
52562306a36Sopenharmony_ci	unsigned int n_rx_outer_ip_hdr_chksum_err;
52662306a36Sopenharmony_ci	unsigned int n_rx_outer_tcp_udp_chksum_err;
52762306a36Sopenharmony_ci	unsigned int n_rx_inner_ip_hdr_chksum_err;
52862306a36Sopenharmony_ci	unsigned int n_rx_inner_tcp_udp_chksum_err;
52962306a36Sopenharmony_ci	unsigned int n_rx_eth_crc_err;
53062306a36Sopenharmony_ci	unsigned int n_rx_mcast_mismatch;
53162306a36Sopenharmony_ci	unsigned int n_rx_frm_trunc;
53262306a36Sopenharmony_ci	unsigned int n_rx_overlength;
53362306a36Sopenharmony_ci	unsigned int n_skbuff_leaks;
53462306a36Sopenharmony_ci	unsigned int n_rx_nodesc_trunc;
53562306a36Sopenharmony_ci	unsigned int n_rx_merge_events;
53662306a36Sopenharmony_ci	unsigned int n_rx_merge_packets;
53762306a36Sopenharmony_ci	unsigned int n_rx_xdp_drops;
53862306a36Sopenharmony_ci	unsigned int n_rx_xdp_bad_drops;
53962306a36Sopenharmony_ci	unsigned int n_rx_xdp_tx;
54062306a36Sopenharmony_ci	unsigned int n_rx_xdp_redirect;
54162306a36Sopenharmony_ci
54262306a36Sopenharmony_ci	unsigned int rx_pkt_n_frags;
54362306a36Sopenharmony_ci	unsigned int rx_pkt_index;
54462306a36Sopenharmony_ci
54562306a36Sopenharmony_ci	struct list_head *rx_list;
54662306a36Sopenharmony_ci
54762306a36Sopenharmony_ci	struct efx_rx_queue rx_queue;
54862306a36Sopenharmony_ci	struct efx_tx_queue tx_queue[EFX_MAX_TXQ_PER_CHANNEL];
54962306a36Sopenharmony_ci	struct efx_tx_queue *tx_queue_by_type[EFX_TXQ_TYPES];
55062306a36Sopenharmony_ci
55162306a36Sopenharmony_ci	enum efx_sync_events_state sync_events_state;
55262306a36Sopenharmony_ci	u32 sync_timestamp_major;
55362306a36Sopenharmony_ci	u32 sync_timestamp_minor;
55462306a36Sopenharmony_ci};
55562306a36Sopenharmony_ci
55662306a36Sopenharmony_ci/**
55762306a36Sopenharmony_ci * struct efx_msi_context - Context for each MSI
55862306a36Sopenharmony_ci * @efx: The associated NIC
55962306a36Sopenharmony_ci * @index: Index of the channel/IRQ
56062306a36Sopenharmony_ci * @name: Name of the channel/IRQ
56162306a36Sopenharmony_ci *
56262306a36Sopenharmony_ci * Unlike &struct efx_channel, this is never reallocated and is always
56362306a36Sopenharmony_ci * safe for the IRQ handler to access.
56462306a36Sopenharmony_ci */
56562306a36Sopenharmony_cistruct efx_msi_context {
56662306a36Sopenharmony_ci	struct efx_nic *efx;
56762306a36Sopenharmony_ci	unsigned int index;
56862306a36Sopenharmony_ci	char name[IFNAMSIZ + 6];
56962306a36Sopenharmony_ci};
57062306a36Sopenharmony_ci
57162306a36Sopenharmony_ci/**
57262306a36Sopenharmony_ci * struct efx_channel_type - distinguishes traffic and extra channels
57362306a36Sopenharmony_ci * @handle_no_channel: Handle failure to allocate an extra channel
57462306a36Sopenharmony_ci * @pre_probe: Set up extra state prior to initialisation
57562306a36Sopenharmony_ci * @post_remove: Tear down extra state after finalisation, if allocated.
57662306a36Sopenharmony_ci *	May be called on channels that have not been probed.
57762306a36Sopenharmony_ci * @get_name: Generate the channel's name (used for its IRQ handler)
57862306a36Sopenharmony_ci * @copy: Copy the channel state prior to reallocation.  May be %NULL if
57962306a36Sopenharmony_ci *	reallocation is not supported.
58062306a36Sopenharmony_ci * @receive_skb: Handle an skb ready to be passed to netif_receive_skb()
58162306a36Sopenharmony_ci * @want_txqs: Determine whether this channel should have TX queues
58262306a36Sopenharmony_ci *	created.  If %NULL, TX queues are not created.
58362306a36Sopenharmony_ci * @keep_eventq: Flag for whether event queue should be kept initialised
58462306a36Sopenharmony_ci *	while the device is stopped
58562306a36Sopenharmony_ci * @want_pio: Flag for whether PIO buffers should be linked to this
58662306a36Sopenharmony_ci *	channel's TX queues.
58762306a36Sopenharmony_ci */
58862306a36Sopenharmony_cistruct efx_channel_type {
58962306a36Sopenharmony_ci	void (*handle_no_channel)(struct efx_nic *);
59062306a36Sopenharmony_ci	int (*pre_probe)(struct efx_channel *);
59162306a36Sopenharmony_ci	void (*post_remove)(struct efx_channel *);
59262306a36Sopenharmony_ci	void (*get_name)(struct efx_channel *, char *buf, size_t len);
59362306a36Sopenharmony_ci	struct efx_channel *(*copy)(const struct efx_channel *);
59462306a36Sopenharmony_ci	bool (*receive_skb)(struct efx_channel *, struct sk_buff *);
59562306a36Sopenharmony_ci	bool (*want_txqs)(struct efx_channel *);
59662306a36Sopenharmony_ci	bool keep_eventq;
59762306a36Sopenharmony_ci	bool want_pio;
59862306a36Sopenharmony_ci};
59962306a36Sopenharmony_ci
60062306a36Sopenharmony_cienum efx_led_mode {
60162306a36Sopenharmony_ci	EFX_LED_OFF	= 0,
60262306a36Sopenharmony_ci	EFX_LED_ON	= 1,
60362306a36Sopenharmony_ci	EFX_LED_DEFAULT	= 2
60462306a36Sopenharmony_ci};
60562306a36Sopenharmony_ci
60662306a36Sopenharmony_ci#define STRING_TABLE_LOOKUP(val, member) \
60762306a36Sopenharmony_ci	((val) < member ## _max) ? member ## _names[val] : "(invalid)"
60862306a36Sopenharmony_ci
60962306a36Sopenharmony_ciextern const char *const efx_siena_loopback_mode_names[];
61062306a36Sopenharmony_ciextern const unsigned int efx_siena_loopback_mode_max;
61162306a36Sopenharmony_ci#define LOOPBACK_MODE(efx) \
61262306a36Sopenharmony_ci	STRING_TABLE_LOOKUP((efx)->loopback_mode, efx_siena_loopback_mode)
61362306a36Sopenharmony_ci
61462306a36Sopenharmony_cienum efx_int_mode {
61562306a36Sopenharmony_ci	/* Be careful if altering to correct macro below */
61662306a36Sopenharmony_ci	EFX_INT_MODE_MSIX = 0,
61762306a36Sopenharmony_ci	EFX_INT_MODE_MSI = 1,
61862306a36Sopenharmony_ci	EFX_INT_MODE_LEGACY = 2,
61962306a36Sopenharmony_ci	EFX_INT_MODE_MAX	/* Insert any new items before this */
62062306a36Sopenharmony_ci};
62162306a36Sopenharmony_ci#define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
62262306a36Sopenharmony_ci
62362306a36Sopenharmony_cienum nic_state {
62462306a36Sopenharmony_ci	STATE_UNINIT = 0,	/* device being probed/removed or is frozen */
62562306a36Sopenharmony_ci	STATE_READY = 1,	/* hardware ready and netdev registered */
62662306a36Sopenharmony_ci	STATE_DISABLED = 2,	/* device disabled due to hardware errors */
62762306a36Sopenharmony_ci	STATE_RECOVERY = 3,	/* device recovering from PCI error */
62862306a36Sopenharmony_ci};
62962306a36Sopenharmony_ci
63062306a36Sopenharmony_ci/* Forward declaration */
63162306a36Sopenharmony_cistruct efx_nic;
63262306a36Sopenharmony_ci
63362306a36Sopenharmony_ci/* Pseudo bit-mask flow control field */
63462306a36Sopenharmony_ci#define EFX_FC_RX	FLOW_CTRL_RX
63562306a36Sopenharmony_ci#define EFX_FC_TX	FLOW_CTRL_TX
63662306a36Sopenharmony_ci#define EFX_FC_AUTO	4
63762306a36Sopenharmony_ci
63862306a36Sopenharmony_ci/**
63962306a36Sopenharmony_ci * struct efx_link_state - Current state of the link
64062306a36Sopenharmony_ci * @up: Link is up
64162306a36Sopenharmony_ci * @fd: Link is full-duplex
64262306a36Sopenharmony_ci * @fc: Actual flow control flags
64362306a36Sopenharmony_ci * @speed: Link speed (Mbps)
64462306a36Sopenharmony_ci */
64562306a36Sopenharmony_cistruct efx_link_state {
64662306a36Sopenharmony_ci	bool up;
64762306a36Sopenharmony_ci	bool fd;
64862306a36Sopenharmony_ci	u8 fc;
64962306a36Sopenharmony_ci	unsigned int speed;
65062306a36Sopenharmony_ci};
65162306a36Sopenharmony_ci
65262306a36Sopenharmony_cistatic inline bool efx_link_state_equal(const struct efx_link_state *left,
65362306a36Sopenharmony_ci					const struct efx_link_state *right)
65462306a36Sopenharmony_ci{
65562306a36Sopenharmony_ci	return left->up == right->up && left->fd == right->fd &&
65662306a36Sopenharmony_ci		left->fc == right->fc && left->speed == right->speed;
65762306a36Sopenharmony_ci}
65862306a36Sopenharmony_ci
65962306a36Sopenharmony_ci/**
66062306a36Sopenharmony_ci * enum efx_phy_mode - PHY operating mode flags
66162306a36Sopenharmony_ci * @PHY_MODE_NORMAL: on and should pass traffic
66262306a36Sopenharmony_ci * @PHY_MODE_TX_DISABLED: on with TX disabled
66362306a36Sopenharmony_ci * @PHY_MODE_LOW_POWER: set to low power through MDIO
66462306a36Sopenharmony_ci * @PHY_MODE_OFF: switched off through external control
66562306a36Sopenharmony_ci * @PHY_MODE_SPECIAL: on but will not pass traffic
66662306a36Sopenharmony_ci */
66762306a36Sopenharmony_cienum efx_phy_mode {
66862306a36Sopenharmony_ci	PHY_MODE_NORMAL		= 0,
66962306a36Sopenharmony_ci	PHY_MODE_TX_DISABLED	= 1,
67062306a36Sopenharmony_ci	PHY_MODE_LOW_POWER	= 2,
67162306a36Sopenharmony_ci	PHY_MODE_OFF		= 4,
67262306a36Sopenharmony_ci	PHY_MODE_SPECIAL	= 8,
67362306a36Sopenharmony_ci};
67462306a36Sopenharmony_ci
67562306a36Sopenharmony_cistatic inline bool efx_phy_mode_disabled(enum efx_phy_mode mode)
67662306a36Sopenharmony_ci{
67762306a36Sopenharmony_ci	return !!(mode & ~PHY_MODE_TX_DISABLED);
67862306a36Sopenharmony_ci}
67962306a36Sopenharmony_ci
68062306a36Sopenharmony_ci/**
68162306a36Sopenharmony_ci * struct efx_hw_stat_desc - Description of a hardware statistic
68262306a36Sopenharmony_ci * @name: Name of the statistic as visible through ethtool, or %NULL if
68362306a36Sopenharmony_ci *	it should not be exposed
68462306a36Sopenharmony_ci * @dma_width: Width in bits (0 for non-DMA statistics)
68562306a36Sopenharmony_ci * @offset: Offset within stats (ignored for non-DMA statistics)
68662306a36Sopenharmony_ci */
68762306a36Sopenharmony_cistruct efx_hw_stat_desc {
68862306a36Sopenharmony_ci	const char *name;
68962306a36Sopenharmony_ci	u16 dma_width;
69062306a36Sopenharmony_ci	u16 offset;
69162306a36Sopenharmony_ci};
69262306a36Sopenharmony_ci
69362306a36Sopenharmony_ci/* Number of bits used in a multicast filter hash address */
69462306a36Sopenharmony_ci#define EFX_MCAST_HASH_BITS 8
69562306a36Sopenharmony_ci
69662306a36Sopenharmony_ci/* Number of (single-bit) entries in a multicast filter hash */
69762306a36Sopenharmony_ci#define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
69862306a36Sopenharmony_ci
69962306a36Sopenharmony_ci/* An Efx multicast filter hash */
70062306a36Sopenharmony_ciunion efx_multicast_hash {
70162306a36Sopenharmony_ci	u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
70262306a36Sopenharmony_ci	efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
70362306a36Sopenharmony_ci};
70462306a36Sopenharmony_ci
70562306a36Sopenharmony_cistruct vfdi_status;
70662306a36Sopenharmony_ci
70762306a36Sopenharmony_ci/* The reserved RSS context value */
70862306a36Sopenharmony_ci#define EFX_MCDI_RSS_CONTEXT_INVALID	0xffffffff
70962306a36Sopenharmony_ci/**
71062306a36Sopenharmony_ci * struct efx_rss_context - A user-defined RSS context for filtering
71162306a36Sopenharmony_ci * @list: node of linked list on which this struct is stored
71262306a36Sopenharmony_ci * @context_id: the RSS_CONTEXT_ID returned by MC firmware, or
71362306a36Sopenharmony_ci *	%EFX_MCDI_RSS_CONTEXT_INVALID if this context is not present on the NIC.
71462306a36Sopenharmony_ci *	For Siena, 0 if RSS is active, else %EFX_MCDI_RSS_CONTEXT_INVALID.
71562306a36Sopenharmony_ci * @user_id: the rss_context ID exposed to userspace over ethtool.
71662306a36Sopenharmony_ci * @rx_hash_udp_4tuple: UDP 4-tuple hashing enabled
71762306a36Sopenharmony_ci * @rx_hash_key: Toeplitz hash key for this RSS context
71862306a36Sopenharmony_ci * @indir_table: Indirection table for this RSS context
71962306a36Sopenharmony_ci */
72062306a36Sopenharmony_cistruct efx_rss_context {
72162306a36Sopenharmony_ci	struct list_head list;
72262306a36Sopenharmony_ci	u32 context_id;
72362306a36Sopenharmony_ci	u32 user_id;
72462306a36Sopenharmony_ci	bool rx_hash_udp_4tuple;
72562306a36Sopenharmony_ci	u8 rx_hash_key[40];
72662306a36Sopenharmony_ci	u32 rx_indir_table[128];
72762306a36Sopenharmony_ci};
72862306a36Sopenharmony_ci
72962306a36Sopenharmony_ci#ifdef CONFIG_RFS_ACCEL
73062306a36Sopenharmony_ci/* Order of these is important, since filter_id >= %EFX_ARFS_FILTER_ID_PENDING
73162306a36Sopenharmony_ci * is used to test if filter does or will exist.
73262306a36Sopenharmony_ci */
73362306a36Sopenharmony_ci#define EFX_ARFS_FILTER_ID_PENDING	-1
73462306a36Sopenharmony_ci#define EFX_ARFS_FILTER_ID_ERROR	-2
73562306a36Sopenharmony_ci#define EFX_ARFS_FILTER_ID_REMOVING	-3
73662306a36Sopenharmony_ci/**
73762306a36Sopenharmony_ci * struct efx_arfs_rule - record of an ARFS filter and its IDs
73862306a36Sopenharmony_ci * @node: linkage into hash table
73962306a36Sopenharmony_ci * @spec: details of the filter (used as key for hash table).  Use efx->type to
74062306a36Sopenharmony_ci *	determine which member to use.
74162306a36Sopenharmony_ci * @rxq_index: channel to which the filter will steer traffic.
74262306a36Sopenharmony_ci * @arfs_id: filter ID which was returned to ARFS
74362306a36Sopenharmony_ci * @filter_id: index in software filter table.  May be
74462306a36Sopenharmony_ci *	%EFX_ARFS_FILTER_ID_PENDING if filter was not inserted yet,
74562306a36Sopenharmony_ci *	%EFX_ARFS_FILTER_ID_ERROR if filter insertion failed, or
74662306a36Sopenharmony_ci *	%EFX_ARFS_FILTER_ID_REMOVING if expiry is currently removing the filter.
74762306a36Sopenharmony_ci */
74862306a36Sopenharmony_cistruct efx_arfs_rule {
74962306a36Sopenharmony_ci	struct hlist_node node;
75062306a36Sopenharmony_ci	struct efx_filter_spec spec;
75162306a36Sopenharmony_ci	u16 rxq_index;
75262306a36Sopenharmony_ci	u16 arfs_id;
75362306a36Sopenharmony_ci	s32 filter_id;
75462306a36Sopenharmony_ci};
75562306a36Sopenharmony_ci
75662306a36Sopenharmony_ci/* Size chosen so that the table is one page (4kB) */
75762306a36Sopenharmony_ci#define EFX_ARFS_HASH_TABLE_SIZE	512
75862306a36Sopenharmony_ci
75962306a36Sopenharmony_ci/**
76062306a36Sopenharmony_ci * struct efx_async_filter_insertion - Request to asynchronously insert a filter
76162306a36Sopenharmony_ci * @net_dev: Reference to the netdevice
76262306a36Sopenharmony_ci * @spec: The filter to insert
76362306a36Sopenharmony_ci * @work: Workitem for this request
76462306a36Sopenharmony_ci * @rxq_index: Identifies the channel for which this request was made
76562306a36Sopenharmony_ci * @flow_id: Identifies the kernel-side flow for which this request was made
76662306a36Sopenharmony_ci */
76762306a36Sopenharmony_cistruct efx_async_filter_insertion {
76862306a36Sopenharmony_ci	struct net_device *net_dev;
76962306a36Sopenharmony_ci	struct efx_filter_spec spec;
77062306a36Sopenharmony_ci	struct work_struct work;
77162306a36Sopenharmony_ci	u16 rxq_index;
77262306a36Sopenharmony_ci	u32 flow_id;
77362306a36Sopenharmony_ci};
77462306a36Sopenharmony_ci
77562306a36Sopenharmony_ci/* Maximum number of ARFS workitems that may be in flight on an efx_nic */
77662306a36Sopenharmony_ci#define EFX_RPS_MAX_IN_FLIGHT	8
77762306a36Sopenharmony_ci#endif /* CONFIG_RFS_ACCEL */
77862306a36Sopenharmony_ci
77962306a36Sopenharmony_cienum efx_xdp_tx_queues_mode {
78062306a36Sopenharmony_ci	EFX_XDP_TX_QUEUES_DEDICATED,	/* one queue per core, locking not needed */
78162306a36Sopenharmony_ci	EFX_XDP_TX_QUEUES_SHARED,	/* each queue used by more than 1 core */
78262306a36Sopenharmony_ci	EFX_XDP_TX_QUEUES_BORROWED	/* queues borrowed from net stack */
78362306a36Sopenharmony_ci};
78462306a36Sopenharmony_ci
78562306a36Sopenharmony_ci/**
78662306a36Sopenharmony_ci * struct efx_nic - an Efx NIC
78762306a36Sopenharmony_ci * @name: Device name (net device name or bus id before net device registered)
78862306a36Sopenharmony_ci * @pci_dev: The PCI device
78962306a36Sopenharmony_ci * @node: List node for maintaning primary/secondary function lists
79062306a36Sopenharmony_ci * @primary: &struct efx_nic instance for the primary function of this
79162306a36Sopenharmony_ci *	controller.  May be the same structure, and may be %NULL if no
79262306a36Sopenharmony_ci *	primary function is bound.  Serialised by rtnl_lock.
79362306a36Sopenharmony_ci * @secondary_list: List of &struct efx_nic instances for the secondary PCI
79462306a36Sopenharmony_ci *	functions of the controller, if this is for the primary function.
79562306a36Sopenharmony_ci *	Serialised by rtnl_lock.
79662306a36Sopenharmony_ci * @type: Controller type attributes
79762306a36Sopenharmony_ci * @legacy_irq: IRQ number
79862306a36Sopenharmony_ci * @workqueue: Workqueue for port reconfigures and the HW monitor.
79962306a36Sopenharmony_ci *	Work items do not hold and must not acquire RTNL.
80062306a36Sopenharmony_ci * @workqueue_name: Name of workqueue
80162306a36Sopenharmony_ci * @reset_work: Scheduled reset workitem
80262306a36Sopenharmony_ci * @membase_phys: Memory BAR value as physical address
80362306a36Sopenharmony_ci * @membase: Memory BAR value
80462306a36Sopenharmony_ci * @vi_stride: step between per-VI registers / memory regions
80562306a36Sopenharmony_ci * @interrupt_mode: Interrupt mode
80662306a36Sopenharmony_ci * @timer_quantum_ns: Interrupt timer quantum, in nanoseconds
80762306a36Sopenharmony_ci * @timer_max_ns: Interrupt timer maximum value, in nanoseconds
80862306a36Sopenharmony_ci * @irq_rx_adaptive: Adaptive IRQ moderation enabled for RX event queues
80962306a36Sopenharmony_ci * @irqs_hooked: Channel interrupts are hooked
81062306a36Sopenharmony_ci * @irq_rx_mod_step_us: Step size for IRQ moderation for RX event queues
81162306a36Sopenharmony_ci * @irq_rx_moderation_us: IRQ moderation time for RX event queues
81262306a36Sopenharmony_ci * @msg_enable: Log message enable flags
81362306a36Sopenharmony_ci * @state: Device state number (%STATE_*). Serialised by the rtnl_lock.
81462306a36Sopenharmony_ci * @reset_pending: Bitmask for pending resets
81562306a36Sopenharmony_ci * @tx_queue: TX DMA queues
81662306a36Sopenharmony_ci * @rx_queue: RX DMA queues
81762306a36Sopenharmony_ci * @channel: Channels
81862306a36Sopenharmony_ci * @msi_context: Context for each MSI
81962306a36Sopenharmony_ci * @extra_channel_types: Types of extra (non-traffic) channels that
82062306a36Sopenharmony_ci *	should be allocated for this NIC
82162306a36Sopenharmony_ci * @xdp_tx_queue_count: Number of entries in %xdp_tx_queues.
82262306a36Sopenharmony_ci * @xdp_tx_queues: Array of pointers to tx queues used for XDP transmit.
82362306a36Sopenharmony_ci * @xdp_txq_queues_mode: XDP TX queues sharing strategy.
82462306a36Sopenharmony_ci * @rxq_entries: Size of receive queues requested by user.
82562306a36Sopenharmony_ci * @txq_entries: Size of transmit queues requested by user.
82662306a36Sopenharmony_ci * @txq_stop_thresh: TX queue fill level at or above which we stop it.
82762306a36Sopenharmony_ci * @txq_wake_thresh: TX queue fill level at or below which we wake it.
82862306a36Sopenharmony_ci * @tx_dc_base: Base qword address in SRAM of TX queue descriptor caches
82962306a36Sopenharmony_ci * @rx_dc_base: Base qword address in SRAM of RX queue descriptor caches
83062306a36Sopenharmony_ci * @sram_lim_qw: Qword address limit of SRAM
83162306a36Sopenharmony_ci * @next_buffer_table: First available buffer table id
83262306a36Sopenharmony_ci * @n_channels: Number of channels in use
83362306a36Sopenharmony_ci * @n_rx_channels: Number of channels used for RX (= number of RX queues)
83462306a36Sopenharmony_ci * @n_tx_channels: Number of channels used for TX
83562306a36Sopenharmony_ci * @n_extra_tx_channels: Number of extra channels with TX queues
83662306a36Sopenharmony_ci * @tx_queues_per_channel: number of TX queues probed on each channel
83762306a36Sopenharmony_ci * @n_xdp_channels: Number of channels used for XDP TX
83862306a36Sopenharmony_ci * @xdp_channel_offset: Offset of zeroth channel used for XPD TX.
83962306a36Sopenharmony_ci * @xdp_tx_per_channel: Max number of TX queues on an XDP TX channel.
84062306a36Sopenharmony_ci * @rx_ip_align: RX DMA address offset to have IP header aligned in
84162306a36Sopenharmony_ci *	accordance with NET_IP_ALIGN
84262306a36Sopenharmony_ci * @rx_dma_len: Current maximum RX DMA length
84362306a36Sopenharmony_ci * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
84462306a36Sopenharmony_ci * @rx_buffer_truesize: Amortised allocation size of an RX buffer,
84562306a36Sopenharmony_ci *	for use in sk_buff::truesize
84662306a36Sopenharmony_ci * @rx_prefix_size: Size of RX prefix before packet data
84762306a36Sopenharmony_ci * @rx_packet_hash_offset: Offset of RX flow hash from start of packet data
84862306a36Sopenharmony_ci *	(valid only if @rx_prefix_size != 0; always negative)
84962306a36Sopenharmony_ci * @rx_packet_len_offset: Offset of RX packet length from start of packet data
85062306a36Sopenharmony_ci *	(valid only for NICs that set %EFX_RX_PKT_PREFIX_LEN; always negative)
85162306a36Sopenharmony_ci * @rx_packet_ts_offset: Offset of timestamp from start of packet data
85262306a36Sopenharmony_ci *	(valid only if channel->sync_timestamps_enabled; always negative)
85362306a36Sopenharmony_ci * @rx_scatter: Scatter mode enabled for receives
85462306a36Sopenharmony_ci * @rss_context: Main RSS context.  Its @list member is the head of the list of
85562306a36Sopenharmony_ci *	RSS contexts created by user requests
85662306a36Sopenharmony_ci * @rss_lock: Protects custom RSS context software state in @rss_context.list
85762306a36Sopenharmony_ci * @vport_id: The function's vport ID, only relevant for PFs
85862306a36Sopenharmony_ci * @int_error_count: Number of internal errors seen recently
85962306a36Sopenharmony_ci * @int_error_expire: Time at which error count will be expired
86062306a36Sopenharmony_ci * @must_realloc_vis: Flag: VIs have yet to be reallocated after MC reboot
86162306a36Sopenharmony_ci * @irq_soft_enabled: Are IRQs soft-enabled? If not, IRQ handler will
86262306a36Sopenharmony_ci *	acknowledge but do nothing else.
86362306a36Sopenharmony_ci * @irq_status: Interrupt status buffer
86462306a36Sopenharmony_ci * @irq_zero_count: Number of legacy IRQs seen with queue flags == 0
86562306a36Sopenharmony_ci * @irq_level: IRQ level/index for IRQs not triggered by an event queue
86662306a36Sopenharmony_ci * @selftest_work: Work item for asynchronous self-test
86762306a36Sopenharmony_ci * @mtd_list: List of MTDs attached to the NIC
86862306a36Sopenharmony_ci * @nic_data: Hardware dependent state
86962306a36Sopenharmony_ci * @mcdi: Management-Controller-to-Driver Interface state
87062306a36Sopenharmony_ci * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode,
87162306a36Sopenharmony_ci *	efx_monitor() and efx_siena_reconfigure_port()
87262306a36Sopenharmony_ci * @port_enabled: Port enabled indicator.
87362306a36Sopenharmony_ci *	Serialises efx_siena_stop_all(), efx_siena_start_all(),
87462306a36Sopenharmony_ci *	efx_monitor() and efx_mac_work() with kernel interfaces.
87562306a36Sopenharmony_ci *	Safe to read under any one of the rtnl_lock, mac_lock, or netif_tx_lock,
87662306a36Sopenharmony_ci *	but all three must be held to modify it.
87762306a36Sopenharmony_ci * @port_initialized: Port initialized?
87862306a36Sopenharmony_ci * @net_dev: Operating system network device. Consider holding the rtnl lock
87962306a36Sopenharmony_ci * @fixed_features: Features which cannot be turned off
88062306a36Sopenharmony_ci * @num_mac_stats: Number of MAC stats reported by firmware (MAC_STATS_NUM_STATS
88162306a36Sopenharmony_ci *	field of %MC_CMD_GET_CAPABILITIES_V4 response, or %MC_CMD_MAC_NSTATS)
88262306a36Sopenharmony_ci * @stats_buffer: DMA buffer for statistics
88362306a36Sopenharmony_ci * @phy_type: PHY type
88462306a36Sopenharmony_ci * @phy_data: PHY private data (including PHY-specific stats)
88562306a36Sopenharmony_ci * @mdio: PHY MDIO interface
88662306a36Sopenharmony_ci * @mdio_bus: PHY MDIO bus ID (only used by Siena)
88762306a36Sopenharmony_ci * @phy_mode: PHY operating mode. Serialised by @mac_lock.
88862306a36Sopenharmony_ci * @link_advertising: Autonegotiation advertising flags
88962306a36Sopenharmony_ci * @fec_config: Forward Error Correction configuration flags.  For bit positions
89062306a36Sopenharmony_ci *	see &enum ethtool_fec_config_bits.
89162306a36Sopenharmony_ci * @link_state: Current state of the link
89262306a36Sopenharmony_ci * @n_link_state_changes: Number of times the link has changed state
89362306a36Sopenharmony_ci * @unicast_filter: Flag for Falcon-arch simple unicast filter.
89462306a36Sopenharmony_ci *	Protected by @mac_lock.
89562306a36Sopenharmony_ci * @multicast_hash: Multicast hash table for Falcon-arch.
89662306a36Sopenharmony_ci *	Protected by @mac_lock.
89762306a36Sopenharmony_ci * @wanted_fc: Wanted flow control flags
89862306a36Sopenharmony_ci * @fc_disable: When non-zero flow control is disabled. Typically used to
89962306a36Sopenharmony_ci *	ensure that network back pressure doesn't delay dma queue flushes.
90062306a36Sopenharmony_ci *	Serialised by the rtnl lock.
90162306a36Sopenharmony_ci * @mac_work: Work item for changing MAC promiscuity and multicast hash
90262306a36Sopenharmony_ci * @loopback_mode: Loopback status
90362306a36Sopenharmony_ci * @loopback_modes: Supported loopback mode bitmask
90462306a36Sopenharmony_ci * @loopback_selftest: Offline self-test private state
90562306a36Sopenharmony_ci * @xdp_prog: Current XDP programme for this interface
90662306a36Sopenharmony_ci * @filter_sem: Filter table rw_semaphore, protects existence of @filter_state
90762306a36Sopenharmony_ci * @filter_state: Architecture-dependent filter table state
90862306a36Sopenharmony_ci * @rps_mutex: Protects RPS state of all channels
90962306a36Sopenharmony_ci * @rps_slot_map: bitmap of in-flight entries in @rps_slot
91062306a36Sopenharmony_ci * @rps_slot: array of ARFS insertion requests for efx_filter_rfs_work()
91162306a36Sopenharmony_ci * @rps_hash_lock: Protects ARFS filter mapping state (@rps_hash_table and
91262306a36Sopenharmony_ci *	@rps_next_id).
91362306a36Sopenharmony_ci * @rps_hash_table: Mapping between ARFS filters and their various IDs
91462306a36Sopenharmony_ci * @rps_next_id: next arfs_id for an ARFS filter
91562306a36Sopenharmony_ci * @active_queues: Count of RX and TX queues that haven't been flushed and drained.
91662306a36Sopenharmony_ci * @rxq_flush_pending: Count of number of receive queues that need to be flushed.
91762306a36Sopenharmony_ci *	Decremented when the efx_flush_rx_queue() is called.
91862306a36Sopenharmony_ci * @rxq_flush_outstanding: Count of number of RX flushes started but not yet
91962306a36Sopenharmony_ci *	completed (either success or failure). Not used when MCDI is used to
92062306a36Sopenharmony_ci *	flush receive queues.
92162306a36Sopenharmony_ci * @flush_wq: wait queue used by efx_nic_flush_queues() to wait for flush completions.
92262306a36Sopenharmony_ci * @vf_count: Number of VFs intended to be enabled.
92362306a36Sopenharmony_ci * @vf_init_count: Number of VFs that have been fully initialised.
92462306a36Sopenharmony_ci * @vi_scale: log2 number of vnics per VF.
92562306a36Sopenharmony_ci * @ptp_data: PTP state data
92662306a36Sopenharmony_ci * @ptp_warned: has this NIC seen and warned about unexpected PTP events?
92762306a36Sopenharmony_ci * @vpd_sn: Serial number read from VPD
92862306a36Sopenharmony_ci * @xdp_rxq_info_failed: Have any of the rx queues failed to initialise their
92962306a36Sopenharmony_ci *      xdp_rxq_info structures?
93062306a36Sopenharmony_ci * @netdev_notifier: Netdevice notifier.
93162306a36Sopenharmony_ci * @mem_bar: The BAR that is mapped into membase.
93262306a36Sopenharmony_ci * @reg_base: Offset from the start of the bar to the function control window.
93362306a36Sopenharmony_ci * @monitor_work: Hardware monitor workitem
93462306a36Sopenharmony_ci * @biu_lock: BIU (bus interface unit) lock
93562306a36Sopenharmony_ci * @last_irq_cpu: Last CPU to handle a possible test interrupt.  This
93662306a36Sopenharmony_ci *	field is used by efx_test_interrupts() to verify that an
93762306a36Sopenharmony_ci *	interrupt has occurred.
93862306a36Sopenharmony_ci * @stats_lock: Statistics update lock. Must be held when calling
93962306a36Sopenharmony_ci *	efx_nic_type::{update,start,stop}_stats.
94062306a36Sopenharmony_ci * @n_rx_noskb_drops: Count of RX packets dropped due to failure to allocate an skb
94162306a36Sopenharmony_ci *
94262306a36Sopenharmony_ci * This is stored in the private area of the &struct net_device.
94362306a36Sopenharmony_ci */
94462306a36Sopenharmony_cistruct efx_nic {
94562306a36Sopenharmony_ci	/* The following fields should be written very rarely */
94662306a36Sopenharmony_ci
94762306a36Sopenharmony_ci	char name[IFNAMSIZ];
94862306a36Sopenharmony_ci	struct list_head node;
94962306a36Sopenharmony_ci	struct efx_nic *primary;
95062306a36Sopenharmony_ci	struct list_head secondary_list;
95162306a36Sopenharmony_ci	struct pci_dev *pci_dev;
95262306a36Sopenharmony_ci	unsigned int port_num;
95362306a36Sopenharmony_ci	const struct efx_nic_type *type;
95462306a36Sopenharmony_ci	int legacy_irq;
95562306a36Sopenharmony_ci	bool eeh_disabled_legacy_irq;
95662306a36Sopenharmony_ci	struct workqueue_struct *workqueue;
95762306a36Sopenharmony_ci	char workqueue_name[16];
95862306a36Sopenharmony_ci	struct work_struct reset_work;
95962306a36Sopenharmony_ci	resource_size_t membase_phys;
96062306a36Sopenharmony_ci	void __iomem *membase;
96162306a36Sopenharmony_ci
96262306a36Sopenharmony_ci	unsigned int vi_stride;
96362306a36Sopenharmony_ci
96462306a36Sopenharmony_ci	enum efx_int_mode interrupt_mode;
96562306a36Sopenharmony_ci	unsigned int timer_quantum_ns;
96662306a36Sopenharmony_ci	unsigned int timer_max_ns;
96762306a36Sopenharmony_ci	bool irq_rx_adaptive;
96862306a36Sopenharmony_ci	bool irqs_hooked;
96962306a36Sopenharmony_ci	unsigned int irq_mod_step_us;
97062306a36Sopenharmony_ci	unsigned int irq_rx_moderation_us;
97162306a36Sopenharmony_ci	u32 msg_enable;
97262306a36Sopenharmony_ci
97362306a36Sopenharmony_ci	enum nic_state state;
97462306a36Sopenharmony_ci	unsigned long reset_pending;
97562306a36Sopenharmony_ci
97662306a36Sopenharmony_ci	struct efx_channel *channel[EFX_MAX_CHANNELS];
97762306a36Sopenharmony_ci	struct efx_msi_context msi_context[EFX_MAX_CHANNELS];
97862306a36Sopenharmony_ci	const struct efx_channel_type *
97962306a36Sopenharmony_ci	extra_channel_type[EFX_MAX_EXTRA_CHANNELS];
98062306a36Sopenharmony_ci
98162306a36Sopenharmony_ci	unsigned int xdp_tx_queue_count;
98262306a36Sopenharmony_ci	struct efx_tx_queue **xdp_tx_queues;
98362306a36Sopenharmony_ci	enum efx_xdp_tx_queues_mode xdp_txq_queues_mode;
98462306a36Sopenharmony_ci
98562306a36Sopenharmony_ci	unsigned rxq_entries;
98662306a36Sopenharmony_ci	unsigned txq_entries;
98762306a36Sopenharmony_ci	unsigned int txq_stop_thresh;
98862306a36Sopenharmony_ci	unsigned int txq_wake_thresh;
98962306a36Sopenharmony_ci
99062306a36Sopenharmony_ci	unsigned tx_dc_base;
99162306a36Sopenharmony_ci	unsigned rx_dc_base;
99262306a36Sopenharmony_ci	unsigned sram_lim_qw;
99362306a36Sopenharmony_ci	unsigned next_buffer_table;
99462306a36Sopenharmony_ci
99562306a36Sopenharmony_ci	unsigned int max_channels;
99662306a36Sopenharmony_ci	unsigned int max_vis;
99762306a36Sopenharmony_ci	unsigned int max_tx_channels;
99862306a36Sopenharmony_ci	unsigned n_channels;
99962306a36Sopenharmony_ci	unsigned n_rx_channels;
100062306a36Sopenharmony_ci	unsigned rss_spread;
100162306a36Sopenharmony_ci	unsigned tx_channel_offset;
100262306a36Sopenharmony_ci	unsigned n_tx_channels;
100362306a36Sopenharmony_ci	unsigned n_extra_tx_channels;
100462306a36Sopenharmony_ci	unsigned int tx_queues_per_channel;
100562306a36Sopenharmony_ci	unsigned int n_xdp_channels;
100662306a36Sopenharmony_ci	unsigned int xdp_channel_offset;
100762306a36Sopenharmony_ci	unsigned int xdp_tx_per_channel;
100862306a36Sopenharmony_ci	unsigned int rx_ip_align;
100962306a36Sopenharmony_ci	unsigned int rx_dma_len;
101062306a36Sopenharmony_ci	unsigned int rx_buffer_order;
101162306a36Sopenharmony_ci	unsigned int rx_buffer_truesize;
101262306a36Sopenharmony_ci	unsigned int rx_page_buf_step;
101362306a36Sopenharmony_ci	unsigned int rx_bufs_per_page;
101462306a36Sopenharmony_ci	unsigned int rx_pages_per_batch;
101562306a36Sopenharmony_ci	unsigned int rx_prefix_size;
101662306a36Sopenharmony_ci	int rx_packet_hash_offset;
101762306a36Sopenharmony_ci	int rx_packet_len_offset;
101862306a36Sopenharmony_ci	int rx_packet_ts_offset;
101962306a36Sopenharmony_ci	bool rx_scatter;
102062306a36Sopenharmony_ci	struct efx_rss_context rss_context;
102162306a36Sopenharmony_ci	struct mutex rss_lock;
102262306a36Sopenharmony_ci	u32 vport_id;
102362306a36Sopenharmony_ci
102462306a36Sopenharmony_ci	unsigned int_error_count;
102562306a36Sopenharmony_ci	unsigned long int_error_expire;
102662306a36Sopenharmony_ci
102762306a36Sopenharmony_ci	bool must_realloc_vis;
102862306a36Sopenharmony_ci	bool irq_soft_enabled;
102962306a36Sopenharmony_ci	struct efx_buffer irq_status;
103062306a36Sopenharmony_ci	unsigned irq_zero_count;
103162306a36Sopenharmony_ci	unsigned irq_level;
103262306a36Sopenharmony_ci	struct delayed_work selftest_work;
103362306a36Sopenharmony_ci
103462306a36Sopenharmony_ci#ifdef CONFIG_SFC_SIENA_MTD
103562306a36Sopenharmony_ci	struct list_head mtd_list;
103662306a36Sopenharmony_ci#endif
103762306a36Sopenharmony_ci
103862306a36Sopenharmony_ci	void *nic_data;
103962306a36Sopenharmony_ci	struct efx_mcdi_data *mcdi;
104062306a36Sopenharmony_ci
104162306a36Sopenharmony_ci	struct mutex mac_lock;
104262306a36Sopenharmony_ci	struct work_struct mac_work;
104362306a36Sopenharmony_ci	bool port_enabled;
104462306a36Sopenharmony_ci
104562306a36Sopenharmony_ci	bool mc_bist_for_other_fn;
104662306a36Sopenharmony_ci	bool port_initialized;
104762306a36Sopenharmony_ci	struct net_device *net_dev;
104862306a36Sopenharmony_ci
104962306a36Sopenharmony_ci	netdev_features_t fixed_features;
105062306a36Sopenharmony_ci
105162306a36Sopenharmony_ci	u16 num_mac_stats;
105262306a36Sopenharmony_ci	struct efx_buffer stats_buffer;
105362306a36Sopenharmony_ci	u64 rx_nodesc_drops_total;
105462306a36Sopenharmony_ci	u64 rx_nodesc_drops_while_down;
105562306a36Sopenharmony_ci	bool rx_nodesc_drops_prev_state;
105662306a36Sopenharmony_ci
105762306a36Sopenharmony_ci	unsigned int phy_type;
105862306a36Sopenharmony_ci	void *phy_data;
105962306a36Sopenharmony_ci	struct mdio_if_info mdio;
106062306a36Sopenharmony_ci	unsigned int mdio_bus;
106162306a36Sopenharmony_ci	enum efx_phy_mode phy_mode;
106262306a36Sopenharmony_ci
106362306a36Sopenharmony_ci	__ETHTOOL_DECLARE_LINK_MODE_MASK(link_advertising);
106462306a36Sopenharmony_ci	u32 fec_config;
106562306a36Sopenharmony_ci	struct efx_link_state link_state;
106662306a36Sopenharmony_ci	unsigned int n_link_state_changes;
106762306a36Sopenharmony_ci
106862306a36Sopenharmony_ci	bool unicast_filter;
106962306a36Sopenharmony_ci	union efx_multicast_hash multicast_hash;
107062306a36Sopenharmony_ci	u8 wanted_fc;
107162306a36Sopenharmony_ci	unsigned fc_disable;
107262306a36Sopenharmony_ci
107362306a36Sopenharmony_ci	atomic_t rx_reset;
107462306a36Sopenharmony_ci	enum efx_loopback_mode loopback_mode;
107562306a36Sopenharmony_ci	u64 loopback_modes;
107662306a36Sopenharmony_ci
107762306a36Sopenharmony_ci	void *loopback_selftest;
107862306a36Sopenharmony_ci	/* We access loopback_selftest immediately before running XDP,
107962306a36Sopenharmony_ci	 * so we want them next to each other.
108062306a36Sopenharmony_ci	 */
108162306a36Sopenharmony_ci	struct bpf_prog __rcu *xdp_prog;
108262306a36Sopenharmony_ci
108362306a36Sopenharmony_ci	struct rw_semaphore filter_sem;
108462306a36Sopenharmony_ci	void *filter_state;
108562306a36Sopenharmony_ci#ifdef CONFIG_RFS_ACCEL
108662306a36Sopenharmony_ci	struct mutex rps_mutex;
108762306a36Sopenharmony_ci	unsigned long rps_slot_map;
108862306a36Sopenharmony_ci	struct efx_async_filter_insertion rps_slot[EFX_RPS_MAX_IN_FLIGHT];
108962306a36Sopenharmony_ci	spinlock_t rps_hash_lock;
109062306a36Sopenharmony_ci	struct hlist_head *rps_hash_table;
109162306a36Sopenharmony_ci	u32 rps_next_id;
109262306a36Sopenharmony_ci#endif
109362306a36Sopenharmony_ci
109462306a36Sopenharmony_ci	atomic_t active_queues;
109562306a36Sopenharmony_ci	atomic_t rxq_flush_pending;
109662306a36Sopenharmony_ci	atomic_t rxq_flush_outstanding;
109762306a36Sopenharmony_ci	wait_queue_head_t flush_wq;
109862306a36Sopenharmony_ci
109962306a36Sopenharmony_ci#ifdef CONFIG_SFC_SIENA_SRIOV
110062306a36Sopenharmony_ci	unsigned vf_count;
110162306a36Sopenharmony_ci	unsigned vf_init_count;
110262306a36Sopenharmony_ci	unsigned vi_scale;
110362306a36Sopenharmony_ci#endif
110462306a36Sopenharmony_ci
110562306a36Sopenharmony_ci	struct efx_ptp_data *ptp_data;
110662306a36Sopenharmony_ci	bool ptp_warned;
110762306a36Sopenharmony_ci
110862306a36Sopenharmony_ci	char *vpd_sn;
110962306a36Sopenharmony_ci	bool xdp_rxq_info_failed;
111062306a36Sopenharmony_ci
111162306a36Sopenharmony_ci	struct notifier_block netdev_notifier;
111262306a36Sopenharmony_ci
111362306a36Sopenharmony_ci	unsigned int mem_bar;
111462306a36Sopenharmony_ci	u32 reg_base;
111562306a36Sopenharmony_ci
111662306a36Sopenharmony_ci	/* The following fields may be written more often */
111762306a36Sopenharmony_ci
111862306a36Sopenharmony_ci	struct delayed_work monitor_work ____cacheline_aligned_in_smp;
111962306a36Sopenharmony_ci	spinlock_t biu_lock;
112062306a36Sopenharmony_ci	int last_irq_cpu;
112162306a36Sopenharmony_ci	spinlock_t stats_lock;
112262306a36Sopenharmony_ci	atomic_t n_rx_noskb_drops;
112362306a36Sopenharmony_ci};
112462306a36Sopenharmony_ci
112562306a36Sopenharmony_cistatic inline int efx_dev_registered(struct efx_nic *efx)
112662306a36Sopenharmony_ci{
112762306a36Sopenharmony_ci	return efx->net_dev->reg_state == NETREG_REGISTERED;
112862306a36Sopenharmony_ci}
112962306a36Sopenharmony_ci
113062306a36Sopenharmony_cistatic inline unsigned int efx_port_num(struct efx_nic *efx)
113162306a36Sopenharmony_ci{
113262306a36Sopenharmony_ci	return efx->port_num;
113362306a36Sopenharmony_ci}
113462306a36Sopenharmony_ci
113562306a36Sopenharmony_cistruct efx_mtd_partition {
113662306a36Sopenharmony_ci	struct list_head node;
113762306a36Sopenharmony_ci	struct mtd_info mtd;
113862306a36Sopenharmony_ci	const char *dev_type_name;
113962306a36Sopenharmony_ci	const char *type_name;
114062306a36Sopenharmony_ci	char name[IFNAMSIZ + 20];
114162306a36Sopenharmony_ci};
114262306a36Sopenharmony_ci
114362306a36Sopenharmony_cistruct efx_udp_tunnel {
114462306a36Sopenharmony_ci#define TUNNEL_ENCAP_UDP_PORT_ENTRY_INVALID	0xffff
114562306a36Sopenharmony_ci	u16 type; /* TUNNEL_ENCAP_UDP_PORT_ENTRY_foo, see mcdi_pcol.h */
114662306a36Sopenharmony_ci	__be16 port;
114762306a36Sopenharmony_ci};
114862306a36Sopenharmony_ci
114962306a36Sopenharmony_ci/**
115062306a36Sopenharmony_ci * struct efx_nic_type - Efx device type definition
115162306a36Sopenharmony_ci * @mem_bar: Get the memory BAR
115262306a36Sopenharmony_ci * @mem_map_size: Get memory BAR mapped size
115362306a36Sopenharmony_ci * @probe: Probe the controller
115462306a36Sopenharmony_ci * @remove: Free resources allocated by probe()
115562306a36Sopenharmony_ci * @init: Initialise the controller
115662306a36Sopenharmony_ci * @dimension_resources: Dimension controller resources (buffer table,
115762306a36Sopenharmony_ci *	and VIs once the available interrupt resources are clear)
115862306a36Sopenharmony_ci * @fini: Shut down the controller
115962306a36Sopenharmony_ci * @monitor: Periodic function for polling link state and hardware monitor
116062306a36Sopenharmony_ci * @map_reset_reason: Map ethtool reset reason to a reset method
116162306a36Sopenharmony_ci * @map_reset_flags: Map ethtool reset flags to a reset method, if possible
116262306a36Sopenharmony_ci * @reset: Reset the controller hardware and possibly the PHY.  This will
116362306a36Sopenharmony_ci *	be called while the controller is uninitialised.
116462306a36Sopenharmony_ci * @probe_port: Probe the MAC and PHY
116562306a36Sopenharmony_ci * @remove_port: Free resources allocated by probe_port()
116662306a36Sopenharmony_ci * @handle_global_event: Handle a "global" event (may be %NULL)
116762306a36Sopenharmony_ci * @fini_dmaq: Flush and finalise DMA queues (RX and TX queues)
116862306a36Sopenharmony_ci * @prepare_flush: Prepare the hardware for flushing the DMA queues
116962306a36Sopenharmony_ci *	(for Falcon architecture)
117062306a36Sopenharmony_ci * @finish_flush: Clean up after flushing the DMA queues (for Falcon
117162306a36Sopenharmony_ci *	architecture)
117262306a36Sopenharmony_ci * @prepare_flr: Prepare for an FLR
117362306a36Sopenharmony_ci * @finish_flr: Clean up after an FLR
117462306a36Sopenharmony_ci * @describe_stats: Describe statistics for ethtool
117562306a36Sopenharmony_ci * @update_stats: Update statistics not provided by event handling.
117662306a36Sopenharmony_ci *	Either argument may be %NULL.
117762306a36Sopenharmony_ci * @update_stats_atomic: Update statistics while in atomic context, if that
117862306a36Sopenharmony_ci *	is more limiting than @update_stats.  Otherwise, leave %NULL and
117962306a36Sopenharmony_ci *	driver core will call @update_stats.
118062306a36Sopenharmony_ci * @start_stats: Start the regular fetching of statistics
118162306a36Sopenharmony_ci * @pull_stats: Pull stats from the NIC and wait until they arrive.
118262306a36Sopenharmony_ci * @stop_stats: Stop the regular fetching of statistics
118362306a36Sopenharmony_ci * @push_irq_moderation: Apply interrupt moderation value
118462306a36Sopenharmony_ci * @reconfigure_port: Push loopback/power/txdis changes to the MAC and PHY
118562306a36Sopenharmony_ci * @prepare_enable_fc_tx: Prepare MAC to enable pause frame TX (may be %NULL)
118662306a36Sopenharmony_ci * @reconfigure_mac: Push MAC address, MTU, flow control and filter settings
118762306a36Sopenharmony_ci *	to the hardware.  Serialised by the mac_lock.
118862306a36Sopenharmony_ci * @check_mac_fault: Check MAC fault state. True if fault present.
118962306a36Sopenharmony_ci * @get_wol: Get WoL configuration from driver state
119062306a36Sopenharmony_ci * @set_wol: Push WoL configuration to the NIC
119162306a36Sopenharmony_ci * @resume_wol: Synchronise WoL state between driver and MC (e.g. after resume)
119262306a36Sopenharmony_ci * @get_fec_stats: Get standard FEC statistics.
119362306a36Sopenharmony_ci * @test_chip: Test registers.  May use efx_farch_test_registers(), and is
119462306a36Sopenharmony_ci *	expected to reset the NIC.
119562306a36Sopenharmony_ci * @test_nvram: Test validity of NVRAM contents
119662306a36Sopenharmony_ci * @mcdi_request: Send an MCDI request with the given header and SDU.
119762306a36Sopenharmony_ci *	The SDU length may be any value from 0 up to the protocol-
119862306a36Sopenharmony_ci *	defined maximum, but its buffer will be padded to a multiple
119962306a36Sopenharmony_ci *	of 4 bytes.
120062306a36Sopenharmony_ci * @mcdi_poll_response: Test whether an MCDI response is available.
120162306a36Sopenharmony_ci * @mcdi_read_response: Read the MCDI response PDU.  The offset will
120262306a36Sopenharmony_ci *	be a multiple of 4.  The length may not be, but the buffer
120362306a36Sopenharmony_ci *	will be padded so it is safe to round up.
120462306a36Sopenharmony_ci * @mcdi_poll_reboot: Test whether the MCDI has rebooted.  If so,
120562306a36Sopenharmony_ci *	return an appropriate error code for aborting any current
120662306a36Sopenharmony_ci *	request; otherwise return 0.
120762306a36Sopenharmony_ci * @irq_enable_master: Enable IRQs on the NIC.  Each event queue must
120862306a36Sopenharmony_ci *	be separately enabled after this.
120962306a36Sopenharmony_ci * @irq_test_generate: Generate a test IRQ
121062306a36Sopenharmony_ci * @irq_disable_non_ev: Disable non-event IRQs on the NIC.  Each event
121162306a36Sopenharmony_ci *	queue must be separately disabled before this.
121262306a36Sopenharmony_ci * @irq_handle_msi: Handle MSI for a channel.  The @dev_id argument is
121362306a36Sopenharmony_ci *	a pointer to the &struct efx_msi_context for the channel.
121462306a36Sopenharmony_ci * @irq_handle_legacy: Handle legacy interrupt.  The @dev_id argument
121562306a36Sopenharmony_ci *	is a pointer to the &struct efx_nic.
121662306a36Sopenharmony_ci * @tx_probe: Allocate resources for TX queue (and select TXQ type)
121762306a36Sopenharmony_ci * @tx_init: Initialise TX queue on the NIC
121862306a36Sopenharmony_ci * @tx_remove: Free resources for TX queue
121962306a36Sopenharmony_ci * @tx_write: Write TX descriptors and doorbell
122062306a36Sopenharmony_ci * @tx_enqueue: Add an SKB to TX queue
122162306a36Sopenharmony_ci * @rx_push_rss_config: Write RSS hash key and indirection table to the NIC
122262306a36Sopenharmony_ci * @rx_pull_rss_config: Read RSS hash key and indirection table back from the NIC
122362306a36Sopenharmony_ci * @rx_push_rss_context_config: Write RSS hash key and indirection table for
122462306a36Sopenharmony_ci *	user RSS context to the NIC
122562306a36Sopenharmony_ci * @rx_pull_rss_context_config: Read RSS hash key and indirection table for user
122662306a36Sopenharmony_ci *	RSS context back from the NIC
122762306a36Sopenharmony_ci * @rx_probe: Allocate resources for RX queue
122862306a36Sopenharmony_ci * @rx_init: Initialise RX queue on the NIC
122962306a36Sopenharmony_ci * @rx_remove: Free resources for RX queue
123062306a36Sopenharmony_ci * @rx_write: Write RX descriptors and doorbell
123162306a36Sopenharmony_ci * @rx_defer_refill: Generate a refill reminder event
123262306a36Sopenharmony_ci * @rx_packet: Receive the queued RX buffer on a channel
123362306a36Sopenharmony_ci * @rx_buf_hash_valid: Determine whether the RX prefix contains a valid hash
123462306a36Sopenharmony_ci * @ev_probe: Allocate resources for event queue
123562306a36Sopenharmony_ci * @ev_init: Initialise event queue on the NIC
123662306a36Sopenharmony_ci * @ev_fini: Deinitialise event queue on the NIC
123762306a36Sopenharmony_ci * @ev_remove: Free resources for event queue
123862306a36Sopenharmony_ci * @ev_process: Process events for a queue, up to the given NAPI quota
123962306a36Sopenharmony_ci * @ev_read_ack: Acknowledge read events on a queue, rearming its IRQ
124062306a36Sopenharmony_ci * @ev_test_generate: Generate a test event
124162306a36Sopenharmony_ci * @filter_table_probe: Probe filter capabilities and set up filter software state
124262306a36Sopenharmony_ci * @filter_table_restore: Restore filters removed from hardware
124362306a36Sopenharmony_ci * @filter_table_remove: Remove filters from hardware and tear down software state
124462306a36Sopenharmony_ci * @filter_update_rx_scatter: Update filters after change to rx scatter setting
124562306a36Sopenharmony_ci * @filter_insert: add or replace a filter
124662306a36Sopenharmony_ci * @filter_remove_safe: remove a filter by ID, carefully
124762306a36Sopenharmony_ci * @filter_get_safe: retrieve a filter by ID, carefully
124862306a36Sopenharmony_ci * @filter_clear_rx: Remove all RX filters whose priority is less than or
124962306a36Sopenharmony_ci *	equal to the given priority and is not %EFX_FILTER_PRI_AUTO
125062306a36Sopenharmony_ci * @filter_count_rx_used: Get the number of filters in use at a given priority
125162306a36Sopenharmony_ci * @filter_get_rx_id_limit: Get maximum value of a filter id, plus 1
125262306a36Sopenharmony_ci * @filter_get_rx_ids: Get list of RX filters at a given priority
125362306a36Sopenharmony_ci * @filter_rfs_expire_one: Consider expiring a filter inserted for RFS.
125462306a36Sopenharmony_ci *	This must check whether the specified table entry is used by RFS
125562306a36Sopenharmony_ci *	and that rps_may_expire_flow() returns true for it.
125662306a36Sopenharmony_ci * @mtd_probe: Probe and add MTD partitions associated with this net device,
125762306a36Sopenharmony_ci *	 using efx_siena_mtd_add()
125862306a36Sopenharmony_ci * @mtd_rename: Set an MTD partition name using the net device name
125962306a36Sopenharmony_ci * @mtd_read: Read from an MTD partition
126062306a36Sopenharmony_ci * @mtd_erase: Erase part of an MTD partition
126162306a36Sopenharmony_ci * @mtd_write: Write to an MTD partition
126262306a36Sopenharmony_ci * @mtd_sync: Wait for write-back to complete on MTD partition.  This
126362306a36Sopenharmony_ci *	also notifies the driver that a writer has finished using this
126462306a36Sopenharmony_ci *	partition.
126562306a36Sopenharmony_ci * @ptp_write_host_time: Send host time to MC as part of sync protocol
126662306a36Sopenharmony_ci * @ptp_set_ts_sync_events: Enable or disable sync events for inline RX
126762306a36Sopenharmony_ci *	timestamping, possibly only temporarily for the purposes of a reset.
126862306a36Sopenharmony_ci * @ptp_set_ts_config: Set hardware timestamp configuration.  The flags
126962306a36Sopenharmony_ci *	and tx_type will already have been validated but this operation
127062306a36Sopenharmony_ci *	must validate and update rx_filter.
127162306a36Sopenharmony_ci * @get_phys_port_id: Get the underlying physical port id.
127262306a36Sopenharmony_ci * @set_mac_address: Set the MAC address of the device
127362306a36Sopenharmony_ci * @tso_versions: Returns mask of firmware-assisted TSO versions supported.
127462306a36Sopenharmony_ci *	If %NULL, then device does not support any TSO version.
127562306a36Sopenharmony_ci * @udp_tnl_push_ports: Push the list of UDP tunnel ports to the NIC if required.
127662306a36Sopenharmony_ci * @udp_tnl_has_port: Check if a port has been added as UDP tunnel
127762306a36Sopenharmony_ci * @print_additional_fwver: Dump NIC-specific additional FW version info
127862306a36Sopenharmony_ci * @sensor_event: Handle a sensor event from MCDI
127962306a36Sopenharmony_ci * @rx_recycle_ring_size: Size of the RX recycle ring
128062306a36Sopenharmony_ci * @revision: Hardware architecture revision
128162306a36Sopenharmony_ci * @txd_ptr_tbl_base: TX descriptor ring base address
128262306a36Sopenharmony_ci * @rxd_ptr_tbl_base: RX descriptor ring base address
128362306a36Sopenharmony_ci * @buf_tbl_base: Buffer table base address
128462306a36Sopenharmony_ci * @evq_ptr_tbl_base: Event queue pointer table base address
128562306a36Sopenharmony_ci * @evq_rptr_tbl_base: Event queue read-pointer table base address
128662306a36Sopenharmony_ci * @max_dma_mask: Maximum possible DMA mask
128762306a36Sopenharmony_ci * @rx_prefix_size: Size of RX prefix before packet data
128862306a36Sopenharmony_ci * @rx_hash_offset: Offset of RX flow hash within prefix
128962306a36Sopenharmony_ci * @rx_ts_offset: Offset of timestamp within prefix
129062306a36Sopenharmony_ci * @rx_buffer_padding: Size of padding at end of RX packet
129162306a36Sopenharmony_ci * @can_rx_scatter: NIC is able to scatter packets to multiple buffers
129262306a36Sopenharmony_ci * @always_rx_scatter: NIC will always scatter packets to multiple buffers
129362306a36Sopenharmony_ci * @option_descriptors: NIC supports TX option descriptors
129462306a36Sopenharmony_ci * @min_interrupt_mode: Lowest capability interrupt mode supported
129562306a36Sopenharmony_ci *	from &enum efx_int_mode.
129662306a36Sopenharmony_ci * @timer_period_max: Maximum period of interrupt timer (in ticks)
129762306a36Sopenharmony_ci * @offload_features: net_device feature flags for protocol offload
129862306a36Sopenharmony_ci *	features implemented in hardware
129962306a36Sopenharmony_ci * @mcdi_max_ver: Maximum MCDI version supported
130062306a36Sopenharmony_ci * @hwtstamp_filters: Mask of hardware timestamp filter types supported
130162306a36Sopenharmony_ci */
130262306a36Sopenharmony_cistruct efx_nic_type {
130362306a36Sopenharmony_ci	bool is_vf;
130462306a36Sopenharmony_ci	unsigned int (*mem_bar)(struct efx_nic *efx);
130562306a36Sopenharmony_ci	unsigned int (*mem_map_size)(struct efx_nic *efx);
130662306a36Sopenharmony_ci	int (*probe)(struct efx_nic *efx);
130762306a36Sopenharmony_ci	void (*remove)(struct efx_nic *efx);
130862306a36Sopenharmony_ci	int (*init)(struct efx_nic *efx);
130962306a36Sopenharmony_ci	int (*dimension_resources)(struct efx_nic *efx);
131062306a36Sopenharmony_ci	void (*fini)(struct efx_nic *efx);
131162306a36Sopenharmony_ci	void (*monitor)(struct efx_nic *efx);
131262306a36Sopenharmony_ci	enum reset_type (*map_reset_reason)(enum reset_type reason);
131362306a36Sopenharmony_ci	int (*map_reset_flags)(u32 *flags);
131462306a36Sopenharmony_ci	int (*reset)(struct efx_nic *efx, enum reset_type method);
131562306a36Sopenharmony_ci	int (*probe_port)(struct efx_nic *efx);
131662306a36Sopenharmony_ci	void (*remove_port)(struct efx_nic *efx);
131762306a36Sopenharmony_ci	bool (*handle_global_event)(struct efx_channel *channel, efx_qword_t *);
131862306a36Sopenharmony_ci	int (*fini_dmaq)(struct efx_nic *efx);
131962306a36Sopenharmony_ci	void (*prepare_flush)(struct efx_nic *efx);
132062306a36Sopenharmony_ci	void (*finish_flush)(struct efx_nic *efx);
132162306a36Sopenharmony_ci	void (*prepare_flr)(struct efx_nic *efx);
132262306a36Sopenharmony_ci	void (*finish_flr)(struct efx_nic *efx);
132362306a36Sopenharmony_ci	size_t (*describe_stats)(struct efx_nic *efx, u8 *names);
132462306a36Sopenharmony_ci	size_t (*update_stats)(struct efx_nic *efx, u64 *full_stats,
132562306a36Sopenharmony_ci			       struct rtnl_link_stats64 *core_stats);
132662306a36Sopenharmony_ci	size_t (*update_stats_atomic)(struct efx_nic *efx, u64 *full_stats,
132762306a36Sopenharmony_ci				      struct rtnl_link_stats64 *core_stats);
132862306a36Sopenharmony_ci	void (*start_stats)(struct efx_nic *efx);
132962306a36Sopenharmony_ci	void (*pull_stats)(struct efx_nic *efx);
133062306a36Sopenharmony_ci	void (*stop_stats)(struct efx_nic *efx);
133162306a36Sopenharmony_ci	void (*push_irq_moderation)(struct efx_channel *channel);
133262306a36Sopenharmony_ci	int (*reconfigure_port)(struct efx_nic *efx);
133362306a36Sopenharmony_ci	void (*prepare_enable_fc_tx)(struct efx_nic *efx);
133462306a36Sopenharmony_ci	int (*reconfigure_mac)(struct efx_nic *efx, bool mtu_only);
133562306a36Sopenharmony_ci	bool (*check_mac_fault)(struct efx_nic *efx);
133662306a36Sopenharmony_ci	void (*get_wol)(struct efx_nic *efx, struct ethtool_wolinfo *wol);
133762306a36Sopenharmony_ci	int (*set_wol)(struct efx_nic *efx, u32 type);
133862306a36Sopenharmony_ci	void (*resume_wol)(struct efx_nic *efx);
133962306a36Sopenharmony_ci	void (*get_fec_stats)(struct efx_nic *efx,
134062306a36Sopenharmony_ci			      struct ethtool_fec_stats *fec_stats);
134162306a36Sopenharmony_ci	unsigned int (*check_caps)(const struct efx_nic *efx,
134262306a36Sopenharmony_ci				   u8 flag,
134362306a36Sopenharmony_ci				   u32 offset);
134462306a36Sopenharmony_ci	int (*test_chip)(struct efx_nic *efx, struct efx_self_tests *tests);
134562306a36Sopenharmony_ci	int (*test_nvram)(struct efx_nic *efx);
134662306a36Sopenharmony_ci	void (*mcdi_request)(struct efx_nic *efx,
134762306a36Sopenharmony_ci			     const efx_dword_t *hdr, size_t hdr_len,
134862306a36Sopenharmony_ci			     const efx_dword_t *sdu, size_t sdu_len);
134962306a36Sopenharmony_ci	bool (*mcdi_poll_response)(struct efx_nic *efx);
135062306a36Sopenharmony_ci	void (*mcdi_read_response)(struct efx_nic *efx, efx_dword_t *pdu,
135162306a36Sopenharmony_ci				   size_t pdu_offset, size_t pdu_len);
135262306a36Sopenharmony_ci	int (*mcdi_poll_reboot)(struct efx_nic *efx);
135362306a36Sopenharmony_ci	void (*mcdi_reboot_detected)(struct efx_nic *efx);
135462306a36Sopenharmony_ci	void (*irq_enable_master)(struct efx_nic *efx);
135562306a36Sopenharmony_ci	int (*irq_test_generate)(struct efx_nic *efx);
135662306a36Sopenharmony_ci	void (*irq_disable_non_ev)(struct efx_nic *efx);
135762306a36Sopenharmony_ci	irqreturn_t (*irq_handle_msi)(int irq, void *dev_id);
135862306a36Sopenharmony_ci	irqreturn_t (*irq_handle_legacy)(int irq, void *dev_id);
135962306a36Sopenharmony_ci	int (*tx_probe)(struct efx_tx_queue *tx_queue);
136062306a36Sopenharmony_ci	void (*tx_init)(struct efx_tx_queue *tx_queue);
136162306a36Sopenharmony_ci	void (*tx_remove)(struct efx_tx_queue *tx_queue);
136262306a36Sopenharmony_ci	void (*tx_write)(struct efx_tx_queue *tx_queue);
136362306a36Sopenharmony_ci	netdev_tx_t (*tx_enqueue)(struct efx_tx_queue *tx_queue, struct sk_buff *skb);
136462306a36Sopenharmony_ci	unsigned int (*tx_limit_len)(struct efx_tx_queue *tx_queue,
136562306a36Sopenharmony_ci				     dma_addr_t dma_addr, unsigned int len);
136662306a36Sopenharmony_ci	int (*rx_push_rss_config)(struct efx_nic *efx, bool user,
136762306a36Sopenharmony_ci				  const u32 *rx_indir_table, const u8 *key);
136862306a36Sopenharmony_ci	int (*rx_pull_rss_config)(struct efx_nic *efx);
136962306a36Sopenharmony_ci	int (*rx_push_rss_context_config)(struct efx_nic *efx,
137062306a36Sopenharmony_ci					  struct efx_rss_context *ctx,
137162306a36Sopenharmony_ci					  const u32 *rx_indir_table,
137262306a36Sopenharmony_ci					  const u8 *key);
137362306a36Sopenharmony_ci	int (*rx_pull_rss_context_config)(struct efx_nic *efx,
137462306a36Sopenharmony_ci					  struct efx_rss_context *ctx);
137562306a36Sopenharmony_ci	void (*rx_restore_rss_contexts)(struct efx_nic *efx);
137662306a36Sopenharmony_ci	int (*rx_probe)(struct efx_rx_queue *rx_queue);
137762306a36Sopenharmony_ci	void (*rx_init)(struct efx_rx_queue *rx_queue);
137862306a36Sopenharmony_ci	void (*rx_remove)(struct efx_rx_queue *rx_queue);
137962306a36Sopenharmony_ci	void (*rx_write)(struct efx_rx_queue *rx_queue);
138062306a36Sopenharmony_ci	void (*rx_defer_refill)(struct efx_rx_queue *rx_queue);
138162306a36Sopenharmony_ci	void (*rx_packet)(struct efx_channel *channel);
138262306a36Sopenharmony_ci	bool (*rx_buf_hash_valid)(const u8 *prefix);
138362306a36Sopenharmony_ci	int (*ev_probe)(struct efx_channel *channel);
138462306a36Sopenharmony_ci	int (*ev_init)(struct efx_channel *channel);
138562306a36Sopenharmony_ci	void (*ev_fini)(struct efx_channel *channel);
138662306a36Sopenharmony_ci	void (*ev_remove)(struct efx_channel *channel);
138762306a36Sopenharmony_ci	int (*ev_process)(struct efx_channel *channel, int quota);
138862306a36Sopenharmony_ci	void (*ev_read_ack)(struct efx_channel *channel);
138962306a36Sopenharmony_ci	void (*ev_test_generate)(struct efx_channel *channel);
139062306a36Sopenharmony_ci	int (*filter_table_probe)(struct efx_nic *efx);
139162306a36Sopenharmony_ci	void (*filter_table_restore)(struct efx_nic *efx);
139262306a36Sopenharmony_ci	void (*filter_table_remove)(struct efx_nic *efx);
139362306a36Sopenharmony_ci	void (*filter_update_rx_scatter)(struct efx_nic *efx);
139462306a36Sopenharmony_ci	s32 (*filter_insert)(struct efx_nic *efx,
139562306a36Sopenharmony_ci			     struct efx_filter_spec *spec, bool replace);
139662306a36Sopenharmony_ci	int (*filter_remove_safe)(struct efx_nic *efx,
139762306a36Sopenharmony_ci				  enum efx_filter_priority priority,
139862306a36Sopenharmony_ci				  u32 filter_id);
139962306a36Sopenharmony_ci	int (*filter_get_safe)(struct efx_nic *efx,
140062306a36Sopenharmony_ci			       enum efx_filter_priority priority,
140162306a36Sopenharmony_ci			       u32 filter_id, struct efx_filter_spec *);
140262306a36Sopenharmony_ci	int (*filter_clear_rx)(struct efx_nic *efx,
140362306a36Sopenharmony_ci			       enum efx_filter_priority priority);
140462306a36Sopenharmony_ci	u32 (*filter_count_rx_used)(struct efx_nic *efx,
140562306a36Sopenharmony_ci				    enum efx_filter_priority priority);
140662306a36Sopenharmony_ci	u32 (*filter_get_rx_id_limit)(struct efx_nic *efx);
140762306a36Sopenharmony_ci	s32 (*filter_get_rx_ids)(struct efx_nic *efx,
140862306a36Sopenharmony_ci				 enum efx_filter_priority priority,
140962306a36Sopenharmony_ci				 u32 *buf, u32 size);
141062306a36Sopenharmony_ci#ifdef CONFIG_RFS_ACCEL
141162306a36Sopenharmony_ci	bool (*filter_rfs_expire_one)(struct efx_nic *efx, u32 flow_id,
141262306a36Sopenharmony_ci				      unsigned int index);
141362306a36Sopenharmony_ci#endif
141462306a36Sopenharmony_ci#ifdef CONFIG_SFC_SIENA_MTD
141562306a36Sopenharmony_ci	int (*mtd_probe)(struct efx_nic *efx);
141662306a36Sopenharmony_ci	void (*mtd_rename)(struct efx_mtd_partition *part);
141762306a36Sopenharmony_ci	int (*mtd_read)(struct mtd_info *mtd, loff_t start, size_t len,
141862306a36Sopenharmony_ci			size_t *retlen, u8 *buffer);
141962306a36Sopenharmony_ci	int (*mtd_erase)(struct mtd_info *mtd, loff_t start, size_t len);
142062306a36Sopenharmony_ci	int (*mtd_write)(struct mtd_info *mtd, loff_t start, size_t len,
142162306a36Sopenharmony_ci			 size_t *retlen, const u8 *buffer);
142262306a36Sopenharmony_ci	int (*mtd_sync)(struct mtd_info *mtd);
142362306a36Sopenharmony_ci#endif
142462306a36Sopenharmony_ci	void (*ptp_write_host_time)(struct efx_nic *efx, u32 host_time);
142562306a36Sopenharmony_ci	int (*ptp_set_ts_sync_events)(struct efx_nic *efx, bool en, bool temp);
142662306a36Sopenharmony_ci	int (*ptp_set_ts_config)(struct efx_nic *efx,
142762306a36Sopenharmony_ci				 struct hwtstamp_config *init);
142862306a36Sopenharmony_ci	int (*sriov_configure)(struct efx_nic *efx, int num_vfs);
142962306a36Sopenharmony_ci	int (*vlan_rx_add_vid)(struct efx_nic *efx, __be16 proto, u16 vid);
143062306a36Sopenharmony_ci	int (*vlan_rx_kill_vid)(struct efx_nic *efx, __be16 proto, u16 vid);
143162306a36Sopenharmony_ci	int (*get_phys_port_id)(struct efx_nic *efx,
143262306a36Sopenharmony_ci				struct netdev_phys_item_id *ppid);
143362306a36Sopenharmony_ci	int (*sriov_init)(struct efx_nic *efx);
143462306a36Sopenharmony_ci	void (*sriov_fini)(struct efx_nic *efx);
143562306a36Sopenharmony_ci	bool (*sriov_wanted)(struct efx_nic *efx);
143662306a36Sopenharmony_ci	void (*sriov_reset)(struct efx_nic *efx);
143762306a36Sopenharmony_ci	void (*sriov_flr)(struct efx_nic *efx, unsigned vf_i);
143862306a36Sopenharmony_ci	int (*sriov_set_vf_mac)(struct efx_nic *efx, int vf_i, const u8 *mac);
143962306a36Sopenharmony_ci	int (*sriov_set_vf_vlan)(struct efx_nic *efx, int vf_i, u16 vlan,
144062306a36Sopenharmony_ci				 u8 qos);
144162306a36Sopenharmony_ci	int (*sriov_set_vf_spoofchk)(struct efx_nic *efx, int vf_i,
144262306a36Sopenharmony_ci				     bool spoofchk);
144362306a36Sopenharmony_ci	int (*sriov_get_vf_config)(struct efx_nic *efx, int vf_i,
144462306a36Sopenharmony_ci				   struct ifla_vf_info *ivi);
144562306a36Sopenharmony_ci	int (*sriov_set_vf_link_state)(struct efx_nic *efx, int vf_i,
144662306a36Sopenharmony_ci				       int link_state);
144762306a36Sopenharmony_ci	int (*vswitching_probe)(struct efx_nic *efx);
144862306a36Sopenharmony_ci	int (*vswitching_restore)(struct efx_nic *efx);
144962306a36Sopenharmony_ci	void (*vswitching_remove)(struct efx_nic *efx);
145062306a36Sopenharmony_ci	int (*get_mac_address)(struct efx_nic *efx, unsigned char *perm_addr);
145162306a36Sopenharmony_ci	int (*set_mac_address)(struct efx_nic *efx);
145262306a36Sopenharmony_ci	u32 (*tso_versions)(struct efx_nic *efx);
145362306a36Sopenharmony_ci	int (*udp_tnl_push_ports)(struct efx_nic *efx);
145462306a36Sopenharmony_ci	bool (*udp_tnl_has_port)(struct efx_nic *efx, __be16 port);
145562306a36Sopenharmony_ci	size_t (*print_additional_fwver)(struct efx_nic *efx, char *buf,
145662306a36Sopenharmony_ci					 size_t len);
145762306a36Sopenharmony_ci	void (*sensor_event)(struct efx_nic *efx, efx_qword_t *ev);
145862306a36Sopenharmony_ci	unsigned int (*rx_recycle_ring_size)(const struct efx_nic *efx);
145962306a36Sopenharmony_ci
146062306a36Sopenharmony_ci	int revision;
146162306a36Sopenharmony_ci	unsigned int txd_ptr_tbl_base;
146262306a36Sopenharmony_ci	unsigned int rxd_ptr_tbl_base;
146362306a36Sopenharmony_ci	unsigned int buf_tbl_base;
146462306a36Sopenharmony_ci	unsigned int evq_ptr_tbl_base;
146562306a36Sopenharmony_ci	unsigned int evq_rptr_tbl_base;
146662306a36Sopenharmony_ci	u64 max_dma_mask;
146762306a36Sopenharmony_ci	unsigned int rx_prefix_size;
146862306a36Sopenharmony_ci	unsigned int rx_hash_offset;
146962306a36Sopenharmony_ci	unsigned int rx_ts_offset;
147062306a36Sopenharmony_ci	unsigned int rx_buffer_padding;
147162306a36Sopenharmony_ci	bool can_rx_scatter;
147262306a36Sopenharmony_ci	bool always_rx_scatter;
147362306a36Sopenharmony_ci	bool option_descriptors;
147462306a36Sopenharmony_ci	unsigned int min_interrupt_mode;
147562306a36Sopenharmony_ci	unsigned int timer_period_max;
147662306a36Sopenharmony_ci	netdev_features_t offload_features;
147762306a36Sopenharmony_ci	int mcdi_max_ver;
147862306a36Sopenharmony_ci	unsigned int max_rx_ip_filters;
147962306a36Sopenharmony_ci	u32 hwtstamp_filters;
148062306a36Sopenharmony_ci	unsigned int rx_hash_key_size;
148162306a36Sopenharmony_ci};
148262306a36Sopenharmony_ci
148362306a36Sopenharmony_ci/**************************************************************************
148462306a36Sopenharmony_ci *
148562306a36Sopenharmony_ci * Prototypes and inline functions
148662306a36Sopenharmony_ci *
148762306a36Sopenharmony_ci *************************************************************************/
148862306a36Sopenharmony_ci
148962306a36Sopenharmony_cistatic inline struct efx_channel *
149062306a36Sopenharmony_ciefx_get_channel(struct efx_nic *efx, unsigned index)
149162306a36Sopenharmony_ci{
149262306a36Sopenharmony_ci	EFX_WARN_ON_ONCE_PARANOID(index >= efx->n_channels);
149362306a36Sopenharmony_ci	return efx->channel[index];
149462306a36Sopenharmony_ci}
149562306a36Sopenharmony_ci
149662306a36Sopenharmony_ci/* Iterate over all used channels */
149762306a36Sopenharmony_ci#define efx_for_each_channel(_channel, _efx)				\
149862306a36Sopenharmony_ci	for (_channel = (_efx)->channel[0];				\
149962306a36Sopenharmony_ci	     _channel;							\
150062306a36Sopenharmony_ci	     _channel = (_channel->channel + 1 < (_efx)->n_channels) ?	\
150162306a36Sopenharmony_ci		     (_efx)->channel[_channel->channel + 1] : NULL)
150262306a36Sopenharmony_ci
150362306a36Sopenharmony_ci/* Iterate over all used channels in reverse */
150462306a36Sopenharmony_ci#define efx_for_each_channel_rev(_channel, _efx)			\
150562306a36Sopenharmony_ci	for (_channel = (_efx)->channel[(_efx)->n_channels - 1];	\
150662306a36Sopenharmony_ci	     _channel;							\
150762306a36Sopenharmony_ci	     _channel = _channel->channel ?				\
150862306a36Sopenharmony_ci		     (_efx)->channel[_channel->channel - 1] : NULL)
150962306a36Sopenharmony_ci
151062306a36Sopenharmony_cistatic inline struct efx_channel *
151162306a36Sopenharmony_ciefx_get_tx_channel(struct efx_nic *efx, unsigned int index)
151262306a36Sopenharmony_ci{
151362306a36Sopenharmony_ci	EFX_WARN_ON_ONCE_PARANOID(index >= efx->n_tx_channels);
151462306a36Sopenharmony_ci	return efx->channel[efx->tx_channel_offset + index];
151562306a36Sopenharmony_ci}
151662306a36Sopenharmony_ci
151762306a36Sopenharmony_cistatic inline struct efx_channel *
151862306a36Sopenharmony_ciefx_get_xdp_channel(struct efx_nic *efx, unsigned int index)
151962306a36Sopenharmony_ci{
152062306a36Sopenharmony_ci	EFX_WARN_ON_ONCE_PARANOID(index >= efx->n_xdp_channels);
152162306a36Sopenharmony_ci	return efx->channel[efx->xdp_channel_offset + index];
152262306a36Sopenharmony_ci}
152362306a36Sopenharmony_ci
152462306a36Sopenharmony_cistatic inline bool efx_channel_is_xdp_tx(struct efx_channel *channel)
152562306a36Sopenharmony_ci{
152662306a36Sopenharmony_ci	return channel->channel - channel->efx->xdp_channel_offset <
152762306a36Sopenharmony_ci	       channel->efx->n_xdp_channels;
152862306a36Sopenharmony_ci}
152962306a36Sopenharmony_ci
153062306a36Sopenharmony_cistatic inline bool efx_channel_has_tx_queues(struct efx_channel *channel)
153162306a36Sopenharmony_ci{
153262306a36Sopenharmony_ci	return channel && channel->channel >= channel->efx->tx_channel_offset;
153362306a36Sopenharmony_ci}
153462306a36Sopenharmony_ci
153562306a36Sopenharmony_cistatic inline unsigned int efx_channel_num_tx_queues(struct efx_channel *channel)
153662306a36Sopenharmony_ci{
153762306a36Sopenharmony_ci	if (efx_channel_is_xdp_tx(channel))
153862306a36Sopenharmony_ci		return channel->efx->xdp_tx_per_channel;
153962306a36Sopenharmony_ci	return channel->efx->tx_queues_per_channel;
154062306a36Sopenharmony_ci}
154162306a36Sopenharmony_ci
154262306a36Sopenharmony_cistatic inline struct efx_tx_queue *
154362306a36Sopenharmony_ciefx_channel_get_tx_queue(struct efx_channel *channel, unsigned int type)
154462306a36Sopenharmony_ci{
154562306a36Sopenharmony_ci	EFX_WARN_ON_ONCE_PARANOID(type >= EFX_TXQ_TYPES);
154662306a36Sopenharmony_ci	return channel->tx_queue_by_type[type];
154762306a36Sopenharmony_ci}
154862306a36Sopenharmony_ci
154962306a36Sopenharmony_cistatic inline struct efx_tx_queue *
155062306a36Sopenharmony_ciefx_get_tx_queue(struct efx_nic *efx, unsigned int index, unsigned int type)
155162306a36Sopenharmony_ci{
155262306a36Sopenharmony_ci	struct efx_channel *channel = efx_get_tx_channel(efx, index);
155362306a36Sopenharmony_ci
155462306a36Sopenharmony_ci	return efx_channel_get_tx_queue(channel, type);
155562306a36Sopenharmony_ci}
155662306a36Sopenharmony_ci
155762306a36Sopenharmony_ci/* Iterate over all TX queues belonging to a channel */
155862306a36Sopenharmony_ci#define efx_for_each_channel_tx_queue(_tx_queue, _channel)		\
155962306a36Sopenharmony_ci	if (!efx_channel_has_tx_queues(_channel))			\
156062306a36Sopenharmony_ci		;							\
156162306a36Sopenharmony_ci	else								\
156262306a36Sopenharmony_ci		for (_tx_queue = (_channel)->tx_queue;			\
156362306a36Sopenharmony_ci		     _tx_queue < (_channel)->tx_queue +			\
156462306a36Sopenharmony_ci				 efx_channel_num_tx_queues(_channel);		\
156562306a36Sopenharmony_ci		     _tx_queue++)
156662306a36Sopenharmony_ci
156762306a36Sopenharmony_cistatic inline bool efx_channel_has_rx_queue(struct efx_channel *channel)
156862306a36Sopenharmony_ci{
156962306a36Sopenharmony_ci	return channel->rx_queue.core_index >= 0;
157062306a36Sopenharmony_ci}
157162306a36Sopenharmony_ci
157262306a36Sopenharmony_cistatic inline struct efx_rx_queue *
157362306a36Sopenharmony_ciefx_channel_get_rx_queue(struct efx_channel *channel)
157462306a36Sopenharmony_ci{
157562306a36Sopenharmony_ci	EFX_WARN_ON_ONCE_PARANOID(!efx_channel_has_rx_queue(channel));
157662306a36Sopenharmony_ci	return &channel->rx_queue;
157762306a36Sopenharmony_ci}
157862306a36Sopenharmony_ci
157962306a36Sopenharmony_ci/* Iterate over all RX queues belonging to a channel */
158062306a36Sopenharmony_ci#define efx_for_each_channel_rx_queue(_rx_queue, _channel)		\
158162306a36Sopenharmony_ci	if (!efx_channel_has_rx_queue(_channel))			\
158262306a36Sopenharmony_ci		;							\
158362306a36Sopenharmony_ci	else								\
158462306a36Sopenharmony_ci		for (_rx_queue = &(_channel)->rx_queue;			\
158562306a36Sopenharmony_ci		     _rx_queue;						\
158662306a36Sopenharmony_ci		     _rx_queue = NULL)
158762306a36Sopenharmony_ci
158862306a36Sopenharmony_cistatic inline struct efx_channel *
158962306a36Sopenharmony_ciefx_rx_queue_channel(struct efx_rx_queue *rx_queue)
159062306a36Sopenharmony_ci{
159162306a36Sopenharmony_ci	return container_of(rx_queue, struct efx_channel, rx_queue);
159262306a36Sopenharmony_ci}
159362306a36Sopenharmony_ci
159462306a36Sopenharmony_cistatic inline int efx_rx_queue_index(struct efx_rx_queue *rx_queue)
159562306a36Sopenharmony_ci{
159662306a36Sopenharmony_ci	return efx_rx_queue_channel(rx_queue)->channel;
159762306a36Sopenharmony_ci}
159862306a36Sopenharmony_ci
159962306a36Sopenharmony_ci/* Returns a pointer to the specified receive buffer in the RX
160062306a36Sopenharmony_ci * descriptor queue.
160162306a36Sopenharmony_ci */
160262306a36Sopenharmony_cistatic inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
160362306a36Sopenharmony_ci						  unsigned int index)
160462306a36Sopenharmony_ci{
160562306a36Sopenharmony_ci	return &rx_queue->buffer[index];
160662306a36Sopenharmony_ci}
160762306a36Sopenharmony_ci
160862306a36Sopenharmony_cistatic inline struct efx_rx_buffer *
160962306a36Sopenharmony_ciefx_rx_buf_next(struct efx_rx_queue *rx_queue, struct efx_rx_buffer *rx_buf)
161062306a36Sopenharmony_ci{
161162306a36Sopenharmony_ci	if (unlikely(rx_buf == efx_rx_buffer(rx_queue, rx_queue->ptr_mask)))
161262306a36Sopenharmony_ci		return efx_rx_buffer(rx_queue, 0);
161362306a36Sopenharmony_ci	else
161462306a36Sopenharmony_ci		return rx_buf + 1;
161562306a36Sopenharmony_ci}
161662306a36Sopenharmony_ci
161762306a36Sopenharmony_ci/**
161862306a36Sopenharmony_ci * EFX_MAX_FRAME_LEN - calculate maximum frame length
161962306a36Sopenharmony_ci *
162062306a36Sopenharmony_ci * This calculates the maximum frame length that will be used for a
162162306a36Sopenharmony_ci * given MTU.  The frame length will be equal to the MTU plus a
162262306a36Sopenharmony_ci * constant amount of header space and padding.  This is the quantity
162362306a36Sopenharmony_ci * that the net driver will program into the MAC as the maximum frame
162462306a36Sopenharmony_ci * length.
162562306a36Sopenharmony_ci *
162662306a36Sopenharmony_ci * The 10G MAC requires 8-byte alignment on the frame
162762306a36Sopenharmony_ci * length, so we round up to the nearest 8.
162862306a36Sopenharmony_ci *
162962306a36Sopenharmony_ci * Re-clocking by the XGXS on RX can reduce an IPG to 32 bits (half an
163062306a36Sopenharmony_ci * XGMII cycle).  If the frame length reaches the maximum value in the
163162306a36Sopenharmony_ci * same cycle, the XMAC can miss the IPG altogether.  We work around
163262306a36Sopenharmony_ci * this by adding a further 16 bytes.
163362306a36Sopenharmony_ci */
163462306a36Sopenharmony_ci#define EFX_FRAME_PAD	16
163562306a36Sopenharmony_ci#define EFX_MAX_FRAME_LEN(mtu) \
163662306a36Sopenharmony_ci	(ALIGN(((mtu) + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN + EFX_FRAME_PAD), 8))
163762306a36Sopenharmony_ci
163862306a36Sopenharmony_cistatic inline bool efx_xmit_with_hwtstamp(struct sk_buff *skb)
163962306a36Sopenharmony_ci{
164062306a36Sopenharmony_ci	return skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP;
164162306a36Sopenharmony_ci}
164262306a36Sopenharmony_cistatic inline void efx_xmit_hwtstamp_pending(struct sk_buff *skb)
164362306a36Sopenharmony_ci{
164462306a36Sopenharmony_ci	skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
164562306a36Sopenharmony_ci}
164662306a36Sopenharmony_ci
164762306a36Sopenharmony_ci/* Get the max fill level of the TX queues on this channel */
164862306a36Sopenharmony_cistatic inline unsigned int
164962306a36Sopenharmony_ciefx_channel_tx_fill_level(struct efx_channel *channel)
165062306a36Sopenharmony_ci{
165162306a36Sopenharmony_ci	struct efx_tx_queue *tx_queue;
165262306a36Sopenharmony_ci	unsigned int fill_level = 0;
165362306a36Sopenharmony_ci
165462306a36Sopenharmony_ci	efx_for_each_channel_tx_queue(tx_queue, channel)
165562306a36Sopenharmony_ci		fill_level = max(fill_level,
165662306a36Sopenharmony_ci				 tx_queue->insert_count - tx_queue->read_count);
165762306a36Sopenharmony_ci
165862306a36Sopenharmony_ci	return fill_level;
165962306a36Sopenharmony_ci}
166062306a36Sopenharmony_ci
166162306a36Sopenharmony_ci/* Conservative approximation of efx_channel_tx_fill_level using cached value */
166262306a36Sopenharmony_cistatic inline unsigned int
166362306a36Sopenharmony_ciefx_channel_tx_old_fill_level(struct efx_channel *channel)
166462306a36Sopenharmony_ci{
166562306a36Sopenharmony_ci	struct efx_tx_queue *tx_queue;
166662306a36Sopenharmony_ci	unsigned int fill_level = 0;
166762306a36Sopenharmony_ci
166862306a36Sopenharmony_ci	efx_for_each_channel_tx_queue(tx_queue, channel)
166962306a36Sopenharmony_ci		fill_level = max(fill_level,
167062306a36Sopenharmony_ci				 tx_queue->insert_count - tx_queue->old_read_count);
167162306a36Sopenharmony_ci
167262306a36Sopenharmony_ci	return fill_level;
167362306a36Sopenharmony_ci}
167462306a36Sopenharmony_ci
167562306a36Sopenharmony_ci/* Get all supported features.
167662306a36Sopenharmony_ci * If a feature is not fixed, it is present in hw_features.
167762306a36Sopenharmony_ci * If a feature is fixed, it does not present in hw_features, but
167862306a36Sopenharmony_ci * always in features.
167962306a36Sopenharmony_ci */
168062306a36Sopenharmony_cistatic inline netdev_features_t efx_supported_features(const struct efx_nic *efx)
168162306a36Sopenharmony_ci{
168262306a36Sopenharmony_ci	const struct net_device *net_dev = efx->net_dev;
168362306a36Sopenharmony_ci
168462306a36Sopenharmony_ci	return net_dev->features | net_dev->hw_features;
168562306a36Sopenharmony_ci}
168662306a36Sopenharmony_ci
168762306a36Sopenharmony_ci/* Get the current TX queue insert index. */
168862306a36Sopenharmony_cistatic inline unsigned int
168962306a36Sopenharmony_ciefx_tx_queue_get_insert_index(const struct efx_tx_queue *tx_queue)
169062306a36Sopenharmony_ci{
169162306a36Sopenharmony_ci	return tx_queue->insert_count & tx_queue->ptr_mask;
169262306a36Sopenharmony_ci}
169362306a36Sopenharmony_ci
169462306a36Sopenharmony_ci/* Get a TX buffer. */
169562306a36Sopenharmony_cistatic inline struct efx_tx_buffer *
169662306a36Sopenharmony_ci__efx_tx_queue_get_insert_buffer(const struct efx_tx_queue *tx_queue)
169762306a36Sopenharmony_ci{
169862306a36Sopenharmony_ci	return &tx_queue->buffer[efx_tx_queue_get_insert_index(tx_queue)];
169962306a36Sopenharmony_ci}
170062306a36Sopenharmony_ci
170162306a36Sopenharmony_ci/* Get a TX buffer, checking it's not currently in use. */
170262306a36Sopenharmony_cistatic inline struct efx_tx_buffer *
170362306a36Sopenharmony_ciefx_tx_queue_get_insert_buffer(const struct efx_tx_queue *tx_queue)
170462306a36Sopenharmony_ci{
170562306a36Sopenharmony_ci	struct efx_tx_buffer *buffer =
170662306a36Sopenharmony_ci		__efx_tx_queue_get_insert_buffer(tx_queue);
170762306a36Sopenharmony_ci
170862306a36Sopenharmony_ci	EFX_WARN_ON_ONCE_PARANOID(buffer->len);
170962306a36Sopenharmony_ci	EFX_WARN_ON_ONCE_PARANOID(buffer->flags);
171062306a36Sopenharmony_ci	EFX_WARN_ON_ONCE_PARANOID(buffer->unmap_len);
171162306a36Sopenharmony_ci
171262306a36Sopenharmony_ci	return buffer;
171362306a36Sopenharmony_ci}
171462306a36Sopenharmony_ci
171562306a36Sopenharmony_ci#endif /* EFX_NET_DRIVER_H */
1716