1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /****************************************************************************
3*4882a593Smuzhiyun * Driver for Solarflare network controllers and boards
4*4882a593Smuzhiyun * Copyright 2005-2006 Fen Systems Ltd.
5*4882a593Smuzhiyun * Copyright 2006-2013 Solarflare Communications Inc.
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #ifndef EF4_NIC_H
9*4882a593Smuzhiyun #define EF4_NIC_H
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #include <linux/net_tstamp.h>
12*4882a593Smuzhiyun #include <linux/i2c-algo-bit.h>
13*4882a593Smuzhiyun #include "net_driver.h"
14*4882a593Smuzhiyun #include "efx.h"
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun enum {
17*4882a593Smuzhiyun EF4_REV_FALCON_A0 = 0,
18*4882a593Smuzhiyun EF4_REV_FALCON_A1 = 1,
19*4882a593Smuzhiyun EF4_REV_FALCON_B0 = 2,
20*4882a593Smuzhiyun };
21*4882a593Smuzhiyun
ef4_nic_rev(struct ef4_nic * efx)22*4882a593Smuzhiyun static inline int ef4_nic_rev(struct ef4_nic *efx)
23*4882a593Smuzhiyun {
24*4882a593Smuzhiyun return efx->type->revision;
25*4882a593Smuzhiyun }
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun u32 ef4_farch_fpga_ver(struct ef4_nic *efx);
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun /* NIC has two interlinked PCI functions for the same port. */
ef4_nic_is_dual_func(struct ef4_nic * efx)30*4882a593Smuzhiyun static inline bool ef4_nic_is_dual_func(struct ef4_nic *efx)
31*4882a593Smuzhiyun {
32*4882a593Smuzhiyun return ef4_nic_rev(efx) < EF4_REV_FALCON_B0;
33*4882a593Smuzhiyun }
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun /* Read the current event from the event queue */
ef4_event(struct ef4_channel * channel,unsigned int index)36*4882a593Smuzhiyun static inline ef4_qword_t *ef4_event(struct ef4_channel *channel,
37*4882a593Smuzhiyun unsigned int index)
38*4882a593Smuzhiyun {
39*4882a593Smuzhiyun return ((ef4_qword_t *) (channel->eventq.buf.addr)) +
40*4882a593Smuzhiyun (index & channel->eventq_mask);
41*4882a593Smuzhiyun }
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun /* See if an event is present
44*4882a593Smuzhiyun *
45*4882a593Smuzhiyun * We check both the high and low dword of the event for all ones. We
46*4882a593Smuzhiyun * wrote all ones when we cleared the event, and no valid event can
47*4882a593Smuzhiyun * have all ones in either its high or low dwords. This approach is
48*4882a593Smuzhiyun * robust against reordering.
49*4882a593Smuzhiyun *
50*4882a593Smuzhiyun * Note that using a single 64-bit comparison is incorrect; even
51*4882a593Smuzhiyun * though the CPU read will be atomic, the DMA write may not be.
52*4882a593Smuzhiyun */
ef4_event_present(ef4_qword_t * event)53*4882a593Smuzhiyun static inline int ef4_event_present(ef4_qword_t *event)
54*4882a593Smuzhiyun {
55*4882a593Smuzhiyun return !(EF4_DWORD_IS_ALL_ONES(event->dword[0]) |
56*4882a593Smuzhiyun EF4_DWORD_IS_ALL_ONES(event->dword[1]));
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun /* Returns a pointer to the specified transmit descriptor in the TX
60*4882a593Smuzhiyun * descriptor queue belonging to the specified channel.
61*4882a593Smuzhiyun */
62*4882a593Smuzhiyun static inline ef4_qword_t *
ef4_tx_desc(struct ef4_tx_queue * tx_queue,unsigned int index)63*4882a593Smuzhiyun ef4_tx_desc(struct ef4_tx_queue *tx_queue, unsigned int index)
64*4882a593Smuzhiyun {
65*4882a593Smuzhiyun return ((ef4_qword_t *) (tx_queue->txd.buf.addr)) + index;
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun /* Get partner of a TX queue, seen as part of the same net core queue */
ef4_tx_queue_partner(struct ef4_tx_queue * tx_queue)69*4882a593Smuzhiyun static inline struct ef4_tx_queue *ef4_tx_queue_partner(struct ef4_tx_queue *tx_queue)
70*4882a593Smuzhiyun {
71*4882a593Smuzhiyun if (tx_queue->queue & EF4_TXQ_TYPE_OFFLOAD)
72*4882a593Smuzhiyun return tx_queue - EF4_TXQ_TYPE_OFFLOAD;
73*4882a593Smuzhiyun else
74*4882a593Smuzhiyun return tx_queue + EF4_TXQ_TYPE_OFFLOAD;
75*4882a593Smuzhiyun }
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun /* Report whether this TX queue would be empty for the given write_count.
78*4882a593Smuzhiyun * May return false negative.
79*4882a593Smuzhiyun */
__ef4_nic_tx_is_empty(struct ef4_tx_queue * tx_queue,unsigned int write_count)80*4882a593Smuzhiyun static inline bool __ef4_nic_tx_is_empty(struct ef4_tx_queue *tx_queue,
81*4882a593Smuzhiyun unsigned int write_count)
82*4882a593Smuzhiyun {
83*4882a593Smuzhiyun unsigned int empty_read_count = READ_ONCE(tx_queue->empty_read_count);
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun if (empty_read_count == 0)
86*4882a593Smuzhiyun return false;
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun return ((empty_read_count ^ write_count) & ~EF4_EMPTY_COUNT_VALID) == 0;
89*4882a593Smuzhiyun }
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun /* Decide whether to push a TX descriptor to the NIC vs merely writing
92*4882a593Smuzhiyun * the doorbell. This can reduce latency when we are adding a single
93*4882a593Smuzhiyun * descriptor to an empty queue, but is otherwise pointless. Further,
94*4882a593Smuzhiyun * Falcon and Siena have hardware bugs (SF bug 33851) that may be
95*4882a593Smuzhiyun * triggered if we don't check this.
96*4882a593Smuzhiyun * We use the write_count used for the last doorbell push, to get the
97*4882a593Smuzhiyun * NIC's view of the tx queue.
98*4882a593Smuzhiyun */
ef4_nic_may_push_tx_desc(struct ef4_tx_queue * tx_queue,unsigned int write_count)99*4882a593Smuzhiyun static inline bool ef4_nic_may_push_tx_desc(struct ef4_tx_queue *tx_queue,
100*4882a593Smuzhiyun unsigned int write_count)
101*4882a593Smuzhiyun {
102*4882a593Smuzhiyun bool was_empty = __ef4_nic_tx_is_empty(tx_queue, write_count);
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun tx_queue->empty_read_count = 0;
105*4882a593Smuzhiyun return was_empty && tx_queue->write_count - write_count == 1;
106*4882a593Smuzhiyun }
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun /* Returns a pointer to the specified descriptor in the RX descriptor queue */
109*4882a593Smuzhiyun static inline ef4_qword_t *
ef4_rx_desc(struct ef4_rx_queue * rx_queue,unsigned int index)110*4882a593Smuzhiyun ef4_rx_desc(struct ef4_rx_queue *rx_queue, unsigned int index)
111*4882a593Smuzhiyun {
112*4882a593Smuzhiyun return ((ef4_qword_t *) (rx_queue->rxd.buf.addr)) + index;
113*4882a593Smuzhiyun }
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun enum {
116*4882a593Smuzhiyun PHY_TYPE_NONE = 0,
117*4882a593Smuzhiyun PHY_TYPE_TXC43128 = 1,
118*4882a593Smuzhiyun PHY_TYPE_88E1111 = 2,
119*4882a593Smuzhiyun PHY_TYPE_SFX7101 = 3,
120*4882a593Smuzhiyun PHY_TYPE_QT2022C2 = 4,
121*4882a593Smuzhiyun PHY_TYPE_PM8358 = 6,
122*4882a593Smuzhiyun PHY_TYPE_SFT9001A = 8,
123*4882a593Smuzhiyun PHY_TYPE_QT2025C = 9,
124*4882a593Smuzhiyun PHY_TYPE_SFT9001B = 10,
125*4882a593Smuzhiyun };
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun #define FALCON_XMAC_LOOPBACKS \
128*4882a593Smuzhiyun ((1 << LOOPBACK_XGMII) | \
129*4882a593Smuzhiyun (1 << LOOPBACK_XGXS) | \
130*4882a593Smuzhiyun (1 << LOOPBACK_XAUI))
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun /* Alignment of PCIe DMA boundaries (4KB) */
133*4882a593Smuzhiyun #define EF4_PAGE_SIZE 4096
134*4882a593Smuzhiyun /* Size and alignment of buffer table entries (same) */
135*4882a593Smuzhiyun #define EF4_BUF_SIZE EF4_PAGE_SIZE
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun /* NIC-generic software stats */
138*4882a593Smuzhiyun enum {
139*4882a593Smuzhiyun GENERIC_STAT_rx_noskb_drops,
140*4882a593Smuzhiyun GENERIC_STAT_rx_nodesc_trunc,
141*4882a593Smuzhiyun GENERIC_STAT_COUNT
142*4882a593Smuzhiyun };
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun /**
145*4882a593Smuzhiyun * struct falcon_board_type - board operations and type information
146*4882a593Smuzhiyun * @id: Board type id, as found in NVRAM
147*4882a593Smuzhiyun * @init: Allocate resources and initialise peripheral hardware
148*4882a593Smuzhiyun * @init_phy: Do board-specific PHY initialisation
149*4882a593Smuzhiyun * @fini: Shut down hardware and free resources
150*4882a593Smuzhiyun * @set_id_led: Set state of identifying LED or revert to automatic function
151*4882a593Smuzhiyun * @monitor: Board-specific health check function
152*4882a593Smuzhiyun */
153*4882a593Smuzhiyun struct falcon_board_type {
154*4882a593Smuzhiyun u8 id;
155*4882a593Smuzhiyun int (*init) (struct ef4_nic *nic);
156*4882a593Smuzhiyun void (*init_phy) (struct ef4_nic *efx);
157*4882a593Smuzhiyun void (*fini) (struct ef4_nic *nic);
158*4882a593Smuzhiyun void (*set_id_led) (struct ef4_nic *efx, enum ef4_led_mode mode);
159*4882a593Smuzhiyun int (*monitor) (struct ef4_nic *nic);
160*4882a593Smuzhiyun };
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun /**
163*4882a593Smuzhiyun * struct falcon_board - board information
164*4882a593Smuzhiyun * @type: Type of board
165*4882a593Smuzhiyun * @major: Major rev. ('A', 'B' ...)
166*4882a593Smuzhiyun * @minor: Minor rev. (0, 1, ...)
167*4882a593Smuzhiyun * @i2c_adap: I2C adapter for on-board peripherals
168*4882a593Smuzhiyun * @i2c_data: Data for bit-banging algorithm
169*4882a593Smuzhiyun * @hwmon_client: I2C client for hardware monitor
170*4882a593Smuzhiyun * @ioexp_client: I2C client for power/port control
171*4882a593Smuzhiyun */
172*4882a593Smuzhiyun struct falcon_board {
173*4882a593Smuzhiyun const struct falcon_board_type *type;
174*4882a593Smuzhiyun int major;
175*4882a593Smuzhiyun int minor;
176*4882a593Smuzhiyun struct i2c_adapter i2c_adap;
177*4882a593Smuzhiyun struct i2c_algo_bit_data i2c_data;
178*4882a593Smuzhiyun struct i2c_client *hwmon_client, *ioexp_client;
179*4882a593Smuzhiyun };
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun /**
182*4882a593Smuzhiyun * struct falcon_spi_device - a Falcon SPI (Serial Peripheral Interface) device
183*4882a593Smuzhiyun * @device_id: Controller's id for the device
184*4882a593Smuzhiyun * @size: Size (in bytes)
185*4882a593Smuzhiyun * @addr_len: Number of address bytes in read/write commands
186*4882a593Smuzhiyun * @munge_address: Flag whether addresses should be munged.
187*4882a593Smuzhiyun * Some devices with 9-bit addresses (e.g. AT25040A EEPROM)
188*4882a593Smuzhiyun * use bit 3 of the command byte as address bit A8, rather
189*4882a593Smuzhiyun * than having a two-byte address. If this flag is set, then
190*4882a593Smuzhiyun * commands should be munged in this way.
191*4882a593Smuzhiyun * @erase_command: Erase command (or 0 if sector erase not needed).
192*4882a593Smuzhiyun * @erase_size: Erase sector size (in bytes)
193*4882a593Smuzhiyun * Erase commands affect sectors with this size and alignment.
194*4882a593Smuzhiyun * This must be a power of two.
195*4882a593Smuzhiyun * @block_size: Write block size (in bytes).
196*4882a593Smuzhiyun * Write commands are limited to blocks with this size and alignment.
197*4882a593Smuzhiyun */
198*4882a593Smuzhiyun struct falcon_spi_device {
199*4882a593Smuzhiyun int device_id;
200*4882a593Smuzhiyun unsigned int size;
201*4882a593Smuzhiyun unsigned int addr_len;
202*4882a593Smuzhiyun unsigned int munge_address:1;
203*4882a593Smuzhiyun u8 erase_command;
204*4882a593Smuzhiyun unsigned int erase_size;
205*4882a593Smuzhiyun unsigned int block_size;
206*4882a593Smuzhiyun };
207*4882a593Smuzhiyun
falcon_spi_present(const struct falcon_spi_device * spi)208*4882a593Smuzhiyun static inline bool falcon_spi_present(const struct falcon_spi_device *spi)
209*4882a593Smuzhiyun {
210*4882a593Smuzhiyun return spi->size != 0;
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun enum {
214*4882a593Smuzhiyun FALCON_STAT_tx_bytes = GENERIC_STAT_COUNT,
215*4882a593Smuzhiyun FALCON_STAT_tx_packets,
216*4882a593Smuzhiyun FALCON_STAT_tx_pause,
217*4882a593Smuzhiyun FALCON_STAT_tx_control,
218*4882a593Smuzhiyun FALCON_STAT_tx_unicast,
219*4882a593Smuzhiyun FALCON_STAT_tx_multicast,
220*4882a593Smuzhiyun FALCON_STAT_tx_broadcast,
221*4882a593Smuzhiyun FALCON_STAT_tx_lt64,
222*4882a593Smuzhiyun FALCON_STAT_tx_64,
223*4882a593Smuzhiyun FALCON_STAT_tx_65_to_127,
224*4882a593Smuzhiyun FALCON_STAT_tx_128_to_255,
225*4882a593Smuzhiyun FALCON_STAT_tx_256_to_511,
226*4882a593Smuzhiyun FALCON_STAT_tx_512_to_1023,
227*4882a593Smuzhiyun FALCON_STAT_tx_1024_to_15xx,
228*4882a593Smuzhiyun FALCON_STAT_tx_15xx_to_jumbo,
229*4882a593Smuzhiyun FALCON_STAT_tx_gtjumbo,
230*4882a593Smuzhiyun FALCON_STAT_tx_non_tcpudp,
231*4882a593Smuzhiyun FALCON_STAT_tx_mac_src_error,
232*4882a593Smuzhiyun FALCON_STAT_tx_ip_src_error,
233*4882a593Smuzhiyun FALCON_STAT_rx_bytes,
234*4882a593Smuzhiyun FALCON_STAT_rx_good_bytes,
235*4882a593Smuzhiyun FALCON_STAT_rx_bad_bytes,
236*4882a593Smuzhiyun FALCON_STAT_rx_packets,
237*4882a593Smuzhiyun FALCON_STAT_rx_good,
238*4882a593Smuzhiyun FALCON_STAT_rx_bad,
239*4882a593Smuzhiyun FALCON_STAT_rx_pause,
240*4882a593Smuzhiyun FALCON_STAT_rx_control,
241*4882a593Smuzhiyun FALCON_STAT_rx_unicast,
242*4882a593Smuzhiyun FALCON_STAT_rx_multicast,
243*4882a593Smuzhiyun FALCON_STAT_rx_broadcast,
244*4882a593Smuzhiyun FALCON_STAT_rx_lt64,
245*4882a593Smuzhiyun FALCON_STAT_rx_64,
246*4882a593Smuzhiyun FALCON_STAT_rx_65_to_127,
247*4882a593Smuzhiyun FALCON_STAT_rx_128_to_255,
248*4882a593Smuzhiyun FALCON_STAT_rx_256_to_511,
249*4882a593Smuzhiyun FALCON_STAT_rx_512_to_1023,
250*4882a593Smuzhiyun FALCON_STAT_rx_1024_to_15xx,
251*4882a593Smuzhiyun FALCON_STAT_rx_15xx_to_jumbo,
252*4882a593Smuzhiyun FALCON_STAT_rx_gtjumbo,
253*4882a593Smuzhiyun FALCON_STAT_rx_bad_lt64,
254*4882a593Smuzhiyun FALCON_STAT_rx_bad_gtjumbo,
255*4882a593Smuzhiyun FALCON_STAT_rx_overflow,
256*4882a593Smuzhiyun FALCON_STAT_rx_symbol_error,
257*4882a593Smuzhiyun FALCON_STAT_rx_align_error,
258*4882a593Smuzhiyun FALCON_STAT_rx_length_error,
259*4882a593Smuzhiyun FALCON_STAT_rx_internal_error,
260*4882a593Smuzhiyun FALCON_STAT_rx_nodesc_drop_cnt,
261*4882a593Smuzhiyun FALCON_STAT_COUNT
262*4882a593Smuzhiyun };
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun /**
265*4882a593Smuzhiyun * struct falcon_nic_data - Falcon NIC state
266*4882a593Smuzhiyun * @pci_dev2: Secondary function of Falcon A
267*4882a593Smuzhiyun * @efx: ef4_nic pointer
268*4882a593Smuzhiyun * @board: Board state and functions
269*4882a593Smuzhiyun * @stats: Hardware statistics
270*4882a593Smuzhiyun * @stats_disable_count: Nest count for disabling statistics fetches
271*4882a593Smuzhiyun * @stats_pending: Is there a pending DMA of MAC statistics.
272*4882a593Smuzhiyun * @stats_timer: A timer for regularly fetching MAC statistics.
273*4882a593Smuzhiyun * @spi_flash: SPI flash device
274*4882a593Smuzhiyun * @spi_eeprom: SPI EEPROM device
275*4882a593Smuzhiyun * @spi_lock: SPI bus lock
276*4882a593Smuzhiyun * @mdio_lock: MDIO bus lock
277*4882a593Smuzhiyun * @xmac_poll_required: XMAC link state needs polling
278*4882a593Smuzhiyun */
279*4882a593Smuzhiyun struct falcon_nic_data {
280*4882a593Smuzhiyun struct pci_dev *pci_dev2;
281*4882a593Smuzhiyun struct ef4_nic *efx;
282*4882a593Smuzhiyun struct falcon_board board;
283*4882a593Smuzhiyun u64 stats[FALCON_STAT_COUNT];
284*4882a593Smuzhiyun unsigned int stats_disable_count;
285*4882a593Smuzhiyun bool stats_pending;
286*4882a593Smuzhiyun struct timer_list stats_timer;
287*4882a593Smuzhiyun struct falcon_spi_device spi_flash;
288*4882a593Smuzhiyun struct falcon_spi_device spi_eeprom;
289*4882a593Smuzhiyun struct mutex spi_lock;
290*4882a593Smuzhiyun struct mutex mdio_lock;
291*4882a593Smuzhiyun bool xmac_poll_required;
292*4882a593Smuzhiyun };
293*4882a593Smuzhiyun
falcon_board(struct ef4_nic * efx)294*4882a593Smuzhiyun static inline struct falcon_board *falcon_board(struct ef4_nic *efx)
295*4882a593Smuzhiyun {
296*4882a593Smuzhiyun struct falcon_nic_data *data = efx->nic_data;
297*4882a593Smuzhiyun return &data->board;
298*4882a593Smuzhiyun }
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun struct ethtool_ts_info;
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun extern const struct ef4_nic_type falcon_a1_nic_type;
303*4882a593Smuzhiyun extern const struct ef4_nic_type falcon_b0_nic_type;
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun /**************************************************************************
306*4882a593Smuzhiyun *
307*4882a593Smuzhiyun * Externs
308*4882a593Smuzhiyun *
309*4882a593Smuzhiyun **************************************************************************
310*4882a593Smuzhiyun */
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun int falcon_probe_board(struct ef4_nic *efx, u16 revision_info);
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun /* TX data path */
ef4_nic_probe_tx(struct ef4_tx_queue * tx_queue)315*4882a593Smuzhiyun static inline int ef4_nic_probe_tx(struct ef4_tx_queue *tx_queue)
316*4882a593Smuzhiyun {
317*4882a593Smuzhiyun return tx_queue->efx->type->tx_probe(tx_queue);
318*4882a593Smuzhiyun }
ef4_nic_init_tx(struct ef4_tx_queue * tx_queue)319*4882a593Smuzhiyun static inline void ef4_nic_init_tx(struct ef4_tx_queue *tx_queue)
320*4882a593Smuzhiyun {
321*4882a593Smuzhiyun tx_queue->efx->type->tx_init(tx_queue);
322*4882a593Smuzhiyun }
ef4_nic_remove_tx(struct ef4_tx_queue * tx_queue)323*4882a593Smuzhiyun static inline void ef4_nic_remove_tx(struct ef4_tx_queue *tx_queue)
324*4882a593Smuzhiyun {
325*4882a593Smuzhiyun tx_queue->efx->type->tx_remove(tx_queue);
326*4882a593Smuzhiyun }
ef4_nic_push_buffers(struct ef4_tx_queue * tx_queue)327*4882a593Smuzhiyun static inline void ef4_nic_push_buffers(struct ef4_tx_queue *tx_queue)
328*4882a593Smuzhiyun {
329*4882a593Smuzhiyun tx_queue->efx->type->tx_write(tx_queue);
330*4882a593Smuzhiyun }
331*4882a593Smuzhiyun
332*4882a593Smuzhiyun /* RX data path */
ef4_nic_probe_rx(struct ef4_rx_queue * rx_queue)333*4882a593Smuzhiyun static inline int ef4_nic_probe_rx(struct ef4_rx_queue *rx_queue)
334*4882a593Smuzhiyun {
335*4882a593Smuzhiyun return rx_queue->efx->type->rx_probe(rx_queue);
336*4882a593Smuzhiyun }
ef4_nic_init_rx(struct ef4_rx_queue * rx_queue)337*4882a593Smuzhiyun static inline void ef4_nic_init_rx(struct ef4_rx_queue *rx_queue)
338*4882a593Smuzhiyun {
339*4882a593Smuzhiyun rx_queue->efx->type->rx_init(rx_queue);
340*4882a593Smuzhiyun }
ef4_nic_remove_rx(struct ef4_rx_queue * rx_queue)341*4882a593Smuzhiyun static inline void ef4_nic_remove_rx(struct ef4_rx_queue *rx_queue)
342*4882a593Smuzhiyun {
343*4882a593Smuzhiyun rx_queue->efx->type->rx_remove(rx_queue);
344*4882a593Smuzhiyun }
ef4_nic_notify_rx_desc(struct ef4_rx_queue * rx_queue)345*4882a593Smuzhiyun static inline void ef4_nic_notify_rx_desc(struct ef4_rx_queue *rx_queue)
346*4882a593Smuzhiyun {
347*4882a593Smuzhiyun rx_queue->efx->type->rx_write(rx_queue);
348*4882a593Smuzhiyun }
ef4_nic_generate_fill_event(struct ef4_rx_queue * rx_queue)349*4882a593Smuzhiyun static inline void ef4_nic_generate_fill_event(struct ef4_rx_queue *rx_queue)
350*4882a593Smuzhiyun {
351*4882a593Smuzhiyun rx_queue->efx->type->rx_defer_refill(rx_queue);
352*4882a593Smuzhiyun }
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun /* Event data path */
ef4_nic_probe_eventq(struct ef4_channel * channel)355*4882a593Smuzhiyun static inline int ef4_nic_probe_eventq(struct ef4_channel *channel)
356*4882a593Smuzhiyun {
357*4882a593Smuzhiyun return channel->efx->type->ev_probe(channel);
358*4882a593Smuzhiyun }
ef4_nic_init_eventq(struct ef4_channel * channel)359*4882a593Smuzhiyun static inline int ef4_nic_init_eventq(struct ef4_channel *channel)
360*4882a593Smuzhiyun {
361*4882a593Smuzhiyun return channel->efx->type->ev_init(channel);
362*4882a593Smuzhiyun }
ef4_nic_fini_eventq(struct ef4_channel * channel)363*4882a593Smuzhiyun static inline void ef4_nic_fini_eventq(struct ef4_channel *channel)
364*4882a593Smuzhiyun {
365*4882a593Smuzhiyun channel->efx->type->ev_fini(channel);
366*4882a593Smuzhiyun }
ef4_nic_remove_eventq(struct ef4_channel * channel)367*4882a593Smuzhiyun static inline void ef4_nic_remove_eventq(struct ef4_channel *channel)
368*4882a593Smuzhiyun {
369*4882a593Smuzhiyun channel->efx->type->ev_remove(channel);
370*4882a593Smuzhiyun }
371*4882a593Smuzhiyun static inline int
ef4_nic_process_eventq(struct ef4_channel * channel,int quota)372*4882a593Smuzhiyun ef4_nic_process_eventq(struct ef4_channel *channel, int quota)
373*4882a593Smuzhiyun {
374*4882a593Smuzhiyun return channel->efx->type->ev_process(channel, quota);
375*4882a593Smuzhiyun }
ef4_nic_eventq_read_ack(struct ef4_channel * channel)376*4882a593Smuzhiyun static inline void ef4_nic_eventq_read_ack(struct ef4_channel *channel)
377*4882a593Smuzhiyun {
378*4882a593Smuzhiyun channel->efx->type->ev_read_ack(channel);
379*4882a593Smuzhiyun }
380*4882a593Smuzhiyun void ef4_nic_event_test_start(struct ef4_channel *channel);
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun /* queue operations */
383*4882a593Smuzhiyun int ef4_farch_tx_probe(struct ef4_tx_queue *tx_queue);
384*4882a593Smuzhiyun void ef4_farch_tx_init(struct ef4_tx_queue *tx_queue);
385*4882a593Smuzhiyun void ef4_farch_tx_fini(struct ef4_tx_queue *tx_queue);
386*4882a593Smuzhiyun void ef4_farch_tx_remove(struct ef4_tx_queue *tx_queue);
387*4882a593Smuzhiyun void ef4_farch_tx_write(struct ef4_tx_queue *tx_queue);
388*4882a593Smuzhiyun unsigned int ef4_farch_tx_limit_len(struct ef4_tx_queue *tx_queue,
389*4882a593Smuzhiyun dma_addr_t dma_addr, unsigned int len);
390*4882a593Smuzhiyun int ef4_farch_rx_probe(struct ef4_rx_queue *rx_queue);
391*4882a593Smuzhiyun void ef4_farch_rx_init(struct ef4_rx_queue *rx_queue);
392*4882a593Smuzhiyun void ef4_farch_rx_fini(struct ef4_rx_queue *rx_queue);
393*4882a593Smuzhiyun void ef4_farch_rx_remove(struct ef4_rx_queue *rx_queue);
394*4882a593Smuzhiyun void ef4_farch_rx_write(struct ef4_rx_queue *rx_queue);
395*4882a593Smuzhiyun void ef4_farch_rx_defer_refill(struct ef4_rx_queue *rx_queue);
396*4882a593Smuzhiyun int ef4_farch_ev_probe(struct ef4_channel *channel);
397*4882a593Smuzhiyun int ef4_farch_ev_init(struct ef4_channel *channel);
398*4882a593Smuzhiyun void ef4_farch_ev_fini(struct ef4_channel *channel);
399*4882a593Smuzhiyun void ef4_farch_ev_remove(struct ef4_channel *channel);
400*4882a593Smuzhiyun int ef4_farch_ev_process(struct ef4_channel *channel, int quota);
401*4882a593Smuzhiyun void ef4_farch_ev_read_ack(struct ef4_channel *channel);
402*4882a593Smuzhiyun void ef4_farch_ev_test_generate(struct ef4_channel *channel);
403*4882a593Smuzhiyun
404*4882a593Smuzhiyun /* filter operations */
405*4882a593Smuzhiyun int ef4_farch_filter_table_probe(struct ef4_nic *efx);
406*4882a593Smuzhiyun void ef4_farch_filter_table_restore(struct ef4_nic *efx);
407*4882a593Smuzhiyun void ef4_farch_filter_table_remove(struct ef4_nic *efx);
408*4882a593Smuzhiyun void ef4_farch_filter_update_rx_scatter(struct ef4_nic *efx);
409*4882a593Smuzhiyun s32 ef4_farch_filter_insert(struct ef4_nic *efx, struct ef4_filter_spec *spec,
410*4882a593Smuzhiyun bool replace);
411*4882a593Smuzhiyun int ef4_farch_filter_remove_safe(struct ef4_nic *efx,
412*4882a593Smuzhiyun enum ef4_filter_priority priority,
413*4882a593Smuzhiyun u32 filter_id);
414*4882a593Smuzhiyun int ef4_farch_filter_get_safe(struct ef4_nic *efx,
415*4882a593Smuzhiyun enum ef4_filter_priority priority, u32 filter_id,
416*4882a593Smuzhiyun struct ef4_filter_spec *);
417*4882a593Smuzhiyun int ef4_farch_filter_clear_rx(struct ef4_nic *efx,
418*4882a593Smuzhiyun enum ef4_filter_priority priority);
419*4882a593Smuzhiyun u32 ef4_farch_filter_count_rx_used(struct ef4_nic *efx,
420*4882a593Smuzhiyun enum ef4_filter_priority priority);
421*4882a593Smuzhiyun u32 ef4_farch_filter_get_rx_id_limit(struct ef4_nic *efx);
422*4882a593Smuzhiyun s32 ef4_farch_filter_get_rx_ids(struct ef4_nic *efx,
423*4882a593Smuzhiyun enum ef4_filter_priority priority, u32 *buf,
424*4882a593Smuzhiyun u32 size);
425*4882a593Smuzhiyun #ifdef CONFIG_RFS_ACCEL
426*4882a593Smuzhiyun s32 ef4_farch_filter_rfs_insert(struct ef4_nic *efx,
427*4882a593Smuzhiyun struct ef4_filter_spec *spec);
428*4882a593Smuzhiyun bool ef4_farch_filter_rfs_expire_one(struct ef4_nic *efx, u32 flow_id,
429*4882a593Smuzhiyun unsigned int index);
430*4882a593Smuzhiyun #endif
431*4882a593Smuzhiyun void ef4_farch_filter_sync_rx_mode(struct ef4_nic *efx);
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun bool ef4_nic_event_present(struct ef4_channel *channel);
434*4882a593Smuzhiyun
435*4882a593Smuzhiyun /* Some statistics are computed as A - B where A and B each increase
436*4882a593Smuzhiyun * linearly with some hardware counter(s) and the counters are read
437*4882a593Smuzhiyun * asynchronously. If the counters contributing to B are always read
438*4882a593Smuzhiyun * after those contributing to A, the computed value may be lower than
439*4882a593Smuzhiyun * the true value by some variable amount, and may decrease between
440*4882a593Smuzhiyun * subsequent computations.
441*4882a593Smuzhiyun *
442*4882a593Smuzhiyun * We should never allow statistics to decrease or to exceed the true
443*4882a593Smuzhiyun * value. Since the computed value will never be greater than the
444*4882a593Smuzhiyun * true value, we can achieve this by only storing the computed value
445*4882a593Smuzhiyun * when it increases.
446*4882a593Smuzhiyun */
ef4_update_diff_stat(u64 * stat,u64 diff)447*4882a593Smuzhiyun static inline void ef4_update_diff_stat(u64 *stat, u64 diff)
448*4882a593Smuzhiyun {
449*4882a593Smuzhiyun if ((s64)(diff - *stat) > 0)
450*4882a593Smuzhiyun *stat = diff;
451*4882a593Smuzhiyun }
452*4882a593Smuzhiyun
453*4882a593Smuzhiyun /* Interrupts */
454*4882a593Smuzhiyun int ef4_nic_init_interrupt(struct ef4_nic *efx);
455*4882a593Smuzhiyun int ef4_nic_irq_test_start(struct ef4_nic *efx);
456*4882a593Smuzhiyun void ef4_nic_fini_interrupt(struct ef4_nic *efx);
457*4882a593Smuzhiyun void ef4_farch_irq_enable_master(struct ef4_nic *efx);
458*4882a593Smuzhiyun int ef4_farch_irq_test_generate(struct ef4_nic *efx);
459*4882a593Smuzhiyun void ef4_farch_irq_disable_master(struct ef4_nic *efx);
460*4882a593Smuzhiyun irqreturn_t ef4_farch_msi_interrupt(int irq, void *dev_id);
461*4882a593Smuzhiyun irqreturn_t ef4_farch_legacy_interrupt(int irq, void *dev_id);
462*4882a593Smuzhiyun irqreturn_t ef4_farch_fatal_interrupt(struct ef4_nic *efx);
463*4882a593Smuzhiyun
ef4_nic_event_test_irq_cpu(struct ef4_channel * channel)464*4882a593Smuzhiyun static inline int ef4_nic_event_test_irq_cpu(struct ef4_channel *channel)
465*4882a593Smuzhiyun {
466*4882a593Smuzhiyun return READ_ONCE(channel->event_test_cpu);
467*4882a593Smuzhiyun }
ef4_nic_irq_test_irq_cpu(struct ef4_nic * efx)468*4882a593Smuzhiyun static inline int ef4_nic_irq_test_irq_cpu(struct ef4_nic *efx)
469*4882a593Smuzhiyun {
470*4882a593Smuzhiyun return READ_ONCE(efx->last_irq_cpu);
471*4882a593Smuzhiyun }
472*4882a593Smuzhiyun
473*4882a593Smuzhiyun /* Global Resources */
474*4882a593Smuzhiyun int ef4_nic_flush_queues(struct ef4_nic *efx);
475*4882a593Smuzhiyun int ef4_farch_fini_dmaq(struct ef4_nic *efx);
476*4882a593Smuzhiyun void ef4_farch_finish_flr(struct ef4_nic *efx);
477*4882a593Smuzhiyun void falcon_start_nic_stats(struct ef4_nic *efx);
478*4882a593Smuzhiyun void falcon_stop_nic_stats(struct ef4_nic *efx);
479*4882a593Smuzhiyun int falcon_reset_xaui(struct ef4_nic *efx);
480*4882a593Smuzhiyun void ef4_farch_dimension_resources(struct ef4_nic *efx, unsigned sram_lim_qw);
481*4882a593Smuzhiyun void ef4_farch_init_common(struct ef4_nic *efx);
482*4882a593Smuzhiyun void ef4_farch_rx_push_indir_table(struct ef4_nic *efx);
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun int ef4_nic_alloc_buffer(struct ef4_nic *efx, struct ef4_buffer *buffer,
485*4882a593Smuzhiyun unsigned int len, gfp_t gfp_flags);
486*4882a593Smuzhiyun void ef4_nic_free_buffer(struct ef4_nic *efx, struct ef4_buffer *buffer);
487*4882a593Smuzhiyun
488*4882a593Smuzhiyun /* Tests */
489*4882a593Smuzhiyun struct ef4_farch_register_test {
490*4882a593Smuzhiyun unsigned address;
491*4882a593Smuzhiyun ef4_oword_t mask;
492*4882a593Smuzhiyun };
493*4882a593Smuzhiyun int ef4_farch_test_registers(struct ef4_nic *efx,
494*4882a593Smuzhiyun const struct ef4_farch_register_test *regs,
495*4882a593Smuzhiyun size_t n_regs);
496*4882a593Smuzhiyun
497*4882a593Smuzhiyun size_t ef4_nic_get_regs_len(struct ef4_nic *efx);
498*4882a593Smuzhiyun void ef4_nic_get_regs(struct ef4_nic *efx, void *buf);
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun size_t ef4_nic_describe_stats(const struct ef4_hw_stat_desc *desc, size_t count,
501*4882a593Smuzhiyun const unsigned long *mask, u8 *names);
502*4882a593Smuzhiyun void ef4_nic_update_stats(const struct ef4_hw_stat_desc *desc, size_t count,
503*4882a593Smuzhiyun const unsigned long *mask, u64 *stats,
504*4882a593Smuzhiyun const void *dma_buf, bool accumulate);
505*4882a593Smuzhiyun void ef4_nic_fix_nodesc_drop_stat(struct ef4_nic *efx, u64 *stat);
506*4882a593Smuzhiyun
507*4882a593Smuzhiyun #define EF4_MAX_FLUSH_TIME 5000
508*4882a593Smuzhiyun
509*4882a593Smuzhiyun void ef4_farch_generate_event(struct ef4_nic *efx, unsigned int evq,
510*4882a593Smuzhiyun ef4_qword_t *event);
511*4882a593Smuzhiyun
512*4882a593Smuzhiyun #endif /* EF4_NIC_H */
513