Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * Driver for Solarflare Solarstorm network controllers and boards |
| 3 | * Copyright 2005-2006 Fen Systems Ltd. |
Ben Hutchings | 0a6f40c | 2011-02-25 00:01:34 +0000 | [diff] [blame] | 4 | * Copyright 2006-2011 Solarflare Communications Inc. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 5 | * |
| 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 Hutchings | 744093c | 2009-11-29 15:12:08 +0000 | [diff] [blame] | 11 | #ifndef EFX_NIC_H |
| 12 | #define EFX_NIC_H |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 13 | |
Stuart Hodgson | 7c236c4 | 2012-09-03 11:09:36 +0100 | [diff] [blame] | 14 | #include <linux/net_tstamp.h> |
Ben Hutchings | 5c16a96 | 2009-11-23 16:05:28 +0000 | [diff] [blame] | 15 | #include <linux/i2c-algo-bit.h> |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 16 | #include "net_driver.h" |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 17 | #include "efx.h" |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 18 | #include "mcdi.h" |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 19 | #include "spi.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * Falcon hardware control |
| 23 | */ |
| 24 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 25 | enum { |
| 26 | EFX_REV_FALCON_A0 = 0, |
| 27 | EFX_REV_FALCON_A1 = 1, |
| 28 | EFX_REV_FALCON_B0 = 2, |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 29 | EFX_REV_SIENA_A0 = 3, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 30 | }; |
| 31 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 32 | static inline int efx_nic_rev(struct efx_nic *efx) |
Ben Hutchings | 5566861 | 2008-05-16 21:16:10 +0100 | [diff] [blame] | 33 | { |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 34 | return efx->type->revision; |
Ben Hutchings | 5566861 | 2008-05-16 21:16:10 +0100 | [diff] [blame] | 35 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 36 | |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 37 | extern u32 efx_farch_fpga_ver(struct efx_nic *efx); |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 38 | |
| 39 | /* NIC has two interlinked PCI functions for the same port. */ |
| 40 | static 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 Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 45 | /* Read the current event from the event queue */ |
| 46 | static 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 | */ |
| 63 | static 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 | */ |
| 72 | static inline efx_qword_t * |
| 73 | efx_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 | */ |
| 84 | static 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 */ |
| 98 | static inline efx_qword_t * |
| 99 | efx_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 Hutchings | c1c4f45 | 2009-11-29 15:08:55 +0000 | [diff] [blame] | 104 | enum { |
| 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 Hutchings | 5b6262d | 2012-02-02 21:21:15 +0000 | [diff] [blame] | 124 | /* 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 Hutchings | 5c16a96 | 2009-11-23 16:05:28 +0000 | [diff] [blame] | 129 | /** |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 130 | * struct falcon_board_type - board operations and type information |
| 131 | * @id: Board type id, as found in NVRAM |
Ben Hutchings | 3759433 | 2009-11-23 16:05:45 +0000 | [diff] [blame] | 132 | * @init: Allocate resources and initialise peripheral hardware |
| 133 | * @init_phy: Do board-specific PHY initialisation |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 134 | * @fini: Shut down hardware and free resources |
Ben Hutchings | 3759433 | 2009-11-23 16:05:45 +0000 | [diff] [blame] | 135 | * @set_id_led: Set state of identifying LED or revert to automatic function |
| 136 | * @monitor: Board-specific health check function |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 137 | */ |
| 138 | struct falcon_board_type { |
| 139 | u8 id; |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 140 | 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 Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 152 | * @i2c_adap: I2C adapter for on-board peripherals |
| 153 | * @i2c_data: Data for bit-banging algorithm |
Ben Hutchings | 3759433 | 2009-11-23 16:05:45 +0000 | [diff] [blame] | 154 | * @hwmon_client: I2C client for hardware monitor |
| 155 | * @ioexp_client: I2C client for power/port control |
| 156 | */ |
| 157 | struct falcon_board { |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 158 | const struct falcon_board_type *type; |
Ben Hutchings | 3759433 | 2009-11-23 16:05:45 +0000 | [diff] [blame] | 159 | int major; |
| 160 | int minor; |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 161 | struct i2c_adapter i2c_adap; |
| 162 | struct i2c_algo_bit_data i2c_data; |
Ben Hutchings | 3759433 | 2009-11-23 16:05:45 +0000 | [diff] [blame] | 163 | struct i2c_client *hwmon_client, *ioexp_client; |
| 164 | }; |
| 165 | |
| 166 | /** |
Ben Hutchings | 5c16a96 | 2009-11-23 16:05:28 +0000 | [diff] [blame] | 167 | * struct falcon_nic_data - Falcon NIC state |
Ben Hutchings | 8986352 | 2009-11-25 16:09:04 +0000 | [diff] [blame] | 168 | * @pci_dev2: Secondary function of Falcon A |
Ben Hutchings | 3759433 | 2009-11-23 16:05:45 +0000 | [diff] [blame] | 169 | * @board: Board state and functions |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 170 | * @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 Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 174 | * @spi_flash: SPI flash device |
| 175 | * @spi_eeprom: SPI EEPROM device |
| 176 | * @spi_lock: SPI bus lock |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 177 | * @mdio_lock: MDIO bus lock |
Ben Hutchings | cef68bd | 2010-12-02 13:47:51 +0000 | [diff] [blame] | 178 | * @xmac_poll_required: XMAC link state needs polling |
Ben Hutchings | 5c16a96 | 2009-11-23 16:05:28 +0000 | [diff] [blame] | 179 | */ |
| 180 | struct falcon_nic_data { |
| 181 | struct pci_dev *pci_dev2; |
Ben Hutchings | 3759433 | 2009-11-23 16:05:45 +0000 | [diff] [blame] | 182 | struct falcon_board board; |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 183 | unsigned int stats_disable_count; |
| 184 | bool stats_pending; |
| 185 | struct timer_list stats_timer; |
| 186 | u32 *stats_dma_done; |
Ben Hutchings | ecd0a6f | 2012-11-28 04:12:41 +0000 | [diff] [blame^] | 187 | struct falcon_spi_device spi_flash; |
| 188 | struct falcon_spi_device spi_eeprom; |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 189 | struct mutex spi_lock; |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 190 | struct mutex mdio_lock; |
Ben Hutchings | cef68bd | 2010-12-02 13:47:51 +0000 | [diff] [blame] | 191 | bool xmac_poll_required; |
Ben Hutchings | 5c16a96 | 2009-11-23 16:05:28 +0000 | [diff] [blame] | 192 | }; |
| 193 | |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 194 | static inline struct falcon_board *falcon_board(struct efx_nic *efx) |
| 195 | { |
Ben Hutchings | 3759433 | 2009-11-23 16:05:45 +0000 | [diff] [blame] | 196 | struct falcon_nic_data *data = efx->nic_data; |
| 197 | return &data->board; |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 200 | /** |
| 201 | * struct siena_nic_data - Siena NIC state |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 202 | * @wol_filter_id: Wake-on-LAN packet filter id |
| 203 | */ |
| 204 | struct siena_nic_data { |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 205 | int wol_filter_id; |
| 206 | }; |
| 207 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 208 | /* |
| 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 | |
| 239 | static inline bool efx_sriov_wanted(struct efx_nic *efx) |
| 240 | { |
| 241 | return efx->vf_count != 0; |
| 242 | } |
| 243 | static inline bool efx_sriov_enabled(struct efx_nic *efx) |
| 244 | { |
| 245 | return efx->vf_init_count != 0; |
| 246 | } |
| 247 | static inline unsigned int efx_vf_size(struct efx_nic *efx) |
| 248 | { |
| 249 | return 1 << efx->vi_scale; |
| 250 | } |
| 251 | |
| 252 | extern int efx_init_sriov(void); |
| 253 | extern void efx_sriov_probe(struct efx_nic *efx); |
| 254 | extern int efx_sriov_init(struct efx_nic *efx); |
| 255 | extern void efx_sriov_mac_address_changed(struct efx_nic *efx); |
| 256 | extern void efx_sriov_tx_flush_done(struct efx_nic *efx, efx_qword_t *event); |
| 257 | extern void efx_sriov_rx_flush_done(struct efx_nic *efx, efx_qword_t *event); |
| 258 | extern void efx_sriov_event(struct efx_channel *channel, efx_qword_t *event); |
| 259 | extern void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq); |
| 260 | extern void efx_sriov_flr(struct efx_nic *efx, unsigned flr); |
| 261 | extern void efx_sriov_reset(struct efx_nic *efx); |
| 262 | extern void efx_sriov_fini(struct efx_nic *efx); |
| 263 | extern void efx_fini_sriov(void); |
| 264 | |
| 265 | #else |
| 266 | |
| 267 | static inline bool efx_sriov_wanted(struct efx_nic *efx) { return false; } |
| 268 | static inline bool efx_sriov_enabled(struct efx_nic *efx) { return false; } |
| 269 | static inline unsigned int efx_vf_size(struct efx_nic *efx) { return 0; } |
| 270 | |
| 271 | static inline int efx_init_sriov(void) { return 0; } |
| 272 | static inline void efx_sriov_probe(struct efx_nic *efx) {} |
| 273 | static inline int efx_sriov_init(struct efx_nic *efx) { return -EOPNOTSUPP; } |
| 274 | static inline void efx_sriov_mac_address_changed(struct efx_nic *efx) {} |
| 275 | static inline void efx_sriov_tx_flush_done(struct efx_nic *efx, |
| 276 | efx_qword_t *event) {} |
| 277 | static inline void efx_sriov_rx_flush_done(struct efx_nic *efx, |
| 278 | efx_qword_t *event) {} |
| 279 | static inline void efx_sriov_event(struct efx_channel *channel, |
| 280 | efx_qword_t *event) {} |
| 281 | static inline void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq) {} |
| 282 | static inline void efx_sriov_flr(struct efx_nic *efx, unsigned flr) {} |
| 283 | static inline void efx_sriov_reset(struct efx_nic *efx) {} |
| 284 | static inline void efx_sriov_fini(struct efx_nic *efx) {} |
| 285 | static inline void efx_fini_sriov(void) {} |
| 286 | |
| 287 | #endif |
| 288 | |
| 289 | extern int efx_sriov_set_vf_mac(struct net_device *dev, int vf, u8 *mac); |
| 290 | extern int efx_sriov_set_vf_vlan(struct net_device *dev, int vf, |
| 291 | u16 vlan, u8 qos); |
| 292 | extern int efx_sriov_get_vf_config(struct net_device *dev, int vf, |
| 293 | struct ifla_vf_info *ivf); |
| 294 | extern int efx_sriov_set_vf_spoofchk(struct net_device *net_dev, int vf, |
| 295 | bool spoofchk); |
| 296 | |
Stuart Hodgson | 7c236c4 | 2012-09-03 11:09:36 +0100 | [diff] [blame] | 297 | struct ethtool_ts_info; |
Stuart Hodgson | 7c236c4 | 2012-09-03 11:09:36 +0100 | [diff] [blame] | 298 | extern void efx_ptp_probe(struct efx_nic *efx); |
| 299 | extern int efx_ptp_ioctl(struct efx_nic *efx, struct ifreq *ifr, int cmd); |
Ben Hutchings | 62ebac9 | 2013-04-08 17:34:58 +0100 | [diff] [blame] | 300 | extern void efx_ptp_get_ts_info(struct efx_nic *efx, |
| 301 | struct ethtool_ts_info *ts_info); |
Stuart Hodgson | 7c236c4 | 2012-09-03 11:09:36 +0100 | [diff] [blame] | 302 | extern bool efx_ptp_is_ptp_tx(struct efx_nic *efx, struct sk_buff *skb); |
| 303 | extern int efx_ptp_tx(struct efx_nic *efx, struct sk_buff *skb); |
| 304 | extern void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev); |
Stuart Hodgson | 7c236c4 | 2012-09-03 11:09:36 +0100 | [diff] [blame] | 305 | |
stephen hemminger | 6c8c251 | 2011-04-14 05:50:12 +0000 | [diff] [blame] | 306 | extern const struct efx_nic_type falcon_a1_nic_type; |
| 307 | extern const struct efx_nic_type falcon_b0_nic_type; |
| 308 | extern const struct efx_nic_type siena_a0_nic_type; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 309 | |
| 310 | /************************************************************************** |
| 311 | * |
| 312 | * Externs |
| 313 | * |
| 314 | ************************************************************************** |
| 315 | */ |
| 316 | |
Ben Hutchings | e41c11e | 2010-04-28 09:01:50 +0000 | [diff] [blame] | 317 | extern int falcon_probe_board(struct efx_nic *efx, u16 revision_info); |
Ben Hutchings | 5087b54 | 2009-10-23 08:29:51 +0000 | [diff] [blame] | 318 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 319 | /* TX data path */ |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 320 | static inline int efx_nic_probe_tx(struct efx_tx_queue *tx_queue) |
| 321 | { |
| 322 | return tx_queue->efx->type->tx_probe(tx_queue); |
| 323 | } |
| 324 | static inline void efx_nic_init_tx(struct efx_tx_queue *tx_queue) |
| 325 | { |
| 326 | tx_queue->efx->type->tx_init(tx_queue); |
| 327 | } |
| 328 | static inline void efx_nic_remove_tx(struct efx_tx_queue *tx_queue) |
| 329 | { |
| 330 | tx_queue->efx->type->tx_remove(tx_queue); |
| 331 | } |
| 332 | static inline void efx_nic_push_buffers(struct efx_tx_queue *tx_queue) |
| 333 | { |
| 334 | tx_queue->efx->type->tx_write(tx_queue); |
| 335 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 336 | |
| 337 | /* RX data path */ |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 338 | static inline int efx_nic_probe_rx(struct efx_rx_queue *rx_queue) |
| 339 | { |
| 340 | return rx_queue->efx->type->rx_probe(rx_queue); |
| 341 | } |
| 342 | static inline void efx_nic_init_rx(struct efx_rx_queue *rx_queue) |
| 343 | { |
| 344 | rx_queue->efx->type->rx_init(rx_queue); |
| 345 | } |
| 346 | static inline void efx_nic_remove_rx(struct efx_rx_queue *rx_queue) |
| 347 | { |
| 348 | rx_queue->efx->type->rx_remove(rx_queue); |
| 349 | } |
| 350 | static inline void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue) |
| 351 | { |
| 352 | rx_queue->efx->type->rx_write(rx_queue); |
| 353 | } |
| 354 | static 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 Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 358 | |
| 359 | /* Event data path */ |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 360 | static inline int efx_nic_probe_eventq(struct efx_channel *channel) |
| 361 | { |
| 362 | return channel->efx->type->ev_probe(channel); |
| 363 | } |
| 364 | static inline void efx_nic_init_eventq(struct efx_channel *channel) |
| 365 | { |
| 366 | channel->efx->type->ev_init(channel); |
| 367 | } |
| 368 | static inline void efx_nic_fini_eventq(struct efx_channel *channel) |
| 369 | { |
| 370 | channel->efx->type->ev_fini(channel); |
| 371 | } |
| 372 | static inline void efx_nic_remove_eventq(struct efx_channel *channel) |
| 373 | { |
| 374 | channel->efx->type->ev_remove(channel); |
| 375 | } |
| 376 | static inline int |
| 377 | efx_nic_process_eventq(struct efx_channel *channel, int quota) |
| 378 | { |
| 379 | return channel->efx->type->ev_process(channel, quota); |
| 380 | } |
| 381 | static inline void efx_nic_eventq_read_ack(struct efx_channel *channel) |
| 382 | { |
| 383 | channel->efx->type->ev_read_ack(channel); |
| 384 | } |
| 385 | extern void efx_nic_event_test_start(struct efx_channel *channel); |
| 386 | |
| 387 | /* Falcon/Siena queue operations */ |
| 388 | extern int efx_farch_tx_probe(struct efx_tx_queue *tx_queue); |
| 389 | extern void efx_farch_tx_init(struct efx_tx_queue *tx_queue); |
| 390 | extern void efx_farch_tx_fini(struct efx_tx_queue *tx_queue); |
| 391 | extern void efx_farch_tx_remove(struct efx_tx_queue *tx_queue); |
| 392 | extern void efx_farch_tx_write(struct efx_tx_queue *tx_queue); |
| 393 | extern int efx_farch_rx_probe(struct efx_rx_queue *rx_queue); |
| 394 | extern void efx_farch_rx_init(struct efx_rx_queue *rx_queue); |
| 395 | extern void efx_farch_rx_fini(struct efx_rx_queue *rx_queue); |
| 396 | extern void efx_farch_rx_remove(struct efx_rx_queue *rx_queue); |
| 397 | extern void efx_farch_rx_write(struct efx_rx_queue *rx_queue); |
| 398 | extern void efx_farch_rx_defer_refill(struct efx_rx_queue *rx_queue); |
| 399 | extern int efx_farch_ev_probe(struct efx_channel *channel); |
| 400 | extern void efx_farch_ev_init(struct efx_channel *channel); |
| 401 | extern void efx_farch_ev_fini(struct efx_channel *channel); |
| 402 | extern void efx_farch_ev_remove(struct efx_channel *channel); |
| 403 | extern int efx_farch_ev_process(struct efx_channel *channel, int quota); |
| 404 | extern void efx_farch_ev_read_ack(struct efx_channel *channel); |
| 405 | extern void efx_farch_ev_test_generate(struct efx_channel *channel); |
| 406 | |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 407 | /* Falcon/Siena filter operations */ |
| 408 | extern int efx_farch_filter_table_probe(struct efx_nic *efx); |
| 409 | extern void efx_farch_filter_table_restore(struct efx_nic *efx); |
| 410 | extern void efx_farch_filter_table_remove(struct efx_nic *efx); |
| 411 | extern void efx_farch_filter_update_rx_scatter(struct efx_nic *efx); |
| 412 | extern s32 efx_farch_filter_insert(struct efx_nic *efx, |
| 413 | struct efx_filter_spec *spec, bool replace); |
| 414 | extern int efx_farch_filter_remove_safe(struct efx_nic *efx, |
| 415 | enum efx_filter_priority priority, |
| 416 | u32 filter_id); |
| 417 | extern int efx_farch_filter_get_safe(struct efx_nic *efx, |
| 418 | enum efx_filter_priority priority, |
| 419 | u32 filter_id, struct efx_filter_spec *); |
| 420 | extern void efx_farch_filter_clear_rx(struct efx_nic *efx, |
| 421 | enum efx_filter_priority priority); |
| 422 | extern u32 efx_farch_filter_count_rx_used(struct efx_nic *efx, |
| 423 | enum efx_filter_priority priority); |
| 424 | extern u32 efx_farch_filter_get_rx_id_limit(struct efx_nic *efx); |
| 425 | extern 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 |
| 429 | extern s32 efx_farch_filter_rfs_insert(struct efx_nic *efx, |
| 430 | struct efx_filter_spec *spec); |
| 431 | extern bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id, |
| 432 | unsigned int index); |
| 433 | #endif |
Ben Hutchings | 964e613 | 2012-11-19 23:08:22 +0000 | [diff] [blame] | 434 | extern void efx_farch_filter_sync_rx_mode(struct efx_nic *efx); |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 435 | |
Ben Hutchings | d4fabcc | 2011-04-04 14:22:11 +0100 | [diff] [blame] | 436 | extern bool efx_nic_event_present(struct efx_channel *channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 437 | |
Ben Hutchings | b7f514a | 2012-07-04 22:25:07 +0100 | [diff] [blame] | 438 | /* 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 | */ |
| 450 | static inline void efx_update_diff_stat(u64 *stat, u64 diff) |
| 451 | { |
| 452 | if ((s64)(diff - *stat) > 0) |
| 453 | *stat = diff; |
| 454 | } |
| 455 | |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 456 | /* Interrupts */ |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 457 | extern int efx_nic_init_interrupt(struct efx_nic *efx); |
Ben Hutchings | eee6f6a | 2012-02-28 23:37:35 +0000 | [diff] [blame] | 458 | extern void efx_nic_irq_test_start(struct efx_nic *efx); |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 459 | extern void efx_nic_fini_interrupt(struct efx_nic *efx); |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 460 | |
| 461 | /* Falcon/Siena interrupts */ |
| 462 | extern void efx_farch_irq_enable_master(struct efx_nic *efx); |
| 463 | extern void efx_farch_irq_test_generate(struct efx_nic *efx); |
| 464 | extern void efx_farch_irq_disable_master(struct efx_nic *efx); |
| 465 | extern irqreturn_t efx_farch_msi_interrupt(int irq, void *dev_id); |
| 466 | extern irqreturn_t efx_farch_legacy_interrupt(int irq, void *dev_id); |
| 467 | extern irqreturn_t efx_farch_fatal_interrupt(struct efx_nic *efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 468 | |
Ben Hutchings | eee6f6a | 2012-02-28 23:37:35 +0000 | [diff] [blame] | 469 | static inline int efx_nic_event_test_irq_cpu(struct efx_channel *channel) |
| 470 | { |
Ben Hutchings | dd40781 | 2012-02-28 23:40:21 +0000 | [diff] [blame] | 471 | return ACCESS_ONCE(channel->event_test_cpu); |
Ben Hutchings | eee6f6a | 2012-02-28 23:37:35 +0000 | [diff] [blame] | 472 | } |
| 473 | static inline int efx_nic_irq_test_irq_cpu(struct efx_nic *efx) |
| 474 | { |
| 475 | return ACCESS_ONCE(efx->last_irq_cpu); |
| 476 | } |
| 477 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 478 | /* Global Resources */ |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 479 | extern int efx_nic_flush_queues(struct efx_nic *efx); |
Ben Hutchings | d5e8cc6 | 2012-09-06 16:52:31 +0100 | [diff] [blame] | 480 | extern void siena_prepare_flush(struct efx_nic *efx); |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 481 | extern int efx_farch_fini_dmaq(struct efx_nic *efx); |
Ben Hutchings | d5e8cc6 | 2012-09-06 16:52:31 +0100 | [diff] [blame] | 482 | extern void siena_finish_flush(struct efx_nic *efx); |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 483 | extern void falcon_start_nic_stats(struct efx_nic *efx); |
| 484 | extern void falcon_stop_nic_stats(struct efx_nic *efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 485 | extern int falcon_reset_xaui(struct efx_nic *efx); |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 486 | extern void efx_farch_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw); |
| 487 | extern void efx_farch_init_common(struct efx_nic *efx); |
| 488 | static inline void efx_nic_push_rx_indir_table(struct efx_nic *efx) |
| 489 | { |
| 490 | efx->type->rx_push_indir_table(efx); |
| 491 | } |
| 492 | extern void efx_farch_rx_push_indir_table(struct efx_nic *efx); |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 493 | |
| 494 | int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer, |
Ben Hutchings | 0d19a54 | 2012-09-18 21:59:52 +0100 | [diff] [blame] | 495 | unsigned int len, gfp_t gfp_flags); |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 496 | void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 497 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 498 | /* Tests */ |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 499 | struct efx_farch_register_test { |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 500 | unsigned address; |
| 501 | efx_oword_t mask; |
| 502 | }; |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 503 | extern int efx_farch_test_registers(struct efx_nic *efx, |
| 504 | const struct efx_farch_register_test *regs, |
| 505 | size_t n_regs); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 506 | |
Ben Hutchings | 5b98c1b | 2010-06-21 03:06:53 +0000 | [diff] [blame] | 507 | extern size_t efx_nic_get_regs_len(struct efx_nic *efx); |
| 508 | extern void efx_nic_get_regs(struct efx_nic *efx, void *buf); |
| 509 | |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 510 | #define EFX_MAX_FLUSH_TIME 5000 |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 511 | |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 512 | extern void efx_farch_generate_event(struct efx_nic *efx, unsigned int evq, |
| 513 | efx_qword_t *event); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 514 | |
Ben Hutchings | 744093c | 2009-11-29 15:12:08 +0000 | [diff] [blame] | 515 | #endif /* EFX_NIC_H */ |