18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/****************************************************************************
38c2ecf20Sopenharmony_ci * Driver for Solarflare network controllers and boards
48c2ecf20Sopenharmony_ci * Copyright 2005-2006 Fen Systems Ltd.
58c2ecf20Sopenharmony_ci * Copyright 2005-2013 Solarflare Communications Inc.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci/* Common definitions for all Efx net driver code */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef EF4_NET_DRIVER_H
118c2ecf20Sopenharmony_ci#define EF4_NET_DRIVER_H
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
148c2ecf20Sopenharmony_ci#include <linux/etherdevice.h>
158c2ecf20Sopenharmony_ci#include <linux/ethtool.h>
168c2ecf20Sopenharmony_ci#include <linux/if_vlan.h>
178c2ecf20Sopenharmony_ci#include <linux/timer.h>
188c2ecf20Sopenharmony_ci#include <linux/mdio.h>
198c2ecf20Sopenharmony_ci#include <linux/list.h>
208c2ecf20Sopenharmony_ci#include <linux/pci.h>
218c2ecf20Sopenharmony_ci#include <linux/device.h>
228c2ecf20Sopenharmony_ci#include <linux/highmem.h>
238c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
248c2ecf20Sopenharmony_ci#include <linux/mutex.h>
258c2ecf20Sopenharmony_ci#include <linux/rwsem.h>
268c2ecf20Sopenharmony_ci#include <linux/vmalloc.h>
278c2ecf20Sopenharmony_ci#include <linux/i2c.h>
288c2ecf20Sopenharmony_ci#include <linux/mtd/mtd.h>
298c2ecf20Sopenharmony_ci#include <net/busy_poll.h>
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#include "enum.h"
328c2ecf20Sopenharmony_ci#include "bitfield.h"
338c2ecf20Sopenharmony_ci#include "filter.h"
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/**************************************************************************
368c2ecf20Sopenharmony_ci *
378c2ecf20Sopenharmony_ci * Build definitions
388c2ecf20Sopenharmony_ci *
398c2ecf20Sopenharmony_ci **************************************************************************/
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define EF4_DRIVER_VERSION	"4.1"
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#ifdef DEBUG
448c2ecf20Sopenharmony_ci#define EF4_BUG_ON_PARANOID(x) BUG_ON(x)
458c2ecf20Sopenharmony_ci#define EF4_WARN_ON_PARANOID(x) WARN_ON(x)
468c2ecf20Sopenharmony_ci#else
478c2ecf20Sopenharmony_ci#define EF4_BUG_ON_PARANOID(x) do {} while (0)
488c2ecf20Sopenharmony_ci#define EF4_WARN_ON_PARANOID(x) do {} while (0)
498c2ecf20Sopenharmony_ci#endif
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/**************************************************************************
528c2ecf20Sopenharmony_ci *
538c2ecf20Sopenharmony_ci * Efx data structures
548c2ecf20Sopenharmony_ci *
558c2ecf20Sopenharmony_ci **************************************************************************/
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#define EF4_MAX_CHANNELS 32U
588c2ecf20Sopenharmony_ci#define EF4_MAX_RX_QUEUES EF4_MAX_CHANNELS
598c2ecf20Sopenharmony_ci#define EF4_EXTRA_CHANNEL_IOV	0
608c2ecf20Sopenharmony_ci#define EF4_EXTRA_CHANNEL_PTP	1
618c2ecf20Sopenharmony_ci#define EF4_MAX_EXTRA_CHANNELS	2U
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/* Checksum generation is a per-queue option in hardware, so each
648c2ecf20Sopenharmony_ci * queue visible to the networking core is backed by two hardware TX
658c2ecf20Sopenharmony_ci * queues. */
668c2ecf20Sopenharmony_ci#define EF4_MAX_TX_TC		2
678c2ecf20Sopenharmony_ci#define EF4_MAX_CORE_TX_QUEUES	(EF4_MAX_TX_TC * EF4_MAX_CHANNELS)
688c2ecf20Sopenharmony_ci#define EF4_TXQ_TYPE_OFFLOAD	1	/* flag */
698c2ecf20Sopenharmony_ci#define EF4_TXQ_TYPE_HIGHPRI	2	/* flag */
708c2ecf20Sopenharmony_ci#define EF4_TXQ_TYPES		4
718c2ecf20Sopenharmony_ci#define EF4_MAX_TX_QUEUES	(EF4_TXQ_TYPES * EF4_MAX_CHANNELS)
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/* Maximum possible MTU the driver supports */
748c2ecf20Sopenharmony_ci#define EF4_MAX_MTU (9 * 1024)
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci/* Minimum MTU, from RFC791 (IP) */
778c2ecf20Sopenharmony_ci#define EF4_MIN_MTU 68
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci/* Size of an RX scatter buffer.  Small enough to pack 2 into a 4K page,
808c2ecf20Sopenharmony_ci * and should be a multiple of the cache line size.
818c2ecf20Sopenharmony_ci */
828c2ecf20Sopenharmony_ci#define EF4_RX_USR_BUF_SIZE	(2048 - 256)
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci/* If possible, we should ensure cache line alignment at start and end
858c2ecf20Sopenharmony_ci * of every buffer.  Otherwise, we just need to ensure 4-byte
868c2ecf20Sopenharmony_ci * alignment of the network header.
878c2ecf20Sopenharmony_ci */
888c2ecf20Sopenharmony_ci#if NET_IP_ALIGN == 0
898c2ecf20Sopenharmony_ci#define EF4_RX_BUF_ALIGNMENT	L1_CACHE_BYTES
908c2ecf20Sopenharmony_ci#else
918c2ecf20Sopenharmony_ci#define EF4_RX_BUF_ALIGNMENT	4
928c2ecf20Sopenharmony_ci#endif
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistruct ef4_self_tests;
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/**
978c2ecf20Sopenharmony_ci * struct ef4_buffer - A general-purpose DMA buffer
988c2ecf20Sopenharmony_ci * @addr: host base address of the buffer
998c2ecf20Sopenharmony_ci * @dma_addr: DMA base address of the buffer
1008c2ecf20Sopenharmony_ci * @len: Buffer length, in bytes
1018c2ecf20Sopenharmony_ci *
1028c2ecf20Sopenharmony_ci * The NIC uses these buffers for its interrupt status registers and
1038c2ecf20Sopenharmony_ci * MAC stats dumps.
1048c2ecf20Sopenharmony_ci */
1058c2ecf20Sopenharmony_cistruct ef4_buffer {
1068c2ecf20Sopenharmony_ci	void *addr;
1078c2ecf20Sopenharmony_ci	dma_addr_t dma_addr;
1088c2ecf20Sopenharmony_ci	unsigned int len;
1098c2ecf20Sopenharmony_ci};
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci/**
1128c2ecf20Sopenharmony_ci * struct ef4_special_buffer - DMA buffer entered into buffer table
1138c2ecf20Sopenharmony_ci * @buf: Standard &struct ef4_buffer
1148c2ecf20Sopenharmony_ci * @index: Buffer index within controller;s buffer table
1158c2ecf20Sopenharmony_ci * @entries: Number of buffer table entries
1168c2ecf20Sopenharmony_ci *
1178c2ecf20Sopenharmony_ci * The NIC has a buffer table that maps buffers of size %EF4_BUF_SIZE.
1188c2ecf20Sopenharmony_ci * Event and descriptor rings are addressed via one or more buffer
1198c2ecf20Sopenharmony_ci * table entries (and so can be physically non-contiguous, although we
1208c2ecf20Sopenharmony_ci * currently do not take advantage of that).  On Falcon and Siena we
1218c2ecf20Sopenharmony_ci * have to take care of allocating and initialising the entries
1228c2ecf20Sopenharmony_ci * ourselves.  On later hardware this is managed by the firmware and
1238c2ecf20Sopenharmony_ci * @index and @entries are left as 0.
1248c2ecf20Sopenharmony_ci */
1258c2ecf20Sopenharmony_cistruct ef4_special_buffer {
1268c2ecf20Sopenharmony_ci	struct ef4_buffer buf;
1278c2ecf20Sopenharmony_ci	unsigned int index;
1288c2ecf20Sopenharmony_ci	unsigned int entries;
1298c2ecf20Sopenharmony_ci};
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/**
1328c2ecf20Sopenharmony_ci * struct ef4_tx_buffer - buffer state for a TX descriptor
1338c2ecf20Sopenharmony_ci * @skb: When @flags & %EF4_TX_BUF_SKB, the associated socket buffer to be
1348c2ecf20Sopenharmony_ci *	freed when descriptor completes
1358c2ecf20Sopenharmony_ci * @option: When @flags & %EF4_TX_BUF_OPTION, a NIC-specific option descriptor.
1368c2ecf20Sopenharmony_ci * @dma_addr: DMA address of the fragment.
1378c2ecf20Sopenharmony_ci * @flags: Flags for allocation and DMA mapping type
1388c2ecf20Sopenharmony_ci * @len: Length of this fragment.
1398c2ecf20Sopenharmony_ci *	This field is zero when the queue slot is empty.
1408c2ecf20Sopenharmony_ci * @unmap_len: Length of this fragment to unmap
1418c2ecf20Sopenharmony_ci * @dma_offset: Offset of @dma_addr from the address of the backing DMA mapping.
1428c2ecf20Sopenharmony_ci * Only valid if @unmap_len != 0.
1438c2ecf20Sopenharmony_ci */
1448c2ecf20Sopenharmony_cistruct ef4_tx_buffer {
1458c2ecf20Sopenharmony_ci	const struct sk_buff *skb;
1468c2ecf20Sopenharmony_ci	union {
1478c2ecf20Sopenharmony_ci		ef4_qword_t option;
1488c2ecf20Sopenharmony_ci		dma_addr_t dma_addr;
1498c2ecf20Sopenharmony_ci	};
1508c2ecf20Sopenharmony_ci	unsigned short flags;
1518c2ecf20Sopenharmony_ci	unsigned short len;
1528c2ecf20Sopenharmony_ci	unsigned short unmap_len;
1538c2ecf20Sopenharmony_ci	unsigned short dma_offset;
1548c2ecf20Sopenharmony_ci};
1558c2ecf20Sopenharmony_ci#define EF4_TX_BUF_CONT		1	/* not last descriptor of packet */
1568c2ecf20Sopenharmony_ci#define EF4_TX_BUF_SKB		2	/* buffer is last part of skb */
1578c2ecf20Sopenharmony_ci#define EF4_TX_BUF_MAP_SINGLE	8	/* buffer was mapped with dma_map_single() */
1588c2ecf20Sopenharmony_ci#define EF4_TX_BUF_OPTION	0x10	/* empty buffer for option descriptor */
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci/**
1618c2ecf20Sopenharmony_ci * struct ef4_tx_queue - An Efx TX queue
1628c2ecf20Sopenharmony_ci *
1638c2ecf20Sopenharmony_ci * This is a ring buffer of TX fragments.
1648c2ecf20Sopenharmony_ci * Since the TX completion path always executes on the same
1658c2ecf20Sopenharmony_ci * CPU and the xmit path can operate on different CPUs,
1668c2ecf20Sopenharmony_ci * performance is increased by ensuring that the completion
1678c2ecf20Sopenharmony_ci * path and the xmit path operate on different cache lines.
1688c2ecf20Sopenharmony_ci * This is particularly important if the xmit path is always
1698c2ecf20Sopenharmony_ci * executing on one CPU which is different from the completion
1708c2ecf20Sopenharmony_ci * path.  There is also a cache line for members which are
1718c2ecf20Sopenharmony_ci * read but not written on the fast path.
1728c2ecf20Sopenharmony_ci *
1738c2ecf20Sopenharmony_ci * @efx: The associated Efx NIC
1748c2ecf20Sopenharmony_ci * @queue: DMA queue number
1758c2ecf20Sopenharmony_ci * @channel: The associated channel
1768c2ecf20Sopenharmony_ci * @core_txq: The networking core TX queue structure
1778c2ecf20Sopenharmony_ci * @buffer: The software buffer ring
1788c2ecf20Sopenharmony_ci * @cb_page: Array of pages of copy buffers.  Carved up according to
1798c2ecf20Sopenharmony_ci *	%EF4_TX_CB_ORDER into %EF4_TX_CB_SIZE-sized chunks.
1808c2ecf20Sopenharmony_ci * @txd: The hardware descriptor ring
1818c2ecf20Sopenharmony_ci * @ptr_mask: The size of the ring minus 1.
1828c2ecf20Sopenharmony_ci * @initialised: Has hardware queue been initialised?
1838c2ecf20Sopenharmony_ci * @tx_min_size: Minimum transmit size for this queue. Depends on HW.
1848c2ecf20Sopenharmony_ci * @read_count: Current read pointer.
1858c2ecf20Sopenharmony_ci *	This is the number of buffers that have been removed from both rings.
1868c2ecf20Sopenharmony_ci * @old_write_count: The value of @write_count when last checked.
1878c2ecf20Sopenharmony_ci *	This is here for performance reasons.  The xmit path will
1888c2ecf20Sopenharmony_ci *	only get the up-to-date value of @write_count if this
1898c2ecf20Sopenharmony_ci *	variable indicates that the queue is empty.  This is to
1908c2ecf20Sopenharmony_ci *	avoid cache-line ping-pong between the xmit path and the
1918c2ecf20Sopenharmony_ci *	completion path.
1928c2ecf20Sopenharmony_ci * @merge_events: Number of TX merged completion events
1938c2ecf20Sopenharmony_ci * @insert_count: Current insert pointer
1948c2ecf20Sopenharmony_ci *	This is the number of buffers that have been added to the
1958c2ecf20Sopenharmony_ci *	software ring.
1968c2ecf20Sopenharmony_ci * @write_count: Current write pointer
1978c2ecf20Sopenharmony_ci *	This is the number of buffers that have been added to the
1988c2ecf20Sopenharmony_ci *	hardware ring.
1998c2ecf20Sopenharmony_ci * @old_read_count: The value of read_count when last checked.
2008c2ecf20Sopenharmony_ci *	This is here for performance reasons.  The xmit path will
2018c2ecf20Sopenharmony_ci *	only get the up-to-date value of read_count if this
2028c2ecf20Sopenharmony_ci *	variable indicates that the queue is full.  This is to
2038c2ecf20Sopenharmony_ci *	avoid cache-line ping-pong between the xmit path and the
2048c2ecf20Sopenharmony_ci *	completion path.
2058c2ecf20Sopenharmony_ci * @pushes: Number of times the TX push feature has been used
2068c2ecf20Sopenharmony_ci * @xmit_more_available: Are any packets waiting to be pushed to the NIC
2078c2ecf20Sopenharmony_ci * @cb_packets: Number of times the TX copybreak feature has been used
2088c2ecf20Sopenharmony_ci * @empty_read_count: If the completion path has seen the queue as empty
2098c2ecf20Sopenharmony_ci *	and the transmission path has not yet checked this, the value of
2108c2ecf20Sopenharmony_ci *	@read_count bitwise-added to %EF4_EMPTY_COUNT_VALID; otherwise 0.
2118c2ecf20Sopenharmony_ci */
2128c2ecf20Sopenharmony_cistruct ef4_tx_queue {
2138c2ecf20Sopenharmony_ci	/* Members which don't change on the fast path */
2148c2ecf20Sopenharmony_ci	struct ef4_nic *efx ____cacheline_aligned_in_smp;
2158c2ecf20Sopenharmony_ci	unsigned queue;
2168c2ecf20Sopenharmony_ci	struct ef4_channel *channel;
2178c2ecf20Sopenharmony_ci	struct netdev_queue *core_txq;
2188c2ecf20Sopenharmony_ci	struct ef4_tx_buffer *buffer;
2198c2ecf20Sopenharmony_ci	struct ef4_buffer *cb_page;
2208c2ecf20Sopenharmony_ci	struct ef4_special_buffer txd;
2218c2ecf20Sopenharmony_ci	unsigned int ptr_mask;
2228c2ecf20Sopenharmony_ci	bool initialised;
2238c2ecf20Sopenharmony_ci	unsigned int tx_min_size;
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci	/* Function pointers used in the fast path. */
2268c2ecf20Sopenharmony_ci	int (*handle_tso)(struct ef4_tx_queue*, struct sk_buff*, bool *);
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci	/* Members used mainly on the completion path */
2298c2ecf20Sopenharmony_ci	unsigned int read_count ____cacheline_aligned_in_smp;
2308c2ecf20Sopenharmony_ci	unsigned int old_write_count;
2318c2ecf20Sopenharmony_ci	unsigned int merge_events;
2328c2ecf20Sopenharmony_ci	unsigned int bytes_compl;
2338c2ecf20Sopenharmony_ci	unsigned int pkts_compl;
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci	/* Members used only on the xmit path */
2368c2ecf20Sopenharmony_ci	unsigned int insert_count ____cacheline_aligned_in_smp;
2378c2ecf20Sopenharmony_ci	unsigned int write_count;
2388c2ecf20Sopenharmony_ci	unsigned int old_read_count;
2398c2ecf20Sopenharmony_ci	unsigned int pushes;
2408c2ecf20Sopenharmony_ci	bool xmit_more_available;
2418c2ecf20Sopenharmony_ci	unsigned int cb_packets;
2428c2ecf20Sopenharmony_ci	/* Statistics to supplement MAC stats */
2438c2ecf20Sopenharmony_ci	unsigned long tx_packets;
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci	/* Members shared between paths and sometimes updated */
2468c2ecf20Sopenharmony_ci	unsigned int empty_read_count ____cacheline_aligned_in_smp;
2478c2ecf20Sopenharmony_ci#define EF4_EMPTY_COUNT_VALID 0x80000000
2488c2ecf20Sopenharmony_ci	atomic_t flush_outstanding;
2498c2ecf20Sopenharmony_ci};
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci#define EF4_TX_CB_ORDER	7
2528c2ecf20Sopenharmony_ci#define EF4_TX_CB_SIZE	(1 << EF4_TX_CB_ORDER) - NET_IP_ALIGN
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci/**
2558c2ecf20Sopenharmony_ci * struct ef4_rx_buffer - An Efx RX data buffer
2568c2ecf20Sopenharmony_ci * @dma_addr: DMA base address of the buffer
2578c2ecf20Sopenharmony_ci * @page: The associated page buffer.
2588c2ecf20Sopenharmony_ci *	Will be %NULL if the buffer slot is currently free.
2598c2ecf20Sopenharmony_ci * @page_offset: If pending: offset in @page of DMA base address.
2608c2ecf20Sopenharmony_ci *	If completed: offset in @page of Ethernet header.
2618c2ecf20Sopenharmony_ci * @len: If pending: length for DMA descriptor.
2628c2ecf20Sopenharmony_ci *	If completed: received length, excluding hash prefix.
2638c2ecf20Sopenharmony_ci * @flags: Flags for buffer and packet state.  These are only set on the
2648c2ecf20Sopenharmony_ci *	first buffer of a scattered packet.
2658c2ecf20Sopenharmony_ci */
2668c2ecf20Sopenharmony_cistruct ef4_rx_buffer {
2678c2ecf20Sopenharmony_ci	dma_addr_t dma_addr;
2688c2ecf20Sopenharmony_ci	struct page *page;
2698c2ecf20Sopenharmony_ci	u16 page_offset;
2708c2ecf20Sopenharmony_ci	u16 len;
2718c2ecf20Sopenharmony_ci	u16 flags;
2728c2ecf20Sopenharmony_ci};
2738c2ecf20Sopenharmony_ci#define EF4_RX_BUF_LAST_IN_PAGE	0x0001
2748c2ecf20Sopenharmony_ci#define EF4_RX_PKT_CSUMMED	0x0002
2758c2ecf20Sopenharmony_ci#define EF4_RX_PKT_DISCARD	0x0004
2768c2ecf20Sopenharmony_ci#define EF4_RX_PKT_TCP		0x0040
2778c2ecf20Sopenharmony_ci#define EF4_RX_PKT_PREFIX_LEN	0x0080	/* length is in prefix only */
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci/**
2808c2ecf20Sopenharmony_ci * struct ef4_rx_page_state - Page-based rx buffer state
2818c2ecf20Sopenharmony_ci *
2828c2ecf20Sopenharmony_ci * Inserted at the start of every page allocated for receive buffers.
2838c2ecf20Sopenharmony_ci * Used to facilitate sharing dma mappings between recycled rx buffers
2848c2ecf20Sopenharmony_ci * and those passed up to the kernel.
2858c2ecf20Sopenharmony_ci *
2868c2ecf20Sopenharmony_ci * @dma_addr: The dma address of this page.
2878c2ecf20Sopenharmony_ci */
2888c2ecf20Sopenharmony_cistruct ef4_rx_page_state {
2898c2ecf20Sopenharmony_ci	dma_addr_t dma_addr;
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci	unsigned int __pad[] ____cacheline_aligned;
2928c2ecf20Sopenharmony_ci};
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci/**
2958c2ecf20Sopenharmony_ci * struct ef4_rx_queue - An Efx RX queue
2968c2ecf20Sopenharmony_ci * @efx: The associated Efx NIC
2978c2ecf20Sopenharmony_ci * @core_index:  Index of network core RX queue.  Will be >= 0 iff this
2988c2ecf20Sopenharmony_ci *	is associated with a real RX queue.
2998c2ecf20Sopenharmony_ci * @buffer: The software buffer ring
3008c2ecf20Sopenharmony_ci * @rxd: The hardware descriptor ring
3018c2ecf20Sopenharmony_ci * @ptr_mask: The size of the ring minus 1.
3028c2ecf20Sopenharmony_ci * @refill_enabled: Enable refill whenever fill level is low
3038c2ecf20Sopenharmony_ci * @flush_pending: Set when a RX flush is pending. Has the same lifetime as
3048c2ecf20Sopenharmony_ci *	@rxq_flush_pending.
3058c2ecf20Sopenharmony_ci * @added_count: Number of buffers added to the receive queue.
3068c2ecf20Sopenharmony_ci * @notified_count: Number of buffers given to NIC (<= @added_count).
3078c2ecf20Sopenharmony_ci * @removed_count: Number of buffers removed from the receive queue.
3088c2ecf20Sopenharmony_ci * @scatter_n: Used by NIC specific receive code.
3098c2ecf20Sopenharmony_ci * @scatter_len: Used by NIC specific receive code.
3108c2ecf20Sopenharmony_ci * @page_ring: The ring to store DMA mapped pages for reuse.
3118c2ecf20Sopenharmony_ci * @page_add: Counter to calculate the write pointer for the recycle ring.
3128c2ecf20Sopenharmony_ci * @page_remove: Counter to calculate the read pointer for the recycle ring.
3138c2ecf20Sopenharmony_ci * @page_recycle_count: The number of pages that have been recycled.
3148c2ecf20Sopenharmony_ci * @page_recycle_failed: The number of pages that couldn't be recycled because
3158c2ecf20Sopenharmony_ci *      the kernel still held a reference to them.
3168c2ecf20Sopenharmony_ci * @page_recycle_full: The number of pages that were released because the
3178c2ecf20Sopenharmony_ci *      recycle ring was full.
3188c2ecf20Sopenharmony_ci * @page_ptr_mask: The number of pages in the RX recycle ring minus 1.
3198c2ecf20Sopenharmony_ci * @max_fill: RX descriptor maximum fill level (<= ring size)
3208c2ecf20Sopenharmony_ci * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
3218c2ecf20Sopenharmony_ci *	(<= @max_fill)
3228c2ecf20Sopenharmony_ci * @min_fill: RX descriptor minimum non-zero fill level.
3238c2ecf20Sopenharmony_ci *	This records the minimum fill level observed when a ring
3248c2ecf20Sopenharmony_ci *	refill was triggered.
3258c2ecf20Sopenharmony_ci * @recycle_count: RX buffer recycle counter.
3268c2ecf20Sopenharmony_ci * @slow_fill: Timer used to defer ef4_nic_generate_fill_event().
3278c2ecf20Sopenharmony_ci */
3288c2ecf20Sopenharmony_cistruct ef4_rx_queue {
3298c2ecf20Sopenharmony_ci	struct ef4_nic *efx;
3308c2ecf20Sopenharmony_ci	int core_index;
3318c2ecf20Sopenharmony_ci	struct ef4_rx_buffer *buffer;
3328c2ecf20Sopenharmony_ci	struct ef4_special_buffer rxd;
3338c2ecf20Sopenharmony_ci	unsigned int ptr_mask;
3348c2ecf20Sopenharmony_ci	bool refill_enabled;
3358c2ecf20Sopenharmony_ci	bool flush_pending;
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	unsigned int added_count;
3388c2ecf20Sopenharmony_ci	unsigned int notified_count;
3398c2ecf20Sopenharmony_ci	unsigned int removed_count;
3408c2ecf20Sopenharmony_ci	unsigned int scatter_n;
3418c2ecf20Sopenharmony_ci	unsigned int scatter_len;
3428c2ecf20Sopenharmony_ci	struct page **page_ring;
3438c2ecf20Sopenharmony_ci	unsigned int page_add;
3448c2ecf20Sopenharmony_ci	unsigned int page_remove;
3458c2ecf20Sopenharmony_ci	unsigned int page_recycle_count;
3468c2ecf20Sopenharmony_ci	unsigned int page_recycle_failed;
3478c2ecf20Sopenharmony_ci	unsigned int page_recycle_full;
3488c2ecf20Sopenharmony_ci	unsigned int page_ptr_mask;
3498c2ecf20Sopenharmony_ci	unsigned int max_fill;
3508c2ecf20Sopenharmony_ci	unsigned int fast_fill_trigger;
3518c2ecf20Sopenharmony_ci	unsigned int min_fill;
3528c2ecf20Sopenharmony_ci	unsigned int min_overfill;
3538c2ecf20Sopenharmony_ci	unsigned int recycle_count;
3548c2ecf20Sopenharmony_ci	struct timer_list slow_fill;
3558c2ecf20Sopenharmony_ci	unsigned int slow_fill_count;
3568c2ecf20Sopenharmony_ci	/* Statistics to supplement MAC stats */
3578c2ecf20Sopenharmony_ci	unsigned long rx_packets;
3588c2ecf20Sopenharmony_ci};
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci/**
3618c2ecf20Sopenharmony_ci * struct ef4_channel - An Efx channel
3628c2ecf20Sopenharmony_ci *
3638c2ecf20Sopenharmony_ci * A channel comprises an event queue, at least one TX queue, at least
3648c2ecf20Sopenharmony_ci * one RX queue, and an associated tasklet for processing the event
3658c2ecf20Sopenharmony_ci * queue.
3668c2ecf20Sopenharmony_ci *
3678c2ecf20Sopenharmony_ci * @efx: Associated Efx NIC
3688c2ecf20Sopenharmony_ci * @channel: Channel instance number
3698c2ecf20Sopenharmony_ci * @type: Channel type definition
3708c2ecf20Sopenharmony_ci * @eventq_init: Event queue initialised flag
3718c2ecf20Sopenharmony_ci * @enabled: Channel enabled indicator
3728c2ecf20Sopenharmony_ci * @irq: IRQ number (MSI and MSI-X only)
3738c2ecf20Sopenharmony_ci * @irq_moderation_us: IRQ moderation value (in microseconds)
3748c2ecf20Sopenharmony_ci * @napi_dev: Net device used with NAPI
3758c2ecf20Sopenharmony_ci * @napi_str: NAPI control structure
3768c2ecf20Sopenharmony_ci * @state: state for NAPI vs busy polling
3778c2ecf20Sopenharmony_ci * @state_lock: lock protecting @state
3788c2ecf20Sopenharmony_ci * @eventq: Event queue buffer
3798c2ecf20Sopenharmony_ci * @eventq_mask: Event queue pointer mask
3808c2ecf20Sopenharmony_ci * @eventq_read_ptr: Event queue read pointer
3818c2ecf20Sopenharmony_ci * @event_test_cpu: Last CPU to handle interrupt or test event for this channel
3828c2ecf20Sopenharmony_ci * @irq_count: Number of IRQs since last adaptive moderation decision
3838c2ecf20Sopenharmony_ci * @irq_mod_score: IRQ moderation score
3848c2ecf20Sopenharmony_ci * @rps_flow_id: Flow IDs of filters allocated for accelerated RFS,
3858c2ecf20Sopenharmony_ci *      indexed by filter ID
3868c2ecf20Sopenharmony_ci * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
3878c2ecf20Sopenharmony_ci * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
3888c2ecf20Sopenharmony_ci * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
3898c2ecf20Sopenharmony_ci * @n_rx_mcast_mismatch: Count of unmatched multicast frames
3908c2ecf20Sopenharmony_ci * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
3918c2ecf20Sopenharmony_ci * @n_rx_overlength: Count of RX_OVERLENGTH errors
3928c2ecf20Sopenharmony_ci * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
3938c2ecf20Sopenharmony_ci * @n_rx_nodesc_trunc: Number of RX packets truncated and then dropped due to
3948c2ecf20Sopenharmony_ci *	lack of descriptors
3958c2ecf20Sopenharmony_ci * @n_rx_merge_events: Number of RX merged completion events
3968c2ecf20Sopenharmony_ci * @n_rx_merge_packets: Number of RX packets completed by merged events
3978c2ecf20Sopenharmony_ci * @rx_pkt_n_frags: Number of fragments in next packet to be delivered by
3988c2ecf20Sopenharmony_ci *	__ef4_rx_packet(), or zero if there is none
3998c2ecf20Sopenharmony_ci * @rx_pkt_index: Ring index of first buffer for next packet to be delivered
4008c2ecf20Sopenharmony_ci *	by __ef4_rx_packet(), if @rx_pkt_n_frags != 0
4018c2ecf20Sopenharmony_ci * @rx_queue: RX queue for this channel
4028c2ecf20Sopenharmony_ci * @tx_queue: TX queues for this channel
4038c2ecf20Sopenharmony_ci */
4048c2ecf20Sopenharmony_cistruct ef4_channel {
4058c2ecf20Sopenharmony_ci	struct ef4_nic *efx;
4068c2ecf20Sopenharmony_ci	int channel;
4078c2ecf20Sopenharmony_ci	const struct ef4_channel_type *type;
4088c2ecf20Sopenharmony_ci	bool eventq_init;
4098c2ecf20Sopenharmony_ci	bool enabled;
4108c2ecf20Sopenharmony_ci	int irq;
4118c2ecf20Sopenharmony_ci	unsigned int irq_moderation_us;
4128c2ecf20Sopenharmony_ci	struct net_device *napi_dev;
4138c2ecf20Sopenharmony_ci	struct napi_struct napi_str;
4148c2ecf20Sopenharmony_ci#ifdef CONFIG_NET_RX_BUSY_POLL
4158c2ecf20Sopenharmony_ci	unsigned long busy_poll_state;
4168c2ecf20Sopenharmony_ci#endif
4178c2ecf20Sopenharmony_ci	struct ef4_special_buffer eventq;
4188c2ecf20Sopenharmony_ci	unsigned int eventq_mask;
4198c2ecf20Sopenharmony_ci	unsigned int eventq_read_ptr;
4208c2ecf20Sopenharmony_ci	int event_test_cpu;
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci	unsigned int irq_count;
4238c2ecf20Sopenharmony_ci	unsigned int irq_mod_score;
4248c2ecf20Sopenharmony_ci#ifdef CONFIG_RFS_ACCEL
4258c2ecf20Sopenharmony_ci	unsigned int rfs_filters_added;
4268c2ecf20Sopenharmony_ci#define RPS_FLOW_ID_INVALID 0xFFFFFFFF
4278c2ecf20Sopenharmony_ci	u32 *rps_flow_id;
4288c2ecf20Sopenharmony_ci#endif
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci	unsigned n_rx_tobe_disc;
4318c2ecf20Sopenharmony_ci	unsigned n_rx_ip_hdr_chksum_err;
4328c2ecf20Sopenharmony_ci	unsigned n_rx_tcp_udp_chksum_err;
4338c2ecf20Sopenharmony_ci	unsigned n_rx_mcast_mismatch;
4348c2ecf20Sopenharmony_ci	unsigned n_rx_frm_trunc;
4358c2ecf20Sopenharmony_ci	unsigned n_rx_overlength;
4368c2ecf20Sopenharmony_ci	unsigned n_skbuff_leaks;
4378c2ecf20Sopenharmony_ci	unsigned int n_rx_nodesc_trunc;
4388c2ecf20Sopenharmony_ci	unsigned int n_rx_merge_events;
4398c2ecf20Sopenharmony_ci	unsigned int n_rx_merge_packets;
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci	unsigned int rx_pkt_n_frags;
4428c2ecf20Sopenharmony_ci	unsigned int rx_pkt_index;
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci	struct ef4_rx_queue rx_queue;
4458c2ecf20Sopenharmony_ci	struct ef4_tx_queue tx_queue[EF4_TXQ_TYPES];
4468c2ecf20Sopenharmony_ci};
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci/**
4498c2ecf20Sopenharmony_ci * struct ef4_msi_context - Context for each MSI
4508c2ecf20Sopenharmony_ci * @efx: The associated NIC
4518c2ecf20Sopenharmony_ci * @index: Index of the channel/IRQ
4528c2ecf20Sopenharmony_ci * @name: Name of the channel/IRQ
4538c2ecf20Sopenharmony_ci *
4548c2ecf20Sopenharmony_ci * Unlike &struct ef4_channel, this is never reallocated and is always
4558c2ecf20Sopenharmony_ci * safe for the IRQ handler to access.
4568c2ecf20Sopenharmony_ci */
4578c2ecf20Sopenharmony_cistruct ef4_msi_context {
4588c2ecf20Sopenharmony_ci	struct ef4_nic *efx;
4598c2ecf20Sopenharmony_ci	unsigned int index;
4608c2ecf20Sopenharmony_ci	char name[IFNAMSIZ + 6];
4618c2ecf20Sopenharmony_ci};
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci/**
4648c2ecf20Sopenharmony_ci * struct ef4_channel_type - distinguishes traffic and extra channels
4658c2ecf20Sopenharmony_ci * @handle_no_channel: Handle failure to allocate an extra channel
4668c2ecf20Sopenharmony_ci * @pre_probe: Set up extra state prior to initialisation
4678c2ecf20Sopenharmony_ci * @post_remove: Tear down extra state after finalisation, if allocated.
4688c2ecf20Sopenharmony_ci *	May be called on channels that have not been probed.
4698c2ecf20Sopenharmony_ci * @get_name: Generate the channel's name (used for its IRQ handler)
4708c2ecf20Sopenharmony_ci * @copy: Copy the channel state prior to reallocation.  May be %NULL if
4718c2ecf20Sopenharmony_ci *	reallocation is not supported.
4728c2ecf20Sopenharmony_ci * @receive_skb: Handle an skb ready to be passed to netif_receive_skb()
4738c2ecf20Sopenharmony_ci * @keep_eventq: Flag for whether event queue should be kept initialised
4748c2ecf20Sopenharmony_ci *	while the device is stopped
4758c2ecf20Sopenharmony_ci */
4768c2ecf20Sopenharmony_cistruct ef4_channel_type {
4778c2ecf20Sopenharmony_ci	void (*handle_no_channel)(struct ef4_nic *);
4788c2ecf20Sopenharmony_ci	int (*pre_probe)(struct ef4_channel *);
4798c2ecf20Sopenharmony_ci	void (*post_remove)(struct ef4_channel *);
4808c2ecf20Sopenharmony_ci	void (*get_name)(struct ef4_channel *, char *buf, size_t len);
4818c2ecf20Sopenharmony_ci	struct ef4_channel *(*copy)(const struct ef4_channel *);
4828c2ecf20Sopenharmony_ci	bool (*receive_skb)(struct ef4_channel *, struct sk_buff *);
4838c2ecf20Sopenharmony_ci	bool keep_eventq;
4848c2ecf20Sopenharmony_ci};
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_cienum ef4_led_mode {
4878c2ecf20Sopenharmony_ci	EF4_LED_OFF	= 0,
4888c2ecf20Sopenharmony_ci	EF4_LED_ON	= 1,
4898c2ecf20Sopenharmony_ci	EF4_LED_DEFAULT	= 2
4908c2ecf20Sopenharmony_ci};
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci#define STRING_TABLE_LOOKUP(val, member) \
4938c2ecf20Sopenharmony_ci	((val) < member ## _max) ? member ## _names[val] : "(invalid)"
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_ciextern const char *const ef4_loopback_mode_names[];
4968c2ecf20Sopenharmony_ciextern const unsigned int ef4_loopback_mode_max;
4978c2ecf20Sopenharmony_ci#define LOOPBACK_MODE(efx) \
4988c2ecf20Sopenharmony_ci	STRING_TABLE_LOOKUP((efx)->loopback_mode, ef4_loopback_mode)
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ciextern const char *const ef4_reset_type_names[];
5018c2ecf20Sopenharmony_ciextern const unsigned int ef4_reset_type_max;
5028c2ecf20Sopenharmony_ci#define RESET_TYPE(type) \
5038c2ecf20Sopenharmony_ci	STRING_TABLE_LOOKUP(type, ef4_reset_type)
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_cienum ef4_int_mode {
5068c2ecf20Sopenharmony_ci	/* Be careful if altering to correct macro below */
5078c2ecf20Sopenharmony_ci	EF4_INT_MODE_MSIX = 0,
5088c2ecf20Sopenharmony_ci	EF4_INT_MODE_MSI = 1,
5098c2ecf20Sopenharmony_ci	EF4_INT_MODE_LEGACY = 2,
5108c2ecf20Sopenharmony_ci	EF4_INT_MODE_MAX	/* Insert any new items before this */
5118c2ecf20Sopenharmony_ci};
5128c2ecf20Sopenharmony_ci#define EF4_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EF4_INT_MODE_MSI)
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_cienum nic_state {
5158c2ecf20Sopenharmony_ci	STATE_UNINIT = 0,	/* device being probed/removed or is frozen */
5168c2ecf20Sopenharmony_ci	STATE_READY = 1,	/* hardware ready and netdev registered */
5178c2ecf20Sopenharmony_ci	STATE_DISABLED = 2,	/* device disabled due to hardware errors */
5188c2ecf20Sopenharmony_ci	STATE_RECOVERY = 3,	/* device recovering from PCI error */
5198c2ecf20Sopenharmony_ci};
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci/* Forward declaration */
5228c2ecf20Sopenharmony_cistruct ef4_nic;
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ci/* Pseudo bit-mask flow control field */
5258c2ecf20Sopenharmony_ci#define EF4_FC_RX	FLOW_CTRL_RX
5268c2ecf20Sopenharmony_ci#define EF4_FC_TX	FLOW_CTRL_TX
5278c2ecf20Sopenharmony_ci#define EF4_FC_AUTO	4
5288c2ecf20Sopenharmony_ci
5298c2ecf20Sopenharmony_ci/**
5308c2ecf20Sopenharmony_ci * struct ef4_link_state - Current state of the link
5318c2ecf20Sopenharmony_ci * @up: Link is up
5328c2ecf20Sopenharmony_ci * @fd: Link is full-duplex
5338c2ecf20Sopenharmony_ci * @fc: Actual flow control flags
5348c2ecf20Sopenharmony_ci * @speed: Link speed (Mbps)
5358c2ecf20Sopenharmony_ci */
5368c2ecf20Sopenharmony_cistruct ef4_link_state {
5378c2ecf20Sopenharmony_ci	bool up;
5388c2ecf20Sopenharmony_ci	bool fd;
5398c2ecf20Sopenharmony_ci	u8 fc;
5408c2ecf20Sopenharmony_ci	unsigned int speed;
5418c2ecf20Sopenharmony_ci};
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_cistatic inline bool ef4_link_state_equal(const struct ef4_link_state *left,
5448c2ecf20Sopenharmony_ci					const struct ef4_link_state *right)
5458c2ecf20Sopenharmony_ci{
5468c2ecf20Sopenharmony_ci	return left->up == right->up && left->fd == right->fd &&
5478c2ecf20Sopenharmony_ci		left->fc == right->fc && left->speed == right->speed;
5488c2ecf20Sopenharmony_ci}
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci/**
5518c2ecf20Sopenharmony_ci * struct ef4_phy_operations - Efx PHY operations table
5528c2ecf20Sopenharmony_ci * @probe: Probe PHY and initialise efx->mdio.mode_support, efx->mdio.mmds,
5538c2ecf20Sopenharmony_ci *	efx->loopback_modes.
5548c2ecf20Sopenharmony_ci * @init: Initialise PHY
5558c2ecf20Sopenharmony_ci * @fini: Shut down PHY
5568c2ecf20Sopenharmony_ci * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
5578c2ecf20Sopenharmony_ci * @poll: Update @link_state and report whether it changed.
5588c2ecf20Sopenharmony_ci *	Serialised by the mac_lock.
5598c2ecf20Sopenharmony_ci * @get_link_ksettings: Get ethtool settings. Serialised by the mac_lock.
5608c2ecf20Sopenharmony_ci * @set_link_ksettings: Set ethtool settings. Serialised by the mac_lock.
5618c2ecf20Sopenharmony_ci * @set_npage_adv: Set abilities advertised in (Extended) Next Page
5628c2ecf20Sopenharmony_ci *	(only needed where AN bit is set in mmds)
5638c2ecf20Sopenharmony_ci * @test_alive: Test that PHY is 'alive' (online)
5648c2ecf20Sopenharmony_ci * @test_name: Get the name of a PHY-specific test/result
5658c2ecf20Sopenharmony_ci * @run_tests: Run tests and record results as appropriate (offline).
5668c2ecf20Sopenharmony_ci *	Flags are the ethtool tests flags.
5678c2ecf20Sopenharmony_ci */
5688c2ecf20Sopenharmony_cistruct ef4_phy_operations {
5698c2ecf20Sopenharmony_ci	int (*probe) (struct ef4_nic *efx);
5708c2ecf20Sopenharmony_ci	int (*init) (struct ef4_nic *efx);
5718c2ecf20Sopenharmony_ci	void (*fini) (struct ef4_nic *efx);
5728c2ecf20Sopenharmony_ci	void (*remove) (struct ef4_nic *efx);
5738c2ecf20Sopenharmony_ci	int (*reconfigure) (struct ef4_nic *efx);
5748c2ecf20Sopenharmony_ci	bool (*poll) (struct ef4_nic *efx);
5758c2ecf20Sopenharmony_ci	void (*get_link_ksettings)(struct ef4_nic *efx,
5768c2ecf20Sopenharmony_ci				   struct ethtool_link_ksettings *cmd);
5778c2ecf20Sopenharmony_ci	int (*set_link_ksettings)(struct ef4_nic *efx,
5788c2ecf20Sopenharmony_ci				  const struct ethtool_link_ksettings *cmd);
5798c2ecf20Sopenharmony_ci	void (*set_npage_adv) (struct ef4_nic *efx, u32);
5808c2ecf20Sopenharmony_ci	int (*test_alive) (struct ef4_nic *efx);
5818c2ecf20Sopenharmony_ci	const char *(*test_name) (struct ef4_nic *efx, unsigned int index);
5828c2ecf20Sopenharmony_ci	int (*run_tests) (struct ef4_nic *efx, int *results, unsigned flags);
5838c2ecf20Sopenharmony_ci	int (*get_module_eeprom) (struct ef4_nic *efx,
5848c2ecf20Sopenharmony_ci			       struct ethtool_eeprom *ee,
5858c2ecf20Sopenharmony_ci			       u8 *data);
5868c2ecf20Sopenharmony_ci	int (*get_module_info) (struct ef4_nic *efx,
5878c2ecf20Sopenharmony_ci				struct ethtool_modinfo *modinfo);
5888c2ecf20Sopenharmony_ci};
5898c2ecf20Sopenharmony_ci
5908c2ecf20Sopenharmony_ci/**
5918c2ecf20Sopenharmony_ci * enum ef4_phy_mode - PHY operating mode flags
5928c2ecf20Sopenharmony_ci * @PHY_MODE_NORMAL: on and should pass traffic
5938c2ecf20Sopenharmony_ci * @PHY_MODE_TX_DISABLED: on with TX disabled
5948c2ecf20Sopenharmony_ci * @PHY_MODE_LOW_POWER: set to low power through MDIO
5958c2ecf20Sopenharmony_ci * @PHY_MODE_OFF: switched off through external control
5968c2ecf20Sopenharmony_ci * @PHY_MODE_SPECIAL: on but will not pass traffic
5978c2ecf20Sopenharmony_ci */
5988c2ecf20Sopenharmony_cienum ef4_phy_mode {
5998c2ecf20Sopenharmony_ci	PHY_MODE_NORMAL		= 0,
6008c2ecf20Sopenharmony_ci	PHY_MODE_TX_DISABLED	= 1,
6018c2ecf20Sopenharmony_ci	PHY_MODE_LOW_POWER	= 2,
6028c2ecf20Sopenharmony_ci	PHY_MODE_OFF		= 4,
6038c2ecf20Sopenharmony_ci	PHY_MODE_SPECIAL	= 8,
6048c2ecf20Sopenharmony_ci};
6058c2ecf20Sopenharmony_ci
6068c2ecf20Sopenharmony_cistatic inline bool ef4_phy_mode_disabled(enum ef4_phy_mode mode)
6078c2ecf20Sopenharmony_ci{
6088c2ecf20Sopenharmony_ci	return !!(mode & ~PHY_MODE_TX_DISABLED);
6098c2ecf20Sopenharmony_ci}
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ci/**
6128c2ecf20Sopenharmony_ci * struct ef4_hw_stat_desc - Description of a hardware statistic
6138c2ecf20Sopenharmony_ci * @name: Name of the statistic as visible through ethtool, or %NULL if
6148c2ecf20Sopenharmony_ci *	it should not be exposed
6158c2ecf20Sopenharmony_ci * @dma_width: Width in bits (0 for non-DMA statistics)
6168c2ecf20Sopenharmony_ci * @offset: Offset within stats (ignored for non-DMA statistics)
6178c2ecf20Sopenharmony_ci */
6188c2ecf20Sopenharmony_cistruct ef4_hw_stat_desc {
6198c2ecf20Sopenharmony_ci	const char *name;
6208c2ecf20Sopenharmony_ci	u16 dma_width;
6218c2ecf20Sopenharmony_ci	u16 offset;
6228c2ecf20Sopenharmony_ci};
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_ci/* Number of bits used in a multicast filter hash address */
6258c2ecf20Sopenharmony_ci#define EF4_MCAST_HASH_BITS 8
6268c2ecf20Sopenharmony_ci
6278c2ecf20Sopenharmony_ci/* Number of (single-bit) entries in a multicast filter hash */
6288c2ecf20Sopenharmony_ci#define EF4_MCAST_HASH_ENTRIES (1 << EF4_MCAST_HASH_BITS)
6298c2ecf20Sopenharmony_ci
6308c2ecf20Sopenharmony_ci/* An Efx multicast filter hash */
6318c2ecf20Sopenharmony_ciunion ef4_multicast_hash {
6328c2ecf20Sopenharmony_ci	u8 byte[EF4_MCAST_HASH_ENTRIES / 8];
6338c2ecf20Sopenharmony_ci	ef4_oword_t oword[EF4_MCAST_HASH_ENTRIES / sizeof(ef4_oword_t) / 8];
6348c2ecf20Sopenharmony_ci};
6358c2ecf20Sopenharmony_ci
6368c2ecf20Sopenharmony_ci/**
6378c2ecf20Sopenharmony_ci * struct ef4_nic - an Efx NIC
6388c2ecf20Sopenharmony_ci * @name: Device name (net device name or bus id before net device registered)
6398c2ecf20Sopenharmony_ci * @pci_dev: The PCI device
6408c2ecf20Sopenharmony_ci * @node: List node for maintaning primary/secondary function lists
6418c2ecf20Sopenharmony_ci * @primary: &struct ef4_nic instance for the primary function of this
6428c2ecf20Sopenharmony_ci *	controller.  May be the same structure, and may be %NULL if no
6438c2ecf20Sopenharmony_ci *	primary function is bound.  Serialised by rtnl_lock.
6448c2ecf20Sopenharmony_ci * @secondary_list: List of &struct ef4_nic instances for the secondary PCI
6458c2ecf20Sopenharmony_ci *	functions of the controller, if this is for the primary function.
6468c2ecf20Sopenharmony_ci *	Serialised by rtnl_lock.
6478c2ecf20Sopenharmony_ci * @type: Controller type attributes
6488c2ecf20Sopenharmony_ci * @legacy_irq: IRQ number
6498c2ecf20Sopenharmony_ci * @workqueue: Workqueue for port reconfigures and the HW monitor.
6508c2ecf20Sopenharmony_ci *	Work items do not hold and must not acquire RTNL.
6518c2ecf20Sopenharmony_ci * @workqueue_name: Name of workqueue
6528c2ecf20Sopenharmony_ci * @reset_work: Scheduled reset workitem
6538c2ecf20Sopenharmony_ci * @membase_phys: Memory BAR value as physical address
6548c2ecf20Sopenharmony_ci * @membase: Memory BAR value
6558c2ecf20Sopenharmony_ci * @interrupt_mode: Interrupt mode
6568c2ecf20Sopenharmony_ci * @timer_quantum_ns: Interrupt timer quantum, in nanoseconds
6578c2ecf20Sopenharmony_ci * @timer_max_ns: Interrupt timer maximum value, in nanoseconds
6588c2ecf20Sopenharmony_ci * @irq_rx_adaptive: Adaptive IRQ moderation enabled for RX event queues
6598c2ecf20Sopenharmony_ci * @irq_rx_mod_step_us: Step size for IRQ moderation for RX event queues
6608c2ecf20Sopenharmony_ci * @irq_rx_moderation_us: IRQ moderation time for RX event queues
6618c2ecf20Sopenharmony_ci * @msg_enable: Log message enable flags
6628c2ecf20Sopenharmony_ci * @state: Device state number (%STATE_*). Serialised by the rtnl_lock.
6638c2ecf20Sopenharmony_ci * @reset_pending: Bitmask for pending resets
6648c2ecf20Sopenharmony_ci * @tx_queue: TX DMA queues
6658c2ecf20Sopenharmony_ci * @rx_queue: RX DMA queues
6668c2ecf20Sopenharmony_ci * @channel: Channels
6678c2ecf20Sopenharmony_ci * @msi_context: Context for each MSI
6688c2ecf20Sopenharmony_ci * @extra_channel_types: Types of extra (non-traffic) channels that
6698c2ecf20Sopenharmony_ci *	should be allocated for this NIC
6708c2ecf20Sopenharmony_ci * @rxq_entries: Size of receive queues requested by user.
6718c2ecf20Sopenharmony_ci * @txq_entries: Size of transmit queues requested by user.
6728c2ecf20Sopenharmony_ci * @txq_stop_thresh: TX queue fill level at or above which we stop it.
6738c2ecf20Sopenharmony_ci * @txq_wake_thresh: TX queue fill level at or below which we wake it.
6748c2ecf20Sopenharmony_ci * @tx_dc_base: Base qword address in SRAM of TX queue descriptor caches
6758c2ecf20Sopenharmony_ci * @rx_dc_base: Base qword address in SRAM of RX queue descriptor caches
6768c2ecf20Sopenharmony_ci * @sram_lim_qw: Qword address limit of SRAM
6778c2ecf20Sopenharmony_ci * @next_buffer_table: First available buffer table id
6788c2ecf20Sopenharmony_ci * @n_channels: Number of channels in use
6798c2ecf20Sopenharmony_ci * @n_rx_channels: Number of channels used for RX (= number of RX queues)
6808c2ecf20Sopenharmony_ci * @n_tx_channels: Number of channels used for TX
6818c2ecf20Sopenharmony_ci * @rx_ip_align: RX DMA address offset to have IP header aligned in
6828c2ecf20Sopenharmony_ci *	in accordance with NET_IP_ALIGN
6838c2ecf20Sopenharmony_ci * @rx_dma_len: Current maximum RX DMA length
6848c2ecf20Sopenharmony_ci * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
6858c2ecf20Sopenharmony_ci * @rx_buffer_truesize: Amortised allocation size of an RX buffer,
6868c2ecf20Sopenharmony_ci *	for use in sk_buff::truesize
6878c2ecf20Sopenharmony_ci * @rx_prefix_size: Size of RX prefix before packet data
6888c2ecf20Sopenharmony_ci * @rx_packet_hash_offset: Offset of RX flow hash from start of packet data
6898c2ecf20Sopenharmony_ci *	(valid only if @rx_prefix_size != 0; always negative)
6908c2ecf20Sopenharmony_ci * @rx_packet_len_offset: Offset of RX packet length from start of packet data
6918c2ecf20Sopenharmony_ci *	(valid only for NICs that set %EF4_RX_PKT_PREFIX_LEN; always negative)
6928c2ecf20Sopenharmony_ci * @rx_packet_ts_offset: Offset of timestamp from start of packet data
6938c2ecf20Sopenharmony_ci *	(valid only if channel->sync_timestamps_enabled; always negative)
6948c2ecf20Sopenharmony_ci * @rx_hash_key: Toeplitz hash key for RSS
6958c2ecf20Sopenharmony_ci * @rx_indir_table: Indirection table for RSS
6968c2ecf20Sopenharmony_ci * @rx_scatter: Scatter mode enabled for receives
6978c2ecf20Sopenharmony_ci * @int_error_count: Number of internal errors seen recently
6988c2ecf20Sopenharmony_ci * @int_error_expire: Time at which error count will be expired
6998c2ecf20Sopenharmony_ci * @irq_soft_enabled: Are IRQs soft-enabled? If not, IRQ handler will
7008c2ecf20Sopenharmony_ci *	acknowledge but do nothing else.
7018c2ecf20Sopenharmony_ci * @irq_status: Interrupt status buffer
7028c2ecf20Sopenharmony_ci * @irq_zero_count: Number of legacy IRQs seen with queue flags == 0
7038c2ecf20Sopenharmony_ci * @irq_level: IRQ level/index for IRQs not triggered by an event queue
7048c2ecf20Sopenharmony_ci * @selftest_work: Work item for asynchronous self-test
7058c2ecf20Sopenharmony_ci * @mtd_list: List of MTDs attached to the NIC
7068c2ecf20Sopenharmony_ci * @nic_data: Hardware dependent state
7078c2ecf20Sopenharmony_ci * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode,
7088c2ecf20Sopenharmony_ci *	ef4_monitor() and ef4_reconfigure_port()
7098c2ecf20Sopenharmony_ci * @port_enabled: Port enabled indicator.
7108c2ecf20Sopenharmony_ci *	Serialises ef4_stop_all(), ef4_start_all(), ef4_monitor() and
7118c2ecf20Sopenharmony_ci *	ef4_mac_work() with kernel interfaces. Safe to read under any
7128c2ecf20Sopenharmony_ci *	one of the rtnl_lock, mac_lock, or netif_tx_lock, but all three must
7138c2ecf20Sopenharmony_ci *	be held to modify it.
7148c2ecf20Sopenharmony_ci * @port_initialized: Port initialized?
7158c2ecf20Sopenharmony_ci * @net_dev: Operating system network device. Consider holding the rtnl lock
7168c2ecf20Sopenharmony_ci * @fixed_features: Features which cannot be turned off
7178c2ecf20Sopenharmony_ci * @stats_buffer: DMA buffer for statistics
7188c2ecf20Sopenharmony_ci * @phy_type: PHY type
7198c2ecf20Sopenharmony_ci * @phy_op: PHY interface
7208c2ecf20Sopenharmony_ci * @phy_data: PHY private data (including PHY-specific stats)
7218c2ecf20Sopenharmony_ci * @mdio: PHY MDIO interface
7228c2ecf20Sopenharmony_ci * @phy_mode: PHY operating mode. Serialised by @mac_lock.
7238c2ecf20Sopenharmony_ci * @link_advertising: Autonegotiation advertising flags
7248c2ecf20Sopenharmony_ci * @link_state: Current state of the link
7258c2ecf20Sopenharmony_ci * @n_link_state_changes: Number of times the link has changed state
7268c2ecf20Sopenharmony_ci * @unicast_filter: Flag for Falcon-arch simple unicast filter.
7278c2ecf20Sopenharmony_ci *	Protected by @mac_lock.
7288c2ecf20Sopenharmony_ci * @multicast_hash: Multicast hash table for Falcon-arch.
7298c2ecf20Sopenharmony_ci *	Protected by @mac_lock.
7308c2ecf20Sopenharmony_ci * @wanted_fc: Wanted flow control flags
7318c2ecf20Sopenharmony_ci * @fc_disable: When non-zero flow control is disabled. Typically used to
7328c2ecf20Sopenharmony_ci *	ensure that network back pressure doesn't delay dma queue flushes.
7338c2ecf20Sopenharmony_ci *	Serialised by the rtnl lock.
7348c2ecf20Sopenharmony_ci * @mac_work: Work item for changing MAC promiscuity and multicast hash
7358c2ecf20Sopenharmony_ci * @loopback_mode: Loopback status
7368c2ecf20Sopenharmony_ci * @loopback_modes: Supported loopback mode bitmask
7378c2ecf20Sopenharmony_ci * @loopback_selftest: Offline self-test private state
7388c2ecf20Sopenharmony_ci * @filter_sem: Filter table rw_semaphore, for freeing the table
7398c2ecf20Sopenharmony_ci * @filter_lock: Filter table lock, for mere content changes
7408c2ecf20Sopenharmony_ci * @filter_state: Architecture-dependent filter table state
7418c2ecf20Sopenharmony_ci * @rps_expire_channel: Next channel to check for expiry
7428c2ecf20Sopenharmony_ci * @rps_expire_index: Next index to check for expiry in
7438c2ecf20Sopenharmony_ci *	@rps_expire_channel's @rps_flow_id
7448c2ecf20Sopenharmony_ci * @active_queues: Count of RX and TX queues that haven't been flushed and drained.
7458c2ecf20Sopenharmony_ci * @rxq_flush_pending: Count of number of receive queues that need to be flushed.
7468c2ecf20Sopenharmony_ci *	Decremented when the ef4_flush_rx_queue() is called.
7478c2ecf20Sopenharmony_ci * @rxq_flush_outstanding: Count of number of RX flushes started but not yet
7488c2ecf20Sopenharmony_ci *	completed (either success or failure). Not used when MCDI is used to
7498c2ecf20Sopenharmony_ci *	flush receive queues.
7508c2ecf20Sopenharmony_ci * @flush_wq: wait queue used by ef4_nic_flush_queues() to wait for flush completions.
7518c2ecf20Sopenharmony_ci * @vpd_sn: Serial number read from VPD
7528c2ecf20Sopenharmony_ci * @monitor_work: Hardware monitor workitem
7538c2ecf20Sopenharmony_ci * @biu_lock: BIU (bus interface unit) lock
7548c2ecf20Sopenharmony_ci * @last_irq_cpu: Last CPU to handle a possible test interrupt.  This
7558c2ecf20Sopenharmony_ci *	field is used by ef4_test_interrupts() to verify that an
7568c2ecf20Sopenharmony_ci *	interrupt has occurred.
7578c2ecf20Sopenharmony_ci * @stats_lock: Statistics update lock. Must be held when calling
7588c2ecf20Sopenharmony_ci *	ef4_nic_type::{update,start,stop}_stats.
7598c2ecf20Sopenharmony_ci * @n_rx_noskb_drops: Count of RX packets dropped due to failure to allocate an skb
7608c2ecf20Sopenharmony_ci *
7618c2ecf20Sopenharmony_ci * This is stored in the private area of the &struct net_device.
7628c2ecf20Sopenharmony_ci */
7638c2ecf20Sopenharmony_cistruct ef4_nic {
7648c2ecf20Sopenharmony_ci	/* The following fields should be written very rarely */
7658c2ecf20Sopenharmony_ci
7668c2ecf20Sopenharmony_ci	char name[IFNAMSIZ];
7678c2ecf20Sopenharmony_ci	struct list_head node;
7688c2ecf20Sopenharmony_ci	struct ef4_nic *primary;
7698c2ecf20Sopenharmony_ci	struct list_head secondary_list;
7708c2ecf20Sopenharmony_ci	struct pci_dev *pci_dev;
7718c2ecf20Sopenharmony_ci	unsigned int port_num;
7728c2ecf20Sopenharmony_ci	const struct ef4_nic_type *type;
7738c2ecf20Sopenharmony_ci	int legacy_irq;
7748c2ecf20Sopenharmony_ci	bool eeh_disabled_legacy_irq;
7758c2ecf20Sopenharmony_ci	struct workqueue_struct *workqueue;
7768c2ecf20Sopenharmony_ci	char workqueue_name[16];
7778c2ecf20Sopenharmony_ci	struct work_struct reset_work;
7788c2ecf20Sopenharmony_ci	resource_size_t membase_phys;
7798c2ecf20Sopenharmony_ci	void __iomem *membase;
7808c2ecf20Sopenharmony_ci
7818c2ecf20Sopenharmony_ci	enum ef4_int_mode interrupt_mode;
7828c2ecf20Sopenharmony_ci	unsigned int timer_quantum_ns;
7838c2ecf20Sopenharmony_ci	unsigned int timer_max_ns;
7848c2ecf20Sopenharmony_ci	bool irq_rx_adaptive;
7858c2ecf20Sopenharmony_ci	unsigned int irq_mod_step_us;
7868c2ecf20Sopenharmony_ci	unsigned int irq_rx_moderation_us;
7878c2ecf20Sopenharmony_ci	u32 msg_enable;
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_ci	enum nic_state state;
7908c2ecf20Sopenharmony_ci	unsigned long reset_pending;
7918c2ecf20Sopenharmony_ci
7928c2ecf20Sopenharmony_ci	struct ef4_channel *channel[EF4_MAX_CHANNELS];
7938c2ecf20Sopenharmony_ci	struct ef4_msi_context msi_context[EF4_MAX_CHANNELS];
7948c2ecf20Sopenharmony_ci	const struct ef4_channel_type *
7958c2ecf20Sopenharmony_ci	extra_channel_type[EF4_MAX_EXTRA_CHANNELS];
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ci	unsigned rxq_entries;
7988c2ecf20Sopenharmony_ci	unsigned txq_entries;
7998c2ecf20Sopenharmony_ci	unsigned int txq_stop_thresh;
8008c2ecf20Sopenharmony_ci	unsigned int txq_wake_thresh;
8018c2ecf20Sopenharmony_ci
8028c2ecf20Sopenharmony_ci	unsigned tx_dc_base;
8038c2ecf20Sopenharmony_ci	unsigned rx_dc_base;
8048c2ecf20Sopenharmony_ci	unsigned sram_lim_qw;
8058c2ecf20Sopenharmony_ci	unsigned next_buffer_table;
8068c2ecf20Sopenharmony_ci
8078c2ecf20Sopenharmony_ci	unsigned int max_channels;
8088c2ecf20Sopenharmony_ci	unsigned int max_tx_channels;
8098c2ecf20Sopenharmony_ci	unsigned n_channels;
8108c2ecf20Sopenharmony_ci	unsigned n_rx_channels;
8118c2ecf20Sopenharmony_ci	unsigned rss_spread;
8128c2ecf20Sopenharmony_ci	unsigned tx_channel_offset;
8138c2ecf20Sopenharmony_ci	unsigned n_tx_channels;
8148c2ecf20Sopenharmony_ci	unsigned int rx_ip_align;
8158c2ecf20Sopenharmony_ci	unsigned int rx_dma_len;
8168c2ecf20Sopenharmony_ci	unsigned int rx_buffer_order;
8178c2ecf20Sopenharmony_ci	unsigned int rx_buffer_truesize;
8188c2ecf20Sopenharmony_ci	unsigned int rx_page_buf_step;
8198c2ecf20Sopenharmony_ci	unsigned int rx_bufs_per_page;
8208c2ecf20Sopenharmony_ci	unsigned int rx_pages_per_batch;
8218c2ecf20Sopenharmony_ci	unsigned int rx_prefix_size;
8228c2ecf20Sopenharmony_ci	int rx_packet_hash_offset;
8238c2ecf20Sopenharmony_ci	int rx_packet_len_offset;
8248c2ecf20Sopenharmony_ci	int rx_packet_ts_offset;
8258c2ecf20Sopenharmony_ci	u8 rx_hash_key[40];
8268c2ecf20Sopenharmony_ci	u32 rx_indir_table[128];
8278c2ecf20Sopenharmony_ci	bool rx_scatter;
8288c2ecf20Sopenharmony_ci
8298c2ecf20Sopenharmony_ci	unsigned int_error_count;
8308c2ecf20Sopenharmony_ci	unsigned long int_error_expire;
8318c2ecf20Sopenharmony_ci
8328c2ecf20Sopenharmony_ci	bool irq_soft_enabled;
8338c2ecf20Sopenharmony_ci	struct ef4_buffer irq_status;
8348c2ecf20Sopenharmony_ci	unsigned irq_zero_count;
8358c2ecf20Sopenharmony_ci	unsigned irq_level;
8368c2ecf20Sopenharmony_ci	struct delayed_work selftest_work;
8378c2ecf20Sopenharmony_ci
8388c2ecf20Sopenharmony_ci#ifdef CONFIG_SFC_FALCON_MTD
8398c2ecf20Sopenharmony_ci	struct list_head mtd_list;
8408c2ecf20Sopenharmony_ci#endif
8418c2ecf20Sopenharmony_ci
8428c2ecf20Sopenharmony_ci	void *nic_data;
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_ci	struct mutex mac_lock;
8458c2ecf20Sopenharmony_ci	struct work_struct mac_work;
8468c2ecf20Sopenharmony_ci	bool port_enabled;
8478c2ecf20Sopenharmony_ci
8488c2ecf20Sopenharmony_ci	bool mc_bist_for_other_fn;
8498c2ecf20Sopenharmony_ci	bool port_initialized;
8508c2ecf20Sopenharmony_ci	struct net_device *net_dev;
8518c2ecf20Sopenharmony_ci
8528c2ecf20Sopenharmony_ci	netdev_features_t fixed_features;
8538c2ecf20Sopenharmony_ci
8548c2ecf20Sopenharmony_ci	struct ef4_buffer stats_buffer;
8558c2ecf20Sopenharmony_ci	u64 rx_nodesc_drops_total;
8568c2ecf20Sopenharmony_ci	u64 rx_nodesc_drops_while_down;
8578c2ecf20Sopenharmony_ci	bool rx_nodesc_drops_prev_state;
8588c2ecf20Sopenharmony_ci
8598c2ecf20Sopenharmony_ci	unsigned int phy_type;
8608c2ecf20Sopenharmony_ci	const struct ef4_phy_operations *phy_op;
8618c2ecf20Sopenharmony_ci	void *phy_data;
8628c2ecf20Sopenharmony_ci	struct mdio_if_info mdio;
8638c2ecf20Sopenharmony_ci	enum ef4_phy_mode phy_mode;
8648c2ecf20Sopenharmony_ci
8658c2ecf20Sopenharmony_ci	u32 link_advertising;
8668c2ecf20Sopenharmony_ci	struct ef4_link_state link_state;
8678c2ecf20Sopenharmony_ci	unsigned int n_link_state_changes;
8688c2ecf20Sopenharmony_ci
8698c2ecf20Sopenharmony_ci	bool unicast_filter;
8708c2ecf20Sopenharmony_ci	union ef4_multicast_hash multicast_hash;
8718c2ecf20Sopenharmony_ci	u8 wanted_fc;
8728c2ecf20Sopenharmony_ci	unsigned fc_disable;
8738c2ecf20Sopenharmony_ci
8748c2ecf20Sopenharmony_ci	atomic_t rx_reset;
8758c2ecf20Sopenharmony_ci	enum ef4_loopback_mode loopback_mode;
8768c2ecf20Sopenharmony_ci	u64 loopback_modes;
8778c2ecf20Sopenharmony_ci
8788c2ecf20Sopenharmony_ci	void *loopback_selftest;
8798c2ecf20Sopenharmony_ci
8808c2ecf20Sopenharmony_ci	struct rw_semaphore filter_sem;
8818c2ecf20Sopenharmony_ci	spinlock_t filter_lock;
8828c2ecf20Sopenharmony_ci	void *filter_state;
8838c2ecf20Sopenharmony_ci#ifdef CONFIG_RFS_ACCEL
8848c2ecf20Sopenharmony_ci	unsigned int rps_expire_channel;
8858c2ecf20Sopenharmony_ci	unsigned int rps_expire_index;
8868c2ecf20Sopenharmony_ci#endif
8878c2ecf20Sopenharmony_ci
8888c2ecf20Sopenharmony_ci	atomic_t active_queues;
8898c2ecf20Sopenharmony_ci	atomic_t rxq_flush_pending;
8908c2ecf20Sopenharmony_ci	atomic_t rxq_flush_outstanding;
8918c2ecf20Sopenharmony_ci	wait_queue_head_t flush_wq;
8928c2ecf20Sopenharmony_ci
8938c2ecf20Sopenharmony_ci	char *vpd_sn;
8948c2ecf20Sopenharmony_ci
8958c2ecf20Sopenharmony_ci	/* The following fields may be written more often */
8968c2ecf20Sopenharmony_ci
8978c2ecf20Sopenharmony_ci	struct delayed_work monitor_work ____cacheline_aligned_in_smp;
8988c2ecf20Sopenharmony_ci	spinlock_t biu_lock;
8998c2ecf20Sopenharmony_ci	int last_irq_cpu;
9008c2ecf20Sopenharmony_ci	spinlock_t stats_lock;
9018c2ecf20Sopenharmony_ci	atomic_t n_rx_noskb_drops;
9028c2ecf20Sopenharmony_ci};
9038c2ecf20Sopenharmony_ci
9048c2ecf20Sopenharmony_cistatic inline int ef4_dev_registered(struct ef4_nic *efx)
9058c2ecf20Sopenharmony_ci{
9068c2ecf20Sopenharmony_ci	return efx->net_dev->reg_state == NETREG_REGISTERED;
9078c2ecf20Sopenharmony_ci}
9088c2ecf20Sopenharmony_ci
9098c2ecf20Sopenharmony_cistatic inline unsigned int ef4_port_num(struct ef4_nic *efx)
9108c2ecf20Sopenharmony_ci{
9118c2ecf20Sopenharmony_ci	return efx->port_num;
9128c2ecf20Sopenharmony_ci}
9138c2ecf20Sopenharmony_ci
9148c2ecf20Sopenharmony_cistruct ef4_mtd_partition {
9158c2ecf20Sopenharmony_ci	struct list_head node;
9168c2ecf20Sopenharmony_ci	struct mtd_info mtd;
9178c2ecf20Sopenharmony_ci	const char *dev_type_name;
9188c2ecf20Sopenharmony_ci	const char *type_name;
9198c2ecf20Sopenharmony_ci	char name[IFNAMSIZ + 20];
9208c2ecf20Sopenharmony_ci};
9218c2ecf20Sopenharmony_ci
9228c2ecf20Sopenharmony_ci/**
9238c2ecf20Sopenharmony_ci * struct ef4_nic_type - Efx device type definition
9248c2ecf20Sopenharmony_ci * @mem_bar: Get the memory BAR
9258c2ecf20Sopenharmony_ci * @mem_map_size: Get memory BAR mapped size
9268c2ecf20Sopenharmony_ci * @probe: Probe the controller
9278c2ecf20Sopenharmony_ci * @remove: Free resources allocated by probe()
9288c2ecf20Sopenharmony_ci * @init: Initialise the controller
9298c2ecf20Sopenharmony_ci * @dimension_resources: Dimension controller resources (buffer table,
9308c2ecf20Sopenharmony_ci *	and VIs once the available interrupt resources are clear)
9318c2ecf20Sopenharmony_ci * @fini: Shut down the controller
9328c2ecf20Sopenharmony_ci * @monitor: Periodic function for polling link state and hardware monitor
9338c2ecf20Sopenharmony_ci * @map_reset_reason: Map ethtool reset reason to a reset method
9348c2ecf20Sopenharmony_ci * @map_reset_flags: Map ethtool reset flags to a reset method, if possible
9358c2ecf20Sopenharmony_ci * @reset: Reset the controller hardware and possibly the PHY.  This will
9368c2ecf20Sopenharmony_ci *	be called while the controller is uninitialised.
9378c2ecf20Sopenharmony_ci * @probe_port: Probe the MAC and PHY
9388c2ecf20Sopenharmony_ci * @remove_port: Free resources allocated by probe_port()
9398c2ecf20Sopenharmony_ci * @handle_global_event: Handle a "global" event (may be %NULL)
9408c2ecf20Sopenharmony_ci * @fini_dmaq: Flush and finalise DMA queues (RX and TX queues)
9418c2ecf20Sopenharmony_ci * @prepare_flush: Prepare the hardware for flushing the DMA queues
9428c2ecf20Sopenharmony_ci *	(for Falcon architecture)
9438c2ecf20Sopenharmony_ci * @finish_flush: Clean up after flushing the DMA queues (for Falcon
9448c2ecf20Sopenharmony_ci *	architecture)
9458c2ecf20Sopenharmony_ci * @prepare_flr: Prepare for an FLR
9468c2ecf20Sopenharmony_ci * @finish_flr: Clean up after an FLR
9478c2ecf20Sopenharmony_ci * @describe_stats: Describe statistics for ethtool
9488c2ecf20Sopenharmony_ci * @update_stats: Update statistics not provided by event handling.
9498c2ecf20Sopenharmony_ci *	Either argument may be %NULL.
9508c2ecf20Sopenharmony_ci * @start_stats: Start the regular fetching of statistics
9518c2ecf20Sopenharmony_ci * @pull_stats: Pull stats from the NIC and wait until they arrive.
9528c2ecf20Sopenharmony_ci * @stop_stats: Stop the regular fetching of statistics
9538c2ecf20Sopenharmony_ci * @set_id_led: Set state of identifying LED or revert to automatic function
9548c2ecf20Sopenharmony_ci * @push_irq_moderation: Apply interrupt moderation value
9558c2ecf20Sopenharmony_ci * @reconfigure_port: Push loopback/power/txdis changes to the MAC and PHY
9568c2ecf20Sopenharmony_ci * @prepare_enable_fc_tx: Prepare MAC to enable pause frame TX (may be %NULL)
9578c2ecf20Sopenharmony_ci * @reconfigure_mac: Push MAC address, MTU, flow control and filter settings
9588c2ecf20Sopenharmony_ci *	to the hardware.  Serialised by the mac_lock.
9598c2ecf20Sopenharmony_ci * @check_mac_fault: Check MAC fault state. True if fault present.
9608c2ecf20Sopenharmony_ci * @get_wol: Get WoL configuration from driver state
9618c2ecf20Sopenharmony_ci * @set_wol: Push WoL configuration to the NIC
9628c2ecf20Sopenharmony_ci * @resume_wol: Synchronise WoL state between driver and MC (e.g. after resume)
9638c2ecf20Sopenharmony_ci * @test_chip: Test registers.  May use ef4_farch_test_registers(), and is
9648c2ecf20Sopenharmony_ci *	expected to reset the NIC.
9658c2ecf20Sopenharmony_ci * @test_nvram: Test validity of NVRAM contents
9668c2ecf20Sopenharmony_ci * @irq_enable_master: Enable IRQs on the NIC.  Each event queue must
9678c2ecf20Sopenharmony_ci *	be separately enabled after this.
9688c2ecf20Sopenharmony_ci * @irq_test_generate: Generate a test IRQ
9698c2ecf20Sopenharmony_ci * @irq_disable_non_ev: Disable non-event IRQs on the NIC.  Each event
9708c2ecf20Sopenharmony_ci *	queue must be separately disabled before this.
9718c2ecf20Sopenharmony_ci * @irq_handle_msi: Handle MSI for a channel.  The @dev_id argument is
9728c2ecf20Sopenharmony_ci *	a pointer to the &struct ef4_msi_context for the channel.
9738c2ecf20Sopenharmony_ci * @irq_handle_legacy: Handle legacy interrupt.  The @dev_id argument
9748c2ecf20Sopenharmony_ci *	is a pointer to the &struct ef4_nic.
9758c2ecf20Sopenharmony_ci * @tx_probe: Allocate resources for TX queue
9768c2ecf20Sopenharmony_ci * @tx_init: Initialise TX queue on the NIC
9778c2ecf20Sopenharmony_ci * @tx_remove: Free resources for TX queue
9788c2ecf20Sopenharmony_ci * @tx_write: Write TX descriptors and doorbell
9798c2ecf20Sopenharmony_ci * @rx_push_rss_config: Write RSS hash key and indirection table to the NIC
9808c2ecf20Sopenharmony_ci * @rx_probe: Allocate resources for RX queue
9818c2ecf20Sopenharmony_ci * @rx_init: Initialise RX queue on the NIC
9828c2ecf20Sopenharmony_ci * @rx_remove: Free resources for RX queue
9838c2ecf20Sopenharmony_ci * @rx_write: Write RX descriptors and doorbell
9848c2ecf20Sopenharmony_ci * @rx_defer_refill: Generate a refill reminder event
9858c2ecf20Sopenharmony_ci * @ev_probe: Allocate resources for event queue
9868c2ecf20Sopenharmony_ci * @ev_init: Initialise event queue on the NIC
9878c2ecf20Sopenharmony_ci * @ev_fini: Deinitialise event queue on the NIC
9888c2ecf20Sopenharmony_ci * @ev_remove: Free resources for event queue
9898c2ecf20Sopenharmony_ci * @ev_process: Process events for a queue, up to the given NAPI quota
9908c2ecf20Sopenharmony_ci * @ev_read_ack: Acknowledge read events on a queue, rearming its IRQ
9918c2ecf20Sopenharmony_ci * @ev_test_generate: Generate a test event
9928c2ecf20Sopenharmony_ci * @filter_table_probe: Probe filter capabilities and set up filter software state
9938c2ecf20Sopenharmony_ci * @filter_table_restore: Restore filters removed from hardware
9948c2ecf20Sopenharmony_ci * @filter_table_remove: Remove filters from hardware and tear down software state
9958c2ecf20Sopenharmony_ci * @filter_update_rx_scatter: Update filters after change to rx scatter setting
9968c2ecf20Sopenharmony_ci * @filter_insert: add or replace a filter
9978c2ecf20Sopenharmony_ci * @filter_remove_safe: remove a filter by ID, carefully
9988c2ecf20Sopenharmony_ci * @filter_get_safe: retrieve a filter by ID, carefully
9998c2ecf20Sopenharmony_ci * @filter_clear_rx: Remove all RX filters whose priority is less than or
10008c2ecf20Sopenharmony_ci *	equal to the given priority and is not %EF4_FILTER_PRI_AUTO
10018c2ecf20Sopenharmony_ci * @filter_count_rx_used: Get the number of filters in use at a given priority
10028c2ecf20Sopenharmony_ci * @filter_get_rx_id_limit: Get maximum value of a filter id, plus 1
10038c2ecf20Sopenharmony_ci * @filter_get_rx_ids: Get list of RX filters at a given priority
10048c2ecf20Sopenharmony_ci * @filter_rfs_insert: Add or replace a filter for RFS.  This must be
10058c2ecf20Sopenharmony_ci *	atomic.  The hardware change may be asynchronous but should
10068c2ecf20Sopenharmony_ci *	not be delayed for long.  It may fail if this can't be done
10078c2ecf20Sopenharmony_ci *	atomically.
10088c2ecf20Sopenharmony_ci * @filter_rfs_expire_one: Consider expiring a filter inserted for RFS.
10098c2ecf20Sopenharmony_ci *	This must check whether the specified table entry is used by RFS
10108c2ecf20Sopenharmony_ci *	and that rps_may_expire_flow() returns true for it.
10118c2ecf20Sopenharmony_ci * @mtd_probe: Probe and add MTD partitions associated with this net device,
10128c2ecf20Sopenharmony_ci *	 using ef4_mtd_add()
10138c2ecf20Sopenharmony_ci * @mtd_rename: Set an MTD partition name using the net device name
10148c2ecf20Sopenharmony_ci * @mtd_read: Read from an MTD partition
10158c2ecf20Sopenharmony_ci * @mtd_erase: Erase part of an MTD partition
10168c2ecf20Sopenharmony_ci * @mtd_write: Write to an MTD partition
10178c2ecf20Sopenharmony_ci * @mtd_sync: Wait for write-back to complete on MTD partition.  This
10188c2ecf20Sopenharmony_ci *	also notifies the driver that a writer has finished using this
10198c2ecf20Sopenharmony_ci *	partition.
10208c2ecf20Sopenharmony_ci * @set_mac_address: Set the MAC address of the device
10218c2ecf20Sopenharmony_ci * @revision: Hardware architecture revision
10228c2ecf20Sopenharmony_ci * @txd_ptr_tbl_base: TX descriptor ring base address
10238c2ecf20Sopenharmony_ci * @rxd_ptr_tbl_base: RX descriptor ring base address
10248c2ecf20Sopenharmony_ci * @buf_tbl_base: Buffer table base address
10258c2ecf20Sopenharmony_ci * @evq_ptr_tbl_base: Event queue pointer table base address
10268c2ecf20Sopenharmony_ci * @evq_rptr_tbl_base: Event queue read-pointer table base address
10278c2ecf20Sopenharmony_ci * @max_dma_mask: Maximum possible DMA mask
10288c2ecf20Sopenharmony_ci * @rx_prefix_size: Size of RX prefix before packet data
10298c2ecf20Sopenharmony_ci * @rx_hash_offset: Offset of RX flow hash within prefix
10308c2ecf20Sopenharmony_ci * @rx_ts_offset: Offset of timestamp within prefix
10318c2ecf20Sopenharmony_ci * @rx_buffer_padding: Size of padding at end of RX packet
10328c2ecf20Sopenharmony_ci * @can_rx_scatter: NIC is able to scatter packets to multiple buffers
10338c2ecf20Sopenharmony_ci * @always_rx_scatter: NIC will always scatter packets to multiple buffers
10348c2ecf20Sopenharmony_ci * @max_interrupt_mode: Highest capability interrupt mode supported
10358c2ecf20Sopenharmony_ci *	from &enum ef4_init_mode.
10368c2ecf20Sopenharmony_ci * @timer_period_max: Maximum period of interrupt timer (in ticks)
10378c2ecf20Sopenharmony_ci * @offload_features: net_device feature flags for protocol offload
10388c2ecf20Sopenharmony_ci *	features implemented in hardware
10398c2ecf20Sopenharmony_ci */
10408c2ecf20Sopenharmony_cistruct ef4_nic_type {
10418c2ecf20Sopenharmony_ci	unsigned int mem_bar;
10428c2ecf20Sopenharmony_ci	unsigned int (*mem_map_size)(struct ef4_nic *efx);
10438c2ecf20Sopenharmony_ci	int (*probe)(struct ef4_nic *efx);
10448c2ecf20Sopenharmony_ci	void (*remove)(struct ef4_nic *efx);
10458c2ecf20Sopenharmony_ci	int (*init)(struct ef4_nic *efx);
10468c2ecf20Sopenharmony_ci	int (*dimension_resources)(struct ef4_nic *efx);
10478c2ecf20Sopenharmony_ci	void (*fini)(struct ef4_nic *efx);
10488c2ecf20Sopenharmony_ci	void (*monitor)(struct ef4_nic *efx);
10498c2ecf20Sopenharmony_ci	enum reset_type (*map_reset_reason)(enum reset_type reason);
10508c2ecf20Sopenharmony_ci	int (*map_reset_flags)(u32 *flags);
10518c2ecf20Sopenharmony_ci	int (*reset)(struct ef4_nic *efx, enum reset_type method);
10528c2ecf20Sopenharmony_ci	int (*probe_port)(struct ef4_nic *efx);
10538c2ecf20Sopenharmony_ci	void (*remove_port)(struct ef4_nic *efx);
10548c2ecf20Sopenharmony_ci	bool (*handle_global_event)(struct ef4_channel *channel, ef4_qword_t *);
10558c2ecf20Sopenharmony_ci	int (*fini_dmaq)(struct ef4_nic *efx);
10568c2ecf20Sopenharmony_ci	void (*prepare_flush)(struct ef4_nic *efx);
10578c2ecf20Sopenharmony_ci	void (*finish_flush)(struct ef4_nic *efx);
10588c2ecf20Sopenharmony_ci	void (*prepare_flr)(struct ef4_nic *efx);
10598c2ecf20Sopenharmony_ci	void (*finish_flr)(struct ef4_nic *efx);
10608c2ecf20Sopenharmony_ci	size_t (*describe_stats)(struct ef4_nic *efx, u8 *names);
10618c2ecf20Sopenharmony_ci	size_t (*update_stats)(struct ef4_nic *efx, u64 *full_stats,
10628c2ecf20Sopenharmony_ci			       struct rtnl_link_stats64 *core_stats);
10638c2ecf20Sopenharmony_ci	void (*start_stats)(struct ef4_nic *efx);
10648c2ecf20Sopenharmony_ci	void (*pull_stats)(struct ef4_nic *efx);
10658c2ecf20Sopenharmony_ci	void (*stop_stats)(struct ef4_nic *efx);
10668c2ecf20Sopenharmony_ci	void (*set_id_led)(struct ef4_nic *efx, enum ef4_led_mode mode);
10678c2ecf20Sopenharmony_ci	void (*push_irq_moderation)(struct ef4_channel *channel);
10688c2ecf20Sopenharmony_ci	int (*reconfigure_port)(struct ef4_nic *efx);
10698c2ecf20Sopenharmony_ci	void (*prepare_enable_fc_tx)(struct ef4_nic *efx);
10708c2ecf20Sopenharmony_ci	int (*reconfigure_mac)(struct ef4_nic *efx);
10718c2ecf20Sopenharmony_ci	bool (*check_mac_fault)(struct ef4_nic *efx);
10728c2ecf20Sopenharmony_ci	void (*get_wol)(struct ef4_nic *efx, struct ethtool_wolinfo *wol);
10738c2ecf20Sopenharmony_ci	int (*set_wol)(struct ef4_nic *efx, u32 type);
10748c2ecf20Sopenharmony_ci	void (*resume_wol)(struct ef4_nic *efx);
10758c2ecf20Sopenharmony_ci	int (*test_chip)(struct ef4_nic *efx, struct ef4_self_tests *tests);
10768c2ecf20Sopenharmony_ci	int (*test_nvram)(struct ef4_nic *efx);
10778c2ecf20Sopenharmony_ci	void (*irq_enable_master)(struct ef4_nic *efx);
10788c2ecf20Sopenharmony_ci	int (*irq_test_generate)(struct ef4_nic *efx);
10798c2ecf20Sopenharmony_ci	void (*irq_disable_non_ev)(struct ef4_nic *efx);
10808c2ecf20Sopenharmony_ci	irqreturn_t (*irq_handle_msi)(int irq, void *dev_id);
10818c2ecf20Sopenharmony_ci	irqreturn_t (*irq_handle_legacy)(int irq, void *dev_id);
10828c2ecf20Sopenharmony_ci	int (*tx_probe)(struct ef4_tx_queue *tx_queue);
10838c2ecf20Sopenharmony_ci	void (*tx_init)(struct ef4_tx_queue *tx_queue);
10848c2ecf20Sopenharmony_ci	void (*tx_remove)(struct ef4_tx_queue *tx_queue);
10858c2ecf20Sopenharmony_ci	void (*tx_write)(struct ef4_tx_queue *tx_queue);
10868c2ecf20Sopenharmony_ci	unsigned int (*tx_limit_len)(struct ef4_tx_queue *tx_queue,
10878c2ecf20Sopenharmony_ci				     dma_addr_t dma_addr, unsigned int len);
10888c2ecf20Sopenharmony_ci	int (*rx_push_rss_config)(struct ef4_nic *efx, bool user,
10898c2ecf20Sopenharmony_ci				  const u32 *rx_indir_table);
10908c2ecf20Sopenharmony_ci	int (*rx_probe)(struct ef4_rx_queue *rx_queue);
10918c2ecf20Sopenharmony_ci	void (*rx_init)(struct ef4_rx_queue *rx_queue);
10928c2ecf20Sopenharmony_ci	void (*rx_remove)(struct ef4_rx_queue *rx_queue);
10938c2ecf20Sopenharmony_ci	void (*rx_write)(struct ef4_rx_queue *rx_queue);
10948c2ecf20Sopenharmony_ci	void (*rx_defer_refill)(struct ef4_rx_queue *rx_queue);
10958c2ecf20Sopenharmony_ci	int (*ev_probe)(struct ef4_channel *channel);
10968c2ecf20Sopenharmony_ci	int (*ev_init)(struct ef4_channel *channel);
10978c2ecf20Sopenharmony_ci	void (*ev_fini)(struct ef4_channel *channel);
10988c2ecf20Sopenharmony_ci	void (*ev_remove)(struct ef4_channel *channel);
10998c2ecf20Sopenharmony_ci	int (*ev_process)(struct ef4_channel *channel, int quota);
11008c2ecf20Sopenharmony_ci	void (*ev_read_ack)(struct ef4_channel *channel);
11018c2ecf20Sopenharmony_ci	void (*ev_test_generate)(struct ef4_channel *channel);
11028c2ecf20Sopenharmony_ci	int (*filter_table_probe)(struct ef4_nic *efx);
11038c2ecf20Sopenharmony_ci	void (*filter_table_restore)(struct ef4_nic *efx);
11048c2ecf20Sopenharmony_ci	void (*filter_table_remove)(struct ef4_nic *efx);
11058c2ecf20Sopenharmony_ci	void (*filter_update_rx_scatter)(struct ef4_nic *efx);
11068c2ecf20Sopenharmony_ci	s32 (*filter_insert)(struct ef4_nic *efx,
11078c2ecf20Sopenharmony_ci			     struct ef4_filter_spec *spec, bool replace);
11088c2ecf20Sopenharmony_ci	int (*filter_remove_safe)(struct ef4_nic *efx,
11098c2ecf20Sopenharmony_ci				  enum ef4_filter_priority priority,
11108c2ecf20Sopenharmony_ci				  u32 filter_id);
11118c2ecf20Sopenharmony_ci	int (*filter_get_safe)(struct ef4_nic *efx,
11128c2ecf20Sopenharmony_ci			       enum ef4_filter_priority priority,
11138c2ecf20Sopenharmony_ci			       u32 filter_id, struct ef4_filter_spec *);
11148c2ecf20Sopenharmony_ci	int (*filter_clear_rx)(struct ef4_nic *efx,
11158c2ecf20Sopenharmony_ci			       enum ef4_filter_priority priority);
11168c2ecf20Sopenharmony_ci	u32 (*filter_count_rx_used)(struct ef4_nic *efx,
11178c2ecf20Sopenharmony_ci				    enum ef4_filter_priority priority);
11188c2ecf20Sopenharmony_ci	u32 (*filter_get_rx_id_limit)(struct ef4_nic *efx);
11198c2ecf20Sopenharmony_ci	s32 (*filter_get_rx_ids)(struct ef4_nic *efx,
11208c2ecf20Sopenharmony_ci				 enum ef4_filter_priority priority,
11218c2ecf20Sopenharmony_ci				 u32 *buf, u32 size);
11228c2ecf20Sopenharmony_ci#ifdef CONFIG_RFS_ACCEL
11238c2ecf20Sopenharmony_ci	s32 (*filter_rfs_insert)(struct ef4_nic *efx,
11248c2ecf20Sopenharmony_ci				 struct ef4_filter_spec *spec);
11258c2ecf20Sopenharmony_ci	bool (*filter_rfs_expire_one)(struct ef4_nic *efx, u32 flow_id,
11268c2ecf20Sopenharmony_ci				      unsigned int index);
11278c2ecf20Sopenharmony_ci#endif
11288c2ecf20Sopenharmony_ci#ifdef CONFIG_SFC_FALCON_MTD
11298c2ecf20Sopenharmony_ci	int (*mtd_probe)(struct ef4_nic *efx);
11308c2ecf20Sopenharmony_ci	void (*mtd_rename)(struct ef4_mtd_partition *part);
11318c2ecf20Sopenharmony_ci	int (*mtd_read)(struct mtd_info *mtd, loff_t start, size_t len,
11328c2ecf20Sopenharmony_ci			size_t *retlen, u8 *buffer);
11338c2ecf20Sopenharmony_ci	int (*mtd_erase)(struct mtd_info *mtd, loff_t start, size_t len);
11348c2ecf20Sopenharmony_ci	int (*mtd_write)(struct mtd_info *mtd, loff_t start, size_t len,
11358c2ecf20Sopenharmony_ci			 size_t *retlen, const u8 *buffer);
11368c2ecf20Sopenharmony_ci	int (*mtd_sync)(struct mtd_info *mtd);
11378c2ecf20Sopenharmony_ci#endif
11388c2ecf20Sopenharmony_ci	int (*get_mac_address)(struct ef4_nic *efx, unsigned char *perm_addr);
11398c2ecf20Sopenharmony_ci	int (*set_mac_address)(struct ef4_nic *efx);
11408c2ecf20Sopenharmony_ci
11418c2ecf20Sopenharmony_ci	int revision;
11428c2ecf20Sopenharmony_ci	unsigned int txd_ptr_tbl_base;
11438c2ecf20Sopenharmony_ci	unsigned int rxd_ptr_tbl_base;
11448c2ecf20Sopenharmony_ci	unsigned int buf_tbl_base;
11458c2ecf20Sopenharmony_ci	unsigned int evq_ptr_tbl_base;
11468c2ecf20Sopenharmony_ci	unsigned int evq_rptr_tbl_base;
11478c2ecf20Sopenharmony_ci	u64 max_dma_mask;
11488c2ecf20Sopenharmony_ci	unsigned int rx_prefix_size;
11498c2ecf20Sopenharmony_ci	unsigned int rx_hash_offset;
11508c2ecf20Sopenharmony_ci	unsigned int rx_ts_offset;
11518c2ecf20Sopenharmony_ci	unsigned int rx_buffer_padding;
11528c2ecf20Sopenharmony_ci	bool can_rx_scatter;
11538c2ecf20Sopenharmony_ci	bool always_rx_scatter;
11548c2ecf20Sopenharmony_ci	unsigned int max_interrupt_mode;
11558c2ecf20Sopenharmony_ci	unsigned int timer_period_max;
11568c2ecf20Sopenharmony_ci	netdev_features_t offload_features;
11578c2ecf20Sopenharmony_ci	unsigned int max_rx_ip_filters;
11588c2ecf20Sopenharmony_ci};
11598c2ecf20Sopenharmony_ci
11608c2ecf20Sopenharmony_ci/**************************************************************************
11618c2ecf20Sopenharmony_ci *
11628c2ecf20Sopenharmony_ci * Prototypes and inline functions
11638c2ecf20Sopenharmony_ci *
11648c2ecf20Sopenharmony_ci *************************************************************************/
11658c2ecf20Sopenharmony_ci
11668c2ecf20Sopenharmony_cistatic inline struct ef4_channel *
11678c2ecf20Sopenharmony_cief4_get_channel(struct ef4_nic *efx, unsigned index)
11688c2ecf20Sopenharmony_ci{
11698c2ecf20Sopenharmony_ci	EF4_BUG_ON_PARANOID(index >= efx->n_channels);
11708c2ecf20Sopenharmony_ci	return efx->channel[index];
11718c2ecf20Sopenharmony_ci}
11728c2ecf20Sopenharmony_ci
11738c2ecf20Sopenharmony_ci/* Iterate over all used channels */
11748c2ecf20Sopenharmony_ci#define ef4_for_each_channel(_channel, _efx)				\
11758c2ecf20Sopenharmony_ci	for (_channel = (_efx)->channel[0];				\
11768c2ecf20Sopenharmony_ci	     _channel;							\
11778c2ecf20Sopenharmony_ci	     _channel = (_channel->channel + 1 < (_efx)->n_channels) ?	\
11788c2ecf20Sopenharmony_ci		     (_efx)->channel[_channel->channel + 1] : NULL)
11798c2ecf20Sopenharmony_ci
11808c2ecf20Sopenharmony_ci/* Iterate over all used channels in reverse */
11818c2ecf20Sopenharmony_ci#define ef4_for_each_channel_rev(_channel, _efx)			\
11828c2ecf20Sopenharmony_ci	for (_channel = (_efx)->channel[(_efx)->n_channels - 1];	\
11838c2ecf20Sopenharmony_ci	     _channel;							\
11848c2ecf20Sopenharmony_ci	     _channel = _channel->channel ?				\
11858c2ecf20Sopenharmony_ci		     (_efx)->channel[_channel->channel - 1] : NULL)
11868c2ecf20Sopenharmony_ci
11878c2ecf20Sopenharmony_cistatic inline struct ef4_tx_queue *
11888c2ecf20Sopenharmony_cief4_get_tx_queue(struct ef4_nic *efx, unsigned index, unsigned type)
11898c2ecf20Sopenharmony_ci{
11908c2ecf20Sopenharmony_ci	EF4_BUG_ON_PARANOID(index >= efx->n_tx_channels ||
11918c2ecf20Sopenharmony_ci			    type >= EF4_TXQ_TYPES);
11928c2ecf20Sopenharmony_ci	return &efx->channel[efx->tx_channel_offset + index]->tx_queue[type];
11938c2ecf20Sopenharmony_ci}
11948c2ecf20Sopenharmony_ci
11958c2ecf20Sopenharmony_cistatic inline bool ef4_channel_has_tx_queues(struct ef4_channel *channel)
11968c2ecf20Sopenharmony_ci{
11978c2ecf20Sopenharmony_ci	return channel->channel - channel->efx->tx_channel_offset <
11988c2ecf20Sopenharmony_ci		channel->efx->n_tx_channels;
11998c2ecf20Sopenharmony_ci}
12008c2ecf20Sopenharmony_ci
12018c2ecf20Sopenharmony_cistatic inline struct ef4_tx_queue *
12028c2ecf20Sopenharmony_cief4_channel_get_tx_queue(struct ef4_channel *channel, unsigned type)
12038c2ecf20Sopenharmony_ci{
12048c2ecf20Sopenharmony_ci	EF4_BUG_ON_PARANOID(!ef4_channel_has_tx_queues(channel) ||
12058c2ecf20Sopenharmony_ci			    type >= EF4_TXQ_TYPES);
12068c2ecf20Sopenharmony_ci	return &channel->tx_queue[type];
12078c2ecf20Sopenharmony_ci}
12088c2ecf20Sopenharmony_ci
12098c2ecf20Sopenharmony_cistatic inline bool ef4_tx_queue_used(struct ef4_tx_queue *tx_queue)
12108c2ecf20Sopenharmony_ci{
12118c2ecf20Sopenharmony_ci	return !(tx_queue->efx->net_dev->num_tc < 2 &&
12128c2ecf20Sopenharmony_ci		 tx_queue->queue & EF4_TXQ_TYPE_HIGHPRI);
12138c2ecf20Sopenharmony_ci}
12148c2ecf20Sopenharmony_ci
12158c2ecf20Sopenharmony_ci/* Iterate over all TX queues belonging to a channel */
12168c2ecf20Sopenharmony_ci#define ef4_for_each_channel_tx_queue(_tx_queue, _channel)		\
12178c2ecf20Sopenharmony_ci	if (!ef4_channel_has_tx_queues(_channel))			\
12188c2ecf20Sopenharmony_ci		;							\
12198c2ecf20Sopenharmony_ci	else								\
12208c2ecf20Sopenharmony_ci		for (_tx_queue = (_channel)->tx_queue;			\
12218c2ecf20Sopenharmony_ci		     _tx_queue < (_channel)->tx_queue + EF4_TXQ_TYPES && \
12228c2ecf20Sopenharmony_ci			     ef4_tx_queue_used(_tx_queue);		\
12238c2ecf20Sopenharmony_ci		     _tx_queue++)
12248c2ecf20Sopenharmony_ci
12258c2ecf20Sopenharmony_ci/* Iterate over all possible TX queues belonging to a channel */
12268c2ecf20Sopenharmony_ci#define ef4_for_each_possible_channel_tx_queue(_tx_queue, _channel)	\
12278c2ecf20Sopenharmony_ci	if (!ef4_channel_has_tx_queues(_channel))			\
12288c2ecf20Sopenharmony_ci		;							\
12298c2ecf20Sopenharmony_ci	else								\
12308c2ecf20Sopenharmony_ci		for (_tx_queue = (_channel)->tx_queue;			\
12318c2ecf20Sopenharmony_ci		     _tx_queue < (_channel)->tx_queue + EF4_TXQ_TYPES;	\
12328c2ecf20Sopenharmony_ci		     _tx_queue++)
12338c2ecf20Sopenharmony_ci
12348c2ecf20Sopenharmony_cistatic inline bool ef4_channel_has_rx_queue(struct ef4_channel *channel)
12358c2ecf20Sopenharmony_ci{
12368c2ecf20Sopenharmony_ci	return channel->rx_queue.core_index >= 0;
12378c2ecf20Sopenharmony_ci}
12388c2ecf20Sopenharmony_ci
12398c2ecf20Sopenharmony_cistatic inline struct ef4_rx_queue *
12408c2ecf20Sopenharmony_cief4_channel_get_rx_queue(struct ef4_channel *channel)
12418c2ecf20Sopenharmony_ci{
12428c2ecf20Sopenharmony_ci	EF4_BUG_ON_PARANOID(!ef4_channel_has_rx_queue(channel));
12438c2ecf20Sopenharmony_ci	return &channel->rx_queue;
12448c2ecf20Sopenharmony_ci}
12458c2ecf20Sopenharmony_ci
12468c2ecf20Sopenharmony_ci/* Iterate over all RX queues belonging to a channel */
12478c2ecf20Sopenharmony_ci#define ef4_for_each_channel_rx_queue(_rx_queue, _channel)		\
12488c2ecf20Sopenharmony_ci	if (!ef4_channel_has_rx_queue(_channel))			\
12498c2ecf20Sopenharmony_ci		;							\
12508c2ecf20Sopenharmony_ci	else								\
12518c2ecf20Sopenharmony_ci		for (_rx_queue = &(_channel)->rx_queue;			\
12528c2ecf20Sopenharmony_ci		     _rx_queue;						\
12538c2ecf20Sopenharmony_ci		     _rx_queue = NULL)
12548c2ecf20Sopenharmony_ci
12558c2ecf20Sopenharmony_cistatic inline struct ef4_channel *
12568c2ecf20Sopenharmony_cief4_rx_queue_channel(struct ef4_rx_queue *rx_queue)
12578c2ecf20Sopenharmony_ci{
12588c2ecf20Sopenharmony_ci	return container_of(rx_queue, struct ef4_channel, rx_queue);
12598c2ecf20Sopenharmony_ci}
12608c2ecf20Sopenharmony_ci
12618c2ecf20Sopenharmony_cistatic inline int ef4_rx_queue_index(struct ef4_rx_queue *rx_queue)
12628c2ecf20Sopenharmony_ci{
12638c2ecf20Sopenharmony_ci	return ef4_rx_queue_channel(rx_queue)->channel;
12648c2ecf20Sopenharmony_ci}
12658c2ecf20Sopenharmony_ci
12668c2ecf20Sopenharmony_ci/* Returns a pointer to the specified receive buffer in the RX
12678c2ecf20Sopenharmony_ci * descriptor queue.
12688c2ecf20Sopenharmony_ci */
12698c2ecf20Sopenharmony_cistatic inline struct ef4_rx_buffer *ef4_rx_buffer(struct ef4_rx_queue *rx_queue,
12708c2ecf20Sopenharmony_ci						  unsigned int index)
12718c2ecf20Sopenharmony_ci{
12728c2ecf20Sopenharmony_ci	return &rx_queue->buffer[index];
12738c2ecf20Sopenharmony_ci}
12748c2ecf20Sopenharmony_ci
12758c2ecf20Sopenharmony_ci/**
12768c2ecf20Sopenharmony_ci * EF4_MAX_FRAME_LEN - calculate maximum frame length
12778c2ecf20Sopenharmony_ci *
12788c2ecf20Sopenharmony_ci * This calculates the maximum frame length that will be used for a
12798c2ecf20Sopenharmony_ci * given MTU.  The frame length will be equal to the MTU plus a
12808c2ecf20Sopenharmony_ci * constant amount of header space and padding.  This is the quantity
12818c2ecf20Sopenharmony_ci * that the net driver will program into the MAC as the maximum frame
12828c2ecf20Sopenharmony_ci * length.
12838c2ecf20Sopenharmony_ci *
12848c2ecf20Sopenharmony_ci * The 10G MAC requires 8-byte alignment on the frame
12858c2ecf20Sopenharmony_ci * length, so we round up to the nearest 8.
12868c2ecf20Sopenharmony_ci *
12878c2ecf20Sopenharmony_ci * Re-clocking by the XGXS on RX can reduce an IPG to 32 bits (half an
12888c2ecf20Sopenharmony_ci * XGMII cycle).  If the frame length reaches the maximum value in the
12898c2ecf20Sopenharmony_ci * same cycle, the XMAC can miss the IPG altogether.  We work around
12908c2ecf20Sopenharmony_ci * this by adding a further 16 bytes.
12918c2ecf20Sopenharmony_ci */
12928c2ecf20Sopenharmony_ci#define EF4_FRAME_PAD	16
12938c2ecf20Sopenharmony_ci#define EF4_MAX_FRAME_LEN(mtu) \
12948c2ecf20Sopenharmony_ci	(ALIGN(((mtu) + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN + EF4_FRAME_PAD), 8))
12958c2ecf20Sopenharmony_ci
12968c2ecf20Sopenharmony_ci/* Get all supported features.
12978c2ecf20Sopenharmony_ci * If a feature is not fixed, it is present in hw_features.
12988c2ecf20Sopenharmony_ci * If a feature is fixed, it does not present in hw_features, but
12998c2ecf20Sopenharmony_ci * always in features.
13008c2ecf20Sopenharmony_ci */
13018c2ecf20Sopenharmony_cistatic inline netdev_features_t ef4_supported_features(const struct ef4_nic *efx)
13028c2ecf20Sopenharmony_ci{
13038c2ecf20Sopenharmony_ci	const struct net_device *net_dev = efx->net_dev;
13048c2ecf20Sopenharmony_ci
13058c2ecf20Sopenharmony_ci	return net_dev->features | net_dev->hw_features;
13068c2ecf20Sopenharmony_ci}
13078c2ecf20Sopenharmony_ci
13088c2ecf20Sopenharmony_ci/* Get the current TX queue insert index. */
13098c2ecf20Sopenharmony_cistatic inline unsigned int
13108c2ecf20Sopenharmony_cief4_tx_queue_get_insert_index(const struct ef4_tx_queue *tx_queue)
13118c2ecf20Sopenharmony_ci{
13128c2ecf20Sopenharmony_ci	return tx_queue->insert_count & tx_queue->ptr_mask;
13138c2ecf20Sopenharmony_ci}
13148c2ecf20Sopenharmony_ci
13158c2ecf20Sopenharmony_ci/* Get a TX buffer. */
13168c2ecf20Sopenharmony_cistatic inline struct ef4_tx_buffer *
13178c2ecf20Sopenharmony_ci__ef4_tx_queue_get_insert_buffer(const struct ef4_tx_queue *tx_queue)
13188c2ecf20Sopenharmony_ci{
13198c2ecf20Sopenharmony_ci	return &tx_queue->buffer[ef4_tx_queue_get_insert_index(tx_queue)];
13208c2ecf20Sopenharmony_ci}
13218c2ecf20Sopenharmony_ci
13228c2ecf20Sopenharmony_ci/* Get a TX buffer, checking it's not currently in use. */
13238c2ecf20Sopenharmony_cistatic inline struct ef4_tx_buffer *
13248c2ecf20Sopenharmony_cief4_tx_queue_get_insert_buffer(const struct ef4_tx_queue *tx_queue)
13258c2ecf20Sopenharmony_ci{
13268c2ecf20Sopenharmony_ci	struct ef4_tx_buffer *buffer =
13278c2ecf20Sopenharmony_ci		__ef4_tx_queue_get_insert_buffer(tx_queue);
13288c2ecf20Sopenharmony_ci
13298c2ecf20Sopenharmony_ci	EF4_BUG_ON_PARANOID(buffer->len);
13308c2ecf20Sopenharmony_ci	EF4_BUG_ON_PARANOID(buffer->flags);
13318c2ecf20Sopenharmony_ci	EF4_BUG_ON_PARANOID(buffer->unmap_len);
13328c2ecf20Sopenharmony_ci
13338c2ecf20Sopenharmony_ci	return buffer;
13348c2ecf20Sopenharmony_ci}
13358c2ecf20Sopenharmony_ci
13368c2ecf20Sopenharmony_ci#endif /* EF4_NET_DRIVER_H */
1337