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 37874aeea5SJeff Kirsher extern u32 efx_nic_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 45874aeea5SJeff Kirsher enum { 46874aeea5SJeff Kirsher PHY_TYPE_NONE = 0, 47874aeea5SJeff Kirsher PHY_TYPE_TXC43128 = 1, 48874aeea5SJeff Kirsher PHY_TYPE_88E1111 = 2, 49874aeea5SJeff Kirsher PHY_TYPE_SFX7101 = 3, 50874aeea5SJeff Kirsher PHY_TYPE_QT2022C2 = 4, 51874aeea5SJeff Kirsher PHY_TYPE_PM8358 = 6, 52874aeea5SJeff Kirsher PHY_TYPE_SFT9001A = 8, 53874aeea5SJeff Kirsher PHY_TYPE_QT2025C = 9, 54874aeea5SJeff Kirsher PHY_TYPE_SFT9001B = 10, 55874aeea5SJeff Kirsher }; 56874aeea5SJeff Kirsher 57874aeea5SJeff Kirsher #define FALCON_XMAC_LOOPBACKS \ 58874aeea5SJeff Kirsher ((1 << LOOPBACK_XGMII) | \ 59874aeea5SJeff Kirsher (1 << LOOPBACK_XGXS) | \ 60874aeea5SJeff Kirsher (1 << LOOPBACK_XAUI)) 61874aeea5SJeff Kirsher 62874aeea5SJeff Kirsher #define FALCON_GMAC_LOOPBACKS \ 63874aeea5SJeff Kirsher (1 << LOOPBACK_GMAC) 64874aeea5SJeff Kirsher 655b6262d0SBen Hutchings /* Alignment of PCIe DMA boundaries (4KB) */ 665b6262d0SBen Hutchings #define EFX_PAGE_SIZE 4096 675b6262d0SBen Hutchings /* Size and alignment of buffer table entries (same) */ 685b6262d0SBen Hutchings #define EFX_BUF_SIZE EFX_PAGE_SIZE 695b6262d0SBen Hutchings 70874aeea5SJeff Kirsher /** 71874aeea5SJeff Kirsher * struct falcon_board_type - board operations and type information 72874aeea5SJeff Kirsher * @id: Board type id, as found in NVRAM 73874aeea5SJeff Kirsher * @init: Allocate resources and initialise peripheral hardware 74874aeea5SJeff Kirsher * @init_phy: Do board-specific PHY initialisation 75874aeea5SJeff Kirsher * @fini: Shut down hardware and free resources 76874aeea5SJeff Kirsher * @set_id_led: Set state of identifying LED or revert to automatic function 77874aeea5SJeff Kirsher * @monitor: Board-specific health check function 78874aeea5SJeff Kirsher */ 79874aeea5SJeff Kirsher struct falcon_board_type { 80874aeea5SJeff Kirsher u8 id; 81874aeea5SJeff Kirsher int (*init) (struct efx_nic *nic); 82874aeea5SJeff Kirsher void (*init_phy) (struct efx_nic *efx); 83874aeea5SJeff Kirsher void (*fini) (struct efx_nic *nic); 84874aeea5SJeff Kirsher void (*set_id_led) (struct efx_nic *efx, enum efx_led_mode mode); 85874aeea5SJeff Kirsher int (*monitor) (struct efx_nic *nic); 86874aeea5SJeff Kirsher }; 87874aeea5SJeff Kirsher 88874aeea5SJeff Kirsher /** 89874aeea5SJeff Kirsher * struct falcon_board - board information 90874aeea5SJeff Kirsher * @type: Type of board 91874aeea5SJeff Kirsher * @major: Major rev. ('A', 'B' ...) 92874aeea5SJeff Kirsher * @minor: Minor rev. (0, 1, ...) 93874aeea5SJeff Kirsher * @i2c_adap: I2C adapter for on-board peripherals 94874aeea5SJeff Kirsher * @i2c_data: Data for bit-banging algorithm 95874aeea5SJeff Kirsher * @hwmon_client: I2C client for hardware monitor 96874aeea5SJeff Kirsher * @ioexp_client: I2C client for power/port control 97874aeea5SJeff Kirsher */ 98874aeea5SJeff Kirsher struct falcon_board { 99874aeea5SJeff Kirsher const struct falcon_board_type *type; 100874aeea5SJeff Kirsher int major; 101874aeea5SJeff Kirsher int minor; 102874aeea5SJeff Kirsher struct i2c_adapter i2c_adap; 103874aeea5SJeff Kirsher struct i2c_algo_bit_data i2c_data; 104874aeea5SJeff Kirsher struct i2c_client *hwmon_client, *ioexp_client; 105874aeea5SJeff Kirsher }; 106874aeea5SJeff Kirsher 107874aeea5SJeff Kirsher /** 108874aeea5SJeff Kirsher * struct falcon_nic_data - Falcon NIC state 109874aeea5SJeff Kirsher * @pci_dev2: Secondary function of Falcon A 110874aeea5SJeff Kirsher * @board: Board state and functions 111874aeea5SJeff Kirsher * @stats_disable_count: Nest count for disabling statistics fetches 112874aeea5SJeff Kirsher * @stats_pending: Is there a pending DMA of MAC statistics. 113874aeea5SJeff Kirsher * @stats_timer: A timer for regularly fetching MAC statistics. 114874aeea5SJeff Kirsher * @stats_dma_done: Pointer to the flag which indicates DMA completion. 115874aeea5SJeff Kirsher * @spi_flash: SPI flash device 116874aeea5SJeff Kirsher * @spi_eeprom: SPI EEPROM device 117874aeea5SJeff Kirsher * @spi_lock: SPI bus lock 118874aeea5SJeff Kirsher * @mdio_lock: MDIO bus lock 119874aeea5SJeff Kirsher * @xmac_poll_required: XMAC link state needs polling 120874aeea5SJeff Kirsher */ 121874aeea5SJeff Kirsher struct falcon_nic_data { 122874aeea5SJeff Kirsher struct pci_dev *pci_dev2; 123874aeea5SJeff Kirsher struct falcon_board board; 124874aeea5SJeff Kirsher unsigned int stats_disable_count; 125874aeea5SJeff Kirsher bool stats_pending; 126874aeea5SJeff Kirsher struct timer_list stats_timer; 127874aeea5SJeff Kirsher u32 *stats_dma_done; 128874aeea5SJeff Kirsher struct efx_spi_device spi_flash; 129874aeea5SJeff Kirsher struct efx_spi_device spi_eeprom; 130874aeea5SJeff Kirsher struct mutex spi_lock; 131874aeea5SJeff Kirsher struct mutex mdio_lock; 132874aeea5SJeff Kirsher bool xmac_poll_required; 133874aeea5SJeff Kirsher }; 134874aeea5SJeff Kirsher 135874aeea5SJeff Kirsher static inline struct falcon_board *falcon_board(struct efx_nic *efx) 136874aeea5SJeff Kirsher { 137874aeea5SJeff Kirsher struct falcon_nic_data *data = efx->nic_data; 138874aeea5SJeff Kirsher return &data->board; 139874aeea5SJeff Kirsher } 140874aeea5SJeff Kirsher 141874aeea5SJeff Kirsher /** 142874aeea5SJeff Kirsher * struct siena_nic_data - Siena NIC state 143874aeea5SJeff Kirsher * @mcdi: Management-Controller-to-Driver Interface 144874aeea5SJeff Kirsher * @wol_filter_id: Wake-on-LAN packet filter id 14555c5e0f8SBen Hutchings * @hwmon: Hardware monitor state 146874aeea5SJeff Kirsher */ 147874aeea5SJeff Kirsher struct siena_nic_data { 148874aeea5SJeff Kirsher struct efx_mcdi_iface mcdi; 149874aeea5SJeff Kirsher int wol_filter_id; 15055c5e0f8SBen Hutchings #ifdef CONFIG_SFC_MCDI_MON 15155c5e0f8SBen Hutchings struct efx_mcdi_mon hwmon; 15255c5e0f8SBen Hutchings #endif 153874aeea5SJeff Kirsher }; 154874aeea5SJeff Kirsher 15555c5e0f8SBen Hutchings #ifdef CONFIG_SFC_MCDI_MON 15655c5e0f8SBen Hutchings static inline struct efx_mcdi_mon *efx_mcdi_mon(struct efx_nic *efx) 15755c5e0f8SBen Hutchings { 15855c5e0f8SBen Hutchings struct siena_nic_data *nic_data; 15955c5e0f8SBen Hutchings EFX_BUG_ON_PARANOID(efx_nic_rev(efx) < EFX_REV_SIENA_A0); 16055c5e0f8SBen Hutchings nic_data = efx->nic_data; 16155c5e0f8SBen Hutchings return &nic_data->hwmon; 16255c5e0f8SBen Hutchings } 16355c5e0f8SBen Hutchings #endif 16455c5e0f8SBen Hutchings 165cd2d5b52SBen Hutchings /* 166cd2d5b52SBen Hutchings * On the SFC9000 family each port is associated with 1 PCI physical 167cd2d5b52SBen Hutchings * function (PF) handled by sfc and a configurable number of virtual 168cd2d5b52SBen Hutchings * functions (VFs) that may be handled by some other driver, often in 169cd2d5b52SBen Hutchings * a VM guest. The queue pointer registers are mapped in both PF and 170cd2d5b52SBen Hutchings * VF BARs such that an 8K region provides access to a single RX, TX 171cd2d5b52SBen Hutchings * and event queue (collectively a Virtual Interface, VI or VNIC). 172cd2d5b52SBen Hutchings * 173cd2d5b52SBen Hutchings * The PF has access to all 1024 VIs while VFs are mapped to VIs 174cd2d5b52SBen Hutchings * according to VI_BASE and VI_SCALE: VF i has access to VIs numbered 175cd2d5b52SBen Hutchings * in range [VI_BASE + i << VI_SCALE, VI_BASE + i + 1 << VI_SCALE). 176cd2d5b52SBen Hutchings * The number of VIs and the VI_SCALE value are configurable but must 177cd2d5b52SBen Hutchings * be established at boot time by firmware. 178cd2d5b52SBen Hutchings */ 179cd2d5b52SBen Hutchings 180cd2d5b52SBen Hutchings /* Maximum VI_SCALE parameter supported by Siena */ 181cd2d5b52SBen Hutchings #define EFX_VI_SCALE_MAX 6 182cd2d5b52SBen Hutchings /* Base VI to use for SR-IOV. Must be aligned to (1 << EFX_VI_SCALE_MAX), 183cd2d5b52SBen Hutchings * so this is the smallest allowed value. */ 184cd2d5b52SBen Hutchings #define EFX_VI_BASE 128U 185cd2d5b52SBen Hutchings /* Maximum number of VFs allowed */ 186cd2d5b52SBen Hutchings #define EFX_VF_COUNT_MAX 127 187cd2d5b52SBen Hutchings /* Limit EVQs on VFs to be only 8k to reduce buffer table reservation */ 188cd2d5b52SBen Hutchings #define EFX_MAX_VF_EVQ_SIZE 8192UL 189cd2d5b52SBen Hutchings /* The number of buffer table entries reserved for each VI on a VF */ 190cd2d5b52SBen Hutchings #define EFX_VF_BUFTBL_PER_VI \ 191cd2d5b52SBen Hutchings ((EFX_MAX_VF_EVQ_SIZE + 2 * EFX_MAX_DMAQ_SIZE) * \ 192cd2d5b52SBen Hutchings sizeof(efx_qword_t) / EFX_BUF_SIZE) 193cd2d5b52SBen Hutchings 194cd2d5b52SBen Hutchings #ifdef CONFIG_SFC_SRIOV 195cd2d5b52SBen Hutchings 196cd2d5b52SBen Hutchings static inline bool efx_sriov_wanted(struct efx_nic *efx) 197cd2d5b52SBen Hutchings { 198cd2d5b52SBen Hutchings return efx->vf_count != 0; 199cd2d5b52SBen Hutchings } 200cd2d5b52SBen Hutchings static inline bool efx_sriov_enabled(struct efx_nic *efx) 201cd2d5b52SBen Hutchings { 202cd2d5b52SBen Hutchings return efx->vf_init_count != 0; 203cd2d5b52SBen Hutchings } 204cd2d5b52SBen Hutchings static inline unsigned int efx_vf_size(struct efx_nic *efx) 205cd2d5b52SBen Hutchings { 206cd2d5b52SBen Hutchings return 1 << efx->vi_scale; 207cd2d5b52SBen Hutchings } 208cd2d5b52SBen Hutchings 209cd2d5b52SBen Hutchings extern int efx_init_sriov(void); 210cd2d5b52SBen Hutchings extern void efx_sriov_probe(struct efx_nic *efx); 211cd2d5b52SBen Hutchings extern int efx_sriov_init(struct efx_nic *efx); 212cd2d5b52SBen Hutchings extern void efx_sriov_mac_address_changed(struct efx_nic *efx); 213cd2d5b52SBen Hutchings extern void efx_sriov_tx_flush_done(struct efx_nic *efx, efx_qword_t *event); 214cd2d5b52SBen Hutchings extern void efx_sriov_rx_flush_done(struct efx_nic *efx, efx_qword_t *event); 215cd2d5b52SBen Hutchings extern void efx_sriov_event(struct efx_channel *channel, efx_qword_t *event); 216cd2d5b52SBen Hutchings extern void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq); 217cd2d5b52SBen Hutchings extern void efx_sriov_flr(struct efx_nic *efx, unsigned flr); 218cd2d5b52SBen Hutchings extern void efx_sriov_reset(struct efx_nic *efx); 219cd2d5b52SBen Hutchings extern void efx_sriov_fini(struct efx_nic *efx); 220cd2d5b52SBen Hutchings extern void efx_fini_sriov(void); 221cd2d5b52SBen Hutchings 222cd2d5b52SBen Hutchings #else 223cd2d5b52SBen Hutchings 224cd2d5b52SBen Hutchings static inline bool efx_sriov_wanted(struct efx_nic *efx) { return false; } 225cd2d5b52SBen Hutchings static inline bool efx_sriov_enabled(struct efx_nic *efx) { return false; } 226cd2d5b52SBen Hutchings static inline unsigned int efx_vf_size(struct efx_nic *efx) { return 0; } 227cd2d5b52SBen Hutchings 228cd2d5b52SBen Hutchings static inline int efx_init_sriov(void) { return 0; } 229cd2d5b52SBen Hutchings static inline void efx_sriov_probe(struct efx_nic *efx) {} 230cd2d5b52SBen Hutchings static inline int efx_sriov_init(struct efx_nic *efx) { return -EOPNOTSUPP; } 231cd2d5b52SBen Hutchings static inline void efx_sriov_mac_address_changed(struct efx_nic *efx) {} 232cd2d5b52SBen Hutchings static inline void efx_sriov_tx_flush_done(struct efx_nic *efx, 233cd2d5b52SBen Hutchings efx_qword_t *event) {} 234cd2d5b52SBen Hutchings static inline void efx_sriov_rx_flush_done(struct efx_nic *efx, 235cd2d5b52SBen Hutchings efx_qword_t *event) {} 236cd2d5b52SBen Hutchings static inline void efx_sriov_event(struct efx_channel *channel, 237cd2d5b52SBen Hutchings efx_qword_t *event) {} 238cd2d5b52SBen Hutchings static inline void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq) {} 239cd2d5b52SBen Hutchings static inline void efx_sriov_flr(struct efx_nic *efx, unsigned flr) {} 240cd2d5b52SBen Hutchings static inline void efx_sriov_reset(struct efx_nic *efx) {} 241cd2d5b52SBen Hutchings static inline void efx_sriov_fini(struct efx_nic *efx) {} 242cd2d5b52SBen Hutchings static inline void efx_fini_sriov(void) {} 243cd2d5b52SBen Hutchings 244cd2d5b52SBen Hutchings #endif 245cd2d5b52SBen Hutchings 246cd2d5b52SBen Hutchings extern int efx_sriov_set_vf_mac(struct net_device *dev, int vf, u8 *mac); 247cd2d5b52SBen Hutchings extern int efx_sriov_set_vf_vlan(struct net_device *dev, int vf, 248cd2d5b52SBen Hutchings u16 vlan, u8 qos); 249cd2d5b52SBen Hutchings extern int efx_sriov_get_vf_config(struct net_device *dev, int vf, 250cd2d5b52SBen Hutchings struct ifla_vf_info *ivf); 251cd2d5b52SBen Hutchings extern int efx_sriov_set_vf_spoofchk(struct net_device *net_dev, int vf, 252cd2d5b52SBen Hutchings bool spoofchk); 253cd2d5b52SBen Hutchings 2547c236c43SStuart Hodgson struct ethtool_ts_info; 2557c236c43SStuart Hodgson extern void efx_ptp_probe(struct efx_nic *efx); 2567c236c43SStuart Hodgson extern int efx_ptp_ioctl(struct efx_nic *efx, struct ifreq *ifr, int cmd); 2577c236c43SStuart Hodgson extern int efx_ptp_get_ts_info(struct net_device *net_dev, 2587c236c43SStuart Hodgson struct ethtool_ts_info *ts_info); 2597c236c43SStuart Hodgson extern bool efx_ptp_is_ptp_tx(struct efx_nic *efx, struct sk_buff *skb); 2607c236c43SStuart Hodgson extern int efx_ptp_tx(struct efx_nic *efx, struct sk_buff *skb); 2617c236c43SStuart Hodgson extern void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev); 2627c236c43SStuart Hodgson 263874aeea5SJeff Kirsher extern const struct efx_nic_type falcon_a1_nic_type; 264874aeea5SJeff Kirsher extern const struct efx_nic_type falcon_b0_nic_type; 265874aeea5SJeff Kirsher extern const struct efx_nic_type siena_a0_nic_type; 266874aeea5SJeff Kirsher 267874aeea5SJeff Kirsher /************************************************************************** 268874aeea5SJeff Kirsher * 269874aeea5SJeff Kirsher * Externs 270874aeea5SJeff Kirsher * 271874aeea5SJeff Kirsher ************************************************************************** 272874aeea5SJeff Kirsher */ 273874aeea5SJeff Kirsher 274874aeea5SJeff Kirsher extern int falcon_probe_board(struct efx_nic *efx, u16 revision_info); 275874aeea5SJeff Kirsher 276874aeea5SJeff Kirsher /* TX data path */ 277874aeea5SJeff Kirsher extern int efx_nic_probe_tx(struct efx_tx_queue *tx_queue); 278874aeea5SJeff Kirsher extern void efx_nic_init_tx(struct efx_tx_queue *tx_queue); 279874aeea5SJeff Kirsher extern void efx_nic_fini_tx(struct efx_tx_queue *tx_queue); 280874aeea5SJeff Kirsher extern void efx_nic_remove_tx(struct efx_tx_queue *tx_queue); 281874aeea5SJeff Kirsher extern void efx_nic_push_buffers(struct efx_tx_queue *tx_queue); 282874aeea5SJeff Kirsher 283874aeea5SJeff Kirsher /* RX data path */ 284874aeea5SJeff Kirsher extern int efx_nic_probe_rx(struct efx_rx_queue *rx_queue); 285874aeea5SJeff Kirsher extern void efx_nic_init_rx(struct efx_rx_queue *rx_queue); 286874aeea5SJeff Kirsher extern void efx_nic_fini_rx(struct efx_rx_queue *rx_queue); 287874aeea5SJeff Kirsher extern void efx_nic_remove_rx(struct efx_rx_queue *rx_queue); 288874aeea5SJeff Kirsher extern void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue); 2892ae75dacSBen Hutchings extern void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue); 290874aeea5SJeff Kirsher 291874aeea5SJeff Kirsher /* Event data path */ 292874aeea5SJeff Kirsher extern int efx_nic_probe_eventq(struct efx_channel *channel); 293874aeea5SJeff Kirsher extern void efx_nic_init_eventq(struct efx_channel *channel); 294874aeea5SJeff Kirsher extern void efx_nic_fini_eventq(struct efx_channel *channel); 295874aeea5SJeff Kirsher extern void efx_nic_remove_eventq(struct efx_channel *channel); 296874aeea5SJeff Kirsher extern int efx_nic_process_eventq(struct efx_channel *channel, int rx_quota); 297874aeea5SJeff Kirsher extern void efx_nic_eventq_read_ack(struct efx_channel *channel); 298874aeea5SJeff Kirsher extern bool efx_nic_event_present(struct efx_channel *channel); 299874aeea5SJeff Kirsher 300874aeea5SJeff Kirsher /* MAC/PHY */ 301874aeea5SJeff Kirsher extern void falcon_drain_tx_fifo(struct efx_nic *efx); 302874aeea5SJeff Kirsher extern void falcon_reconfigure_mac_wrapper(struct efx_nic *efx); 303710b208dSBen Hutchings extern bool falcon_xmac_check_fault(struct efx_nic *efx); 304710b208dSBen Hutchings extern int falcon_reconfigure_xmac(struct efx_nic *efx); 305710b208dSBen Hutchings extern void falcon_update_stats_xmac(struct efx_nic *efx); 306874aeea5SJeff Kirsher 307b7f514afSBen Hutchings /* Some statistics are computed as A - B where A and B each increase 308b7f514afSBen Hutchings * linearly with some hardware counter(s) and the counters are read 309b7f514afSBen Hutchings * asynchronously. If the counters contributing to B are always read 310b7f514afSBen Hutchings * after those contributing to A, the computed value may be lower than 311b7f514afSBen Hutchings * the true value by some variable amount, and may decrease between 312b7f514afSBen Hutchings * subsequent computations. 313b7f514afSBen Hutchings * 314b7f514afSBen Hutchings * We should never allow statistics to decrease or to exceed the true 315b7f514afSBen Hutchings * value. Since the computed value will never be greater than the 316b7f514afSBen Hutchings * true value, we can achieve this by only storing the computed value 317b7f514afSBen Hutchings * when it increases. 318b7f514afSBen Hutchings */ 319b7f514afSBen Hutchings static inline void efx_update_diff_stat(u64 *stat, u64 diff) 320b7f514afSBen Hutchings { 321b7f514afSBen Hutchings if ((s64)(diff - *stat) > 0) 322b7f514afSBen Hutchings *stat = diff; 323b7f514afSBen Hutchings } 324b7f514afSBen Hutchings 325874aeea5SJeff Kirsher /* Interrupts and test events */ 326874aeea5SJeff Kirsher extern int efx_nic_init_interrupt(struct efx_nic *efx); 327874aeea5SJeff Kirsher extern void efx_nic_enable_interrupts(struct efx_nic *efx); 328eee6f6a9SBen Hutchings extern void efx_nic_event_test_start(struct efx_channel *channel); 329eee6f6a9SBen Hutchings extern void efx_nic_irq_test_start(struct efx_nic *efx); 330874aeea5SJeff Kirsher extern void efx_nic_disable_interrupts(struct efx_nic *efx); 331874aeea5SJeff Kirsher extern void efx_nic_fini_interrupt(struct efx_nic *efx); 332874aeea5SJeff Kirsher extern irqreturn_t efx_nic_fatal_interrupt(struct efx_nic *efx); 333874aeea5SJeff Kirsher extern irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id); 334874aeea5SJeff Kirsher extern void falcon_irq_ack_a1(struct efx_nic *efx); 335874aeea5SJeff Kirsher 336eee6f6a9SBen Hutchings static inline int efx_nic_event_test_irq_cpu(struct efx_channel *channel) 337eee6f6a9SBen Hutchings { 338dd40781eSBen Hutchings return ACCESS_ONCE(channel->event_test_cpu); 339eee6f6a9SBen Hutchings } 340eee6f6a9SBen Hutchings static inline int efx_nic_irq_test_irq_cpu(struct efx_nic *efx) 341eee6f6a9SBen Hutchings { 342eee6f6a9SBen Hutchings return ACCESS_ONCE(efx->last_irq_cpu); 343eee6f6a9SBen Hutchings } 344eee6f6a9SBen Hutchings 345874aeea5SJeff Kirsher /* Global Resources */ 346874aeea5SJeff Kirsher extern int efx_nic_flush_queues(struct efx_nic *efx); 347d5e8cc6cSBen Hutchings extern void siena_prepare_flush(struct efx_nic *efx); 348d5e8cc6cSBen Hutchings extern void siena_finish_flush(struct efx_nic *efx); 349874aeea5SJeff Kirsher extern void falcon_start_nic_stats(struct efx_nic *efx); 350874aeea5SJeff Kirsher extern void falcon_stop_nic_stats(struct efx_nic *efx); 351874aeea5SJeff Kirsher extern void falcon_setup_xaui(struct efx_nic *efx); 352874aeea5SJeff Kirsher extern int falcon_reset_xaui(struct efx_nic *efx); 35328e47c49SBen Hutchings extern void 35428e47c49SBen Hutchings efx_nic_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw); 355874aeea5SJeff Kirsher extern void efx_nic_init_common(struct efx_nic *efx); 356874aeea5SJeff Kirsher extern void efx_nic_push_rx_indir_table(struct efx_nic *efx); 357874aeea5SJeff Kirsher 358874aeea5SJeff Kirsher int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer, 359874aeea5SJeff Kirsher unsigned int len); 360874aeea5SJeff Kirsher void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer); 361874aeea5SJeff Kirsher 362874aeea5SJeff Kirsher /* Tests */ 363874aeea5SJeff Kirsher struct efx_nic_register_test { 364874aeea5SJeff Kirsher unsigned address; 365874aeea5SJeff Kirsher efx_oword_t mask; 366874aeea5SJeff Kirsher }; 367874aeea5SJeff Kirsher extern int efx_nic_test_registers(struct efx_nic *efx, 368874aeea5SJeff Kirsher const struct efx_nic_register_test *regs, 369874aeea5SJeff Kirsher size_t n_regs); 370874aeea5SJeff Kirsher 371874aeea5SJeff Kirsher extern size_t efx_nic_get_regs_len(struct efx_nic *efx); 372874aeea5SJeff Kirsher extern void efx_nic_get_regs(struct efx_nic *efx, void *buf); 373874aeea5SJeff Kirsher 374874aeea5SJeff Kirsher /************************************************************************** 375874aeea5SJeff Kirsher * 376874aeea5SJeff Kirsher * Falcon MAC stats 377874aeea5SJeff Kirsher * 378874aeea5SJeff Kirsher ************************************************************************** 379874aeea5SJeff Kirsher */ 380874aeea5SJeff Kirsher 381874aeea5SJeff Kirsher #define FALCON_STAT_OFFSET(falcon_stat) EFX_VAL(falcon_stat, offset) 382874aeea5SJeff Kirsher #define FALCON_STAT_WIDTH(falcon_stat) EFX_VAL(falcon_stat, WIDTH) 383874aeea5SJeff Kirsher 384874aeea5SJeff Kirsher /* Retrieve statistic from statistics block */ 385874aeea5SJeff Kirsher #define FALCON_STAT(efx, falcon_stat, efx_stat) do { \ 386874aeea5SJeff Kirsher if (FALCON_STAT_WIDTH(falcon_stat) == 16) \ 387874aeea5SJeff Kirsher (efx)->mac_stats.efx_stat += le16_to_cpu( \ 388874aeea5SJeff Kirsher *((__force __le16 *) \ 389874aeea5SJeff Kirsher (efx->stats_buffer.addr + \ 390874aeea5SJeff Kirsher FALCON_STAT_OFFSET(falcon_stat)))); \ 391874aeea5SJeff Kirsher else if (FALCON_STAT_WIDTH(falcon_stat) == 32) \ 392874aeea5SJeff Kirsher (efx)->mac_stats.efx_stat += le32_to_cpu( \ 393874aeea5SJeff Kirsher *((__force __le32 *) \ 394874aeea5SJeff Kirsher (efx->stats_buffer.addr + \ 395874aeea5SJeff Kirsher FALCON_STAT_OFFSET(falcon_stat)))); \ 396874aeea5SJeff Kirsher else \ 397874aeea5SJeff Kirsher (efx)->mac_stats.efx_stat += le64_to_cpu( \ 398874aeea5SJeff Kirsher *((__force __le64 *) \ 399874aeea5SJeff Kirsher (efx->stats_buffer.addr + \ 400874aeea5SJeff Kirsher FALCON_STAT_OFFSET(falcon_stat)))); \ 401874aeea5SJeff Kirsher } while (0) 402874aeea5SJeff Kirsher 403874aeea5SJeff Kirsher #define FALCON_MAC_STATS_SIZE 0x100 404874aeea5SJeff Kirsher 405874aeea5SJeff Kirsher #define MAC_DATA_LBN 0 406874aeea5SJeff Kirsher #define MAC_DATA_WIDTH 32 407874aeea5SJeff Kirsher 40890893000SBen Hutchings extern void efx_generate_event(struct efx_nic *efx, unsigned int evq, 409874aeea5SJeff Kirsher efx_qword_t *event); 410874aeea5SJeff Kirsher 411874aeea5SJeff Kirsher extern void falcon_poll_xmac(struct efx_nic *efx); 412874aeea5SJeff Kirsher 413874aeea5SJeff Kirsher #endif /* EFX_NIC_H */ 414