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 14874aeea5SJeff Kirsher #include <linux/i2c-algo-bit.h> 15874aeea5SJeff Kirsher #include "net_driver.h" 16874aeea5SJeff Kirsher #include "efx.h" 17874aeea5SJeff Kirsher #include "mcdi.h" 18874aeea5SJeff Kirsher #include "spi.h" 19874aeea5SJeff Kirsher 20874aeea5SJeff Kirsher /* 21874aeea5SJeff Kirsher * Falcon hardware control 22874aeea5SJeff Kirsher */ 23874aeea5SJeff Kirsher 24874aeea5SJeff Kirsher enum { 25874aeea5SJeff Kirsher EFX_REV_FALCON_A0 = 0, 26874aeea5SJeff Kirsher EFX_REV_FALCON_A1 = 1, 27874aeea5SJeff Kirsher EFX_REV_FALCON_B0 = 2, 28874aeea5SJeff Kirsher EFX_REV_SIENA_A0 = 3, 29874aeea5SJeff Kirsher }; 30874aeea5SJeff Kirsher 31874aeea5SJeff Kirsher static inline int efx_nic_rev(struct efx_nic *efx) 32874aeea5SJeff Kirsher { 33874aeea5SJeff Kirsher return efx->type->revision; 34874aeea5SJeff Kirsher } 35874aeea5SJeff Kirsher 36874aeea5SJeff Kirsher extern u32 efx_nic_fpga_ver(struct efx_nic *efx); 37874aeea5SJeff Kirsher 38874aeea5SJeff Kirsher static inline bool efx_nic_has_mc(struct efx_nic *efx) 39874aeea5SJeff Kirsher { 40874aeea5SJeff Kirsher return efx_nic_rev(efx) >= EFX_REV_SIENA_A0; 41874aeea5SJeff Kirsher } 42874aeea5SJeff Kirsher /* NIC has two interlinked PCI functions for the same port. */ 43874aeea5SJeff Kirsher static inline bool efx_nic_is_dual_func(struct efx_nic *efx) 44874aeea5SJeff Kirsher { 45874aeea5SJeff Kirsher return efx_nic_rev(efx) < EFX_REV_FALCON_B0; 46874aeea5SJeff Kirsher } 47874aeea5SJeff Kirsher 48874aeea5SJeff Kirsher enum { 49874aeea5SJeff Kirsher PHY_TYPE_NONE = 0, 50874aeea5SJeff Kirsher PHY_TYPE_TXC43128 = 1, 51874aeea5SJeff Kirsher PHY_TYPE_88E1111 = 2, 52874aeea5SJeff Kirsher PHY_TYPE_SFX7101 = 3, 53874aeea5SJeff Kirsher PHY_TYPE_QT2022C2 = 4, 54874aeea5SJeff Kirsher PHY_TYPE_PM8358 = 6, 55874aeea5SJeff Kirsher PHY_TYPE_SFT9001A = 8, 56874aeea5SJeff Kirsher PHY_TYPE_QT2025C = 9, 57874aeea5SJeff Kirsher PHY_TYPE_SFT9001B = 10, 58874aeea5SJeff Kirsher }; 59874aeea5SJeff Kirsher 60874aeea5SJeff Kirsher #define FALCON_XMAC_LOOPBACKS \ 61874aeea5SJeff Kirsher ((1 << LOOPBACK_XGMII) | \ 62874aeea5SJeff Kirsher (1 << LOOPBACK_XGXS) | \ 63874aeea5SJeff Kirsher (1 << LOOPBACK_XAUI)) 64874aeea5SJeff Kirsher 65874aeea5SJeff Kirsher #define FALCON_GMAC_LOOPBACKS \ 66874aeea5SJeff Kirsher (1 << LOOPBACK_GMAC) 67874aeea5SJeff Kirsher 685b6262d0SBen Hutchings /* Alignment of PCIe DMA boundaries (4KB) */ 695b6262d0SBen Hutchings #define EFX_PAGE_SIZE 4096 705b6262d0SBen Hutchings /* Size and alignment of buffer table entries (same) */ 715b6262d0SBen Hutchings #define EFX_BUF_SIZE EFX_PAGE_SIZE 725b6262d0SBen Hutchings 73874aeea5SJeff Kirsher /** 74874aeea5SJeff Kirsher * struct falcon_board_type - board operations and type information 75874aeea5SJeff Kirsher * @id: Board type id, as found in NVRAM 76874aeea5SJeff Kirsher * @ref_model: Model number of Solarflare reference design 77874aeea5SJeff Kirsher * @gen_type: Generic board type description 78874aeea5SJeff Kirsher * @init: Allocate resources and initialise peripheral hardware 79874aeea5SJeff Kirsher * @init_phy: Do board-specific PHY initialisation 80874aeea5SJeff Kirsher * @fini: Shut down hardware and free resources 81874aeea5SJeff Kirsher * @set_id_led: Set state of identifying LED or revert to automatic function 82874aeea5SJeff Kirsher * @monitor: Board-specific health check function 83874aeea5SJeff Kirsher */ 84874aeea5SJeff Kirsher struct falcon_board_type { 85874aeea5SJeff Kirsher u8 id; 86874aeea5SJeff Kirsher const char *ref_model; 87874aeea5SJeff Kirsher const char *gen_type; 88874aeea5SJeff Kirsher int (*init) (struct efx_nic *nic); 89874aeea5SJeff Kirsher void (*init_phy) (struct efx_nic *efx); 90874aeea5SJeff Kirsher void (*fini) (struct efx_nic *nic); 91874aeea5SJeff Kirsher void (*set_id_led) (struct efx_nic *efx, enum efx_led_mode mode); 92874aeea5SJeff Kirsher int (*monitor) (struct efx_nic *nic); 93874aeea5SJeff Kirsher }; 94874aeea5SJeff Kirsher 95874aeea5SJeff Kirsher /** 96874aeea5SJeff Kirsher * struct falcon_board - board information 97874aeea5SJeff Kirsher * @type: Type of board 98874aeea5SJeff Kirsher * @major: Major rev. ('A', 'B' ...) 99874aeea5SJeff Kirsher * @minor: Minor rev. (0, 1, ...) 100874aeea5SJeff Kirsher * @i2c_adap: I2C adapter for on-board peripherals 101874aeea5SJeff Kirsher * @i2c_data: Data for bit-banging algorithm 102874aeea5SJeff Kirsher * @hwmon_client: I2C client for hardware monitor 103874aeea5SJeff Kirsher * @ioexp_client: I2C client for power/port control 104874aeea5SJeff Kirsher */ 105874aeea5SJeff Kirsher struct falcon_board { 106874aeea5SJeff Kirsher const struct falcon_board_type *type; 107874aeea5SJeff Kirsher int major; 108874aeea5SJeff Kirsher int minor; 109874aeea5SJeff Kirsher struct i2c_adapter i2c_adap; 110874aeea5SJeff Kirsher struct i2c_algo_bit_data i2c_data; 111874aeea5SJeff Kirsher struct i2c_client *hwmon_client, *ioexp_client; 112874aeea5SJeff Kirsher }; 113874aeea5SJeff Kirsher 114874aeea5SJeff Kirsher /** 115874aeea5SJeff Kirsher * struct falcon_nic_data - Falcon NIC state 116874aeea5SJeff Kirsher * @pci_dev2: Secondary function of Falcon A 117874aeea5SJeff Kirsher * @board: Board state and functions 118874aeea5SJeff Kirsher * @stats_disable_count: Nest count for disabling statistics fetches 119874aeea5SJeff Kirsher * @stats_pending: Is there a pending DMA of MAC statistics. 120874aeea5SJeff Kirsher * @stats_timer: A timer for regularly fetching MAC statistics. 121874aeea5SJeff Kirsher * @stats_dma_done: Pointer to the flag which indicates DMA completion. 122874aeea5SJeff Kirsher * @spi_flash: SPI flash device 123874aeea5SJeff Kirsher * @spi_eeprom: SPI EEPROM device 124874aeea5SJeff Kirsher * @spi_lock: SPI bus lock 125874aeea5SJeff Kirsher * @mdio_lock: MDIO bus lock 126874aeea5SJeff Kirsher * @xmac_poll_required: XMAC link state needs polling 127874aeea5SJeff Kirsher */ 128874aeea5SJeff Kirsher struct falcon_nic_data { 129874aeea5SJeff Kirsher struct pci_dev *pci_dev2; 130874aeea5SJeff Kirsher struct falcon_board board; 131874aeea5SJeff Kirsher unsigned int stats_disable_count; 132874aeea5SJeff Kirsher bool stats_pending; 133874aeea5SJeff Kirsher struct timer_list stats_timer; 134874aeea5SJeff Kirsher u32 *stats_dma_done; 135874aeea5SJeff Kirsher struct efx_spi_device spi_flash; 136874aeea5SJeff Kirsher struct efx_spi_device spi_eeprom; 137874aeea5SJeff Kirsher struct mutex spi_lock; 138874aeea5SJeff Kirsher struct mutex mdio_lock; 139874aeea5SJeff Kirsher bool xmac_poll_required; 140874aeea5SJeff Kirsher }; 141874aeea5SJeff Kirsher 142874aeea5SJeff Kirsher static inline struct falcon_board *falcon_board(struct efx_nic *efx) 143874aeea5SJeff Kirsher { 144874aeea5SJeff Kirsher struct falcon_nic_data *data = efx->nic_data; 145874aeea5SJeff Kirsher return &data->board; 146874aeea5SJeff Kirsher } 147874aeea5SJeff Kirsher 148874aeea5SJeff Kirsher /** 149874aeea5SJeff Kirsher * struct siena_nic_data - Siena NIC state 150874aeea5SJeff Kirsher * @mcdi: Management-Controller-to-Driver Interface 151874aeea5SJeff Kirsher * @wol_filter_id: Wake-on-LAN packet filter id 15255c5e0f8SBen Hutchings * @hwmon: Hardware monitor state 153874aeea5SJeff Kirsher */ 154874aeea5SJeff Kirsher struct siena_nic_data { 155874aeea5SJeff Kirsher struct efx_mcdi_iface mcdi; 156874aeea5SJeff Kirsher int wol_filter_id; 15755c5e0f8SBen Hutchings #ifdef CONFIG_SFC_MCDI_MON 15855c5e0f8SBen Hutchings struct efx_mcdi_mon hwmon; 15955c5e0f8SBen Hutchings #endif 160874aeea5SJeff Kirsher }; 161874aeea5SJeff Kirsher 16255c5e0f8SBen Hutchings #ifdef CONFIG_SFC_MCDI_MON 16355c5e0f8SBen Hutchings static inline struct efx_mcdi_mon *efx_mcdi_mon(struct efx_nic *efx) 16455c5e0f8SBen Hutchings { 16555c5e0f8SBen Hutchings struct siena_nic_data *nic_data; 16655c5e0f8SBen Hutchings EFX_BUG_ON_PARANOID(efx_nic_rev(efx) < EFX_REV_SIENA_A0); 16755c5e0f8SBen Hutchings nic_data = efx->nic_data; 16855c5e0f8SBen Hutchings return &nic_data->hwmon; 16955c5e0f8SBen Hutchings } 17055c5e0f8SBen Hutchings #endif 17155c5e0f8SBen Hutchings 172874aeea5SJeff Kirsher extern const struct efx_nic_type falcon_a1_nic_type; 173874aeea5SJeff Kirsher extern const struct efx_nic_type falcon_b0_nic_type; 174874aeea5SJeff Kirsher extern const struct efx_nic_type siena_a0_nic_type; 175874aeea5SJeff Kirsher 176874aeea5SJeff Kirsher /************************************************************************** 177874aeea5SJeff Kirsher * 178874aeea5SJeff Kirsher * Externs 179874aeea5SJeff Kirsher * 180874aeea5SJeff Kirsher ************************************************************************** 181874aeea5SJeff Kirsher */ 182874aeea5SJeff Kirsher 183874aeea5SJeff Kirsher extern int falcon_probe_board(struct efx_nic *efx, u16 revision_info); 184874aeea5SJeff Kirsher 185874aeea5SJeff Kirsher /* TX data path */ 186874aeea5SJeff Kirsher extern int efx_nic_probe_tx(struct efx_tx_queue *tx_queue); 187874aeea5SJeff Kirsher extern void efx_nic_init_tx(struct efx_tx_queue *tx_queue); 188874aeea5SJeff Kirsher extern void efx_nic_fini_tx(struct efx_tx_queue *tx_queue); 189874aeea5SJeff Kirsher extern void efx_nic_remove_tx(struct efx_tx_queue *tx_queue); 190874aeea5SJeff Kirsher extern void efx_nic_push_buffers(struct efx_tx_queue *tx_queue); 191874aeea5SJeff Kirsher 192874aeea5SJeff Kirsher /* RX data path */ 193874aeea5SJeff Kirsher extern int efx_nic_probe_rx(struct efx_rx_queue *rx_queue); 194874aeea5SJeff Kirsher extern void efx_nic_init_rx(struct efx_rx_queue *rx_queue); 195874aeea5SJeff Kirsher extern void efx_nic_fini_rx(struct efx_rx_queue *rx_queue); 196874aeea5SJeff Kirsher extern void efx_nic_remove_rx(struct efx_rx_queue *rx_queue); 197874aeea5SJeff Kirsher extern void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue); 1982ae75dacSBen Hutchings extern void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue); 199874aeea5SJeff Kirsher 200874aeea5SJeff Kirsher /* Event data path */ 201874aeea5SJeff Kirsher extern int efx_nic_probe_eventq(struct efx_channel *channel); 202874aeea5SJeff Kirsher extern void efx_nic_init_eventq(struct efx_channel *channel); 203874aeea5SJeff Kirsher extern void efx_nic_fini_eventq(struct efx_channel *channel); 204874aeea5SJeff Kirsher extern void efx_nic_remove_eventq(struct efx_channel *channel); 205874aeea5SJeff Kirsher extern int efx_nic_process_eventq(struct efx_channel *channel, int rx_quota); 206874aeea5SJeff Kirsher extern void efx_nic_eventq_read_ack(struct efx_channel *channel); 207874aeea5SJeff Kirsher extern bool efx_nic_event_present(struct efx_channel *channel); 208874aeea5SJeff Kirsher 209874aeea5SJeff Kirsher /* MAC/PHY */ 210874aeea5SJeff Kirsher extern void falcon_drain_tx_fifo(struct efx_nic *efx); 211874aeea5SJeff Kirsher extern void falcon_reconfigure_mac_wrapper(struct efx_nic *efx); 212710b208dSBen Hutchings extern bool falcon_xmac_check_fault(struct efx_nic *efx); 213710b208dSBen Hutchings extern int falcon_reconfigure_xmac(struct efx_nic *efx); 214710b208dSBen Hutchings extern void falcon_update_stats_xmac(struct efx_nic *efx); 215874aeea5SJeff Kirsher 216874aeea5SJeff Kirsher /* Interrupts and test events */ 217874aeea5SJeff Kirsher extern int efx_nic_init_interrupt(struct efx_nic *efx); 218874aeea5SJeff Kirsher extern void efx_nic_enable_interrupts(struct efx_nic *efx); 219874aeea5SJeff Kirsher extern void efx_nic_generate_test_event(struct efx_channel *channel); 220874aeea5SJeff Kirsher extern void efx_nic_generate_interrupt(struct efx_nic *efx); 221874aeea5SJeff Kirsher extern void efx_nic_disable_interrupts(struct efx_nic *efx); 222874aeea5SJeff Kirsher extern void efx_nic_fini_interrupt(struct efx_nic *efx); 223874aeea5SJeff Kirsher extern irqreturn_t efx_nic_fatal_interrupt(struct efx_nic *efx); 224874aeea5SJeff Kirsher extern irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id); 225874aeea5SJeff Kirsher extern void falcon_irq_ack_a1(struct efx_nic *efx); 226874aeea5SJeff Kirsher 227874aeea5SJeff Kirsher /* Global Resources */ 228874aeea5SJeff Kirsher extern int efx_nic_flush_queues(struct efx_nic *efx); 229874aeea5SJeff Kirsher extern void falcon_start_nic_stats(struct efx_nic *efx); 230874aeea5SJeff Kirsher extern void falcon_stop_nic_stats(struct efx_nic *efx); 231874aeea5SJeff Kirsher extern void falcon_setup_xaui(struct efx_nic *efx); 232874aeea5SJeff Kirsher extern int falcon_reset_xaui(struct efx_nic *efx); 23328e47c49SBen Hutchings extern void 23428e47c49SBen Hutchings efx_nic_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw); 235874aeea5SJeff Kirsher extern void efx_nic_init_common(struct efx_nic *efx); 236874aeea5SJeff Kirsher extern void efx_nic_push_rx_indir_table(struct efx_nic *efx); 237874aeea5SJeff Kirsher 238874aeea5SJeff Kirsher int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer, 239874aeea5SJeff Kirsher unsigned int len); 240874aeea5SJeff Kirsher void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer); 241874aeea5SJeff Kirsher 242874aeea5SJeff Kirsher /* Tests */ 243874aeea5SJeff Kirsher struct efx_nic_register_test { 244874aeea5SJeff Kirsher unsigned address; 245874aeea5SJeff Kirsher efx_oword_t mask; 246874aeea5SJeff Kirsher }; 247874aeea5SJeff Kirsher extern int efx_nic_test_registers(struct efx_nic *efx, 248874aeea5SJeff Kirsher const struct efx_nic_register_test *regs, 249874aeea5SJeff Kirsher size_t n_regs); 250874aeea5SJeff Kirsher 251874aeea5SJeff Kirsher extern size_t efx_nic_get_regs_len(struct efx_nic *efx); 252874aeea5SJeff Kirsher extern void efx_nic_get_regs(struct efx_nic *efx, void *buf); 253874aeea5SJeff Kirsher 254874aeea5SJeff Kirsher /************************************************************************** 255874aeea5SJeff Kirsher * 256874aeea5SJeff Kirsher * Falcon MAC stats 257874aeea5SJeff Kirsher * 258874aeea5SJeff Kirsher ************************************************************************** 259874aeea5SJeff Kirsher */ 260874aeea5SJeff Kirsher 261874aeea5SJeff Kirsher #define FALCON_STAT_OFFSET(falcon_stat) EFX_VAL(falcon_stat, offset) 262874aeea5SJeff Kirsher #define FALCON_STAT_WIDTH(falcon_stat) EFX_VAL(falcon_stat, WIDTH) 263874aeea5SJeff Kirsher 264874aeea5SJeff Kirsher /* Retrieve statistic from statistics block */ 265874aeea5SJeff Kirsher #define FALCON_STAT(efx, falcon_stat, efx_stat) do { \ 266874aeea5SJeff Kirsher if (FALCON_STAT_WIDTH(falcon_stat) == 16) \ 267874aeea5SJeff Kirsher (efx)->mac_stats.efx_stat += le16_to_cpu( \ 268874aeea5SJeff Kirsher *((__force __le16 *) \ 269874aeea5SJeff Kirsher (efx->stats_buffer.addr + \ 270874aeea5SJeff Kirsher FALCON_STAT_OFFSET(falcon_stat)))); \ 271874aeea5SJeff Kirsher else if (FALCON_STAT_WIDTH(falcon_stat) == 32) \ 272874aeea5SJeff Kirsher (efx)->mac_stats.efx_stat += le32_to_cpu( \ 273874aeea5SJeff Kirsher *((__force __le32 *) \ 274874aeea5SJeff Kirsher (efx->stats_buffer.addr + \ 275874aeea5SJeff Kirsher FALCON_STAT_OFFSET(falcon_stat)))); \ 276874aeea5SJeff Kirsher else \ 277874aeea5SJeff Kirsher (efx)->mac_stats.efx_stat += le64_to_cpu( \ 278874aeea5SJeff Kirsher *((__force __le64 *) \ 279874aeea5SJeff Kirsher (efx->stats_buffer.addr + \ 280874aeea5SJeff Kirsher FALCON_STAT_OFFSET(falcon_stat)))); \ 281874aeea5SJeff Kirsher } while (0) 282874aeea5SJeff Kirsher 283874aeea5SJeff Kirsher #define FALCON_MAC_STATS_SIZE 0x100 284874aeea5SJeff Kirsher 285874aeea5SJeff Kirsher #define MAC_DATA_LBN 0 286874aeea5SJeff Kirsher #define MAC_DATA_WIDTH 32 287874aeea5SJeff Kirsher 28890893000SBen Hutchings extern void efx_generate_event(struct efx_nic *efx, unsigned int evq, 289874aeea5SJeff Kirsher efx_qword_t *event); 290874aeea5SJeff Kirsher 291874aeea5SJeff Kirsher extern void falcon_poll_xmac(struct efx_nic *efx); 292874aeea5SJeff Kirsher 293874aeea5SJeff Kirsher #endif /* EFX_NIC_H */ 294