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 2005-2013 Solarflare Communications Inc. 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci/* Common definitions for all Efx net driver code */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#ifndef EF4_NET_DRIVER_H 1162306a36Sopenharmony_ci#define EF4_NET_DRIVER_H 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#include <linux/netdevice.h> 1462306a36Sopenharmony_ci#include <linux/etherdevice.h> 1562306a36Sopenharmony_ci#include <linux/ethtool.h> 1662306a36Sopenharmony_ci#include <linux/if_vlan.h> 1762306a36Sopenharmony_ci#include <linux/timer.h> 1862306a36Sopenharmony_ci#include <linux/mdio.h> 1962306a36Sopenharmony_ci#include <linux/list.h> 2062306a36Sopenharmony_ci#include <linux/pci.h> 2162306a36Sopenharmony_ci#include <linux/device.h> 2262306a36Sopenharmony_ci#include <linux/highmem.h> 2362306a36Sopenharmony_ci#include <linux/workqueue.h> 2462306a36Sopenharmony_ci#include <linux/mutex.h> 2562306a36Sopenharmony_ci#include <linux/rwsem.h> 2662306a36Sopenharmony_ci#include <linux/vmalloc.h> 2762306a36Sopenharmony_ci#include <linux/i2c.h> 2862306a36Sopenharmony_ci#include <linux/mtd/mtd.h> 2962306a36Sopenharmony_ci#include <net/busy_poll.h> 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#include "enum.h" 3262306a36Sopenharmony_ci#include "bitfield.h" 3362306a36Sopenharmony_ci#include "filter.h" 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci/************************************************************************** 3662306a36Sopenharmony_ci * 3762306a36Sopenharmony_ci * Build definitions 3862306a36Sopenharmony_ci * 3962306a36Sopenharmony_ci **************************************************************************/ 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#define EF4_DRIVER_VERSION "4.1" 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#ifdef DEBUG 4462306a36Sopenharmony_ci#define EF4_BUG_ON_PARANOID(x) BUG_ON(x) 4562306a36Sopenharmony_ci#define EF4_WARN_ON_PARANOID(x) WARN_ON(x) 4662306a36Sopenharmony_ci#else 4762306a36Sopenharmony_ci#define EF4_BUG_ON_PARANOID(x) do {} while (0) 4862306a36Sopenharmony_ci#define EF4_WARN_ON_PARANOID(x) do {} while (0) 4962306a36Sopenharmony_ci#endif 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci/************************************************************************** 5262306a36Sopenharmony_ci * 5362306a36Sopenharmony_ci * Efx data structures 5462306a36Sopenharmony_ci * 5562306a36Sopenharmony_ci **************************************************************************/ 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci#define EF4_MAX_CHANNELS 32U 5862306a36Sopenharmony_ci#define EF4_MAX_RX_QUEUES EF4_MAX_CHANNELS 5962306a36Sopenharmony_ci#define EF4_EXTRA_CHANNEL_IOV 0 6062306a36Sopenharmony_ci#define EF4_EXTRA_CHANNEL_PTP 1 6162306a36Sopenharmony_ci#define EF4_MAX_EXTRA_CHANNELS 2U 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci/* Checksum generation is a per-queue option in hardware, so each 6462306a36Sopenharmony_ci * queue visible to the networking core is backed by two hardware TX 6562306a36Sopenharmony_ci * queues. */ 6662306a36Sopenharmony_ci#define EF4_MAX_TX_TC 2 6762306a36Sopenharmony_ci#define EF4_MAX_CORE_TX_QUEUES (EF4_MAX_TX_TC * EF4_MAX_CHANNELS) 6862306a36Sopenharmony_ci#define EF4_TXQ_TYPE_OFFLOAD 1 /* flag */ 6962306a36Sopenharmony_ci#define EF4_TXQ_TYPE_HIGHPRI 2 /* flag */ 7062306a36Sopenharmony_ci#define EF4_TXQ_TYPES 4 7162306a36Sopenharmony_ci#define EF4_MAX_TX_QUEUES (EF4_TXQ_TYPES * EF4_MAX_CHANNELS) 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci/* Maximum possible MTU the driver supports */ 7462306a36Sopenharmony_ci#define EF4_MAX_MTU (9 * 1024) 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci/* Minimum MTU, from RFC791 (IP) */ 7762306a36Sopenharmony_ci#define EF4_MIN_MTU 68 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci/* Size of an RX scatter buffer. Small enough to pack 2 into a 4K page, 8062306a36Sopenharmony_ci * and should be a multiple of the cache line size. 8162306a36Sopenharmony_ci */ 8262306a36Sopenharmony_ci#define EF4_RX_USR_BUF_SIZE (2048 - 256) 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci/* If possible, we should ensure cache line alignment at start and end 8562306a36Sopenharmony_ci * of every buffer. Otherwise, we just need to ensure 4-byte 8662306a36Sopenharmony_ci * alignment of the network header. 8762306a36Sopenharmony_ci */ 8862306a36Sopenharmony_ci#if NET_IP_ALIGN == 0 8962306a36Sopenharmony_ci#define EF4_RX_BUF_ALIGNMENT L1_CACHE_BYTES 9062306a36Sopenharmony_ci#else 9162306a36Sopenharmony_ci#define EF4_RX_BUF_ALIGNMENT 4 9262306a36Sopenharmony_ci#endif 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_cistruct ef4_self_tests; 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci/** 9762306a36Sopenharmony_ci * struct ef4_buffer - A general-purpose DMA buffer 9862306a36Sopenharmony_ci * @addr: host base address of the buffer 9962306a36Sopenharmony_ci * @dma_addr: DMA base address of the buffer 10062306a36Sopenharmony_ci * @len: Buffer length, in bytes 10162306a36Sopenharmony_ci * 10262306a36Sopenharmony_ci * The NIC uses these buffers for its interrupt status registers and 10362306a36Sopenharmony_ci * MAC stats dumps. 10462306a36Sopenharmony_ci */ 10562306a36Sopenharmony_cistruct ef4_buffer { 10662306a36Sopenharmony_ci void *addr; 10762306a36Sopenharmony_ci dma_addr_t dma_addr; 10862306a36Sopenharmony_ci unsigned int len; 10962306a36Sopenharmony_ci}; 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci/** 11262306a36Sopenharmony_ci * struct ef4_special_buffer - DMA buffer entered into buffer table 11362306a36Sopenharmony_ci * @buf: Standard &struct ef4_buffer 11462306a36Sopenharmony_ci * @index: Buffer index within controller;s buffer table 11562306a36Sopenharmony_ci * @entries: Number of buffer table entries 11662306a36Sopenharmony_ci * 11762306a36Sopenharmony_ci * The NIC has a buffer table that maps buffers of size %EF4_BUF_SIZE. 11862306a36Sopenharmony_ci * Event and descriptor rings are addressed via one or more buffer 11962306a36Sopenharmony_ci * table entries (and so can be physically non-contiguous, although we 12062306a36Sopenharmony_ci * currently do not take advantage of that). On Falcon and Siena we 12162306a36Sopenharmony_ci * have to take care of allocating and initialising the entries 12262306a36Sopenharmony_ci * ourselves. On later hardware this is managed by the firmware and 12362306a36Sopenharmony_ci * @index and @entries are left as 0. 12462306a36Sopenharmony_ci */ 12562306a36Sopenharmony_cistruct ef4_special_buffer { 12662306a36Sopenharmony_ci struct ef4_buffer buf; 12762306a36Sopenharmony_ci unsigned int index; 12862306a36Sopenharmony_ci unsigned int entries; 12962306a36Sopenharmony_ci}; 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci/** 13262306a36Sopenharmony_ci * struct ef4_tx_buffer - buffer state for a TX descriptor 13362306a36Sopenharmony_ci * @skb: When @flags & %EF4_TX_BUF_SKB, the associated socket buffer to be 13462306a36Sopenharmony_ci * freed when descriptor completes 13562306a36Sopenharmony_ci * @option: When @flags & %EF4_TX_BUF_OPTION, a NIC-specific option descriptor. 13662306a36Sopenharmony_ci * @dma_addr: DMA address of the fragment. 13762306a36Sopenharmony_ci * @flags: Flags for allocation and DMA mapping type 13862306a36Sopenharmony_ci * @len: Length of this fragment. 13962306a36Sopenharmony_ci * This field is zero when the queue slot is empty. 14062306a36Sopenharmony_ci * @unmap_len: Length of this fragment to unmap 14162306a36Sopenharmony_ci * @dma_offset: Offset of @dma_addr from the address of the backing DMA mapping. 14262306a36Sopenharmony_ci * Only valid if @unmap_len != 0. 14362306a36Sopenharmony_ci */ 14462306a36Sopenharmony_cistruct ef4_tx_buffer { 14562306a36Sopenharmony_ci const struct sk_buff *skb; 14662306a36Sopenharmony_ci union { 14762306a36Sopenharmony_ci ef4_qword_t option; 14862306a36Sopenharmony_ci dma_addr_t dma_addr; 14962306a36Sopenharmony_ci }; 15062306a36Sopenharmony_ci unsigned short flags; 15162306a36Sopenharmony_ci unsigned short len; 15262306a36Sopenharmony_ci unsigned short unmap_len; 15362306a36Sopenharmony_ci unsigned short dma_offset; 15462306a36Sopenharmony_ci}; 15562306a36Sopenharmony_ci#define EF4_TX_BUF_CONT 1 /* not last descriptor of packet */ 15662306a36Sopenharmony_ci#define EF4_TX_BUF_SKB 2 /* buffer is last part of skb */ 15762306a36Sopenharmony_ci#define EF4_TX_BUF_MAP_SINGLE 8 /* buffer was mapped with dma_map_single() */ 15862306a36Sopenharmony_ci#define EF4_TX_BUF_OPTION 0x10 /* empty buffer for option descriptor */ 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci/** 16162306a36Sopenharmony_ci * struct ef4_tx_queue - An Efx TX queue 16262306a36Sopenharmony_ci * 16362306a36Sopenharmony_ci * This is a ring buffer of TX fragments. 16462306a36Sopenharmony_ci * Since the TX completion path always executes on the same 16562306a36Sopenharmony_ci * CPU and the xmit path can operate on different CPUs, 16662306a36Sopenharmony_ci * performance is increased by ensuring that the completion 16762306a36Sopenharmony_ci * path and the xmit path operate on different cache lines. 16862306a36Sopenharmony_ci * This is particularly important if the xmit path is always 16962306a36Sopenharmony_ci * executing on one CPU which is different from the completion 17062306a36Sopenharmony_ci * path. There is also a cache line for members which are 17162306a36Sopenharmony_ci * read but not written on the fast path. 17262306a36Sopenharmony_ci * 17362306a36Sopenharmony_ci * @efx: The associated Efx NIC 17462306a36Sopenharmony_ci * @queue: DMA queue number 17562306a36Sopenharmony_ci * @channel: The associated channel 17662306a36Sopenharmony_ci * @core_txq: The networking core TX queue structure 17762306a36Sopenharmony_ci * @buffer: The software buffer ring 17862306a36Sopenharmony_ci * @cb_page: Array of pages of copy buffers. Carved up according to 17962306a36Sopenharmony_ci * %EF4_TX_CB_ORDER into %EF4_TX_CB_SIZE-sized chunks. 18062306a36Sopenharmony_ci * @txd: The hardware descriptor ring 18162306a36Sopenharmony_ci * @ptr_mask: The size of the ring minus 1. 18262306a36Sopenharmony_ci * @initialised: Has hardware queue been initialised? 18362306a36Sopenharmony_ci * @tx_min_size: Minimum transmit size for this queue. Depends on HW. 18462306a36Sopenharmony_ci * @read_count: Current read pointer. 18562306a36Sopenharmony_ci * This is the number of buffers that have been removed from both rings. 18662306a36Sopenharmony_ci * @old_write_count: The value of @write_count when last checked. 18762306a36Sopenharmony_ci * This is here for performance reasons. The xmit path will 18862306a36Sopenharmony_ci * only get the up-to-date value of @write_count if this 18962306a36Sopenharmony_ci * variable indicates that the queue is empty. This is to 19062306a36Sopenharmony_ci * avoid cache-line ping-pong between the xmit path and the 19162306a36Sopenharmony_ci * completion path. 19262306a36Sopenharmony_ci * @merge_events: Number of TX merged completion events 19362306a36Sopenharmony_ci * @insert_count: Current insert pointer 19462306a36Sopenharmony_ci * This is the number of buffers that have been added to the 19562306a36Sopenharmony_ci * software ring. 19662306a36Sopenharmony_ci * @write_count: Current write pointer 19762306a36Sopenharmony_ci * This is the number of buffers that have been added to the 19862306a36Sopenharmony_ci * hardware ring. 19962306a36Sopenharmony_ci * @old_read_count: The value of read_count when last checked. 20062306a36Sopenharmony_ci * This is here for performance reasons. The xmit path will 20162306a36Sopenharmony_ci * only get the up-to-date value of read_count if this 20262306a36Sopenharmony_ci * variable indicates that the queue is full. This is to 20362306a36Sopenharmony_ci * avoid cache-line ping-pong between the xmit path and the 20462306a36Sopenharmony_ci * completion path. 20562306a36Sopenharmony_ci * @pushes: Number of times the TX push feature has been used 20662306a36Sopenharmony_ci * @xmit_more_available: Are any packets waiting to be pushed to the NIC 20762306a36Sopenharmony_ci * @cb_packets: Number of times the TX copybreak feature has been used 20862306a36Sopenharmony_ci * @empty_read_count: If the completion path has seen the queue as empty 20962306a36Sopenharmony_ci * and the transmission path has not yet checked this, the value of 21062306a36Sopenharmony_ci * @read_count bitwise-added to %EF4_EMPTY_COUNT_VALID; otherwise 0. 21162306a36Sopenharmony_ci */ 21262306a36Sopenharmony_cistruct ef4_tx_queue { 21362306a36Sopenharmony_ci /* Members which don't change on the fast path */ 21462306a36Sopenharmony_ci struct ef4_nic *efx ____cacheline_aligned_in_smp; 21562306a36Sopenharmony_ci unsigned queue; 21662306a36Sopenharmony_ci struct ef4_channel *channel; 21762306a36Sopenharmony_ci struct netdev_queue *core_txq; 21862306a36Sopenharmony_ci struct ef4_tx_buffer *buffer; 21962306a36Sopenharmony_ci struct ef4_buffer *cb_page; 22062306a36Sopenharmony_ci struct ef4_special_buffer txd; 22162306a36Sopenharmony_ci unsigned int ptr_mask; 22262306a36Sopenharmony_ci bool initialised; 22362306a36Sopenharmony_ci unsigned int tx_min_size; 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci /* Function pointers used in the fast path. */ 22662306a36Sopenharmony_ci int (*handle_tso)(struct ef4_tx_queue*, struct sk_buff*, bool *); 22762306a36Sopenharmony_ci 22862306a36Sopenharmony_ci /* Members used mainly on the completion path */ 22962306a36Sopenharmony_ci unsigned int read_count ____cacheline_aligned_in_smp; 23062306a36Sopenharmony_ci unsigned int old_write_count; 23162306a36Sopenharmony_ci unsigned int merge_events; 23262306a36Sopenharmony_ci unsigned int bytes_compl; 23362306a36Sopenharmony_ci unsigned int pkts_compl; 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_ci /* Members used only on the xmit path */ 23662306a36Sopenharmony_ci unsigned int insert_count ____cacheline_aligned_in_smp; 23762306a36Sopenharmony_ci unsigned int write_count; 23862306a36Sopenharmony_ci unsigned int old_read_count; 23962306a36Sopenharmony_ci unsigned int pushes; 24062306a36Sopenharmony_ci bool xmit_more_available; 24162306a36Sopenharmony_ci unsigned int cb_packets; 24262306a36Sopenharmony_ci /* Statistics to supplement MAC stats */ 24362306a36Sopenharmony_ci unsigned long tx_packets; 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ci /* Members shared between paths and sometimes updated */ 24662306a36Sopenharmony_ci unsigned int empty_read_count ____cacheline_aligned_in_smp; 24762306a36Sopenharmony_ci#define EF4_EMPTY_COUNT_VALID 0x80000000 24862306a36Sopenharmony_ci atomic_t flush_outstanding; 24962306a36Sopenharmony_ci}; 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_ci#define EF4_TX_CB_ORDER 7 25262306a36Sopenharmony_ci#define EF4_TX_CB_SIZE (1 << EF4_TX_CB_ORDER) - NET_IP_ALIGN 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ci/** 25562306a36Sopenharmony_ci * struct ef4_rx_buffer - An Efx RX data buffer 25662306a36Sopenharmony_ci * @dma_addr: DMA base address of the buffer 25762306a36Sopenharmony_ci * @page: The associated page buffer. 25862306a36Sopenharmony_ci * Will be %NULL if the buffer slot is currently free. 25962306a36Sopenharmony_ci * @page_offset: If pending: offset in @page of DMA base address. 26062306a36Sopenharmony_ci * If completed: offset in @page of Ethernet header. 26162306a36Sopenharmony_ci * @len: If pending: length for DMA descriptor. 26262306a36Sopenharmony_ci * If completed: received length, excluding hash prefix. 26362306a36Sopenharmony_ci * @flags: Flags for buffer and packet state. These are only set on the 26462306a36Sopenharmony_ci * first buffer of a scattered packet. 26562306a36Sopenharmony_ci */ 26662306a36Sopenharmony_cistruct ef4_rx_buffer { 26762306a36Sopenharmony_ci dma_addr_t dma_addr; 26862306a36Sopenharmony_ci struct page *page; 26962306a36Sopenharmony_ci u16 page_offset; 27062306a36Sopenharmony_ci u16 len; 27162306a36Sopenharmony_ci u16 flags; 27262306a36Sopenharmony_ci}; 27362306a36Sopenharmony_ci#define EF4_RX_BUF_LAST_IN_PAGE 0x0001 27462306a36Sopenharmony_ci#define EF4_RX_PKT_CSUMMED 0x0002 27562306a36Sopenharmony_ci#define EF4_RX_PKT_DISCARD 0x0004 27662306a36Sopenharmony_ci#define EF4_RX_PKT_TCP 0x0040 27762306a36Sopenharmony_ci#define EF4_RX_PKT_PREFIX_LEN 0x0080 /* length is in prefix only */ 27862306a36Sopenharmony_ci 27962306a36Sopenharmony_ci/** 28062306a36Sopenharmony_ci * struct ef4_rx_page_state - Page-based rx buffer state 28162306a36Sopenharmony_ci * 28262306a36Sopenharmony_ci * Inserted at the start of every page allocated for receive buffers. 28362306a36Sopenharmony_ci * Used to facilitate sharing dma mappings between recycled rx buffers 28462306a36Sopenharmony_ci * and those passed up to the kernel. 28562306a36Sopenharmony_ci * 28662306a36Sopenharmony_ci * @dma_addr: The dma address of this page. 28762306a36Sopenharmony_ci */ 28862306a36Sopenharmony_cistruct ef4_rx_page_state { 28962306a36Sopenharmony_ci dma_addr_t dma_addr; 29062306a36Sopenharmony_ci 29162306a36Sopenharmony_ci unsigned int __pad[] ____cacheline_aligned; 29262306a36Sopenharmony_ci}; 29362306a36Sopenharmony_ci 29462306a36Sopenharmony_ci/** 29562306a36Sopenharmony_ci * struct ef4_rx_queue - An Efx RX queue 29662306a36Sopenharmony_ci * @efx: The associated Efx NIC 29762306a36Sopenharmony_ci * @core_index: Index of network core RX queue. Will be >= 0 iff this 29862306a36Sopenharmony_ci * is associated with a real RX queue. 29962306a36Sopenharmony_ci * @buffer: The software buffer ring 30062306a36Sopenharmony_ci * @rxd: The hardware descriptor ring 30162306a36Sopenharmony_ci * @ptr_mask: The size of the ring minus 1. 30262306a36Sopenharmony_ci * @refill_enabled: Enable refill whenever fill level is low 30362306a36Sopenharmony_ci * @flush_pending: Set when a RX flush is pending. Has the same lifetime as 30462306a36Sopenharmony_ci * @rxq_flush_pending. 30562306a36Sopenharmony_ci * @added_count: Number of buffers added to the receive queue. 30662306a36Sopenharmony_ci * @notified_count: Number of buffers given to NIC (<= @added_count). 30762306a36Sopenharmony_ci * @removed_count: Number of buffers removed from the receive queue. 30862306a36Sopenharmony_ci * @scatter_n: Used by NIC specific receive code. 30962306a36Sopenharmony_ci * @scatter_len: Used by NIC specific receive code. 31062306a36Sopenharmony_ci * @page_ring: The ring to store DMA mapped pages for reuse. 31162306a36Sopenharmony_ci * @page_add: Counter to calculate the write pointer for the recycle ring. 31262306a36Sopenharmony_ci * @page_remove: Counter to calculate the read pointer for the recycle ring. 31362306a36Sopenharmony_ci * @page_recycle_count: The number of pages that have been recycled. 31462306a36Sopenharmony_ci * @page_recycle_failed: The number of pages that couldn't be recycled because 31562306a36Sopenharmony_ci * the kernel still held a reference to them. 31662306a36Sopenharmony_ci * @page_recycle_full: The number of pages that were released because the 31762306a36Sopenharmony_ci * recycle ring was full. 31862306a36Sopenharmony_ci * @page_ptr_mask: The number of pages in the RX recycle ring minus 1. 31962306a36Sopenharmony_ci * @max_fill: RX descriptor maximum fill level (<= ring size) 32062306a36Sopenharmony_ci * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill 32162306a36Sopenharmony_ci * (<= @max_fill) 32262306a36Sopenharmony_ci * @min_fill: RX descriptor minimum non-zero fill level. 32362306a36Sopenharmony_ci * This records the minimum fill level observed when a ring 32462306a36Sopenharmony_ci * refill was triggered. 32562306a36Sopenharmony_ci * @recycle_count: RX buffer recycle counter. 32662306a36Sopenharmony_ci * @slow_fill: Timer used to defer ef4_nic_generate_fill_event(). 32762306a36Sopenharmony_ci */ 32862306a36Sopenharmony_cistruct ef4_rx_queue { 32962306a36Sopenharmony_ci struct ef4_nic *efx; 33062306a36Sopenharmony_ci int core_index; 33162306a36Sopenharmony_ci struct ef4_rx_buffer *buffer; 33262306a36Sopenharmony_ci struct ef4_special_buffer rxd; 33362306a36Sopenharmony_ci unsigned int ptr_mask; 33462306a36Sopenharmony_ci bool refill_enabled; 33562306a36Sopenharmony_ci bool flush_pending; 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_ci unsigned int added_count; 33862306a36Sopenharmony_ci unsigned int notified_count; 33962306a36Sopenharmony_ci unsigned int removed_count; 34062306a36Sopenharmony_ci unsigned int scatter_n; 34162306a36Sopenharmony_ci unsigned int scatter_len; 34262306a36Sopenharmony_ci struct page **page_ring; 34362306a36Sopenharmony_ci unsigned int page_add; 34462306a36Sopenharmony_ci unsigned int page_remove; 34562306a36Sopenharmony_ci unsigned int page_recycle_count; 34662306a36Sopenharmony_ci unsigned int page_recycle_failed; 34762306a36Sopenharmony_ci unsigned int page_recycle_full; 34862306a36Sopenharmony_ci unsigned int page_ptr_mask; 34962306a36Sopenharmony_ci unsigned int max_fill; 35062306a36Sopenharmony_ci unsigned int fast_fill_trigger; 35162306a36Sopenharmony_ci unsigned int min_fill; 35262306a36Sopenharmony_ci unsigned int min_overfill; 35362306a36Sopenharmony_ci unsigned int recycle_count; 35462306a36Sopenharmony_ci struct timer_list slow_fill; 35562306a36Sopenharmony_ci unsigned int slow_fill_count; 35662306a36Sopenharmony_ci /* Statistics to supplement MAC stats */ 35762306a36Sopenharmony_ci unsigned long rx_packets; 35862306a36Sopenharmony_ci}; 35962306a36Sopenharmony_ci 36062306a36Sopenharmony_ci/** 36162306a36Sopenharmony_ci * struct ef4_channel - An Efx channel 36262306a36Sopenharmony_ci * 36362306a36Sopenharmony_ci * A channel comprises an event queue, at least one TX queue, at least 36462306a36Sopenharmony_ci * one RX queue, and an associated tasklet for processing the event 36562306a36Sopenharmony_ci * queue. 36662306a36Sopenharmony_ci * 36762306a36Sopenharmony_ci * @efx: Associated Efx NIC 36862306a36Sopenharmony_ci * @channel: Channel instance number 36962306a36Sopenharmony_ci * @type: Channel type definition 37062306a36Sopenharmony_ci * @eventq_init: Event queue initialised flag 37162306a36Sopenharmony_ci * @enabled: Channel enabled indicator 37262306a36Sopenharmony_ci * @irq: IRQ number (MSI and MSI-X only) 37362306a36Sopenharmony_ci * @irq_moderation_us: IRQ moderation value (in microseconds) 37462306a36Sopenharmony_ci * @napi_dev: Net device used with NAPI 37562306a36Sopenharmony_ci * @napi_str: NAPI control structure 37662306a36Sopenharmony_ci * @state: state for NAPI vs busy polling 37762306a36Sopenharmony_ci * @state_lock: lock protecting @state 37862306a36Sopenharmony_ci * @eventq: Event queue buffer 37962306a36Sopenharmony_ci * @eventq_mask: Event queue pointer mask 38062306a36Sopenharmony_ci * @eventq_read_ptr: Event queue read pointer 38162306a36Sopenharmony_ci * @event_test_cpu: Last CPU to handle interrupt or test event for this channel 38262306a36Sopenharmony_ci * @irq_count: Number of IRQs since last adaptive moderation decision 38362306a36Sopenharmony_ci * @irq_mod_score: IRQ moderation score 38462306a36Sopenharmony_ci * @rps_flow_id: Flow IDs of filters allocated for accelerated RFS, 38562306a36Sopenharmony_ci * indexed by filter ID 38662306a36Sopenharmony_ci * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors 38762306a36Sopenharmony_ci * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors 38862306a36Sopenharmony_ci * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors 38962306a36Sopenharmony_ci * @n_rx_mcast_mismatch: Count of unmatched multicast frames 39062306a36Sopenharmony_ci * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors 39162306a36Sopenharmony_ci * @n_rx_overlength: Count of RX_OVERLENGTH errors 39262306a36Sopenharmony_ci * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun 39362306a36Sopenharmony_ci * @n_rx_nodesc_trunc: Number of RX packets truncated and then dropped due to 39462306a36Sopenharmony_ci * lack of descriptors 39562306a36Sopenharmony_ci * @n_rx_merge_events: Number of RX merged completion events 39662306a36Sopenharmony_ci * @n_rx_merge_packets: Number of RX packets completed by merged events 39762306a36Sopenharmony_ci * @rx_pkt_n_frags: Number of fragments in next packet to be delivered by 39862306a36Sopenharmony_ci * __ef4_rx_packet(), or zero if there is none 39962306a36Sopenharmony_ci * @rx_pkt_index: Ring index of first buffer for next packet to be delivered 40062306a36Sopenharmony_ci * by __ef4_rx_packet(), if @rx_pkt_n_frags != 0 40162306a36Sopenharmony_ci * @rx_queue: RX queue for this channel 40262306a36Sopenharmony_ci * @tx_queue: TX queues for this channel 40362306a36Sopenharmony_ci */ 40462306a36Sopenharmony_cistruct ef4_channel { 40562306a36Sopenharmony_ci struct ef4_nic *efx; 40662306a36Sopenharmony_ci int channel; 40762306a36Sopenharmony_ci const struct ef4_channel_type *type; 40862306a36Sopenharmony_ci bool eventq_init; 40962306a36Sopenharmony_ci bool enabled; 41062306a36Sopenharmony_ci int irq; 41162306a36Sopenharmony_ci unsigned int irq_moderation_us; 41262306a36Sopenharmony_ci struct net_device *napi_dev; 41362306a36Sopenharmony_ci struct napi_struct napi_str; 41462306a36Sopenharmony_ci#ifdef CONFIG_NET_RX_BUSY_POLL 41562306a36Sopenharmony_ci unsigned long busy_poll_state; 41662306a36Sopenharmony_ci#endif 41762306a36Sopenharmony_ci struct ef4_special_buffer eventq; 41862306a36Sopenharmony_ci unsigned int eventq_mask; 41962306a36Sopenharmony_ci unsigned int eventq_read_ptr; 42062306a36Sopenharmony_ci int event_test_cpu; 42162306a36Sopenharmony_ci 42262306a36Sopenharmony_ci unsigned int irq_count; 42362306a36Sopenharmony_ci unsigned int irq_mod_score; 42462306a36Sopenharmony_ci#ifdef CONFIG_RFS_ACCEL 42562306a36Sopenharmony_ci unsigned int rfs_filters_added; 42662306a36Sopenharmony_ci#define RPS_FLOW_ID_INVALID 0xFFFFFFFF 42762306a36Sopenharmony_ci u32 *rps_flow_id; 42862306a36Sopenharmony_ci#endif 42962306a36Sopenharmony_ci 43062306a36Sopenharmony_ci unsigned n_rx_tobe_disc; 43162306a36Sopenharmony_ci unsigned n_rx_ip_hdr_chksum_err; 43262306a36Sopenharmony_ci unsigned n_rx_tcp_udp_chksum_err; 43362306a36Sopenharmony_ci unsigned n_rx_mcast_mismatch; 43462306a36Sopenharmony_ci unsigned n_rx_frm_trunc; 43562306a36Sopenharmony_ci unsigned n_rx_overlength; 43662306a36Sopenharmony_ci unsigned n_skbuff_leaks; 43762306a36Sopenharmony_ci unsigned int n_rx_nodesc_trunc; 43862306a36Sopenharmony_ci unsigned int n_rx_merge_events; 43962306a36Sopenharmony_ci unsigned int n_rx_merge_packets; 44062306a36Sopenharmony_ci 44162306a36Sopenharmony_ci unsigned int rx_pkt_n_frags; 44262306a36Sopenharmony_ci unsigned int rx_pkt_index; 44362306a36Sopenharmony_ci 44462306a36Sopenharmony_ci struct ef4_rx_queue rx_queue; 44562306a36Sopenharmony_ci struct ef4_tx_queue tx_queue[EF4_TXQ_TYPES]; 44662306a36Sopenharmony_ci}; 44762306a36Sopenharmony_ci 44862306a36Sopenharmony_ci/** 44962306a36Sopenharmony_ci * struct ef4_msi_context - Context for each MSI 45062306a36Sopenharmony_ci * @efx: The associated NIC 45162306a36Sopenharmony_ci * @index: Index of the channel/IRQ 45262306a36Sopenharmony_ci * @name: Name of the channel/IRQ 45362306a36Sopenharmony_ci * 45462306a36Sopenharmony_ci * Unlike &struct ef4_channel, this is never reallocated and is always 45562306a36Sopenharmony_ci * safe for the IRQ handler to access. 45662306a36Sopenharmony_ci */ 45762306a36Sopenharmony_cistruct ef4_msi_context { 45862306a36Sopenharmony_ci struct ef4_nic *efx; 45962306a36Sopenharmony_ci unsigned int index; 46062306a36Sopenharmony_ci char name[IFNAMSIZ + 6]; 46162306a36Sopenharmony_ci}; 46262306a36Sopenharmony_ci 46362306a36Sopenharmony_ci/** 46462306a36Sopenharmony_ci * struct ef4_channel_type - distinguishes traffic and extra channels 46562306a36Sopenharmony_ci * @handle_no_channel: Handle failure to allocate an extra channel 46662306a36Sopenharmony_ci * @pre_probe: Set up extra state prior to initialisation 46762306a36Sopenharmony_ci * @post_remove: Tear down extra state after finalisation, if allocated. 46862306a36Sopenharmony_ci * May be called on channels that have not been probed. 46962306a36Sopenharmony_ci * @get_name: Generate the channel's name (used for its IRQ handler) 47062306a36Sopenharmony_ci * @copy: Copy the channel state prior to reallocation. May be %NULL if 47162306a36Sopenharmony_ci * reallocation is not supported. 47262306a36Sopenharmony_ci * @receive_skb: Handle an skb ready to be passed to netif_receive_skb() 47362306a36Sopenharmony_ci * @keep_eventq: Flag for whether event queue should be kept initialised 47462306a36Sopenharmony_ci * while the device is stopped 47562306a36Sopenharmony_ci */ 47662306a36Sopenharmony_cistruct ef4_channel_type { 47762306a36Sopenharmony_ci void (*handle_no_channel)(struct ef4_nic *); 47862306a36Sopenharmony_ci int (*pre_probe)(struct ef4_channel *); 47962306a36Sopenharmony_ci void (*post_remove)(struct ef4_channel *); 48062306a36Sopenharmony_ci void (*get_name)(struct ef4_channel *, char *buf, size_t len); 48162306a36Sopenharmony_ci struct ef4_channel *(*copy)(const struct ef4_channel *); 48262306a36Sopenharmony_ci bool (*receive_skb)(struct ef4_channel *, struct sk_buff *); 48362306a36Sopenharmony_ci bool keep_eventq; 48462306a36Sopenharmony_ci}; 48562306a36Sopenharmony_ci 48662306a36Sopenharmony_cienum ef4_led_mode { 48762306a36Sopenharmony_ci EF4_LED_OFF = 0, 48862306a36Sopenharmony_ci EF4_LED_ON = 1, 48962306a36Sopenharmony_ci EF4_LED_DEFAULT = 2 49062306a36Sopenharmony_ci}; 49162306a36Sopenharmony_ci 49262306a36Sopenharmony_ci#define STRING_TABLE_LOOKUP(val, member) \ 49362306a36Sopenharmony_ci ((val) < member ## _max) ? member ## _names[val] : "(invalid)" 49462306a36Sopenharmony_ci 49562306a36Sopenharmony_ciextern const char *const ef4_loopback_mode_names[]; 49662306a36Sopenharmony_ciextern const unsigned int ef4_loopback_mode_max; 49762306a36Sopenharmony_ci#define LOOPBACK_MODE(efx) \ 49862306a36Sopenharmony_ci STRING_TABLE_LOOKUP((efx)->loopback_mode, ef4_loopback_mode) 49962306a36Sopenharmony_ci 50062306a36Sopenharmony_ciextern const char *const ef4_reset_type_names[]; 50162306a36Sopenharmony_ciextern const unsigned int ef4_reset_type_max; 50262306a36Sopenharmony_ci#define RESET_TYPE(type) \ 50362306a36Sopenharmony_ci STRING_TABLE_LOOKUP(type, ef4_reset_type) 50462306a36Sopenharmony_ci 50562306a36Sopenharmony_cienum ef4_int_mode { 50662306a36Sopenharmony_ci /* Be careful if altering to correct macro below */ 50762306a36Sopenharmony_ci EF4_INT_MODE_MSIX = 0, 50862306a36Sopenharmony_ci EF4_INT_MODE_MSI = 1, 50962306a36Sopenharmony_ci EF4_INT_MODE_LEGACY = 2, 51062306a36Sopenharmony_ci EF4_INT_MODE_MAX /* Insert any new items before this */ 51162306a36Sopenharmony_ci}; 51262306a36Sopenharmony_ci#define EF4_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EF4_INT_MODE_MSI) 51362306a36Sopenharmony_ci 51462306a36Sopenharmony_cienum nic_state { 51562306a36Sopenharmony_ci STATE_UNINIT = 0, /* device being probed/removed or is frozen */ 51662306a36Sopenharmony_ci STATE_READY = 1, /* hardware ready and netdev registered */ 51762306a36Sopenharmony_ci STATE_DISABLED = 2, /* device disabled due to hardware errors */ 51862306a36Sopenharmony_ci STATE_RECOVERY = 3, /* device recovering from PCI error */ 51962306a36Sopenharmony_ci}; 52062306a36Sopenharmony_ci 52162306a36Sopenharmony_ci/* Forward declaration */ 52262306a36Sopenharmony_cistruct ef4_nic; 52362306a36Sopenharmony_ci 52462306a36Sopenharmony_ci/* Pseudo bit-mask flow control field */ 52562306a36Sopenharmony_ci#define EF4_FC_RX FLOW_CTRL_RX 52662306a36Sopenharmony_ci#define EF4_FC_TX FLOW_CTRL_TX 52762306a36Sopenharmony_ci#define EF4_FC_AUTO 4 52862306a36Sopenharmony_ci 52962306a36Sopenharmony_ci/** 53062306a36Sopenharmony_ci * struct ef4_link_state - Current state of the link 53162306a36Sopenharmony_ci * @up: Link is up 53262306a36Sopenharmony_ci * @fd: Link is full-duplex 53362306a36Sopenharmony_ci * @fc: Actual flow control flags 53462306a36Sopenharmony_ci * @speed: Link speed (Mbps) 53562306a36Sopenharmony_ci */ 53662306a36Sopenharmony_cistruct ef4_link_state { 53762306a36Sopenharmony_ci bool up; 53862306a36Sopenharmony_ci bool fd; 53962306a36Sopenharmony_ci u8 fc; 54062306a36Sopenharmony_ci unsigned int speed; 54162306a36Sopenharmony_ci}; 54262306a36Sopenharmony_ci 54362306a36Sopenharmony_cistatic inline bool ef4_link_state_equal(const struct ef4_link_state *left, 54462306a36Sopenharmony_ci const struct ef4_link_state *right) 54562306a36Sopenharmony_ci{ 54662306a36Sopenharmony_ci return left->up == right->up && left->fd == right->fd && 54762306a36Sopenharmony_ci left->fc == right->fc && left->speed == right->speed; 54862306a36Sopenharmony_ci} 54962306a36Sopenharmony_ci 55062306a36Sopenharmony_ci/** 55162306a36Sopenharmony_ci * struct ef4_phy_operations - Efx PHY operations table 55262306a36Sopenharmony_ci * @probe: Probe PHY and initialise efx->mdio.mode_support, efx->mdio.mmds, 55362306a36Sopenharmony_ci * efx->loopback_modes. 55462306a36Sopenharmony_ci * @init: Initialise PHY 55562306a36Sopenharmony_ci * @fini: Shut down PHY 55662306a36Sopenharmony_ci * @reconfigure: Reconfigure PHY (e.g. for new link parameters) 55762306a36Sopenharmony_ci * @poll: Update @link_state and report whether it changed. 55862306a36Sopenharmony_ci * Serialised by the mac_lock. 55962306a36Sopenharmony_ci * @get_link_ksettings: Get ethtool settings. Serialised by the mac_lock. 56062306a36Sopenharmony_ci * @set_link_ksettings: Set ethtool settings. Serialised by the mac_lock. 56162306a36Sopenharmony_ci * @set_npage_adv: Set abilities advertised in (Extended) Next Page 56262306a36Sopenharmony_ci * (only needed where AN bit is set in mmds) 56362306a36Sopenharmony_ci * @test_alive: Test that PHY is 'alive' (online) 56462306a36Sopenharmony_ci * @test_name: Get the name of a PHY-specific test/result 56562306a36Sopenharmony_ci * @run_tests: Run tests and record results as appropriate (offline). 56662306a36Sopenharmony_ci * Flags are the ethtool tests flags. 56762306a36Sopenharmony_ci */ 56862306a36Sopenharmony_cistruct ef4_phy_operations { 56962306a36Sopenharmony_ci int (*probe) (struct ef4_nic *efx); 57062306a36Sopenharmony_ci int (*init) (struct ef4_nic *efx); 57162306a36Sopenharmony_ci void (*fini) (struct ef4_nic *efx); 57262306a36Sopenharmony_ci void (*remove) (struct ef4_nic *efx); 57362306a36Sopenharmony_ci int (*reconfigure) (struct ef4_nic *efx); 57462306a36Sopenharmony_ci bool (*poll) (struct ef4_nic *efx); 57562306a36Sopenharmony_ci void (*get_link_ksettings)(struct ef4_nic *efx, 57662306a36Sopenharmony_ci struct ethtool_link_ksettings *cmd); 57762306a36Sopenharmony_ci int (*set_link_ksettings)(struct ef4_nic *efx, 57862306a36Sopenharmony_ci const struct ethtool_link_ksettings *cmd); 57962306a36Sopenharmony_ci void (*set_npage_adv) (struct ef4_nic *efx, u32); 58062306a36Sopenharmony_ci int (*test_alive) (struct ef4_nic *efx); 58162306a36Sopenharmony_ci const char *(*test_name) (struct ef4_nic *efx, unsigned int index); 58262306a36Sopenharmony_ci int (*run_tests) (struct ef4_nic *efx, int *results, unsigned flags); 58362306a36Sopenharmony_ci int (*get_module_eeprom) (struct ef4_nic *efx, 58462306a36Sopenharmony_ci struct ethtool_eeprom *ee, 58562306a36Sopenharmony_ci u8 *data); 58662306a36Sopenharmony_ci int (*get_module_info) (struct ef4_nic *efx, 58762306a36Sopenharmony_ci struct ethtool_modinfo *modinfo); 58862306a36Sopenharmony_ci}; 58962306a36Sopenharmony_ci 59062306a36Sopenharmony_ci/** 59162306a36Sopenharmony_ci * enum ef4_phy_mode - PHY operating mode flags 59262306a36Sopenharmony_ci * @PHY_MODE_NORMAL: on and should pass traffic 59362306a36Sopenharmony_ci * @PHY_MODE_TX_DISABLED: on with TX disabled 59462306a36Sopenharmony_ci * @PHY_MODE_LOW_POWER: set to low power through MDIO 59562306a36Sopenharmony_ci * @PHY_MODE_OFF: switched off through external control 59662306a36Sopenharmony_ci * @PHY_MODE_SPECIAL: on but will not pass traffic 59762306a36Sopenharmony_ci */ 59862306a36Sopenharmony_cienum ef4_phy_mode { 59962306a36Sopenharmony_ci PHY_MODE_NORMAL = 0, 60062306a36Sopenharmony_ci PHY_MODE_TX_DISABLED = 1, 60162306a36Sopenharmony_ci PHY_MODE_LOW_POWER = 2, 60262306a36Sopenharmony_ci PHY_MODE_OFF = 4, 60362306a36Sopenharmony_ci PHY_MODE_SPECIAL = 8, 60462306a36Sopenharmony_ci}; 60562306a36Sopenharmony_ci 60662306a36Sopenharmony_cistatic inline bool ef4_phy_mode_disabled(enum ef4_phy_mode mode) 60762306a36Sopenharmony_ci{ 60862306a36Sopenharmony_ci return !!(mode & ~PHY_MODE_TX_DISABLED); 60962306a36Sopenharmony_ci} 61062306a36Sopenharmony_ci 61162306a36Sopenharmony_ci/** 61262306a36Sopenharmony_ci * struct ef4_hw_stat_desc - Description of a hardware statistic 61362306a36Sopenharmony_ci * @name: Name of the statistic as visible through ethtool, or %NULL if 61462306a36Sopenharmony_ci * it should not be exposed 61562306a36Sopenharmony_ci * @dma_width: Width in bits (0 for non-DMA statistics) 61662306a36Sopenharmony_ci * @offset: Offset within stats (ignored for non-DMA statistics) 61762306a36Sopenharmony_ci */ 61862306a36Sopenharmony_cistruct ef4_hw_stat_desc { 61962306a36Sopenharmony_ci const char *name; 62062306a36Sopenharmony_ci u16 dma_width; 62162306a36Sopenharmony_ci u16 offset; 62262306a36Sopenharmony_ci}; 62362306a36Sopenharmony_ci 62462306a36Sopenharmony_ci/* Number of bits used in a multicast filter hash address */ 62562306a36Sopenharmony_ci#define EF4_MCAST_HASH_BITS 8 62662306a36Sopenharmony_ci 62762306a36Sopenharmony_ci/* Number of (single-bit) entries in a multicast filter hash */ 62862306a36Sopenharmony_ci#define EF4_MCAST_HASH_ENTRIES (1 << EF4_MCAST_HASH_BITS) 62962306a36Sopenharmony_ci 63062306a36Sopenharmony_ci/* An Efx multicast filter hash */ 63162306a36Sopenharmony_ciunion ef4_multicast_hash { 63262306a36Sopenharmony_ci u8 byte[EF4_MCAST_HASH_ENTRIES / 8]; 63362306a36Sopenharmony_ci ef4_oword_t oword[EF4_MCAST_HASH_ENTRIES / sizeof(ef4_oword_t) / 8]; 63462306a36Sopenharmony_ci}; 63562306a36Sopenharmony_ci 63662306a36Sopenharmony_ci/** 63762306a36Sopenharmony_ci * struct ef4_nic - an Efx NIC 63862306a36Sopenharmony_ci * @name: Device name (net device name or bus id before net device registered) 63962306a36Sopenharmony_ci * @pci_dev: The PCI device 64062306a36Sopenharmony_ci * @node: List node for maintaining primary/secondary function lists 64162306a36Sopenharmony_ci * @primary: &struct ef4_nic instance for the primary function of this 64262306a36Sopenharmony_ci * controller. May be the same structure, and may be %NULL if no 64362306a36Sopenharmony_ci * primary function is bound. Serialised by rtnl_lock. 64462306a36Sopenharmony_ci * @secondary_list: List of &struct ef4_nic instances for the secondary PCI 64562306a36Sopenharmony_ci * functions of the controller, if this is for the primary function. 64662306a36Sopenharmony_ci * Serialised by rtnl_lock. 64762306a36Sopenharmony_ci * @type: Controller type attributes 64862306a36Sopenharmony_ci * @legacy_irq: IRQ number 64962306a36Sopenharmony_ci * @workqueue: Workqueue for port reconfigures and the HW monitor. 65062306a36Sopenharmony_ci * Work items do not hold and must not acquire RTNL. 65162306a36Sopenharmony_ci * @workqueue_name: Name of workqueue 65262306a36Sopenharmony_ci * @reset_work: Scheduled reset workitem 65362306a36Sopenharmony_ci * @membase_phys: Memory BAR value as physical address 65462306a36Sopenharmony_ci * @membase: Memory BAR value 65562306a36Sopenharmony_ci * @interrupt_mode: Interrupt mode 65662306a36Sopenharmony_ci * @timer_quantum_ns: Interrupt timer quantum, in nanoseconds 65762306a36Sopenharmony_ci * @timer_max_ns: Interrupt timer maximum value, in nanoseconds 65862306a36Sopenharmony_ci * @irq_rx_adaptive: Adaptive IRQ moderation enabled for RX event queues 65962306a36Sopenharmony_ci * @irq_rx_mod_step_us: Step size for IRQ moderation for RX event queues 66062306a36Sopenharmony_ci * @irq_rx_moderation_us: IRQ moderation time for RX event queues 66162306a36Sopenharmony_ci * @msg_enable: Log message enable flags 66262306a36Sopenharmony_ci * @state: Device state number (%STATE_*). Serialised by the rtnl_lock. 66362306a36Sopenharmony_ci * @reset_pending: Bitmask for pending resets 66462306a36Sopenharmony_ci * @tx_queue: TX DMA queues 66562306a36Sopenharmony_ci * @rx_queue: RX DMA queues 66662306a36Sopenharmony_ci * @channel: Channels 66762306a36Sopenharmony_ci * @msi_context: Context for each MSI 66862306a36Sopenharmony_ci * @extra_channel_types: Types of extra (non-traffic) channels that 66962306a36Sopenharmony_ci * should be allocated for this NIC 67062306a36Sopenharmony_ci * @rxq_entries: Size of receive queues requested by user. 67162306a36Sopenharmony_ci * @txq_entries: Size of transmit queues requested by user. 67262306a36Sopenharmony_ci * @txq_stop_thresh: TX queue fill level at or above which we stop it. 67362306a36Sopenharmony_ci * @txq_wake_thresh: TX queue fill level at or below which we wake it. 67462306a36Sopenharmony_ci * @tx_dc_base: Base qword address in SRAM of TX queue descriptor caches 67562306a36Sopenharmony_ci * @rx_dc_base: Base qword address in SRAM of RX queue descriptor caches 67662306a36Sopenharmony_ci * @sram_lim_qw: Qword address limit of SRAM 67762306a36Sopenharmony_ci * @next_buffer_table: First available buffer table id 67862306a36Sopenharmony_ci * @n_channels: Number of channels in use 67962306a36Sopenharmony_ci * @n_rx_channels: Number of channels used for RX (= number of RX queues) 68062306a36Sopenharmony_ci * @n_tx_channels: Number of channels used for TX 68162306a36Sopenharmony_ci * @rx_ip_align: RX DMA address offset to have IP header aligned in 68262306a36Sopenharmony_ci * accordance with NET_IP_ALIGN 68362306a36Sopenharmony_ci * @rx_dma_len: Current maximum RX DMA length 68462306a36Sopenharmony_ci * @rx_buffer_order: Order (log2) of number of pages for each RX buffer 68562306a36Sopenharmony_ci * @rx_buffer_truesize: Amortised allocation size of an RX buffer, 68662306a36Sopenharmony_ci * for use in sk_buff::truesize 68762306a36Sopenharmony_ci * @rx_prefix_size: Size of RX prefix before packet data 68862306a36Sopenharmony_ci * @rx_packet_hash_offset: Offset of RX flow hash from start of packet data 68962306a36Sopenharmony_ci * (valid only if @rx_prefix_size != 0; always negative) 69062306a36Sopenharmony_ci * @rx_packet_len_offset: Offset of RX packet length from start of packet data 69162306a36Sopenharmony_ci * (valid only for NICs that set %EF4_RX_PKT_PREFIX_LEN; always negative) 69262306a36Sopenharmony_ci * @rx_packet_ts_offset: Offset of timestamp from start of packet data 69362306a36Sopenharmony_ci * (valid only if channel->sync_timestamps_enabled; always negative) 69462306a36Sopenharmony_ci * @rx_hash_key: Toeplitz hash key for RSS 69562306a36Sopenharmony_ci * @rx_indir_table: Indirection table for RSS 69662306a36Sopenharmony_ci * @rx_scatter: Scatter mode enabled for receives 69762306a36Sopenharmony_ci * @int_error_count: Number of internal errors seen recently 69862306a36Sopenharmony_ci * @int_error_expire: Time at which error count will be expired 69962306a36Sopenharmony_ci * @irq_soft_enabled: Are IRQs soft-enabled? If not, IRQ handler will 70062306a36Sopenharmony_ci * acknowledge but do nothing else. 70162306a36Sopenharmony_ci * @irq_status: Interrupt status buffer 70262306a36Sopenharmony_ci * @irq_zero_count: Number of legacy IRQs seen with queue flags == 0 70362306a36Sopenharmony_ci * @irq_level: IRQ level/index for IRQs not triggered by an event queue 70462306a36Sopenharmony_ci * @selftest_work: Work item for asynchronous self-test 70562306a36Sopenharmony_ci * @mtd_list: List of MTDs attached to the NIC 70662306a36Sopenharmony_ci * @nic_data: Hardware dependent state 70762306a36Sopenharmony_ci * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode, 70862306a36Sopenharmony_ci * ef4_monitor() and ef4_reconfigure_port() 70962306a36Sopenharmony_ci * @port_enabled: Port enabled indicator. 71062306a36Sopenharmony_ci * Serialises ef4_stop_all(), ef4_start_all(), ef4_monitor() and 71162306a36Sopenharmony_ci * ef4_mac_work() with kernel interfaces. Safe to read under any 71262306a36Sopenharmony_ci * one of the rtnl_lock, mac_lock, or netif_tx_lock, but all three must 71362306a36Sopenharmony_ci * be held to modify it. 71462306a36Sopenharmony_ci * @port_initialized: Port initialized? 71562306a36Sopenharmony_ci * @net_dev: Operating system network device. Consider holding the rtnl lock 71662306a36Sopenharmony_ci * @fixed_features: Features which cannot be turned off 71762306a36Sopenharmony_ci * @stats_buffer: DMA buffer for statistics 71862306a36Sopenharmony_ci * @phy_type: PHY type 71962306a36Sopenharmony_ci * @phy_op: PHY interface 72062306a36Sopenharmony_ci * @phy_data: PHY private data (including PHY-specific stats) 72162306a36Sopenharmony_ci * @mdio: PHY MDIO interface 72262306a36Sopenharmony_ci * @phy_mode: PHY operating mode. Serialised by @mac_lock. 72362306a36Sopenharmony_ci * @link_advertising: Autonegotiation advertising flags 72462306a36Sopenharmony_ci * @link_state: Current state of the link 72562306a36Sopenharmony_ci * @n_link_state_changes: Number of times the link has changed state 72662306a36Sopenharmony_ci * @unicast_filter: Flag for Falcon-arch simple unicast filter. 72762306a36Sopenharmony_ci * Protected by @mac_lock. 72862306a36Sopenharmony_ci * @multicast_hash: Multicast hash table for Falcon-arch. 72962306a36Sopenharmony_ci * Protected by @mac_lock. 73062306a36Sopenharmony_ci * @wanted_fc: Wanted flow control flags 73162306a36Sopenharmony_ci * @fc_disable: When non-zero flow control is disabled. Typically used to 73262306a36Sopenharmony_ci * ensure that network back pressure doesn't delay dma queue flushes. 73362306a36Sopenharmony_ci * Serialised by the rtnl lock. 73462306a36Sopenharmony_ci * @mac_work: Work item for changing MAC promiscuity and multicast hash 73562306a36Sopenharmony_ci * @loopback_mode: Loopback status 73662306a36Sopenharmony_ci * @loopback_modes: Supported loopback mode bitmask 73762306a36Sopenharmony_ci * @loopback_selftest: Offline self-test private state 73862306a36Sopenharmony_ci * @filter_sem: Filter table rw_semaphore, for freeing the table 73962306a36Sopenharmony_ci * @filter_lock: Filter table lock, for mere content changes 74062306a36Sopenharmony_ci * @filter_state: Architecture-dependent filter table state 74162306a36Sopenharmony_ci * @rps_expire_channel: Next channel to check for expiry 74262306a36Sopenharmony_ci * @rps_expire_index: Next index to check for expiry in 74362306a36Sopenharmony_ci * @rps_expire_channel's @rps_flow_id 74462306a36Sopenharmony_ci * @active_queues: Count of RX and TX queues that haven't been flushed and drained. 74562306a36Sopenharmony_ci * @rxq_flush_pending: Count of number of receive queues that need to be flushed. 74662306a36Sopenharmony_ci * Decremented when the ef4_flush_rx_queue() is called. 74762306a36Sopenharmony_ci * @rxq_flush_outstanding: Count of number of RX flushes started but not yet 74862306a36Sopenharmony_ci * completed (either success or failure). Not used when MCDI is used to 74962306a36Sopenharmony_ci * flush receive queues. 75062306a36Sopenharmony_ci * @flush_wq: wait queue used by ef4_nic_flush_queues() to wait for flush completions. 75162306a36Sopenharmony_ci * @vpd_sn: Serial number read from VPD 75262306a36Sopenharmony_ci * @monitor_work: Hardware monitor workitem 75362306a36Sopenharmony_ci * @biu_lock: BIU (bus interface unit) lock 75462306a36Sopenharmony_ci * @last_irq_cpu: Last CPU to handle a possible test interrupt. This 75562306a36Sopenharmony_ci * field is used by ef4_test_interrupts() to verify that an 75662306a36Sopenharmony_ci * interrupt has occurred. 75762306a36Sopenharmony_ci * @stats_lock: Statistics update lock. Must be held when calling 75862306a36Sopenharmony_ci * ef4_nic_type::{update,start,stop}_stats. 75962306a36Sopenharmony_ci * @n_rx_noskb_drops: Count of RX packets dropped due to failure to allocate an skb 76062306a36Sopenharmony_ci * 76162306a36Sopenharmony_ci * This is stored in the private area of the &struct net_device. 76262306a36Sopenharmony_ci */ 76362306a36Sopenharmony_cistruct ef4_nic { 76462306a36Sopenharmony_ci /* The following fields should be written very rarely */ 76562306a36Sopenharmony_ci 76662306a36Sopenharmony_ci char name[IFNAMSIZ]; 76762306a36Sopenharmony_ci struct list_head node; 76862306a36Sopenharmony_ci struct ef4_nic *primary; 76962306a36Sopenharmony_ci struct list_head secondary_list; 77062306a36Sopenharmony_ci struct pci_dev *pci_dev; 77162306a36Sopenharmony_ci unsigned int port_num; 77262306a36Sopenharmony_ci const struct ef4_nic_type *type; 77362306a36Sopenharmony_ci int legacy_irq; 77462306a36Sopenharmony_ci bool eeh_disabled_legacy_irq; 77562306a36Sopenharmony_ci struct workqueue_struct *workqueue; 77662306a36Sopenharmony_ci char workqueue_name[16]; 77762306a36Sopenharmony_ci struct work_struct reset_work; 77862306a36Sopenharmony_ci resource_size_t membase_phys; 77962306a36Sopenharmony_ci void __iomem *membase; 78062306a36Sopenharmony_ci 78162306a36Sopenharmony_ci enum ef4_int_mode interrupt_mode; 78262306a36Sopenharmony_ci unsigned int timer_quantum_ns; 78362306a36Sopenharmony_ci unsigned int timer_max_ns; 78462306a36Sopenharmony_ci bool irq_rx_adaptive; 78562306a36Sopenharmony_ci unsigned int irq_mod_step_us; 78662306a36Sopenharmony_ci unsigned int irq_rx_moderation_us; 78762306a36Sopenharmony_ci u32 msg_enable; 78862306a36Sopenharmony_ci 78962306a36Sopenharmony_ci enum nic_state state; 79062306a36Sopenharmony_ci unsigned long reset_pending; 79162306a36Sopenharmony_ci 79262306a36Sopenharmony_ci struct ef4_channel *channel[EF4_MAX_CHANNELS]; 79362306a36Sopenharmony_ci struct ef4_msi_context msi_context[EF4_MAX_CHANNELS]; 79462306a36Sopenharmony_ci const struct ef4_channel_type * 79562306a36Sopenharmony_ci extra_channel_type[EF4_MAX_EXTRA_CHANNELS]; 79662306a36Sopenharmony_ci 79762306a36Sopenharmony_ci unsigned rxq_entries; 79862306a36Sopenharmony_ci unsigned txq_entries; 79962306a36Sopenharmony_ci unsigned int txq_stop_thresh; 80062306a36Sopenharmony_ci unsigned int txq_wake_thresh; 80162306a36Sopenharmony_ci 80262306a36Sopenharmony_ci unsigned tx_dc_base; 80362306a36Sopenharmony_ci unsigned rx_dc_base; 80462306a36Sopenharmony_ci unsigned sram_lim_qw; 80562306a36Sopenharmony_ci unsigned next_buffer_table; 80662306a36Sopenharmony_ci 80762306a36Sopenharmony_ci unsigned int max_channels; 80862306a36Sopenharmony_ci unsigned int max_tx_channels; 80962306a36Sopenharmony_ci unsigned n_channels; 81062306a36Sopenharmony_ci unsigned n_rx_channels; 81162306a36Sopenharmony_ci unsigned rss_spread; 81262306a36Sopenharmony_ci unsigned tx_channel_offset; 81362306a36Sopenharmony_ci unsigned n_tx_channels; 81462306a36Sopenharmony_ci unsigned int rx_ip_align; 81562306a36Sopenharmony_ci unsigned int rx_dma_len; 81662306a36Sopenharmony_ci unsigned int rx_buffer_order; 81762306a36Sopenharmony_ci unsigned int rx_buffer_truesize; 81862306a36Sopenharmony_ci unsigned int rx_page_buf_step; 81962306a36Sopenharmony_ci unsigned int rx_bufs_per_page; 82062306a36Sopenharmony_ci unsigned int rx_pages_per_batch; 82162306a36Sopenharmony_ci unsigned int rx_prefix_size; 82262306a36Sopenharmony_ci int rx_packet_hash_offset; 82362306a36Sopenharmony_ci int rx_packet_len_offset; 82462306a36Sopenharmony_ci int rx_packet_ts_offset; 82562306a36Sopenharmony_ci u8 rx_hash_key[40]; 82662306a36Sopenharmony_ci u32 rx_indir_table[128]; 82762306a36Sopenharmony_ci bool rx_scatter; 82862306a36Sopenharmony_ci 82962306a36Sopenharmony_ci unsigned int_error_count; 83062306a36Sopenharmony_ci unsigned long int_error_expire; 83162306a36Sopenharmony_ci 83262306a36Sopenharmony_ci bool irq_soft_enabled; 83362306a36Sopenharmony_ci struct ef4_buffer irq_status; 83462306a36Sopenharmony_ci unsigned irq_zero_count; 83562306a36Sopenharmony_ci unsigned irq_level; 83662306a36Sopenharmony_ci struct delayed_work selftest_work; 83762306a36Sopenharmony_ci 83862306a36Sopenharmony_ci#ifdef CONFIG_SFC_FALCON_MTD 83962306a36Sopenharmony_ci struct list_head mtd_list; 84062306a36Sopenharmony_ci#endif 84162306a36Sopenharmony_ci 84262306a36Sopenharmony_ci void *nic_data; 84362306a36Sopenharmony_ci 84462306a36Sopenharmony_ci struct mutex mac_lock; 84562306a36Sopenharmony_ci struct work_struct mac_work; 84662306a36Sopenharmony_ci bool port_enabled; 84762306a36Sopenharmony_ci 84862306a36Sopenharmony_ci bool mc_bist_for_other_fn; 84962306a36Sopenharmony_ci bool port_initialized; 85062306a36Sopenharmony_ci struct net_device *net_dev; 85162306a36Sopenharmony_ci 85262306a36Sopenharmony_ci netdev_features_t fixed_features; 85362306a36Sopenharmony_ci 85462306a36Sopenharmony_ci struct ef4_buffer stats_buffer; 85562306a36Sopenharmony_ci u64 rx_nodesc_drops_total; 85662306a36Sopenharmony_ci u64 rx_nodesc_drops_while_down; 85762306a36Sopenharmony_ci bool rx_nodesc_drops_prev_state; 85862306a36Sopenharmony_ci 85962306a36Sopenharmony_ci unsigned int phy_type; 86062306a36Sopenharmony_ci const struct ef4_phy_operations *phy_op; 86162306a36Sopenharmony_ci void *phy_data; 86262306a36Sopenharmony_ci struct mdio_if_info mdio; 86362306a36Sopenharmony_ci enum ef4_phy_mode phy_mode; 86462306a36Sopenharmony_ci 86562306a36Sopenharmony_ci u32 link_advertising; 86662306a36Sopenharmony_ci struct ef4_link_state link_state; 86762306a36Sopenharmony_ci unsigned int n_link_state_changes; 86862306a36Sopenharmony_ci 86962306a36Sopenharmony_ci bool unicast_filter; 87062306a36Sopenharmony_ci union ef4_multicast_hash multicast_hash; 87162306a36Sopenharmony_ci u8 wanted_fc; 87262306a36Sopenharmony_ci unsigned fc_disable; 87362306a36Sopenharmony_ci 87462306a36Sopenharmony_ci atomic_t rx_reset; 87562306a36Sopenharmony_ci enum ef4_loopback_mode loopback_mode; 87662306a36Sopenharmony_ci u64 loopback_modes; 87762306a36Sopenharmony_ci 87862306a36Sopenharmony_ci void *loopback_selftest; 87962306a36Sopenharmony_ci 88062306a36Sopenharmony_ci struct rw_semaphore filter_sem; 88162306a36Sopenharmony_ci spinlock_t filter_lock; 88262306a36Sopenharmony_ci void *filter_state; 88362306a36Sopenharmony_ci#ifdef CONFIG_RFS_ACCEL 88462306a36Sopenharmony_ci unsigned int rps_expire_channel; 88562306a36Sopenharmony_ci unsigned int rps_expire_index; 88662306a36Sopenharmony_ci#endif 88762306a36Sopenharmony_ci 88862306a36Sopenharmony_ci atomic_t active_queues; 88962306a36Sopenharmony_ci atomic_t rxq_flush_pending; 89062306a36Sopenharmony_ci atomic_t rxq_flush_outstanding; 89162306a36Sopenharmony_ci wait_queue_head_t flush_wq; 89262306a36Sopenharmony_ci 89362306a36Sopenharmony_ci char *vpd_sn; 89462306a36Sopenharmony_ci 89562306a36Sopenharmony_ci /* The following fields may be written more often */ 89662306a36Sopenharmony_ci 89762306a36Sopenharmony_ci struct delayed_work monitor_work ____cacheline_aligned_in_smp; 89862306a36Sopenharmony_ci spinlock_t biu_lock; 89962306a36Sopenharmony_ci int last_irq_cpu; 90062306a36Sopenharmony_ci spinlock_t stats_lock; 90162306a36Sopenharmony_ci atomic_t n_rx_noskb_drops; 90262306a36Sopenharmony_ci}; 90362306a36Sopenharmony_ci 90462306a36Sopenharmony_cistatic inline int ef4_dev_registered(struct ef4_nic *efx) 90562306a36Sopenharmony_ci{ 90662306a36Sopenharmony_ci return efx->net_dev->reg_state == NETREG_REGISTERED; 90762306a36Sopenharmony_ci} 90862306a36Sopenharmony_ci 90962306a36Sopenharmony_cistatic inline unsigned int ef4_port_num(struct ef4_nic *efx) 91062306a36Sopenharmony_ci{ 91162306a36Sopenharmony_ci return efx->port_num; 91262306a36Sopenharmony_ci} 91362306a36Sopenharmony_ci 91462306a36Sopenharmony_cistruct ef4_mtd_partition { 91562306a36Sopenharmony_ci struct list_head node; 91662306a36Sopenharmony_ci struct mtd_info mtd; 91762306a36Sopenharmony_ci const char *dev_type_name; 91862306a36Sopenharmony_ci const char *type_name; 91962306a36Sopenharmony_ci char name[IFNAMSIZ + 20]; 92062306a36Sopenharmony_ci}; 92162306a36Sopenharmony_ci 92262306a36Sopenharmony_ci/** 92362306a36Sopenharmony_ci * struct ef4_nic_type - Efx device type definition 92462306a36Sopenharmony_ci * @mem_bar: Get the memory BAR 92562306a36Sopenharmony_ci * @mem_map_size: Get memory BAR mapped size 92662306a36Sopenharmony_ci * @probe: Probe the controller 92762306a36Sopenharmony_ci * @remove: Free resources allocated by probe() 92862306a36Sopenharmony_ci * @init: Initialise the controller 92962306a36Sopenharmony_ci * @dimension_resources: Dimension controller resources (buffer table, 93062306a36Sopenharmony_ci * and VIs once the available interrupt resources are clear) 93162306a36Sopenharmony_ci * @fini: Shut down the controller 93262306a36Sopenharmony_ci * @monitor: Periodic function for polling link state and hardware monitor 93362306a36Sopenharmony_ci * @map_reset_reason: Map ethtool reset reason to a reset method 93462306a36Sopenharmony_ci * @map_reset_flags: Map ethtool reset flags to a reset method, if possible 93562306a36Sopenharmony_ci * @reset: Reset the controller hardware and possibly the PHY. This will 93662306a36Sopenharmony_ci * be called while the controller is uninitialised. 93762306a36Sopenharmony_ci * @probe_port: Probe the MAC and PHY 93862306a36Sopenharmony_ci * @remove_port: Free resources allocated by probe_port() 93962306a36Sopenharmony_ci * @handle_global_event: Handle a "global" event (may be %NULL) 94062306a36Sopenharmony_ci * @fini_dmaq: Flush and finalise DMA queues (RX and TX queues) 94162306a36Sopenharmony_ci * @prepare_flush: Prepare the hardware for flushing the DMA queues 94262306a36Sopenharmony_ci * (for Falcon architecture) 94362306a36Sopenharmony_ci * @finish_flush: Clean up after flushing the DMA queues (for Falcon 94462306a36Sopenharmony_ci * architecture) 94562306a36Sopenharmony_ci * @prepare_flr: Prepare for an FLR 94662306a36Sopenharmony_ci * @finish_flr: Clean up after an FLR 94762306a36Sopenharmony_ci * @describe_stats: Describe statistics for ethtool 94862306a36Sopenharmony_ci * @update_stats: Update statistics not provided by event handling. 94962306a36Sopenharmony_ci * Either argument may be %NULL. 95062306a36Sopenharmony_ci * @start_stats: Start the regular fetching of statistics 95162306a36Sopenharmony_ci * @pull_stats: Pull stats from the NIC and wait until they arrive. 95262306a36Sopenharmony_ci * @stop_stats: Stop the regular fetching of statistics 95362306a36Sopenharmony_ci * @set_id_led: Set state of identifying LED or revert to automatic function 95462306a36Sopenharmony_ci * @push_irq_moderation: Apply interrupt moderation value 95562306a36Sopenharmony_ci * @reconfigure_port: Push loopback/power/txdis changes to the MAC and PHY 95662306a36Sopenharmony_ci * @prepare_enable_fc_tx: Prepare MAC to enable pause frame TX (may be %NULL) 95762306a36Sopenharmony_ci * @reconfigure_mac: Push MAC address, MTU, flow control and filter settings 95862306a36Sopenharmony_ci * to the hardware. Serialised by the mac_lock. 95962306a36Sopenharmony_ci * @check_mac_fault: Check MAC fault state. True if fault present. 96062306a36Sopenharmony_ci * @get_wol: Get WoL configuration from driver state 96162306a36Sopenharmony_ci * @set_wol: Push WoL configuration to the NIC 96262306a36Sopenharmony_ci * @resume_wol: Synchronise WoL state between driver and MC (e.g. after resume) 96362306a36Sopenharmony_ci * @test_chip: Test registers. May use ef4_farch_test_registers(), and is 96462306a36Sopenharmony_ci * expected to reset the NIC. 96562306a36Sopenharmony_ci * @test_nvram: Test validity of NVRAM contents 96662306a36Sopenharmony_ci * @irq_enable_master: Enable IRQs on the NIC. Each event queue must 96762306a36Sopenharmony_ci * be separately enabled after this. 96862306a36Sopenharmony_ci * @irq_test_generate: Generate a test IRQ 96962306a36Sopenharmony_ci * @irq_disable_non_ev: Disable non-event IRQs on the NIC. Each event 97062306a36Sopenharmony_ci * queue must be separately disabled before this. 97162306a36Sopenharmony_ci * @irq_handle_msi: Handle MSI for a channel. The @dev_id argument is 97262306a36Sopenharmony_ci * a pointer to the &struct ef4_msi_context for the channel. 97362306a36Sopenharmony_ci * @irq_handle_legacy: Handle legacy interrupt. The @dev_id argument 97462306a36Sopenharmony_ci * is a pointer to the &struct ef4_nic. 97562306a36Sopenharmony_ci * @tx_probe: Allocate resources for TX queue 97662306a36Sopenharmony_ci * @tx_init: Initialise TX queue on the NIC 97762306a36Sopenharmony_ci * @tx_remove: Free resources for TX queue 97862306a36Sopenharmony_ci * @tx_write: Write TX descriptors and doorbell 97962306a36Sopenharmony_ci * @rx_push_rss_config: Write RSS hash key and indirection table to the NIC 98062306a36Sopenharmony_ci * @rx_probe: Allocate resources for RX queue 98162306a36Sopenharmony_ci * @rx_init: Initialise RX queue on the NIC 98262306a36Sopenharmony_ci * @rx_remove: Free resources for RX queue 98362306a36Sopenharmony_ci * @rx_write: Write RX descriptors and doorbell 98462306a36Sopenharmony_ci * @rx_defer_refill: Generate a refill reminder event 98562306a36Sopenharmony_ci * @ev_probe: Allocate resources for event queue 98662306a36Sopenharmony_ci * @ev_init: Initialise event queue on the NIC 98762306a36Sopenharmony_ci * @ev_fini: Deinitialise event queue on the NIC 98862306a36Sopenharmony_ci * @ev_remove: Free resources for event queue 98962306a36Sopenharmony_ci * @ev_process: Process events for a queue, up to the given NAPI quota 99062306a36Sopenharmony_ci * @ev_read_ack: Acknowledge read events on a queue, rearming its IRQ 99162306a36Sopenharmony_ci * @ev_test_generate: Generate a test event 99262306a36Sopenharmony_ci * @filter_table_probe: Probe filter capabilities and set up filter software state 99362306a36Sopenharmony_ci * @filter_table_restore: Restore filters removed from hardware 99462306a36Sopenharmony_ci * @filter_table_remove: Remove filters from hardware and tear down software state 99562306a36Sopenharmony_ci * @filter_update_rx_scatter: Update filters after change to rx scatter setting 99662306a36Sopenharmony_ci * @filter_insert: add or replace a filter 99762306a36Sopenharmony_ci * @filter_remove_safe: remove a filter by ID, carefully 99862306a36Sopenharmony_ci * @filter_get_safe: retrieve a filter by ID, carefully 99962306a36Sopenharmony_ci * @filter_clear_rx: Remove all RX filters whose priority is less than or 100062306a36Sopenharmony_ci * equal to the given priority and is not %EF4_FILTER_PRI_AUTO 100162306a36Sopenharmony_ci * @filter_count_rx_used: Get the number of filters in use at a given priority 100262306a36Sopenharmony_ci * @filter_get_rx_id_limit: Get maximum value of a filter id, plus 1 100362306a36Sopenharmony_ci * @filter_get_rx_ids: Get list of RX filters at a given priority 100462306a36Sopenharmony_ci * @filter_rfs_insert: Add or replace a filter for RFS. This must be 100562306a36Sopenharmony_ci * atomic. The hardware change may be asynchronous but should 100662306a36Sopenharmony_ci * not be delayed for long. It may fail if this can't be done 100762306a36Sopenharmony_ci * atomically. 100862306a36Sopenharmony_ci * @filter_rfs_expire_one: Consider expiring a filter inserted for RFS. 100962306a36Sopenharmony_ci * This must check whether the specified table entry is used by RFS 101062306a36Sopenharmony_ci * and that rps_may_expire_flow() returns true for it. 101162306a36Sopenharmony_ci * @mtd_probe: Probe and add MTD partitions associated with this net device, 101262306a36Sopenharmony_ci * using ef4_mtd_add() 101362306a36Sopenharmony_ci * @mtd_rename: Set an MTD partition name using the net device name 101462306a36Sopenharmony_ci * @mtd_read: Read from an MTD partition 101562306a36Sopenharmony_ci * @mtd_erase: Erase part of an MTD partition 101662306a36Sopenharmony_ci * @mtd_write: Write to an MTD partition 101762306a36Sopenharmony_ci * @mtd_sync: Wait for write-back to complete on MTD partition. This 101862306a36Sopenharmony_ci * also notifies the driver that a writer has finished using this 101962306a36Sopenharmony_ci * partition. 102062306a36Sopenharmony_ci * @set_mac_address: Set the MAC address of the device 102162306a36Sopenharmony_ci * @revision: Hardware architecture revision 102262306a36Sopenharmony_ci * @txd_ptr_tbl_base: TX descriptor ring base address 102362306a36Sopenharmony_ci * @rxd_ptr_tbl_base: RX descriptor ring base address 102462306a36Sopenharmony_ci * @buf_tbl_base: Buffer table base address 102562306a36Sopenharmony_ci * @evq_ptr_tbl_base: Event queue pointer table base address 102662306a36Sopenharmony_ci * @evq_rptr_tbl_base: Event queue read-pointer table base address 102762306a36Sopenharmony_ci * @max_dma_mask: Maximum possible DMA mask 102862306a36Sopenharmony_ci * @rx_prefix_size: Size of RX prefix before packet data 102962306a36Sopenharmony_ci * @rx_hash_offset: Offset of RX flow hash within prefix 103062306a36Sopenharmony_ci * @rx_ts_offset: Offset of timestamp within prefix 103162306a36Sopenharmony_ci * @rx_buffer_padding: Size of padding at end of RX packet 103262306a36Sopenharmony_ci * @can_rx_scatter: NIC is able to scatter packets to multiple buffers 103362306a36Sopenharmony_ci * @always_rx_scatter: NIC will always scatter packets to multiple buffers 103462306a36Sopenharmony_ci * @max_interrupt_mode: Highest capability interrupt mode supported 103562306a36Sopenharmony_ci * from &enum ef4_init_mode. 103662306a36Sopenharmony_ci * @timer_period_max: Maximum period of interrupt timer (in ticks) 103762306a36Sopenharmony_ci * @offload_features: net_device feature flags for protocol offload 103862306a36Sopenharmony_ci * features implemented in hardware 103962306a36Sopenharmony_ci */ 104062306a36Sopenharmony_cistruct ef4_nic_type { 104162306a36Sopenharmony_ci unsigned int mem_bar; 104262306a36Sopenharmony_ci unsigned int (*mem_map_size)(struct ef4_nic *efx); 104362306a36Sopenharmony_ci int (*probe)(struct ef4_nic *efx); 104462306a36Sopenharmony_ci void (*remove)(struct ef4_nic *efx); 104562306a36Sopenharmony_ci int (*init)(struct ef4_nic *efx); 104662306a36Sopenharmony_ci int (*dimension_resources)(struct ef4_nic *efx); 104762306a36Sopenharmony_ci void (*fini)(struct ef4_nic *efx); 104862306a36Sopenharmony_ci void (*monitor)(struct ef4_nic *efx); 104962306a36Sopenharmony_ci enum reset_type (*map_reset_reason)(enum reset_type reason); 105062306a36Sopenharmony_ci int (*map_reset_flags)(u32 *flags); 105162306a36Sopenharmony_ci int (*reset)(struct ef4_nic *efx, enum reset_type method); 105262306a36Sopenharmony_ci int (*probe_port)(struct ef4_nic *efx); 105362306a36Sopenharmony_ci void (*remove_port)(struct ef4_nic *efx); 105462306a36Sopenharmony_ci bool (*handle_global_event)(struct ef4_channel *channel, ef4_qword_t *); 105562306a36Sopenharmony_ci int (*fini_dmaq)(struct ef4_nic *efx); 105662306a36Sopenharmony_ci void (*prepare_flush)(struct ef4_nic *efx); 105762306a36Sopenharmony_ci void (*finish_flush)(struct ef4_nic *efx); 105862306a36Sopenharmony_ci void (*prepare_flr)(struct ef4_nic *efx); 105962306a36Sopenharmony_ci void (*finish_flr)(struct ef4_nic *efx); 106062306a36Sopenharmony_ci size_t (*describe_stats)(struct ef4_nic *efx, u8 *names); 106162306a36Sopenharmony_ci size_t (*update_stats)(struct ef4_nic *efx, u64 *full_stats, 106262306a36Sopenharmony_ci struct rtnl_link_stats64 *core_stats); 106362306a36Sopenharmony_ci void (*start_stats)(struct ef4_nic *efx); 106462306a36Sopenharmony_ci void (*pull_stats)(struct ef4_nic *efx); 106562306a36Sopenharmony_ci void (*stop_stats)(struct ef4_nic *efx); 106662306a36Sopenharmony_ci void (*set_id_led)(struct ef4_nic *efx, enum ef4_led_mode mode); 106762306a36Sopenharmony_ci void (*push_irq_moderation)(struct ef4_channel *channel); 106862306a36Sopenharmony_ci int (*reconfigure_port)(struct ef4_nic *efx); 106962306a36Sopenharmony_ci void (*prepare_enable_fc_tx)(struct ef4_nic *efx); 107062306a36Sopenharmony_ci int (*reconfigure_mac)(struct ef4_nic *efx); 107162306a36Sopenharmony_ci bool (*check_mac_fault)(struct ef4_nic *efx); 107262306a36Sopenharmony_ci void (*get_wol)(struct ef4_nic *efx, struct ethtool_wolinfo *wol); 107362306a36Sopenharmony_ci int (*set_wol)(struct ef4_nic *efx, u32 type); 107462306a36Sopenharmony_ci void (*resume_wol)(struct ef4_nic *efx); 107562306a36Sopenharmony_ci int (*test_chip)(struct ef4_nic *efx, struct ef4_self_tests *tests); 107662306a36Sopenharmony_ci int (*test_nvram)(struct ef4_nic *efx); 107762306a36Sopenharmony_ci void (*irq_enable_master)(struct ef4_nic *efx); 107862306a36Sopenharmony_ci int (*irq_test_generate)(struct ef4_nic *efx); 107962306a36Sopenharmony_ci void (*irq_disable_non_ev)(struct ef4_nic *efx); 108062306a36Sopenharmony_ci irqreturn_t (*irq_handle_msi)(int irq, void *dev_id); 108162306a36Sopenharmony_ci irqreturn_t (*irq_handle_legacy)(int irq, void *dev_id); 108262306a36Sopenharmony_ci int (*tx_probe)(struct ef4_tx_queue *tx_queue); 108362306a36Sopenharmony_ci void (*tx_init)(struct ef4_tx_queue *tx_queue); 108462306a36Sopenharmony_ci void (*tx_remove)(struct ef4_tx_queue *tx_queue); 108562306a36Sopenharmony_ci void (*tx_write)(struct ef4_tx_queue *tx_queue); 108662306a36Sopenharmony_ci unsigned int (*tx_limit_len)(struct ef4_tx_queue *tx_queue, 108762306a36Sopenharmony_ci dma_addr_t dma_addr, unsigned int len); 108862306a36Sopenharmony_ci int (*rx_push_rss_config)(struct ef4_nic *efx, bool user, 108962306a36Sopenharmony_ci const u32 *rx_indir_table); 109062306a36Sopenharmony_ci int (*rx_probe)(struct ef4_rx_queue *rx_queue); 109162306a36Sopenharmony_ci void (*rx_init)(struct ef4_rx_queue *rx_queue); 109262306a36Sopenharmony_ci void (*rx_remove)(struct ef4_rx_queue *rx_queue); 109362306a36Sopenharmony_ci void (*rx_write)(struct ef4_rx_queue *rx_queue); 109462306a36Sopenharmony_ci void (*rx_defer_refill)(struct ef4_rx_queue *rx_queue); 109562306a36Sopenharmony_ci int (*ev_probe)(struct ef4_channel *channel); 109662306a36Sopenharmony_ci int (*ev_init)(struct ef4_channel *channel); 109762306a36Sopenharmony_ci void (*ev_fini)(struct ef4_channel *channel); 109862306a36Sopenharmony_ci void (*ev_remove)(struct ef4_channel *channel); 109962306a36Sopenharmony_ci int (*ev_process)(struct ef4_channel *channel, int quota); 110062306a36Sopenharmony_ci void (*ev_read_ack)(struct ef4_channel *channel); 110162306a36Sopenharmony_ci void (*ev_test_generate)(struct ef4_channel *channel); 110262306a36Sopenharmony_ci int (*filter_table_probe)(struct ef4_nic *efx); 110362306a36Sopenharmony_ci void (*filter_table_restore)(struct ef4_nic *efx); 110462306a36Sopenharmony_ci void (*filter_table_remove)(struct ef4_nic *efx); 110562306a36Sopenharmony_ci void (*filter_update_rx_scatter)(struct ef4_nic *efx); 110662306a36Sopenharmony_ci s32 (*filter_insert)(struct ef4_nic *efx, 110762306a36Sopenharmony_ci struct ef4_filter_spec *spec, bool replace); 110862306a36Sopenharmony_ci int (*filter_remove_safe)(struct ef4_nic *efx, 110962306a36Sopenharmony_ci enum ef4_filter_priority priority, 111062306a36Sopenharmony_ci u32 filter_id); 111162306a36Sopenharmony_ci int (*filter_get_safe)(struct ef4_nic *efx, 111262306a36Sopenharmony_ci enum ef4_filter_priority priority, 111362306a36Sopenharmony_ci u32 filter_id, struct ef4_filter_spec *); 111462306a36Sopenharmony_ci int (*filter_clear_rx)(struct ef4_nic *efx, 111562306a36Sopenharmony_ci enum ef4_filter_priority priority); 111662306a36Sopenharmony_ci u32 (*filter_count_rx_used)(struct ef4_nic *efx, 111762306a36Sopenharmony_ci enum ef4_filter_priority priority); 111862306a36Sopenharmony_ci u32 (*filter_get_rx_id_limit)(struct ef4_nic *efx); 111962306a36Sopenharmony_ci s32 (*filter_get_rx_ids)(struct ef4_nic *efx, 112062306a36Sopenharmony_ci enum ef4_filter_priority priority, 112162306a36Sopenharmony_ci u32 *buf, u32 size); 112262306a36Sopenharmony_ci#ifdef CONFIG_RFS_ACCEL 112362306a36Sopenharmony_ci s32 (*filter_rfs_insert)(struct ef4_nic *efx, 112462306a36Sopenharmony_ci struct ef4_filter_spec *spec); 112562306a36Sopenharmony_ci bool (*filter_rfs_expire_one)(struct ef4_nic *efx, u32 flow_id, 112662306a36Sopenharmony_ci unsigned int index); 112762306a36Sopenharmony_ci#endif 112862306a36Sopenharmony_ci#ifdef CONFIG_SFC_FALCON_MTD 112962306a36Sopenharmony_ci int (*mtd_probe)(struct ef4_nic *efx); 113062306a36Sopenharmony_ci void (*mtd_rename)(struct ef4_mtd_partition *part); 113162306a36Sopenharmony_ci int (*mtd_read)(struct mtd_info *mtd, loff_t start, size_t len, 113262306a36Sopenharmony_ci size_t *retlen, u8 *buffer); 113362306a36Sopenharmony_ci int (*mtd_erase)(struct mtd_info *mtd, loff_t start, size_t len); 113462306a36Sopenharmony_ci int (*mtd_write)(struct mtd_info *mtd, loff_t start, size_t len, 113562306a36Sopenharmony_ci size_t *retlen, const u8 *buffer); 113662306a36Sopenharmony_ci int (*mtd_sync)(struct mtd_info *mtd); 113762306a36Sopenharmony_ci#endif 113862306a36Sopenharmony_ci int (*get_mac_address)(struct ef4_nic *efx, unsigned char *perm_addr); 113962306a36Sopenharmony_ci int (*set_mac_address)(struct ef4_nic *efx); 114062306a36Sopenharmony_ci 114162306a36Sopenharmony_ci int revision; 114262306a36Sopenharmony_ci unsigned int txd_ptr_tbl_base; 114362306a36Sopenharmony_ci unsigned int rxd_ptr_tbl_base; 114462306a36Sopenharmony_ci unsigned int buf_tbl_base; 114562306a36Sopenharmony_ci unsigned int evq_ptr_tbl_base; 114662306a36Sopenharmony_ci unsigned int evq_rptr_tbl_base; 114762306a36Sopenharmony_ci u64 max_dma_mask; 114862306a36Sopenharmony_ci unsigned int rx_prefix_size; 114962306a36Sopenharmony_ci unsigned int rx_hash_offset; 115062306a36Sopenharmony_ci unsigned int rx_ts_offset; 115162306a36Sopenharmony_ci unsigned int rx_buffer_padding; 115262306a36Sopenharmony_ci bool can_rx_scatter; 115362306a36Sopenharmony_ci bool always_rx_scatter; 115462306a36Sopenharmony_ci unsigned int max_interrupt_mode; 115562306a36Sopenharmony_ci unsigned int timer_period_max; 115662306a36Sopenharmony_ci netdev_features_t offload_features; 115762306a36Sopenharmony_ci unsigned int max_rx_ip_filters; 115862306a36Sopenharmony_ci}; 115962306a36Sopenharmony_ci 116062306a36Sopenharmony_ci/************************************************************************** 116162306a36Sopenharmony_ci * 116262306a36Sopenharmony_ci * Prototypes and inline functions 116362306a36Sopenharmony_ci * 116462306a36Sopenharmony_ci *************************************************************************/ 116562306a36Sopenharmony_ci 116662306a36Sopenharmony_cistatic inline struct ef4_channel * 116762306a36Sopenharmony_cief4_get_channel(struct ef4_nic *efx, unsigned index) 116862306a36Sopenharmony_ci{ 116962306a36Sopenharmony_ci EF4_BUG_ON_PARANOID(index >= efx->n_channels); 117062306a36Sopenharmony_ci return efx->channel[index]; 117162306a36Sopenharmony_ci} 117262306a36Sopenharmony_ci 117362306a36Sopenharmony_ci/* Iterate over all used channels */ 117462306a36Sopenharmony_ci#define ef4_for_each_channel(_channel, _efx) \ 117562306a36Sopenharmony_ci for (_channel = (_efx)->channel[0]; \ 117662306a36Sopenharmony_ci _channel; \ 117762306a36Sopenharmony_ci _channel = (_channel->channel + 1 < (_efx)->n_channels) ? \ 117862306a36Sopenharmony_ci (_efx)->channel[_channel->channel + 1] : NULL) 117962306a36Sopenharmony_ci 118062306a36Sopenharmony_ci/* Iterate over all used channels in reverse */ 118162306a36Sopenharmony_ci#define ef4_for_each_channel_rev(_channel, _efx) \ 118262306a36Sopenharmony_ci for (_channel = (_efx)->channel[(_efx)->n_channels - 1]; \ 118362306a36Sopenharmony_ci _channel; \ 118462306a36Sopenharmony_ci _channel = _channel->channel ? \ 118562306a36Sopenharmony_ci (_efx)->channel[_channel->channel - 1] : NULL) 118662306a36Sopenharmony_ci 118762306a36Sopenharmony_cistatic inline struct ef4_tx_queue * 118862306a36Sopenharmony_cief4_get_tx_queue(struct ef4_nic *efx, unsigned index, unsigned type) 118962306a36Sopenharmony_ci{ 119062306a36Sopenharmony_ci EF4_BUG_ON_PARANOID(index >= efx->n_tx_channels || 119162306a36Sopenharmony_ci type >= EF4_TXQ_TYPES); 119262306a36Sopenharmony_ci return &efx->channel[efx->tx_channel_offset + index]->tx_queue[type]; 119362306a36Sopenharmony_ci} 119462306a36Sopenharmony_ci 119562306a36Sopenharmony_cistatic inline bool ef4_channel_has_tx_queues(struct ef4_channel *channel) 119662306a36Sopenharmony_ci{ 119762306a36Sopenharmony_ci return channel->channel - channel->efx->tx_channel_offset < 119862306a36Sopenharmony_ci channel->efx->n_tx_channels; 119962306a36Sopenharmony_ci} 120062306a36Sopenharmony_ci 120162306a36Sopenharmony_cistatic inline struct ef4_tx_queue * 120262306a36Sopenharmony_cief4_channel_get_tx_queue(struct ef4_channel *channel, unsigned type) 120362306a36Sopenharmony_ci{ 120462306a36Sopenharmony_ci EF4_BUG_ON_PARANOID(!ef4_channel_has_tx_queues(channel) || 120562306a36Sopenharmony_ci type >= EF4_TXQ_TYPES); 120662306a36Sopenharmony_ci return &channel->tx_queue[type]; 120762306a36Sopenharmony_ci} 120862306a36Sopenharmony_ci 120962306a36Sopenharmony_cistatic inline bool ef4_tx_queue_used(struct ef4_tx_queue *tx_queue) 121062306a36Sopenharmony_ci{ 121162306a36Sopenharmony_ci return !(tx_queue->efx->net_dev->num_tc < 2 && 121262306a36Sopenharmony_ci tx_queue->queue & EF4_TXQ_TYPE_HIGHPRI); 121362306a36Sopenharmony_ci} 121462306a36Sopenharmony_ci 121562306a36Sopenharmony_ci/* Iterate over all TX queues belonging to a channel */ 121662306a36Sopenharmony_ci#define ef4_for_each_channel_tx_queue(_tx_queue, _channel) \ 121762306a36Sopenharmony_ci if (!ef4_channel_has_tx_queues(_channel)) \ 121862306a36Sopenharmony_ci ; \ 121962306a36Sopenharmony_ci else \ 122062306a36Sopenharmony_ci for (_tx_queue = (_channel)->tx_queue; \ 122162306a36Sopenharmony_ci _tx_queue < (_channel)->tx_queue + EF4_TXQ_TYPES && \ 122262306a36Sopenharmony_ci ef4_tx_queue_used(_tx_queue); \ 122362306a36Sopenharmony_ci _tx_queue++) 122462306a36Sopenharmony_ci 122562306a36Sopenharmony_ci/* Iterate over all possible TX queues belonging to a channel */ 122662306a36Sopenharmony_ci#define ef4_for_each_possible_channel_tx_queue(_tx_queue, _channel) \ 122762306a36Sopenharmony_ci if (!ef4_channel_has_tx_queues(_channel)) \ 122862306a36Sopenharmony_ci ; \ 122962306a36Sopenharmony_ci else \ 123062306a36Sopenharmony_ci for (_tx_queue = (_channel)->tx_queue; \ 123162306a36Sopenharmony_ci _tx_queue < (_channel)->tx_queue + EF4_TXQ_TYPES; \ 123262306a36Sopenharmony_ci _tx_queue++) 123362306a36Sopenharmony_ci 123462306a36Sopenharmony_cistatic inline bool ef4_channel_has_rx_queue(struct ef4_channel *channel) 123562306a36Sopenharmony_ci{ 123662306a36Sopenharmony_ci return channel->rx_queue.core_index >= 0; 123762306a36Sopenharmony_ci} 123862306a36Sopenharmony_ci 123962306a36Sopenharmony_cistatic inline struct ef4_rx_queue * 124062306a36Sopenharmony_cief4_channel_get_rx_queue(struct ef4_channel *channel) 124162306a36Sopenharmony_ci{ 124262306a36Sopenharmony_ci EF4_BUG_ON_PARANOID(!ef4_channel_has_rx_queue(channel)); 124362306a36Sopenharmony_ci return &channel->rx_queue; 124462306a36Sopenharmony_ci} 124562306a36Sopenharmony_ci 124662306a36Sopenharmony_ci/* Iterate over all RX queues belonging to a channel */ 124762306a36Sopenharmony_ci#define ef4_for_each_channel_rx_queue(_rx_queue, _channel) \ 124862306a36Sopenharmony_ci if (!ef4_channel_has_rx_queue(_channel)) \ 124962306a36Sopenharmony_ci ; \ 125062306a36Sopenharmony_ci else \ 125162306a36Sopenharmony_ci for (_rx_queue = &(_channel)->rx_queue; \ 125262306a36Sopenharmony_ci _rx_queue; \ 125362306a36Sopenharmony_ci _rx_queue = NULL) 125462306a36Sopenharmony_ci 125562306a36Sopenharmony_cistatic inline struct ef4_channel * 125662306a36Sopenharmony_cief4_rx_queue_channel(struct ef4_rx_queue *rx_queue) 125762306a36Sopenharmony_ci{ 125862306a36Sopenharmony_ci return container_of(rx_queue, struct ef4_channel, rx_queue); 125962306a36Sopenharmony_ci} 126062306a36Sopenharmony_ci 126162306a36Sopenharmony_cistatic inline int ef4_rx_queue_index(struct ef4_rx_queue *rx_queue) 126262306a36Sopenharmony_ci{ 126362306a36Sopenharmony_ci return ef4_rx_queue_channel(rx_queue)->channel; 126462306a36Sopenharmony_ci} 126562306a36Sopenharmony_ci 126662306a36Sopenharmony_ci/* Returns a pointer to the specified receive buffer in the RX 126762306a36Sopenharmony_ci * descriptor queue. 126862306a36Sopenharmony_ci */ 126962306a36Sopenharmony_cistatic inline struct ef4_rx_buffer *ef4_rx_buffer(struct ef4_rx_queue *rx_queue, 127062306a36Sopenharmony_ci unsigned int index) 127162306a36Sopenharmony_ci{ 127262306a36Sopenharmony_ci return &rx_queue->buffer[index]; 127362306a36Sopenharmony_ci} 127462306a36Sopenharmony_ci 127562306a36Sopenharmony_ci/** 127662306a36Sopenharmony_ci * EF4_MAX_FRAME_LEN - calculate maximum frame length 127762306a36Sopenharmony_ci * 127862306a36Sopenharmony_ci * This calculates the maximum frame length that will be used for a 127962306a36Sopenharmony_ci * given MTU. The frame length will be equal to the MTU plus a 128062306a36Sopenharmony_ci * constant amount of header space and padding. This is the quantity 128162306a36Sopenharmony_ci * that the net driver will program into the MAC as the maximum frame 128262306a36Sopenharmony_ci * length. 128362306a36Sopenharmony_ci * 128462306a36Sopenharmony_ci * The 10G MAC requires 8-byte alignment on the frame 128562306a36Sopenharmony_ci * length, so we round up to the nearest 8. 128662306a36Sopenharmony_ci * 128762306a36Sopenharmony_ci * Re-clocking by the XGXS on RX can reduce an IPG to 32 bits (half an 128862306a36Sopenharmony_ci * XGMII cycle). If the frame length reaches the maximum value in the 128962306a36Sopenharmony_ci * same cycle, the XMAC can miss the IPG altogether. We work around 129062306a36Sopenharmony_ci * this by adding a further 16 bytes. 129162306a36Sopenharmony_ci */ 129262306a36Sopenharmony_ci#define EF4_FRAME_PAD 16 129362306a36Sopenharmony_ci#define EF4_MAX_FRAME_LEN(mtu) \ 129462306a36Sopenharmony_ci (ALIGN(((mtu) + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN + EF4_FRAME_PAD), 8)) 129562306a36Sopenharmony_ci 129662306a36Sopenharmony_ci/* Get all supported features. 129762306a36Sopenharmony_ci * If a feature is not fixed, it is present in hw_features. 129862306a36Sopenharmony_ci * If a feature is fixed, it does not present in hw_features, but 129962306a36Sopenharmony_ci * always in features. 130062306a36Sopenharmony_ci */ 130162306a36Sopenharmony_cistatic inline netdev_features_t ef4_supported_features(const struct ef4_nic *efx) 130262306a36Sopenharmony_ci{ 130362306a36Sopenharmony_ci const struct net_device *net_dev = efx->net_dev; 130462306a36Sopenharmony_ci 130562306a36Sopenharmony_ci return net_dev->features | net_dev->hw_features; 130662306a36Sopenharmony_ci} 130762306a36Sopenharmony_ci 130862306a36Sopenharmony_ci/* Get the current TX queue insert index. */ 130962306a36Sopenharmony_cistatic inline unsigned int 131062306a36Sopenharmony_cief4_tx_queue_get_insert_index(const struct ef4_tx_queue *tx_queue) 131162306a36Sopenharmony_ci{ 131262306a36Sopenharmony_ci return tx_queue->insert_count & tx_queue->ptr_mask; 131362306a36Sopenharmony_ci} 131462306a36Sopenharmony_ci 131562306a36Sopenharmony_ci/* Get a TX buffer. */ 131662306a36Sopenharmony_cistatic inline struct ef4_tx_buffer * 131762306a36Sopenharmony_ci__ef4_tx_queue_get_insert_buffer(const struct ef4_tx_queue *tx_queue) 131862306a36Sopenharmony_ci{ 131962306a36Sopenharmony_ci return &tx_queue->buffer[ef4_tx_queue_get_insert_index(tx_queue)]; 132062306a36Sopenharmony_ci} 132162306a36Sopenharmony_ci 132262306a36Sopenharmony_ci/* Get a TX buffer, checking it's not currently in use. */ 132362306a36Sopenharmony_cistatic inline struct ef4_tx_buffer * 132462306a36Sopenharmony_cief4_tx_queue_get_insert_buffer(const struct ef4_tx_queue *tx_queue) 132562306a36Sopenharmony_ci{ 132662306a36Sopenharmony_ci struct ef4_tx_buffer *buffer = 132762306a36Sopenharmony_ci __ef4_tx_queue_get_insert_buffer(tx_queue); 132862306a36Sopenharmony_ci 132962306a36Sopenharmony_ci EF4_BUG_ON_PARANOID(buffer->len); 133062306a36Sopenharmony_ci EF4_BUG_ON_PARANOID(buffer->flags); 133162306a36Sopenharmony_ci EF4_BUG_ON_PARANOID(buffer->unmap_len); 133262306a36Sopenharmony_ci 133362306a36Sopenharmony_ci return buffer; 133462306a36Sopenharmony_ci} 133562306a36Sopenharmony_ci 133662306a36Sopenharmony_ci#endif /* EF4_NET_DRIVER_H */ 1337