blob: b90dc8a24cca7b14c35a58db2be9f286b41898b4 [file] [log] [blame]
Ben Hutchings8ceee662008-04-27 12:55:59 +01001/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
Ben Hutchings0a6f40c2011-02-25 00:01:34 +00004 * Copyright 2006-2011 Solarflare Communications Inc.
Ben Hutchings8ceee662008-04-27 12:55:59 +01005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
Ben Hutchings744093c2009-11-29 15:12:08 +000011#ifndef EFX_NIC_H
12#define EFX_NIC_H
Ben Hutchings8ceee662008-04-27 12:55:59 +010013
Stuart Hodgson7c236c42012-09-03 11:09:36 +010014#include <linux/net_tstamp.h>
Ben Hutchings5c16a962009-11-23 16:05:28 +000015#include <linux/i2c-algo-bit.h>
Ben Hutchings8ceee662008-04-27 12:55:59 +010016#include "net_driver.h"
Ben Hutchings177dfcd2008-12-12 21:50:08 -080017#include "efx.h"
Ben Hutchings8880f4e2009-11-29 15:15:41 +000018#include "mcdi.h"
Ben Hutchings4de92182010-12-02 13:47:29 +000019#include "spi.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010020
21/*
22 * Falcon hardware control
23 */
24
Ben Hutchingsdaeda632009-11-28 05:36:04 +000025enum {
26 EFX_REV_FALCON_A0 = 0,
27 EFX_REV_FALCON_A1 = 1,
28 EFX_REV_FALCON_B0 = 2,
Ben Hutchings8880f4e2009-11-29 15:15:41 +000029 EFX_REV_SIENA_A0 = 3,
Ben Hutchings8ceee662008-04-27 12:55:59 +010030};
31
Ben Hutchingsdaeda632009-11-28 05:36:04 +000032static inline int efx_nic_rev(struct efx_nic *efx)
Ben Hutchings55668612008-05-16 21:16:10 +010033{
Ben Hutchingsdaeda632009-11-28 05:36:04 +000034 return efx->type->revision;
Ben Hutchings55668612008-05-16 21:16:10 +010035}
Ben Hutchings8ceee662008-04-27 12:55:59 +010036
Ben Hutchings86094f72013-08-21 19:51:04 +010037extern u32 efx_farch_fpga_ver(struct efx_nic *efx);
Ben Hutchings152b6a62009-11-29 03:43:56 +000038
39/* NIC has two interlinked PCI functions for the same port. */
40static inline bool efx_nic_is_dual_func(struct efx_nic *efx)
41{
42 return efx_nic_rev(efx) < EFX_REV_FALCON_B0;
43}
44
Ben Hutchings86094f72013-08-21 19:51:04 +010045/* Read the current event from the event queue */
46static inline efx_qword_t *efx_event(struct efx_channel *channel,
47 unsigned int index)
48{
49 return ((efx_qword_t *) (channel->eventq.buf.addr)) +
50 (index & channel->eventq_mask);
51}
52
53/* See if an event is present
54 *
55 * We check both the high and low dword of the event for all ones. We
56 * wrote all ones when we cleared the event, and no valid event can
57 * have all ones in either its high or low dwords. This approach is
58 * robust against reordering.
59 *
60 * Note that using a single 64-bit comparison is incorrect; even
61 * though the CPU read will be atomic, the DMA write may not be.
62 */
63static inline int efx_event_present(efx_qword_t *event)
64{
65 return !(EFX_DWORD_IS_ALL_ONES(event->dword[0]) |
66 EFX_DWORD_IS_ALL_ONES(event->dword[1]));
67}
68
69/* Returns a pointer to the specified transmit descriptor in the TX
70 * descriptor queue belonging to the specified channel.
71 */
72static inline efx_qword_t *
73efx_tx_desc(struct efx_tx_queue *tx_queue, unsigned int index)
74{
75 return ((efx_qword_t *) (tx_queue->txd.buf.addr)) + index;
76}
77
78/* Decide whether to push a TX descriptor to the NIC vs merely writing
79 * the doorbell. This can reduce latency when we are adding a single
80 * descriptor to an empty queue, but is otherwise pointless. Further,
81 * Falcon and Siena have hardware bugs (SF bug 33851) that may be
82 * triggered if we don't check this.
83 */
84static inline bool efx_nic_may_push_tx_desc(struct efx_tx_queue *tx_queue,
85 unsigned int write_count)
86{
87 unsigned empty_read_count = ACCESS_ONCE(tx_queue->empty_read_count);
88
89 if (empty_read_count == 0)
90 return false;
91
92 tx_queue->empty_read_count = 0;
93 return ((empty_read_count ^ write_count) & ~EFX_EMPTY_COUNT_VALID) == 0
94 && tx_queue->write_count - write_count == 1;
95}
96
97/* Returns a pointer to the specified descriptor in the RX descriptor queue */
98static inline efx_qword_t *
99efx_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
100{
101 return ((efx_qword_t *) (rx_queue->rxd.buf.addr)) + index;
102}
103
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000104enum {
105 PHY_TYPE_NONE = 0,
106 PHY_TYPE_TXC43128 = 1,
107 PHY_TYPE_88E1111 = 2,
108 PHY_TYPE_SFX7101 = 3,
109 PHY_TYPE_QT2022C2 = 4,
110 PHY_TYPE_PM8358 = 6,
111 PHY_TYPE_SFT9001A = 8,
112 PHY_TYPE_QT2025C = 9,
113 PHY_TYPE_SFT9001B = 10,
114};
115
116#define FALCON_XMAC_LOOPBACKS \
117 ((1 << LOOPBACK_XGMII) | \
118 (1 << LOOPBACK_XGXS) | \
119 (1 << LOOPBACK_XAUI))
120
121#define FALCON_GMAC_LOOPBACKS \
122 (1 << LOOPBACK_GMAC)
123
Ben Hutchings5b6262d2012-02-02 21:21:15 +0000124/* Alignment of PCIe DMA boundaries (4KB) */
125#define EFX_PAGE_SIZE 4096
126/* Size and alignment of buffer table entries (same) */
127#define EFX_BUF_SIZE EFX_PAGE_SIZE
128
Ben Hutchings5c16a962009-11-23 16:05:28 +0000129/**
Ben Hutchings44838a42009-11-25 16:09:41 +0000130 * struct falcon_board_type - board operations and type information
131 * @id: Board type id, as found in NVRAM
Ben Hutchings37594332009-11-23 16:05:45 +0000132 * @init: Allocate resources and initialise peripheral hardware
133 * @init_phy: Do board-specific PHY initialisation
Ben Hutchings44838a42009-11-25 16:09:41 +0000134 * @fini: Shut down hardware and free resources
Ben Hutchings37594332009-11-23 16:05:45 +0000135 * @set_id_led: Set state of identifying LED or revert to automatic function
136 * @monitor: Board-specific health check function
Ben Hutchings44838a42009-11-25 16:09:41 +0000137 */
138struct falcon_board_type {
139 u8 id;
Ben Hutchings44838a42009-11-25 16:09:41 +0000140 int (*init) (struct efx_nic *nic);
141 void (*init_phy) (struct efx_nic *efx);
142 void (*fini) (struct efx_nic *nic);
143 void (*set_id_led) (struct efx_nic *efx, enum efx_led_mode mode);
144 int (*monitor) (struct efx_nic *nic);
145};
146
147/**
148 * struct falcon_board - board information
149 * @type: Type of board
150 * @major: Major rev. ('A', 'B' ...)
151 * @minor: Minor rev. (0, 1, ...)
Ben Hutchingse775fb92009-11-23 16:06:02 +0000152 * @i2c_adap: I2C adapter for on-board peripherals
153 * @i2c_data: Data for bit-banging algorithm
Ben Hutchings37594332009-11-23 16:05:45 +0000154 * @hwmon_client: I2C client for hardware monitor
155 * @ioexp_client: I2C client for power/port control
156 */
157struct falcon_board {
Ben Hutchings44838a42009-11-25 16:09:41 +0000158 const struct falcon_board_type *type;
Ben Hutchings37594332009-11-23 16:05:45 +0000159 int major;
160 int minor;
Ben Hutchingse775fb92009-11-23 16:06:02 +0000161 struct i2c_adapter i2c_adap;
162 struct i2c_algo_bit_data i2c_data;
Ben Hutchings37594332009-11-23 16:05:45 +0000163 struct i2c_client *hwmon_client, *ioexp_client;
164};
165
166/**
Ben Hutchings5c16a962009-11-23 16:05:28 +0000167 * struct falcon_nic_data - Falcon NIC state
Ben Hutchings89863522009-11-25 16:09:04 +0000168 * @pci_dev2: Secondary function of Falcon A
Ben Hutchings37594332009-11-23 16:05:45 +0000169 * @board: Board state and functions
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000170 * @stats_disable_count: Nest count for disabling statistics fetches
171 * @stats_pending: Is there a pending DMA of MAC statistics.
172 * @stats_timer: A timer for regularly fetching MAC statistics.
173 * @stats_dma_done: Pointer to the flag which indicates DMA completion.
Ben Hutchings4de92182010-12-02 13:47:29 +0000174 * @spi_flash: SPI flash device
175 * @spi_eeprom: SPI EEPROM device
176 * @spi_lock: SPI bus lock
Ben Hutchings4833f022010-12-02 13:47:35 +0000177 * @mdio_lock: MDIO bus lock
Ben Hutchingscef68bd2010-12-02 13:47:51 +0000178 * @xmac_poll_required: XMAC link state needs polling
Ben Hutchings5c16a962009-11-23 16:05:28 +0000179 */
180struct falcon_nic_data {
181 struct pci_dev *pci_dev2;
Ben Hutchings37594332009-11-23 16:05:45 +0000182 struct falcon_board board;
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000183 unsigned int stats_disable_count;
184 bool stats_pending;
185 struct timer_list stats_timer;
186 u32 *stats_dma_done;
Ben Hutchingsecd0a6f2012-11-28 04:12:41 +0000187 struct falcon_spi_device spi_flash;
188 struct falcon_spi_device spi_eeprom;
Ben Hutchings4de92182010-12-02 13:47:29 +0000189 struct mutex spi_lock;
Ben Hutchings4833f022010-12-02 13:47:35 +0000190 struct mutex mdio_lock;
Ben Hutchingscef68bd2010-12-02 13:47:51 +0000191 bool xmac_poll_required;
Ben Hutchings5c16a962009-11-23 16:05:28 +0000192};
193
Ben Hutchings278c0622009-11-23 16:05:12 +0000194static inline struct falcon_board *falcon_board(struct efx_nic *efx)
195{
Ben Hutchings37594332009-11-23 16:05:45 +0000196 struct falcon_nic_data *data = efx->nic_data;
197 return &data->board;
Ben Hutchings278c0622009-11-23 16:05:12 +0000198}
199
Ben Hutchings8880f4e2009-11-29 15:15:41 +0000200/**
201 * struct siena_nic_data - Siena NIC state
Ben Hutchings8880f4e2009-11-29 15:15:41 +0000202 * @wol_filter_id: Wake-on-LAN packet filter id
203 */
204struct siena_nic_data {
Ben Hutchings8880f4e2009-11-29 15:15:41 +0000205 int wol_filter_id;
206};
207
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000208/*
209 * On the SFC9000 family each port is associated with 1 PCI physical
210 * function (PF) handled by sfc and a configurable number of virtual
211 * functions (VFs) that may be handled by some other driver, often in
212 * a VM guest. The queue pointer registers are mapped in both PF and
213 * VF BARs such that an 8K region provides access to a single RX, TX
214 * and event queue (collectively a Virtual Interface, VI or VNIC).
215 *
216 * The PF has access to all 1024 VIs while VFs are mapped to VIs
217 * according to VI_BASE and VI_SCALE: VF i has access to VIs numbered
218 * in range [VI_BASE + i << VI_SCALE, VI_BASE + i + 1 << VI_SCALE).
219 * The number of VIs and the VI_SCALE value are configurable but must
220 * be established at boot time by firmware.
221 */
222
223/* Maximum VI_SCALE parameter supported by Siena */
224#define EFX_VI_SCALE_MAX 6
225/* Base VI to use for SR-IOV. Must be aligned to (1 << EFX_VI_SCALE_MAX),
226 * so this is the smallest allowed value. */
227#define EFX_VI_BASE 128U
228/* Maximum number of VFs allowed */
229#define EFX_VF_COUNT_MAX 127
230/* Limit EVQs on VFs to be only 8k to reduce buffer table reservation */
231#define EFX_MAX_VF_EVQ_SIZE 8192UL
232/* The number of buffer table entries reserved for each VI on a VF */
233#define EFX_VF_BUFTBL_PER_VI \
234 ((EFX_MAX_VF_EVQ_SIZE + 2 * EFX_MAX_DMAQ_SIZE) * \
235 sizeof(efx_qword_t) / EFX_BUF_SIZE)
236
237#ifdef CONFIG_SFC_SRIOV
238
239static inline bool efx_sriov_wanted(struct efx_nic *efx)
240{
241 return efx->vf_count != 0;
242}
243static inline bool efx_sriov_enabled(struct efx_nic *efx)
244{
245 return efx->vf_init_count != 0;
246}
247static inline unsigned int efx_vf_size(struct efx_nic *efx)
248{
249 return 1 << efx->vi_scale;
250}
251
252extern int efx_init_sriov(void);
253extern void efx_sriov_probe(struct efx_nic *efx);
254extern int efx_sriov_init(struct efx_nic *efx);
255extern void efx_sriov_mac_address_changed(struct efx_nic *efx);
256extern void efx_sriov_tx_flush_done(struct efx_nic *efx, efx_qword_t *event);
257extern void efx_sriov_rx_flush_done(struct efx_nic *efx, efx_qword_t *event);
258extern void efx_sriov_event(struct efx_channel *channel, efx_qword_t *event);
259extern void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq);
260extern void efx_sriov_flr(struct efx_nic *efx, unsigned flr);
261extern void efx_sriov_reset(struct efx_nic *efx);
262extern void efx_sriov_fini(struct efx_nic *efx);
263extern void efx_fini_sriov(void);
264
265#else
266
267static inline bool efx_sriov_wanted(struct efx_nic *efx) { return false; }
268static inline bool efx_sriov_enabled(struct efx_nic *efx) { return false; }
269static inline unsigned int efx_vf_size(struct efx_nic *efx) { return 0; }
270
271static inline int efx_init_sriov(void) { return 0; }
272static inline void efx_sriov_probe(struct efx_nic *efx) {}
273static inline int efx_sriov_init(struct efx_nic *efx) { return -EOPNOTSUPP; }
274static inline void efx_sriov_mac_address_changed(struct efx_nic *efx) {}
275static inline void efx_sriov_tx_flush_done(struct efx_nic *efx,
276 efx_qword_t *event) {}
277static inline void efx_sriov_rx_flush_done(struct efx_nic *efx,
278 efx_qword_t *event) {}
279static inline void efx_sriov_event(struct efx_channel *channel,
280 efx_qword_t *event) {}
281static inline void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq) {}
282static inline void efx_sriov_flr(struct efx_nic *efx, unsigned flr) {}
283static inline void efx_sriov_reset(struct efx_nic *efx) {}
284static inline void efx_sriov_fini(struct efx_nic *efx) {}
285static inline void efx_fini_sriov(void) {}
286
287#endif
288
289extern int efx_sriov_set_vf_mac(struct net_device *dev, int vf, u8 *mac);
290extern int efx_sriov_set_vf_vlan(struct net_device *dev, int vf,
291 u16 vlan, u8 qos);
292extern int efx_sriov_get_vf_config(struct net_device *dev, int vf,
293 struct ifla_vf_info *ivf);
294extern int efx_sriov_set_vf_spoofchk(struct net_device *net_dev, int vf,
295 bool spoofchk);
296
Stuart Hodgson7c236c42012-09-03 11:09:36 +0100297struct ethtool_ts_info;
Stuart Hodgson7c236c42012-09-03 11:09:36 +0100298extern void efx_ptp_probe(struct efx_nic *efx);
299extern int efx_ptp_ioctl(struct efx_nic *efx, struct ifreq *ifr, int cmd);
Ben Hutchings62ebac92013-04-08 17:34:58 +0100300extern void efx_ptp_get_ts_info(struct efx_nic *efx,
301 struct ethtool_ts_info *ts_info);
Stuart Hodgson7c236c42012-09-03 11:09:36 +0100302extern bool efx_ptp_is_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
303extern int efx_ptp_tx(struct efx_nic *efx, struct sk_buff *skb);
304extern void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev);
Stuart Hodgson7c236c42012-09-03 11:09:36 +0100305
stephen hemminger6c8c2512011-04-14 05:50:12 +0000306extern const struct efx_nic_type falcon_a1_nic_type;
307extern const struct efx_nic_type falcon_b0_nic_type;
308extern const struct efx_nic_type siena_a0_nic_type;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100309
310/**************************************************************************
311 *
312 * Externs
313 *
314 **************************************************************************
315 */
316
Ben Hutchingse41c11e2010-04-28 09:01:50 +0000317extern int falcon_probe_board(struct efx_nic *efx, u16 revision_info);
Ben Hutchings5087b542009-10-23 08:29:51 +0000318
Ben Hutchings8ceee662008-04-27 12:55:59 +0100319/* TX data path */
Ben Hutchings86094f72013-08-21 19:51:04 +0100320static inline int efx_nic_probe_tx(struct efx_tx_queue *tx_queue)
321{
322 return tx_queue->efx->type->tx_probe(tx_queue);
323}
324static inline void efx_nic_init_tx(struct efx_tx_queue *tx_queue)
325{
326 tx_queue->efx->type->tx_init(tx_queue);
327}
328static inline void efx_nic_remove_tx(struct efx_tx_queue *tx_queue)
329{
330 tx_queue->efx->type->tx_remove(tx_queue);
331}
332static inline void efx_nic_push_buffers(struct efx_tx_queue *tx_queue)
333{
334 tx_queue->efx->type->tx_write(tx_queue);
335}
Ben Hutchings8ceee662008-04-27 12:55:59 +0100336
337/* RX data path */
Ben Hutchings86094f72013-08-21 19:51:04 +0100338static inline int efx_nic_probe_rx(struct efx_rx_queue *rx_queue)
339{
340 return rx_queue->efx->type->rx_probe(rx_queue);
341}
342static inline void efx_nic_init_rx(struct efx_rx_queue *rx_queue)
343{
344 rx_queue->efx->type->rx_init(rx_queue);
345}
346static inline void efx_nic_remove_rx(struct efx_rx_queue *rx_queue)
347{
348 rx_queue->efx->type->rx_remove(rx_queue);
349}
350static inline void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue)
351{
352 rx_queue->efx->type->rx_write(rx_queue);
353}
354static inline void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue)
355{
356 rx_queue->efx->type->rx_defer_refill(rx_queue);
357}
Ben Hutchings8ceee662008-04-27 12:55:59 +0100358
359/* Event data path */
Ben Hutchings86094f72013-08-21 19:51:04 +0100360static inline int efx_nic_probe_eventq(struct efx_channel *channel)
361{
362 return channel->efx->type->ev_probe(channel);
363}
364static inline void efx_nic_init_eventq(struct efx_channel *channel)
365{
366 channel->efx->type->ev_init(channel);
367}
368static inline void efx_nic_fini_eventq(struct efx_channel *channel)
369{
370 channel->efx->type->ev_fini(channel);
371}
372static inline void efx_nic_remove_eventq(struct efx_channel *channel)
373{
374 channel->efx->type->ev_remove(channel);
375}
376static inline int
377efx_nic_process_eventq(struct efx_channel *channel, int quota)
378{
379 return channel->efx->type->ev_process(channel, quota);
380}
381static inline void efx_nic_eventq_read_ack(struct efx_channel *channel)
382{
383 channel->efx->type->ev_read_ack(channel);
384}
385extern void efx_nic_event_test_start(struct efx_channel *channel);
386
387/* Falcon/Siena queue operations */
388extern int efx_farch_tx_probe(struct efx_tx_queue *tx_queue);
389extern void efx_farch_tx_init(struct efx_tx_queue *tx_queue);
390extern void efx_farch_tx_fini(struct efx_tx_queue *tx_queue);
391extern void efx_farch_tx_remove(struct efx_tx_queue *tx_queue);
392extern void efx_farch_tx_write(struct efx_tx_queue *tx_queue);
393extern int efx_farch_rx_probe(struct efx_rx_queue *rx_queue);
394extern void efx_farch_rx_init(struct efx_rx_queue *rx_queue);
395extern void efx_farch_rx_fini(struct efx_rx_queue *rx_queue);
396extern void efx_farch_rx_remove(struct efx_rx_queue *rx_queue);
397extern void efx_farch_rx_write(struct efx_rx_queue *rx_queue);
398extern void efx_farch_rx_defer_refill(struct efx_rx_queue *rx_queue);
399extern int efx_farch_ev_probe(struct efx_channel *channel);
400extern void efx_farch_ev_init(struct efx_channel *channel);
401extern void efx_farch_ev_fini(struct efx_channel *channel);
402extern void efx_farch_ev_remove(struct efx_channel *channel);
403extern int efx_farch_ev_process(struct efx_channel *channel, int quota);
404extern void efx_farch_ev_read_ack(struct efx_channel *channel);
405extern void efx_farch_ev_test_generate(struct efx_channel *channel);
406
Ben Hutchingsadd72472012-11-08 01:46:53 +0000407/* Falcon/Siena filter operations */
408extern int efx_farch_filter_table_probe(struct efx_nic *efx);
409extern void efx_farch_filter_table_restore(struct efx_nic *efx);
410extern void efx_farch_filter_table_remove(struct efx_nic *efx);
411extern void efx_farch_filter_update_rx_scatter(struct efx_nic *efx);
412extern s32 efx_farch_filter_insert(struct efx_nic *efx,
413 struct efx_filter_spec *spec, bool replace);
414extern int efx_farch_filter_remove_safe(struct efx_nic *efx,
415 enum efx_filter_priority priority,
416 u32 filter_id);
417extern int efx_farch_filter_get_safe(struct efx_nic *efx,
418 enum efx_filter_priority priority,
419 u32 filter_id, struct efx_filter_spec *);
420extern void efx_farch_filter_clear_rx(struct efx_nic *efx,
421 enum efx_filter_priority priority);
422extern u32 efx_farch_filter_count_rx_used(struct efx_nic *efx,
423 enum efx_filter_priority priority);
424extern u32 efx_farch_filter_get_rx_id_limit(struct efx_nic *efx);
425extern s32 efx_farch_filter_get_rx_ids(struct efx_nic *efx,
426 enum efx_filter_priority priority,
427 u32 *buf, u32 size);
428#ifdef CONFIG_RFS_ACCEL
429extern s32 efx_farch_filter_rfs_insert(struct efx_nic *efx,
430 struct efx_filter_spec *spec);
431extern bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
432 unsigned int index);
433#endif
Ben Hutchings964e6132012-11-19 23:08:22 +0000434extern void efx_farch_filter_sync_rx_mode(struct efx_nic *efx);
Ben Hutchingsadd72472012-11-08 01:46:53 +0000435
Ben Hutchingsd4fabcc2011-04-04 14:22:11 +0100436extern bool efx_nic_event_present(struct efx_channel *channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100437
Ben Hutchingsb7f514a2012-07-04 22:25:07 +0100438/* Some statistics are computed as A - B where A and B each increase
439 * linearly with some hardware counter(s) and the counters are read
440 * asynchronously. If the counters contributing to B are always read
441 * after those contributing to A, the computed value may be lower than
442 * the true value by some variable amount, and may decrease between
443 * subsequent computations.
444 *
445 * We should never allow statistics to decrease or to exceed the true
446 * value. Since the computed value will never be greater than the
447 * true value, we can achieve this by only storing the computed value
448 * when it increases.
449 */
450static inline void efx_update_diff_stat(u64 *stat, u64 diff)
451{
452 if ((s64)(diff - *stat) > 0)
453 *stat = diff;
454}
455
Ben Hutchings86094f72013-08-21 19:51:04 +0100456/* Interrupts */
Ben Hutchings152b6a62009-11-29 03:43:56 +0000457extern int efx_nic_init_interrupt(struct efx_nic *efx);
Ben Hutchingseee6f6a2012-02-28 23:37:35 +0000458extern void efx_nic_irq_test_start(struct efx_nic *efx);
Ben Hutchings152b6a62009-11-29 03:43:56 +0000459extern void efx_nic_fini_interrupt(struct efx_nic *efx);
Ben Hutchings86094f72013-08-21 19:51:04 +0100460
461/* Falcon/Siena interrupts */
462extern void efx_farch_irq_enable_master(struct efx_nic *efx);
463extern void efx_farch_irq_test_generate(struct efx_nic *efx);
464extern void efx_farch_irq_disable_master(struct efx_nic *efx);
465extern irqreturn_t efx_farch_msi_interrupt(int irq, void *dev_id);
466extern irqreturn_t efx_farch_legacy_interrupt(int irq, void *dev_id);
467extern irqreturn_t efx_farch_fatal_interrupt(struct efx_nic *efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100468
Ben Hutchingseee6f6a2012-02-28 23:37:35 +0000469static inline int efx_nic_event_test_irq_cpu(struct efx_channel *channel)
470{
Ben Hutchingsdd407812012-02-28 23:40:21 +0000471 return ACCESS_ONCE(channel->event_test_cpu);
Ben Hutchingseee6f6a2012-02-28 23:37:35 +0000472}
473static inline int efx_nic_irq_test_irq_cpu(struct efx_nic *efx)
474{
475 return ACCESS_ONCE(efx->last_irq_cpu);
476}
477
Ben Hutchings8ceee662008-04-27 12:55:59 +0100478/* Global Resources */
Ben Hutchings86094f72013-08-21 19:51:04 +0100479extern int efx_nic_flush_queues(struct efx_nic *efx);
Ben Hutchingsd5e8cc62012-09-06 16:52:31 +0100480extern void siena_prepare_flush(struct efx_nic *efx);
Ben Hutchings86094f72013-08-21 19:51:04 +0100481extern int efx_farch_fini_dmaq(struct efx_nic *efx);
Ben Hutchingsd5e8cc62012-09-06 16:52:31 +0100482extern void siena_finish_flush(struct efx_nic *efx);
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000483extern void falcon_start_nic_stats(struct efx_nic *efx);
484extern void falcon_stop_nic_stats(struct efx_nic *efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100485extern int falcon_reset_xaui(struct efx_nic *efx);
Ben Hutchings86094f72013-08-21 19:51:04 +0100486extern void efx_farch_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw);
487extern void efx_farch_init_common(struct efx_nic *efx);
488static inline void efx_nic_push_rx_indir_table(struct efx_nic *efx)
489{
490 efx->type->rx_push_indir_table(efx);
491}
492extern void efx_farch_rx_push_indir_table(struct efx_nic *efx);
Ben Hutchings152b6a62009-11-29 03:43:56 +0000493
494int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
Ben Hutchings0d19a542012-09-18 21:59:52 +0100495 unsigned int len, gfp_t gfp_flags);
Ben Hutchings152b6a62009-11-29 03:43:56 +0000496void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100497
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100498/* Tests */
Ben Hutchings86094f72013-08-21 19:51:04 +0100499struct efx_farch_register_test {
Ben Hutchings152b6a62009-11-29 03:43:56 +0000500 unsigned address;
501 efx_oword_t mask;
502};
Ben Hutchings86094f72013-08-21 19:51:04 +0100503extern int efx_farch_test_registers(struct efx_nic *efx,
504 const struct efx_farch_register_test *regs,
505 size_t n_regs);
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100506
Ben Hutchings5b98c1b2010-06-21 03:06:53 +0000507extern size_t efx_nic_get_regs_len(struct efx_nic *efx);
508extern void efx_nic_get_regs(struct efx_nic *efx, void *buf);
509
Ben Hutchingsab0115f2012-09-13 01:11:31 +0100510#define EFX_MAX_FLUSH_TIME 5000
Ben Hutchings8ceee662008-04-27 12:55:59 +0100511
Ben Hutchings86094f72013-08-21 19:51:04 +0100512extern void efx_farch_generate_event(struct efx_nic *efx, unsigned int evq,
513 efx_qword_t *event);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100514
Ben Hutchings744093c2009-11-29 15:12:08 +0000515#endif /* EFX_NIC_H */