1874aeea5SJeff Kirsher /**************************************************************************** 2f7a6d2c4SBen Hutchings * Driver for Solarflare network controllers and boards 3874aeea5SJeff Kirsher * Copyright 2005-2006 Fen Systems Ltd. 4f7a6d2c4SBen Hutchings * Copyright 2006-2013 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 20874aeea5SJeff Kirsher enum { 21874aeea5SJeff Kirsher EFX_REV_FALCON_A0 = 0, 22874aeea5SJeff Kirsher EFX_REV_FALCON_A1 = 1, 23874aeea5SJeff Kirsher EFX_REV_FALCON_B0 = 2, 24874aeea5SJeff Kirsher EFX_REV_SIENA_A0 = 3, 258127d661SBen Hutchings EFX_REV_HUNT_A0 = 4, 26874aeea5SJeff Kirsher }; 27874aeea5SJeff Kirsher 28874aeea5SJeff Kirsher static inline int efx_nic_rev(struct efx_nic *efx) 29874aeea5SJeff Kirsher { 30874aeea5SJeff Kirsher return efx->type->revision; 31874aeea5SJeff Kirsher } 32874aeea5SJeff Kirsher 3300aef986SJoe Perches u32 efx_farch_fpga_ver(struct efx_nic *efx); 34874aeea5SJeff Kirsher 35874aeea5SJeff Kirsher /* NIC has two interlinked PCI functions for the same port. */ 36874aeea5SJeff Kirsher static inline bool efx_nic_is_dual_func(struct efx_nic *efx) 37874aeea5SJeff Kirsher { 38874aeea5SJeff Kirsher return efx_nic_rev(efx) < EFX_REV_FALCON_B0; 39874aeea5SJeff Kirsher } 40874aeea5SJeff Kirsher 4186094f7fSBen Hutchings /* Read the current event from the event queue */ 4286094f7fSBen Hutchings static inline efx_qword_t *efx_event(struct efx_channel *channel, 4386094f7fSBen Hutchings unsigned int index) 4486094f7fSBen Hutchings { 4586094f7fSBen Hutchings return ((efx_qword_t *) (channel->eventq.buf.addr)) + 4686094f7fSBen Hutchings (index & channel->eventq_mask); 4786094f7fSBen Hutchings } 4886094f7fSBen Hutchings 4986094f7fSBen Hutchings /* See if an event is present 5086094f7fSBen Hutchings * 5186094f7fSBen Hutchings * We check both the high and low dword of the event for all ones. We 5286094f7fSBen Hutchings * wrote all ones when we cleared the event, and no valid event can 5386094f7fSBen Hutchings * have all ones in either its high or low dwords. This approach is 5486094f7fSBen Hutchings * robust against reordering. 5586094f7fSBen Hutchings * 5686094f7fSBen Hutchings * Note that using a single 64-bit comparison is incorrect; even 5786094f7fSBen Hutchings * though the CPU read will be atomic, the DMA write may not be. 5886094f7fSBen Hutchings */ 5986094f7fSBen Hutchings static inline int efx_event_present(efx_qword_t *event) 6086094f7fSBen Hutchings { 6186094f7fSBen Hutchings return !(EFX_DWORD_IS_ALL_ONES(event->dword[0]) | 6286094f7fSBen Hutchings EFX_DWORD_IS_ALL_ONES(event->dword[1])); 6386094f7fSBen Hutchings } 6486094f7fSBen Hutchings 6586094f7fSBen Hutchings /* Returns a pointer to the specified transmit descriptor in the TX 6686094f7fSBen Hutchings * descriptor queue belonging to the specified channel. 6786094f7fSBen Hutchings */ 6886094f7fSBen Hutchings static inline efx_qword_t * 6986094f7fSBen Hutchings efx_tx_desc(struct efx_tx_queue *tx_queue, unsigned int index) 7086094f7fSBen Hutchings { 7186094f7fSBen Hutchings return ((efx_qword_t *) (tx_queue->txd.buf.addr)) + index; 7286094f7fSBen Hutchings } 7386094f7fSBen Hutchings 7470b33fb0SEdward Cree /* Get partner of a TX queue, seen as part of the same net core queue */ 7570b33fb0SEdward Cree static struct efx_tx_queue *efx_tx_queue_partner(struct efx_tx_queue *tx_queue) 7670b33fb0SEdward Cree { 7770b33fb0SEdward Cree if (tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD) 7870b33fb0SEdward Cree return tx_queue - EFX_TXQ_TYPE_OFFLOAD; 7970b33fb0SEdward Cree else 8070b33fb0SEdward Cree return tx_queue + EFX_TXQ_TYPE_OFFLOAD; 8170b33fb0SEdward Cree } 8270b33fb0SEdward Cree 8370b33fb0SEdward Cree /* Report whether this TX queue would be empty for the given write_count. 8470b33fb0SEdward Cree * May return false negative. 85306a2782SBen Hutchings */ 86306a2782SBen Hutchings static inline bool __efx_nic_tx_is_empty(struct efx_tx_queue *tx_queue, 87306a2782SBen Hutchings unsigned int write_count) 88306a2782SBen Hutchings { 89306a2782SBen Hutchings unsigned int empty_read_count = ACCESS_ONCE(tx_queue->empty_read_count); 90306a2782SBen Hutchings 91306a2782SBen Hutchings if (empty_read_count == 0) 92306a2782SBen Hutchings return false; 93306a2782SBen Hutchings 94306a2782SBen Hutchings return ((empty_read_count ^ write_count) & ~EFX_EMPTY_COUNT_VALID) == 0; 95306a2782SBen Hutchings } 96306a2782SBen Hutchings 9770b33fb0SEdward Cree /* Decide whether we can use TX PIO, ie. write packet data directly into 9870b33fb0SEdward Cree * a buffer on the device. This can reduce latency at the expense of 9970b33fb0SEdward Cree * throughput, so we only do this if both hardware and software TX rings 10070b33fb0SEdward Cree * are empty. This also ensures that only one packet at a time can be 10170b33fb0SEdward Cree * using the PIO buffer. 10270b33fb0SEdward Cree */ 10370b33fb0SEdward Cree static inline bool efx_nic_may_tx_pio(struct efx_tx_queue *tx_queue) 104306a2782SBen Hutchings { 10570b33fb0SEdward Cree struct efx_tx_queue *partner = efx_tx_queue_partner(tx_queue); 10670b33fb0SEdward Cree return tx_queue->piobuf && 10770b33fb0SEdward Cree __efx_nic_tx_is_empty(tx_queue, tx_queue->insert_count) && 10870b33fb0SEdward Cree __efx_nic_tx_is_empty(partner, partner->insert_count); 109306a2782SBen Hutchings } 110306a2782SBen Hutchings 11186094f7fSBen Hutchings /* Decide whether to push a TX descriptor to the NIC vs merely writing 11286094f7fSBen Hutchings * the doorbell. This can reduce latency when we are adding a single 11386094f7fSBen Hutchings * descriptor to an empty queue, but is otherwise pointless. Further, 11486094f7fSBen Hutchings * Falcon and Siena have hardware bugs (SF bug 33851) that may be 11586094f7fSBen Hutchings * triggered if we don't check this. 11670b33fb0SEdward Cree * We use the write_count used for the last doorbell push, to get the 11770b33fb0SEdward Cree * NIC's view of the tx queue. 11886094f7fSBen Hutchings */ 11986094f7fSBen Hutchings static inline bool efx_nic_may_push_tx_desc(struct efx_tx_queue *tx_queue, 12086094f7fSBen Hutchings unsigned int write_count) 12186094f7fSBen Hutchings { 122306a2782SBen Hutchings bool was_empty = __efx_nic_tx_is_empty(tx_queue, write_count); 12386094f7fSBen Hutchings 12486094f7fSBen Hutchings tx_queue->empty_read_count = 0; 125306a2782SBen Hutchings return was_empty && tx_queue->write_count - write_count == 1; 12686094f7fSBen Hutchings } 12786094f7fSBen Hutchings 12886094f7fSBen Hutchings /* Returns a pointer to the specified descriptor in the RX descriptor queue */ 12986094f7fSBen Hutchings static inline efx_qword_t * 13086094f7fSBen Hutchings efx_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index) 13186094f7fSBen Hutchings { 13286094f7fSBen Hutchings return ((efx_qword_t *) (rx_queue->rxd.buf.addr)) + index; 13386094f7fSBen Hutchings } 13486094f7fSBen Hutchings 135874aeea5SJeff Kirsher enum { 136874aeea5SJeff Kirsher PHY_TYPE_NONE = 0, 137874aeea5SJeff Kirsher PHY_TYPE_TXC43128 = 1, 138874aeea5SJeff Kirsher PHY_TYPE_88E1111 = 2, 139874aeea5SJeff Kirsher PHY_TYPE_SFX7101 = 3, 140874aeea5SJeff Kirsher PHY_TYPE_QT2022C2 = 4, 141874aeea5SJeff Kirsher PHY_TYPE_PM8358 = 6, 142874aeea5SJeff Kirsher PHY_TYPE_SFT9001A = 8, 143874aeea5SJeff Kirsher PHY_TYPE_QT2025C = 9, 144874aeea5SJeff Kirsher PHY_TYPE_SFT9001B = 10, 145874aeea5SJeff Kirsher }; 146874aeea5SJeff Kirsher 147874aeea5SJeff Kirsher #define FALCON_XMAC_LOOPBACKS \ 148874aeea5SJeff Kirsher ((1 << LOOPBACK_XGMII) | \ 149874aeea5SJeff Kirsher (1 << LOOPBACK_XGXS) | \ 150874aeea5SJeff Kirsher (1 << LOOPBACK_XAUI)) 151874aeea5SJeff Kirsher 1525b6262d0SBen Hutchings /* Alignment of PCIe DMA boundaries (4KB) */ 1535b6262d0SBen Hutchings #define EFX_PAGE_SIZE 4096 1545b6262d0SBen Hutchings /* Size and alignment of buffer table entries (same) */ 1555b6262d0SBen Hutchings #define EFX_BUF_SIZE EFX_PAGE_SIZE 1565b6262d0SBen Hutchings 157e4d112e4SEdward Cree /* NIC-generic software stats */ 158e4d112e4SEdward Cree enum { 159e4d112e4SEdward Cree GENERIC_STAT_rx_noskb_drops, 160e4d112e4SEdward Cree GENERIC_STAT_rx_nodesc_trunc, 161e4d112e4SEdward Cree GENERIC_STAT_COUNT 162e4d112e4SEdward Cree }; 163e4d112e4SEdward Cree 164874aeea5SJeff Kirsher /** 165874aeea5SJeff Kirsher * struct falcon_board_type - board operations and type information 166874aeea5SJeff Kirsher * @id: Board type id, as found in NVRAM 167874aeea5SJeff Kirsher * @init: Allocate resources and initialise peripheral hardware 168874aeea5SJeff Kirsher * @init_phy: Do board-specific PHY initialisation 169874aeea5SJeff Kirsher * @fini: Shut down hardware and free resources 170874aeea5SJeff Kirsher * @set_id_led: Set state of identifying LED or revert to automatic function 171874aeea5SJeff Kirsher * @monitor: Board-specific health check function 172874aeea5SJeff Kirsher */ 173874aeea5SJeff Kirsher struct falcon_board_type { 174874aeea5SJeff Kirsher u8 id; 175874aeea5SJeff Kirsher int (*init) (struct efx_nic *nic); 176874aeea5SJeff Kirsher void (*init_phy) (struct efx_nic *efx); 177874aeea5SJeff Kirsher void (*fini) (struct efx_nic *nic); 178874aeea5SJeff Kirsher void (*set_id_led) (struct efx_nic *efx, enum efx_led_mode mode); 179874aeea5SJeff Kirsher int (*monitor) (struct efx_nic *nic); 180874aeea5SJeff Kirsher }; 181874aeea5SJeff Kirsher 182874aeea5SJeff Kirsher /** 183874aeea5SJeff Kirsher * struct falcon_board - board information 184874aeea5SJeff Kirsher * @type: Type of board 185874aeea5SJeff Kirsher * @major: Major rev. ('A', 'B' ...) 186874aeea5SJeff Kirsher * @minor: Minor rev. (0, 1, ...) 187874aeea5SJeff Kirsher * @i2c_adap: I2C adapter for on-board peripherals 188874aeea5SJeff Kirsher * @i2c_data: Data for bit-banging algorithm 189874aeea5SJeff Kirsher * @hwmon_client: I2C client for hardware monitor 190874aeea5SJeff Kirsher * @ioexp_client: I2C client for power/port control 191874aeea5SJeff Kirsher */ 192874aeea5SJeff Kirsher struct falcon_board { 193874aeea5SJeff Kirsher const struct falcon_board_type *type; 194874aeea5SJeff Kirsher int major; 195874aeea5SJeff Kirsher int minor; 196874aeea5SJeff Kirsher struct i2c_adapter i2c_adap; 197874aeea5SJeff Kirsher struct i2c_algo_bit_data i2c_data; 198874aeea5SJeff Kirsher struct i2c_client *hwmon_client, *ioexp_client; 199874aeea5SJeff Kirsher }; 200874aeea5SJeff Kirsher 201874aeea5SJeff Kirsher /** 20245a3fd55SBen Hutchings * struct falcon_spi_device - a Falcon SPI (Serial Peripheral Interface) device 20345a3fd55SBen Hutchings * @device_id: Controller's id for the device 20445a3fd55SBen Hutchings * @size: Size (in bytes) 20545a3fd55SBen Hutchings * @addr_len: Number of address bytes in read/write commands 20645a3fd55SBen Hutchings * @munge_address: Flag whether addresses should be munged. 20745a3fd55SBen Hutchings * Some devices with 9-bit addresses (e.g. AT25040A EEPROM) 20845a3fd55SBen Hutchings * use bit 3 of the command byte as address bit A8, rather 20945a3fd55SBen Hutchings * than having a two-byte address. If this flag is set, then 21045a3fd55SBen Hutchings * commands should be munged in this way. 21145a3fd55SBen Hutchings * @erase_command: Erase command (or 0 if sector erase not needed). 21245a3fd55SBen Hutchings * @erase_size: Erase sector size (in bytes) 21345a3fd55SBen Hutchings * Erase commands affect sectors with this size and alignment. 21445a3fd55SBen Hutchings * This must be a power of two. 21545a3fd55SBen Hutchings * @block_size: Write block size (in bytes). 21645a3fd55SBen Hutchings * Write commands are limited to blocks with this size and alignment. 21745a3fd55SBen Hutchings */ 21845a3fd55SBen Hutchings struct falcon_spi_device { 21945a3fd55SBen Hutchings int device_id; 22045a3fd55SBen Hutchings unsigned int size; 22145a3fd55SBen Hutchings unsigned int addr_len; 22245a3fd55SBen Hutchings unsigned int munge_address:1; 22345a3fd55SBen Hutchings u8 erase_command; 22445a3fd55SBen Hutchings unsigned int erase_size; 22545a3fd55SBen Hutchings unsigned int block_size; 22645a3fd55SBen Hutchings }; 22745a3fd55SBen Hutchings 22845a3fd55SBen Hutchings static inline bool falcon_spi_present(const struct falcon_spi_device *spi) 22945a3fd55SBen Hutchings { 23045a3fd55SBen Hutchings return spi->size != 0; 23145a3fd55SBen Hutchings } 23245a3fd55SBen Hutchings 233cd0ecc9aSBen Hutchings enum { 234e4d112e4SEdward Cree FALCON_STAT_tx_bytes = GENERIC_STAT_COUNT, 235cd0ecc9aSBen Hutchings FALCON_STAT_tx_packets, 236cd0ecc9aSBen Hutchings FALCON_STAT_tx_pause, 237cd0ecc9aSBen Hutchings FALCON_STAT_tx_control, 238cd0ecc9aSBen Hutchings FALCON_STAT_tx_unicast, 239cd0ecc9aSBen Hutchings FALCON_STAT_tx_multicast, 240cd0ecc9aSBen Hutchings FALCON_STAT_tx_broadcast, 241cd0ecc9aSBen Hutchings FALCON_STAT_tx_lt64, 242cd0ecc9aSBen Hutchings FALCON_STAT_tx_64, 243cd0ecc9aSBen Hutchings FALCON_STAT_tx_65_to_127, 244cd0ecc9aSBen Hutchings FALCON_STAT_tx_128_to_255, 245cd0ecc9aSBen Hutchings FALCON_STAT_tx_256_to_511, 246cd0ecc9aSBen Hutchings FALCON_STAT_tx_512_to_1023, 247cd0ecc9aSBen Hutchings FALCON_STAT_tx_1024_to_15xx, 248cd0ecc9aSBen Hutchings FALCON_STAT_tx_15xx_to_jumbo, 249cd0ecc9aSBen Hutchings FALCON_STAT_tx_gtjumbo, 250cd0ecc9aSBen Hutchings FALCON_STAT_tx_non_tcpudp, 251cd0ecc9aSBen Hutchings FALCON_STAT_tx_mac_src_error, 252cd0ecc9aSBen Hutchings FALCON_STAT_tx_ip_src_error, 253cd0ecc9aSBen Hutchings FALCON_STAT_rx_bytes, 254cd0ecc9aSBen Hutchings FALCON_STAT_rx_good_bytes, 255cd0ecc9aSBen Hutchings FALCON_STAT_rx_bad_bytes, 256cd0ecc9aSBen Hutchings FALCON_STAT_rx_packets, 257cd0ecc9aSBen Hutchings FALCON_STAT_rx_good, 258cd0ecc9aSBen Hutchings FALCON_STAT_rx_bad, 259cd0ecc9aSBen Hutchings FALCON_STAT_rx_pause, 260cd0ecc9aSBen Hutchings FALCON_STAT_rx_control, 261cd0ecc9aSBen Hutchings FALCON_STAT_rx_unicast, 262cd0ecc9aSBen Hutchings FALCON_STAT_rx_multicast, 263cd0ecc9aSBen Hutchings FALCON_STAT_rx_broadcast, 264cd0ecc9aSBen Hutchings FALCON_STAT_rx_lt64, 265cd0ecc9aSBen Hutchings FALCON_STAT_rx_64, 266cd0ecc9aSBen Hutchings FALCON_STAT_rx_65_to_127, 267cd0ecc9aSBen Hutchings FALCON_STAT_rx_128_to_255, 268cd0ecc9aSBen Hutchings FALCON_STAT_rx_256_to_511, 269cd0ecc9aSBen Hutchings FALCON_STAT_rx_512_to_1023, 270cd0ecc9aSBen Hutchings FALCON_STAT_rx_1024_to_15xx, 271cd0ecc9aSBen Hutchings FALCON_STAT_rx_15xx_to_jumbo, 272cd0ecc9aSBen Hutchings FALCON_STAT_rx_gtjumbo, 273cd0ecc9aSBen Hutchings FALCON_STAT_rx_bad_lt64, 274cd0ecc9aSBen Hutchings FALCON_STAT_rx_bad_gtjumbo, 275cd0ecc9aSBen Hutchings FALCON_STAT_rx_overflow, 276cd0ecc9aSBen Hutchings FALCON_STAT_rx_symbol_error, 277cd0ecc9aSBen Hutchings FALCON_STAT_rx_align_error, 278cd0ecc9aSBen Hutchings FALCON_STAT_rx_length_error, 279cd0ecc9aSBen Hutchings FALCON_STAT_rx_internal_error, 280cd0ecc9aSBen Hutchings FALCON_STAT_rx_nodesc_drop_cnt, 281cd0ecc9aSBen Hutchings FALCON_STAT_COUNT 282cd0ecc9aSBen Hutchings }; 283cd0ecc9aSBen Hutchings 28445a3fd55SBen Hutchings /** 285874aeea5SJeff Kirsher * struct falcon_nic_data - Falcon NIC state 286874aeea5SJeff Kirsher * @pci_dev2: Secondary function of Falcon A 287874aeea5SJeff Kirsher * @board: Board state and functions 288cd0ecc9aSBen Hutchings * @stats: Hardware statistics 289874aeea5SJeff Kirsher * @stats_disable_count: Nest count for disabling statistics fetches 290874aeea5SJeff Kirsher * @stats_pending: Is there a pending DMA of MAC statistics. 291874aeea5SJeff Kirsher * @stats_timer: A timer for regularly fetching MAC statistics. 292874aeea5SJeff Kirsher * @spi_flash: SPI flash device 293874aeea5SJeff Kirsher * @spi_eeprom: SPI EEPROM device 294874aeea5SJeff Kirsher * @spi_lock: SPI bus lock 295874aeea5SJeff Kirsher * @mdio_lock: MDIO bus lock 296874aeea5SJeff Kirsher * @xmac_poll_required: XMAC link state needs polling 297874aeea5SJeff Kirsher */ 298874aeea5SJeff Kirsher struct falcon_nic_data { 299874aeea5SJeff Kirsher struct pci_dev *pci_dev2; 300874aeea5SJeff Kirsher struct falcon_board board; 301cd0ecc9aSBen Hutchings u64 stats[FALCON_STAT_COUNT]; 302874aeea5SJeff Kirsher unsigned int stats_disable_count; 303874aeea5SJeff Kirsher bool stats_pending; 304874aeea5SJeff Kirsher struct timer_list stats_timer; 305ecd0a6f0SBen Hutchings struct falcon_spi_device spi_flash; 306ecd0a6f0SBen Hutchings struct falcon_spi_device spi_eeprom; 307874aeea5SJeff Kirsher struct mutex spi_lock; 308874aeea5SJeff Kirsher struct mutex mdio_lock; 309874aeea5SJeff Kirsher bool xmac_poll_required; 310874aeea5SJeff Kirsher }; 311874aeea5SJeff Kirsher 312874aeea5SJeff Kirsher static inline struct falcon_board *falcon_board(struct efx_nic *efx) 313874aeea5SJeff Kirsher { 314874aeea5SJeff Kirsher struct falcon_nic_data *data = efx->nic_data; 315874aeea5SJeff Kirsher return &data->board; 316874aeea5SJeff Kirsher } 317874aeea5SJeff Kirsher 318cd0ecc9aSBen Hutchings enum { 319e4d112e4SEdward Cree SIENA_STAT_tx_bytes = GENERIC_STAT_COUNT, 320cd0ecc9aSBen Hutchings SIENA_STAT_tx_good_bytes, 321cd0ecc9aSBen Hutchings SIENA_STAT_tx_bad_bytes, 322cd0ecc9aSBen Hutchings SIENA_STAT_tx_packets, 323cd0ecc9aSBen Hutchings SIENA_STAT_tx_bad, 324cd0ecc9aSBen Hutchings SIENA_STAT_tx_pause, 325cd0ecc9aSBen Hutchings SIENA_STAT_tx_control, 326cd0ecc9aSBen Hutchings SIENA_STAT_tx_unicast, 327cd0ecc9aSBen Hutchings SIENA_STAT_tx_multicast, 328cd0ecc9aSBen Hutchings SIENA_STAT_tx_broadcast, 329cd0ecc9aSBen Hutchings SIENA_STAT_tx_lt64, 330cd0ecc9aSBen Hutchings SIENA_STAT_tx_64, 331cd0ecc9aSBen Hutchings SIENA_STAT_tx_65_to_127, 332cd0ecc9aSBen Hutchings SIENA_STAT_tx_128_to_255, 333cd0ecc9aSBen Hutchings SIENA_STAT_tx_256_to_511, 334cd0ecc9aSBen Hutchings SIENA_STAT_tx_512_to_1023, 335cd0ecc9aSBen Hutchings SIENA_STAT_tx_1024_to_15xx, 336cd0ecc9aSBen Hutchings SIENA_STAT_tx_15xx_to_jumbo, 337cd0ecc9aSBen Hutchings SIENA_STAT_tx_gtjumbo, 338cd0ecc9aSBen Hutchings SIENA_STAT_tx_collision, 339cd0ecc9aSBen Hutchings SIENA_STAT_tx_single_collision, 340cd0ecc9aSBen Hutchings SIENA_STAT_tx_multiple_collision, 341cd0ecc9aSBen Hutchings SIENA_STAT_tx_excessive_collision, 342cd0ecc9aSBen Hutchings SIENA_STAT_tx_deferred, 343cd0ecc9aSBen Hutchings SIENA_STAT_tx_late_collision, 344cd0ecc9aSBen Hutchings SIENA_STAT_tx_excessive_deferred, 345cd0ecc9aSBen Hutchings SIENA_STAT_tx_non_tcpudp, 346cd0ecc9aSBen Hutchings SIENA_STAT_tx_mac_src_error, 347cd0ecc9aSBen Hutchings SIENA_STAT_tx_ip_src_error, 348cd0ecc9aSBen Hutchings SIENA_STAT_rx_bytes, 349cd0ecc9aSBen Hutchings SIENA_STAT_rx_good_bytes, 350cd0ecc9aSBen Hutchings SIENA_STAT_rx_bad_bytes, 351cd0ecc9aSBen Hutchings SIENA_STAT_rx_packets, 352cd0ecc9aSBen Hutchings SIENA_STAT_rx_good, 353cd0ecc9aSBen Hutchings SIENA_STAT_rx_bad, 354cd0ecc9aSBen Hutchings SIENA_STAT_rx_pause, 355cd0ecc9aSBen Hutchings SIENA_STAT_rx_control, 356cd0ecc9aSBen Hutchings SIENA_STAT_rx_unicast, 357cd0ecc9aSBen Hutchings SIENA_STAT_rx_multicast, 358cd0ecc9aSBen Hutchings SIENA_STAT_rx_broadcast, 359cd0ecc9aSBen Hutchings SIENA_STAT_rx_lt64, 360cd0ecc9aSBen Hutchings SIENA_STAT_rx_64, 361cd0ecc9aSBen Hutchings SIENA_STAT_rx_65_to_127, 362cd0ecc9aSBen Hutchings SIENA_STAT_rx_128_to_255, 363cd0ecc9aSBen Hutchings SIENA_STAT_rx_256_to_511, 364cd0ecc9aSBen Hutchings SIENA_STAT_rx_512_to_1023, 365cd0ecc9aSBen Hutchings SIENA_STAT_rx_1024_to_15xx, 366cd0ecc9aSBen Hutchings SIENA_STAT_rx_15xx_to_jumbo, 367cd0ecc9aSBen Hutchings SIENA_STAT_rx_gtjumbo, 368cd0ecc9aSBen Hutchings SIENA_STAT_rx_bad_gtjumbo, 369cd0ecc9aSBen Hutchings SIENA_STAT_rx_overflow, 370cd0ecc9aSBen Hutchings SIENA_STAT_rx_false_carrier, 371cd0ecc9aSBen Hutchings SIENA_STAT_rx_symbol_error, 372cd0ecc9aSBen Hutchings SIENA_STAT_rx_align_error, 373cd0ecc9aSBen Hutchings SIENA_STAT_rx_length_error, 374cd0ecc9aSBen Hutchings SIENA_STAT_rx_internal_error, 375cd0ecc9aSBen Hutchings SIENA_STAT_rx_nodesc_drop_cnt, 376cd0ecc9aSBen Hutchings SIENA_STAT_COUNT 377cd0ecc9aSBen Hutchings }; 378cd0ecc9aSBen Hutchings 379874aeea5SJeff Kirsher /** 380874aeea5SJeff Kirsher * struct siena_nic_data - Siena NIC state 3812dc313ecSShradha Shah * @efx: Pointer back to main interface structure 382874aeea5SJeff Kirsher * @wol_filter_id: Wake-on-LAN packet filter id 383cd0ecc9aSBen Hutchings * @stats: Hardware statistics 384bf3d0156SDaniel Pieczko * @vf: Array of &struct siena_vf objects 3852dc313ecSShradha Shah * @vf_buftbl_base: The zeroth buffer table index used to back VF queues. 3862dc313ecSShradha Shah * @vfdi_status: Common VFDI status page to be dmad to VF address space. 3872dc313ecSShradha Shah * @local_addr_list: List of local addresses. Protected by %local_lock. 3882dc313ecSShradha Shah * @local_page_list: List of DMA addressable pages used to broadcast 3892dc313ecSShradha Shah * %local_addr_list. Protected by %local_lock. 3902dc313ecSShradha Shah * @local_lock: Mutex protecting %local_addr_list and %local_page_list. 3912dc313ecSShradha Shah * @peer_work: Work item to broadcast peer addresses to VMs. 392874aeea5SJeff Kirsher */ 393874aeea5SJeff Kirsher struct siena_nic_data { 3942dc313ecSShradha Shah struct efx_nic *efx; 395874aeea5SJeff Kirsher int wol_filter_id; 396cd0ecc9aSBen Hutchings u64 stats[SIENA_STAT_COUNT]; 3972dc313ecSShradha Shah #ifdef CONFIG_SFC_SRIOV 398bf3d0156SDaniel Pieczko struct siena_vf *vf; 3992dc313ecSShradha Shah struct efx_channel *vfdi_channel; 4002dc313ecSShradha Shah unsigned vf_buftbl_base; 4012dc313ecSShradha Shah struct efx_buffer vfdi_status; 4022dc313ecSShradha Shah struct list_head local_addr_list; 4032dc313ecSShradha Shah struct list_head local_page_list; 4042dc313ecSShradha Shah struct mutex local_lock; 4052dc313ecSShradha Shah struct work_struct peer_work; 4062dc313ecSShradha Shah #endif 407874aeea5SJeff Kirsher }; 408874aeea5SJeff Kirsher 4098127d661SBen Hutchings enum { 410e80ca013SDaniel Pieczko EF10_STAT_port_tx_bytes = GENERIC_STAT_COUNT, 411e80ca013SDaniel Pieczko EF10_STAT_port_tx_packets, 412e80ca013SDaniel Pieczko EF10_STAT_port_tx_pause, 413e80ca013SDaniel Pieczko EF10_STAT_port_tx_control, 414e80ca013SDaniel Pieczko EF10_STAT_port_tx_unicast, 415e80ca013SDaniel Pieczko EF10_STAT_port_tx_multicast, 416e80ca013SDaniel Pieczko EF10_STAT_port_tx_broadcast, 417e80ca013SDaniel Pieczko EF10_STAT_port_tx_lt64, 418e80ca013SDaniel Pieczko EF10_STAT_port_tx_64, 419e80ca013SDaniel Pieczko EF10_STAT_port_tx_65_to_127, 420e80ca013SDaniel Pieczko EF10_STAT_port_tx_128_to_255, 421e80ca013SDaniel Pieczko EF10_STAT_port_tx_256_to_511, 422e80ca013SDaniel Pieczko EF10_STAT_port_tx_512_to_1023, 423e80ca013SDaniel Pieczko EF10_STAT_port_tx_1024_to_15xx, 424e80ca013SDaniel Pieczko EF10_STAT_port_tx_15xx_to_jumbo, 425e80ca013SDaniel Pieczko EF10_STAT_port_rx_bytes, 426e80ca013SDaniel Pieczko EF10_STAT_port_rx_bytes_minus_good_bytes, 427e80ca013SDaniel Pieczko EF10_STAT_port_rx_good_bytes, 428e80ca013SDaniel Pieczko EF10_STAT_port_rx_bad_bytes, 429e80ca013SDaniel Pieczko EF10_STAT_port_rx_packets, 430e80ca013SDaniel Pieczko EF10_STAT_port_rx_good, 431e80ca013SDaniel Pieczko EF10_STAT_port_rx_bad, 432e80ca013SDaniel Pieczko EF10_STAT_port_rx_pause, 433e80ca013SDaniel Pieczko EF10_STAT_port_rx_control, 434e80ca013SDaniel Pieczko EF10_STAT_port_rx_unicast, 435e80ca013SDaniel Pieczko EF10_STAT_port_rx_multicast, 436e80ca013SDaniel Pieczko EF10_STAT_port_rx_broadcast, 437e80ca013SDaniel Pieczko EF10_STAT_port_rx_lt64, 438e80ca013SDaniel Pieczko EF10_STAT_port_rx_64, 439e80ca013SDaniel Pieczko EF10_STAT_port_rx_65_to_127, 440e80ca013SDaniel Pieczko EF10_STAT_port_rx_128_to_255, 441e80ca013SDaniel Pieczko EF10_STAT_port_rx_256_to_511, 442e80ca013SDaniel Pieczko EF10_STAT_port_rx_512_to_1023, 443e80ca013SDaniel Pieczko EF10_STAT_port_rx_1024_to_15xx, 444e80ca013SDaniel Pieczko EF10_STAT_port_rx_15xx_to_jumbo, 445e80ca013SDaniel Pieczko EF10_STAT_port_rx_gtjumbo, 446e80ca013SDaniel Pieczko EF10_STAT_port_rx_bad_gtjumbo, 447e80ca013SDaniel Pieczko EF10_STAT_port_rx_overflow, 448e80ca013SDaniel Pieczko EF10_STAT_port_rx_align_error, 449e80ca013SDaniel Pieczko EF10_STAT_port_rx_length_error, 450e80ca013SDaniel Pieczko EF10_STAT_port_rx_nodesc_drops, 451e80ca013SDaniel Pieczko EF10_STAT_port_rx_pm_trunc_bb_overflow, 452e80ca013SDaniel Pieczko EF10_STAT_port_rx_pm_discard_bb_overflow, 453e80ca013SDaniel Pieczko EF10_STAT_port_rx_pm_trunc_vfifo_full, 454e80ca013SDaniel Pieczko EF10_STAT_port_rx_pm_discard_vfifo_full, 455e80ca013SDaniel Pieczko EF10_STAT_port_rx_pm_trunc_qbb, 456e80ca013SDaniel Pieczko EF10_STAT_port_rx_pm_discard_qbb, 457e80ca013SDaniel Pieczko EF10_STAT_port_rx_pm_discard_mapping, 458e80ca013SDaniel Pieczko EF10_STAT_port_rx_dp_q_disabled_packets, 459e80ca013SDaniel Pieczko EF10_STAT_port_rx_dp_di_dropped_packets, 460e80ca013SDaniel Pieczko EF10_STAT_port_rx_dp_streaming_packets, 461e80ca013SDaniel Pieczko EF10_STAT_port_rx_dp_hlb_fetch, 462e80ca013SDaniel Pieczko EF10_STAT_port_rx_dp_hlb_wait, 4633c36a2adSDaniel Pieczko EF10_STAT_rx_unicast, 4643c36a2adSDaniel Pieczko EF10_STAT_rx_unicast_bytes, 4653c36a2adSDaniel Pieczko EF10_STAT_rx_multicast, 4663c36a2adSDaniel Pieczko EF10_STAT_rx_multicast_bytes, 4673c36a2adSDaniel Pieczko EF10_STAT_rx_broadcast, 4683c36a2adSDaniel Pieczko EF10_STAT_rx_broadcast_bytes, 4693c36a2adSDaniel Pieczko EF10_STAT_rx_bad, 4703c36a2adSDaniel Pieczko EF10_STAT_rx_bad_bytes, 4713c36a2adSDaniel Pieczko EF10_STAT_rx_overflow, 4723c36a2adSDaniel Pieczko EF10_STAT_tx_unicast, 4733c36a2adSDaniel Pieczko EF10_STAT_tx_unicast_bytes, 4743c36a2adSDaniel Pieczko EF10_STAT_tx_multicast, 4753c36a2adSDaniel Pieczko EF10_STAT_tx_multicast_bytes, 4763c36a2adSDaniel Pieczko EF10_STAT_tx_broadcast, 4773c36a2adSDaniel Pieczko EF10_STAT_tx_broadcast_bytes, 4783c36a2adSDaniel Pieczko EF10_STAT_tx_bad, 4793c36a2adSDaniel Pieczko EF10_STAT_tx_bad_bytes, 4803c36a2adSDaniel Pieczko EF10_STAT_tx_overflow, 4818127d661SBen Hutchings EF10_STAT_COUNT 4828127d661SBen Hutchings }; 4838127d661SBen Hutchings 484183233beSBen Hutchings /* Maximum number of TX PIO buffers we may allocate to a function. 485183233beSBen Hutchings * This matches the total number of buffers on each SFC9100-family 486183233beSBen Hutchings * controller. 487183233beSBen Hutchings */ 488183233beSBen Hutchings #define EF10_TX_PIOBUF_COUNT 16 489183233beSBen Hutchings 4908127d661SBen Hutchings /** 4918127d661SBen Hutchings * struct efx_ef10_nic_data - EF10 architecture NIC state 4928127d661SBen Hutchings * @mcdi_buf: DMA buffer for MCDI 4938127d661SBen Hutchings * @warm_boot_count: Last seen MC warm boot count 4948127d661SBen Hutchings * @vi_base: Absolute index of first VI in this function 4958127d661SBen Hutchings * @n_allocated_vis: Number of VIs allocated to this function 4968127d661SBen Hutchings * @must_realloc_vis: Flag: VIs have yet to be reallocated after MC reboot 4978127d661SBen Hutchings * @must_restore_filters: Flag: filters have yet to be restored after MC reboot 498183233beSBen Hutchings * @n_piobufs: Number of PIO buffers allocated to this function 499183233beSBen Hutchings * @wc_membase: Base address of write-combining mapping of the memory BAR 500183233beSBen Hutchings * @pio_write_base: Base address for writing PIO buffers 501183233beSBen Hutchings * @pio_write_vi_base: Relative VI number for @pio_write_base 502183233beSBen Hutchings * @piobuf_handle: Handle of each PIO buffer allocated 503183233beSBen Hutchings * @must_restore_piobufs: Flag: PIO buffers have yet to be restored after MC 504183233beSBen Hutchings * reboot 5058127d661SBen Hutchings * @rx_rss_context: Firmware handle for our RSS context 506267c0157SJon Cooper * @rx_rss_context_exclusive: Whether our RSS context is exclusive or shared 5078127d661SBen Hutchings * @stats: Hardware statistics 5088127d661SBen Hutchings * @workaround_35388: Flag: firmware supports workaround for bug 35388 50946e612b0SDaniel Pieczko * @workaround_26807: Flag: firmware supports workaround for bug 26807 510539de7c5SBert Kenward * @workaround_61265: Flag: firmware supports workaround for bug 61265 511a915ccc9SBen Hutchings * @must_check_datapath_caps: Flag: @datapath_caps needs to be revalidated 512a915ccc9SBen Hutchings * after MC reboot 5138127d661SBen Hutchings * @datapath_caps: Capabilities of datapath firmware (FLAGS1 field of 5148127d661SBen Hutchings * %MC_CMD_GET_CAPABILITIES response) 515ca889a05SBert Kenward * @datapath_caps2: Further Capabilities of datapath firmware (FLAGS2 field of 516ca889a05SBert Kenward * %MC_CMD_GET_CAPABILITIES response) 5178d9f9dd4SDaniel Pieczko * @rx_dpcpu_fw_id: Firmware ID of the RxDPCPU 5188d9f9dd4SDaniel Pieczko * @tx_dpcpu_fw_id: Firmware ID of the TxDPCPU 51945b2449eSDaniel Pieczko * @vport_id: The function's vport ID, only relevant for PFs 5206d8aaaf6SDaniel Pieczko * @must_probe_vswitching: Flag: vswitching has yet to be setup after MC reboot 5211cd9ecbbSDaniel Pieczko * @pf_index: The number for this PF, or the parent PF if this is a VF 5223c5eb876SShradha Shah #ifdef CONFIG_SFC_SRIOV 5233c5eb876SShradha Shah * @vf: Pointer to VF data structure 5243c5eb876SShradha Shah #endif 52534813fe2SAndrew Rybchenko * @vport_mac: The MAC address on the vport, only for PFs; VFs will be zero 52634813fe2SAndrew Rybchenko * @vlan_list: List of VLANs added over the interface. Serialised by vlan_lock. 52734813fe2SAndrew Rybchenko * @vlan_lock: Lock to serialize access to vlan_list. 5288127d661SBen Hutchings */ 5298127d661SBen Hutchings struct efx_ef10_nic_data { 5308127d661SBen Hutchings struct efx_buffer mcdi_buf; 5318127d661SBen Hutchings u16 warm_boot_count; 5328127d661SBen Hutchings unsigned int vi_base; 5338127d661SBen Hutchings unsigned int n_allocated_vis; 5348127d661SBen Hutchings bool must_realloc_vis; 5358127d661SBen Hutchings bool must_restore_filters; 536183233beSBen Hutchings unsigned int n_piobufs; 537183233beSBen Hutchings void __iomem *wc_membase, *pio_write_base; 538183233beSBen Hutchings unsigned int pio_write_vi_base; 539183233beSBen Hutchings unsigned int piobuf_handle[EF10_TX_PIOBUF_COUNT]; 540183233beSBen Hutchings bool must_restore_piobufs; 5418127d661SBen Hutchings u32 rx_rss_context; 542267c0157SJon Cooper bool rx_rss_context_exclusive; 5438127d661SBen Hutchings u64 stats[EF10_STAT_COUNT]; 5448127d661SBen Hutchings bool workaround_35388; 54546e612b0SDaniel Pieczko bool workaround_26807; 546539de7c5SBert Kenward bool workaround_61265; 547a915ccc9SBen Hutchings bool must_check_datapath_caps; 5488127d661SBen Hutchings u32 datapath_caps; 549ca889a05SBert Kenward u32 datapath_caps2; 5508d9f9dd4SDaniel Pieczko unsigned int rx_dpcpu_fw_id; 5518d9f9dd4SDaniel Pieczko unsigned int tx_dpcpu_fw_id; 55245b2449eSDaniel Pieczko unsigned int vport_id; 5536d8aaaf6SDaniel Pieczko bool must_probe_vswitching; 5541cd9ecbbSDaniel Pieczko unsigned int pf_index; 5551d051e00SShradha Shah u8 port_id[ETH_ALEN]; 5563c5eb876SShradha Shah #ifdef CONFIG_SFC_SRIOV 55788a37de6SShradha Shah unsigned int vf_index; 5583c5eb876SShradha Shah struct ef10_vf *vf; 5593c5eb876SShradha Shah #endif 5603c5eb876SShradha Shah u8 vport_mac[ETH_ALEN]; 56134813fe2SAndrew Rybchenko struct list_head vlan_list; 56234813fe2SAndrew Rybchenko struct mutex vlan_lock; 5638127d661SBen Hutchings }; 5648127d661SBen Hutchings 56500aef986SJoe Perches int efx_init_sriov(void); 56600aef986SJoe Perches void efx_fini_sriov(void); 567cd2d5b52SBen Hutchings 5687c236c43SStuart Hodgson struct ethtool_ts_info; 569ac36baf8SBen Hutchings int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel); 570ac36baf8SBen Hutchings void efx_ptp_defer_probe_with_channel(struct efx_nic *efx); 571ac36baf8SBen Hutchings void efx_ptp_remove(struct efx_nic *efx); 572433dc9b3SBen Hutchings int efx_ptp_set_ts_config(struct efx_nic *efx, struct ifreq *ifr); 573433dc9b3SBen Hutchings int efx_ptp_get_ts_config(struct efx_nic *efx, struct ifreq *ifr); 57400aef986SJoe Perches void efx_ptp_get_ts_info(struct efx_nic *efx, struct ethtool_ts_info *ts_info); 57500aef986SJoe Perches bool efx_ptp_is_ptp_tx(struct efx_nic *efx, struct sk_buff *skb); 5769ec06595SDaniel Pieczko int efx_ptp_get_mode(struct efx_nic *efx); 5779ec06595SDaniel Pieczko int efx_ptp_change_mode(struct efx_nic *efx, bool enable_wanted, 5789ec06595SDaniel Pieczko unsigned int new_mode); 57900aef986SJoe Perches int efx_ptp_tx(struct efx_nic *efx, struct sk_buff *skb); 58000aef986SJoe Perches void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev); 58199691c4aSBen Hutchings size_t efx_ptp_describe_stats(struct efx_nic *efx, u8 *strings); 58299691c4aSBen Hutchings size_t efx_ptp_update_stats(struct efx_nic *efx, u64 *stats); 583bd9a265dSJon Cooper void efx_time_sync_event(struct efx_channel *channel, efx_qword_t *ev); 584bd9a265dSJon Cooper void __efx_rx_skb_attach_timestamp(struct efx_channel *channel, 585bd9a265dSJon Cooper struct sk_buff *skb); 586bd9a265dSJon Cooper static inline void efx_rx_skb_attach_timestamp(struct efx_channel *channel, 587bd9a265dSJon Cooper struct sk_buff *skb) 588bd9a265dSJon Cooper { 589bd9a265dSJon Cooper if (channel->sync_events_state == SYNC_EVENTS_VALID) 590bd9a265dSJon Cooper __efx_rx_skb_attach_timestamp(channel, skb); 591bd9a265dSJon Cooper } 5922ea4dc28SAlexandre Rames void efx_ptp_start_datapath(struct efx_nic *efx); 5932ea4dc28SAlexandre Rames void efx_ptp_stop_datapath(struct efx_nic *efx); 5947c236c43SStuart Hodgson 595874aeea5SJeff Kirsher extern const struct efx_nic_type falcon_a1_nic_type; 596874aeea5SJeff Kirsher extern const struct efx_nic_type falcon_b0_nic_type; 597874aeea5SJeff Kirsher extern const struct efx_nic_type siena_a0_nic_type; 5988127d661SBen Hutchings extern const struct efx_nic_type efx_hunt_a0_nic_type; 59902246a7fSShradha Shah extern const struct efx_nic_type efx_hunt_a0_vf_nic_type; 600874aeea5SJeff Kirsher 601874aeea5SJeff Kirsher /************************************************************************** 602874aeea5SJeff Kirsher * 603874aeea5SJeff Kirsher * Externs 604874aeea5SJeff Kirsher * 605874aeea5SJeff Kirsher ************************************************************************** 606874aeea5SJeff Kirsher */ 607874aeea5SJeff Kirsher 60800aef986SJoe Perches int falcon_probe_board(struct efx_nic *efx, u16 revision_info); 609874aeea5SJeff Kirsher 610874aeea5SJeff Kirsher /* TX data path */ 61186094f7fSBen Hutchings static inline int efx_nic_probe_tx(struct efx_tx_queue *tx_queue) 61286094f7fSBen Hutchings { 61386094f7fSBen Hutchings return tx_queue->efx->type->tx_probe(tx_queue); 61486094f7fSBen Hutchings } 61586094f7fSBen Hutchings static inline void efx_nic_init_tx(struct efx_tx_queue *tx_queue) 61686094f7fSBen Hutchings { 61786094f7fSBen Hutchings tx_queue->efx->type->tx_init(tx_queue); 61886094f7fSBen Hutchings } 61986094f7fSBen Hutchings static inline void efx_nic_remove_tx(struct efx_tx_queue *tx_queue) 62086094f7fSBen Hutchings { 62186094f7fSBen Hutchings tx_queue->efx->type->tx_remove(tx_queue); 62286094f7fSBen Hutchings } 62386094f7fSBen Hutchings static inline void efx_nic_push_buffers(struct efx_tx_queue *tx_queue) 62486094f7fSBen Hutchings { 62586094f7fSBen Hutchings tx_queue->efx->type->tx_write(tx_queue); 62686094f7fSBen Hutchings } 627874aeea5SJeff Kirsher 628874aeea5SJeff Kirsher /* RX data path */ 62986094f7fSBen Hutchings static inline int efx_nic_probe_rx(struct efx_rx_queue *rx_queue) 63086094f7fSBen Hutchings { 63186094f7fSBen Hutchings return rx_queue->efx->type->rx_probe(rx_queue); 63286094f7fSBen Hutchings } 63386094f7fSBen Hutchings static inline void efx_nic_init_rx(struct efx_rx_queue *rx_queue) 63486094f7fSBen Hutchings { 63586094f7fSBen Hutchings rx_queue->efx->type->rx_init(rx_queue); 63686094f7fSBen Hutchings } 63786094f7fSBen Hutchings static inline void efx_nic_remove_rx(struct efx_rx_queue *rx_queue) 63886094f7fSBen Hutchings { 63986094f7fSBen Hutchings rx_queue->efx->type->rx_remove(rx_queue); 64086094f7fSBen Hutchings } 64186094f7fSBen Hutchings static inline void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue) 64286094f7fSBen Hutchings { 64386094f7fSBen Hutchings rx_queue->efx->type->rx_write(rx_queue); 64486094f7fSBen Hutchings } 64586094f7fSBen Hutchings static inline void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue) 64686094f7fSBen Hutchings { 64786094f7fSBen Hutchings rx_queue->efx->type->rx_defer_refill(rx_queue); 64886094f7fSBen Hutchings } 649874aeea5SJeff Kirsher 650874aeea5SJeff Kirsher /* Event data path */ 65186094f7fSBen Hutchings static inline int efx_nic_probe_eventq(struct efx_channel *channel) 65286094f7fSBen Hutchings { 65386094f7fSBen Hutchings return channel->efx->type->ev_probe(channel); 65486094f7fSBen Hutchings } 655261e4d96SJon Cooper static inline int efx_nic_init_eventq(struct efx_channel *channel) 65686094f7fSBen Hutchings { 657261e4d96SJon Cooper return channel->efx->type->ev_init(channel); 65886094f7fSBen Hutchings } 65986094f7fSBen Hutchings static inline void efx_nic_fini_eventq(struct efx_channel *channel) 66086094f7fSBen Hutchings { 66186094f7fSBen Hutchings channel->efx->type->ev_fini(channel); 66286094f7fSBen Hutchings } 66386094f7fSBen Hutchings static inline void efx_nic_remove_eventq(struct efx_channel *channel) 66486094f7fSBen Hutchings { 66586094f7fSBen Hutchings channel->efx->type->ev_remove(channel); 66686094f7fSBen Hutchings } 66786094f7fSBen Hutchings static inline int 66886094f7fSBen Hutchings efx_nic_process_eventq(struct efx_channel *channel, int quota) 66986094f7fSBen Hutchings { 67086094f7fSBen Hutchings return channel->efx->type->ev_process(channel, quota); 67186094f7fSBen Hutchings } 67286094f7fSBen Hutchings static inline void efx_nic_eventq_read_ack(struct efx_channel *channel) 67386094f7fSBen Hutchings { 67486094f7fSBen Hutchings channel->efx->type->ev_read_ack(channel); 67586094f7fSBen Hutchings } 67600aef986SJoe Perches void efx_nic_event_test_start(struct efx_channel *channel); 67786094f7fSBen Hutchings 67886094f7fSBen Hutchings /* Falcon/Siena queue operations */ 67900aef986SJoe Perches int efx_farch_tx_probe(struct efx_tx_queue *tx_queue); 68000aef986SJoe Perches void efx_farch_tx_init(struct efx_tx_queue *tx_queue); 68100aef986SJoe Perches void efx_farch_tx_fini(struct efx_tx_queue *tx_queue); 68200aef986SJoe Perches void efx_farch_tx_remove(struct efx_tx_queue *tx_queue); 68300aef986SJoe Perches void efx_farch_tx_write(struct efx_tx_queue *tx_queue); 684e9117e50SBert Kenward unsigned int efx_farch_tx_limit_len(struct efx_tx_queue *tx_queue, 685e9117e50SBert Kenward dma_addr_t dma_addr, unsigned int len); 68600aef986SJoe Perches int efx_farch_rx_probe(struct efx_rx_queue *rx_queue); 68700aef986SJoe Perches void efx_farch_rx_init(struct efx_rx_queue *rx_queue); 68800aef986SJoe Perches void efx_farch_rx_fini(struct efx_rx_queue *rx_queue); 68900aef986SJoe Perches void efx_farch_rx_remove(struct efx_rx_queue *rx_queue); 69000aef986SJoe Perches void efx_farch_rx_write(struct efx_rx_queue *rx_queue); 69100aef986SJoe Perches void efx_farch_rx_defer_refill(struct efx_rx_queue *rx_queue); 69200aef986SJoe Perches int efx_farch_ev_probe(struct efx_channel *channel); 69300aef986SJoe Perches int efx_farch_ev_init(struct efx_channel *channel); 69400aef986SJoe Perches void efx_farch_ev_fini(struct efx_channel *channel); 69500aef986SJoe Perches void efx_farch_ev_remove(struct efx_channel *channel); 69600aef986SJoe Perches int efx_farch_ev_process(struct efx_channel *channel, int quota); 69700aef986SJoe Perches void efx_farch_ev_read_ack(struct efx_channel *channel); 69800aef986SJoe Perches void efx_farch_ev_test_generate(struct efx_channel *channel); 69986094f7fSBen Hutchings 700add72477SBen Hutchings /* Falcon/Siena filter operations */ 70100aef986SJoe Perches int efx_farch_filter_table_probe(struct efx_nic *efx); 70200aef986SJoe Perches void efx_farch_filter_table_restore(struct efx_nic *efx); 70300aef986SJoe Perches void efx_farch_filter_table_remove(struct efx_nic *efx); 70400aef986SJoe Perches void efx_farch_filter_update_rx_scatter(struct efx_nic *efx); 70500aef986SJoe Perches s32 efx_farch_filter_insert(struct efx_nic *efx, struct efx_filter_spec *spec, 70600aef986SJoe Perches bool replace); 70700aef986SJoe Perches int efx_farch_filter_remove_safe(struct efx_nic *efx, 708add72477SBen Hutchings enum efx_filter_priority priority, 709add72477SBen Hutchings u32 filter_id); 71000aef986SJoe Perches int efx_farch_filter_get_safe(struct efx_nic *efx, 71100aef986SJoe Perches enum efx_filter_priority priority, u32 filter_id, 71200aef986SJoe Perches struct efx_filter_spec *); 713fbd79120SBen Hutchings int efx_farch_filter_clear_rx(struct efx_nic *efx, 714add72477SBen Hutchings enum efx_filter_priority priority); 71500aef986SJoe Perches u32 efx_farch_filter_count_rx_used(struct efx_nic *efx, 716add72477SBen Hutchings enum efx_filter_priority priority); 71700aef986SJoe Perches u32 efx_farch_filter_get_rx_id_limit(struct efx_nic *efx); 71800aef986SJoe Perches s32 efx_farch_filter_get_rx_ids(struct efx_nic *efx, 71900aef986SJoe Perches enum efx_filter_priority priority, u32 *buf, 72000aef986SJoe Perches u32 size); 721add72477SBen Hutchings #ifdef CONFIG_RFS_ACCEL 72200aef986SJoe Perches s32 efx_farch_filter_rfs_insert(struct efx_nic *efx, 723add72477SBen Hutchings struct efx_filter_spec *spec); 72400aef986SJoe Perches bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id, 725add72477SBen Hutchings unsigned int index); 726add72477SBen Hutchings #endif 72700aef986SJoe Perches void efx_farch_filter_sync_rx_mode(struct efx_nic *efx); 728add72477SBen Hutchings 72900aef986SJoe Perches bool efx_nic_event_present(struct efx_channel *channel); 730874aeea5SJeff Kirsher 731b7f514afSBen Hutchings /* Some statistics are computed as A - B where A and B each increase 732b7f514afSBen Hutchings * linearly with some hardware counter(s) and the counters are read 733b7f514afSBen Hutchings * asynchronously. If the counters contributing to B are always read 734b7f514afSBen Hutchings * after those contributing to A, the computed value may be lower than 735b7f514afSBen Hutchings * the true value by some variable amount, and may decrease between 736b7f514afSBen Hutchings * subsequent computations. 737b7f514afSBen Hutchings * 738b7f514afSBen Hutchings * We should never allow statistics to decrease or to exceed the true 739b7f514afSBen Hutchings * value. Since the computed value will never be greater than the 740b7f514afSBen Hutchings * true value, we can achieve this by only storing the computed value 741b7f514afSBen Hutchings * when it increases. 742b7f514afSBen Hutchings */ 743b7f514afSBen Hutchings static inline void efx_update_diff_stat(u64 *stat, u64 diff) 744b7f514afSBen Hutchings { 745b7f514afSBen Hutchings if ((s64)(diff - *stat) > 0) 746b7f514afSBen Hutchings *stat = diff; 747b7f514afSBen Hutchings } 748b7f514afSBen Hutchings 74986094f7fSBen Hutchings /* Interrupts */ 75000aef986SJoe Perches int efx_nic_init_interrupt(struct efx_nic *efx); 751942e298eSJon Cooper int efx_nic_irq_test_start(struct efx_nic *efx); 75200aef986SJoe Perches void efx_nic_fini_interrupt(struct efx_nic *efx); 75386094f7fSBen Hutchings 75486094f7fSBen Hutchings /* Falcon/Siena interrupts */ 75500aef986SJoe Perches void efx_farch_irq_enable_master(struct efx_nic *efx); 756942e298eSJon Cooper int efx_farch_irq_test_generate(struct efx_nic *efx); 75700aef986SJoe Perches void efx_farch_irq_disable_master(struct efx_nic *efx); 75800aef986SJoe Perches irqreturn_t efx_farch_msi_interrupt(int irq, void *dev_id); 75900aef986SJoe Perches irqreturn_t efx_farch_legacy_interrupt(int irq, void *dev_id); 76000aef986SJoe Perches irqreturn_t efx_farch_fatal_interrupt(struct efx_nic *efx); 761874aeea5SJeff Kirsher 762eee6f6a9SBen Hutchings static inline int efx_nic_event_test_irq_cpu(struct efx_channel *channel) 763eee6f6a9SBen Hutchings { 764dd40781eSBen Hutchings return ACCESS_ONCE(channel->event_test_cpu); 765eee6f6a9SBen Hutchings } 766eee6f6a9SBen Hutchings static inline int efx_nic_irq_test_irq_cpu(struct efx_nic *efx) 767eee6f6a9SBen Hutchings { 768eee6f6a9SBen Hutchings return ACCESS_ONCE(efx->last_irq_cpu); 769eee6f6a9SBen Hutchings } 770eee6f6a9SBen Hutchings 771874aeea5SJeff Kirsher /* Global Resources */ 77200aef986SJoe Perches int efx_nic_flush_queues(struct efx_nic *efx); 77300aef986SJoe Perches void siena_prepare_flush(struct efx_nic *efx); 77400aef986SJoe Perches int efx_farch_fini_dmaq(struct efx_nic *efx); 775e283546cSEdward Cree void efx_farch_finish_flr(struct efx_nic *efx); 77600aef986SJoe Perches void siena_finish_flush(struct efx_nic *efx); 77700aef986SJoe Perches void falcon_start_nic_stats(struct efx_nic *efx); 77800aef986SJoe Perches void falcon_stop_nic_stats(struct efx_nic *efx); 77900aef986SJoe Perches int falcon_reset_xaui(struct efx_nic *efx); 78000aef986SJoe Perches void efx_farch_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw); 78100aef986SJoe Perches void efx_farch_init_common(struct efx_nic *efx); 78200aef986SJoe Perches void efx_ef10_handle_drain_event(struct efx_nic *efx); 78300aef986SJoe Perches void efx_farch_rx_push_indir_table(struct efx_nic *efx); 784874aeea5SJeff Kirsher 785874aeea5SJeff Kirsher int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer, 7860d19a540SBen Hutchings unsigned int len, gfp_t gfp_flags); 787874aeea5SJeff Kirsher void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer); 788874aeea5SJeff Kirsher 789874aeea5SJeff Kirsher /* Tests */ 79086094f7fSBen Hutchings struct efx_farch_register_test { 791874aeea5SJeff Kirsher unsigned address; 792874aeea5SJeff Kirsher efx_oword_t mask; 793874aeea5SJeff Kirsher }; 79400aef986SJoe Perches int efx_farch_test_registers(struct efx_nic *efx, 79586094f7fSBen Hutchings const struct efx_farch_register_test *regs, 796874aeea5SJeff Kirsher size_t n_regs); 797874aeea5SJeff Kirsher 79800aef986SJoe Perches size_t efx_nic_get_regs_len(struct efx_nic *efx); 79900aef986SJoe Perches void efx_nic_get_regs(struct efx_nic *efx, void *buf); 800874aeea5SJeff Kirsher 80100aef986SJoe Perches size_t efx_nic_describe_stats(const struct efx_hw_stat_desc *desc, size_t count, 802cd0ecc9aSBen Hutchings const unsigned long *mask, u8 *names); 80300aef986SJoe Perches void efx_nic_update_stats(const struct efx_hw_stat_desc *desc, size_t count, 80400aef986SJoe Perches const unsigned long *mask, u64 *stats, 80500aef986SJoe Perches const void *dma_buf, bool accumulate); 806f8f3b5aeSJon Cooper void efx_nic_fix_nodesc_drop_stat(struct efx_nic *efx, u64 *stat); 807cd0ecc9aSBen Hutchings 808ab0115fcSBen Hutchings #define EFX_MAX_FLUSH_TIME 5000 809874aeea5SJeff Kirsher 81000aef986SJoe Perches void efx_farch_generate_event(struct efx_nic *efx, unsigned int evq, 811874aeea5SJeff Kirsher efx_qword_t *event); 812874aeea5SJeff Kirsher 813874aeea5SJeff Kirsher #endif /* EFX_NIC_H */ 814