xref: /openbmc/linux/drivers/net/ethernet/sfc/nic.h (revision 79ac47ae)
1874aeea5SJeff Kirsher /****************************************************************************
2f7a6d2c4SBen Hutchings  * Driver for Solarflare network controllers and boards
3874aeea5SJeff Kirsher  * Copyright 2005-2006 Fen Systems Ltd.
4f7a6d2c4SBen Hutchings  * Copyright 2006-2013 Solarflare Communications Inc.
5874aeea5SJeff Kirsher  *
6874aeea5SJeff Kirsher  * This program is free software; you can redistribute it and/or modify it
7874aeea5SJeff Kirsher  * under the terms of the GNU General Public License version 2 as published
8874aeea5SJeff Kirsher  * by the Free Software Foundation, incorporated herein by reference.
9874aeea5SJeff Kirsher  */
10874aeea5SJeff Kirsher 
11874aeea5SJeff Kirsher #ifndef EFX_NIC_H
12874aeea5SJeff Kirsher #define EFX_NIC_H
13874aeea5SJeff Kirsher 
147c236c43SStuart Hodgson #include <linux/net_tstamp.h>
15874aeea5SJeff Kirsher #include <linux/i2c-algo-bit.h>
16874aeea5SJeff Kirsher #include "net_driver.h"
17874aeea5SJeff Kirsher #include "efx.h"
18874aeea5SJeff Kirsher #include "mcdi.h"
19874aeea5SJeff Kirsher 
20874aeea5SJeff Kirsher enum {
21874aeea5SJeff Kirsher 	EFX_REV_FALCON_A0 = 0,
22874aeea5SJeff Kirsher 	EFX_REV_FALCON_A1 = 1,
23874aeea5SJeff Kirsher 	EFX_REV_FALCON_B0 = 2,
24874aeea5SJeff Kirsher 	EFX_REV_SIENA_A0 = 3,
258127d661SBen Hutchings 	EFX_REV_HUNT_A0 = 4,
26874aeea5SJeff Kirsher };
27874aeea5SJeff Kirsher 
28874aeea5SJeff Kirsher static inline int efx_nic_rev(struct efx_nic *efx)
29874aeea5SJeff Kirsher {
30874aeea5SJeff Kirsher 	return efx->type->revision;
31874aeea5SJeff Kirsher }
32874aeea5SJeff Kirsher 
3300aef986SJoe Perches u32 efx_farch_fpga_ver(struct efx_nic *efx);
34874aeea5SJeff Kirsher 
35874aeea5SJeff Kirsher /* NIC has two interlinked PCI functions for the same port. */
36874aeea5SJeff Kirsher static inline bool efx_nic_is_dual_func(struct efx_nic *efx)
37874aeea5SJeff Kirsher {
38874aeea5SJeff Kirsher 	return efx_nic_rev(efx) < EFX_REV_FALCON_B0;
39874aeea5SJeff Kirsher }
40874aeea5SJeff Kirsher 
4186094f7fSBen Hutchings /* Read the current event from the event queue */
4286094f7fSBen Hutchings static inline efx_qword_t *efx_event(struct efx_channel *channel,
4386094f7fSBen Hutchings 				     unsigned int index)
4486094f7fSBen Hutchings {
4586094f7fSBen Hutchings 	return ((efx_qword_t *) (channel->eventq.buf.addr)) +
4686094f7fSBen Hutchings 		(index & channel->eventq_mask);
4786094f7fSBen Hutchings }
4886094f7fSBen Hutchings 
4986094f7fSBen Hutchings /* See if an event is present
5086094f7fSBen Hutchings  *
5186094f7fSBen Hutchings  * We check both the high and low dword of the event for all ones.  We
5286094f7fSBen Hutchings  * wrote all ones when we cleared the event, and no valid event can
5386094f7fSBen Hutchings  * have all ones in either its high or low dwords.  This approach is
5486094f7fSBen Hutchings  * robust against reordering.
5586094f7fSBen Hutchings  *
5686094f7fSBen Hutchings  * Note that using a single 64-bit comparison is incorrect; even
5786094f7fSBen Hutchings  * though the CPU read will be atomic, the DMA write may not be.
5886094f7fSBen Hutchings  */
5986094f7fSBen Hutchings static inline int efx_event_present(efx_qword_t *event)
6086094f7fSBen Hutchings {
6186094f7fSBen Hutchings 	return !(EFX_DWORD_IS_ALL_ONES(event->dword[0]) |
6286094f7fSBen Hutchings 		  EFX_DWORD_IS_ALL_ONES(event->dword[1]));
6386094f7fSBen Hutchings }
6486094f7fSBen Hutchings 
6586094f7fSBen Hutchings /* Returns a pointer to the specified transmit descriptor in the TX
6686094f7fSBen Hutchings  * descriptor queue belonging to the specified channel.
6786094f7fSBen Hutchings  */
6886094f7fSBen Hutchings static inline efx_qword_t *
6986094f7fSBen Hutchings efx_tx_desc(struct efx_tx_queue *tx_queue, unsigned int index)
7086094f7fSBen Hutchings {
7186094f7fSBen Hutchings 	return ((efx_qword_t *) (tx_queue->txd.buf.addr)) + index;
7286094f7fSBen Hutchings }
7386094f7fSBen Hutchings 
74306a2782SBen Hutchings /* Report whether the NIC considers this TX queue empty, given the
75306a2782SBen Hutchings  * write_count used for the last doorbell push.  May return false
76306a2782SBen Hutchings  * negative.
77306a2782SBen Hutchings  */
78306a2782SBen Hutchings static inline bool __efx_nic_tx_is_empty(struct efx_tx_queue *tx_queue,
79306a2782SBen Hutchings 					 unsigned int write_count)
80306a2782SBen Hutchings {
81306a2782SBen Hutchings 	unsigned int empty_read_count = ACCESS_ONCE(tx_queue->empty_read_count);
82306a2782SBen Hutchings 
83306a2782SBen Hutchings 	if (empty_read_count == 0)
84306a2782SBen Hutchings 		return false;
85306a2782SBen Hutchings 
86306a2782SBen Hutchings 	return ((empty_read_count ^ write_count) & ~EFX_EMPTY_COUNT_VALID) == 0;
87306a2782SBen Hutchings }
88306a2782SBen Hutchings 
89306a2782SBen Hutchings static inline bool efx_nic_tx_is_empty(struct efx_tx_queue *tx_queue)
90306a2782SBen Hutchings {
91306a2782SBen Hutchings 	return __efx_nic_tx_is_empty(tx_queue, tx_queue->write_count);
92306a2782SBen Hutchings }
93306a2782SBen Hutchings 
9486094f7fSBen Hutchings /* Decide whether to push a TX descriptor to the NIC vs merely writing
9586094f7fSBen Hutchings  * the doorbell.  This can reduce latency when we are adding a single
9686094f7fSBen Hutchings  * descriptor to an empty queue, but is otherwise pointless.  Further,
9786094f7fSBen Hutchings  * Falcon and Siena have hardware bugs (SF bug 33851) that may be
9886094f7fSBen Hutchings  * triggered if we don't check this.
9986094f7fSBen Hutchings  */
10086094f7fSBen Hutchings static inline bool efx_nic_may_push_tx_desc(struct efx_tx_queue *tx_queue,
10186094f7fSBen Hutchings 					    unsigned int write_count)
10286094f7fSBen Hutchings {
103306a2782SBen Hutchings 	bool was_empty = __efx_nic_tx_is_empty(tx_queue, write_count);
10486094f7fSBen Hutchings 
10586094f7fSBen Hutchings 	tx_queue->empty_read_count = 0;
106306a2782SBen Hutchings 	return was_empty && tx_queue->write_count - write_count == 1;
10786094f7fSBen Hutchings }
10886094f7fSBen Hutchings 
10986094f7fSBen Hutchings /* Returns a pointer to the specified descriptor in the RX descriptor queue */
11086094f7fSBen Hutchings static inline efx_qword_t *
11186094f7fSBen Hutchings efx_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
11286094f7fSBen Hutchings {
11386094f7fSBen Hutchings 	return ((efx_qword_t *) (rx_queue->rxd.buf.addr)) + index;
11486094f7fSBen Hutchings }
11586094f7fSBen Hutchings 
116874aeea5SJeff Kirsher enum {
117874aeea5SJeff Kirsher 	PHY_TYPE_NONE = 0,
118874aeea5SJeff Kirsher 	PHY_TYPE_TXC43128 = 1,
119874aeea5SJeff Kirsher 	PHY_TYPE_88E1111 = 2,
120874aeea5SJeff Kirsher 	PHY_TYPE_SFX7101 = 3,
121874aeea5SJeff Kirsher 	PHY_TYPE_QT2022C2 = 4,
122874aeea5SJeff Kirsher 	PHY_TYPE_PM8358 = 6,
123874aeea5SJeff Kirsher 	PHY_TYPE_SFT9001A = 8,
124874aeea5SJeff Kirsher 	PHY_TYPE_QT2025C = 9,
125874aeea5SJeff Kirsher 	PHY_TYPE_SFT9001B = 10,
126874aeea5SJeff Kirsher };
127874aeea5SJeff Kirsher 
128874aeea5SJeff Kirsher #define FALCON_XMAC_LOOPBACKS			\
129874aeea5SJeff Kirsher 	((1 << LOOPBACK_XGMII) |		\
130874aeea5SJeff Kirsher 	 (1 << LOOPBACK_XGXS) |			\
131874aeea5SJeff Kirsher 	 (1 << LOOPBACK_XAUI))
132874aeea5SJeff Kirsher 
1335b6262d0SBen Hutchings /* Alignment of PCIe DMA boundaries (4KB) */
1345b6262d0SBen Hutchings #define EFX_PAGE_SIZE	4096
1355b6262d0SBen Hutchings /* Size and alignment of buffer table entries (same) */
1365b6262d0SBen Hutchings #define EFX_BUF_SIZE	EFX_PAGE_SIZE
1375b6262d0SBen Hutchings 
138874aeea5SJeff Kirsher /**
139874aeea5SJeff Kirsher  * struct falcon_board_type - board operations and type information
140874aeea5SJeff Kirsher  * @id: Board type id, as found in NVRAM
141874aeea5SJeff Kirsher  * @init: Allocate resources and initialise peripheral hardware
142874aeea5SJeff Kirsher  * @init_phy: Do board-specific PHY initialisation
143874aeea5SJeff Kirsher  * @fini: Shut down hardware and free resources
144874aeea5SJeff Kirsher  * @set_id_led: Set state of identifying LED or revert to automatic function
145874aeea5SJeff Kirsher  * @monitor: Board-specific health check function
146874aeea5SJeff Kirsher  */
147874aeea5SJeff Kirsher struct falcon_board_type {
148874aeea5SJeff Kirsher 	u8 id;
149874aeea5SJeff Kirsher 	int (*init) (struct efx_nic *nic);
150874aeea5SJeff Kirsher 	void (*init_phy) (struct efx_nic *efx);
151874aeea5SJeff Kirsher 	void (*fini) (struct efx_nic *nic);
152874aeea5SJeff Kirsher 	void (*set_id_led) (struct efx_nic *efx, enum efx_led_mode mode);
153874aeea5SJeff Kirsher 	int (*monitor) (struct efx_nic *nic);
154874aeea5SJeff Kirsher };
155874aeea5SJeff Kirsher 
156874aeea5SJeff Kirsher /**
157874aeea5SJeff Kirsher  * struct falcon_board - board information
158874aeea5SJeff Kirsher  * @type: Type of board
159874aeea5SJeff Kirsher  * @major: Major rev. ('A', 'B' ...)
160874aeea5SJeff Kirsher  * @minor: Minor rev. (0, 1, ...)
161874aeea5SJeff Kirsher  * @i2c_adap: I2C adapter for on-board peripherals
162874aeea5SJeff Kirsher  * @i2c_data: Data for bit-banging algorithm
163874aeea5SJeff Kirsher  * @hwmon_client: I2C client for hardware monitor
164874aeea5SJeff Kirsher  * @ioexp_client: I2C client for power/port control
165874aeea5SJeff Kirsher  */
166874aeea5SJeff Kirsher struct falcon_board {
167874aeea5SJeff Kirsher 	const struct falcon_board_type *type;
168874aeea5SJeff Kirsher 	int major;
169874aeea5SJeff Kirsher 	int minor;
170874aeea5SJeff Kirsher 	struct i2c_adapter i2c_adap;
171874aeea5SJeff Kirsher 	struct i2c_algo_bit_data i2c_data;
172874aeea5SJeff Kirsher 	struct i2c_client *hwmon_client, *ioexp_client;
173874aeea5SJeff Kirsher };
174874aeea5SJeff Kirsher 
175874aeea5SJeff Kirsher /**
17645a3fd55SBen Hutchings  * struct falcon_spi_device - a Falcon SPI (Serial Peripheral Interface) device
17745a3fd55SBen Hutchings  * @device_id:		Controller's id for the device
17845a3fd55SBen Hutchings  * @size:		Size (in bytes)
17945a3fd55SBen Hutchings  * @addr_len:		Number of address bytes in read/write commands
18045a3fd55SBen Hutchings  * @munge_address:	Flag whether addresses should be munged.
18145a3fd55SBen Hutchings  *	Some devices with 9-bit addresses (e.g. AT25040A EEPROM)
18245a3fd55SBen Hutchings  *	use bit 3 of the command byte as address bit A8, rather
18345a3fd55SBen Hutchings  *	than having a two-byte address.  If this flag is set, then
18445a3fd55SBen Hutchings  *	commands should be munged in this way.
18545a3fd55SBen Hutchings  * @erase_command:	Erase command (or 0 if sector erase not needed).
18645a3fd55SBen Hutchings  * @erase_size:		Erase sector size (in bytes)
18745a3fd55SBen Hutchings  *	Erase commands affect sectors with this size and alignment.
18845a3fd55SBen Hutchings  *	This must be a power of two.
18945a3fd55SBen Hutchings  * @block_size:		Write block size (in bytes).
19045a3fd55SBen Hutchings  *	Write commands are limited to blocks with this size and alignment.
19145a3fd55SBen Hutchings  */
19245a3fd55SBen Hutchings struct falcon_spi_device {
19345a3fd55SBen Hutchings 	int device_id;
19445a3fd55SBen Hutchings 	unsigned int size;
19545a3fd55SBen Hutchings 	unsigned int addr_len;
19645a3fd55SBen Hutchings 	unsigned int munge_address:1;
19745a3fd55SBen Hutchings 	u8 erase_command;
19845a3fd55SBen Hutchings 	unsigned int erase_size;
19945a3fd55SBen Hutchings 	unsigned int block_size;
20045a3fd55SBen Hutchings };
20145a3fd55SBen Hutchings 
20245a3fd55SBen Hutchings static inline bool falcon_spi_present(const struct falcon_spi_device *spi)
20345a3fd55SBen Hutchings {
20445a3fd55SBen Hutchings 	return spi->size != 0;
20545a3fd55SBen Hutchings }
20645a3fd55SBen Hutchings 
207cd0ecc9aSBen Hutchings enum {
208cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_bytes,
209cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_packets,
210cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_pause,
211cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_control,
212cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_unicast,
213cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_multicast,
214cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_broadcast,
215cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_lt64,
216cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_64,
217cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_65_to_127,
218cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_128_to_255,
219cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_256_to_511,
220cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_512_to_1023,
221cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_1024_to_15xx,
222cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_15xx_to_jumbo,
223cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_gtjumbo,
224cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_non_tcpudp,
225cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_mac_src_error,
226cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_ip_src_error,
227cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_bytes,
228cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_good_bytes,
229cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_bad_bytes,
230cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_packets,
231cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_good,
232cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_bad,
233cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_pause,
234cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_control,
235cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_unicast,
236cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_multicast,
237cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_broadcast,
238cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_lt64,
239cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_64,
240cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_65_to_127,
241cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_128_to_255,
242cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_256_to_511,
243cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_512_to_1023,
244cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_1024_to_15xx,
245cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_15xx_to_jumbo,
246cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_gtjumbo,
247cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_bad_lt64,
248cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_bad_gtjumbo,
249cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_overflow,
250cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_symbol_error,
251cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_align_error,
252cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_length_error,
253cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_internal_error,
254cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_nodesc_drop_cnt,
255cd0ecc9aSBen Hutchings 	FALCON_STAT_COUNT
256cd0ecc9aSBen Hutchings };
257cd0ecc9aSBen Hutchings 
25845a3fd55SBen Hutchings /**
259874aeea5SJeff Kirsher  * struct falcon_nic_data - Falcon NIC state
260874aeea5SJeff Kirsher  * @pci_dev2: Secondary function of Falcon A
261874aeea5SJeff Kirsher  * @board: Board state and functions
262cd0ecc9aSBen Hutchings  * @stats: Hardware statistics
263874aeea5SJeff Kirsher  * @stats_disable_count: Nest count for disabling statistics fetches
264874aeea5SJeff Kirsher  * @stats_pending: Is there a pending DMA of MAC statistics.
265874aeea5SJeff Kirsher  * @stats_timer: A timer for regularly fetching MAC statistics.
266874aeea5SJeff Kirsher  * @spi_flash: SPI flash device
267874aeea5SJeff Kirsher  * @spi_eeprom: SPI EEPROM device
268874aeea5SJeff Kirsher  * @spi_lock: SPI bus lock
269874aeea5SJeff Kirsher  * @mdio_lock: MDIO bus lock
270874aeea5SJeff Kirsher  * @xmac_poll_required: XMAC link state needs polling
271874aeea5SJeff Kirsher  */
272874aeea5SJeff Kirsher struct falcon_nic_data {
273874aeea5SJeff Kirsher 	struct pci_dev *pci_dev2;
274874aeea5SJeff Kirsher 	struct falcon_board board;
275cd0ecc9aSBen Hutchings 	u64 stats[FALCON_STAT_COUNT];
276874aeea5SJeff Kirsher 	unsigned int stats_disable_count;
277874aeea5SJeff Kirsher 	bool stats_pending;
278874aeea5SJeff Kirsher 	struct timer_list stats_timer;
279ecd0a6f0SBen Hutchings 	struct falcon_spi_device spi_flash;
280ecd0a6f0SBen Hutchings 	struct falcon_spi_device spi_eeprom;
281874aeea5SJeff Kirsher 	struct mutex spi_lock;
282874aeea5SJeff Kirsher 	struct mutex mdio_lock;
283874aeea5SJeff Kirsher 	bool xmac_poll_required;
284874aeea5SJeff Kirsher };
285874aeea5SJeff Kirsher 
286874aeea5SJeff Kirsher static inline struct falcon_board *falcon_board(struct efx_nic *efx)
287874aeea5SJeff Kirsher {
288874aeea5SJeff Kirsher 	struct falcon_nic_data *data = efx->nic_data;
289874aeea5SJeff Kirsher 	return &data->board;
290874aeea5SJeff Kirsher }
291874aeea5SJeff Kirsher 
292cd0ecc9aSBen Hutchings enum {
293cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_bytes,
294cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_good_bytes,
295cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_bad_bytes,
296cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_packets,
297cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_bad,
298cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_pause,
299cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_control,
300cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_unicast,
301cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_multicast,
302cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_broadcast,
303cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_lt64,
304cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_64,
305cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_65_to_127,
306cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_128_to_255,
307cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_256_to_511,
308cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_512_to_1023,
309cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_1024_to_15xx,
310cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_15xx_to_jumbo,
311cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_gtjumbo,
312cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_collision,
313cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_single_collision,
314cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_multiple_collision,
315cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_excessive_collision,
316cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_deferred,
317cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_late_collision,
318cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_excessive_deferred,
319cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_non_tcpudp,
320cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_mac_src_error,
321cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_ip_src_error,
322cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_bytes,
323cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_good_bytes,
324cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_bad_bytes,
325cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_packets,
326cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_good,
327cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_bad,
328cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_pause,
329cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_control,
330cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_unicast,
331cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_multicast,
332cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_broadcast,
333cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_lt64,
334cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_64,
335cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_65_to_127,
336cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_128_to_255,
337cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_256_to_511,
338cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_512_to_1023,
339cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_1024_to_15xx,
340cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_15xx_to_jumbo,
341cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_gtjumbo,
342cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_bad_gtjumbo,
343cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_overflow,
344cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_false_carrier,
345cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_symbol_error,
346cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_align_error,
347cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_length_error,
348cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_internal_error,
349cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_nodesc_drop_cnt,
350cd0ecc9aSBen Hutchings 	SIENA_STAT_COUNT
351cd0ecc9aSBen Hutchings };
352cd0ecc9aSBen Hutchings 
353874aeea5SJeff Kirsher /**
354874aeea5SJeff Kirsher  * struct siena_nic_data - Siena NIC state
355874aeea5SJeff Kirsher  * @wol_filter_id: Wake-on-LAN packet filter id
356cd0ecc9aSBen Hutchings  * @stats: Hardware statistics
357874aeea5SJeff Kirsher  */
358874aeea5SJeff Kirsher struct siena_nic_data {
359874aeea5SJeff Kirsher 	int wol_filter_id;
360cd0ecc9aSBen Hutchings 	u64 stats[SIENA_STAT_COUNT];
361874aeea5SJeff Kirsher };
362874aeea5SJeff Kirsher 
3638127d661SBen Hutchings enum {
3648127d661SBen Hutchings 	EF10_STAT_tx_bytes,
3658127d661SBen Hutchings 	EF10_STAT_tx_packets,
3668127d661SBen Hutchings 	EF10_STAT_tx_pause,
3678127d661SBen Hutchings 	EF10_STAT_tx_control,
3688127d661SBen Hutchings 	EF10_STAT_tx_unicast,
3698127d661SBen Hutchings 	EF10_STAT_tx_multicast,
3708127d661SBen Hutchings 	EF10_STAT_tx_broadcast,
3718127d661SBen Hutchings 	EF10_STAT_tx_lt64,
3728127d661SBen Hutchings 	EF10_STAT_tx_64,
3738127d661SBen Hutchings 	EF10_STAT_tx_65_to_127,
3748127d661SBen Hutchings 	EF10_STAT_tx_128_to_255,
3758127d661SBen Hutchings 	EF10_STAT_tx_256_to_511,
3768127d661SBen Hutchings 	EF10_STAT_tx_512_to_1023,
3778127d661SBen Hutchings 	EF10_STAT_tx_1024_to_15xx,
3788127d661SBen Hutchings 	EF10_STAT_tx_15xx_to_jumbo,
3798127d661SBen Hutchings 	EF10_STAT_rx_bytes,
3808127d661SBen Hutchings 	EF10_STAT_rx_bytes_minus_good_bytes,
3818127d661SBen Hutchings 	EF10_STAT_rx_good_bytes,
3828127d661SBen Hutchings 	EF10_STAT_rx_bad_bytes,
3838127d661SBen Hutchings 	EF10_STAT_rx_packets,
3848127d661SBen Hutchings 	EF10_STAT_rx_good,
3858127d661SBen Hutchings 	EF10_STAT_rx_bad,
3868127d661SBen Hutchings 	EF10_STAT_rx_pause,
3878127d661SBen Hutchings 	EF10_STAT_rx_control,
3888127d661SBen Hutchings 	EF10_STAT_rx_unicast,
3898127d661SBen Hutchings 	EF10_STAT_rx_multicast,
3908127d661SBen Hutchings 	EF10_STAT_rx_broadcast,
3918127d661SBen Hutchings 	EF10_STAT_rx_lt64,
3928127d661SBen Hutchings 	EF10_STAT_rx_64,
3938127d661SBen Hutchings 	EF10_STAT_rx_65_to_127,
3948127d661SBen Hutchings 	EF10_STAT_rx_128_to_255,
3958127d661SBen Hutchings 	EF10_STAT_rx_256_to_511,
3968127d661SBen Hutchings 	EF10_STAT_rx_512_to_1023,
3978127d661SBen Hutchings 	EF10_STAT_rx_1024_to_15xx,
3988127d661SBen Hutchings 	EF10_STAT_rx_15xx_to_jumbo,
3998127d661SBen Hutchings 	EF10_STAT_rx_gtjumbo,
4008127d661SBen Hutchings 	EF10_STAT_rx_bad_gtjumbo,
4018127d661SBen Hutchings 	EF10_STAT_rx_overflow,
4028127d661SBen Hutchings 	EF10_STAT_rx_align_error,
4038127d661SBen Hutchings 	EF10_STAT_rx_length_error,
4048127d661SBen Hutchings 	EF10_STAT_rx_nodesc_drops,
405568d7a00SEdward Cree 	EF10_STAT_rx_pm_trunc_bb_overflow,
406568d7a00SEdward Cree 	EF10_STAT_rx_pm_discard_bb_overflow,
407568d7a00SEdward Cree 	EF10_STAT_rx_pm_trunc_vfifo_full,
408568d7a00SEdward Cree 	EF10_STAT_rx_pm_discard_vfifo_full,
409568d7a00SEdward Cree 	EF10_STAT_rx_pm_trunc_qbb,
410568d7a00SEdward Cree 	EF10_STAT_rx_pm_discard_qbb,
411568d7a00SEdward Cree 	EF10_STAT_rx_pm_discard_mapping,
412568d7a00SEdward Cree 	EF10_STAT_rx_dp_q_disabled_packets,
413568d7a00SEdward Cree 	EF10_STAT_rx_dp_di_dropped_packets,
414568d7a00SEdward Cree 	EF10_STAT_rx_dp_streaming_packets,
41579ac47aeSShradha Shah 	EF10_STAT_rx_dp_hlb_fetch,
41679ac47aeSShradha Shah 	EF10_STAT_rx_dp_hlb_wait,
4178127d661SBen Hutchings 	EF10_STAT_COUNT
4188127d661SBen Hutchings };
4198127d661SBen Hutchings 
420183233beSBen Hutchings /* Maximum number of TX PIO buffers we may allocate to a function.
421183233beSBen Hutchings  * This matches the total number of buffers on each SFC9100-family
422183233beSBen Hutchings  * controller.
423183233beSBen Hutchings  */
424183233beSBen Hutchings #define EF10_TX_PIOBUF_COUNT 16
425183233beSBen Hutchings 
4268127d661SBen Hutchings /**
4278127d661SBen Hutchings  * struct efx_ef10_nic_data - EF10 architecture NIC state
4288127d661SBen Hutchings  * @mcdi_buf: DMA buffer for MCDI
4298127d661SBen Hutchings  * @warm_boot_count: Last seen MC warm boot count
4308127d661SBen Hutchings  * @vi_base: Absolute index of first VI in this function
4318127d661SBen Hutchings  * @n_allocated_vis: Number of VIs allocated to this function
4328127d661SBen Hutchings  * @must_realloc_vis: Flag: VIs have yet to be reallocated after MC reboot
4338127d661SBen Hutchings  * @must_restore_filters: Flag: filters have yet to be restored after MC reboot
434183233beSBen Hutchings  * @n_piobufs: Number of PIO buffers allocated to this function
435183233beSBen Hutchings  * @wc_membase: Base address of write-combining mapping of the memory BAR
436183233beSBen Hutchings  * @pio_write_base: Base address for writing PIO buffers
437183233beSBen Hutchings  * @pio_write_vi_base: Relative VI number for @pio_write_base
438183233beSBen Hutchings  * @piobuf_handle: Handle of each PIO buffer allocated
439183233beSBen Hutchings  * @must_restore_piobufs: Flag: PIO buffers have yet to be restored after MC
440183233beSBen Hutchings  *	reboot
4418127d661SBen Hutchings  * @rx_rss_context: Firmware handle for our RSS context
4428127d661SBen Hutchings  * @stats: Hardware statistics
4438127d661SBen Hutchings  * @workaround_35388: Flag: firmware supports workaround for bug 35388
444a915ccc9SBen Hutchings  * @must_check_datapath_caps: Flag: @datapath_caps needs to be revalidated
445a915ccc9SBen Hutchings  *	after MC reboot
4468127d661SBen Hutchings  * @datapath_caps: Capabilities of datapath firmware (FLAGS1 field of
4478127d661SBen Hutchings  *	%MC_CMD_GET_CAPABILITIES response)
4488127d661SBen Hutchings  */
4498127d661SBen Hutchings struct efx_ef10_nic_data {
4508127d661SBen Hutchings 	struct efx_buffer mcdi_buf;
4518127d661SBen Hutchings 	u16 warm_boot_count;
4528127d661SBen Hutchings 	unsigned int vi_base;
4538127d661SBen Hutchings 	unsigned int n_allocated_vis;
4548127d661SBen Hutchings 	bool must_realloc_vis;
4558127d661SBen Hutchings 	bool must_restore_filters;
456183233beSBen Hutchings 	unsigned int n_piobufs;
457183233beSBen Hutchings 	void __iomem *wc_membase, *pio_write_base;
458183233beSBen Hutchings 	unsigned int pio_write_vi_base;
459183233beSBen Hutchings 	unsigned int piobuf_handle[EF10_TX_PIOBUF_COUNT];
460183233beSBen Hutchings 	bool must_restore_piobufs;
4618127d661SBen Hutchings 	u32 rx_rss_context;
4628127d661SBen Hutchings 	u64 stats[EF10_STAT_COUNT];
4638127d661SBen Hutchings 	bool workaround_35388;
464a915ccc9SBen Hutchings 	bool must_check_datapath_caps;
4658127d661SBen Hutchings 	u32 datapath_caps;
4668127d661SBen Hutchings };
4678127d661SBen Hutchings 
468cd2d5b52SBen Hutchings /*
469cd2d5b52SBen Hutchings  * On the SFC9000 family each port is associated with 1 PCI physical
470cd2d5b52SBen Hutchings  * function (PF) handled by sfc and a configurable number of virtual
471cd2d5b52SBen Hutchings  * functions (VFs) that may be handled by some other driver, often in
472cd2d5b52SBen Hutchings  * a VM guest.  The queue pointer registers are mapped in both PF and
473cd2d5b52SBen Hutchings  * VF BARs such that an 8K region provides access to a single RX, TX
474cd2d5b52SBen Hutchings  * and event queue (collectively a Virtual Interface, VI or VNIC).
475cd2d5b52SBen Hutchings  *
476cd2d5b52SBen Hutchings  * The PF has access to all 1024 VIs while VFs are mapped to VIs
477cd2d5b52SBen Hutchings  * according to VI_BASE and VI_SCALE: VF i has access to VIs numbered
478cd2d5b52SBen Hutchings  * in range [VI_BASE + i << VI_SCALE, VI_BASE + i + 1 << VI_SCALE).
479cd2d5b52SBen Hutchings  * The number of VIs and the VI_SCALE value are configurable but must
480cd2d5b52SBen Hutchings  * be established at boot time by firmware.
481cd2d5b52SBen Hutchings  */
482cd2d5b52SBen Hutchings 
483cd2d5b52SBen Hutchings /* Maximum VI_SCALE parameter supported by Siena */
484cd2d5b52SBen Hutchings #define EFX_VI_SCALE_MAX 6
485cd2d5b52SBen Hutchings /* Base VI to use for SR-IOV. Must be aligned to (1 << EFX_VI_SCALE_MAX),
486cd2d5b52SBen Hutchings  * so this is the smallest allowed value. */
487cd2d5b52SBen Hutchings #define EFX_VI_BASE 128U
488cd2d5b52SBen Hutchings /* Maximum number of VFs allowed */
489cd2d5b52SBen Hutchings #define EFX_VF_COUNT_MAX 127
490cd2d5b52SBen Hutchings /* Limit EVQs on VFs to be only 8k to reduce buffer table reservation */
491cd2d5b52SBen Hutchings #define EFX_MAX_VF_EVQ_SIZE 8192UL
492cd2d5b52SBen Hutchings /* The number of buffer table entries reserved for each VI on a VF */
493cd2d5b52SBen Hutchings #define EFX_VF_BUFTBL_PER_VI					\
494cd2d5b52SBen Hutchings 	((EFX_MAX_VF_EVQ_SIZE + 2 * EFX_MAX_DMAQ_SIZE) *	\
495cd2d5b52SBen Hutchings 	 sizeof(efx_qword_t) / EFX_BUF_SIZE)
496cd2d5b52SBen Hutchings 
497cd2d5b52SBen Hutchings #ifdef CONFIG_SFC_SRIOV
498cd2d5b52SBen Hutchings 
499cd2d5b52SBen Hutchings static inline bool efx_sriov_wanted(struct efx_nic *efx)
500cd2d5b52SBen Hutchings {
501cd2d5b52SBen Hutchings 	return efx->vf_count != 0;
502cd2d5b52SBen Hutchings }
503cd2d5b52SBen Hutchings static inline bool efx_sriov_enabled(struct efx_nic *efx)
504cd2d5b52SBen Hutchings {
505cd2d5b52SBen Hutchings 	return efx->vf_init_count != 0;
506cd2d5b52SBen Hutchings }
507cd2d5b52SBen Hutchings static inline unsigned int efx_vf_size(struct efx_nic *efx)
508cd2d5b52SBen Hutchings {
509cd2d5b52SBen Hutchings 	return 1 << efx->vi_scale;
510cd2d5b52SBen Hutchings }
511cd2d5b52SBen Hutchings 
51200aef986SJoe Perches int efx_init_sriov(void);
51300aef986SJoe Perches void efx_sriov_probe(struct efx_nic *efx);
51400aef986SJoe Perches int efx_sriov_init(struct efx_nic *efx);
51500aef986SJoe Perches void efx_sriov_mac_address_changed(struct efx_nic *efx);
51600aef986SJoe Perches void efx_sriov_tx_flush_done(struct efx_nic *efx, efx_qword_t *event);
51700aef986SJoe Perches void efx_sriov_rx_flush_done(struct efx_nic *efx, efx_qword_t *event);
51800aef986SJoe Perches void efx_sriov_event(struct efx_channel *channel, efx_qword_t *event);
51900aef986SJoe Perches void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq);
52000aef986SJoe Perches void efx_sriov_flr(struct efx_nic *efx, unsigned flr);
52100aef986SJoe Perches void efx_sriov_reset(struct efx_nic *efx);
52200aef986SJoe Perches void efx_sriov_fini(struct efx_nic *efx);
52300aef986SJoe Perches void efx_fini_sriov(void);
524cd2d5b52SBen Hutchings 
525cd2d5b52SBen Hutchings #else
526cd2d5b52SBen Hutchings 
527cd2d5b52SBen Hutchings static inline bool efx_sriov_wanted(struct efx_nic *efx) { return false; }
528cd2d5b52SBen Hutchings static inline bool efx_sriov_enabled(struct efx_nic *efx) { return false; }
529cd2d5b52SBen Hutchings static inline unsigned int efx_vf_size(struct efx_nic *efx) { return 0; }
530cd2d5b52SBen Hutchings 
531cd2d5b52SBen Hutchings static inline int efx_init_sriov(void) { return 0; }
532cd2d5b52SBen Hutchings static inline void efx_sriov_probe(struct efx_nic *efx) {}
533cd2d5b52SBen Hutchings static inline int efx_sriov_init(struct efx_nic *efx) { return -EOPNOTSUPP; }
534cd2d5b52SBen Hutchings static inline void efx_sriov_mac_address_changed(struct efx_nic *efx) {}
535cd2d5b52SBen Hutchings static inline void efx_sriov_tx_flush_done(struct efx_nic *efx,
536cd2d5b52SBen Hutchings 					   efx_qword_t *event) {}
537cd2d5b52SBen Hutchings static inline void efx_sriov_rx_flush_done(struct efx_nic *efx,
538cd2d5b52SBen Hutchings 					   efx_qword_t *event) {}
539cd2d5b52SBen Hutchings static inline void efx_sriov_event(struct efx_channel *channel,
540cd2d5b52SBen Hutchings 				   efx_qword_t *event) {}
541cd2d5b52SBen Hutchings static inline void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq) {}
542cd2d5b52SBen Hutchings static inline void efx_sriov_flr(struct efx_nic *efx, unsigned flr) {}
543cd2d5b52SBen Hutchings static inline void efx_sriov_reset(struct efx_nic *efx) {}
544cd2d5b52SBen Hutchings static inline void efx_sriov_fini(struct efx_nic *efx) {}
545cd2d5b52SBen Hutchings static inline void efx_fini_sriov(void) {}
546cd2d5b52SBen Hutchings 
547cd2d5b52SBen Hutchings #endif
548cd2d5b52SBen Hutchings 
54900aef986SJoe Perches int efx_sriov_set_vf_mac(struct net_device *dev, int vf, u8 *mac);
55000aef986SJoe Perches int efx_sriov_set_vf_vlan(struct net_device *dev, int vf, u16 vlan, u8 qos);
55100aef986SJoe Perches int efx_sriov_get_vf_config(struct net_device *dev, int vf,
552cd2d5b52SBen Hutchings 			    struct ifla_vf_info *ivf);
55300aef986SJoe Perches int efx_sriov_set_vf_spoofchk(struct net_device *net_dev, int vf,
554cd2d5b52SBen Hutchings 			      bool spoofchk);
555cd2d5b52SBen Hutchings 
5567c236c43SStuart Hodgson struct ethtool_ts_info;
557ac36baf8SBen Hutchings int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel);
558ac36baf8SBen Hutchings void efx_ptp_defer_probe_with_channel(struct efx_nic *efx);
559ac36baf8SBen Hutchings void efx_ptp_remove(struct efx_nic *efx);
560433dc9b3SBen Hutchings int efx_ptp_set_ts_config(struct efx_nic *efx, struct ifreq *ifr);
561433dc9b3SBen Hutchings int efx_ptp_get_ts_config(struct efx_nic *efx, struct ifreq *ifr);
56200aef986SJoe Perches void efx_ptp_get_ts_info(struct efx_nic *efx, struct ethtool_ts_info *ts_info);
56300aef986SJoe Perches bool efx_ptp_is_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
5649ec06595SDaniel Pieczko int efx_ptp_get_mode(struct efx_nic *efx);
5659ec06595SDaniel Pieczko int efx_ptp_change_mode(struct efx_nic *efx, bool enable_wanted,
5669ec06595SDaniel Pieczko 			unsigned int new_mode);
56700aef986SJoe Perches int efx_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
56800aef986SJoe Perches void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev);
569bd9a265dSJon Cooper void efx_time_sync_event(struct efx_channel *channel, efx_qword_t *ev);
570bd9a265dSJon Cooper void __efx_rx_skb_attach_timestamp(struct efx_channel *channel,
571bd9a265dSJon Cooper 				   struct sk_buff *skb);
572bd9a265dSJon Cooper static inline void efx_rx_skb_attach_timestamp(struct efx_channel *channel,
573bd9a265dSJon Cooper 					       struct sk_buff *skb)
574bd9a265dSJon Cooper {
575bd9a265dSJon Cooper 	if (channel->sync_events_state == SYNC_EVENTS_VALID)
576bd9a265dSJon Cooper 		__efx_rx_skb_attach_timestamp(channel, skb);
577bd9a265dSJon Cooper }
5782ea4dc28SAlexandre Rames void efx_ptp_start_datapath(struct efx_nic *efx);
5792ea4dc28SAlexandre Rames void efx_ptp_stop_datapath(struct efx_nic *efx);
5807c236c43SStuart Hodgson 
581874aeea5SJeff Kirsher extern const struct efx_nic_type falcon_a1_nic_type;
582874aeea5SJeff Kirsher extern const struct efx_nic_type falcon_b0_nic_type;
583874aeea5SJeff Kirsher extern const struct efx_nic_type siena_a0_nic_type;
5848127d661SBen Hutchings extern const struct efx_nic_type efx_hunt_a0_nic_type;
585874aeea5SJeff Kirsher 
586874aeea5SJeff Kirsher /**************************************************************************
587874aeea5SJeff Kirsher  *
588874aeea5SJeff Kirsher  * Externs
589874aeea5SJeff Kirsher  *
590874aeea5SJeff Kirsher  **************************************************************************
591874aeea5SJeff Kirsher  */
592874aeea5SJeff Kirsher 
59300aef986SJoe Perches int falcon_probe_board(struct efx_nic *efx, u16 revision_info);
594874aeea5SJeff Kirsher 
595874aeea5SJeff Kirsher /* TX data path */
59686094f7fSBen Hutchings static inline int efx_nic_probe_tx(struct efx_tx_queue *tx_queue)
59786094f7fSBen Hutchings {
59886094f7fSBen Hutchings 	return tx_queue->efx->type->tx_probe(tx_queue);
59986094f7fSBen Hutchings }
60086094f7fSBen Hutchings static inline void efx_nic_init_tx(struct efx_tx_queue *tx_queue)
60186094f7fSBen Hutchings {
60286094f7fSBen Hutchings 	tx_queue->efx->type->tx_init(tx_queue);
60386094f7fSBen Hutchings }
60486094f7fSBen Hutchings static inline void efx_nic_remove_tx(struct efx_tx_queue *tx_queue)
60586094f7fSBen Hutchings {
60686094f7fSBen Hutchings 	tx_queue->efx->type->tx_remove(tx_queue);
60786094f7fSBen Hutchings }
60886094f7fSBen Hutchings static inline void efx_nic_push_buffers(struct efx_tx_queue *tx_queue)
60986094f7fSBen Hutchings {
61086094f7fSBen Hutchings 	tx_queue->efx->type->tx_write(tx_queue);
61186094f7fSBen Hutchings }
612874aeea5SJeff Kirsher 
613874aeea5SJeff Kirsher /* RX data path */
61486094f7fSBen Hutchings static inline int efx_nic_probe_rx(struct efx_rx_queue *rx_queue)
61586094f7fSBen Hutchings {
61686094f7fSBen Hutchings 	return rx_queue->efx->type->rx_probe(rx_queue);
61786094f7fSBen Hutchings }
61886094f7fSBen Hutchings static inline void efx_nic_init_rx(struct efx_rx_queue *rx_queue)
61986094f7fSBen Hutchings {
62086094f7fSBen Hutchings 	rx_queue->efx->type->rx_init(rx_queue);
62186094f7fSBen Hutchings }
62286094f7fSBen Hutchings static inline void efx_nic_remove_rx(struct efx_rx_queue *rx_queue)
62386094f7fSBen Hutchings {
62486094f7fSBen Hutchings 	rx_queue->efx->type->rx_remove(rx_queue);
62586094f7fSBen Hutchings }
62686094f7fSBen Hutchings static inline void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue)
62786094f7fSBen Hutchings {
62886094f7fSBen Hutchings 	rx_queue->efx->type->rx_write(rx_queue);
62986094f7fSBen Hutchings }
63086094f7fSBen Hutchings static inline void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue)
63186094f7fSBen Hutchings {
63286094f7fSBen Hutchings 	rx_queue->efx->type->rx_defer_refill(rx_queue);
63386094f7fSBen Hutchings }
634874aeea5SJeff Kirsher 
635874aeea5SJeff Kirsher /* Event data path */
63686094f7fSBen Hutchings static inline int efx_nic_probe_eventq(struct efx_channel *channel)
63786094f7fSBen Hutchings {
63886094f7fSBen Hutchings 	return channel->efx->type->ev_probe(channel);
63986094f7fSBen Hutchings }
640261e4d96SJon Cooper static inline int efx_nic_init_eventq(struct efx_channel *channel)
64186094f7fSBen Hutchings {
642261e4d96SJon Cooper 	return channel->efx->type->ev_init(channel);
64386094f7fSBen Hutchings }
64486094f7fSBen Hutchings static inline void efx_nic_fini_eventq(struct efx_channel *channel)
64586094f7fSBen Hutchings {
64686094f7fSBen Hutchings 	channel->efx->type->ev_fini(channel);
64786094f7fSBen Hutchings }
64886094f7fSBen Hutchings static inline void efx_nic_remove_eventq(struct efx_channel *channel)
64986094f7fSBen Hutchings {
65086094f7fSBen Hutchings 	channel->efx->type->ev_remove(channel);
65186094f7fSBen Hutchings }
65286094f7fSBen Hutchings static inline int
65386094f7fSBen Hutchings efx_nic_process_eventq(struct efx_channel *channel, int quota)
65486094f7fSBen Hutchings {
65586094f7fSBen Hutchings 	return channel->efx->type->ev_process(channel, quota);
65686094f7fSBen Hutchings }
65786094f7fSBen Hutchings static inline void efx_nic_eventq_read_ack(struct efx_channel *channel)
65886094f7fSBen Hutchings {
65986094f7fSBen Hutchings 	channel->efx->type->ev_read_ack(channel);
66086094f7fSBen Hutchings }
66100aef986SJoe Perches void efx_nic_event_test_start(struct efx_channel *channel);
66286094f7fSBen Hutchings 
66386094f7fSBen Hutchings /* Falcon/Siena queue operations */
66400aef986SJoe Perches int efx_farch_tx_probe(struct efx_tx_queue *tx_queue);
66500aef986SJoe Perches void efx_farch_tx_init(struct efx_tx_queue *tx_queue);
66600aef986SJoe Perches void efx_farch_tx_fini(struct efx_tx_queue *tx_queue);
66700aef986SJoe Perches void efx_farch_tx_remove(struct efx_tx_queue *tx_queue);
66800aef986SJoe Perches void efx_farch_tx_write(struct efx_tx_queue *tx_queue);
66900aef986SJoe Perches int efx_farch_rx_probe(struct efx_rx_queue *rx_queue);
67000aef986SJoe Perches void efx_farch_rx_init(struct efx_rx_queue *rx_queue);
67100aef986SJoe Perches void efx_farch_rx_fini(struct efx_rx_queue *rx_queue);
67200aef986SJoe Perches void efx_farch_rx_remove(struct efx_rx_queue *rx_queue);
67300aef986SJoe Perches void efx_farch_rx_write(struct efx_rx_queue *rx_queue);
67400aef986SJoe Perches void efx_farch_rx_defer_refill(struct efx_rx_queue *rx_queue);
67500aef986SJoe Perches int efx_farch_ev_probe(struct efx_channel *channel);
67600aef986SJoe Perches int efx_farch_ev_init(struct efx_channel *channel);
67700aef986SJoe Perches void efx_farch_ev_fini(struct efx_channel *channel);
67800aef986SJoe Perches void efx_farch_ev_remove(struct efx_channel *channel);
67900aef986SJoe Perches int efx_farch_ev_process(struct efx_channel *channel, int quota);
68000aef986SJoe Perches void efx_farch_ev_read_ack(struct efx_channel *channel);
68100aef986SJoe Perches void efx_farch_ev_test_generate(struct efx_channel *channel);
68286094f7fSBen Hutchings 
683add72477SBen Hutchings /* Falcon/Siena filter operations */
68400aef986SJoe Perches int efx_farch_filter_table_probe(struct efx_nic *efx);
68500aef986SJoe Perches void efx_farch_filter_table_restore(struct efx_nic *efx);
68600aef986SJoe Perches void efx_farch_filter_table_remove(struct efx_nic *efx);
68700aef986SJoe Perches void efx_farch_filter_update_rx_scatter(struct efx_nic *efx);
68800aef986SJoe Perches s32 efx_farch_filter_insert(struct efx_nic *efx, struct efx_filter_spec *spec,
68900aef986SJoe Perches 			    bool replace);
69000aef986SJoe Perches int efx_farch_filter_remove_safe(struct efx_nic *efx,
691add72477SBen Hutchings 				 enum efx_filter_priority priority,
692add72477SBen Hutchings 				 u32 filter_id);
69300aef986SJoe Perches int efx_farch_filter_get_safe(struct efx_nic *efx,
69400aef986SJoe Perches 			      enum efx_filter_priority priority, u32 filter_id,
69500aef986SJoe Perches 			      struct efx_filter_spec *);
696fbd79120SBen Hutchings int efx_farch_filter_clear_rx(struct efx_nic *efx,
697add72477SBen Hutchings 			      enum efx_filter_priority priority);
69800aef986SJoe Perches u32 efx_farch_filter_count_rx_used(struct efx_nic *efx,
699add72477SBen Hutchings 				   enum efx_filter_priority priority);
70000aef986SJoe Perches u32 efx_farch_filter_get_rx_id_limit(struct efx_nic *efx);
70100aef986SJoe Perches s32 efx_farch_filter_get_rx_ids(struct efx_nic *efx,
70200aef986SJoe Perches 				enum efx_filter_priority priority, u32 *buf,
70300aef986SJoe Perches 				u32 size);
704add72477SBen Hutchings #ifdef CONFIG_RFS_ACCEL
70500aef986SJoe Perches s32 efx_farch_filter_rfs_insert(struct efx_nic *efx,
706add72477SBen Hutchings 				struct efx_filter_spec *spec);
70700aef986SJoe Perches bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
708add72477SBen Hutchings 				     unsigned int index);
709add72477SBen Hutchings #endif
71000aef986SJoe Perches void efx_farch_filter_sync_rx_mode(struct efx_nic *efx);
711add72477SBen Hutchings 
71200aef986SJoe Perches bool efx_nic_event_present(struct efx_channel *channel);
713874aeea5SJeff Kirsher 
714b7f514afSBen Hutchings /* Some statistics are computed as A - B where A and B each increase
715b7f514afSBen Hutchings  * linearly with some hardware counter(s) and the counters are read
716b7f514afSBen Hutchings  * asynchronously.  If the counters contributing to B are always read
717b7f514afSBen Hutchings  * after those contributing to A, the computed value may be lower than
718b7f514afSBen Hutchings  * the true value by some variable amount, and may decrease between
719b7f514afSBen Hutchings  * subsequent computations.
720b7f514afSBen Hutchings  *
721b7f514afSBen Hutchings  * We should never allow statistics to decrease or to exceed the true
722b7f514afSBen Hutchings  * value.  Since the computed value will never be greater than the
723b7f514afSBen Hutchings  * true value, we can achieve this by only storing the computed value
724b7f514afSBen Hutchings  * when it increases.
725b7f514afSBen Hutchings  */
726b7f514afSBen Hutchings static inline void efx_update_diff_stat(u64 *stat, u64 diff)
727b7f514afSBen Hutchings {
728b7f514afSBen Hutchings 	if ((s64)(diff - *stat) > 0)
729b7f514afSBen Hutchings 		*stat = diff;
730b7f514afSBen Hutchings }
731b7f514afSBen Hutchings 
73286094f7fSBen Hutchings /* Interrupts */
73300aef986SJoe Perches int efx_nic_init_interrupt(struct efx_nic *efx);
73400aef986SJoe Perches void efx_nic_irq_test_start(struct efx_nic *efx);
73500aef986SJoe Perches void efx_nic_fini_interrupt(struct efx_nic *efx);
73686094f7fSBen Hutchings 
73786094f7fSBen Hutchings /* Falcon/Siena interrupts */
73800aef986SJoe Perches void efx_farch_irq_enable_master(struct efx_nic *efx);
73900aef986SJoe Perches void efx_farch_irq_test_generate(struct efx_nic *efx);
74000aef986SJoe Perches void efx_farch_irq_disable_master(struct efx_nic *efx);
74100aef986SJoe Perches irqreturn_t efx_farch_msi_interrupt(int irq, void *dev_id);
74200aef986SJoe Perches irqreturn_t efx_farch_legacy_interrupt(int irq, void *dev_id);
74300aef986SJoe Perches irqreturn_t efx_farch_fatal_interrupt(struct efx_nic *efx);
744874aeea5SJeff Kirsher 
745eee6f6a9SBen Hutchings static inline int efx_nic_event_test_irq_cpu(struct efx_channel *channel)
746eee6f6a9SBen Hutchings {
747dd40781eSBen Hutchings 	return ACCESS_ONCE(channel->event_test_cpu);
748eee6f6a9SBen Hutchings }
749eee6f6a9SBen Hutchings static inline int efx_nic_irq_test_irq_cpu(struct efx_nic *efx)
750eee6f6a9SBen Hutchings {
751eee6f6a9SBen Hutchings 	return ACCESS_ONCE(efx->last_irq_cpu);
752eee6f6a9SBen Hutchings }
753eee6f6a9SBen Hutchings 
754874aeea5SJeff Kirsher /* Global Resources */
75500aef986SJoe Perches int efx_nic_flush_queues(struct efx_nic *efx);
75600aef986SJoe Perches void siena_prepare_flush(struct efx_nic *efx);
75700aef986SJoe Perches int efx_farch_fini_dmaq(struct efx_nic *efx);
75800aef986SJoe Perches void siena_finish_flush(struct efx_nic *efx);
75900aef986SJoe Perches void falcon_start_nic_stats(struct efx_nic *efx);
76000aef986SJoe Perches void falcon_stop_nic_stats(struct efx_nic *efx);
76100aef986SJoe Perches int falcon_reset_xaui(struct efx_nic *efx);
76200aef986SJoe Perches void efx_farch_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw);
76300aef986SJoe Perches void efx_farch_init_common(struct efx_nic *efx);
76400aef986SJoe Perches void efx_ef10_handle_drain_event(struct efx_nic *efx);
76500aef986SJoe Perches void efx_farch_rx_push_indir_table(struct efx_nic *efx);
766874aeea5SJeff Kirsher 
767874aeea5SJeff Kirsher int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
7680d19a540SBen Hutchings 			 unsigned int len, gfp_t gfp_flags);
769874aeea5SJeff Kirsher void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer);
770874aeea5SJeff Kirsher 
771874aeea5SJeff Kirsher /* Tests */
77286094f7fSBen Hutchings struct efx_farch_register_test {
773874aeea5SJeff Kirsher 	unsigned address;
774874aeea5SJeff Kirsher 	efx_oword_t mask;
775874aeea5SJeff Kirsher };
77600aef986SJoe Perches int efx_farch_test_registers(struct efx_nic *efx,
77786094f7fSBen Hutchings 			     const struct efx_farch_register_test *regs,
778874aeea5SJeff Kirsher 			     size_t n_regs);
779874aeea5SJeff Kirsher 
78000aef986SJoe Perches size_t efx_nic_get_regs_len(struct efx_nic *efx);
78100aef986SJoe Perches void efx_nic_get_regs(struct efx_nic *efx, void *buf);
782874aeea5SJeff Kirsher 
78300aef986SJoe Perches size_t efx_nic_describe_stats(const struct efx_hw_stat_desc *desc, size_t count,
784cd0ecc9aSBen Hutchings 			      const unsigned long *mask, u8 *names);
78500aef986SJoe Perches void efx_nic_update_stats(const struct efx_hw_stat_desc *desc, size_t count,
78600aef986SJoe Perches 			  const unsigned long *mask, u64 *stats,
78700aef986SJoe Perches 			  const void *dma_buf, bool accumulate);
788f8f3b5aeSJon Cooper void efx_nic_fix_nodesc_drop_stat(struct efx_nic *efx, u64 *stat);
789cd0ecc9aSBen Hutchings 
790ab0115fcSBen Hutchings #define EFX_MAX_FLUSH_TIME 5000
791874aeea5SJeff Kirsher 
79200aef986SJoe Perches void efx_farch_generate_event(struct efx_nic *efx, unsigned int evq,
793874aeea5SJeff Kirsher 			      efx_qword_t *event);
794874aeea5SJeff Kirsher 
795874aeea5SJeff Kirsher #endif /* EFX_NIC_H */
796