xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/sfc/falcon/net_driver.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /****************************************************************************
3*4882a593Smuzhiyun  * Driver for Solarflare network controllers and boards
4*4882a593Smuzhiyun  * Copyright 2005-2006 Fen Systems Ltd.
5*4882a593Smuzhiyun  * Copyright 2005-2013 Solarflare Communications Inc.
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun /* Common definitions for all Efx net driver code */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #ifndef EF4_NET_DRIVER_H
11*4882a593Smuzhiyun #define EF4_NET_DRIVER_H
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <linux/netdevice.h>
14*4882a593Smuzhiyun #include <linux/etherdevice.h>
15*4882a593Smuzhiyun #include <linux/ethtool.h>
16*4882a593Smuzhiyun #include <linux/if_vlan.h>
17*4882a593Smuzhiyun #include <linux/timer.h>
18*4882a593Smuzhiyun #include <linux/mdio.h>
19*4882a593Smuzhiyun #include <linux/list.h>
20*4882a593Smuzhiyun #include <linux/pci.h>
21*4882a593Smuzhiyun #include <linux/device.h>
22*4882a593Smuzhiyun #include <linux/highmem.h>
23*4882a593Smuzhiyun #include <linux/workqueue.h>
24*4882a593Smuzhiyun #include <linux/mutex.h>
25*4882a593Smuzhiyun #include <linux/rwsem.h>
26*4882a593Smuzhiyun #include <linux/vmalloc.h>
27*4882a593Smuzhiyun #include <linux/i2c.h>
28*4882a593Smuzhiyun #include <linux/mtd/mtd.h>
29*4882a593Smuzhiyun #include <net/busy_poll.h>
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #include "enum.h"
32*4882a593Smuzhiyun #include "bitfield.h"
33*4882a593Smuzhiyun #include "filter.h"
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun /**************************************************************************
36*4882a593Smuzhiyun  *
37*4882a593Smuzhiyun  * Build definitions
38*4882a593Smuzhiyun  *
39*4882a593Smuzhiyun  **************************************************************************/
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun #define EF4_DRIVER_VERSION	"4.1"
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun #ifdef DEBUG
44*4882a593Smuzhiyun #define EF4_BUG_ON_PARANOID(x) BUG_ON(x)
45*4882a593Smuzhiyun #define EF4_WARN_ON_PARANOID(x) WARN_ON(x)
46*4882a593Smuzhiyun #else
47*4882a593Smuzhiyun #define EF4_BUG_ON_PARANOID(x) do {} while (0)
48*4882a593Smuzhiyun #define EF4_WARN_ON_PARANOID(x) do {} while (0)
49*4882a593Smuzhiyun #endif
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun /**************************************************************************
52*4882a593Smuzhiyun  *
53*4882a593Smuzhiyun  * Efx data structures
54*4882a593Smuzhiyun  *
55*4882a593Smuzhiyun  **************************************************************************/
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun #define EF4_MAX_CHANNELS 32U
58*4882a593Smuzhiyun #define EF4_MAX_RX_QUEUES EF4_MAX_CHANNELS
59*4882a593Smuzhiyun #define EF4_EXTRA_CHANNEL_IOV	0
60*4882a593Smuzhiyun #define EF4_EXTRA_CHANNEL_PTP	1
61*4882a593Smuzhiyun #define EF4_MAX_EXTRA_CHANNELS	2U
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /* Checksum generation is a per-queue option in hardware, so each
64*4882a593Smuzhiyun  * queue visible to the networking core is backed by two hardware TX
65*4882a593Smuzhiyun  * queues. */
66*4882a593Smuzhiyun #define EF4_MAX_TX_TC		2
67*4882a593Smuzhiyun #define EF4_MAX_CORE_TX_QUEUES	(EF4_MAX_TX_TC * EF4_MAX_CHANNELS)
68*4882a593Smuzhiyun #define EF4_TXQ_TYPE_OFFLOAD	1	/* flag */
69*4882a593Smuzhiyun #define EF4_TXQ_TYPE_HIGHPRI	2	/* flag */
70*4882a593Smuzhiyun #define EF4_TXQ_TYPES		4
71*4882a593Smuzhiyun #define EF4_MAX_TX_QUEUES	(EF4_TXQ_TYPES * EF4_MAX_CHANNELS)
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun /* Maximum possible MTU the driver supports */
74*4882a593Smuzhiyun #define EF4_MAX_MTU (9 * 1024)
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun /* Minimum MTU, from RFC791 (IP) */
77*4882a593Smuzhiyun #define EF4_MIN_MTU 68
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun /* Size of an RX scatter buffer.  Small enough to pack 2 into a 4K page,
80*4882a593Smuzhiyun  * and should be a multiple of the cache line size.
81*4882a593Smuzhiyun  */
82*4882a593Smuzhiyun #define EF4_RX_USR_BUF_SIZE	(2048 - 256)
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun /* If possible, we should ensure cache line alignment at start and end
85*4882a593Smuzhiyun  * of every buffer.  Otherwise, we just need to ensure 4-byte
86*4882a593Smuzhiyun  * alignment of the network header.
87*4882a593Smuzhiyun  */
88*4882a593Smuzhiyun #if NET_IP_ALIGN == 0
89*4882a593Smuzhiyun #define EF4_RX_BUF_ALIGNMENT	L1_CACHE_BYTES
90*4882a593Smuzhiyun #else
91*4882a593Smuzhiyun #define EF4_RX_BUF_ALIGNMENT	4
92*4882a593Smuzhiyun #endif
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun struct ef4_self_tests;
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun /**
97*4882a593Smuzhiyun  * struct ef4_buffer - A general-purpose DMA buffer
98*4882a593Smuzhiyun  * @addr: host base address of the buffer
99*4882a593Smuzhiyun  * @dma_addr: DMA base address of the buffer
100*4882a593Smuzhiyun  * @len: Buffer length, in bytes
101*4882a593Smuzhiyun  *
102*4882a593Smuzhiyun  * The NIC uses these buffers for its interrupt status registers and
103*4882a593Smuzhiyun  * MAC stats dumps.
104*4882a593Smuzhiyun  */
105*4882a593Smuzhiyun struct ef4_buffer {
106*4882a593Smuzhiyun 	void *addr;
107*4882a593Smuzhiyun 	dma_addr_t dma_addr;
108*4882a593Smuzhiyun 	unsigned int len;
109*4882a593Smuzhiyun };
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun /**
112*4882a593Smuzhiyun  * struct ef4_special_buffer - DMA buffer entered into buffer table
113*4882a593Smuzhiyun  * @buf: Standard &struct ef4_buffer
114*4882a593Smuzhiyun  * @index: Buffer index within controller;s buffer table
115*4882a593Smuzhiyun  * @entries: Number of buffer table entries
116*4882a593Smuzhiyun  *
117*4882a593Smuzhiyun  * The NIC has a buffer table that maps buffers of size %EF4_BUF_SIZE.
118*4882a593Smuzhiyun  * Event and descriptor rings are addressed via one or more buffer
119*4882a593Smuzhiyun  * table entries (and so can be physically non-contiguous, although we
120*4882a593Smuzhiyun  * currently do not take advantage of that).  On Falcon and Siena we
121*4882a593Smuzhiyun  * have to take care of allocating and initialising the entries
122*4882a593Smuzhiyun  * ourselves.  On later hardware this is managed by the firmware and
123*4882a593Smuzhiyun  * @index and @entries are left as 0.
124*4882a593Smuzhiyun  */
125*4882a593Smuzhiyun struct ef4_special_buffer {
126*4882a593Smuzhiyun 	struct ef4_buffer buf;
127*4882a593Smuzhiyun 	unsigned int index;
128*4882a593Smuzhiyun 	unsigned int entries;
129*4882a593Smuzhiyun };
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun /**
132*4882a593Smuzhiyun  * struct ef4_tx_buffer - buffer state for a TX descriptor
133*4882a593Smuzhiyun  * @skb: When @flags & %EF4_TX_BUF_SKB, the associated socket buffer to be
134*4882a593Smuzhiyun  *	freed when descriptor completes
135*4882a593Smuzhiyun  * @option: When @flags & %EF4_TX_BUF_OPTION, a NIC-specific option descriptor.
136*4882a593Smuzhiyun  * @dma_addr: DMA address of the fragment.
137*4882a593Smuzhiyun  * @flags: Flags for allocation and DMA mapping type
138*4882a593Smuzhiyun  * @len: Length of this fragment.
139*4882a593Smuzhiyun  *	This field is zero when the queue slot is empty.
140*4882a593Smuzhiyun  * @unmap_len: Length of this fragment to unmap
141*4882a593Smuzhiyun  * @dma_offset: Offset of @dma_addr from the address of the backing DMA mapping.
142*4882a593Smuzhiyun  * Only valid if @unmap_len != 0.
143*4882a593Smuzhiyun  */
144*4882a593Smuzhiyun struct ef4_tx_buffer {
145*4882a593Smuzhiyun 	const struct sk_buff *skb;
146*4882a593Smuzhiyun 	union {
147*4882a593Smuzhiyun 		ef4_qword_t option;
148*4882a593Smuzhiyun 		dma_addr_t dma_addr;
149*4882a593Smuzhiyun 	};
150*4882a593Smuzhiyun 	unsigned short flags;
151*4882a593Smuzhiyun 	unsigned short len;
152*4882a593Smuzhiyun 	unsigned short unmap_len;
153*4882a593Smuzhiyun 	unsigned short dma_offset;
154*4882a593Smuzhiyun };
155*4882a593Smuzhiyun #define EF4_TX_BUF_CONT		1	/* not last descriptor of packet */
156*4882a593Smuzhiyun #define EF4_TX_BUF_SKB		2	/* buffer is last part of skb */
157*4882a593Smuzhiyun #define EF4_TX_BUF_MAP_SINGLE	8	/* buffer was mapped with dma_map_single() */
158*4882a593Smuzhiyun #define EF4_TX_BUF_OPTION	0x10	/* empty buffer for option descriptor */
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun /**
161*4882a593Smuzhiyun  * struct ef4_tx_queue - An Efx TX queue
162*4882a593Smuzhiyun  *
163*4882a593Smuzhiyun  * This is a ring buffer of TX fragments.
164*4882a593Smuzhiyun  * Since the TX completion path always executes on the same
165*4882a593Smuzhiyun  * CPU and the xmit path can operate on different CPUs,
166*4882a593Smuzhiyun  * performance is increased by ensuring that the completion
167*4882a593Smuzhiyun  * path and the xmit path operate on different cache lines.
168*4882a593Smuzhiyun  * This is particularly important if the xmit path is always
169*4882a593Smuzhiyun  * executing on one CPU which is different from the completion
170*4882a593Smuzhiyun  * path.  There is also a cache line for members which are
171*4882a593Smuzhiyun  * read but not written on the fast path.
172*4882a593Smuzhiyun  *
173*4882a593Smuzhiyun  * @efx: The associated Efx NIC
174*4882a593Smuzhiyun  * @queue: DMA queue number
175*4882a593Smuzhiyun  * @channel: The associated channel
176*4882a593Smuzhiyun  * @core_txq: The networking core TX queue structure
177*4882a593Smuzhiyun  * @buffer: The software buffer ring
178*4882a593Smuzhiyun  * @cb_page: Array of pages of copy buffers.  Carved up according to
179*4882a593Smuzhiyun  *	%EF4_TX_CB_ORDER into %EF4_TX_CB_SIZE-sized chunks.
180*4882a593Smuzhiyun  * @txd: The hardware descriptor ring
181*4882a593Smuzhiyun  * @ptr_mask: The size of the ring minus 1.
182*4882a593Smuzhiyun  * @initialised: Has hardware queue been initialised?
183*4882a593Smuzhiyun  * @tx_min_size: Minimum transmit size for this queue. Depends on HW.
184*4882a593Smuzhiyun  * @read_count: Current read pointer.
185*4882a593Smuzhiyun  *	This is the number of buffers that have been removed from both rings.
186*4882a593Smuzhiyun  * @old_write_count: The value of @write_count when last checked.
187*4882a593Smuzhiyun  *	This is here for performance reasons.  The xmit path will
188*4882a593Smuzhiyun  *	only get the up-to-date value of @write_count if this
189*4882a593Smuzhiyun  *	variable indicates that the queue is empty.  This is to
190*4882a593Smuzhiyun  *	avoid cache-line ping-pong between the xmit path and the
191*4882a593Smuzhiyun  *	completion path.
192*4882a593Smuzhiyun  * @merge_events: Number of TX merged completion events
193*4882a593Smuzhiyun  * @insert_count: Current insert pointer
194*4882a593Smuzhiyun  *	This is the number of buffers that have been added to the
195*4882a593Smuzhiyun  *	software ring.
196*4882a593Smuzhiyun  * @write_count: Current write pointer
197*4882a593Smuzhiyun  *	This is the number of buffers that have been added to the
198*4882a593Smuzhiyun  *	hardware ring.
199*4882a593Smuzhiyun  * @old_read_count: The value of read_count when last checked.
200*4882a593Smuzhiyun  *	This is here for performance reasons.  The xmit path will
201*4882a593Smuzhiyun  *	only get the up-to-date value of read_count if this
202*4882a593Smuzhiyun  *	variable indicates that the queue is full.  This is to
203*4882a593Smuzhiyun  *	avoid cache-line ping-pong between the xmit path and the
204*4882a593Smuzhiyun  *	completion path.
205*4882a593Smuzhiyun  * @pushes: Number of times the TX push feature has been used
206*4882a593Smuzhiyun  * @xmit_more_available: Are any packets waiting to be pushed to the NIC
207*4882a593Smuzhiyun  * @cb_packets: Number of times the TX copybreak feature has been used
208*4882a593Smuzhiyun  * @empty_read_count: If the completion path has seen the queue as empty
209*4882a593Smuzhiyun  *	and the transmission path has not yet checked this, the value of
210*4882a593Smuzhiyun  *	@read_count bitwise-added to %EF4_EMPTY_COUNT_VALID; otherwise 0.
211*4882a593Smuzhiyun  */
212*4882a593Smuzhiyun struct ef4_tx_queue {
213*4882a593Smuzhiyun 	/* Members which don't change on the fast path */
214*4882a593Smuzhiyun 	struct ef4_nic *efx ____cacheline_aligned_in_smp;
215*4882a593Smuzhiyun 	unsigned queue;
216*4882a593Smuzhiyun 	struct ef4_channel *channel;
217*4882a593Smuzhiyun 	struct netdev_queue *core_txq;
218*4882a593Smuzhiyun 	struct ef4_tx_buffer *buffer;
219*4882a593Smuzhiyun 	struct ef4_buffer *cb_page;
220*4882a593Smuzhiyun 	struct ef4_special_buffer txd;
221*4882a593Smuzhiyun 	unsigned int ptr_mask;
222*4882a593Smuzhiyun 	bool initialised;
223*4882a593Smuzhiyun 	unsigned int tx_min_size;
224*4882a593Smuzhiyun 
225*4882a593Smuzhiyun 	/* Function pointers used in the fast path. */
226*4882a593Smuzhiyun 	int (*handle_tso)(struct ef4_tx_queue*, struct sk_buff*, bool *);
227*4882a593Smuzhiyun 
228*4882a593Smuzhiyun 	/* Members used mainly on the completion path */
229*4882a593Smuzhiyun 	unsigned int read_count ____cacheline_aligned_in_smp;
230*4882a593Smuzhiyun 	unsigned int old_write_count;
231*4882a593Smuzhiyun 	unsigned int merge_events;
232*4882a593Smuzhiyun 	unsigned int bytes_compl;
233*4882a593Smuzhiyun 	unsigned int pkts_compl;
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun 	/* Members used only on the xmit path */
236*4882a593Smuzhiyun 	unsigned int insert_count ____cacheline_aligned_in_smp;
237*4882a593Smuzhiyun 	unsigned int write_count;
238*4882a593Smuzhiyun 	unsigned int old_read_count;
239*4882a593Smuzhiyun 	unsigned int pushes;
240*4882a593Smuzhiyun 	bool xmit_more_available;
241*4882a593Smuzhiyun 	unsigned int cb_packets;
242*4882a593Smuzhiyun 	/* Statistics to supplement MAC stats */
243*4882a593Smuzhiyun 	unsigned long tx_packets;
244*4882a593Smuzhiyun 
245*4882a593Smuzhiyun 	/* Members shared between paths and sometimes updated */
246*4882a593Smuzhiyun 	unsigned int empty_read_count ____cacheline_aligned_in_smp;
247*4882a593Smuzhiyun #define EF4_EMPTY_COUNT_VALID 0x80000000
248*4882a593Smuzhiyun 	atomic_t flush_outstanding;
249*4882a593Smuzhiyun };
250*4882a593Smuzhiyun 
251*4882a593Smuzhiyun #define EF4_TX_CB_ORDER	7
252*4882a593Smuzhiyun #define EF4_TX_CB_SIZE	(1 << EF4_TX_CB_ORDER) - NET_IP_ALIGN
253*4882a593Smuzhiyun 
254*4882a593Smuzhiyun /**
255*4882a593Smuzhiyun  * struct ef4_rx_buffer - An Efx RX data buffer
256*4882a593Smuzhiyun  * @dma_addr: DMA base address of the buffer
257*4882a593Smuzhiyun  * @page: The associated page buffer.
258*4882a593Smuzhiyun  *	Will be %NULL if the buffer slot is currently free.
259*4882a593Smuzhiyun  * @page_offset: If pending: offset in @page of DMA base address.
260*4882a593Smuzhiyun  *	If completed: offset in @page of Ethernet header.
261*4882a593Smuzhiyun  * @len: If pending: length for DMA descriptor.
262*4882a593Smuzhiyun  *	If completed: received length, excluding hash prefix.
263*4882a593Smuzhiyun  * @flags: Flags for buffer and packet state.  These are only set on the
264*4882a593Smuzhiyun  *	first buffer of a scattered packet.
265*4882a593Smuzhiyun  */
266*4882a593Smuzhiyun struct ef4_rx_buffer {
267*4882a593Smuzhiyun 	dma_addr_t dma_addr;
268*4882a593Smuzhiyun 	struct page *page;
269*4882a593Smuzhiyun 	u16 page_offset;
270*4882a593Smuzhiyun 	u16 len;
271*4882a593Smuzhiyun 	u16 flags;
272*4882a593Smuzhiyun };
273*4882a593Smuzhiyun #define EF4_RX_BUF_LAST_IN_PAGE	0x0001
274*4882a593Smuzhiyun #define EF4_RX_PKT_CSUMMED	0x0002
275*4882a593Smuzhiyun #define EF4_RX_PKT_DISCARD	0x0004
276*4882a593Smuzhiyun #define EF4_RX_PKT_TCP		0x0040
277*4882a593Smuzhiyun #define EF4_RX_PKT_PREFIX_LEN	0x0080	/* length is in prefix only */
278*4882a593Smuzhiyun 
279*4882a593Smuzhiyun /**
280*4882a593Smuzhiyun  * struct ef4_rx_page_state - Page-based rx buffer state
281*4882a593Smuzhiyun  *
282*4882a593Smuzhiyun  * Inserted at the start of every page allocated for receive buffers.
283*4882a593Smuzhiyun  * Used to facilitate sharing dma mappings between recycled rx buffers
284*4882a593Smuzhiyun  * and those passed up to the kernel.
285*4882a593Smuzhiyun  *
286*4882a593Smuzhiyun  * @dma_addr: The dma address of this page.
287*4882a593Smuzhiyun  */
288*4882a593Smuzhiyun struct ef4_rx_page_state {
289*4882a593Smuzhiyun 	dma_addr_t dma_addr;
290*4882a593Smuzhiyun 
291*4882a593Smuzhiyun 	unsigned int __pad[] ____cacheline_aligned;
292*4882a593Smuzhiyun };
293*4882a593Smuzhiyun 
294*4882a593Smuzhiyun /**
295*4882a593Smuzhiyun  * struct ef4_rx_queue - An Efx RX queue
296*4882a593Smuzhiyun  * @efx: The associated Efx NIC
297*4882a593Smuzhiyun  * @core_index:  Index of network core RX queue.  Will be >= 0 iff this
298*4882a593Smuzhiyun  *	is associated with a real RX queue.
299*4882a593Smuzhiyun  * @buffer: The software buffer ring
300*4882a593Smuzhiyun  * @rxd: The hardware descriptor ring
301*4882a593Smuzhiyun  * @ptr_mask: The size of the ring minus 1.
302*4882a593Smuzhiyun  * @refill_enabled: Enable refill whenever fill level is low
303*4882a593Smuzhiyun  * @flush_pending: Set when a RX flush is pending. Has the same lifetime as
304*4882a593Smuzhiyun  *	@rxq_flush_pending.
305*4882a593Smuzhiyun  * @added_count: Number of buffers added to the receive queue.
306*4882a593Smuzhiyun  * @notified_count: Number of buffers given to NIC (<= @added_count).
307*4882a593Smuzhiyun  * @removed_count: Number of buffers removed from the receive queue.
308*4882a593Smuzhiyun  * @scatter_n: Used by NIC specific receive code.
309*4882a593Smuzhiyun  * @scatter_len: Used by NIC specific receive code.
310*4882a593Smuzhiyun  * @page_ring: The ring to store DMA mapped pages for reuse.
311*4882a593Smuzhiyun  * @page_add: Counter to calculate the write pointer for the recycle ring.
312*4882a593Smuzhiyun  * @page_remove: Counter to calculate the read pointer for the recycle ring.
313*4882a593Smuzhiyun  * @page_recycle_count: The number of pages that have been recycled.
314*4882a593Smuzhiyun  * @page_recycle_failed: The number of pages that couldn't be recycled because
315*4882a593Smuzhiyun  *      the kernel still held a reference to them.
316*4882a593Smuzhiyun  * @page_recycle_full: The number of pages that were released because the
317*4882a593Smuzhiyun  *      recycle ring was full.
318*4882a593Smuzhiyun  * @page_ptr_mask: The number of pages in the RX recycle ring minus 1.
319*4882a593Smuzhiyun  * @max_fill: RX descriptor maximum fill level (<= ring size)
320*4882a593Smuzhiyun  * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
321*4882a593Smuzhiyun  *	(<= @max_fill)
322*4882a593Smuzhiyun  * @min_fill: RX descriptor minimum non-zero fill level.
323*4882a593Smuzhiyun  *	This records the minimum fill level observed when a ring
324*4882a593Smuzhiyun  *	refill was triggered.
325*4882a593Smuzhiyun  * @recycle_count: RX buffer recycle counter.
326*4882a593Smuzhiyun  * @slow_fill: Timer used to defer ef4_nic_generate_fill_event().
327*4882a593Smuzhiyun  */
328*4882a593Smuzhiyun struct ef4_rx_queue {
329*4882a593Smuzhiyun 	struct ef4_nic *efx;
330*4882a593Smuzhiyun 	int core_index;
331*4882a593Smuzhiyun 	struct ef4_rx_buffer *buffer;
332*4882a593Smuzhiyun 	struct ef4_special_buffer rxd;
333*4882a593Smuzhiyun 	unsigned int ptr_mask;
334*4882a593Smuzhiyun 	bool refill_enabled;
335*4882a593Smuzhiyun 	bool flush_pending;
336*4882a593Smuzhiyun 
337*4882a593Smuzhiyun 	unsigned int added_count;
338*4882a593Smuzhiyun 	unsigned int notified_count;
339*4882a593Smuzhiyun 	unsigned int removed_count;
340*4882a593Smuzhiyun 	unsigned int scatter_n;
341*4882a593Smuzhiyun 	unsigned int scatter_len;
342*4882a593Smuzhiyun 	struct page **page_ring;
343*4882a593Smuzhiyun 	unsigned int page_add;
344*4882a593Smuzhiyun 	unsigned int page_remove;
345*4882a593Smuzhiyun 	unsigned int page_recycle_count;
346*4882a593Smuzhiyun 	unsigned int page_recycle_failed;
347*4882a593Smuzhiyun 	unsigned int page_recycle_full;
348*4882a593Smuzhiyun 	unsigned int page_ptr_mask;
349*4882a593Smuzhiyun 	unsigned int max_fill;
350*4882a593Smuzhiyun 	unsigned int fast_fill_trigger;
351*4882a593Smuzhiyun 	unsigned int min_fill;
352*4882a593Smuzhiyun 	unsigned int min_overfill;
353*4882a593Smuzhiyun 	unsigned int recycle_count;
354*4882a593Smuzhiyun 	struct timer_list slow_fill;
355*4882a593Smuzhiyun 	unsigned int slow_fill_count;
356*4882a593Smuzhiyun 	/* Statistics to supplement MAC stats */
357*4882a593Smuzhiyun 	unsigned long rx_packets;
358*4882a593Smuzhiyun };
359*4882a593Smuzhiyun 
360*4882a593Smuzhiyun /**
361*4882a593Smuzhiyun  * struct ef4_channel - An Efx channel
362*4882a593Smuzhiyun  *
363*4882a593Smuzhiyun  * A channel comprises an event queue, at least one TX queue, at least
364*4882a593Smuzhiyun  * one RX queue, and an associated tasklet for processing the event
365*4882a593Smuzhiyun  * queue.
366*4882a593Smuzhiyun  *
367*4882a593Smuzhiyun  * @efx: Associated Efx NIC
368*4882a593Smuzhiyun  * @channel: Channel instance number
369*4882a593Smuzhiyun  * @type: Channel type definition
370*4882a593Smuzhiyun  * @eventq_init: Event queue initialised flag
371*4882a593Smuzhiyun  * @enabled: Channel enabled indicator
372*4882a593Smuzhiyun  * @irq: IRQ number (MSI and MSI-X only)
373*4882a593Smuzhiyun  * @irq_moderation_us: IRQ moderation value (in microseconds)
374*4882a593Smuzhiyun  * @napi_dev: Net device used with NAPI
375*4882a593Smuzhiyun  * @napi_str: NAPI control structure
376*4882a593Smuzhiyun  * @state: state for NAPI vs busy polling
377*4882a593Smuzhiyun  * @state_lock: lock protecting @state
378*4882a593Smuzhiyun  * @eventq: Event queue buffer
379*4882a593Smuzhiyun  * @eventq_mask: Event queue pointer mask
380*4882a593Smuzhiyun  * @eventq_read_ptr: Event queue read pointer
381*4882a593Smuzhiyun  * @event_test_cpu: Last CPU to handle interrupt or test event for this channel
382*4882a593Smuzhiyun  * @irq_count: Number of IRQs since last adaptive moderation decision
383*4882a593Smuzhiyun  * @irq_mod_score: IRQ moderation score
384*4882a593Smuzhiyun  * @rps_flow_id: Flow IDs of filters allocated for accelerated RFS,
385*4882a593Smuzhiyun  *      indexed by filter ID
386*4882a593Smuzhiyun  * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
387*4882a593Smuzhiyun  * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
388*4882a593Smuzhiyun  * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
389*4882a593Smuzhiyun  * @n_rx_mcast_mismatch: Count of unmatched multicast frames
390*4882a593Smuzhiyun  * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
391*4882a593Smuzhiyun  * @n_rx_overlength: Count of RX_OVERLENGTH errors
392*4882a593Smuzhiyun  * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
393*4882a593Smuzhiyun  * @n_rx_nodesc_trunc: Number of RX packets truncated and then dropped due to
394*4882a593Smuzhiyun  *	lack of descriptors
395*4882a593Smuzhiyun  * @n_rx_merge_events: Number of RX merged completion events
396*4882a593Smuzhiyun  * @n_rx_merge_packets: Number of RX packets completed by merged events
397*4882a593Smuzhiyun  * @rx_pkt_n_frags: Number of fragments in next packet to be delivered by
398*4882a593Smuzhiyun  *	__ef4_rx_packet(), or zero if there is none
399*4882a593Smuzhiyun  * @rx_pkt_index: Ring index of first buffer for next packet to be delivered
400*4882a593Smuzhiyun  *	by __ef4_rx_packet(), if @rx_pkt_n_frags != 0
401*4882a593Smuzhiyun  * @rx_queue: RX queue for this channel
402*4882a593Smuzhiyun  * @tx_queue: TX queues for this channel
403*4882a593Smuzhiyun  */
404*4882a593Smuzhiyun struct ef4_channel {
405*4882a593Smuzhiyun 	struct ef4_nic *efx;
406*4882a593Smuzhiyun 	int channel;
407*4882a593Smuzhiyun 	const struct ef4_channel_type *type;
408*4882a593Smuzhiyun 	bool eventq_init;
409*4882a593Smuzhiyun 	bool enabled;
410*4882a593Smuzhiyun 	int irq;
411*4882a593Smuzhiyun 	unsigned int irq_moderation_us;
412*4882a593Smuzhiyun 	struct net_device *napi_dev;
413*4882a593Smuzhiyun 	struct napi_struct napi_str;
414*4882a593Smuzhiyun #ifdef CONFIG_NET_RX_BUSY_POLL
415*4882a593Smuzhiyun 	unsigned long busy_poll_state;
416*4882a593Smuzhiyun #endif
417*4882a593Smuzhiyun 	struct ef4_special_buffer eventq;
418*4882a593Smuzhiyun 	unsigned int eventq_mask;
419*4882a593Smuzhiyun 	unsigned int eventq_read_ptr;
420*4882a593Smuzhiyun 	int event_test_cpu;
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun 	unsigned int irq_count;
423*4882a593Smuzhiyun 	unsigned int irq_mod_score;
424*4882a593Smuzhiyun #ifdef CONFIG_RFS_ACCEL
425*4882a593Smuzhiyun 	unsigned int rfs_filters_added;
426*4882a593Smuzhiyun #define RPS_FLOW_ID_INVALID 0xFFFFFFFF
427*4882a593Smuzhiyun 	u32 *rps_flow_id;
428*4882a593Smuzhiyun #endif
429*4882a593Smuzhiyun 
430*4882a593Smuzhiyun 	unsigned n_rx_tobe_disc;
431*4882a593Smuzhiyun 	unsigned n_rx_ip_hdr_chksum_err;
432*4882a593Smuzhiyun 	unsigned n_rx_tcp_udp_chksum_err;
433*4882a593Smuzhiyun 	unsigned n_rx_mcast_mismatch;
434*4882a593Smuzhiyun 	unsigned n_rx_frm_trunc;
435*4882a593Smuzhiyun 	unsigned n_rx_overlength;
436*4882a593Smuzhiyun 	unsigned n_skbuff_leaks;
437*4882a593Smuzhiyun 	unsigned int n_rx_nodesc_trunc;
438*4882a593Smuzhiyun 	unsigned int n_rx_merge_events;
439*4882a593Smuzhiyun 	unsigned int n_rx_merge_packets;
440*4882a593Smuzhiyun 
441*4882a593Smuzhiyun 	unsigned int rx_pkt_n_frags;
442*4882a593Smuzhiyun 	unsigned int rx_pkt_index;
443*4882a593Smuzhiyun 
444*4882a593Smuzhiyun 	struct ef4_rx_queue rx_queue;
445*4882a593Smuzhiyun 	struct ef4_tx_queue tx_queue[EF4_TXQ_TYPES];
446*4882a593Smuzhiyun };
447*4882a593Smuzhiyun 
448*4882a593Smuzhiyun /**
449*4882a593Smuzhiyun  * struct ef4_msi_context - Context for each MSI
450*4882a593Smuzhiyun  * @efx: The associated NIC
451*4882a593Smuzhiyun  * @index: Index of the channel/IRQ
452*4882a593Smuzhiyun  * @name: Name of the channel/IRQ
453*4882a593Smuzhiyun  *
454*4882a593Smuzhiyun  * Unlike &struct ef4_channel, this is never reallocated and is always
455*4882a593Smuzhiyun  * safe for the IRQ handler to access.
456*4882a593Smuzhiyun  */
457*4882a593Smuzhiyun struct ef4_msi_context {
458*4882a593Smuzhiyun 	struct ef4_nic *efx;
459*4882a593Smuzhiyun 	unsigned int index;
460*4882a593Smuzhiyun 	char name[IFNAMSIZ + 6];
461*4882a593Smuzhiyun };
462*4882a593Smuzhiyun 
463*4882a593Smuzhiyun /**
464*4882a593Smuzhiyun  * struct ef4_channel_type - distinguishes traffic and extra channels
465*4882a593Smuzhiyun  * @handle_no_channel: Handle failure to allocate an extra channel
466*4882a593Smuzhiyun  * @pre_probe: Set up extra state prior to initialisation
467*4882a593Smuzhiyun  * @post_remove: Tear down extra state after finalisation, if allocated.
468*4882a593Smuzhiyun  *	May be called on channels that have not been probed.
469*4882a593Smuzhiyun  * @get_name: Generate the channel's name (used for its IRQ handler)
470*4882a593Smuzhiyun  * @copy: Copy the channel state prior to reallocation.  May be %NULL if
471*4882a593Smuzhiyun  *	reallocation is not supported.
472*4882a593Smuzhiyun  * @receive_skb: Handle an skb ready to be passed to netif_receive_skb()
473*4882a593Smuzhiyun  * @keep_eventq: Flag for whether event queue should be kept initialised
474*4882a593Smuzhiyun  *	while the device is stopped
475*4882a593Smuzhiyun  */
476*4882a593Smuzhiyun struct ef4_channel_type {
477*4882a593Smuzhiyun 	void (*handle_no_channel)(struct ef4_nic *);
478*4882a593Smuzhiyun 	int (*pre_probe)(struct ef4_channel *);
479*4882a593Smuzhiyun 	void (*post_remove)(struct ef4_channel *);
480*4882a593Smuzhiyun 	void (*get_name)(struct ef4_channel *, char *buf, size_t len);
481*4882a593Smuzhiyun 	struct ef4_channel *(*copy)(const struct ef4_channel *);
482*4882a593Smuzhiyun 	bool (*receive_skb)(struct ef4_channel *, struct sk_buff *);
483*4882a593Smuzhiyun 	bool keep_eventq;
484*4882a593Smuzhiyun };
485*4882a593Smuzhiyun 
486*4882a593Smuzhiyun enum ef4_led_mode {
487*4882a593Smuzhiyun 	EF4_LED_OFF	= 0,
488*4882a593Smuzhiyun 	EF4_LED_ON	= 1,
489*4882a593Smuzhiyun 	EF4_LED_DEFAULT	= 2
490*4882a593Smuzhiyun };
491*4882a593Smuzhiyun 
492*4882a593Smuzhiyun #define STRING_TABLE_LOOKUP(val, member) \
493*4882a593Smuzhiyun 	((val) < member ## _max) ? member ## _names[val] : "(invalid)"
494*4882a593Smuzhiyun 
495*4882a593Smuzhiyun extern const char *const ef4_loopback_mode_names[];
496*4882a593Smuzhiyun extern const unsigned int ef4_loopback_mode_max;
497*4882a593Smuzhiyun #define LOOPBACK_MODE(efx) \
498*4882a593Smuzhiyun 	STRING_TABLE_LOOKUP((efx)->loopback_mode, ef4_loopback_mode)
499*4882a593Smuzhiyun 
500*4882a593Smuzhiyun extern const char *const ef4_reset_type_names[];
501*4882a593Smuzhiyun extern const unsigned int ef4_reset_type_max;
502*4882a593Smuzhiyun #define RESET_TYPE(type) \
503*4882a593Smuzhiyun 	STRING_TABLE_LOOKUP(type, ef4_reset_type)
504*4882a593Smuzhiyun 
505*4882a593Smuzhiyun enum ef4_int_mode {
506*4882a593Smuzhiyun 	/* Be careful if altering to correct macro below */
507*4882a593Smuzhiyun 	EF4_INT_MODE_MSIX = 0,
508*4882a593Smuzhiyun 	EF4_INT_MODE_MSI = 1,
509*4882a593Smuzhiyun 	EF4_INT_MODE_LEGACY = 2,
510*4882a593Smuzhiyun 	EF4_INT_MODE_MAX	/* Insert any new items before this */
511*4882a593Smuzhiyun };
512*4882a593Smuzhiyun #define EF4_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EF4_INT_MODE_MSI)
513*4882a593Smuzhiyun 
514*4882a593Smuzhiyun enum nic_state {
515*4882a593Smuzhiyun 	STATE_UNINIT = 0,	/* device being probed/removed or is frozen */
516*4882a593Smuzhiyun 	STATE_READY = 1,	/* hardware ready and netdev registered */
517*4882a593Smuzhiyun 	STATE_DISABLED = 2,	/* device disabled due to hardware errors */
518*4882a593Smuzhiyun 	STATE_RECOVERY = 3,	/* device recovering from PCI error */
519*4882a593Smuzhiyun };
520*4882a593Smuzhiyun 
521*4882a593Smuzhiyun /* Forward declaration */
522*4882a593Smuzhiyun struct ef4_nic;
523*4882a593Smuzhiyun 
524*4882a593Smuzhiyun /* Pseudo bit-mask flow control field */
525*4882a593Smuzhiyun #define EF4_FC_RX	FLOW_CTRL_RX
526*4882a593Smuzhiyun #define EF4_FC_TX	FLOW_CTRL_TX
527*4882a593Smuzhiyun #define EF4_FC_AUTO	4
528*4882a593Smuzhiyun 
529*4882a593Smuzhiyun /**
530*4882a593Smuzhiyun  * struct ef4_link_state - Current state of the link
531*4882a593Smuzhiyun  * @up: Link is up
532*4882a593Smuzhiyun  * @fd: Link is full-duplex
533*4882a593Smuzhiyun  * @fc: Actual flow control flags
534*4882a593Smuzhiyun  * @speed: Link speed (Mbps)
535*4882a593Smuzhiyun  */
536*4882a593Smuzhiyun struct ef4_link_state {
537*4882a593Smuzhiyun 	bool up;
538*4882a593Smuzhiyun 	bool fd;
539*4882a593Smuzhiyun 	u8 fc;
540*4882a593Smuzhiyun 	unsigned int speed;
541*4882a593Smuzhiyun };
542*4882a593Smuzhiyun 
ef4_link_state_equal(const struct ef4_link_state * left,const struct ef4_link_state * right)543*4882a593Smuzhiyun static inline bool ef4_link_state_equal(const struct ef4_link_state *left,
544*4882a593Smuzhiyun 					const struct ef4_link_state *right)
545*4882a593Smuzhiyun {
546*4882a593Smuzhiyun 	return left->up == right->up && left->fd == right->fd &&
547*4882a593Smuzhiyun 		left->fc == right->fc && left->speed == right->speed;
548*4882a593Smuzhiyun }
549*4882a593Smuzhiyun 
550*4882a593Smuzhiyun /**
551*4882a593Smuzhiyun  * struct ef4_phy_operations - Efx PHY operations table
552*4882a593Smuzhiyun  * @probe: Probe PHY and initialise efx->mdio.mode_support, efx->mdio.mmds,
553*4882a593Smuzhiyun  *	efx->loopback_modes.
554*4882a593Smuzhiyun  * @init: Initialise PHY
555*4882a593Smuzhiyun  * @fini: Shut down PHY
556*4882a593Smuzhiyun  * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
557*4882a593Smuzhiyun  * @poll: Update @link_state and report whether it changed.
558*4882a593Smuzhiyun  *	Serialised by the mac_lock.
559*4882a593Smuzhiyun  * @get_link_ksettings: Get ethtool settings. Serialised by the mac_lock.
560*4882a593Smuzhiyun  * @set_link_ksettings: Set ethtool settings. Serialised by the mac_lock.
561*4882a593Smuzhiyun  * @set_npage_adv: Set abilities advertised in (Extended) Next Page
562*4882a593Smuzhiyun  *	(only needed where AN bit is set in mmds)
563*4882a593Smuzhiyun  * @test_alive: Test that PHY is 'alive' (online)
564*4882a593Smuzhiyun  * @test_name: Get the name of a PHY-specific test/result
565*4882a593Smuzhiyun  * @run_tests: Run tests and record results as appropriate (offline).
566*4882a593Smuzhiyun  *	Flags are the ethtool tests flags.
567*4882a593Smuzhiyun  */
568*4882a593Smuzhiyun struct ef4_phy_operations {
569*4882a593Smuzhiyun 	int (*probe) (struct ef4_nic *efx);
570*4882a593Smuzhiyun 	int (*init) (struct ef4_nic *efx);
571*4882a593Smuzhiyun 	void (*fini) (struct ef4_nic *efx);
572*4882a593Smuzhiyun 	void (*remove) (struct ef4_nic *efx);
573*4882a593Smuzhiyun 	int (*reconfigure) (struct ef4_nic *efx);
574*4882a593Smuzhiyun 	bool (*poll) (struct ef4_nic *efx);
575*4882a593Smuzhiyun 	void (*get_link_ksettings)(struct ef4_nic *efx,
576*4882a593Smuzhiyun 				   struct ethtool_link_ksettings *cmd);
577*4882a593Smuzhiyun 	int (*set_link_ksettings)(struct ef4_nic *efx,
578*4882a593Smuzhiyun 				  const struct ethtool_link_ksettings *cmd);
579*4882a593Smuzhiyun 	void (*set_npage_adv) (struct ef4_nic *efx, u32);
580*4882a593Smuzhiyun 	int (*test_alive) (struct ef4_nic *efx);
581*4882a593Smuzhiyun 	const char *(*test_name) (struct ef4_nic *efx, unsigned int index);
582*4882a593Smuzhiyun 	int (*run_tests) (struct ef4_nic *efx, int *results, unsigned flags);
583*4882a593Smuzhiyun 	int (*get_module_eeprom) (struct ef4_nic *efx,
584*4882a593Smuzhiyun 			       struct ethtool_eeprom *ee,
585*4882a593Smuzhiyun 			       u8 *data);
586*4882a593Smuzhiyun 	int (*get_module_info) (struct ef4_nic *efx,
587*4882a593Smuzhiyun 				struct ethtool_modinfo *modinfo);
588*4882a593Smuzhiyun };
589*4882a593Smuzhiyun 
590*4882a593Smuzhiyun /**
591*4882a593Smuzhiyun  * enum ef4_phy_mode - PHY operating mode flags
592*4882a593Smuzhiyun  * @PHY_MODE_NORMAL: on and should pass traffic
593*4882a593Smuzhiyun  * @PHY_MODE_TX_DISABLED: on with TX disabled
594*4882a593Smuzhiyun  * @PHY_MODE_LOW_POWER: set to low power through MDIO
595*4882a593Smuzhiyun  * @PHY_MODE_OFF: switched off through external control
596*4882a593Smuzhiyun  * @PHY_MODE_SPECIAL: on but will not pass traffic
597*4882a593Smuzhiyun  */
598*4882a593Smuzhiyun enum ef4_phy_mode {
599*4882a593Smuzhiyun 	PHY_MODE_NORMAL		= 0,
600*4882a593Smuzhiyun 	PHY_MODE_TX_DISABLED	= 1,
601*4882a593Smuzhiyun 	PHY_MODE_LOW_POWER	= 2,
602*4882a593Smuzhiyun 	PHY_MODE_OFF		= 4,
603*4882a593Smuzhiyun 	PHY_MODE_SPECIAL	= 8,
604*4882a593Smuzhiyun };
605*4882a593Smuzhiyun 
ef4_phy_mode_disabled(enum ef4_phy_mode mode)606*4882a593Smuzhiyun static inline bool ef4_phy_mode_disabled(enum ef4_phy_mode mode)
607*4882a593Smuzhiyun {
608*4882a593Smuzhiyun 	return !!(mode & ~PHY_MODE_TX_DISABLED);
609*4882a593Smuzhiyun }
610*4882a593Smuzhiyun 
611*4882a593Smuzhiyun /**
612*4882a593Smuzhiyun  * struct ef4_hw_stat_desc - Description of a hardware statistic
613*4882a593Smuzhiyun  * @name: Name of the statistic as visible through ethtool, or %NULL if
614*4882a593Smuzhiyun  *	it should not be exposed
615*4882a593Smuzhiyun  * @dma_width: Width in bits (0 for non-DMA statistics)
616*4882a593Smuzhiyun  * @offset: Offset within stats (ignored for non-DMA statistics)
617*4882a593Smuzhiyun  */
618*4882a593Smuzhiyun struct ef4_hw_stat_desc {
619*4882a593Smuzhiyun 	const char *name;
620*4882a593Smuzhiyun 	u16 dma_width;
621*4882a593Smuzhiyun 	u16 offset;
622*4882a593Smuzhiyun };
623*4882a593Smuzhiyun 
624*4882a593Smuzhiyun /* Number of bits used in a multicast filter hash address */
625*4882a593Smuzhiyun #define EF4_MCAST_HASH_BITS 8
626*4882a593Smuzhiyun 
627*4882a593Smuzhiyun /* Number of (single-bit) entries in a multicast filter hash */
628*4882a593Smuzhiyun #define EF4_MCAST_HASH_ENTRIES (1 << EF4_MCAST_HASH_BITS)
629*4882a593Smuzhiyun 
630*4882a593Smuzhiyun /* An Efx multicast filter hash */
631*4882a593Smuzhiyun union ef4_multicast_hash {
632*4882a593Smuzhiyun 	u8 byte[EF4_MCAST_HASH_ENTRIES / 8];
633*4882a593Smuzhiyun 	ef4_oword_t oword[EF4_MCAST_HASH_ENTRIES / sizeof(ef4_oword_t) / 8];
634*4882a593Smuzhiyun };
635*4882a593Smuzhiyun 
636*4882a593Smuzhiyun /**
637*4882a593Smuzhiyun  * struct ef4_nic - an Efx NIC
638*4882a593Smuzhiyun  * @name: Device name (net device name or bus id before net device registered)
639*4882a593Smuzhiyun  * @pci_dev: The PCI device
640*4882a593Smuzhiyun  * @node: List node for maintaning primary/secondary function lists
641*4882a593Smuzhiyun  * @primary: &struct ef4_nic instance for the primary function of this
642*4882a593Smuzhiyun  *	controller.  May be the same structure, and may be %NULL if no
643*4882a593Smuzhiyun  *	primary function is bound.  Serialised by rtnl_lock.
644*4882a593Smuzhiyun  * @secondary_list: List of &struct ef4_nic instances for the secondary PCI
645*4882a593Smuzhiyun  *	functions of the controller, if this is for the primary function.
646*4882a593Smuzhiyun  *	Serialised by rtnl_lock.
647*4882a593Smuzhiyun  * @type: Controller type attributes
648*4882a593Smuzhiyun  * @legacy_irq: IRQ number
649*4882a593Smuzhiyun  * @workqueue: Workqueue for port reconfigures and the HW monitor.
650*4882a593Smuzhiyun  *	Work items do not hold and must not acquire RTNL.
651*4882a593Smuzhiyun  * @workqueue_name: Name of workqueue
652*4882a593Smuzhiyun  * @reset_work: Scheduled reset workitem
653*4882a593Smuzhiyun  * @membase_phys: Memory BAR value as physical address
654*4882a593Smuzhiyun  * @membase: Memory BAR value
655*4882a593Smuzhiyun  * @interrupt_mode: Interrupt mode
656*4882a593Smuzhiyun  * @timer_quantum_ns: Interrupt timer quantum, in nanoseconds
657*4882a593Smuzhiyun  * @timer_max_ns: Interrupt timer maximum value, in nanoseconds
658*4882a593Smuzhiyun  * @irq_rx_adaptive: Adaptive IRQ moderation enabled for RX event queues
659*4882a593Smuzhiyun  * @irq_rx_mod_step_us: Step size for IRQ moderation for RX event queues
660*4882a593Smuzhiyun  * @irq_rx_moderation_us: IRQ moderation time for RX event queues
661*4882a593Smuzhiyun  * @msg_enable: Log message enable flags
662*4882a593Smuzhiyun  * @state: Device state number (%STATE_*). Serialised by the rtnl_lock.
663*4882a593Smuzhiyun  * @reset_pending: Bitmask for pending resets
664*4882a593Smuzhiyun  * @tx_queue: TX DMA queues
665*4882a593Smuzhiyun  * @rx_queue: RX DMA queues
666*4882a593Smuzhiyun  * @channel: Channels
667*4882a593Smuzhiyun  * @msi_context: Context for each MSI
668*4882a593Smuzhiyun  * @extra_channel_types: Types of extra (non-traffic) channels that
669*4882a593Smuzhiyun  *	should be allocated for this NIC
670*4882a593Smuzhiyun  * @rxq_entries: Size of receive queues requested by user.
671*4882a593Smuzhiyun  * @txq_entries: Size of transmit queues requested by user.
672*4882a593Smuzhiyun  * @txq_stop_thresh: TX queue fill level at or above which we stop it.
673*4882a593Smuzhiyun  * @txq_wake_thresh: TX queue fill level at or below which we wake it.
674*4882a593Smuzhiyun  * @tx_dc_base: Base qword address in SRAM of TX queue descriptor caches
675*4882a593Smuzhiyun  * @rx_dc_base: Base qword address in SRAM of RX queue descriptor caches
676*4882a593Smuzhiyun  * @sram_lim_qw: Qword address limit of SRAM
677*4882a593Smuzhiyun  * @next_buffer_table: First available buffer table id
678*4882a593Smuzhiyun  * @n_channels: Number of channels in use
679*4882a593Smuzhiyun  * @n_rx_channels: Number of channels used for RX (= number of RX queues)
680*4882a593Smuzhiyun  * @n_tx_channels: Number of channels used for TX
681*4882a593Smuzhiyun  * @rx_ip_align: RX DMA address offset to have IP header aligned in
682*4882a593Smuzhiyun  *	in accordance with NET_IP_ALIGN
683*4882a593Smuzhiyun  * @rx_dma_len: Current maximum RX DMA length
684*4882a593Smuzhiyun  * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
685*4882a593Smuzhiyun  * @rx_buffer_truesize: Amortised allocation size of an RX buffer,
686*4882a593Smuzhiyun  *	for use in sk_buff::truesize
687*4882a593Smuzhiyun  * @rx_prefix_size: Size of RX prefix before packet data
688*4882a593Smuzhiyun  * @rx_packet_hash_offset: Offset of RX flow hash from start of packet data
689*4882a593Smuzhiyun  *	(valid only if @rx_prefix_size != 0; always negative)
690*4882a593Smuzhiyun  * @rx_packet_len_offset: Offset of RX packet length from start of packet data
691*4882a593Smuzhiyun  *	(valid only for NICs that set %EF4_RX_PKT_PREFIX_LEN; always negative)
692*4882a593Smuzhiyun  * @rx_packet_ts_offset: Offset of timestamp from start of packet data
693*4882a593Smuzhiyun  *	(valid only if channel->sync_timestamps_enabled; always negative)
694*4882a593Smuzhiyun  * @rx_hash_key: Toeplitz hash key for RSS
695*4882a593Smuzhiyun  * @rx_indir_table: Indirection table for RSS
696*4882a593Smuzhiyun  * @rx_scatter: Scatter mode enabled for receives
697*4882a593Smuzhiyun  * @int_error_count: Number of internal errors seen recently
698*4882a593Smuzhiyun  * @int_error_expire: Time at which error count will be expired
699*4882a593Smuzhiyun  * @irq_soft_enabled: Are IRQs soft-enabled? If not, IRQ handler will
700*4882a593Smuzhiyun  *	acknowledge but do nothing else.
701*4882a593Smuzhiyun  * @irq_status: Interrupt status buffer
702*4882a593Smuzhiyun  * @irq_zero_count: Number of legacy IRQs seen with queue flags == 0
703*4882a593Smuzhiyun  * @irq_level: IRQ level/index for IRQs not triggered by an event queue
704*4882a593Smuzhiyun  * @selftest_work: Work item for asynchronous self-test
705*4882a593Smuzhiyun  * @mtd_list: List of MTDs attached to the NIC
706*4882a593Smuzhiyun  * @nic_data: Hardware dependent state
707*4882a593Smuzhiyun  * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode,
708*4882a593Smuzhiyun  *	ef4_monitor() and ef4_reconfigure_port()
709*4882a593Smuzhiyun  * @port_enabled: Port enabled indicator.
710*4882a593Smuzhiyun  *	Serialises ef4_stop_all(), ef4_start_all(), ef4_monitor() and
711*4882a593Smuzhiyun  *	ef4_mac_work() with kernel interfaces. Safe to read under any
712*4882a593Smuzhiyun  *	one of the rtnl_lock, mac_lock, or netif_tx_lock, but all three must
713*4882a593Smuzhiyun  *	be held to modify it.
714*4882a593Smuzhiyun  * @port_initialized: Port initialized?
715*4882a593Smuzhiyun  * @net_dev: Operating system network device. Consider holding the rtnl lock
716*4882a593Smuzhiyun  * @fixed_features: Features which cannot be turned off
717*4882a593Smuzhiyun  * @stats_buffer: DMA buffer for statistics
718*4882a593Smuzhiyun  * @phy_type: PHY type
719*4882a593Smuzhiyun  * @phy_op: PHY interface
720*4882a593Smuzhiyun  * @phy_data: PHY private data (including PHY-specific stats)
721*4882a593Smuzhiyun  * @mdio: PHY MDIO interface
722*4882a593Smuzhiyun  * @phy_mode: PHY operating mode. Serialised by @mac_lock.
723*4882a593Smuzhiyun  * @link_advertising: Autonegotiation advertising flags
724*4882a593Smuzhiyun  * @link_state: Current state of the link
725*4882a593Smuzhiyun  * @n_link_state_changes: Number of times the link has changed state
726*4882a593Smuzhiyun  * @unicast_filter: Flag for Falcon-arch simple unicast filter.
727*4882a593Smuzhiyun  *	Protected by @mac_lock.
728*4882a593Smuzhiyun  * @multicast_hash: Multicast hash table for Falcon-arch.
729*4882a593Smuzhiyun  *	Protected by @mac_lock.
730*4882a593Smuzhiyun  * @wanted_fc: Wanted flow control flags
731*4882a593Smuzhiyun  * @fc_disable: When non-zero flow control is disabled. Typically used to
732*4882a593Smuzhiyun  *	ensure that network back pressure doesn't delay dma queue flushes.
733*4882a593Smuzhiyun  *	Serialised by the rtnl lock.
734*4882a593Smuzhiyun  * @mac_work: Work item for changing MAC promiscuity and multicast hash
735*4882a593Smuzhiyun  * @loopback_mode: Loopback status
736*4882a593Smuzhiyun  * @loopback_modes: Supported loopback mode bitmask
737*4882a593Smuzhiyun  * @loopback_selftest: Offline self-test private state
738*4882a593Smuzhiyun  * @filter_sem: Filter table rw_semaphore, for freeing the table
739*4882a593Smuzhiyun  * @filter_lock: Filter table lock, for mere content changes
740*4882a593Smuzhiyun  * @filter_state: Architecture-dependent filter table state
741*4882a593Smuzhiyun  * @rps_expire_channel: Next channel to check for expiry
742*4882a593Smuzhiyun  * @rps_expire_index: Next index to check for expiry in
743*4882a593Smuzhiyun  *	@rps_expire_channel's @rps_flow_id
744*4882a593Smuzhiyun  * @active_queues: Count of RX and TX queues that haven't been flushed and drained.
745*4882a593Smuzhiyun  * @rxq_flush_pending: Count of number of receive queues that need to be flushed.
746*4882a593Smuzhiyun  *	Decremented when the ef4_flush_rx_queue() is called.
747*4882a593Smuzhiyun  * @rxq_flush_outstanding: Count of number of RX flushes started but not yet
748*4882a593Smuzhiyun  *	completed (either success or failure). Not used when MCDI is used to
749*4882a593Smuzhiyun  *	flush receive queues.
750*4882a593Smuzhiyun  * @flush_wq: wait queue used by ef4_nic_flush_queues() to wait for flush completions.
751*4882a593Smuzhiyun  * @vpd_sn: Serial number read from VPD
752*4882a593Smuzhiyun  * @monitor_work: Hardware monitor workitem
753*4882a593Smuzhiyun  * @biu_lock: BIU (bus interface unit) lock
754*4882a593Smuzhiyun  * @last_irq_cpu: Last CPU to handle a possible test interrupt.  This
755*4882a593Smuzhiyun  *	field is used by ef4_test_interrupts() to verify that an
756*4882a593Smuzhiyun  *	interrupt has occurred.
757*4882a593Smuzhiyun  * @stats_lock: Statistics update lock. Must be held when calling
758*4882a593Smuzhiyun  *	ef4_nic_type::{update,start,stop}_stats.
759*4882a593Smuzhiyun  * @n_rx_noskb_drops: Count of RX packets dropped due to failure to allocate an skb
760*4882a593Smuzhiyun  *
761*4882a593Smuzhiyun  * This is stored in the private area of the &struct net_device.
762*4882a593Smuzhiyun  */
763*4882a593Smuzhiyun struct ef4_nic {
764*4882a593Smuzhiyun 	/* The following fields should be written very rarely */
765*4882a593Smuzhiyun 
766*4882a593Smuzhiyun 	char name[IFNAMSIZ];
767*4882a593Smuzhiyun 	struct list_head node;
768*4882a593Smuzhiyun 	struct ef4_nic *primary;
769*4882a593Smuzhiyun 	struct list_head secondary_list;
770*4882a593Smuzhiyun 	struct pci_dev *pci_dev;
771*4882a593Smuzhiyun 	unsigned int port_num;
772*4882a593Smuzhiyun 	const struct ef4_nic_type *type;
773*4882a593Smuzhiyun 	int legacy_irq;
774*4882a593Smuzhiyun 	bool eeh_disabled_legacy_irq;
775*4882a593Smuzhiyun 	struct workqueue_struct *workqueue;
776*4882a593Smuzhiyun 	char workqueue_name[16];
777*4882a593Smuzhiyun 	struct work_struct reset_work;
778*4882a593Smuzhiyun 	resource_size_t membase_phys;
779*4882a593Smuzhiyun 	void __iomem *membase;
780*4882a593Smuzhiyun 
781*4882a593Smuzhiyun 	enum ef4_int_mode interrupt_mode;
782*4882a593Smuzhiyun 	unsigned int timer_quantum_ns;
783*4882a593Smuzhiyun 	unsigned int timer_max_ns;
784*4882a593Smuzhiyun 	bool irq_rx_adaptive;
785*4882a593Smuzhiyun 	unsigned int irq_mod_step_us;
786*4882a593Smuzhiyun 	unsigned int irq_rx_moderation_us;
787*4882a593Smuzhiyun 	u32 msg_enable;
788*4882a593Smuzhiyun 
789*4882a593Smuzhiyun 	enum nic_state state;
790*4882a593Smuzhiyun 	unsigned long reset_pending;
791*4882a593Smuzhiyun 
792*4882a593Smuzhiyun 	struct ef4_channel *channel[EF4_MAX_CHANNELS];
793*4882a593Smuzhiyun 	struct ef4_msi_context msi_context[EF4_MAX_CHANNELS];
794*4882a593Smuzhiyun 	const struct ef4_channel_type *
795*4882a593Smuzhiyun 	extra_channel_type[EF4_MAX_EXTRA_CHANNELS];
796*4882a593Smuzhiyun 
797*4882a593Smuzhiyun 	unsigned rxq_entries;
798*4882a593Smuzhiyun 	unsigned txq_entries;
799*4882a593Smuzhiyun 	unsigned int txq_stop_thresh;
800*4882a593Smuzhiyun 	unsigned int txq_wake_thresh;
801*4882a593Smuzhiyun 
802*4882a593Smuzhiyun 	unsigned tx_dc_base;
803*4882a593Smuzhiyun 	unsigned rx_dc_base;
804*4882a593Smuzhiyun 	unsigned sram_lim_qw;
805*4882a593Smuzhiyun 	unsigned next_buffer_table;
806*4882a593Smuzhiyun 
807*4882a593Smuzhiyun 	unsigned int max_channels;
808*4882a593Smuzhiyun 	unsigned int max_tx_channels;
809*4882a593Smuzhiyun 	unsigned n_channels;
810*4882a593Smuzhiyun 	unsigned n_rx_channels;
811*4882a593Smuzhiyun 	unsigned rss_spread;
812*4882a593Smuzhiyun 	unsigned tx_channel_offset;
813*4882a593Smuzhiyun 	unsigned n_tx_channels;
814*4882a593Smuzhiyun 	unsigned int rx_ip_align;
815*4882a593Smuzhiyun 	unsigned int rx_dma_len;
816*4882a593Smuzhiyun 	unsigned int rx_buffer_order;
817*4882a593Smuzhiyun 	unsigned int rx_buffer_truesize;
818*4882a593Smuzhiyun 	unsigned int rx_page_buf_step;
819*4882a593Smuzhiyun 	unsigned int rx_bufs_per_page;
820*4882a593Smuzhiyun 	unsigned int rx_pages_per_batch;
821*4882a593Smuzhiyun 	unsigned int rx_prefix_size;
822*4882a593Smuzhiyun 	int rx_packet_hash_offset;
823*4882a593Smuzhiyun 	int rx_packet_len_offset;
824*4882a593Smuzhiyun 	int rx_packet_ts_offset;
825*4882a593Smuzhiyun 	u8 rx_hash_key[40];
826*4882a593Smuzhiyun 	u32 rx_indir_table[128];
827*4882a593Smuzhiyun 	bool rx_scatter;
828*4882a593Smuzhiyun 
829*4882a593Smuzhiyun 	unsigned int_error_count;
830*4882a593Smuzhiyun 	unsigned long int_error_expire;
831*4882a593Smuzhiyun 
832*4882a593Smuzhiyun 	bool irq_soft_enabled;
833*4882a593Smuzhiyun 	struct ef4_buffer irq_status;
834*4882a593Smuzhiyun 	unsigned irq_zero_count;
835*4882a593Smuzhiyun 	unsigned irq_level;
836*4882a593Smuzhiyun 	struct delayed_work selftest_work;
837*4882a593Smuzhiyun 
838*4882a593Smuzhiyun #ifdef CONFIG_SFC_FALCON_MTD
839*4882a593Smuzhiyun 	struct list_head mtd_list;
840*4882a593Smuzhiyun #endif
841*4882a593Smuzhiyun 
842*4882a593Smuzhiyun 	void *nic_data;
843*4882a593Smuzhiyun 
844*4882a593Smuzhiyun 	struct mutex mac_lock;
845*4882a593Smuzhiyun 	struct work_struct mac_work;
846*4882a593Smuzhiyun 	bool port_enabled;
847*4882a593Smuzhiyun 
848*4882a593Smuzhiyun 	bool mc_bist_for_other_fn;
849*4882a593Smuzhiyun 	bool port_initialized;
850*4882a593Smuzhiyun 	struct net_device *net_dev;
851*4882a593Smuzhiyun 
852*4882a593Smuzhiyun 	netdev_features_t fixed_features;
853*4882a593Smuzhiyun 
854*4882a593Smuzhiyun 	struct ef4_buffer stats_buffer;
855*4882a593Smuzhiyun 	u64 rx_nodesc_drops_total;
856*4882a593Smuzhiyun 	u64 rx_nodesc_drops_while_down;
857*4882a593Smuzhiyun 	bool rx_nodesc_drops_prev_state;
858*4882a593Smuzhiyun 
859*4882a593Smuzhiyun 	unsigned int phy_type;
860*4882a593Smuzhiyun 	const struct ef4_phy_operations *phy_op;
861*4882a593Smuzhiyun 	void *phy_data;
862*4882a593Smuzhiyun 	struct mdio_if_info mdio;
863*4882a593Smuzhiyun 	enum ef4_phy_mode phy_mode;
864*4882a593Smuzhiyun 
865*4882a593Smuzhiyun 	u32 link_advertising;
866*4882a593Smuzhiyun 	struct ef4_link_state link_state;
867*4882a593Smuzhiyun 	unsigned int n_link_state_changes;
868*4882a593Smuzhiyun 
869*4882a593Smuzhiyun 	bool unicast_filter;
870*4882a593Smuzhiyun 	union ef4_multicast_hash multicast_hash;
871*4882a593Smuzhiyun 	u8 wanted_fc;
872*4882a593Smuzhiyun 	unsigned fc_disable;
873*4882a593Smuzhiyun 
874*4882a593Smuzhiyun 	atomic_t rx_reset;
875*4882a593Smuzhiyun 	enum ef4_loopback_mode loopback_mode;
876*4882a593Smuzhiyun 	u64 loopback_modes;
877*4882a593Smuzhiyun 
878*4882a593Smuzhiyun 	void *loopback_selftest;
879*4882a593Smuzhiyun 
880*4882a593Smuzhiyun 	struct rw_semaphore filter_sem;
881*4882a593Smuzhiyun 	spinlock_t filter_lock;
882*4882a593Smuzhiyun 	void *filter_state;
883*4882a593Smuzhiyun #ifdef CONFIG_RFS_ACCEL
884*4882a593Smuzhiyun 	unsigned int rps_expire_channel;
885*4882a593Smuzhiyun 	unsigned int rps_expire_index;
886*4882a593Smuzhiyun #endif
887*4882a593Smuzhiyun 
888*4882a593Smuzhiyun 	atomic_t active_queues;
889*4882a593Smuzhiyun 	atomic_t rxq_flush_pending;
890*4882a593Smuzhiyun 	atomic_t rxq_flush_outstanding;
891*4882a593Smuzhiyun 	wait_queue_head_t flush_wq;
892*4882a593Smuzhiyun 
893*4882a593Smuzhiyun 	char *vpd_sn;
894*4882a593Smuzhiyun 
895*4882a593Smuzhiyun 	/* The following fields may be written more often */
896*4882a593Smuzhiyun 
897*4882a593Smuzhiyun 	struct delayed_work monitor_work ____cacheline_aligned_in_smp;
898*4882a593Smuzhiyun 	spinlock_t biu_lock;
899*4882a593Smuzhiyun 	int last_irq_cpu;
900*4882a593Smuzhiyun 	spinlock_t stats_lock;
901*4882a593Smuzhiyun 	atomic_t n_rx_noskb_drops;
902*4882a593Smuzhiyun };
903*4882a593Smuzhiyun 
ef4_dev_registered(struct ef4_nic * efx)904*4882a593Smuzhiyun static inline int ef4_dev_registered(struct ef4_nic *efx)
905*4882a593Smuzhiyun {
906*4882a593Smuzhiyun 	return efx->net_dev->reg_state == NETREG_REGISTERED;
907*4882a593Smuzhiyun }
908*4882a593Smuzhiyun 
ef4_port_num(struct ef4_nic * efx)909*4882a593Smuzhiyun static inline unsigned int ef4_port_num(struct ef4_nic *efx)
910*4882a593Smuzhiyun {
911*4882a593Smuzhiyun 	return efx->port_num;
912*4882a593Smuzhiyun }
913*4882a593Smuzhiyun 
914*4882a593Smuzhiyun struct ef4_mtd_partition {
915*4882a593Smuzhiyun 	struct list_head node;
916*4882a593Smuzhiyun 	struct mtd_info mtd;
917*4882a593Smuzhiyun 	const char *dev_type_name;
918*4882a593Smuzhiyun 	const char *type_name;
919*4882a593Smuzhiyun 	char name[IFNAMSIZ + 20];
920*4882a593Smuzhiyun };
921*4882a593Smuzhiyun 
922*4882a593Smuzhiyun /**
923*4882a593Smuzhiyun  * struct ef4_nic_type - Efx device type definition
924*4882a593Smuzhiyun  * @mem_bar: Get the memory BAR
925*4882a593Smuzhiyun  * @mem_map_size: Get memory BAR mapped size
926*4882a593Smuzhiyun  * @probe: Probe the controller
927*4882a593Smuzhiyun  * @remove: Free resources allocated by probe()
928*4882a593Smuzhiyun  * @init: Initialise the controller
929*4882a593Smuzhiyun  * @dimension_resources: Dimension controller resources (buffer table,
930*4882a593Smuzhiyun  *	and VIs once the available interrupt resources are clear)
931*4882a593Smuzhiyun  * @fini: Shut down the controller
932*4882a593Smuzhiyun  * @monitor: Periodic function for polling link state and hardware monitor
933*4882a593Smuzhiyun  * @map_reset_reason: Map ethtool reset reason to a reset method
934*4882a593Smuzhiyun  * @map_reset_flags: Map ethtool reset flags to a reset method, if possible
935*4882a593Smuzhiyun  * @reset: Reset the controller hardware and possibly the PHY.  This will
936*4882a593Smuzhiyun  *	be called while the controller is uninitialised.
937*4882a593Smuzhiyun  * @probe_port: Probe the MAC and PHY
938*4882a593Smuzhiyun  * @remove_port: Free resources allocated by probe_port()
939*4882a593Smuzhiyun  * @handle_global_event: Handle a "global" event (may be %NULL)
940*4882a593Smuzhiyun  * @fini_dmaq: Flush and finalise DMA queues (RX and TX queues)
941*4882a593Smuzhiyun  * @prepare_flush: Prepare the hardware for flushing the DMA queues
942*4882a593Smuzhiyun  *	(for Falcon architecture)
943*4882a593Smuzhiyun  * @finish_flush: Clean up after flushing the DMA queues (for Falcon
944*4882a593Smuzhiyun  *	architecture)
945*4882a593Smuzhiyun  * @prepare_flr: Prepare for an FLR
946*4882a593Smuzhiyun  * @finish_flr: Clean up after an FLR
947*4882a593Smuzhiyun  * @describe_stats: Describe statistics for ethtool
948*4882a593Smuzhiyun  * @update_stats: Update statistics not provided by event handling.
949*4882a593Smuzhiyun  *	Either argument may be %NULL.
950*4882a593Smuzhiyun  * @start_stats: Start the regular fetching of statistics
951*4882a593Smuzhiyun  * @pull_stats: Pull stats from the NIC and wait until they arrive.
952*4882a593Smuzhiyun  * @stop_stats: Stop the regular fetching of statistics
953*4882a593Smuzhiyun  * @set_id_led: Set state of identifying LED or revert to automatic function
954*4882a593Smuzhiyun  * @push_irq_moderation: Apply interrupt moderation value
955*4882a593Smuzhiyun  * @reconfigure_port: Push loopback/power/txdis changes to the MAC and PHY
956*4882a593Smuzhiyun  * @prepare_enable_fc_tx: Prepare MAC to enable pause frame TX (may be %NULL)
957*4882a593Smuzhiyun  * @reconfigure_mac: Push MAC address, MTU, flow control and filter settings
958*4882a593Smuzhiyun  *	to the hardware.  Serialised by the mac_lock.
959*4882a593Smuzhiyun  * @check_mac_fault: Check MAC fault state. True if fault present.
960*4882a593Smuzhiyun  * @get_wol: Get WoL configuration from driver state
961*4882a593Smuzhiyun  * @set_wol: Push WoL configuration to the NIC
962*4882a593Smuzhiyun  * @resume_wol: Synchronise WoL state between driver and MC (e.g. after resume)
963*4882a593Smuzhiyun  * @test_chip: Test registers.  May use ef4_farch_test_registers(), and is
964*4882a593Smuzhiyun  *	expected to reset the NIC.
965*4882a593Smuzhiyun  * @test_nvram: Test validity of NVRAM contents
966*4882a593Smuzhiyun  * @irq_enable_master: Enable IRQs on the NIC.  Each event queue must
967*4882a593Smuzhiyun  *	be separately enabled after this.
968*4882a593Smuzhiyun  * @irq_test_generate: Generate a test IRQ
969*4882a593Smuzhiyun  * @irq_disable_non_ev: Disable non-event IRQs on the NIC.  Each event
970*4882a593Smuzhiyun  *	queue must be separately disabled before this.
971*4882a593Smuzhiyun  * @irq_handle_msi: Handle MSI for a channel.  The @dev_id argument is
972*4882a593Smuzhiyun  *	a pointer to the &struct ef4_msi_context for the channel.
973*4882a593Smuzhiyun  * @irq_handle_legacy: Handle legacy interrupt.  The @dev_id argument
974*4882a593Smuzhiyun  *	is a pointer to the &struct ef4_nic.
975*4882a593Smuzhiyun  * @tx_probe: Allocate resources for TX queue
976*4882a593Smuzhiyun  * @tx_init: Initialise TX queue on the NIC
977*4882a593Smuzhiyun  * @tx_remove: Free resources for TX queue
978*4882a593Smuzhiyun  * @tx_write: Write TX descriptors and doorbell
979*4882a593Smuzhiyun  * @rx_push_rss_config: Write RSS hash key and indirection table to the NIC
980*4882a593Smuzhiyun  * @rx_probe: Allocate resources for RX queue
981*4882a593Smuzhiyun  * @rx_init: Initialise RX queue on the NIC
982*4882a593Smuzhiyun  * @rx_remove: Free resources for RX queue
983*4882a593Smuzhiyun  * @rx_write: Write RX descriptors and doorbell
984*4882a593Smuzhiyun  * @rx_defer_refill: Generate a refill reminder event
985*4882a593Smuzhiyun  * @ev_probe: Allocate resources for event queue
986*4882a593Smuzhiyun  * @ev_init: Initialise event queue on the NIC
987*4882a593Smuzhiyun  * @ev_fini: Deinitialise event queue on the NIC
988*4882a593Smuzhiyun  * @ev_remove: Free resources for event queue
989*4882a593Smuzhiyun  * @ev_process: Process events for a queue, up to the given NAPI quota
990*4882a593Smuzhiyun  * @ev_read_ack: Acknowledge read events on a queue, rearming its IRQ
991*4882a593Smuzhiyun  * @ev_test_generate: Generate a test event
992*4882a593Smuzhiyun  * @filter_table_probe: Probe filter capabilities and set up filter software state
993*4882a593Smuzhiyun  * @filter_table_restore: Restore filters removed from hardware
994*4882a593Smuzhiyun  * @filter_table_remove: Remove filters from hardware and tear down software state
995*4882a593Smuzhiyun  * @filter_update_rx_scatter: Update filters after change to rx scatter setting
996*4882a593Smuzhiyun  * @filter_insert: add or replace a filter
997*4882a593Smuzhiyun  * @filter_remove_safe: remove a filter by ID, carefully
998*4882a593Smuzhiyun  * @filter_get_safe: retrieve a filter by ID, carefully
999*4882a593Smuzhiyun  * @filter_clear_rx: Remove all RX filters whose priority is less than or
1000*4882a593Smuzhiyun  *	equal to the given priority and is not %EF4_FILTER_PRI_AUTO
1001*4882a593Smuzhiyun  * @filter_count_rx_used: Get the number of filters in use at a given priority
1002*4882a593Smuzhiyun  * @filter_get_rx_id_limit: Get maximum value of a filter id, plus 1
1003*4882a593Smuzhiyun  * @filter_get_rx_ids: Get list of RX filters at a given priority
1004*4882a593Smuzhiyun  * @filter_rfs_insert: Add or replace a filter for RFS.  This must be
1005*4882a593Smuzhiyun  *	atomic.  The hardware change may be asynchronous but should
1006*4882a593Smuzhiyun  *	not be delayed for long.  It may fail if this can't be done
1007*4882a593Smuzhiyun  *	atomically.
1008*4882a593Smuzhiyun  * @filter_rfs_expire_one: Consider expiring a filter inserted for RFS.
1009*4882a593Smuzhiyun  *	This must check whether the specified table entry is used by RFS
1010*4882a593Smuzhiyun  *	and that rps_may_expire_flow() returns true for it.
1011*4882a593Smuzhiyun  * @mtd_probe: Probe and add MTD partitions associated with this net device,
1012*4882a593Smuzhiyun  *	 using ef4_mtd_add()
1013*4882a593Smuzhiyun  * @mtd_rename: Set an MTD partition name using the net device name
1014*4882a593Smuzhiyun  * @mtd_read: Read from an MTD partition
1015*4882a593Smuzhiyun  * @mtd_erase: Erase part of an MTD partition
1016*4882a593Smuzhiyun  * @mtd_write: Write to an MTD partition
1017*4882a593Smuzhiyun  * @mtd_sync: Wait for write-back to complete on MTD partition.  This
1018*4882a593Smuzhiyun  *	also notifies the driver that a writer has finished using this
1019*4882a593Smuzhiyun  *	partition.
1020*4882a593Smuzhiyun  * @set_mac_address: Set the MAC address of the device
1021*4882a593Smuzhiyun  * @revision: Hardware architecture revision
1022*4882a593Smuzhiyun  * @txd_ptr_tbl_base: TX descriptor ring base address
1023*4882a593Smuzhiyun  * @rxd_ptr_tbl_base: RX descriptor ring base address
1024*4882a593Smuzhiyun  * @buf_tbl_base: Buffer table base address
1025*4882a593Smuzhiyun  * @evq_ptr_tbl_base: Event queue pointer table base address
1026*4882a593Smuzhiyun  * @evq_rptr_tbl_base: Event queue read-pointer table base address
1027*4882a593Smuzhiyun  * @max_dma_mask: Maximum possible DMA mask
1028*4882a593Smuzhiyun  * @rx_prefix_size: Size of RX prefix before packet data
1029*4882a593Smuzhiyun  * @rx_hash_offset: Offset of RX flow hash within prefix
1030*4882a593Smuzhiyun  * @rx_ts_offset: Offset of timestamp within prefix
1031*4882a593Smuzhiyun  * @rx_buffer_padding: Size of padding at end of RX packet
1032*4882a593Smuzhiyun  * @can_rx_scatter: NIC is able to scatter packets to multiple buffers
1033*4882a593Smuzhiyun  * @always_rx_scatter: NIC will always scatter packets to multiple buffers
1034*4882a593Smuzhiyun  * @max_interrupt_mode: Highest capability interrupt mode supported
1035*4882a593Smuzhiyun  *	from &enum ef4_init_mode.
1036*4882a593Smuzhiyun  * @timer_period_max: Maximum period of interrupt timer (in ticks)
1037*4882a593Smuzhiyun  * @offload_features: net_device feature flags for protocol offload
1038*4882a593Smuzhiyun  *	features implemented in hardware
1039*4882a593Smuzhiyun  */
1040*4882a593Smuzhiyun struct ef4_nic_type {
1041*4882a593Smuzhiyun 	unsigned int mem_bar;
1042*4882a593Smuzhiyun 	unsigned int (*mem_map_size)(struct ef4_nic *efx);
1043*4882a593Smuzhiyun 	int (*probe)(struct ef4_nic *efx);
1044*4882a593Smuzhiyun 	void (*remove)(struct ef4_nic *efx);
1045*4882a593Smuzhiyun 	int (*init)(struct ef4_nic *efx);
1046*4882a593Smuzhiyun 	int (*dimension_resources)(struct ef4_nic *efx);
1047*4882a593Smuzhiyun 	void (*fini)(struct ef4_nic *efx);
1048*4882a593Smuzhiyun 	void (*monitor)(struct ef4_nic *efx);
1049*4882a593Smuzhiyun 	enum reset_type (*map_reset_reason)(enum reset_type reason);
1050*4882a593Smuzhiyun 	int (*map_reset_flags)(u32 *flags);
1051*4882a593Smuzhiyun 	int (*reset)(struct ef4_nic *efx, enum reset_type method);
1052*4882a593Smuzhiyun 	int (*probe_port)(struct ef4_nic *efx);
1053*4882a593Smuzhiyun 	void (*remove_port)(struct ef4_nic *efx);
1054*4882a593Smuzhiyun 	bool (*handle_global_event)(struct ef4_channel *channel, ef4_qword_t *);
1055*4882a593Smuzhiyun 	int (*fini_dmaq)(struct ef4_nic *efx);
1056*4882a593Smuzhiyun 	void (*prepare_flush)(struct ef4_nic *efx);
1057*4882a593Smuzhiyun 	void (*finish_flush)(struct ef4_nic *efx);
1058*4882a593Smuzhiyun 	void (*prepare_flr)(struct ef4_nic *efx);
1059*4882a593Smuzhiyun 	void (*finish_flr)(struct ef4_nic *efx);
1060*4882a593Smuzhiyun 	size_t (*describe_stats)(struct ef4_nic *efx, u8 *names);
1061*4882a593Smuzhiyun 	size_t (*update_stats)(struct ef4_nic *efx, u64 *full_stats,
1062*4882a593Smuzhiyun 			       struct rtnl_link_stats64 *core_stats);
1063*4882a593Smuzhiyun 	void (*start_stats)(struct ef4_nic *efx);
1064*4882a593Smuzhiyun 	void (*pull_stats)(struct ef4_nic *efx);
1065*4882a593Smuzhiyun 	void (*stop_stats)(struct ef4_nic *efx);
1066*4882a593Smuzhiyun 	void (*set_id_led)(struct ef4_nic *efx, enum ef4_led_mode mode);
1067*4882a593Smuzhiyun 	void (*push_irq_moderation)(struct ef4_channel *channel);
1068*4882a593Smuzhiyun 	int (*reconfigure_port)(struct ef4_nic *efx);
1069*4882a593Smuzhiyun 	void (*prepare_enable_fc_tx)(struct ef4_nic *efx);
1070*4882a593Smuzhiyun 	int (*reconfigure_mac)(struct ef4_nic *efx);
1071*4882a593Smuzhiyun 	bool (*check_mac_fault)(struct ef4_nic *efx);
1072*4882a593Smuzhiyun 	void (*get_wol)(struct ef4_nic *efx, struct ethtool_wolinfo *wol);
1073*4882a593Smuzhiyun 	int (*set_wol)(struct ef4_nic *efx, u32 type);
1074*4882a593Smuzhiyun 	void (*resume_wol)(struct ef4_nic *efx);
1075*4882a593Smuzhiyun 	int (*test_chip)(struct ef4_nic *efx, struct ef4_self_tests *tests);
1076*4882a593Smuzhiyun 	int (*test_nvram)(struct ef4_nic *efx);
1077*4882a593Smuzhiyun 	void (*irq_enable_master)(struct ef4_nic *efx);
1078*4882a593Smuzhiyun 	int (*irq_test_generate)(struct ef4_nic *efx);
1079*4882a593Smuzhiyun 	void (*irq_disable_non_ev)(struct ef4_nic *efx);
1080*4882a593Smuzhiyun 	irqreturn_t (*irq_handle_msi)(int irq, void *dev_id);
1081*4882a593Smuzhiyun 	irqreturn_t (*irq_handle_legacy)(int irq, void *dev_id);
1082*4882a593Smuzhiyun 	int (*tx_probe)(struct ef4_tx_queue *tx_queue);
1083*4882a593Smuzhiyun 	void (*tx_init)(struct ef4_tx_queue *tx_queue);
1084*4882a593Smuzhiyun 	void (*tx_remove)(struct ef4_tx_queue *tx_queue);
1085*4882a593Smuzhiyun 	void (*tx_write)(struct ef4_tx_queue *tx_queue);
1086*4882a593Smuzhiyun 	unsigned int (*tx_limit_len)(struct ef4_tx_queue *tx_queue,
1087*4882a593Smuzhiyun 				     dma_addr_t dma_addr, unsigned int len);
1088*4882a593Smuzhiyun 	int (*rx_push_rss_config)(struct ef4_nic *efx, bool user,
1089*4882a593Smuzhiyun 				  const u32 *rx_indir_table);
1090*4882a593Smuzhiyun 	int (*rx_probe)(struct ef4_rx_queue *rx_queue);
1091*4882a593Smuzhiyun 	void (*rx_init)(struct ef4_rx_queue *rx_queue);
1092*4882a593Smuzhiyun 	void (*rx_remove)(struct ef4_rx_queue *rx_queue);
1093*4882a593Smuzhiyun 	void (*rx_write)(struct ef4_rx_queue *rx_queue);
1094*4882a593Smuzhiyun 	void (*rx_defer_refill)(struct ef4_rx_queue *rx_queue);
1095*4882a593Smuzhiyun 	int (*ev_probe)(struct ef4_channel *channel);
1096*4882a593Smuzhiyun 	int (*ev_init)(struct ef4_channel *channel);
1097*4882a593Smuzhiyun 	void (*ev_fini)(struct ef4_channel *channel);
1098*4882a593Smuzhiyun 	void (*ev_remove)(struct ef4_channel *channel);
1099*4882a593Smuzhiyun 	int (*ev_process)(struct ef4_channel *channel, int quota);
1100*4882a593Smuzhiyun 	void (*ev_read_ack)(struct ef4_channel *channel);
1101*4882a593Smuzhiyun 	void (*ev_test_generate)(struct ef4_channel *channel);
1102*4882a593Smuzhiyun 	int (*filter_table_probe)(struct ef4_nic *efx);
1103*4882a593Smuzhiyun 	void (*filter_table_restore)(struct ef4_nic *efx);
1104*4882a593Smuzhiyun 	void (*filter_table_remove)(struct ef4_nic *efx);
1105*4882a593Smuzhiyun 	void (*filter_update_rx_scatter)(struct ef4_nic *efx);
1106*4882a593Smuzhiyun 	s32 (*filter_insert)(struct ef4_nic *efx,
1107*4882a593Smuzhiyun 			     struct ef4_filter_spec *spec, bool replace);
1108*4882a593Smuzhiyun 	int (*filter_remove_safe)(struct ef4_nic *efx,
1109*4882a593Smuzhiyun 				  enum ef4_filter_priority priority,
1110*4882a593Smuzhiyun 				  u32 filter_id);
1111*4882a593Smuzhiyun 	int (*filter_get_safe)(struct ef4_nic *efx,
1112*4882a593Smuzhiyun 			       enum ef4_filter_priority priority,
1113*4882a593Smuzhiyun 			       u32 filter_id, struct ef4_filter_spec *);
1114*4882a593Smuzhiyun 	int (*filter_clear_rx)(struct ef4_nic *efx,
1115*4882a593Smuzhiyun 			       enum ef4_filter_priority priority);
1116*4882a593Smuzhiyun 	u32 (*filter_count_rx_used)(struct ef4_nic *efx,
1117*4882a593Smuzhiyun 				    enum ef4_filter_priority priority);
1118*4882a593Smuzhiyun 	u32 (*filter_get_rx_id_limit)(struct ef4_nic *efx);
1119*4882a593Smuzhiyun 	s32 (*filter_get_rx_ids)(struct ef4_nic *efx,
1120*4882a593Smuzhiyun 				 enum ef4_filter_priority priority,
1121*4882a593Smuzhiyun 				 u32 *buf, u32 size);
1122*4882a593Smuzhiyun #ifdef CONFIG_RFS_ACCEL
1123*4882a593Smuzhiyun 	s32 (*filter_rfs_insert)(struct ef4_nic *efx,
1124*4882a593Smuzhiyun 				 struct ef4_filter_spec *spec);
1125*4882a593Smuzhiyun 	bool (*filter_rfs_expire_one)(struct ef4_nic *efx, u32 flow_id,
1126*4882a593Smuzhiyun 				      unsigned int index);
1127*4882a593Smuzhiyun #endif
1128*4882a593Smuzhiyun #ifdef CONFIG_SFC_FALCON_MTD
1129*4882a593Smuzhiyun 	int (*mtd_probe)(struct ef4_nic *efx);
1130*4882a593Smuzhiyun 	void (*mtd_rename)(struct ef4_mtd_partition *part);
1131*4882a593Smuzhiyun 	int (*mtd_read)(struct mtd_info *mtd, loff_t start, size_t len,
1132*4882a593Smuzhiyun 			size_t *retlen, u8 *buffer);
1133*4882a593Smuzhiyun 	int (*mtd_erase)(struct mtd_info *mtd, loff_t start, size_t len);
1134*4882a593Smuzhiyun 	int (*mtd_write)(struct mtd_info *mtd, loff_t start, size_t len,
1135*4882a593Smuzhiyun 			 size_t *retlen, const u8 *buffer);
1136*4882a593Smuzhiyun 	int (*mtd_sync)(struct mtd_info *mtd);
1137*4882a593Smuzhiyun #endif
1138*4882a593Smuzhiyun 	int (*get_mac_address)(struct ef4_nic *efx, unsigned char *perm_addr);
1139*4882a593Smuzhiyun 	int (*set_mac_address)(struct ef4_nic *efx);
1140*4882a593Smuzhiyun 
1141*4882a593Smuzhiyun 	int revision;
1142*4882a593Smuzhiyun 	unsigned int txd_ptr_tbl_base;
1143*4882a593Smuzhiyun 	unsigned int rxd_ptr_tbl_base;
1144*4882a593Smuzhiyun 	unsigned int buf_tbl_base;
1145*4882a593Smuzhiyun 	unsigned int evq_ptr_tbl_base;
1146*4882a593Smuzhiyun 	unsigned int evq_rptr_tbl_base;
1147*4882a593Smuzhiyun 	u64 max_dma_mask;
1148*4882a593Smuzhiyun 	unsigned int rx_prefix_size;
1149*4882a593Smuzhiyun 	unsigned int rx_hash_offset;
1150*4882a593Smuzhiyun 	unsigned int rx_ts_offset;
1151*4882a593Smuzhiyun 	unsigned int rx_buffer_padding;
1152*4882a593Smuzhiyun 	bool can_rx_scatter;
1153*4882a593Smuzhiyun 	bool always_rx_scatter;
1154*4882a593Smuzhiyun 	unsigned int max_interrupt_mode;
1155*4882a593Smuzhiyun 	unsigned int timer_period_max;
1156*4882a593Smuzhiyun 	netdev_features_t offload_features;
1157*4882a593Smuzhiyun 	unsigned int max_rx_ip_filters;
1158*4882a593Smuzhiyun };
1159*4882a593Smuzhiyun 
1160*4882a593Smuzhiyun /**************************************************************************
1161*4882a593Smuzhiyun  *
1162*4882a593Smuzhiyun  * Prototypes and inline functions
1163*4882a593Smuzhiyun  *
1164*4882a593Smuzhiyun  *************************************************************************/
1165*4882a593Smuzhiyun 
1166*4882a593Smuzhiyun static inline struct ef4_channel *
ef4_get_channel(struct ef4_nic * efx,unsigned index)1167*4882a593Smuzhiyun ef4_get_channel(struct ef4_nic *efx, unsigned index)
1168*4882a593Smuzhiyun {
1169*4882a593Smuzhiyun 	EF4_BUG_ON_PARANOID(index >= efx->n_channels);
1170*4882a593Smuzhiyun 	return efx->channel[index];
1171*4882a593Smuzhiyun }
1172*4882a593Smuzhiyun 
1173*4882a593Smuzhiyun /* Iterate over all used channels */
1174*4882a593Smuzhiyun #define ef4_for_each_channel(_channel, _efx)				\
1175*4882a593Smuzhiyun 	for (_channel = (_efx)->channel[0];				\
1176*4882a593Smuzhiyun 	     _channel;							\
1177*4882a593Smuzhiyun 	     _channel = (_channel->channel + 1 < (_efx)->n_channels) ?	\
1178*4882a593Smuzhiyun 		     (_efx)->channel[_channel->channel + 1] : NULL)
1179*4882a593Smuzhiyun 
1180*4882a593Smuzhiyun /* Iterate over all used channels in reverse */
1181*4882a593Smuzhiyun #define ef4_for_each_channel_rev(_channel, _efx)			\
1182*4882a593Smuzhiyun 	for (_channel = (_efx)->channel[(_efx)->n_channels - 1];	\
1183*4882a593Smuzhiyun 	     _channel;							\
1184*4882a593Smuzhiyun 	     _channel = _channel->channel ?				\
1185*4882a593Smuzhiyun 		     (_efx)->channel[_channel->channel - 1] : NULL)
1186*4882a593Smuzhiyun 
1187*4882a593Smuzhiyun static inline struct ef4_tx_queue *
ef4_get_tx_queue(struct ef4_nic * efx,unsigned index,unsigned type)1188*4882a593Smuzhiyun ef4_get_tx_queue(struct ef4_nic *efx, unsigned index, unsigned type)
1189*4882a593Smuzhiyun {
1190*4882a593Smuzhiyun 	EF4_BUG_ON_PARANOID(index >= efx->n_tx_channels ||
1191*4882a593Smuzhiyun 			    type >= EF4_TXQ_TYPES);
1192*4882a593Smuzhiyun 	return &efx->channel[efx->tx_channel_offset + index]->tx_queue[type];
1193*4882a593Smuzhiyun }
1194*4882a593Smuzhiyun 
ef4_channel_has_tx_queues(struct ef4_channel * channel)1195*4882a593Smuzhiyun static inline bool ef4_channel_has_tx_queues(struct ef4_channel *channel)
1196*4882a593Smuzhiyun {
1197*4882a593Smuzhiyun 	return channel->channel - channel->efx->tx_channel_offset <
1198*4882a593Smuzhiyun 		channel->efx->n_tx_channels;
1199*4882a593Smuzhiyun }
1200*4882a593Smuzhiyun 
1201*4882a593Smuzhiyun static inline struct ef4_tx_queue *
ef4_channel_get_tx_queue(struct ef4_channel * channel,unsigned type)1202*4882a593Smuzhiyun ef4_channel_get_tx_queue(struct ef4_channel *channel, unsigned type)
1203*4882a593Smuzhiyun {
1204*4882a593Smuzhiyun 	EF4_BUG_ON_PARANOID(!ef4_channel_has_tx_queues(channel) ||
1205*4882a593Smuzhiyun 			    type >= EF4_TXQ_TYPES);
1206*4882a593Smuzhiyun 	return &channel->tx_queue[type];
1207*4882a593Smuzhiyun }
1208*4882a593Smuzhiyun 
ef4_tx_queue_used(struct ef4_tx_queue * tx_queue)1209*4882a593Smuzhiyun static inline bool ef4_tx_queue_used(struct ef4_tx_queue *tx_queue)
1210*4882a593Smuzhiyun {
1211*4882a593Smuzhiyun 	return !(tx_queue->efx->net_dev->num_tc < 2 &&
1212*4882a593Smuzhiyun 		 tx_queue->queue & EF4_TXQ_TYPE_HIGHPRI);
1213*4882a593Smuzhiyun }
1214*4882a593Smuzhiyun 
1215*4882a593Smuzhiyun /* Iterate over all TX queues belonging to a channel */
1216*4882a593Smuzhiyun #define ef4_for_each_channel_tx_queue(_tx_queue, _channel)		\
1217*4882a593Smuzhiyun 	if (!ef4_channel_has_tx_queues(_channel))			\
1218*4882a593Smuzhiyun 		;							\
1219*4882a593Smuzhiyun 	else								\
1220*4882a593Smuzhiyun 		for (_tx_queue = (_channel)->tx_queue;			\
1221*4882a593Smuzhiyun 		     _tx_queue < (_channel)->tx_queue + EF4_TXQ_TYPES && \
1222*4882a593Smuzhiyun 			     ef4_tx_queue_used(_tx_queue);		\
1223*4882a593Smuzhiyun 		     _tx_queue++)
1224*4882a593Smuzhiyun 
1225*4882a593Smuzhiyun /* Iterate over all possible TX queues belonging to a channel */
1226*4882a593Smuzhiyun #define ef4_for_each_possible_channel_tx_queue(_tx_queue, _channel)	\
1227*4882a593Smuzhiyun 	if (!ef4_channel_has_tx_queues(_channel))			\
1228*4882a593Smuzhiyun 		;							\
1229*4882a593Smuzhiyun 	else								\
1230*4882a593Smuzhiyun 		for (_tx_queue = (_channel)->tx_queue;			\
1231*4882a593Smuzhiyun 		     _tx_queue < (_channel)->tx_queue + EF4_TXQ_TYPES;	\
1232*4882a593Smuzhiyun 		     _tx_queue++)
1233*4882a593Smuzhiyun 
ef4_channel_has_rx_queue(struct ef4_channel * channel)1234*4882a593Smuzhiyun static inline bool ef4_channel_has_rx_queue(struct ef4_channel *channel)
1235*4882a593Smuzhiyun {
1236*4882a593Smuzhiyun 	return channel->rx_queue.core_index >= 0;
1237*4882a593Smuzhiyun }
1238*4882a593Smuzhiyun 
1239*4882a593Smuzhiyun static inline struct ef4_rx_queue *
ef4_channel_get_rx_queue(struct ef4_channel * channel)1240*4882a593Smuzhiyun ef4_channel_get_rx_queue(struct ef4_channel *channel)
1241*4882a593Smuzhiyun {
1242*4882a593Smuzhiyun 	EF4_BUG_ON_PARANOID(!ef4_channel_has_rx_queue(channel));
1243*4882a593Smuzhiyun 	return &channel->rx_queue;
1244*4882a593Smuzhiyun }
1245*4882a593Smuzhiyun 
1246*4882a593Smuzhiyun /* Iterate over all RX queues belonging to a channel */
1247*4882a593Smuzhiyun #define ef4_for_each_channel_rx_queue(_rx_queue, _channel)		\
1248*4882a593Smuzhiyun 	if (!ef4_channel_has_rx_queue(_channel))			\
1249*4882a593Smuzhiyun 		;							\
1250*4882a593Smuzhiyun 	else								\
1251*4882a593Smuzhiyun 		for (_rx_queue = &(_channel)->rx_queue;			\
1252*4882a593Smuzhiyun 		     _rx_queue;						\
1253*4882a593Smuzhiyun 		     _rx_queue = NULL)
1254*4882a593Smuzhiyun 
1255*4882a593Smuzhiyun static inline struct ef4_channel *
ef4_rx_queue_channel(struct ef4_rx_queue * rx_queue)1256*4882a593Smuzhiyun ef4_rx_queue_channel(struct ef4_rx_queue *rx_queue)
1257*4882a593Smuzhiyun {
1258*4882a593Smuzhiyun 	return container_of(rx_queue, struct ef4_channel, rx_queue);
1259*4882a593Smuzhiyun }
1260*4882a593Smuzhiyun 
ef4_rx_queue_index(struct ef4_rx_queue * rx_queue)1261*4882a593Smuzhiyun static inline int ef4_rx_queue_index(struct ef4_rx_queue *rx_queue)
1262*4882a593Smuzhiyun {
1263*4882a593Smuzhiyun 	return ef4_rx_queue_channel(rx_queue)->channel;
1264*4882a593Smuzhiyun }
1265*4882a593Smuzhiyun 
1266*4882a593Smuzhiyun /* Returns a pointer to the specified receive buffer in the RX
1267*4882a593Smuzhiyun  * descriptor queue.
1268*4882a593Smuzhiyun  */
ef4_rx_buffer(struct ef4_rx_queue * rx_queue,unsigned int index)1269*4882a593Smuzhiyun static inline struct ef4_rx_buffer *ef4_rx_buffer(struct ef4_rx_queue *rx_queue,
1270*4882a593Smuzhiyun 						  unsigned int index)
1271*4882a593Smuzhiyun {
1272*4882a593Smuzhiyun 	return &rx_queue->buffer[index];
1273*4882a593Smuzhiyun }
1274*4882a593Smuzhiyun 
1275*4882a593Smuzhiyun /**
1276*4882a593Smuzhiyun  * EF4_MAX_FRAME_LEN - calculate maximum frame length
1277*4882a593Smuzhiyun  *
1278*4882a593Smuzhiyun  * This calculates the maximum frame length that will be used for a
1279*4882a593Smuzhiyun  * given MTU.  The frame length will be equal to the MTU plus a
1280*4882a593Smuzhiyun  * constant amount of header space and padding.  This is the quantity
1281*4882a593Smuzhiyun  * that the net driver will program into the MAC as the maximum frame
1282*4882a593Smuzhiyun  * length.
1283*4882a593Smuzhiyun  *
1284*4882a593Smuzhiyun  * The 10G MAC requires 8-byte alignment on the frame
1285*4882a593Smuzhiyun  * length, so we round up to the nearest 8.
1286*4882a593Smuzhiyun  *
1287*4882a593Smuzhiyun  * Re-clocking by the XGXS on RX can reduce an IPG to 32 bits (half an
1288*4882a593Smuzhiyun  * XGMII cycle).  If the frame length reaches the maximum value in the
1289*4882a593Smuzhiyun  * same cycle, the XMAC can miss the IPG altogether.  We work around
1290*4882a593Smuzhiyun  * this by adding a further 16 bytes.
1291*4882a593Smuzhiyun  */
1292*4882a593Smuzhiyun #define EF4_FRAME_PAD	16
1293*4882a593Smuzhiyun #define EF4_MAX_FRAME_LEN(mtu) \
1294*4882a593Smuzhiyun 	(ALIGN(((mtu) + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN + EF4_FRAME_PAD), 8))
1295*4882a593Smuzhiyun 
1296*4882a593Smuzhiyun /* Get all supported features.
1297*4882a593Smuzhiyun  * If a feature is not fixed, it is present in hw_features.
1298*4882a593Smuzhiyun  * If a feature is fixed, it does not present in hw_features, but
1299*4882a593Smuzhiyun  * always in features.
1300*4882a593Smuzhiyun  */
ef4_supported_features(const struct ef4_nic * efx)1301*4882a593Smuzhiyun static inline netdev_features_t ef4_supported_features(const struct ef4_nic *efx)
1302*4882a593Smuzhiyun {
1303*4882a593Smuzhiyun 	const struct net_device *net_dev = efx->net_dev;
1304*4882a593Smuzhiyun 
1305*4882a593Smuzhiyun 	return net_dev->features | net_dev->hw_features;
1306*4882a593Smuzhiyun }
1307*4882a593Smuzhiyun 
1308*4882a593Smuzhiyun /* Get the current TX queue insert index. */
1309*4882a593Smuzhiyun static inline unsigned int
ef4_tx_queue_get_insert_index(const struct ef4_tx_queue * tx_queue)1310*4882a593Smuzhiyun ef4_tx_queue_get_insert_index(const struct ef4_tx_queue *tx_queue)
1311*4882a593Smuzhiyun {
1312*4882a593Smuzhiyun 	return tx_queue->insert_count & tx_queue->ptr_mask;
1313*4882a593Smuzhiyun }
1314*4882a593Smuzhiyun 
1315*4882a593Smuzhiyun /* Get a TX buffer. */
1316*4882a593Smuzhiyun static inline struct ef4_tx_buffer *
__ef4_tx_queue_get_insert_buffer(const struct ef4_tx_queue * tx_queue)1317*4882a593Smuzhiyun __ef4_tx_queue_get_insert_buffer(const struct ef4_tx_queue *tx_queue)
1318*4882a593Smuzhiyun {
1319*4882a593Smuzhiyun 	return &tx_queue->buffer[ef4_tx_queue_get_insert_index(tx_queue)];
1320*4882a593Smuzhiyun }
1321*4882a593Smuzhiyun 
1322*4882a593Smuzhiyun /* Get a TX buffer, checking it's not currently in use. */
1323*4882a593Smuzhiyun static inline struct ef4_tx_buffer *
ef4_tx_queue_get_insert_buffer(const struct ef4_tx_queue * tx_queue)1324*4882a593Smuzhiyun ef4_tx_queue_get_insert_buffer(const struct ef4_tx_queue *tx_queue)
1325*4882a593Smuzhiyun {
1326*4882a593Smuzhiyun 	struct ef4_tx_buffer *buffer =
1327*4882a593Smuzhiyun 		__ef4_tx_queue_get_insert_buffer(tx_queue);
1328*4882a593Smuzhiyun 
1329*4882a593Smuzhiyun 	EF4_BUG_ON_PARANOID(buffer->len);
1330*4882a593Smuzhiyun 	EF4_BUG_ON_PARANOID(buffer->flags);
1331*4882a593Smuzhiyun 	EF4_BUG_ON_PARANOID(buffer->unmap_len);
1332*4882a593Smuzhiyun 
1333*4882a593Smuzhiyun 	return buffer;
1334*4882a593Smuzhiyun }
1335*4882a593Smuzhiyun 
1336*4882a593Smuzhiyun #endif /* EF4_NET_DRIVER_H */
1337