xref: /openbmc/linux/drivers/net/ethernet/sfc/nic.h (revision e80ca013)
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 
7470b33fb0SEdward Cree /* Get partner of a TX queue, seen as part of the same net core queue */
7570b33fb0SEdward Cree static struct efx_tx_queue *efx_tx_queue_partner(struct efx_tx_queue *tx_queue)
7670b33fb0SEdward Cree {
7770b33fb0SEdward Cree 	if (tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD)
7870b33fb0SEdward Cree 		return tx_queue - EFX_TXQ_TYPE_OFFLOAD;
7970b33fb0SEdward Cree 	else
8070b33fb0SEdward Cree 		return tx_queue + EFX_TXQ_TYPE_OFFLOAD;
8170b33fb0SEdward Cree }
8270b33fb0SEdward Cree 
8370b33fb0SEdward Cree /* Report whether this TX queue would be empty for the given write_count.
8470b33fb0SEdward Cree  * May return false negative.
85306a2782SBen Hutchings  */
86306a2782SBen Hutchings static inline bool __efx_nic_tx_is_empty(struct efx_tx_queue *tx_queue,
87306a2782SBen Hutchings 					 unsigned int write_count)
88306a2782SBen Hutchings {
89306a2782SBen Hutchings 	unsigned int empty_read_count = ACCESS_ONCE(tx_queue->empty_read_count);
90306a2782SBen Hutchings 
91306a2782SBen Hutchings 	if (empty_read_count == 0)
92306a2782SBen Hutchings 		return false;
93306a2782SBen Hutchings 
94306a2782SBen Hutchings 	return ((empty_read_count ^ write_count) & ~EFX_EMPTY_COUNT_VALID) == 0;
95306a2782SBen Hutchings }
96306a2782SBen Hutchings 
9770b33fb0SEdward Cree /* Decide whether we can use TX PIO, ie. write packet data directly into
9870b33fb0SEdward Cree  * a buffer on the device.  This can reduce latency at the expense of
9970b33fb0SEdward Cree  * throughput, so we only do this if both hardware and software TX rings
10070b33fb0SEdward Cree  * are empty.  This also ensures that only one packet at a time can be
10170b33fb0SEdward Cree  * using the PIO buffer.
10270b33fb0SEdward Cree  */
10370b33fb0SEdward Cree static inline bool efx_nic_may_tx_pio(struct efx_tx_queue *tx_queue)
104306a2782SBen Hutchings {
10570b33fb0SEdward Cree 	struct efx_tx_queue *partner = efx_tx_queue_partner(tx_queue);
10670b33fb0SEdward Cree 	return tx_queue->piobuf &&
10770b33fb0SEdward Cree 	       __efx_nic_tx_is_empty(tx_queue, tx_queue->insert_count) &&
10870b33fb0SEdward Cree 	       __efx_nic_tx_is_empty(partner, partner->insert_count);
109306a2782SBen Hutchings }
110306a2782SBen Hutchings 
11186094f7fSBen Hutchings /* Decide whether to push a TX descriptor to the NIC vs merely writing
11286094f7fSBen Hutchings  * the doorbell.  This can reduce latency when we are adding a single
11386094f7fSBen Hutchings  * descriptor to an empty queue, but is otherwise pointless.  Further,
11486094f7fSBen Hutchings  * Falcon and Siena have hardware bugs (SF bug 33851) that may be
11586094f7fSBen Hutchings  * triggered if we don't check this.
11670b33fb0SEdward Cree  * We use the write_count used for the last doorbell push, to get the
11770b33fb0SEdward Cree  * NIC's view of the tx queue.
11886094f7fSBen Hutchings  */
11986094f7fSBen Hutchings static inline bool efx_nic_may_push_tx_desc(struct efx_tx_queue *tx_queue,
12086094f7fSBen Hutchings 					    unsigned int write_count)
12186094f7fSBen Hutchings {
122306a2782SBen Hutchings 	bool was_empty = __efx_nic_tx_is_empty(tx_queue, write_count);
12386094f7fSBen Hutchings 
12486094f7fSBen Hutchings 	tx_queue->empty_read_count = 0;
125306a2782SBen Hutchings 	return was_empty && tx_queue->write_count - write_count == 1;
12686094f7fSBen Hutchings }
12786094f7fSBen Hutchings 
12886094f7fSBen Hutchings /* Returns a pointer to the specified descriptor in the RX descriptor queue */
12986094f7fSBen Hutchings static inline efx_qword_t *
13086094f7fSBen Hutchings efx_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
13186094f7fSBen Hutchings {
13286094f7fSBen Hutchings 	return ((efx_qword_t *) (rx_queue->rxd.buf.addr)) + index;
13386094f7fSBen Hutchings }
13486094f7fSBen Hutchings 
135874aeea5SJeff Kirsher enum {
136874aeea5SJeff Kirsher 	PHY_TYPE_NONE = 0,
137874aeea5SJeff Kirsher 	PHY_TYPE_TXC43128 = 1,
138874aeea5SJeff Kirsher 	PHY_TYPE_88E1111 = 2,
139874aeea5SJeff Kirsher 	PHY_TYPE_SFX7101 = 3,
140874aeea5SJeff Kirsher 	PHY_TYPE_QT2022C2 = 4,
141874aeea5SJeff Kirsher 	PHY_TYPE_PM8358 = 6,
142874aeea5SJeff Kirsher 	PHY_TYPE_SFT9001A = 8,
143874aeea5SJeff Kirsher 	PHY_TYPE_QT2025C = 9,
144874aeea5SJeff Kirsher 	PHY_TYPE_SFT9001B = 10,
145874aeea5SJeff Kirsher };
146874aeea5SJeff Kirsher 
147874aeea5SJeff Kirsher #define FALCON_XMAC_LOOPBACKS			\
148874aeea5SJeff Kirsher 	((1 << LOOPBACK_XGMII) |		\
149874aeea5SJeff Kirsher 	 (1 << LOOPBACK_XGXS) |			\
150874aeea5SJeff Kirsher 	 (1 << LOOPBACK_XAUI))
151874aeea5SJeff Kirsher 
1525b6262d0SBen Hutchings /* Alignment of PCIe DMA boundaries (4KB) */
1535b6262d0SBen Hutchings #define EFX_PAGE_SIZE	4096
1545b6262d0SBen Hutchings /* Size and alignment of buffer table entries (same) */
1555b6262d0SBen Hutchings #define EFX_BUF_SIZE	EFX_PAGE_SIZE
1565b6262d0SBen Hutchings 
157e4d112e4SEdward Cree /* NIC-generic software stats */
158e4d112e4SEdward Cree enum {
159e4d112e4SEdward Cree 	GENERIC_STAT_rx_noskb_drops,
160e4d112e4SEdward Cree 	GENERIC_STAT_rx_nodesc_trunc,
161e4d112e4SEdward Cree 	GENERIC_STAT_COUNT
162e4d112e4SEdward Cree };
163e4d112e4SEdward Cree 
164874aeea5SJeff Kirsher /**
165874aeea5SJeff Kirsher  * struct falcon_board_type - board operations and type information
166874aeea5SJeff Kirsher  * @id: Board type id, as found in NVRAM
167874aeea5SJeff Kirsher  * @init: Allocate resources and initialise peripheral hardware
168874aeea5SJeff Kirsher  * @init_phy: Do board-specific PHY initialisation
169874aeea5SJeff Kirsher  * @fini: Shut down hardware and free resources
170874aeea5SJeff Kirsher  * @set_id_led: Set state of identifying LED or revert to automatic function
171874aeea5SJeff Kirsher  * @monitor: Board-specific health check function
172874aeea5SJeff Kirsher  */
173874aeea5SJeff Kirsher struct falcon_board_type {
174874aeea5SJeff Kirsher 	u8 id;
175874aeea5SJeff Kirsher 	int (*init) (struct efx_nic *nic);
176874aeea5SJeff Kirsher 	void (*init_phy) (struct efx_nic *efx);
177874aeea5SJeff Kirsher 	void (*fini) (struct efx_nic *nic);
178874aeea5SJeff Kirsher 	void (*set_id_led) (struct efx_nic *efx, enum efx_led_mode mode);
179874aeea5SJeff Kirsher 	int (*monitor) (struct efx_nic *nic);
180874aeea5SJeff Kirsher };
181874aeea5SJeff Kirsher 
182874aeea5SJeff Kirsher /**
183874aeea5SJeff Kirsher  * struct falcon_board - board information
184874aeea5SJeff Kirsher  * @type: Type of board
185874aeea5SJeff Kirsher  * @major: Major rev. ('A', 'B' ...)
186874aeea5SJeff Kirsher  * @minor: Minor rev. (0, 1, ...)
187874aeea5SJeff Kirsher  * @i2c_adap: I2C adapter for on-board peripherals
188874aeea5SJeff Kirsher  * @i2c_data: Data for bit-banging algorithm
189874aeea5SJeff Kirsher  * @hwmon_client: I2C client for hardware monitor
190874aeea5SJeff Kirsher  * @ioexp_client: I2C client for power/port control
191874aeea5SJeff Kirsher  */
192874aeea5SJeff Kirsher struct falcon_board {
193874aeea5SJeff Kirsher 	const struct falcon_board_type *type;
194874aeea5SJeff Kirsher 	int major;
195874aeea5SJeff Kirsher 	int minor;
196874aeea5SJeff Kirsher 	struct i2c_adapter i2c_adap;
197874aeea5SJeff Kirsher 	struct i2c_algo_bit_data i2c_data;
198874aeea5SJeff Kirsher 	struct i2c_client *hwmon_client, *ioexp_client;
199874aeea5SJeff Kirsher };
200874aeea5SJeff Kirsher 
201874aeea5SJeff Kirsher /**
20245a3fd55SBen Hutchings  * struct falcon_spi_device - a Falcon SPI (Serial Peripheral Interface) device
20345a3fd55SBen Hutchings  * @device_id:		Controller's id for the device
20445a3fd55SBen Hutchings  * @size:		Size (in bytes)
20545a3fd55SBen Hutchings  * @addr_len:		Number of address bytes in read/write commands
20645a3fd55SBen Hutchings  * @munge_address:	Flag whether addresses should be munged.
20745a3fd55SBen Hutchings  *	Some devices with 9-bit addresses (e.g. AT25040A EEPROM)
20845a3fd55SBen Hutchings  *	use bit 3 of the command byte as address bit A8, rather
20945a3fd55SBen Hutchings  *	than having a two-byte address.  If this flag is set, then
21045a3fd55SBen Hutchings  *	commands should be munged in this way.
21145a3fd55SBen Hutchings  * @erase_command:	Erase command (or 0 if sector erase not needed).
21245a3fd55SBen Hutchings  * @erase_size:		Erase sector size (in bytes)
21345a3fd55SBen Hutchings  *	Erase commands affect sectors with this size and alignment.
21445a3fd55SBen Hutchings  *	This must be a power of two.
21545a3fd55SBen Hutchings  * @block_size:		Write block size (in bytes).
21645a3fd55SBen Hutchings  *	Write commands are limited to blocks with this size and alignment.
21745a3fd55SBen Hutchings  */
21845a3fd55SBen Hutchings struct falcon_spi_device {
21945a3fd55SBen Hutchings 	int device_id;
22045a3fd55SBen Hutchings 	unsigned int size;
22145a3fd55SBen Hutchings 	unsigned int addr_len;
22245a3fd55SBen Hutchings 	unsigned int munge_address:1;
22345a3fd55SBen Hutchings 	u8 erase_command;
22445a3fd55SBen Hutchings 	unsigned int erase_size;
22545a3fd55SBen Hutchings 	unsigned int block_size;
22645a3fd55SBen Hutchings };
22745a3fd55SBen Hutchings 
22845a3fd55SBen Hutchings static inline bool falcon_spi_present(const struct falcon_spi_device *spi)
22945a3fd55SBen Hutchings {
23045a3fd55SBen Hutchings 	return spi->size != 0;
23145a3fd55SBen Hutchings }
23245a3fd55SBen Hutchings 
233cd0ecc9aSBen Hutchings enum {
234e4d112e4SEdward Cree 	FALCON_STAT_tx_bytes = GENERIC_STAT_COUNT,
235cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_packets,
236cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_pause,
237cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_control,
238cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_unicast,
239cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_multicast,
240cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_broadcast,
241cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_lt64,
242cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_64,
243cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_65_to_127,
244cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_128_to_255,
245cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_256_to_511,
246cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_512_to_1023,
247cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_1024_to_15xx,
248cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_15xx_to_jumbo,
249cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_gtjumbo,
250cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_non_tcpudp,
251cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_mac_src_error,
252cd0ecc9aSBen Hutchings 	FALCON_STAT_tx_ip_src_error,
253cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_bytes,
254cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_good_bytes,
255cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_bad_bytes,
256cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_packets,
257cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_good,
258cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_bad,
259cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_pause,
260cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_control,
261cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_unicast,
262cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_multicast,
263cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_broadcast,
264cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_lt64,
265cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_64,
266cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_65_to_127,
267cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_128_to_255,
268cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_256_to_511,
269cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_512_to_1023,
270cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_1024_to_15xx,
271cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_15xx_to_jumbo,
272cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_gtjumbo,
273cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_bad_lt64,
274cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_bad_gtjumbo,
275cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_overflow,
276cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_symbol_error,
277cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_align_error,
278cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_length_error,
279cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_internal_error,
280cd0ecc9aSBen Hutchings 	FALCON_STAT_rx_nodesc_drop_cnt,
281cd0ecc9aSBen Hutchings 	FALCON_STAT_COUNT
282cd0ecc9aSBen Hutchings };
283cd0ecc9aSBen Hutchings 
28445a3fd55SBen Hutchings /**
285874aeea5SJeff Kirsher  * struct falcon_nic_data - Falcon NIC state
286874aeea5SJeff Kirsher  * @pci_dev2: Secondary function of Falcon A
287874aeea5SJeff Kirsher  * @board: Board state and functions
288cd0ecc9aSBen Hutchings  * @stats: Hardware statistics
289874aeea5SJeff Kirsher  * @stats_disable_count: Nest count for disabling statistics fetches
290874aeea5SJeff Kirsher  * @stats_pending: Is there a pending DMA of MAC statistics.
291874aeea5SJeff Kirsher  * @stats_timer: A timer for regularly fetching MAC statistics.
292874aeea5SJeff Kirsher  * @spi_flash: SPI flash device
293874aeea5SJeff Kirsher  * @spi_eeprom: SPI EEPROM device
294874aeea5SJeff Kirsher  * @spi_lock: SPI bus lock
295874aeea5SJeff Kirsher  * @mdio_lock: MDIO bus lock
296874aeea5SJeff Kirsher  * @xmac_poll_required: XMAC link state needs polling
297874aeea5SJeff Kirsher  */
298874aeea5SJeff Kirsher struct falcon_nic_data {
299874aeea5SJeff Kirsher 	struct pci_dev *pci_dev2;
300874aeea5SJeff Kirsher 	struct falcon_board board;
301cd0ecc9aSBen Hutchings 	u64 stats[FALCON_STAT_COUNT];
302874aeea5SJeff Kirsher 	unsigned int stats_disable_count;
303874aeea5SJeff Kirsher 	bool stats_pending;
304874aeea5SJeff Kirsher 	struct timer_list stats_timer;
305ecd0a6f0SBen Hutchings 	struct falcon_spi_device spi_flash;
306ecd0a6f0SBen Hutchings 	struct falcon_spi_device spi_eeprom;
307874aeea5SJeff Kirsher 	struct mutex spi_lock;
308874aeea5SJeff Kirsher 	struct mutex mdio_lock;
309874aeea5SJeff Kirsher 	bool xmac_poll_required;
310874aeea5SJeff Kirsher };
311874aeea5SJeff Kirsher 
312874aeea5SJeff Kirsher static inline struct falcon_board *falcon_board(struct efx_nic *efx)
313874aeea5SJeff Kirsher {
314874aeea5SJeff Kirsher 	struct falcon_nic_data *data = efx->nic_data;
315874aeea5SJeff Kirsher 	return &data->board;
316874aeea5SJeff Kirsher }
317874aeea5SJeff Kirsher 
318cd0ecc9aSBen Hutchings enum {
319e4d112e4SEdward Cree 	SIENA_STAT_tx_bytes = GENERIC_STAT_COUNT,
320cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_good_bytes,
321cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_bad_bytes,
322cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_packets,
323cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_bad,
324cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_pause,
325cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_control,
326cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_unicast,
327cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_multicast,
328cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_broadcast,
329cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_lt64,
330cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_64,
331cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_65_to_127,
332cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_128_to_255,
333cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_256_to_511,
334cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_512_to_1023,
335cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_1024_to_15xx,
336cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_15xx_to_jumbo,
337cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_gtjumbo,
338cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_collision,
339cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_single_collision,
340cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_multiple_collision,
341cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_excessive_collision,
342cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_deferred,
343cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_late_collision,
344cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_excessive_deferred,
345cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_non_tcpudp,
346cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_mac_src_error,
347cd0ecc9aSBen Hutchings 	SIENA_STAT_tx_ip_src_error,
348cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_bytes,
349cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_good_bytes,
350cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_bad_bytes,
351cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_packets,
352cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_good,
353cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_bad,
354cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_pause,
355cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_control,
356cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_unicast,
357cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_multicast,
358cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_broadcast,
359cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_lt64,
360cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_64,
361cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_65_to_127,
362cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_128_to_255,
363cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_256_to_511,
364cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_512_to_1023,
365cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_1024_to_15xx,
366cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_15xx_to_jumbo,
367cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_gtjumbo,
368cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_bad_gtjumbo,
369cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_overflow,
370cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_false_carrier,
371cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_symbol_error,
372cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_align_error,
373cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_length_error,
374cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_internal_error,
375cd0ecc9aSBen Hutchings 	SIENA_STAT_rx_nodesc_drop_cnt,
376cd0ecc9aSBen Hutchings 	SIENA_STAT_COUNT
377cd0ecc9aSBen Hutchings };
378cd0ecc9aSBen Hutchings 
379874aeea5SJeff Kirsher /**
380874aeea5SJeff Kirsher  * struct siena_nic_data - Siena NIC state
3812dc313ecSShradha Shah  * @efx: Pointer back to main interface structure
382874aeea5SJeff Kirsher  * @wol_filter_id: Wake-on-LAN packet filter id
383cd0ecc9aSBen Hutchings  * @stats: Hardware statistics
384bf3d0156SDaniel Pieczko  * @vf: Array of &struct siena_vf objects
3852dc313ecSShradha Shah  * @vf_buftbl_base: The zeroth buffer table index used to back VF queues.
3862dc313ecSShradha Shah  * @vfdi_status: Common VFDI status page to be dmad to VF address space.
3872dc313ecSShradha Shah  * @local_addr_list: List of local addresses. Protected by %local_lock.
3882dc313ecSShradha Shah  * @local_page_list: List of DMA addressable pages used to broadcast
3892dc313ecSShradha Shah  *	%local_addr_list. Protected by %local_lock.
3902dc313ecSShradha Shah  * @local_lock: Mutex protecting %local_addr_list and %local_page_list.
3912dc313ecSShradha Shah  * @peer_work: Work item to broadcast peer addresses to VMs.
392874aeea5SJeff Kirsher  */
393874aeea5SJeff Kirsher struct siena_nic_data {
3942dc313ecSShradha Shah 	struct efx_nic *efx;
395874aeea5SJeff Kirsher 	int wol_filter_id;
396cd0ecc9aSBen Hutchings 	u64 stats[SIENA_STAT_COUNT];
3972dc313ecSShradha Shah #ifdef CONFIG_SFC_SRIOV
398bf3d0156SDaniel Pieczko 	struct siena_vf *vf;
3992dc313ecSShradha Shah 	struct efx_channel *vfdi_channel;
4002dc313ecSShradha Shah 	unsigned vf_buftbl_base;
4012dc313ecSShradha Shah 	struct efx_buffer vfdi_status;
4022dc313ecSShradha Shah 	struct list_head local_addr_list;
4032dc313ecSShradha Shah 	struct list_head local_page_list;
4042dc313ecSShradha Shah 	struct mutex local_lock;
4052dc313ecSShradha Shah 	struct work_struct peer_work;
4062dc313ecSShradha Shah #endif
407874aeea5SJeff Kirsher };
408874aeea5SJeff Kirsher 
4098127d661SBen Hutchings enum {
410e80ca013SDaniel Pieczko 	EF10_STAT_port_tx_bytes = GENERIC_STAT_COUNT,
411e80ca013SDaniel Pieczko 	EF10_STAT_port_tx_packets,
412e80ca013SDaniel Pieczko 	EF10_STAT_port_tx_pause,
413e80ca013SDaniel Pieczko 	EF10_STAT_port_tx_control,
414e80ca013SDaniel Pieczko 	EF10_STAT_port_tx_unicast,
415e80ca013SDaniel Pieczko 	EF10_STAT_port_tx_multicast,
416e80ca013SDaniel Pieczko 	EF10_STAT_port_tx_broadcast,
417e80ca013SDaniel Pieczko 	EF10_STAT_port_tx_lt64,
418e80ca013SDaniel Pieczko 	EF10_STAT_port_tx_64,
419e80ca013SDaniel Pieczko 	EF10_STAT_port_tx_65_to_127,
420e80ca013SDaniel Pieczko 	EF10_STAT_port_tx_128_to_255,
421e80ca013SDaniel Pieczko 	EF10_STAT_port_tx_256_to_511,
422e80ca013SDaniel Pieczko 	EF10_STAT_port_tx_512_to_1023,
423e80ca013SDaniel Pieczko 	EF10_STAT_port_tx_1024_to_15xx,
424e80ca013SDaniel Pieczko 	EF10_STAT_port_tx_15xx_to_jumbo,
425e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_bytes,
426e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_bytes_minus_good_bytes,
427e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_good_bytes,
428e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_bad_bytes,
429e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_packets,
430e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_good,
431e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_bad,
432e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_pause,
433e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_control,
434e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_unicast,
435e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_multicast,
436e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_broadcast,
437e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_lt64,
438e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_64,
439e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_65_to_127,
440e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_128_to_255,
441e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_256_to_511,
442e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_512_to_1023,
443e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_1024_to_15xx,
444e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_15xx_to_jumbo,
445e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_gtjumbo,
446e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_bad_gtjumbo,
447e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_overflow,
448e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_align_error,
449e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_length_error,
450e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_nodesc_drops,
451e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_pm_trunc_bb_overflow,
452e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_pm_discard_bb_overflow,
453e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_pm_trunc_vfifo_full,
454e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_pm_discard_vfifo_full,
455e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_pm_trunc_qbb,
456e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_pm_discard_qbb,
457e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_pm_discard_mapping,
458e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_dp_q_disabled_packets,
459e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_dp_di_dropped_packets,
460e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_dp_streaming_packets,
461e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_dp_hlb_fetch,
462e80ca013SDaniel Pieczko 	EF10_STAT_port_rx_dp_hlb_wait,
4638127d661SBen Hutchings 	EF10_STAT_COUNT
4648127d661SBen Hutchings };
4658127d661SBen Hutchings 
466183233beSBen Hutchings /* Maximum number of TX PIO buffers we may allocate to a function.
467183233beSBen Hutchings  * This matches the total number of buffers on each SFC9100-family
468183233beSBen Hutchings  * controller.
469183233beSBen Hutchings  */
470183233beSBen Hutchings #define EF10_TX_PIOBUF_COUNT 16
471183233beSBen Hutchings 
4728127d661SBen Hutchings /**
4738127d661SBen Hutchings  * struct efx_ef10_nic_data - EF10 architecture NIC state
4748127d661SBen Hutchings  * @mcdi_buf: DMA buffer for MCDI
4758127d661SBen Hutchings  * @warm_boot_count: Last seen MC warm boot count
4768127d661SBen Hutchings  * @vi_base: Absolute index of first VI in this function
4778127d661SBen Hutchings  * @n_allocated_vis: Number of VIs allocated to this function
4788127d661SBen Hutchings  * @must_realloc_vis: Flag: VIs have yet to be reallocated after MC reboot
4798127d661SBen Hutchings  * @must_restore_filters: Flag: filters have yet to be restored after MC reboot
480183233beSBen Hutchings  * @n_piobufs: Number of PIO buffers allocated to this function
481183233beSBen Hutchings  * @wc_membase: Base address of write-combining mapping of the memory BAR
482183233beSBen Hutchings  * @pio_write_base: Base address for writing PIO buffers
483183233beSBen Hutchings  * @pio_write_vi_base: Relative VI number for @pio_write_base
484183233beSBen Hutchings  * @piobuf_handle: Handle of each PIO buffer allocated
485183233beSBen Hutchings  * @must_restore_piobufs: Flag: PIO buffers have yet to be restored after MC
486183233beSBen Hutchings  *	reboot
4878127d661SBen Hutchings  * @rx_rss_context: Firmware handle for our RSS context
488267c0157SJon Cooper  * @rx_rss_context_exclusive: Whether our RSS context is exclusive or shared
4898127d661SBen Hutchings  * @stats: Hardware statistics
4908127d661SBen Hutchings  * @workaround_35388: Flag: firmware supports workaround for bug 35388
491a915ccc9SBen Hutchings  * @must_check_datapath_caps: Flag: @datapath_caps needs to be revalidated
492a915ccc9SBen Hutchings  *	after MC reboot
4938127d661SBen Hutchings  * @datapath_caps: Capabilities of datapath firmware (FLAGS1 field of
4948127d661SBen Hutchings  *	%MC_CMD_GET_CAPABILITIES response)
4958d9f9dd4SDaniel Pieczko  * @rx_dpcpu_fw_id: Firmware ID of the RxDPCPU
4968d9f9dd4SDaniel Pieczko  * @tx_dpcpu_fw_id: Firmware ID of the TxDPCPU
49745b2449eSDaniel Pieczko  * @vport_id: The function's vport ID, only relevant for PFs
4986d8aaaf6SDaniel Pieczko  * @must_probe_vswitching: Flag: vswitching has yet to be setup after MC reboot
4991cd9ecbbSDaniel Pieczko  * @pf_index: The number for this PF, or the parent PF if this is a VF
5003c5eb876SShradha Shah #ifdef CONFIG_SFC_SRIOV
5013c5eb876SShradha Shah  * @vf: Pointer to VF data structure
5023c5eb876SShradha Shah #endif
5038127d661SBen Hutchings  */
5048127d661SBen Hutchings struct efx_ef10_nic_data {
5058127d661SBen Hutchings 	struct efx_buffer mcdi_buf;
5068127d661SBen Hutchings 	u16 warm_boot_count;
5078127d661SBen Hutchings 	unsigned int vi_base;
5088127d661SBen Hutchings 	unsigned int n_allocated_vis;
5098127d661SBen Hutchings 	bool must_realloc_vis;
5108127d661SBen Hutchings 	bool must_restore_filters;
511183233beSBen Hutchings 	unsigned int n_piobufs;
512183233beSBen Hutchings 	void __iomem *wc_membase, *pio_write_base;
513183233beSBen Hutchings 	unsigned int pio_write_vi_base;
514183233beSBen Hutchings 	unsigned int piobuf_handle[EF10_TX_PIOBUF_COUNT];
515183233beSBen Hutchings 	bool must_restore_piobufs;
5168127d661SBen Hutchings 	u32 rx_rss_context;
517267c0157SJon Cooper 	bool rx_rss_context_exclusive;
5188127d661SBen Hutchings 	u64 stats[EF10_STAT_COUNT];
5198127d661SBen Hutchings 	bool workaround_35388;
520a915ccc9SBen Hutchings 	bool must_check_datapath_caps;
5218127d661SBen Hutchings 	u32 datapath_caps;
5228d9f9dd4SDaniel Pieczko 	unsigned int rx_dpcpu_fw_id;
5238d9f9dd4SDaniel Pieczko 	unsigned int tx_dpcpu_fw_id;
52445b2449eSDaniel Pieczko 	unsigned int vport_id;
5256d8aaaf6SDaniel Pieczko 	bool must_probe_vswitching;
5261cd9ecbbSDaniel Pieczko 	unsigned int pf_index;
5271d051e00SShradha Shah 	u8 port_id[ETH_ALEN];
5283c5eb876SShradha Shah #ifdef CONFIG_SFC_SRIOV
52988a37de6SShradha Shah 	unsigned int vf_index;
5303c5eb876SShradha Shah 	struct ef10_vf *vf;
5313c5eb876SShradha Shah #endif
5323c5eb876SShradha Shah 	u8 vport_mac[ETH_ALEN];
5338127d661SBen Hutchings };
5348127d661SBen Hutchings 
53500aef986SJoe Perches int efx_init_sriov(void);
53600aef986SJoe Perches void efx_fini_sriov(void);
537cd2d5b52SBen Hutchings 
5387c236c43SStuart Hodgson struct ethtool_ts_info;
539ac36baf8SBen Hutchings int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel);
540ac36baf8SBen Hutchings void efx_ptp_defer_probe_with_channel(struct efx_nic *efx);
541ac36baf8SBen Hutchings void efx_ptp_remove(struct efx_nic *efx);
542433dc9b3SBen Hutchings int efx_ptp_set_ts_config(struct efx_nic *efx, struct ifreq *ifr);
543433dc9b3SBen Hutchings int efx_ptp_get_ts_config(struct efx_nic *efx, struct ifreq *ifr);
54400aef986SJoe Perches void efx_ptp_get_ts_info(struct efx_nic *efx, struct ethtool_ts_info *ts_info);
54500aef986SJoe Perches bool efx_ptp_is_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
5469ec06595SDaniel Pieczko int efx_ptp_get_mode(struct efx_nic *efx);
5479ec06595SDaniel Pieczko int efx_ptp_change_mode(struct efx_nic *efx, bool enable_wanted,
5489ec06595SDaniel Pieczko 			unsigned int new_mode);
54900aef986SJoe Perches int efx_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
55000aef986SJoe Perches void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev);
55199691c4aSBen Hutchings size_t efx_ptp_describe_stats(struct efx_nic *efx, u8 *strings);
55299691c4aSBen Hutchings size_t efx_ptp_update_stats(struct efx_nic *efx, u64 *stats);
553bd9a265dSJon Cooper void efx_time_sync_event(struct efx_channel *channel, efx_qword_t *ev);
554bd9a265dSJon Cooper void __efx_rx_skb_attach_timestamp(struct efx_channel *channel,
555bd9a265dSJon Cooper 				   struct sk_buff *skb);
556bd9a265dSJon Cooper static inline void efx_rx_skb_attach_timestamp(struct efx_channel *channel,
557bd9a265dSJon Cooper 					       struct sk_buff *skb)
558bd9a265dSJon Cooper {
559bd9a265dSJon Cooper 	if (channel->sync_events_state == SYNC_EVENTS_VALID)
560bd9a265dSJon Cooper 		__efx_rx_skb_attach_timestamp(channel, skb);
561bd9a265dSJon Cooper }
5622ea4dc28SAlexandre Rames void efx_ptp_start_datapath(struct efx_nic *efx);
5632ea4dc28SAlexandre Rames void efx_ptp_stop_datapath(struct efx_nic *efx);
5647c236c43SStuart Hodgson 
565874aeea5SJeff Kirsher extern const struct efx_nic_type falcon_a1_nic_type;
566874aeea5SJeff Kirsher extern const struct efx_nic_type falcon_b0_nic_type;
567874aeea5SJeff Kirsher extern const struct efx_nic_type siena_a0_nic_type;
5688127d661SBen Hutchings extern const struct efx_nic_type efx_hunt_a0_nic_type;
56902246a7fSShradha Shah extern const struct efx_nic_type efx_hunt_a0_vf_nic_type;
570874aeea5SJeff Kirsher 
571874aeea5SJeff Kirsher /**************************************************************************
572874aeea5SJeff Kirsher  *
573874aeea5SJeff Kirsher  * Externs
574874aeea5SJeff Kirsher  *
575874aeea5SJeff Kirsher  **************************************************************************
576874aeea5SJeff Kirsher  */
577874aeea5SJeff Kirsher 
57800aef986SJoe Perches int falcon_probe_board(struct efx_nic *efx, u16 revision_info);
579874aeea5SJeff Kirsher 
580874aeea5SJeff Kirsher /* TX data path */
58186094f7fSBen Hutchings static inline int efx_nic_probe_tx(struct efx_tx_queue *tx_queue)
58286094f7fSBen Hutchings {
58386094f7fSBen Hutchings 	return tx_queue->efx->type->tx_probe(tx_queue);
58486094f7fSBen Hutchings }
58586094f7fSBen Hutchings static inline void efx_nic_init_tx(struct efx_tx_queue *tx_queue)
58686094f7fSBen Hutchings {
58786094f7fSBen Hutchings 	tx_queue->efx->type->tx_init(tx_queue);
58886094f7fSBen Hutchings }
58986094f7fSBen Hutchings static inline void efx_nic_remove_tx(struct efx_tx_queue *tx_queue)
59086094f7fSBen Hutchings {
59186094f7fSBen Hutchings 	tx_queue->efx->type->tx_remove(tx_queue);
59286094f7fSBen Hutchings }
59386094f7fSBen Hutchings static inline void efx_nic_push_buffers(struct efx_tx_queue *tx_queue)
59486094f7fSBen Hutchings {
59586094f7fSBen Hutchings 	tx_queue->efx->type->tx_write(tx_queue);
59686094f7fSBen Hutchings }
597874aeea5SJeff Kirsher 
598874aeea5SJeff Kirsher /* RX data path */
59986094f7fSBen Hutchings static inline int efx_nic_probe_rx(struct efx_rx_queue *rx_queue)
60086094f7fSBen Hutchings {
60186094f7fSBen Hutchings 	return rx_queue->efx->type->rx_probe(rx_queue);
60286094f7fSBen Hutchings }
60386094f7fSBen Hutchings static inline void efx_nic_init_rx(struct efx_rx_queue *rx_queue)
60486094f7fSBen Hutchings {
60586094f7fSBen Hutchings 	rx_queue->efx->type->rx_init(rx_queue);
60686094f7fSBen Hutchings }
60786094f7fSBen Hutchings static inline void efx_nic_remove_rx(struct efx_rx_queue *rx_queue)
60886094f7fSBen Hutchings {
60986094f7fSBen Hutchings 	rx_queue->efx->type->rx_remove(rx_queue);
61086094f7fSBen Hutchings }
61186094f7fSBen Hutchings static inline void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue)
61286094f7fSBen Hutchings {
61386094f7fSBen Hutchings 	rx_queue->efx->type->rx_write(rx_queue);
61486094f7fSBen Hutchings }
61586094f7fSBen Hutchings static inline void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue)
61686094f7fSBen Hutchings {
61786094f7fSBen Hutchings 	rx_queue->efx->type->rx_defer_refill(rx_queue);
61886094f7fSBen Hutchings }
619874aeea5SJeff Kirsher 
620874aeea5SJeff Kirsher /* Event data path */
62186094f7fSBen Hutchings static inline int efx_nic_probe_eventq(struct efx_channel *channel)
62286094f7fSBen Hutchings {
62386094f7fSBen Hutchings 	return channel->efx->type->ev_probe(channel);
62486094f7fSBen Hutchings }
625261e4d96SJon Cooper static inline int efx_nic_init_eventq(struct efx_channel *channel)
62686094f7fSBen Hutchings {
627261e4d96SJon Cooper 	return channel->efx->type->ev_init(channel);
62886094f7fSBen Hutchings }
62986094f7fSBen Hutchings static inline void efx_nic_fini_eventq(struct efx_channel *channel)
63086094f7fSBen Hutchings {
63186094f7fSBen Hutchings 	channel->efx->type->ev_fini(channel);
63286094f7fSBen Hutchings }
63386094f7fSBen Hutchings static inline void efx_nic_remove_eventq(struct efx_channel *channel)
63486094f7fSBen Hutchings {
63586094f7fSBen Hutchings 	channel->efx->type->ev_remove(channel);
63686094f7fSBen Hutchings }
63786094f7fSBen Hutchings static inline int
63886094f7fSBen Hutchings efx_nic_process_eventq(struct efx_channel *channel, int quota)
63986094f7fSBen Hutchings {
64086094f7fSBen Hutchings 	return channel->efx->type->ev_process(channel, quota);
64186094f7fSBen Hutchings }
64286094f7fSBen Hutchings static inline void efx_nic_eventq_read_ack(struct efx_channel *channel)
64386094f7fSBen Hutchings {
64486094f7fSBen Hutchings 	channel->efx->type->ev_read_ack(channel);
64586094f7fSBen Hutchings }
64600aef986SJoe Perches void efx_nic_event_test_start(struct efx_channel *channel);
64786094f7fSBen Hutchings 
64886094f7fSBen Hutchings /* Falcon/Siena queue operations */
64900aef986SJoe Perches int efx_farch_tx_probe(struct efx_tx_queue *tx_queue);
65000aef986SJoe Perches void efx_farch_tx_init(struct efx_tx_queue *tx_queue);
65100aef986SJoe Perches void efx_farch_tx_fini(struct efx_tx_queue *tx_queue);
65200aef986SJoe Perches void efx_farch_tx_remove(struct efx_tx_queue *tx_queue);
65300aef986SJoe Perches void efx_farch_tx_write(struct efx_tx_queue *tx_queue);
65400aef986SJoe Perches int efx_farch_rx_probe(struct efx_rx_queue *rx_queue);
65500aef986SJoe Perches void efx_farch_rx_init(struct efx_rx_queue *rx_queue);
65600aef986SJoe Perches void efx_farch_rx_fini(struct efx_rx_queue *rx_queue);
65700aef986SJoe Perches void efx_farch_rx_remove(struct efx_rx_queue *rx_queue);
65800aef986SJoe Perches void efx_farch_rx_write(struct efx_rx_queue *rx_queue);
65900aef986SJoe Perches void efx_farch_rx_defer_refill(struct efx_rx_queue *rx_queue);
66000aef986SJoe Perches int efx_farch_ev_probe(struct efx_channel *channel);
66100aef986SJoe Perches int efx_farch_ev_init(struct efx_channel *channel);
66200aef986SJoe Perches void efx_farch_ev_fini(struct efx_channel *channel);
66300aef986SJoe Perches void efx_farch_ev_remove(struct efx_channel *channel);
66400aef986SJoe Perches int efx_farch_ev_process(struct efx_channel *channel, int quota);
66500aef986SJoe Perches void efx_farch_ev_read_ack(struct efx_channel *channel);
66600aef986SJoe Perches void efx_farch_ev_test_generate(struct efx_channel *channel);
66786094f7fSBen Hutchings 
668add72477SBen Hutchings /* Falcon/Siena filter operations */
66900aef986SJoe Perches int efx_farch_filter_table_probe(struct efx_nic *efx);
67000aef986SJoe Perches void efx_farch_filter_table_restore(struct efx_nic *efx);
67100aef986SJoe Perches void efx_farch_filter_table_remove(struct efx_nic *efx);
67200aef986SJoe Perches void efx_farch_filter_update_rx_scatter(struct efx_nic *efx);
67300aef986SJoe Perches s32 efx_farch_filter_insert(struct efx_nic *efx, struct efx_filter_spec *spec,
67400aef986SJoe Perches 			    bool replace);
67500aef986SJoe Perches int efx_farch_filter_remove_safe(struct efx_nic *efx,
676add72477SBen Hutchings 				 enum efx_filter_priority priority,
677add72477SBen Hutchings 				 u32 filter_id);
67800aef986SJoe Perches int efx_farch_filter_get_safe(struct efx_nic *efx,
67900aef986SJoe Perches 			      enum efx_filter_priority priority, u32 filter_id,
68000aef986SJoe Perches 			      struct efx_filter_spec *);
681fbd79120SBen Hutchings int efx_farch_filter_clear_rx(struct efx_nic *efx,
682add72477SBen Hutchings 			      enum efx_filter_priority priority);
68300aef986SJoe Perches u32 efx_farch_filter_count_rx_used(struct efx_nic *efx,
684add72477SBen Hutchings 				   enum efx_filter_priority priority);
68500aef986SJoe Perches u32 efx_farch_filter_get_rx_id_limit(struct efx_nic *efx);
68600aef986SJoe Perches s32 efx_farch_filter_get_rx_ids(struct efx_nic *efx,
68700aef986SJoe Perches 				enum efx_filter_priority priority, u32 *buf,
68800aef986SJoe Perches 				u32 size);
689add72477SBen Hutchings #ifdef CONFIG_RFS_ACCEL
69000aef986SJoe Perches s32 efx_farch_filter_rfs_insert(struct efx_nic *efx,
691add72477SBen Hutchings 				struct efx_filter_spec *spec);
69200aef986SJoe Perches bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
693add72477SBen Hutchings 				     unsigned int index);
694add72477SBen Hutchings #endif
69500aef986SJoe Perches void efx_farch_filter_sync_rx_mode(struct efx_nic *efx);
696add72477SBen Hutchings 
69700aef986SJoe Perches bool efx_nic_event_present(struct efx_channel *channel);
698874aeea5SJeff Kirsher 
699b7f514afSBen Hutchings /* Some statistics are computed as A - B where A and B each increase
700b7f514afSBen Hutchings  * linearly with some hardware counter(s) and the counters are read
701b7f514afSBen Hutchings  * asynchronously.  If the counters contributing to B are always read
702b7f514afSBen Hutchings  * after those contributing to A, the computed value may be lower than
703b7f514afSBen Hutchings  * the true value by some variable amount, and may decrease between
704b7f514afSBen Hutchings  * subsequent computations.
705b7f514afSBen Hutchings  *
706b7f514afSBen Hutchings  * We should never allow statistics to decrease or to exceed the true
707b7f514afSBen Hutchings  * value.  Since the computed value will never be greater than the
708b7f514afSBen Hutchings  * true value, we can achieve this by only storing the computed value
709b7f514afSBen Hutchings  * when it increases.
710b7f514afSBen Hutchings  */
711b7f514afSBen Hutchings static inline void efx_update_diff_stat(u64 *stat, u64 diff)
712b7f514afSBen Hutchings {
713b7f514afSBen Hutchings 	if ((s64)(diff - *stat) > 0)
714b7f514afSBen Hutchings 		*stat = diff;
715b7f514afSBen Hutchings }
716b7f514afSBen Hutchings 
71786094f7fSBen Hutchings /* Interrupts */
71800aef986SJoe Perches int efx_nic_init_interrupt(struct efx_nic *efx);
71900aef986SJoe Perches void efx_nic_irq_test_start(struct efx_nic *efx);
72000aef986SJoe Perches void efx_nic_fini_interrupt(struct efx_nic *efx);
72186094f7fSBen Hutchings 
72286094f7fSBen Hutchings /* Falcon/Siena interrupts */
72300aef986SJoe Perches void efx_farch_irq_enable_master(struct efx_nic *efx);
72400aef986SJoe Perches void efx_farch_irq_test_generate(struct efx_nic *efx);
72500aef986SJoe Perches void efx_farch_irq_disable_master(struct efx_nic *efx);
72600aef986SJoe Perches irqreturn_t efx_farch_msi_interrupt(int irq, void *dev_id);
72700aef986SJoe Perches irqreturn_t efx_farch_legacy_interrupt(int irq, void *dev_id);
72800aef986SJoe Perches irqreturn_t efx_farch_fatal_interrupt(struct efx_nic *efx);
729874aeea5SJeff Kirsher 
730eee6f6a9SBen Hutchings static inline int efx_nic_event_test_irq_cpu(struct efx_channel *channel)
731eee6f6a9SBen Hutchings {
732dd40781eSBen Hutchings 	return ACCESS_ONCE(channel->event_test_cpu);
733eee6f6a9SBen Hutchings }
734eee6f6a9SBen Hutchings static inline int efx_nic_irq_test_irq_cpu(struct efx_nic *efx)
735eee6f6a9SBen Hutchings {
736eee6f6a9SBen Hutchings 	return ACCESS_ONCE(efx->last_irq_cpu);
737eee6f6a9SBen Hutchings }
738eee6f6a9SBen Hutchings 
739874aeea5SJeff Kirsher /* Global Resources */
74000aef986SJoe Perches int efx_nic_flush_queues(struct efx_nic *efx);
74100aef986SJoe Perches void siena_prepare_flush(struct efx_nic *efx);
74200aef986SJoe Perches int efx_farch_fini_dmaq(struct efx_nic *efx);
743e283546cSEdward Cree void efx_farch_finish_flr(struct efx_nic *efx);
74400aef986SJoe Perches void siena_finish_flush(struct efx_nic *efx);
74500aef986SJoe Perches void falcon_start_nic_stats(struct efx_nic *efx);
74600aef986SJoe Perches void falcon_stop_nic_stats(struct efx_nic *efx);
74700aef986SJoe Perches int falcon_reset_xaui(struct efx_nic *efx);
74800aef986SJoe Perches void efx_farch_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw);
74900aef986SJoe Perches void efx_farch_init_common(struct efx_nic *efx);
75000aef986SJoe Perches void efx_ef10_handle_drain_event(struct efx_nic *efx);
75100aef986SJoe Perches void efx_farch_rx_push_indir_table(struct efx_nic *efx);
752874aeea5SJeff Kirsher 
753874aeea5SJeff Kirsher int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
7540d19a540SBen Hutchings 			 unsigned int len, gfp_t gfp_flags);
755874aeea5SJeff Kirsher void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer);
756874aeea5SJeff Kirsher 
757874aeea5SJeff Kirsher /* Tests */
75886094f7fSBen Hutchings struct efx_farch_register_test {
759874aeea5SJeff Kirsher 	unsigned address;
760874aeea5SJeff Kirsher 	efx_oword_t mask;
761874aeea5SJeff Kirsher };
76200aef986SJoe Perches int efx_farch_test_registers(struct efx_nic *efx,
76386094f7fSBen Hutchings 			     const struct efx_farch_register_test *regs,
764874aeea5SJeff Kirsher 			     size_t n_regs);
765874aeea5SJeff Kirsher 
76600aef986SJoe Perches size_t efx_nic_get_regs_len(struct efx_nic *efx);
76700aef986SJoe Perches void efx_nic_get_regs(struct efx_nic *efx, void *buf);
768874aeea5SJeff Kirsher 
76900aef986SJoe Perches size_t efx_nic_describe_stats(const struct efx_hw_stat_desc *desc, size_t count,
770cd0ecc9aSBen Hutchings 			      const unsigned long *mask, u8 *names);
77100aef986SJoe Perches void efx_nic_update_stats(const struct efx_hw_stat_desc *desc, size_t count,
77200aef986SJoe Perches 			  const unsigned long *mask, u64 *stats,
77300aef986SJoe Perches 			  const void *dma_buf, bool accumulate);
774f8f3b5aeSJon Cooper void efx_nic_fix_nodesc_drop_stat(struct efx_nic *efx, u64 *stat);
775cd0ecc9aSBen Hutchings 
776ab0115fcSBen Hutchings #define EFX_MAX_FLUSH_TIME 5000
777874aeea5SJeff Kirsher 
77800aef986SJoe Perches void efx_farch_generate_event(struct efx_nic *efx, unsigned int evq,
779874aeea5SJeff Kirsher 			      efx_qword_t *event);
780874aeea5SJeff Kirsher 
781874aeea5SJeff Kirsher #endif /* EFX_NIC_H */
782