xref: /openbmc/linux/drivers/net/ethernet/sfc/nic.h (revision 45b2449e)
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 {
410e4d112e4SEdward Cree 	EF10_STAT_tx_bytes = GENERIC_STAT_COUNT,
4118127d661SBen Hutchings 	EF10_STAT_tx_packets,
4128127d661SBen Hutchings 	EF10_STAT_tx_pause,
4138127d661SBen Hutchings 	EF10_STAT_tx_control,
4148127d661SBen Hutchings 	EF10_STAT_tx_unicast,
4158127d661SBen Hutchings 	EF10_STAT_tx_multicast,
4168127d661SBen Hutchings 	EF10_STAT_tx_broadcast,
4178127d661SBen Hutchings 	EF10_STAT_tx_lt64,
4188127d661SBen Hutchings 	EF10_STAT_tx_64,
4198127d661SBen Hutchings 	EF10_STAT_tx_65_to_127,
4208127d661SBen Hutchings 	EF10_STAT_tx_128_to_255,
4218127d661SBen Hutchings 	EF10_STAT_tx_256_to_511,
4228127d661SBen Hutchings 	EF10_STAT_tx_512_to_1023,
4238127d661SBen Hutchings 	EF10_STAT_tx_1024_to_15xx,
4248127d661SBen Hutchings 	EF10_STAT_tx_15xx_to_jumbo,
4258127d661SBen Hutchings 	EF10_STAT_rx_bytes,
4268127d661SBen Hutchings 	EF10_STAT_rx_bytes_minus_good_bytes,
4278127d661SBen Hutchings 	EF10_STAT_rx_good_bytes,
4288127d661SBen Hutchings 	EF10_STAT_rx_bad_bytes,
4298127d661SBen Hutchings 	EF10_STAT_rx_packets,
4308127d661SBen Hutchings 	EF10_STAT_rx_good,
4318127d661SBen Hutchings 	EF10_STAT_rx_bad,
4328127d661SBen Hutchings 	EF10_STAT_rx_pause,
4338127d661SBen Hutchings 	EF10_STAT_rx_control,
4348127d661SBen Hutchings 	EF10_STAT_rx_unicast,
4358127d661SBen Hutchings 	EF10_STAT_rx_multicast,
4368127d661SBen Hutchings 	EF10_STAT_rx_broadcast,
4378127d661SBen Hutchings 	EF10_STAT_rx_lt64,
4388127d661SBen Hutchings 	EF10_STAT_rx_64,
4398127d661SBen Hutchings 	EF10_STAT_rx_65_to_127,
4408127d661SBen Hutchings 	EF10_STAT_rx_128_to_255,
4418127d661SBen Hutchings 	EF10_STAT_rx_256_to_511,
4428127d661SBen Hutchings 	EF10_STAT_rx_512_to_1023,
4438127d661SBen Hutchings 	EF10_STAT_rx_1024_to_15xx,
4448127d661SBen Hutchings 	EF10_STAT_rx_15xx_to_jumbo,
4458127d661SBen Hutchings 	EF10_STAT_rx_gtjumbo,
4468127d661SBen Hutchings 	EF10_STAT_rx_bad_gtjumbo,
4478127d661SBen Hutchings 	EF10_STAT_rx_overflow,
4488127d661SBen Hutchings 	EF10_STAT_rx_align_error,
4498127d661SBen Hutchings 	EF10_STAT_rx_length_error,
4508127d661SBen Hutchings 	EF10_STAT_rx_nodesc_drops,
451568d7a00SEdward Cree 	EF10_STAT_rx_pm_trunc_bb_overflow,
452568d7a00SEdward Cree 	EF10_STAT_rx_pm_discard_bb_overflow,
453568d7a00SEdward Cree 	EF10_STAT_rx_pm_trunc_vfifo_full,
454568d7a00SEdward Cree 	EF10_STAT_rx_pm_discard_vfifo_full,
455568d7a00SEdward Cree 	EF10_STAT_rx_pm_trunc_qbb,
456568d7a00SEdward Cree 	EF10_STAT_rx_pm_discard_qbb,
457568d7a00SEdward Cree 	EF10_STAT_rx_pm_discard_mapping,
458568d7a00SEdward Cree 	EF10_STAT_rx_dp_q_disabled_packets,
459568d7a00SEdward Cree 	EF10_STAT_rx_dp_di_dropped_packets,
460568d7a00SEdward Cree 	EF10_STAT_rx_dp_streaming_packets,
46179ac47aeSShradha Shah 	EF10_STAT_rx_dp_hlb_fetch,
46279ac47aeSShradha Shah 	EF10_STAT_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
4888127d661SBen Hutchings  * @stats: Hardware statistics
4898127d661SBen Hutchings  * @workaround_35388: Flag: firmware supports workaround for bug 35388
490a915ccc9SBen Hutchings  * @must_check_datapath_caps: Flag: @datapath_caps needs to be revalidated
491a915ccc9SBen Hutchings  *	after MC reboot
4928127d661SBen Hutchings  * @datapath_caps: Capabilities of datapath firmware (FLAGS1 field of
4938127d661SBen Hutchings  *	%MC_CMD_GET_CAPABILITIES response)
4948d9f9dd4SDaniel Pieczko  * @rx_dpcpu_fw_id: Firmware ID of the RxDPCPU
4958d9f9dd4SDaniel Pieczko  * @tx_dpcpu_fw_id: Firmware ID of the TxDPCPU
49645b2449eSDaniel Pieczko  * @vport_id: The function's vport ID, only relevant for PFs
4978127d661SBen Hutchings  */
4988127d661SBen Hutchings struct efx_ef10_nic_data {
4998127d661SBen Hutchings 	struct efx_buffer mcdi_buf;
5008127d661SBen Hutchings 	u16 warm_boot_count;
5018127d661SBen Hutchings 	unsigned int vi_base;
5028127d661SBen Hutchings 	unsigned int n_allocated_vis;
5038127d661SBen Hutchings 	bool must_realloc_vis;
5048127d661SBen Hutchings 	bool must_restore_filters;
505183233beSBen Hutchings 	unsigned int n_piobufs;
506183233beSBen Hutchings 	void __iomem *wc_membase, *pio_write_base;
507183233beSBen Hutchings 	unsigned int pio_write_vi_base;
508183233beSBen Hutchings 	unsigned int piobuf_handle[EF10_TX_PIOBUF_COUNT];
509183233beSBen Hutchings 	bool must_restore_piobufs;
5108127d661SBen Hutchings 	u32 rx_rss_context;
5118127d661SBen Hutchings 	u64 stats[EF10_STAT_COUNT];
5128127d661SBen Hutchings 	bool workaround_35388;
513a915ccc9SBen Hutchings 	bool must_check_datapath_caps;
5148127d661SBen Hutchings 	u32 datapath_caps;
5158d9f9dd4SDaniel Pieczko 	unsigned int rx_dpcpu_fw_id;
5168d9f9dd4SDaniel Pieczko 	unsigned int tx_dpcpu_fw_id;
51745b2449eSDaniel Pieczko 	unsigned int vport_id;
5188127d661SBen Hutchings };
5198127d661SBen Hutchings 
52000aef986SJoe Perches int efx_init_sriov(void);
52100aef986SJoe Perches void efx_fini_sriov(void);
522cd2d5b52SBen Hutchings 
5237c236c43SStuart Hodgson struct ethtool_ts_info;
524ac36baf8SBen Hutchings int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel);
525ac36baf8SBen Hutchings void efx_ptp_defer_probe_with_channel(struct efx_nic *efx);
526ac36baf8SBen Hutchings void efx_ptp_remove(struct efx_nic *efx);
527433dc9b3SBen Hutchings int efx_ptp_set_ts_config(struct efx_nic *efx, struct ifreq *ifr);
528433dc9b3SBen Hutchings int efx_ptp_get_ts_config(struct efx_nic *efx, struct ifreq *ifr);
52900aef986SJoe Perches void efx_ptp_get_ts_info(struct efx_nic *efx, struct ethtool_ts_info *ts_info);
53000aef986SJoe Perches bool efx_ptp_is_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
5319ec06595SDaniel Pieczko int efx_ptp_get_mode(struct efx_nic *efx);
5329ec06595SDaniel Pieczko int efx_ptp_change_mode(struct efx_nic *efx, bool enable_wanted,
5339ec06595SDaniel Pieczko 			unsigned int new_mode);
53400aef986SJoe Perches int efx_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
53500aef986SJoe Perches void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev);
53699691c4aSBen Hutchings size_t efx_ptp_describe_stats(struct efx_nic *efx, u8 *strings);
53799691c4aSBen Hutchings size_t efx_ptp_update_stats(struct efx_nic *efx, u64 *stats);
538bd9a265dSJon Cooper void efx_time_sync_event(struct efx_channel *channel, efx_qword_t *ev);
539bd9a265dSJon Cooper void __efx_rx_skb_attach_timestamp(struct efx_channel *channel,
540bd9a265dSJon Cooper 				   struct sk_buff *skb);
541bd9a265dSJon Cooper static inline void efx_rx_skb_attach_timestamp(struct efx_channel *channel,
542bd9a265dSJon Cooper 					       struct sk_buff *skb)
543bd9a265dSJon Cooper {
544bd9a265dSJon Cooper 	if (channel->sync_events_state == SYNC_EVENTS_VALID)
545bd9a265dSJon Cooper 		__efx_rx_skb_attach_timestamp(channel, skb);
546bd9a265dSJon Cooper }
5472ea4dc28SAlexandre Rames void efx_ptp_start_datapath(struct efx_nic *efx);
5482ea4dc28SAlexandre Rames void efx_ptp_stop_datapath(struct efx_nic *efx);
5497c236c43SStuart Hodgson 
550874aeea5SJeff Kirsher extern const struct efx_nic_type falcon_a1_nic_type;
551874aeea5SJeff Kirsher extern const struct efx_nic_type falcon_b0_nic_type;
552874aeea5SJeff Kirsher extern const struct efx_nic_type siena_a0_nic_type;
5538127d661SBen Hutchings extern const struct efx_nic_type efx_hunt_a0_nic_type;
554874aeea5SJeff Kirsher 
555874aeea5SJeff Kirsher /**************************************************************************
556874aeea5SJeff Kirsher  *
557874aeea5SJeff Kirsher  * Externs
558874aeea5SJeff Kirsher  *
559874aeea5SJeff Kirsher  **************************************************************************
560874aeea5SJeff Kirsher  */
561874aeea5SJeff Kirsher 
56200aef986SJoe Perches int falcon_probe_board(struct efx_nic *efx, u16 revision_info);
563874aeea5SJeff Kirsher 
564874aeea5SJeff Kirsher /* TX data path */
56586094f7fSBen Hutchings static inline int efx_nic_probe_tx(struct efx_tx_queue *tx_queue)
56686094f7fSBen Hutchings {
56786094f7fSBen Hutchings 	return tx_queue->efx->type->tx_probe(tx_queue);
56886094f7fSBen Hutchings }
56986094f7fSBen Hutchings static inline void efx_nic_init_tx(struct efx_tx_queue *tx_queue)
57086094f7fSBen Hutchings {
57186094f7fSBen Hutchings 	tx_queue->efx->type->tx_init(tx_queue);
57286094f7fSBen Hutchings }
57386094f7fSBen Hutchings static inline void efx_nic_remove_tx(struct efx_tx_queue *tx_queue)
57486094f7fSBen Hutchings {
57586094f7fSBen Hutchings 	tx_queue->efx->type->tx_remove(tx_queue);
57686094f7fSBen Hutchings }
57786094f7fSBen Hutchings static inline void efx_nic_push_buffers(struct efx_tx_queue *tx_queue)
57886094f7fSBen Hutchings {
57986094f7fSBen Hutchings 	tx_queue->efx->type->tx_write(tx_queue);
58086094f7fSBen Hutchings }
581874aeea5SJeff Kirsher 
582874aeea5SJeff Kirsher /* RX data path */
58386094f7fSBen Hutchings static inline int efx_nic_probe_rx(struct efx_rx_queue *rx_queue)
58486094f7fSBen Hutchings {
58586094f7fSBen Hutchings 	return rx_queue->efx->type->rx_probe(rx_queue);
58686094f7fSBen Hutchings }
58786094f7fSBen Hutchings static inline void efx_nic_init_rx(struct efx_rx_queue *rx_queue)
58886094f7fSBen Hutchings {
58986094f7fSBen Hutchings 	rx_queue->efx->type->rx_init(rx_queue);
59086094f7fSBen Hutchings }
59186094f7fSBen Hutchings static inline void efx_nic_remove_rx(struct efx_rx_queue *rx_queue)
59286094f7fSBen Hutchings {
59386094f7fSBen Hutchings 	rx_queue->efx->type->rx_remove(rx_queue);
59486094f7fSBen Hutchings }
59586094f7fSBen Hutchings static inline void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue)
59686094f7fSBen Hutchings {
59786094f7fSBen Hutchings 	rx_queue->efx->type->rx_write(rx_queue);
59886094f7fSBen Hutchings }
59986094f7fSBen Hutchings static inline void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue)
60086094f7fSBen Hutchings {
60186094f7fSBen Hutchings 	rx_queue->efx->type->rx_defer_refill(rx_queue);
60286094f7fSBen Hutchings }
603874aeea5SJeff Kirsher 
604874aeea5SJeff Kirsher /* Event data path */
60586094f7fSBen Hutchings static inline int efx_nic_probe_eventq(struct efx_channel *channel)
60686094f7fSBen Hutchings {
60786094f7fSBen Hutchings 	return channel->efx->type->ev_probe(channel);
60886094f7fSBen Hutchings }
609261e4d96SJon Cooper static inline int efx_nic_init_eventq(struct efx_channel *channel)
61086094f7fSBen Hutchings {
611261e4d96SJon Cooper 	return channel->efx->type->ev_init(channel);
61286094f7fSBen Hutchings }
61386094f7fSBen Hutchings static inline void efx_nic_fini_eventq(struct efx_channel *channel)
61486094f7fSBen Hutchings {
61586094f7fSBen Hutchings 	channel->efx->type->ev_fini(channel);
61686094f7fSBen Hutchings }
61786094f7fSBen Hutchings static inline void efx_nic_remove_eventq(struct efx_channel *channel)
61886094f7fSBen Hutchings {
61986094f7fSBen Hutchings 	channel->efx->type->ev_remove(channel);
62086094f7fSBen Hutchings }
62186094f7fSBen Hutchings static inline int
62286094f7fSBen Hutchings efx_nic_process_eventq(struct efx_channel *channel, int quota)
62386094f7fSBen Hutchings {
62486094f7fSBen Hutchings 	return channel->efx->type->ev_process(channel, quota);
62586094f7fSBen Hutchings }
62686094f7fSBen Hutchings static inline void efx_nic_eventq_read_ack(struct efx_channel *channel)
62786094f7fSBen Hutchings {
62886094f7fSBen Hutchings 	channel->efx->type->ev_read_ack(channel);
62986094f7fSBen Hutchings }
63000aef986SJoe Perches void efx_nic_event_test_start(struct efx_channel *channel);
63186094f7fSBen Hutchings 
63286094f7fSBen Hutchings /* Falcon/Siena queue operations */
63300aef986SJoe Perches int efx_farch_tx_probe(struct efx_tx_queue *tx_queue);
63400aef986SJoe Perches void efx_farch_tx_init(struct efx_tx_queue *tx_queue);
63500aef986SJoe Perches void efx_farch_tx_fini(struct efx_tx_queue *tx_queue);
63600aef986SJoe Perches void efx_farch_tx_remove(struct efx_tx_queue *tx_queue);
63700aef986SJoe Perches void efx_farch_tx_write(struct efx_tx_queue *tx_queue);
63800aef986SJoe Perches int efx_farch_rx_probe(struct efx_rx_queue *rx_queue);
63900aef986SJoe Perches void efx_farch_rx_init(struct efx_rx_queue *rx_queue);
64000aef986SJoe Perches void efx_farch_rx_fini(struct efx_rx_queue *rx_queue);
64100aef986SJoe Perches void efx_farch_rx_remove(struct efx_rx_queue *rx_queue);
64200aef986SJoe Perches void efx_farch_rx_write(struct efx_rx_queue *rx_queue);
64300aef986SJoe Perches void efx_farch_rx_defer_refill(struct efx_rx_queue *rx_queue);
64400aef986SJoe Perches int efx_farch_ev_probe(struct efx_channel *channel);
64500aef986SJoe Perches int efx_farch_ev_init(struct efx_channel *channel);
64600aef986SJoe Perches void efx_farch_ev_fini(struct efx_channel *channel);
64700aef986SJoe Perches void efx_farch_ev_remove(struct efx_channel *channel);
64800aef986SJoe Perches int efx_farch_ev_process(struct efx_channel *channel, int quota);
64900aef986SJoe Perches void efx_farch_ev_read_ack(struct efx_channel *channel);
65000aef986SJoe Perches void efx_farch_ev_test_generate(struct efx_channel *channel);
65186094f7fSBen Hutchings 
652add72477SBen Hutchings /* Falcon/Siena filter operations */
65300aef986SJoe Perches int efx_farch_filter_table_probe(struct efx_nic *efx);
65400aef986SJoe Perches void efx_farch_filter_table_restore(struct efx_nic *efx);
65500aef986SJoe Perches void efx_farch_filter_table_remove(struct efx_nic *efx);
65600aef986SJoe Perches void efx_farch_filter_update_rx_scatter(struct efx_nic *efx);
65700aef986SJoe Perches s32 efx_farch_filter_insert(struct efx_nic *efx, struct efx_filter_spec *spec,
65800aef986SJoe Perches 			    bool replace);
65900aef986SJoe Perches int efx_farch_filter_remove_safe(struct efx_nic *efx,
660add72477SBen Hutchings 				 enum efx_filter_priority priority,
661add72477SBen Hutchings 				 u32 filter_id);
66200aef986SJoe Perches int efx_farch_filter_get_safe(struct efx_nic *efx,
66300aef986SJoe Perches 			      enum efx_filter_priority priority, u32 filter_id,
66400aef986SJoe Perches 			      struct efx_filter_spec *);
665fbd79120SBen Hutchings int efx_farch_filter_clear_rx(struct efx_nic *efx,
666add72477SBen Hutchings 			      enum efx_filter_priority priority);
66700aef986SJoe Perches u32 efx_farch_filter_count_rx_used(struct efx_nic *efx,
668add72477SBen Hutchings 				   enum efx_filter_priority priority);
66900aef986SJoe Perches u32 efx_farch_filter_get_rx_id_limit(struct efx_nic *efx);
67000aef986SJoe Perches s32 efx_farch_filter_get_rx_ids(struct efx_nic *efx,
67100aef986SJoe Perches 				enum efx_filter_priority priority, u32 *buf,
67200aef986SJoe Perches 				u32 size);
673add72477SBen Hutchings #ifdef CONFIG_RFS_ACCEL
67400aef986SJoe Perches s32 efx_farch_filter_rfs_insert(struct efx_nic *efx,
675add72477SBen Hutchings 				struct efx_filter_spec *spec);
67600aef986SJoe Perches bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
677add72477SBen Hutchings 				     unsigned int index);
678add72477SBen Hutchings #endif
67900aef986SJoe Perches void efx_farch_filter_sync_rx_mode(struct efx_nic *efx);
680add72477SBen Hutchings 
68100aef986SJoe Perches bool efx_nic_event_present(struct efx_channel *channel);
682874aeea5SJeff Kirsher 
683b7f514afSBen Hutchings /* Some statistics are computed as A - B where A and B each increase
684b7f514afSBen Hutchings  * linearly with some hardware counter(s) and the counters are read
685b7f514afSBen Hutchings  * asynchronously.  If the counters contributing to B are always read
686b7f514afSBen Hutchings  * after those contributing to A, the computed value may be lower than
687b7f514afSBen Hutchings  * the true value by some variable amount, and may decrease between
688b7f514afSBen Hutchings  * subsequent computations.
689b7f514afSBen Hutchings  *
690b7f514afSBen Hutchings  * We should never allow statistics to decrease or to exceed the true
691b7f514afSBen Hutchings  * value.  Since the computed value will never be greater than the
692b7f514afSBen Hutchings  * true value, we can achieve this by only storing the computed value
693b7f514afSBen Hutchings  * when it increases.
694b7f514afSBen Hutchings  */
695b7f514afSBen Hutchings static inline void efx_update_diff_stat(u64 *stat, u64 diff)
696b7f514afSBen Hutchings {
697b7f514afSBen Hutchings 	if ((s64)(diff - *stat) > 0)
698b7f514afSBen Hutchings 		*stat = diff;
699b7f514afSBen Hutchings }
700b7f514afSBen Hutchings 
70186094f7fSBen Hutchings /* Interrupts */
70200aef986SJoe Perches int efx_nic_init_interrupt(struct efx_nic *efx);
70300aef986SJoe Perches void efx_nic_irq_test_start(struct efx_nic *efx);
70400aef986SJoe Perches void efx_nic_fini_interrupt(struct efx_nic *efx);
70586094f7fSBen Hutchings 
70686094f7fSBen Hutchings /* Falcon/Siena interrupts */
70700aef986SJoe Perches void efx_farch_irq_enable_master(struct efx_nic *efx);
70800aef986SJoe Perches void efx_farch_irq_test_generate(struct efx_nic *efx);
70900aef986SJoe Perches void efx_farch_irq_disable_master(struct efx_nic *efx);
71000aef986SJoe Perches irqreturn_t efx_farch_msi_interrupt(int irq, void *dev_id);
71100aef986SJoe Perches irqreturn_t efx_farch_legacy_interrupt(int irq, void *dev_id);
71200aef986SJoe Perches irqreturn_t efx_farch_fatal_interrupt(struct efx_nic *efx);
713874aeea5SJeff Kirsher 
714eee6f6a9SBen Hutchings static inline int efx_nic_event_test_irq_cpu(struct efx_channel *channel)
715eee6f6a9SBen Hutchings {
716dd40781eSBen Hutchings 	return ACCESS_ONCE(channel->event_test_cpu);
717eee6f6a9SBen Hutchings }
718eee6f6a9SBen Hutchings static inline int efx_nic_irq_test_irq_cpu(struct efx_nic *efx)
719eee6f6a9SBen Hutchings {
720eee6f6a9SBen Hutchings 	return ACCESS_ONCE(efx->last_irq_cpu);
721eee6f6a9SBen Hutchings }
722eee6f6a9SBen Hutchings 
723874aeea5SJeff Kirsher /* Global Resources */
72400aef986SJoe Perches int efx_nic_flush_queues(struct efx_nic *efx);
72500aef986SJoe Perches void siena_prepare_flush(struct efx_nic *efx);
72600aef986SJoe Perches int efx_farch_fini_dmaq(struct efx_nic *efx);
727e283546cSEdward Cree void efx_farch_finish_flr(struct efx_nic *efx);
72800aef986SJoe Perches void siena_finish_flush(struct efx_nic *efx);
72900aef986SJoe Perches void falcon_start_nic_stats(struct efx_nic *efx);
73000aef986SJoe Perches void falcon_stop_nic_stats(struct efx_nic *efx);
73100aef986SJoe Perches int falcon_reset_xaui(struct efx_nic *efx);
73200aef986SJoe Perches void efx_farch_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw);
73300aef986SJoe Perches void efx_farch_init_common(struct efx_nic *efx);
73400aef986SJoe Perches void efx_ef10_handle_drain_event(struct efx_nic *efx);
73500aef986SJoe Perches void efx_farch_rx_push_indir_table(struct efx_nic *efx);
736874aeea5SJeff Kirsher 
737874aeea5SJeff Kirsher int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
7380d19a540SBen Hutchings 			 unsigned int len, gfp_t gfp_flags);
739874aeea5SJeff Kirsher void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer);
740874aeea5SJeff Kirsher 
741874aeea5SJeff Kirsher /* Tests */
74286094f7fSBen Hutchings struct efx_farch_register_test {
743874aeea5SJeff Kirsher 	unsigned address;
744874aeea5SJeff Kirsher 	efx_oword_t mask;
745874aeea5SJeff Kirsher };
74600aef986SJoe Perches int efx_farch_test_registers(struct efx_nic *efx,
74786094f7fSBen Hutchings 			     const struct efx_farch_register_test *regs,
748874aeea5SJeff Kirsher 			     size_t n_regs);
749874aeea5SJeff Kirsher 
75000aef986SJoe Perches size_t efx_nic_get_regs_len(struct efx_nic *efx);
75100aef986SJoe Perches void efx_nic_get_regs(struct efx_nic *efx, void *buf);
752874aeea5SJeff Kirsher 
75300aef986SJoe Perches size_t efx_nic_describe_stats(const struct efx_hw_stat_desc *desc, size_t count,
754cd0ecc9aSBen Hutchings 			      const unsigned long *mask, u8 *names);
75500aef986SJoe Perches void efx_nic_update_stats(const struct efx_hw_stat_desc *desc, size_t count,
75600aef986SJoe Perches 			  const unsigned long *mask, u64 *stats,
75700aef986SJoe Perches 			  const void *dma_buf, bool accumulate);
758f8f3b5aeSJon Cooper void efx_nic_fix_nodesc_drop_stat(struct efx_nic *efx, u64 *stat);
759cd0ecc9aSBen Hutchings 
760ab0115fcSBen Hutchings #define EFX_MAX_FLUSH_TIME 5000
761874aeea5SJeff Kirsher 
76200aef986SJoe Perches void efx_farch_generate_event(struct efx_nic *efx, unsigned int evq,
763874aeea5SJeff Kirsher 			      efx_qword_t *event);
764874aeea5SJeff Kirsher 
765874aeea5SJeff Kirsher #endif /* EFX_NIC_H */
766