xref: /openbmc/linux/drivers/net/ethernet/sfc/nic.h (revision ecd0a6f0)
1874aeea5SJeff Kirsher /****************************************************************************
2874aeea5SJeff Kirsher  * Driver for Solarflare Solarstorm network controllers and boards
3874aeea5SJeff Kirsher  * Copyright 2005-2006 Fen Systems Ltd.
4874aeea5SJeff Kirsher  * Copyright 2006-2011 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 #include "spi.h"
20874aeea5SJeff Kirsher 
21874aeea5SJeff Kirsher /*
22874aeea5SJeff Kirsher  * Falcon hardware control
23874aeea5SJeff Kirsher  */
24874aeea5SJeff Kirsher 
25874aeea5SJeff Kirsher enum {
26874aeea5SJeff Kirsher 	EFX_REV_FALCON_A0 = 0,
27874aeea5SJeff Kirsher 	EFX_REV_FALCON_A1 = 1,
28874aeea5SJeff Kirsher 	EFX_REV_FALCON_B0 = 2,
29874aeea5SJeff Kirsher 	EFX_REV_SIENA_A0 = 3,
30874aeea5SJeff Kirsher };
31874aeea5SJeff Kirsher 
32874aeea5SJeff Kirsher static inline int efx_nic_rev(struct efx_nic *efx)
33874aeea5SJeff Kirsher {
34874aeea5SJeff Kirsher 	return efx->type->revision;
35874aeea5SJeff Kirsher }
36874aeea5SJeff Kirsher 
3786094f7fSBen Hutchings extern u32 efx_farch_fpga_ver(struct efx_nic *efx);
38874aeea5SJeff Kirsher 
39874aeea5SJeff Kirsher /* NIC has two interlinked PCI functions for the same port. */
40874aeea5SJeff Kirsher static inline bool efx_nic_is_dual_func(struct efx_nic *efx)
41874aeea5SJeff Kirsher {
42874aeea5SJeff Kirsher 	return efx_nic_rev(efx) < EFX_REV_FALCON_B0;
43874aeea5SJeff Kirsher }
44874aeea5SJeff Kirsher 
4586094f7fSBen Hutchings /* Read the current event from the event queue */
4686094f7fSBen Hutchings static inline efx_qword_t *efx_event(struct efx_channel *channel,
4786094f7fSBen Hutchings 				     unsigned int index)
4886094f7fSBen Hutchings {
4986094f7fSBen Hutchings 	return ((efx_qword_t *) (channel->eventq.buf.addr)) +
5086094f7fSBen Hutchings 		(index & channel->eventq_mask);
5186094f7fSBen Hutchings }
5286094f7fSBen Hutchings 
5386094f7fSBen Hutchings /* See if an event is present
5486094f7fSBen Hutchings  *
5586094f7fSBen Hutchings  * We check both the high and low dword of the event for all ones.  We
5686094f7fSBen Hutchings  * wrote all ones when we cleared the event, and no valid event can
5786094f7fSBen Hutchings  * have all ones in either its high or low dwords.  This approach is
5886094f7fSBen Hutchings  * robust against reordering.
5986094f7fSBen Hutchings  *
6086094f7fSBen Hutchings  * Note that using a single 64-bit comparison is incorrect; even
6186094f7fSBen Hutchings  * though the CPU read will be atomic, the DMA write may not be.
6286094f7fSBen Hutchings  */
6386094f7fSBen Hutchings static inline int efx_event_present(efx_qword_t *event)
6486094f7fSBen Hutchings {
6586094f7fSBen Hutchings 	return !(EFX_DWORD_IS_ALL_ONES(event->dword[0]) |
6686094f7fSBen Hutchings 		  EFX_DWORD_IS_ALL_ONES(event->dword[1]));
6786094f7fSBen Hutchings }
6886094f7fSBen Hutchings 
6986094f7fSBen Hutchings /* Returns a pointer to the specified transmit descriptor in the TX
7086094f7fSBen Hutchings  * descriptor queue belonging to the specified channel.
7186094f7fSBen Hutchings  */
7286094f7fSBen Hutchings static inline efx_qword_t *
7386094f7fSBen Hutchings efx_tx_desc(struct efx_tx_queue *tx_queue, unsigned int index)
7486094f7fSBen Hutchings {
7586094f7fSBen Hutchings 	return ((efx_qword_t *) (tx_queue->txd.buf.addr)) + index;
7686094f7fSBen Hutchings }
7786094f7fSBen Hutchings 
7886094f7fSBen Hutchings /* Decide whether to push a TX descriptor to the NIC vs merely writing
7986094f7fSBen Hutchings  * the doorbell.  This can reduce latency when we are adding a single
8086094f7fSBen Hutchings  * descriptor to an empty queue, but is otherwise pointless.  Further,
8186094f7fSBen Hutchings  * Falcon and Siena have hardware bugs (SF bug 33851) that may be
8286094f7fSBen Hutchings  * triggered if we don't check this.
8386094f7fSBen Hutchings  */
8486094f7fSBen Hutchings static inline bool efx_nic_may_push_tx_desc(struct efx_tx_queue *tx_queue,
8586094f7fSBen Hutchings 					    unsigned int write_count)
8686094f7fSBen Hutchings {
8786094f7fSBen Hutchings 	unsigned empty_read_count = ACCESS_ONCE(tx_queue->empty_read_count);
8886094f7fSBen Hutchings 
8986094f7fSBen Hutchings 	if (empty_read_count == 0)
9086094f7fSBen Hutchings 		return false;
9186094f7fSBen Hutchings 
9286094f7fSBen Hutchings 	tx_queue->empty_read_count = 0;
9386094f7fSBen Hutchings 	return ((empty_read_count ^ write_count) & ~EFX_EMPTY_COUNT_VALID) == 0
9486094f7fSBen Hutchings 		&& tx_queue->write_count - write_count == 1;
9586094f7fSBen Hutchings }
9686094f7fSBen Hutchings 
9786094f7fSBen Hutchings /* Returns a pointer to the specified descriptor in the RX descriptor queue */
9886094f7fSBen Hutchings static inline efx_qword_t *
9986094f7fSBen Hutchings efx_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
10086094f7fSBen Hutchings {
10186094f7fSBen Hutchings 	return ((efx_qword_t *) (rx_queue->rxd.buf.addr)) + index;
10286094f7fSBen Hutchings }
10386094f7fSBen Hutchings 
104874aeea5SJeff Kirsher enum {
105874aeea5SJeff Kirsher 	PHY_TYPE_NONE = 0,
106874aeea5SJeff Kirsher 	PHY_TYPE_TXC43128 = 1,
107874aeea5SJeff Kirsher 	PHY_TYPE_88E1111 = 2,
108874aeea5SJeff Kirsher 	PHY_TYPE_SFX7101 = 3,
109874aeea5SJeff Kirsher 	PHY_TYPE_QT2022C2 = 4,
110874aeea5SJeff Kirsher 	PHY_TYPE_PM8358 = 6,
111874aeea5SJeff Kirsher 	PHY_TYPE_SFT9001A = 8,
112874aeea5SJeff Kirsher 	PHY_TYPE_QT2025C = 9,
113874aeea5SJeff Kirsher 	PHY_TYPE_SFT9001B = 10,
114874aeea5SJeff Kirsher };
115874aeea5SJeff Kirsher 
116874aeea5SJeff Kirsher #define FALCON_XMAC_LOOPBACKS			\
117874aeea5SJeff Kirsher 	((1 << LOOPBACK_XGMII) |		\
118874aeea5SJeff Kirsher 	 (1 << LOOPBACK_XGXS) |			\
119874aeea5SJeff Kirsher 	 (1 << LOOPBACK_XAUI))
120874aeea5SJeff Kirsher 
121874aeea5SJeff Kirsher #define FALCON_GMAC_LOOPBACKS			\
122874aeea5SJeff Kirsher 	(1 << LOOPBACK_GMAC)
123874aeea5SJeff Kirsher 
1245b6262d0SBen Hutchings /* Alignment of PCIe DMA boundaries (4KB) */
1255b6262d0SBen Hutchings #define EFX_PAGE_SIZE	4096
1265b6262d0SBen Hutchings /* Size and alignment of buffer table entries (same) */
1275b6262d0SBen Hutchings #define EFX_BUF_SIZE	EFX_PAGE_SIZE
1285b6262d0SBen Hutchings 
129874aeea5SJeff Kirsher /**
130874aeea5SJeff Kirsher  * struct falcon_board_type - board operations and type information
131874aeea5SJeff Kirsher  * @id: Board type id, as found in NVRAM
132874aeea5SJeff Kirsher  * @init: Allocate resources and initialise peripheral hardware
133874aeea5SJeff Kirsher  * @init_phy: Do board-specific PHY initialisation
134874aeea5SJeff Kirsher  * @fini: Shut down hardware and free resources
135874aeea5SJeff Kirsher  * @set_id_led: Set state of identifying LED or revert to automatic function
136874aeea5SJeff Kirsher  * @monitor: Board-specific health check function
137874aeea5SJeff Kirsher  */
138874aeea5SJeff Kirsher struct falcon_board_type {
139874aeea5SJeff Kirsher 	u8 id;
140874aeea5SJeff Kirsher 	int (*init) (struct efx_nic *nic);
141874aeea5SJeff Kirsher 	void (*init_phy) (struct efx_nic *efx);
142874aeea5SJeff Kirsher 	void (*fini) (struct efx_nic *nic);
143874aeea5SJeff Kirsher 	void (*set_id_led) (struct efx_nic *efx, enum efx_led_mode mode);
144874aeea5SJeff Kirsher 	int (*monitor) (struct efx_nic *nic);
145874aeea5SJeff Kirsher };
146874aeea5SJeff Kirsher 
147874aeea5SJeff Kirsher /**
148874aeea5SJeff Kirsher  * struct falcon_board - board information
149874aeea5SJeff Kirsher  * @type: Type of board
150874aeea5SJeff Kirsher  * @major: Major rev. ('A', 'B' ...)
151874aeea5SJeff Kirsher  * @minor: Minor rev. (0, 1, ...)
152874aeea5SJeff Kirsher  * @i2c_adap: I2C adapter for on-board peripherals
153874aeea5SJeff Kirsher  * @i2c_data: Data for bit-banging algorithm
154874aeea5SJeff Kirsher  * @hwmon_client: I2C client for hardware monitor
155874aeea5SJeff Kirsher  * @ioexp_client: I2C client for power/port control
156874aeea5SJeff Kirsher  */
157874aeea5SJeff Kirsher struct falcon_board {
158874aeea5SJeff Kirsher 	const struct falcon_board_type *type;
159874aeea5SJeff Kirsher 	int major;
160874aeea5SJeff Kirsher 	int minor;
161874aeea5SJeff Kirsher 	struct i2c_adapter i2c_adap;
162874aeea5SJeff Kirsher 	struct i2c_algo_bit_data i2c_data;
163874aeea5SJeff Kirsher 	struct i2c_client *hwmon_client, *ioexp_client;
164874aeea5SJeff Kirsher };
165874aeea5SJeff Kirsher 
166874aeea5SJeff Kirsher /**
167874aeea5SJeff Kirsher  * struct falcon_nic_data - Falcon NIC state
168874aeea5SJeff Kirsher  * @pci_dev2: Secondary function of Falcon A
169874aeea5SJeff Kirsher  * @board: Board state and functions
170874aeea5SJeff Kirsher  * @stats_disable_count: Nest count for disabling statistics fetches
171874aeea5SJeff Kirsher  * @stats_pending: Is there a pending DMA of MAC statistics.
172874aeea5SJeff Kirsher  * @stats_timer: A timer for regularly fetching MAC statistics.
173874aeea5SJeff Kirsher  * @stats_dma_done: Pointer to the flag which indicates DMA completion.
174874aeea5SJeff Kirsher  * @spi_flash: SPI flash device
175874aeea5SJeff Kirsher  * @spi_eeprom: SPI EEPROM device
176874aeea5SJeff Kirsher  * @spi_lock: SPI bus lock
177874aeea5SJeff Kirsher  * @mdio_lock: MDIO bus lock
178874aeea5SJeff Kirsher  * @xmac_poll_required: XMAC link state needs polling
179874aeea5SJeff Kirsher  */
180874aeea5SJeff Kirsher struct falcon_nic_data {
181874aeea5SJeff Kirsher 	struct pci_dev *pci_dev2;
182874aeea5SJeff Kirsher 	struct falcon_board board;
183874aeea5SJeff Kirsher 	unsigned int stats_disable_count;
184874aeea5SJeff Kirsher 	bool stats_pending;
185874aeea5SJeff Kirsher 	struct timer_list stats_timer;
186874aeea5SJeff Kirsher 	u32 *stats_dma_done;
187ecd0a6f0SBen Hutchings 	struct falcon_spi_device spi_flash;
188ecd0a6f0SBen Hutchings 	struct falcon_spi_device spi_eeprom;
189874aeea5SJeff Kirsher 	struct mutex spi_lock;
190874aeea5SJeff Kirsher 	struct mutex mdio_lock;
191874aeea5SJeff Kirsher 	bool xmac_poll_required;
192874aeea5SJeff Kirsher };
193874aeea5SJeff Kirsher 
194874aeea5SJeff Kirsher static inline struct falcon_board *falcon_board(struct efx_nic *efx)
195874aeea5SJeff Kirsher {
196874aeea5SJeff Kirsher 	struct falcon_nic_data *data = efx->nic_data;
197874aeea5SJeff Kirsher 	return &data->board;
198874aeea5SJeff Kirsher }
199874aeea5SJeff Kirsher 
200874aeea5SJeff Kirsher /**
201874aeea5SJeff Kirsher  * struct siena_nic_data - Siena NIC state
202874aeea5SJeff Kirsher  * @wol_filter_id: Wake-on-LAN packet filter id
203874aeea5SJeff Kirsher  */
204874aeea5SJeff Kirsher struct siena_nic_data {
205874aeea5SJeff Kirsher 	int wol_filter_id;
206874aeea5SJeff Kirsher };
207874aeea5SJeff Kirsher 
208cd2d5b52SBen Hutchings /*
209cd2d5b52SBen Hutchings  * On the SFC9000 family each port is associated with 1 PCI physical
210cd2d5b52SBen Hutchings  * function (PF) handled by sfc and a configurable number of virtual
211cd2d5b52SBen Hutchings  * functions (VFs) that may be handled by some other driver, often in
212cd2d5b52SBen Hutchings  * a VM guest.  The queue pointer registers are mapped in both PF and
213cd2d5b52SBen Hutchings  * VF BARs such that an 8K region provides access to a single RX, TX
214cd2d5b52SBen Hutchings  * and event queue (collectively a Virtual Interface, VI or VNIC).
215cd2d5b52SBen Hutchings  *
216cd2d5b52SBen Hutchings  * The PF has access to all 1024 VIs while VFs are mapped to VIs
217cd2d5b52SBen Hutchings  * according to VI_BASE and VI_SCALE: VF i has access to VIs numbered
218cd2d5b52SBen Hutchings  * in range [VI_BASE + i << VI_SCALE, VI_BASE + i + 1 << VI_SCALE).
219cd2d5b52SBen Hutchings  * The number of VIs and the VI_SCALE value are configurable but must
220cd2d5b52SBen Hutchings  * be established at boot time by firmware.
221cd2d5b52SBen Hutchings  */
222cd2d5b52SBen Hutchings 
223cd2d5b52SBen Hutchings /* Maximum VI_SCALE parameter supported by Siena */
224cd2d5b52SBen Hutchings #define EFX_VI_SCALE_MAX 6
225cd2d5b52SBen Hutchings /* Base VI to use for SR-IOV. Must be aligned to (1 << EFX_VI_SCALE_MAX),
226cd2d5b52SBen Hutchings  * so this is the smallest allowed value. */
227cd2d5b52SBen Hutchings #define EFX_VI_BASE 128U
228cd2d5b52SBen Hutchings /* Maximum number of VFs allowed */
229cd2d5b52SBen Hutchings #define EFX_VF_COUNT_MAX 127
230cd2d5b52SBen Hutchings /* Limit EVQs on VFs to be only 8k to reduce buffer table reservation */
231cd2d5b52SBen Hutchings #define EFX_MAX_VF_EVQ_SIZE 8192UL
232cd2d5b52SBen Hutchings /* The number of buffer table entries reserved for each VI on a VF */
233cd2d5b52SBen Hutchings #define EFX_VF_BUFTBL_PER_VI					\
234cd2d5b52SBen Hutchings 	((EFX_MAX_VF_EVQ_SIZE + 2 * EFX_MAX_DMAQ_SIZE) *	\
235cd2d5b52SBen Hutchings 	 sizeof(efx_qword_t) / EFX_BUF_SIZE)
236cd2d5b52SBen Hutchings 
237cd2d5b52SBen Hutchings #ifdef CONFIG_SFC_SRIOV
238cd2d5b52SBen Hutchings 
239cd2d5b52SBen Hutchings static inline bool efx_sriov_wanted(struct efx_nic *efx)
240cd2d5b52SBen Hutchings {
241cd2d5b52SBen Hutchings 	return efx->vf_count != 0;
242cd2d5b52SBen Hutchings }
243cd2d5b52SBen Hutchings static inline bool efx_sriov_enabled(struct efx_nic *efx)
244cd2d5b52SBen Hutchings {
245cd2d5b52SBen Hutchings 	return efx->vf_init_count != 0;
246cd2d5b52SBen Hutchings }
247cd2d5b52SBen Hutchings static inline unsigned int efx_vf_size(struct efx_nic *efx)
248cd2d5b52SBen Hutchings {
249cd2d5b52SBen Hutchings 	return 1 << efx->vi_scale;
250cd2d5b52SBen Hutchings }
251cd2d5b52SBen Hutchings 
252cd2d5b52SBen Hutchings extern int efx_init_sriov(void);
253cd2d5b52SBen Hutchings extern void efx_sriov_probe(struct efx_nic *efx);
254cd2d5b52SBen Hutchings extern int efx_sriov_init(struct efx_nic *efx);
255cd2d5b52SBen Hutchings extern void efx_sriov_mac_address_changed(struct efx_nic *efx);
256cd2d5b52SBen Hutchings extern void efx_sriov_tx_flush_done(struct efx_nic *efx, efx_qword_t *event);
257cd2d5b52SBen Hutchings extern void efx_sriov_rx_flush_done(struct efx_nic *efx, efx_qword_t *event);
258cd2d5b52SBen Hutchings extern void efx_sriov_event(struct efx_channel *channel, efx_qword_t *event);
259cd2d5b52SBen Hutchings extern void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq);
260cd2d5b52SBen Hutchings extern void efx_sriov_flr(struct efx_nic *efx, unsigned flr);
261cd2d5b52SBen Hutchings extern void efx_sriov_reset(struct efx_nic *efx);
262cd2d5b52SBen Hutchings extern void efx_sriov_fini(struct efx_nic *efx);
263cd2d5b52SBen Hutchings extern void efx_fini_sriov(void);
264cd2d5b52SBen Hutchings 
265cd2d5b52SBen Hutchings #else
266cd2d5b52SBen Hutchings 
267cd2d5b52SBen Hutchings static inline bool efx_sriov_wanted(struct efx_nic *efx) { return false; }
268cd2d5b52SBen Hutchings static inline bool efx_sriov_enabled(struct efx_nic *efx) { return false; }
269cd2d5b52SBen Hutchings static inline unsigned int efx_vf_size(struct efx_nic *efx) { return 0; }
270cd2d5b52SBen Hutchings 
271cd2d5b52SBen Hutchings static inline int efx_init_sriov(void) { return 0; }
272cd2d5b52SBen Hutchings static inline void efx_sriov_probe(struct efx_nic *efx) {}
273cd2d5b52SBen Hutchings static inline int efx_sriov_init(struct efx_nic *efx) { return -EOPNOTSUPP; }
274cd2d5b52SBen Hutchings static inline void efx_sriov_mac_address_changed(struct efx_nic *efx) {}
275cd2d5b52SBen Hutchings static inline void efx_sriov_tx_flush_done(struct efx_nic *efx,
276cd2d5b52SBen Hutchings 					   efx_qword_t *event) {}
277cd2d5b52SBen Hutchings static inline void efx_sriov_rx_flush_done(struct efx_nic *efx,
278cd2d5b52SBen Hutchings 					   efx_qword_t *event) {}
279cd2d5b52SBen Hutchings static inline void efx_sriov_event(struct efx_channel *channel,
280cd2d5b52SBen Hutchings 				   efx_qword_t *event) {}
281cd2d5b52SBen Hutchings static inline void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq) {}
282cd2d5b52SBen Hutchings static inline void efx_sriov_flr(struct efx_nic *efx, unsigned flr) {}
283cd2d5b52SBen Hutchings static inline void efx_sriov_reset(struct efx_nic *efx) {}
284cd2d5b52SBen Hutchings static inline void efx_sriov_fini(struct efx_nic *efx) {}
285cd2d5b52SBen Hutchings static inline void efx_fini_sriov(void) {}
286cd2d5b52SBen Hutchings 
287cd2d5b52SBen Hutchings #endif
288cd2d5b52SBen Hutchings 
289cd2d5b52SBen Hutchings extern int efx_sriov_set_vf_mac(struct net_device *dev, int vf, u8 *mac);
290cd2d5b52SBen Hutchings extern int efx_sriov_set_vf_vlan(struct net_device *dev, int vf,
291cd2d5b52SBen Hutchings 				 u16 vlan, u8 qos);
292cd2d5b52SBen Hutchings extern int efx_sriov_get_vf_config(struct net_device *dev, int vf,
293cd2d5b52SBen Hutchings 				   struct ifla_vf_info *ivf);
294cd2d5b52SBen Hutchings extern int efx_sriov_set_vf_spoofchk(struct net_device *net_dev, int vf,
295cd2d5b52SBen Hutchings 				     bool spoofchk);
296cd2d5b52SBen Hutchings 
2977c236c43SStuart Hodgson struct ethtool_ts_info;
2987c236c43SStuart Hodgson extern void efx_ptp_probe(struct efx_nic *efx);
2997c236c43SStuart Hodgson extern int efx_ptp_ioctl(struct efx_nic *efx, struct ifreq *ifr, int cmd);
30062ebac92SBen Hutchings extern void efx_ptp_get_ts_info(struct efx_nic *efx,
3017c236c43SStuart Hodgson 				struct ethtool_ts_info *ts_info);
3027c236c43SStuart Hodgson extern bool efx_ptp_is_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
3037c236c43SStuart Hodgson extern int efx_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
3047c236c43SStuart Hodgson extern void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev);
3057c236c43SStuart Hodgson 
306874aeea5SJeff Kirsher extern const struct efx_nic_type falcon_a1_nic_type;
307874aeea5SJeff Kirsher extern const struct efx_nic_type falcon_b0_nic_type;
308874aeea5SJeff Kirsher extern const struct efx_nic_type siena_a0_nic_type;
309874aeea5SJeff Kirsher 
310874aeea5SJeff Kirsher /**************************************************************************
311874aeea5SJeff Kirsher  *
312874aeea5SJeff Kirsher  * Externs
313874aeea5SJeff Kirsher  *
314874aeea5SJeff Kirsher  **************************************************************************
315874aeea5SJeff Kirsher  */
316874aeea5SJeff Kirsher 
317874aeea5SJeff Kirsher extern int falcon_probe_board(struct efx_nic *efx, u16 revision_info);
318874aeea5SJeff Kirsher 
319874aeea5SJeff Kirsher /* TX data path */
32086094f7fSBen Hutchings static inline int efx_nic_probe_tx(struct efx_tx_queue *tx_queue)
32186094f7fSBen Hutchings {
32286094f7fSBen Hutchings 	return tx_queue->efx->type->tx_probe(tx_queue);
32386094f7fSBen Hutchings }
32486094f7fSBen Hutchings static inline void efx_nic_init_tx(struct efx_tx_queue *tx_queue)
32586094f7fSBen Hutchings {
32686094f7fSBen Hutchings 	tx_queue->efx->type->tx_init(tx_queue);
32786094f7fSBen Hutchings }
32886094f7fSBen Hutchings static inline void efx_nic_remove_tx(struct efx_tx_queue *tx_queue)
32986094f7fSBen Hutchings {
33086094f7fSBen Hutchings 	tx_queue->efx->type->tx_remove(tx_queue);
33186094f7fSBen Hutchings }
33286094f7fSBen Hutchings static inline void efx_nic_push_buffers(struct efx_tx_queue *tx_queue)
33386094f7fSBen Hutchings {
33486094f7fSBen Hutchings 	tx_queue->efx->type->tx_write(tx_queue);
33586094f7fSBen Hutchings }
336874aeea5SJeff Kirsher 
337874aeea5SJeff Kirsher /* RX data path */
33886094f7fSBen Hutchings static inline int efx_nic_probe_rx(struct efx_rx_queue *rx_queue)
33986094f7fSBen Hutchings {
34086094f7fSBen Hutchings 	return rx_queue->efx->type->rx_probe(rx_queue);
34186094f7fSBen Hutchings }
34286094f7fSBen Hutchings static inline void efx_nic_init_rx(struct efx_rx_queue *rx_queue)
34386094f7fSBen Hutchings {
34486094f7fSBen Hutchings 	rx_queue->efx->type->rx_init(rx_queue);
34586094f7fSBen Hutchings }
34686094f7fSBen Hutchings static inline void efx_nic_remove_rx(struct efx_rx_queue *rx_queue)
34786094f7fSBen Hutchings {
34886094f7fSBen Hutchings 	rx_queue->efx->type->rx_remove(rx_queue);
34986094f7fSBen Hutchings }
35086094f7fSBen Hutchings static inline void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue)
35186094f7fSBen Hutchings {
35286094f7fSBen Hutchings 	rx_queue->efx->type->rx_write(rx_queue);
35386094f7fSBen Hutchings }
35486094f7fSBen Hutchings static inline void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue)
35586094f7fSBen Hutchings {
35686094f7fSBen Hutchings 	rx_queue->efx->type->rx_defer_refill(rx_queue);
35786094f7fSBen Hutchings }
358874aeea5SJeff Kirsher 
359874aeea5SJeff Kirsher /* Event data path */
36086094f7fSBen Hutchings static inline int efx_nic_probe_eventq(struct efx_channel *channel)
36186094f7fSBen Hutchings {
36286094f7fSBen Hutchings 	return channel->efx->type->ev_probe(channel);
36386094f7fSBen Hutchings }
36486094f7fSBen Hutchings static inline void efx_nic_init_eventq(struct efx_channel *channel)
36586094f7fSBen Hutchings {
36686094f7fSBen Hutchings 	channel->efx->type->ev_init(channel);
36786094f7fSBen Hutchings }
36886094f7fSBen Hutchings static inline void efx_nic_fini_eventq(struct efx_channel *channel)
36986094f7fSBen Hutchings {
37086094f7fSBen Hutchings 	channel->efx->type->ev_fini(channel);
37186094f7fSBen Hutchings }
37286094f7fSBen Hutchings static inline void efx_nic_remove_eventq(struct efx_channel *channel)
37386094f7fSBen Hutchings {
37486094f7fSBen Hutchings 	channel->efx->type->ev_remove(channel);
37586094f7fSBen Hutchings }
37686094f7fSBen Hutchings static inline int
37786094f7fSBen Hutchings efx_nic_process_eventq(struct efx_channel *channel, int quota)
37886094f7fSBen Hutchings {
37986094f7fSBen Hutchings 	return channel->efx->type->ev_process(channel, quota);
38086094f7fSBen Hutchings }
38186094f7fSBen Hutchings static inline void efx_nic_eventq_read_ack(struct efx_channel *channel)
38286094f7fSBen Hutchings {
38386094f7fSBen Hutchings 	channel->efx->type->ev_read_ack(channel);
38486094f7fSBen Hutchings }
38586094f7fSBen Hutchings extern void efx_nic_event_test_start(struct efx_channel *channel);
38686094f7fSBen Hutchings 
38786094f7fSBen Hutchings /* Falcon/Siena queue operations */
38886094f7fSBen Hutchings extern int efx_farch_tx_probe(struct efx_tx_queue *tx_queue);
38986094f7fSBen Hutchings extern void efx_farch_tx_init(struct efx_tx_queue *tx_queue);
39086094f7fSBen Hutchings extern void efx_farch_tx_fini(struct efx_tx_queue *tx_queue);
39186094f7fSBen Hutchings extern void efx_farch_tx_remove(struct efx_tx_queue *tx_queue);
39286094f7fSBen Hutchings extern void efx_farch_tx_write(struct efx_tx_queue *tx_queue);
39386094f7fSBen Hutchings extern int efx_farch_rx_probe(struct efx_rx_queue *rx_queue);
39486094f7fSBen Hutchings extern void efx_farch_rx_init(struct efx_rx_queue *rx_queue);
39586094f7fSBen Hutchings extern void efx_farch_rx_fini(struct efx_rx_queue *rx_queue);
39686094f7fSBen Hutchings extern void efx_farch_rx_remove(struct efx_rx_queue *rx_queue);
39786094f7fSBen Hutchings extern void efx_farch_rx_write(struct efx_rx_queue *rx_queue);
39886094f7fSBen Hutchings extern void efx_farch_rx_defer_refill(struct efx_rx_queue *rx_queue);
39986094f7fSBen Hutchings extern int efx_farch_ev_probe(struct efx_channel *channel);
40086094f7fSBen Hutchings extern void efx_farch_ev_init(struct efx_channel *channel);
40186094f7fSBen Hutchings extern void efx_farch_ev_fini(struct efx_channel *channel);
40286094f7fSBen Hutchings extern void efx_farch_ev_remove(struct efx_channel *channel);
40386094f7fSBen Hutchings extern int efx_farch_ev_process(struct efx_channel *channel, int quota);
40486094f7fSBen Hutchings extern void efx_farch_ev_read_ack(struct efx_channel *channel);
40586094f7fSBen Hutchings extern void efx_farch_ev_test_generate(struct efx_channel *channel);
40686094f7fSBen Hutchings 
407add72477SBen Hutchings /* Falcon/Siena filter operations */
408add72477SBen Hutchings extern int efx_farch_filter_table_probe(struct efx_nic *efx);
409add72477SBen Hutchings extern void efx_farch_filter_table_restore(struct efx_nic *efx);
410add72477SBen Hutchings extern void efx_farch_filter_table_remove(struct efx_nic *efx);
411add72477SBen Hutchings extern void efx_farch_filter_update_rx_scatter(struct efx_nic *efx);
412add72477SBen Hutchings extern s32 efx_farch_filter_insert(struct efx_nic *efx,
413add72477SBen Hutchings 				   struct efx_filter_spec *spec, bool replace);
414add72477SBen Hutchings extern int efx_farch_filter_remove_safe(struct efx_nic *efx,
415add72477SBen Hutchings 					enum efx_filter_priority priority,
416add72477SBen Hutchings 					u32 filter_id);
417add72477SBen Hutchings extern int efx_farch_filter_get_safe(struct efx_nic *efx,
418add72477SBen Hutchings 				     enum efx_filter_priority priority,
419add72477SBen Hutchings 				     u32 filter_id, struct efx_filter_spec *);
420add72477SBen Hutchings extern void efx_farch_filter_clear_rx(struct efx_nic *efx,
421add72477SBen Hutchings 				      enum efx_filter_priority priority);
422add72477SBen Hutchings extern u32 efx_farch_filter_count_rx_used(struct efx_nic *efx,
423add72477SBen Hutchings 					  enum efx_filter_priority priority);
424add72477SBen Hutchings extern u32 efx_farch_filter_get_rx_id_limit(struct efx_nic *efx);
425add72477SBen Hutchings extern s32 efx_farch_filter_get_rx_ids(struct efx_nic *efx,
426add72477SBen Hutchings 				       enum efx_filter_priority priority,
427add72477SBen Hutchings 				       u32 *buf, u32 size);
428add72477SBen Hutchings #ifdef CONFIG_RFS_ACCEL
429add72477SBen Hutchings extern s32 efx_farch_filter_rfs_insert(struct efx_nic *efx,
430add72477SBen Hutchings 				       struct efx_filter_spec *spec);
431add72477SBen Hutchings extern bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
432add72477SBen Hutchings 					    unsigned int index);
433add72477SBen Hutchings #endif
434964e6135SBen Hutchings extern void efx_farch_filter_sync_rx_mode(struct efx_nic *efx);
435add72477SBen Hutchings 
436874aeea5SJeff Kirsher extern bool efx_nic_event_present(struct efx_channel *channel);
437874aeea5SJeff Kirsher 
438b7f514afSBen Hutchings /* Some statistics are computed as A - B where A and B each increase
439b7f514afSBen Hutchings  * linearly with some hardware counter(s) and the counters are read
440b7f514afSBen Hutchings  * asynchronously.  If the counters contributing to B are always read
441b7f514afSBen Hutchings  * after those contributing to A, the computed value may be lower than
442b7f514afSBen Hutchings  * the true value by some variable amount, and may decrease between
443b7f514afSBen Hutchings  * subsequent computations.
444b7f514afSBen Hutchings  *
445b7f514afSBen Hutchings  * We should never allow statistics to decrease or to exceed the true
446b7f514afSBen Hutchings  * value.  Since the computed value will never be greater than the
447b7f514afSBen Hutchings  * true value, we can achieve this by only storing the computed value
448b7f514afSBen Hutchings  * when it increases.
449b7f514afSBen Hutchings  */
450b7f514afSBen Hutchings static inline void efx_update_diff_stat(u64 *stat, u64 diff)
451b7f514afSBen Hutchings {
452b7f514afSBen Hutchings 	if ((s64)(diff - *stat) > 0)
453b7f514afSBen Hutchings 		*stat = diff;
454b7f514afSBen Hutchings }
455b7f514afSBen Hutchings 
45686094f7fSBen Hutchings /* Interrupts */
457874aeea5SJeff Kirsher extern int efx_nic_init_interrupt(struct efx_nic *efx);
458eee6f6a9SBen Hutchings extern void efx_nic_irq_test_start(struct efx_nic *efx);
459874aeea5SJeff Kirsher extern void efx_nic_fini_interrupt(struct efx_nic *efx);
46086094f7fSBen Hutchings 
46186094f7fSBen Hutchings /* Falcon/Siena interrupts */
46286094f7fSBen Hutchings extern void efx_farch_irq_enable_master(struct efx_nic *efx);
46386094f7fSBen Hutchings extern void efx_farch_irq_test_generate(struct efx_nic *efx);
46486094f7fSBen Hutchings extern void efx_farch_irq_disable_master(struct efx_nic *efx);
46586094f7fSBen Hutchings extern irqreturn_t efx_farch_msi_interrupt(int irq, void *dev_id);
46686094f7fSBen Hutchings extern irqreturn_t efx_farch_legacy_interrupt(int irq, void *dev_id);
46786094f7fSBen Hutchings extern irqreturn_t efx_farch_fatal_interrupt(struct efx_nic *efx);
468874aeea5SJeff Kirsher 
469eee6f6a9SBen Hutchings static inline int efx_nic_event_test_irq_cpu(struct efx_channel *channel)
470eee6f6a9SBen Hutchings {
471dd40781eSBen Hutchings 	return ACCESS_ONCE(channel->event_test_cpu);
472eee6f6a9SBen Hutchings }
473eee6f6a9SBen Hutchings static inline int efx_nic_irq_test_irq_cpu(struct efx_nic *efx)
474eee6f6a9SBen Hutchings {
475eee6f6a9SBen Hutchings 	return ACCESS_ONCE(efx->last_irq_cpu);
476eee6f6a9SBen Hutchings }
477eee6f6a9SBen Hutchings 
478874aeea5SJeff Kirsher /* Global Resources */
47986094f7fSBen Hutchings extern int efx_nic_flush_queues(struct efx_nic *efx);
480d5e8cc6cSBen Hutchings extern void siena_prepare_flush(struct efx_nic *efx);
48186094f7fSBen Hutchings extern int efx_farch_fini_dmaq(struct efx_nic *efx);
482d5e8cc6cSBen Hutchings extern void siena_finish_flush(struct efx_nic *efx);
483874aeea5SJeff Kirsher extern void falcon_start_nic_stats(struct efx_nic *efx);
484874aeea5SJeff Kirsher extern void falcon_stop_nic_stats(struct efx_nic *efx);
485874aeea5SJeff Kirsher extern int falcon_reset_xaui(struct efx_nic *efx);
48686094f7fSBen Hutchings extern void efx_farch_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw);
48786094f7fSBen Hutchings extern void efx_farch_init_common(struct efx_nic *efx);
48886094f7fSBen Hutchings static inline void efx_nic_push_rx_indir_table(struct efx_nic *efx)
48986094f7fSBen Hutchings {
49086094f7fSBen Hutchings 	efx->type->rx_push_indir_table(efx);
49186094f7fSBen Hutchings }
49286094f7fSBen Hutchings extern void efx_farch_rx_push_indir_table(struct efx_nic *efx);
493874aeea5SJeff Kirsher 
494874aeea5SJeff Kirsher int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
4950d19a540SBen Hutchings 			 unsigned int len, gfp_t gfp_flags);
496874aeea5SJeff Kirsher void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer);
497874aeea5SJeff Kirsher 
498874aeea5SJeff Kirsher /* Tests */
49986094f7fSBen Hutchings struct efx_farch_register_test {
500874aeea5SJeff Kirsher 	unsigned address;
501874aeea5SJeff Kirsher 	efx_oword_t mask;
502874aeea5SJeff Kirsher };
50386094f7fSBen Hutchings extern int efx_farch_test_registers(struct efx_nic *efx,
50486094f7fSBen Hutchings 				    const struct efx_farch_register_test *regs,
505874aeea5SJeff Kirsher 				    size_t n_regs);
506874aeea5SJeff Kirsher 
507874aeea5SJeff Kirsher extern size_t efx_nic_get_regs_len(struct efx_nic *efx);
508874aeea5SJeff Kirsher extern void efx_nic_get_regs(struct efx_nic *efx, void *buf);
509874aeea5SJeff Kirsher 
510ab0115fcSBen Hutchings #define EFX_MAX_FLUSH_TIME 5000
511874aeea5SJeff Kirsher 
51286094f7fSBen Hutchings extern void efx_farch_generate_event(struct efx_nic *efx, unsigned int evq,
513874aeea5SJeff Kirsher 				     efx_qword_t *event);
514874aeea5SJeff Kirsher 
515874aeea5SJeff Kirsher #endif /* EFX_NIC_H */
516