162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/**************************************************************************** 362306a36Sopenharmony_ci * Driver for Solarflare network controllers and boards 462306a36Sopenharmony_ci * Copyright 2005-2006 Fen Systems Ltd. 562306a36Sopenharmony_ci * Copyright 2006-2013 Solarflare Communications Inc. 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#ifndef EF4_NIC_H 962306a36Sopenharmony_ci#define EF4_NIC_H 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include <linux/net_tstamp.h> 1262306a36Sopenharmony_ci#include <linux/i2c-algo-bit.h> 1362306a36Sopenharmony_ci#include "net_driver.h" 1462306a36Sopenharmony_ci#include "efx.h" 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_cienum { 1762306a36Sopenharmony_ci EF4_REV_FALCON_A0 = 0, 1862306a36Sopenharmony_ci EF4_REV_FALCON_A1 = 1, 1962306a36Sopenharmony_ci EF4_REV_FALCON_B0 = 2, 2062306a36Sopenharmony_ci}; 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_cistatic inline int ef4_nic_rev(struct ef4_nic *efx) 2362306a36Sopenharmony_ci{ 2462306a36Sopenharmony_ci return efx->type->revision; 2562306a36Sopenharmony_ci} 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ciu32 ef4_farch_fpga_ver(struct ef4_nic *efx); 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci/* NIC has two interlinked PCI functions for the same port. */ 3062306a36Sopenharmony_cistatic inline bool ef4_nic_is_dual_func(struct ef4_nic *efx) 3162306a36Sopenharmony_ci{ 3262306a36Sopenharmony_ci return ef4_nic_rev(efx) < EF4_REV_FALCON_B0; 3362306a36Sopenharmony_ci} 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci/* Read the current event from the event queue */ 3662306a36Sopenharmony_cistatic inline ef4_qword_t *ef4_event(struct ef4_channel *channel, 3762306a36Sopenharmony_ci unsigned int index) 3862306a36Sopenharmony_ci{ 3962306a36Sopenharmony_ci return ((ef4_qword_t *) (channel->eventq.buf.addr)) + 4062306a36Sopenharmony_ci (index & channel->eventq_mask); 4162306a36Sopenharmony_ci} 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci/* See if an event is present 4462306a36Sopenharmony_ci * 4562306a36Sopenharmony_ci * We check both the high and low dword of the event for all ones. We 4662306a36Sopenharmony_ci * wrote all ones when we cleared the event, and no valid event can 4762306a36Sopenharmony_ci * have all ones in either its high or low dwords. This approach is 4862306a36Sopenharmony_ci * robust against reordering. 4962306a36Sopenharmony_ci * 5062306a36Sopenharmony_ci * Note that using a single 64-bit comparison is incorrect; even 5162306a36Sopenharmony_ci * though the CPU read will be atomic, the DMA write may not be. 5262306a36Sopenharmony_ci */ 5362306a36Sopenharmony_cistatic inline int ef4_event_present(ef4_qword_t *event) 5462306a36Sopenharmony_ci{ 5562306a36Sopenharmony_ci return !(EF4_DWORD_IS_ALL_ONES(event->dword[0]) | 5662306a36Sopenharmony_ci EF4_DWORD_IS_ALL_ONES(event->dword[1])); 5762306a36Sopenharmony_ci} 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci/* Returns a pointer to the specified transmit descriptor in the TX 6062306a36Sopenharmony_ci * descriptor queue belonging to the specified channel. 6162306a36Sopenharmony_ci */ 6262306a36Sopenharmony_cistatic inline ef4_qword_t * 6362306a36Sopenharmony_cief4_tx_desc(struct ef4_tx_queue *tx_queue, unsigned int index) 6462306a36Sopenharmony_ci{ 6562306a36Sopenharmony_ci return ((ef4_qword_t *) (tx_queue->txd.buf.addr)) + index; 6662306a36Sopenharmony_ci} 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci/* Get partner of a TX queue, seen as part of the same net core queue */ 6962306a36Sopenharmony_cistatic inline struct ef4_tx_queue *ef4_tx_queue_partner(struct ef4_tx_queue *tx_queue) 7062306a36Sopenharmony_ci{ 7162306a36Sopenharmony_ci if (tx_queue->queue & EF4_TXQ_TYPE_OFFLOAD) 7262306a36Sopenharmony_ci return tx_queue - EF4_TXQ_TYPE_OFFLOAD; 7362306a36Sopenharmony_ci else 7462306a36Sopenharmony_ci return tx_queue + EF4_TXQ_TYPE_OFFLOAD; 7562306a36Sopenharmony_ci} 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci/* Report whether this TX queue would be empty for the given write_count. 7862306a36Sopenharmony_ci * May return false negative. 7962306a36Sopenharmony_ci */ 8062306a36Sopenharmony_cistatic inline bool __ef4_nic_tx_is_empty(struct ef4_tx_queue *tx_queue, 8162306a36Sopenharmony_ci unsigned int write_count) 8262306a36Sopenharmony_ci{ 8362306a36Sopenharmony_ci unsigned int empty_read_count = READ_ONCE(tx_queue->empty_read_count); 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci if (empty_read_count == 0) 8662306a36Sopenharmony_ci return false; 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci return ((empty_read_count ^ write_count) & ~EF4_EMPTY_COUNT_VALID) == 0; 8962306a36Sopenharmony_ci} 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci/* Decide whether to push a TX descriptor to the NIC vs merely writing 9262306a36Sopenharmony_ci * the doorbell. This can reduce latency when we are adding a single 9362306a36Sopenharmony_ci * descriptor to an empty queue, but is otherwise pointless. Further, 9462306a36Sopenharmony_ci * Falcon and Siena have hardware bugs (SF bug 33851) that may be 9562306a36Sopenharmony_ci * triggered if we don't check this. 9662306a36Sopenharmony_ci * We use the write_count used for the last doorbell push, to get the 9762306a36Sopenharmony_ci * NIC's view of the tx queue. 9862306a36Sopenharmony_ci */ 9962306a36Sopenharmony_cistatic inline bool ef4_nic_may_push_tx_desc(struct ef4_tx_queue *tx_queue, 10062306a36Sopenharmony_ci unsigned int write_count) 10162306a36Sopenharmony_ci{ 10262306a36Sopenharmony_ci bool was_empty = __ef4_nic_tx_is_empty(tx_queue, write_count); 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci tx_queue->empty_read_count = 0; 10562306a36Sopenharmony_ci return was_empty && tx_queue->write_count - write_count == 1; 10662306a36Sopenharmony_ci} 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci/* Returns a pointer to the specified descriptor in the RX descriptor queue */ 10962306a36Sopenharmony_cistatic inline ef4_qword_t * 11062306a36Sopenharmony_cief4_rx_desc(struct ef4_rx_queue *rx_queue, unsigned int index) 11162306a36Sopenharmony_ci{ 11262306a36Sopenharmony_ci return ((ef4_qword_t *) (rx_queue->rxd.buf.addr)) + index; 11362306a36Sopenharmony_ci} 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_cienum { 11662306a36Sopenharmony_ci PHY_TYPE_NONE = 0, 11762306a36Sopenharmony_ci PHY_TYPE_TXC43128 = 1, 11862306a36Sopenharmony_ci PHY_TYPE_88E1111 = 2, 11962306a36Sopenharmony_ci PHY_TYPE_SFX7101 = 3, 12062306a36Sopenharmony_ci PHY_TYPE_QT2022C2 = 4, 12162306a36Sopenharmony_ci PHY_TYPE_PM8358 = 6, 12262306a36Sopenharmony_ci PHY_TYPE_SFT9001A = 8, 12362306a36Sopenharmony_ci PHY_TYPE_QT2025C = 9, 12462306a36Sopenharmony_ci PHY_TYPE_SFT9001B = 10, 12562306a36Sopenharmony_ci}; 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci#define FALCON_XMAC_LOOPBACKS \ 12862306a36Sopenharmony_ci ((1 << LOOPBACK_XGMII) | \ 12962306a36Sopenharmony_ci (1 << LOOPBACK_XGXS) | \ 13062306a36Sopenharmony_ci (1 << LOOPBACK_XAUI)) 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci/* Alignment of PCIe DMA boundaries (4KB) */ 13362306a36Sopenharmony_ci#define EF4_PAGE_SIZE 4096 13462306a36Sopenharmony_ci/* Size and alignment of buffer table entries (same) */ 13562306a36Sopenharmony_ci#define EF4_BUF_SIZE EF4_PAGE_SIZE 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci/* NIC-generic software stats */ 13862306a36Sopenharmony_cienum { 13962306a36Sopenharmony_ci GENERIC_STAT_rx_noskb_drops, 14062306a36Sopenharmony_ci GENERIC_STAT_rx_nodesc_trunc, 14162306a36Sopenharmony_ci GENERIC_STAT_COUNT 14262306a36Sopenharmony_ci}; 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci/** 14562306a36Sopenharmony_ci * struct falcon_board_type - board operations and type information 14662306a36Sopenharmony_ci * @id: Board type id, as found in NVRAM 14762306a36Sopenharmony_ci * @init: Allocate resources and initialise peripheral hardware 14862306a36Sopenharmony_ci * @init_phy: Do board-specific PHY initialisation 14962306a36Sopenharmony_ci * @fini: Shut down hardware and free resources 15062306a36Sopenharmony_ci * @set_id_led: Set state of identifying LED or revert to automatic function 15162306a36Sopenharmony_ci * @monitor: Board-specific health check function 15262306a36Sopenharmony_ci */ 15362306a36Sopenharmony_cistruct falcon_board_type { 15462306a36Sopenharmony_ci u8 id; 15562306a36Sopenharmony_ci int (*init) (struct ef4_nic *nic); 15662306a36Sopenharmony_ci void (*init_phy) (struct ef4_nic *efx); 15762306a36Sopenharmony_ci void (*fini) (struct ef4_nic *nic); 15862306a36Sopenharmony_ci void (*set_id_led) (struct ef4_nic *efx, enum ef4_led_mode mode); 15962306a36Sopenharmony_ci int (*monitor) (struct ef4_nic *nic); 16062306a36Sopenharmony_ci}; 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci/** 16362306a36Sopenharmony_ci * struct falcon_board - board information 16462306a36Sopenharmony_ci * @type: Type of board 16562306a36Sopenharmony_ci * @major: Major rev. ('A', 'B' ...) 16662306a36Sopenharmony_ci * @minor: Minor rev. (0, 1, ...) 16762306a36Sopenharmony_ci * @i2c_adap: I2C adapter for on-board peripherals 16862306a36Sopenharmony_ci * @i2c_data: Data for bit-banging algorithm 16962306a36Sopenharmony_ci * @hwmon_client: I2C client for hardware monitor 17062306a36Sopenharmony_ci * @ioexp_client: I2C client for power/port control 17162306a36Sopenharmony_ci */ 17262306a36Sopenharmony_cistruct falcon_board { 17362306a36Sopenharmony_ci const struct falcon_board_type *type; 17462306a36Sopenharmony_ci int major; 17562306a36Sopenharmony_ci int minor; 17662306a36Sopenharmony_ci struct i2c_adapter i2c_adap; 17762306a36Sopenharmony_ci struct i2c_algo_bit_data i2c_data; 17862306a36Sopenharmony_ci struct i2c_client *hwmon_client, *ioexp_client; 17962306a36Sopenharmony_ci}; 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci/** 18262306a36Sopenharmony_ci * struct falcon_spi_device - a Falcon SPI (Serial Peripheral Interface) device 18362306a36Sopenharmony_ci * @device_id: Controller's id for the device 18462306a36Sopenharmony_ci * @size: Size (in bytes) 18562306a36Sopenharmony_ci * @addr_len: Number of address bytes in read/write commands 18662306a36Sopenharmony_ci * @munge_address: Flag whether addresses should be munged. 18762306a36Sopenharmony_ci * Some devices with 9-bit addresses (e.g. AT25040A EEPROM) 18862306a36Sopenharmony_ci * use bit 3 of the command byte as address bit A8, rather 18962306a36Sopenharmony_ci * than having a two-byte address. If this flag is set, then 19062306a36Sopenharmony_ci * commands should be munged in this way. 19162306a36Sopenharmony_ci * @erase_command: Erase command (or 0 if sector erase not needed). 19262306a36Sopenharmony_ci * @erase_size: Erase sector size (in bytes) 19362306a36Sopenharmony_ci * Erase commands affect sectors with this size and alignment. 19462306a36Sopenharmony_ci * This must be a power of two. 19562306a36Sopenharmony_ci * @block_size: Write block size (in bytes). 19662306a36Sopenharmony_ci * Write commands are limited to blocks with this size and alignment. 19762306a36Sopenharmony_ci */ 19862306a36Sopenharmony_cistruct falcon_spi_device { 19962306a36Sopenharmony_ci int device_id; 20062306a36Sopenharmony_ci unsigned int size; 20162306a36Sopenharmony_ci unsigned int addr_len; 20262306a36Sopenharmony_ci unsigned int munge_address:1; 20362306a36Sopenharmony_ci u8 erase_command; 20462306a36Sopenharmony_ci unsigned int erase_size; 20562306a36Sopenharmony_ci unsigned int block_size; 20662306a36Sopenharmony_ci}; 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_cistatic inline bool falcon_spi_present(const struct falcon_spi_device *spi) 20962306a36Sopenharmony_ci{ 21062306a36Sopenharmony_ci return spi->size != 0; 21162306a36Sopenharmony_ci} 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_cienum { 21462306a36Sopenharmony_ci FALCON_STAT_tx_bytes = GENERIC_STAT_COUNT, 21562306a36Sopenharmony_ci FALCON_STAT_tx_packets, 21662306a36Sopenharmony_ci FALCON_STAT_tx_pause, 21762306a36Sopenharmony_ci FALCON_STAT_tx_control, 21862306a36Sopenharmony_ci FALCON_STAT_tx_unicast, 21962306a36Sopenharmony_ci FALCON_STAT_tx_multicast, 22062306a36Sopenharmony_ci FALCON_STAT_tx_broadcast, 22162306a36Sopenharmony_ci FALCON_STAT_tx_lt64, 22262306a36Sopenharmony_ci FALCON_STAT_tx_64, 22362306a36Sopenharmony_ci FALCON_STAT_tx_65_to_127, 22462306a36Sopenharmony_ci FALCON_STAT_tx_128_to_255, 22562306a36Sopenharmony_ci FALCON_STAT_tx_256_to_511, 22662306a36Sopenharmony_ci FALCON_STAT_tx_512_to_1023, 22762306a36Sopenharmony_ci FALCON_STAT_tx_1024_to_15xx, 22862306a36Sopenharmony_ci FALCON_STAT_tx_15xx_to_jumbo, 22962306a36Sopenharmony_ci FALCON_STAT_tx_gtjumbo, 23062306a36Sopenharmony_ci FALCON_STAT_tx_non_tcpudp, 23162306a36Sopenharmony_ci FALCON_STAT_tx_mac_src_error, 23262306a36Sopenharmony_ci FALCON_STAT_tx_ip_src_error, 23362306a36Sopenharmony_ci FALCON_STAT_rx_bytes, 23462306a36Sopenharmony_ci FALCON_STAT_rx_good_bytes, 23562306a36Sopenharmony_ci FALCON_STAT_rx_bad_bytes, 23662306a36Sopenharmony_ci FALCON_STAT_rx_packets, 23762306a36Sopenharmony_ci FALCON_STAT_rx_good, 23862306a36Sopenharmony_ci FALCON_STAT_rx_bad, 23962306a36Sopenharmony_ci FALCON_STAT_rx_pause, 24062306a36Sopenharmony_ci FALCON_STAT_rx_control, 24162306a36Sopenharmony_ci FALCON_STAT_rx_unicast, 24262306a36Sopenharmony_ci FALCON_STAT_rx_multicast, 24362306a36Sopenharmony_ci FALCON_STAT_rx_broadcast, 24462306a36Sopenharmony_ci FALCON_STAT_rx_lt64, 24562306a36Sopenharmony_ci FALCON_STAT_rx_64, 24662306a36Sopenharmony_ci FALCON_STAT_rx_65_to_127, 24762306a36Sopenharmony_ci FALCON_STAT_rx_128_to_255, 24862306a36Sopenharmony_ci FALCON_STAT_rx_256_to_511, 24962306a36Sopenharmony_ci FALCON_STAT_rx_512_to_1023, 25062306a36Sopenharmony_ci FALCON_STAT_rx_1024_to_15xx, 25162306a36Sopenharmony_ci FALCON_STAT_rx_15xx_to_jumbo, 25262306a36Sopenharmony_ci FALCON_STAT_rx_gtjumbo, 25362306a36Sopenharmony_ci FALCON_STAT_rx_bad_lt64, 25462306a36Sopenharmony_ci FALCON_STAT_rx_bad_gtjumbo, 25562306a36Sopenharmony_ci FALCON_STAT_rx_overflow, 25662306a36Sopenharmony_ci FALCON_STAT_rx_symbol_error, 25762306a36Sopenharmony_ci FALCON_STAT_rx_align_error, 25862306a36Sopenharmony_ci FALCON_STAT_rx_length_error, 25962306a36Sopenharmony_ci FALCON_STAT_rx_internal_error, 26062306a36Sopenharmony_ci FALCON_STAT_rx_nodesc_drop_cnt, 26162306a36Sopenharmony_ci FALCON_STAT_COUNT 26262306a36Sopenharmony_ci}; 26362306a36Sopenharmony_ci 26462306a36Sopenharmony_ci/** 26562306a36Sopenharmony_ci * struct falcon_nic_data - Falcon NIC state 26662306a36Sopenharmony_ci * @pci_dev2: Secondary function of Falcon A 26762306a36Sopenharmony_ci * @efx: ef4_nic pointer 26862306a36Sopenharmony_ci * @board: Board state and functions 26962306a36Sopenharmony_ci * @stats: Hardware statistics 27062306a36Sopenharmony_ci * @stats_disable_count: Nest count for disabling statistics fetches 27162306a36Sopenharmony_ci * @stats_pending: Is there a pending DMA of MAC statistics. 27262306a36Sopenharmony_ci * @stats_timer: A timer for regularly fetching MAC statistics. 27362306a36Sopenharmony_ci * @spi_flash: SPI flash device 27462306a36Sopenharmony_ci * @spi_eeprom: SPI EEPROM device 27562306a36Sopenharmony_ci * @spi_lock: SPI bus lock 27662306a36Sopenharmony_ci * @mdio_lock: MDIO bus lock 27762306a36Sopenharmony_ci * @xmac_poll_required: XMAC link state needs polling 27862306a36Sopenharmony_ci */ 27962306a36Sopenharmony_cistruct falcon_nic_data { 28062306a36Sopenharmony_ci struct pci_dev *pci_dev2; 28162306a36Sopenharmony_ci struct ef4_nic *efx; 28262306a36Sopenharmony_ci struct falcon_board board; 28362306a36Sopenharmony_ci u64 stats[FALCON_STAT_COUNT]; 28462306a36Sopenharmony_ci unsigned int stats_disable_count; 28562306a36Sopenharmony_ci bool stats_pending; 28662306a36Sopenharmony_ci struct timer_list stats_timer; 28762306a36Sopenharmony_ci struct falcon_spi_device spi_flash; 28862306a36Sopenharmony_ci struct falcon_spi_device spi_eeprom; 28962306a36Sopenharmony_ci struct mutex spi_lock; 29062306a36Sopenharmony_ci struct mutex mdio_lock; 29162306a36Sopenharmony_ci bool xmac_poll_required; 29262306a36Sopenharmony_ci}; 29362306a36Sopenharmony_ci 29462306a36Sopenharmony_cistatic inline struct falcon_board *falcon_board(struct ef4_nic *efx) 29562306a36Sopenharmony_ci{ 29662306a36Sopenharmony_ci struct falcon_nic_data *data = efx->nic_data; 29762306a36Sopenharmony_ci return &data->board; 29862306a36Sopenharmony_ci} 29962306a36Sopenharmony_ci 30062306a36Sopenharmony_cistruct ethtool_ts_info; 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ciextern const struct ef4_nic_type falcon_a1_nic_type; 30362306a36Sopenharmony_ciextern const struct ef4_nic_type falcon_b0_nic_type; 30462306a36Sopenharmony_ci 30562306a36Sopenharmony_ci/************************************************************************** 30662306a36Sopenharmony_ci * 30762306a36Sopenharmony_ci * Externs 30862306a36Sopenharmony_ci * 30962306a36Sopenharmony_ci ************************************************************************** 31062306a36Sopenharmony_ci */ 31162306a36Sopenharmony_ci 31262306a36Sopenharmony_ciint falcon_probe_board(struct ef4_nic *efx, u16 revision_info); 31362306a36Sopenharmony_ci 31462306a36Sopenharmony_ci/* TX data path */ 31562306a36Sopenharmony_cistatic inline int ef4_nic_probe_tx(struct ef4_tx_queue *tx_queue) 31662306a36Sopenharmony_ci{ 31762306a36Sopenharmony_ci return tx_queue->efx->type->tx_probe(tx_queue); 31862306a36Sopenharmony_ci} 31962306a36Sopenharmony_cistatic inline void ef4_nic_init_tx(struct ef4_tx_queue *tx_queue) 32062306a36Sopenharmony_ci{ 32162306a36Sopenharmony_ci tx_queue->efx->type->tx_init(tx_queue); 32262306a36Sopenharmony_ci} 32362306a36Sopenharmony_cistatic inline void ef4_nic_remove_tx(struct ef4_tx_queue *tx_queue) 32462306a36Sopenharmony_ci{ 32562306a36Sopenharmony_ci tx_queue->efx->type->tx_remove(tx_queue); 32662306a36Sopenharmony_ci} 32762306a36Sopenharmony_cistatic inline void ef4_nic_push_buffers(struct ef4_tx_queue *tx_queue) 32862306a36Sopenharmony_ci{ 32962306a36Sopenharmony_ci tx_queue->efx->type->tx_write(tx_queue); 33062306a36Sopenharmony_ci} 33162306a36Sopenharmony_ci 33262306a36Sopenharmony_ci/* RX data path */ 33362306a36Sopenharmony_cistatic inline int ef4_nic_probe_rx(struct ef4_rx_queue *rx_queue) 33462306a36Sopenharmony_ci{ 33562306a36Sopenharmony_ci return rx_queue->efx->type->rx_probe(rx_queue); 33662306a36Sopenharmony_ci} 33762306a36Sopenharmony_cistatic inline void ef4_nic_init_rx(struct ef4_rx_queue *rx_queue) 33862306a36Sopenharmony_ci{ 33962306a36Sopenharmony_ci rx_queue->efx->type->rx_init(rx_queue); 34062306a36Sopenharmony_ci} 34162306a36Sopenharmony_cistatic inline void ef4_nic_remove_rx(struct ef4_rx_queue *rx_queue) 34262306a36Sopenharmony_ci{ 34362306a36Sopenharmony_ci rx_queue->efx->type->rx_remove(rx_queue); 34462306a36Sopenharmony_ci} 34562306a36Sopenharmony_cistatic inline void ef4_nic_notify_rx_desc(struct ef4_rx_queue *rx_queue) 34662306a36Sopenharmony_ci{ 34762306a36Sopenharmony_ci rx_queue->efx->type->rx_write(rx_queue); 34862306a36Sopenharmony_ci} 34962306a36Sopenharmony_cistatic inline void ef4_nic_generate_fill_event(struct ef4_rx_queue *rx_queue) 35062306a36Sopenharmony_ci{ 35162306a36Sopenharmony_ci rx_queue->efx->type->rx_defer_refill(rx_queue); 35262306a36Sopenharmony_ci} 35362306a36Sopenharmony_ci 35462306a36Sopenharmony_ci/* Event data path */ 35562306a36Sopenharmony_cistatic inline int ef4_nic_probe_eventq(struct ef4_channel *channel) 35662306a36Sopenharmony_ci{ 35762306a36Sopenharmony_ci return channel->efx->type->ev_probe(channel); 35862306a36Sopenharmony_ci} 35962306a36Sopenharmony_cistatic inline int ef4_nic_init_eventq(struct ef4_channel *channel) 36062306a36Sopenharmony_ci{ 36162306a36Sopenharmony_ci return channel->efx->type->ev_init(channel); 36262306a36Sopenharmony_ci} 36362306a36Sopenharmony_cistatic inline void ef4_nic_fini_eventq(struct ef4_channel *channel) 36462306a36Sopenharmony_ci{ 36562306a36Sopenharmony_ci channel->efx->type->ev_fini(channel); 36662306a36Sopenharmony_ci} 36762306a36Sopenharmony_cistatic inline void ef4_nic_remove_eventq(struct ef4_channel *channel) 36862306a36Sopenharmony_ci{ 36962306a36Sopenharmony_ci channel->efx->type->ev_remove(channel); 37062306a36Sopenharmony_ci} 37162306a36Sopenharmony_cistatic inline int 37262306a36Sopenharmony_cief4_nic_process_eventq(struct ef4_channel *channel, int quota) 37362306a36Sopenharmony_ci{ 37462306a36Sopenharmony_ci return channel->efx->type->ev_process(channel, quota); 37562306a36Sopenharmony_ci} 37662306a36Sopenharmony_cistatic inline void ef4_nic_eventq_read_ack(struct ef4_channel *channel) 37762306a36Sopenharmony_ci{ 37862306a36Sopenharmony_ci channel->efx->type->ev_read_ack(channel); 37962306a36Sopenharmony_ci} 38062306a36Sopenharmony_civoid ef4_nic_event_test_start(struct ef4_channel *channel); 38162306a36Sopenharmony_ci 38262306a36Sopenharmony_ci/* queue operations */ 38362306a36Sopenharmony_ciint ef4_farch_tx_probe(struct ef4_tx_queue *tx_queue); 38462306a36Sopenharmony_civoid ef4_farch_tx_init(struct ef4_tx_queue *tx_queue); 38562306a36Sopenharmony_civoid ef4_farch_tx_fini(struct ef4_tx_queue *tx_queue); 38662306a36Sopenharmony_civoid ef4_farch_tx_remove(struct ef4_tx_queue *tx_queue); 38762306a36Sopenharmony_civoid ef4_farch_tx_write(struct ef4_tx_queue *tx_queue); 38862306a36Sopenharmony_ciunsigned int ef4_farch_tx_limit_len(struct ef4_tx_queue *tx_queue, 38962306a36Sopenharmony_ci dma_addr_t dma_addr, unsigned int len); 39062306a36Sopenharmony_ciint ef4_farch_rx_probe(struct ef4_rx_queue *rx_queue); 39162306a36Sopenharmony_civoid ef4_farch_rx_init(struct ef4_rx_queue *rx_queue); 39262306a36Sopenharmony_civoid ef4_farch_rx_fini(struct ef4_rx_queue *rx_queue); 39362306a36Sopenharmony_civoid ef4_farch_rx_remove(struct ef4_rx_queue *rx_queue); 39462306a36Sopenharmony_civoid ef4_farch_rx_write(struct ef4_rx_queue *rx_queue); 39562306a36Sopenharmony_civoid ef4_farch_rx_defer_refill(struct ef4_rx_queue *rx_queue); 39662306a36Sopenharmony_ciint ef4_farch_ev_probe(struct ef4_channel *channel); 39762306a36Sopenharmony_ciint ef4_farch_ev_init(struct ef4_channel *channel); 39862306a36Sopenharmony_civoid ef4_farch_ev_fini(struct ef4_channel *channel); 39962306a36Sopenharmony_civoid ef4_farch_ev_remove(struct ef4_channel *channel); 40062306a36Sopenharmony_ciint ef4_farch_ev_process(struct ef4_channel *channel, int quota); 40162306a36Sopenharmony_civoid ef4_farch_ev_read_ack(struct ef4_channel *channel); 40262306a36Sopenharmony_civoid ef4_farch_ev_test_generate(struct ef4_channel *channel); 40362306a36Sopenharmony_ci 40462306a36Sopenharmony_ci/* filter operations */ 40562306a36Sopenharmony_ciint ef4_farch_filter_table_probe(struct ef4_nic *efx); 40662306a36Sopenharmony_civoid ef4_farch_filter_table_restore(struct ef4_nic *efx); 40762306a36Sopenharmony_civoid ef4_farch_filter_table_remove(struct ef4_nic *efx); 40862306a36Sopenharmony_civoid ef4_farch_filter_update_rx_scatter(struct ef4_nic *efx); 40962306a36Sopenharmony_cis32 ef4_farch_filter_insert(struct ef4_nic *efx, struct ef4_filter_spec *spec, 41062306a36Sopenharmony_ci bool replace); 41162306a36Sopenharmony_ciint ef4_farch_filter_remove_safe(struct ef4_nic *efx, 41262306a36Sopenharmony_ci enum ef4_filter_priority priority, 41362306a36Sopenharmony_ci u32 filter_id); 41462306a36Sopenharmony_ciint ef4_farch_filter_get_safe(struct ef4_nic *efx, 41562306a36Sopenharmony_ci enum ef4_filter_priority priority, u32 filter_id, 41662306a36Sopenharmony_ci struct ef4_filter_spec *); 41762306a36Sopenharmony_ciint ef4_farch_filter_clear_rx(struct ef4_nic *efx, 41862306a36Sopenharmony_ci enum ef4_filter_priority priority); 41962306a36Sopenharmony_ciu32 ef4_farch_filter_count_rx_used(struct ef4_nic *efx, 42062306a36Sopenharmony_ci enum ef4_filter_priority priority); 42162306a36Sopenharmony_ciu32 ef4_farch_filter_get_rx_id_limit(struct ef4_nic *efx); 42262306a36Sopenharmony_cis32 ef4_farch_filter_get_rx_ids(struct ef4_nic *efx, 42362306a36Sopenharmony_ci enum ef4_filter_priority priority, u32 *buf, 42462306a36Sopenharmony_ci u32 size); 42562306a36Sopenharmony_ci#ifdef CONFIG_RFS_ACCEL 42662306a36Sopenharmony_cis32 ef4_farch_filter_rfs_insert(struct ef4_nic *efx, 42762306a36Sopenharmony_ci struct ef4_filter_spec *spec); 42862306a36Sopenharmony_cibool ef4_farch_filter_rfs_expire_one(struct ef4_nic *efx, u32 flow_id, 42962306a36Sopenharmony_ci unsigned int index); 43062306a36Sopenharmony_ci#endif 43162306a36Sopenharmony_civoid ef4_farch_filter_sync_rx_mode(struct ef4_nic *efx); 43262306a36Sopenharmony_ci 43362306a36Sopenharmony_cibool ef4_nic_event_present(struct ef4_channel *channel); 43462306a36Sopenharmony_ci 43562306a36Sopenharmony_ci/* Some statistics are computed as A - B where A and B each increase 43662306a36Sopenharmony_ci * linearly with some hardware counter(s) and the counters are read 43762306a36Sopenharmony_ci * asynchronously. If the counters contributing to B are always read 43862306a36Sopenharmony_ci * after those contributing to A, the computed value may be lower than 43962306a36Sopenharmony_ci * the true value by some variable amount, and may decrease between 44062306a36Sopenharmony_ci * subsequent computations. 44162306a36Sopenharmony_ci * 44262306a36Sopenharmony_ci * We should never allow statistics to decrease or to exceed the true 44362306a36Sopenharmony_ci * value. Since the computed value will never be greater than the 44462306a36Sopenharmony_ci * true value, we can achieve this by only storing the computed value 44562306a36Sopenharmony_ci * when it increases. 44662306a36Sopenharmony_ci */ 44762306a36Sopenharmony_cistatic inline void ef4_update_diff_stat(u64 *stat, u64 diff) 44862306a36Sopenharmony_ci{ 44962306a36Sopenharmony_ci if ((s64)(diff - *stat) > 0) 45062306a36Sopenharmony_ci *stat = diff; 45162306a36Sopenharmony_ci} 45262306a36Sopenharmony_ci 45362306a36Sopenharmony_ci/* Interrupts */ 45462306a36Sopenharmony_ciint ef4_nic_init_interrupt(struct ef4_nic *efx); 45562306a36Sopenharmony_ciint ef4_nic_irq_test_start(struct ef4_nic *efx); 45662306a36Sopenharmony_civoid ef4_nic_fini_interrupt(struct ef4_nic *efx); 45762306a36Sopenharmony_civoid ef4_farch_irq_enable_master(struct ef4_nic *efx); 45862306a36Sopenharmony_ciint ef4_farch_irq_test_generate(struct ef4_nic *efx); 45962306a36Sopenharmony_civoid ef4_farch_irq_disable_master(struct ef4_nic *efx); 46062306a36Sopenharmony_ciirqreturn_t ef4_farch_msi_interrupt(int irq, void *dev_id); 46162306a36Sopenharmony_ciirqreturn_t ef4_farch_legacy_interrupt(int irq, void *dev_id); 46262306a36Sopenharmony_ciirqreturn_t ef4_farch_fatal_interrupt(struct ef4_nic *efx); 46362306a36Sopenharmony_ci 46462306a36Sopenharmony_cistatic inline int ef4_nic_event_test_irq_cpu(struct ef4_channel *channel) 46562306a36Sopenharmony_ci{ 46662306a36Sopenharmony_ci return READ_ONCE(channel->event_test_cpu); 46762306a36Sopenharmony_ci} 46862306a36Sopenharmony_cistatic inline int ef4_nic_irq_test_irq_cpu(struct ef4_nic *efx) 46962306a36Sopenharmony_ci{ 47062306a36Sopenharmony_ci return READ_ONCE(efx->last_irq_cpu); 47162306a36Sopenharmony_ci} 47262306a36Sopenharmony_ci 47362306a36Sopenharmony_ci/* Global Resources */ 47462306a36Sopenharmony_ciint ef4_nic_flush_queues(struct ef4_nic *efx); 47562306a36Sopenharmony_ciint ef4_farch_fini_dmaq(struct ef4_nic *efx); 47662306a36Sopenharmony_civoid ef4_farch_finish_flr(struct ef4_nic *efx); 47762306a36Sopenharmony_civoid falcon_start_nic_stats(struct ef4_nic *efx); 47862306a36Sopenharmony_civoid falcon_stop_nic_stats(struct ef4_nic *efx); 47962306a36Sopenharmony_ciint falcon_reset_xaui(struct ef4_nic *efx); 48062306a36Sopenharmony_civoid ef4_farch_dimension_resources(struct ef4_nic *efx, unsigned sram_lim_qw); 48162306a36Sopenharmony_civoid ef4_farch_init_common(struct ef4_nic *efx); 48262306a36Sopenharmony_civoid ef4_farch_rx_push_indir_table(struct ef4_nic *efx); 48362306a36Sopenharmony_ci 48462306a36Sopenharmony_ciint ef4_nic_alloc_buffer(struct ef4_nic *efx, struct ef4_buffer *buffer, 48562306a36Sopenharmony_ci unsigned int len, gfp_t gfp_flags); 48662306a36Sopenharmony_civoid ef4_nic_free_buffer(struct ef4_nic *efx, struct ef4_buffer *buffer); 48762306a36Sopenharmony_ci 48862306a36Sopenharmony_ci/* Tests */ 48962306a36Sopenharmony_cistruct ef4_farch_register_test { 49062306a36Sopenharmony_ci unsigned address; 49162306a36Sopenharmony_ci ef4_oword_t mask; 49262306a36Sopenharmony_ci}; 49362306a36Sopenharmony_ciint ef4_farch_test_registers(struct ef4_nic *efx, 49462306a36Sopenharmony_ci const struct ef4_farch_register_test *regs, 49562306a36Sopenharmony_ci size_t n_regs); 49662306a36Sopenharmony_ci 49762306a36Sopenharmony_cisize_t ef4_nic_get_regs_len(struct ef4_nic *efx); 49862306a36Sopenharmony_civoid ef4_nic_get_regs(struct ef4_nic *efx, void *buf); 49962306a36Sopenharmony_ci 50062306a36Sopenharmony_cisize_t ef4_nic_describe_stats(const struct ef4_hw_stat_desc *desc, size_t count, 50162306a36Sopenharmony_ci const unsigned long *mask, u8 *names); 50262306a36Sopenharmony_civoid ef4_nic_update_stats(const struct ef4_hw_stat_desc *desc, size_t count, 50362306a36Sopenharmony_ci const unsigned long *mask, u64 *stats, 50462306a36Sopenharmony_ci const void *dma_buf, bool accumulate); 50562306a36Sopenharmony_civoid ef4_nic_fix_nodesc_drop_stat(struct ef4_nic *efx, u64 *stat); 50662306a36Sopenharmony_ci 50762306a36Sopenharmony_ci#define EF4_MAX_FLUSH_TIME 5000 50862306a36Sopenharmony_ci 50962306a36Sopenharmony_civoid ef4_farch_generate_event(struct ef4_nic *efx, unsigned int evq, 51062306a36Sopenharmony_ci ef4_qword_t *event); 51162306a36Sopenharmony_ci 51262306a36Sopenharmony_ci#endif /* EF4_NIC_H */ 513