162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* Copyright(c) 1999 - 2018 Intel Corporation. */ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci#ifndef _IXGBEVF_H_ 562306a36Sopenharmony_ci#define _IXGBEVF_H_ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#include <linux/types.h> 862306a36Sopenharmony_ci#include <linux/bitops.h> 962306a36Sopenharmony_ci#include <linux/timer.h> 1062306a36Sopenharmony_ci#include <linux/io.h> 1162306a36Sopenharmony_ci#include <linux/netdevice.h> 1262306a36Sopenharmony_ci#include <linux/if_vlan.h> 1362306a36Sopenharmony_ci#include <linux/u64_stats_sync.h> 1462306a36Sopenharmony_ci#include <net/xdp.h> 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#include "vf.h" 1762306a36Sopenharmony_ci#include "ipsec.h" 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#define IXGBE_MAX_TXD_PWR 14 2062306a36Sopenharmony_ci#define IXGBE_MAX_DATA_PER_TXD BIT(IXGBE_MAX_TXD_PWR) 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci/* Tx Descriptors needed, worst case */ 2362306a36Sopenharmony_ci#define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IXGBE_MAX_DATA_PER_TXD) 2462306a36Sopenharmony_ci#define DESC_NEEDED (MAX_SKB_FRAGS + 4) 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci/* wrapper around a pointer to a socket buffer, 2762306a36Sopenharmony_ci * so a DMA handle can be stored along with the buffer 2862306a36Sopenharmony_ci */ 2962306a36Sopenharmony_cistruct ixgbevf_tx_buffer { 3062306a36Sopenharmony_ci union ixgbe_adv_tx_desc *next_to_watch; 3162306a36Sopenharmony_ci unsigned long time_stamp; 3262306a36Sopenharmony_ci union { 3362306a36Sopenharmony_ci struct sk_buff *skb; 3462306a36Sopenharmony_ci /* XDP uses address ptr on irq_clean */ 3562306a36Sopenharmony_ci void *data; 3662306a36Sopenharmony_ci }; 3762306a36Sopenharmony_ci unsigned int bytecount; 3862306a36Sopenharmony_ci unsigned short gso_segs; 3962306a36Sopenharmony_ci __be16 protocol; 4062306a36Sopenharmony_ci DEFINE_DMA_UNMAP_ADDR(dma); 4162306a36Sopenharmony_ci DEFINE_DMA_UNMAP_LEN(len); 4262306a36Sopenharmony_ci u32 tx_flags; 4362306a36Sopenharmony_ci}; 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_cistruct ixgbevf_rx_buffer { 4662306a36Sopenharmony_ci dma_addr_t dma; 4762306a36Sopenharmony_ci struct page *page; 4862306a36Sopenharmony_ci#if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536) 4962306a36Sopenharmony_ci __u32 page_offset; 5062306a36Sopenharmony_ci#else 5162306a36Sopenharmony_ci __u16 page_offset; 5262306a36Sopenharmony_ci#endif 5362306a36Sopenharmony_ci __u16 pagecnt_bias; 5462306a36Sopenharmony_ci}; 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_cistruct ixgbevf_stats { 5762306a36Sopenharmony_ci u64 packets; 5862306a36Sopenharmony_ci u64 bytes; 5962306a36Sopenharmony_ci}; 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_cistruct ixgbevf_tx_queue_stats { 6262306a36Sopenharmony_ci u64 restart_queue; 6362306a36Sopenharmony_ci u64 tx_busy; 6462306a36Sopenharmony_ci u64 tx_done_old; 6562306a36Sopenharmony_ci}; 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_cistruct ixgbevf_rx_queue_stats { 6862306a36Sopenharmony_ci u64 alloc_rx_page_failed; 6962306a36Sopenharmony_ci u64 alloc_rx_buff_failed; 7062306a36Sopenharmony_ci u64 alloc_rx_page; 7162306a36Sopenharmony_ci u64 csum_err; 7262306a36Sopenharmony_ci}; 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_cienum ixgbevf_ring_state_t { 7562306a36Sopenharmony_ci __IXGBEVF_RX_3K_BUFFER, 7662306a36Sopenharmony_ci __IXGBEVF_RX_BUILD_SKB_ENABLED, 7762306a36Sopenharmony_ci __IXGBEVF_TX_DETECT_HANG, 7862306a36Sopenharmony_ci __IXGBEVF_HANG_CHECK_ARMED, 7962306a36Sopenharmony_ci __IXGBEVF_TX_XDP_RING, 8062306a36Sopenharmony_ci __IXGBEVF_TX_XDP_RING_PRIMED, 8162306a36Sopenharmony_ci}; 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci#define ring_is_xdp(ring) \ 8462306a36Sopenharmony_ci test_bit(__IXGBEVF_TX_XDP_RING, &(ring)->state) 8562306a36Sopenharmony_ci#define set_ring_xdp(ring) \ 8662306a36Sopenharmony_ci set_bit(__IXGBEVF_TX_XDP_RING, &(ring)->state) 8762306a36Sopenharmony_ci#define clear_ring_xdp(ring) \ 8862306a36Sopenharmony_ci clear_bit(__IXGBEVF_TX_XDP_RING, &(ring)->state) 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_cistruct ixgbevf_ring { 9162306a36Sopenharmony_ci struct ixgbevf_ring *next; 9262306a36Sopenharmony_ci struct ixgbevf_q_vector *q_vector; /* backpointer to q_vector */ 9362306a36Sopenharmony_ci struct net_device *netdev; 9462306a36Sopenharmony_ci struct bpf_prog *xdp_prog; 9562306a36Sopenharmony_ci struct device *dev; 9662306a36Sopenharmony_ci void *desc; /* descriptor ring memory */ 9762306a36Sopenharmony_ci dma_addr_t dma; /* phys. address of descriptor ring */ 9862306a36Sopenharmony_ci unsigned int size; /* length in bytes */ 9962306a36Sopenharmony_ci u16 count; /* amount of descriptors */ 10062306a36Sopenharmony_ci u16 next_to_use; 10162306a36Sopenharmony_ci u16 next_to_clean; 10262306a36Sopenharmony_ci u16 next_to_alloc; 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci union { 10562306a36Sopenharmony_ci struct ixgbevf_tx_buffer *tx_buffer_info; 10662306a36Sopenharmony_ci struct ixgbevf_rx_buffer *rx_buffer_info; 10762306a36Sopenharmony_ci }; 10862306a36Sopenharmony_ci unsigned long state; 10962306a36Sopenharmony_ci struct ixgbevf_stats stats; 11062306a36Sopenharmony_ci struct u64_stats_sync syncp; 11162306a36Sopenharmony_ci union { 11262306a36Sopenharmony_ci struct ixgbevf_tx_queue_stats tx_stats; 11362306a36Sopenharmony_ci struct ixgbevf_rx_queue_stats rx_stats; 11462306a36Sopenharmony_ci }; 11562306a36Sopenharmony_ci struct xdp_rxq_info xdp_rxq; 11662306a36Sopenharmony_ci u64 hw_csum_rx_error; 11762306a36Sopenharmony_ci u8 __iomem *tail; 11862306a36Sopenharmony_ci struct sk_buff *skb; 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci /* holds the special value that gets the hardware register offset 12162306a36Sopenharmony_ci * associated with this ring, which is different for DCB and RSS modes 12262306a36Sopenharmony_ci */ 12362306a36Sopenharmony_ci u16 reg_idx; 12462306a36Sopenharmony_ci int queue_index; /* needed for multiqueue queue management */ 12562306a36Sopenharmony_ci} ____cacheline_internodealigned_in_smp; 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci/* How many Rx Buffers do we bundle into one write to the hardware ? */ 12862306a36Sopenharmony_ci#define IXGBEVF_RX_BUFFER_WRITE 16 /* Must be power of 2 */ 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci#define MAX_RX_QUEUES IXGBE_VF_MAX_RX_QUEUES 13162306a36Sopenharmony_ci#define MAX_TX_QUEUES IXGBE_VF_MAX_TX_QUEUES 13262306a36Sopenharmony_ci#define MAX_XDP_QUEUES IXGBE_VF_MAX_TX_QUEUES 13362306a36Sopenharmony_ci#define IXGBEVF_MAX_RSS_QUEUES 2 13462306a36Sopenharmony_ci#define IXGBEVF_82599_RETA_SIZE 128 /* 128 entries */ 13562306a36Sopenharmony_ci#define IXGBEVF_X550_VFRETA_SIZE 64 /* 64 entries */ 13662306a36Sopenharmony_ci#define IXGBEVF_RSS_HASH_KEY_SIZE 40 13762306a36Sopenharmony_ci#define IXGBEVF_VFRSSRK_REGS 10 /* 10 registers for RSS key */ 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci#define IXGBEVF_DEFAULT_TXD 1024 14062306a36Sopenharmony_ci#define IXGBEVF_DEFAULT_RXD 512 14162306a36Sopenharmony_ci#define IXGBEVF_MAX_TXD 4096 14262306a36Sopenharmony_ci#define IXGBEVF_MIN_TXD 64 14362306a36Sopenharmony_ci#define IXGBEVF_MAX_RXD 4096 14462306a36Sopenharmony_ci#define IXGBEVF_MIN_RXD 64 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci/* Supported Rx Buffer Sizes */ 14762306a36Sopenharmony_ci#define IXGBEVF_RXBUFFER_256 256 /* Used for packet split */ 14862306a36Sopenharmony_ci#define IXGBEVF_RXBUFFER_2048 2048 14962306a36Sopenharmony_ci#define IXGBEVF_RXBUFFER_3072 3072 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci#define IXGBEVF_RX_HDR_SIZE IXGBEVF_RXBUFFER_256 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ci#define MAXIMUM_ETHERNET_VLAN_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN) 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci#define IXGBEVF_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN) 15662306a36Sopenharmony_ci#if (PAGE_SIZE < 8192) 15762306a36Sopenharmony_ci#define IXGBEVF_MAX_FRAME_BUILD_SKB \ 15862306a36Sopenharmony_ci (SKB_WITH_OVERHEAD(IXGBEVF_RXBUFFER_2048) - IXGBEVF_SKB_PAD) 15962306a36Sopenharmony_ci#else 16062306a36Sopenharmony_ci#define IXGBEVF_MAX_FRAME_BUILD_SKB IXGBEVF_RXBUFFER_2048 16162306a36Sopenharmony_ci#endif 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci#define IXGBE_TX_FLAGS_CSUM BIT(0) 16462306a36Sopenharmony_ci#define IXGBE_TX_FLAGS_VLAN BIT(1) 16562306a36Sopenharmony_ci#define IXGBE_TX_FLAGS_TSO BIT(2) 16662306a36Sopenharmony_ci#define IXGBE_TX_FLAGS_IPV4 BIT(3) 16762306a36Sopenharmony_ci#define IXGBE_TX_FLAGS_IPSEC BIT(4) 16862306a36Sopenharmony_ci#define IXGBE_TX_FLAGS_VLAN_MASK 0xffff0000 16962306a36Sopenharmony_ci#define IXGBE_TX_FLAGS_VLAN_PRIO_MASK 0x0000e000 17062306a36Sopenharmony_ci#define IXGBE_TX_FLAGS_VLAN_SHIFT 16 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ci#define ring_uses_large_buffer(ring) \ 17362306a36Sopenharmony_ci test_bit(__IXGBEVF_RX_3K_BUFFER, &(ring)->state) 17462306a36Sopenharmony_ci#define set_ring_uses_large_buffer(ring) \ 17562306a36Sopenharmony_ci set_bit(__IXGBEVF_RX_3K_BUFFER, &(ring)->state) 17662306a36Sopenharmony_ci#define clear_ring_uses_large_buffer(ring) \ 17762306a36Sopenharmony_ci clear_bit(__IXGBEVF_RX_3K_BUFFER, &(ring)->state) 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ci#define ring_uses_build_skb(ring) \ 18062306a36Sopenharmony_ci test_bit(__IXGBEVF_RX_BUILD_SKB_ENABLED, &(ring)->state) 18162306a36Sopenharmony_ci#define set_ring_build_skb_enabled(ring) \ 18262306a36Sopenharmony_ci set_bit(__IXGBEVF_RX_BUILD_SKB_ENABLED, &(ring)->state) 18362306a36Sopenharmony_ci#define clear_ring_build_skb_enabled(ring) \ 18462306a36Sopenharmony_ci clear_bit(__IXGBEVF_RX_BUILD_SKB_ENABLED, &(ring)->state) 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_cistatic inline unsigned int ixgbevf_rx_bufsz(struct ixgbevf_ring *ring) 18762306a36Sopenharmony_ci{ 18862306a36Sopenharmony_ci#if (PAGE_SIZE < 8192) 18962306a36Sopenharmony_ci if (ring_uses_large_buffer(ring)) 19062306a36Sopenharmony_ci return IXGBEVF_RXBUFFER_3072; 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ci if (ring_uses_build_skb(ring)) 19362306a36Sopenharmony_ci return IXGBEVF_MAX_FRAME_BUILD_SKB; 19462306a36Sopenharmony_ci#endif 19562306a36Sopenharmony_ci return IXGBEVF_RXBUFFER_2048; 19662306a36Sopenharmony_ci} 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_cistatic inline unsigned int ixgbevf_rx_pg_order(struct ixgbevf_ring *ring) 19962306a36Sopenharmony_ci{ 20062306a36Sopenharmony_ci#if (PAGE_SIZE < 8192) 20162306a36Sopenharmony_ci if (ring_uses_large_buffer(ring)) 20262306a36Sopenharmony_ci return 1; 20362306a36Sopenharmony_ci#endif 20462306a36Sopenharmony_ci return 0; 20562306a36Sopenharmony_ci} 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_ci#define ixgbevf_rx_pg_size(_ring) (PAGE_SIZE << ixgbevf_rx_pg_order(_ring)) 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci#define check_for_tx_hang(ring) \ 21062306a36Sopenharmony_ci test_bit(__IXGBEVF_TX_DETECT_HANG, &(ring)->state) 21162306a36Sopenharmony_ci#define set_check_for_tx_hang(ring) \ 21262306a36Sopenharmony_ci set_bit(__IXGBEVF_TX_DETECT_HANG, &(ring)->state) 21362306a36Sopenharmony_ci#define clear_check_for_tx_hang(ring) \ 21462306a36Sopenharmony_ci clear_bit(__IXGBEVF_TX_DETECT_HANG, &(ring)->state) 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_cistruct ixgbevf_ring_container { 21762306a36Sopenharmony_ci struct ixgbevf_ring *ring; /* pointer to linked list of rings */ 21862306a36Sopenharmony_ci unsigned int total_bytes; /* total bytes processed this int */ 21962306a36Sopenharmony_ci unsigned int total_packets; /* total packets processed this int */ 22062306a36Sopenharmony_ci u8 count; /* total number of rings in vector */ 22162306a36Sopenharmony_ci u8 itr; /* current ITR setting for ring */ 22262306a36Sopenharmony_ci}; 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ci/* iterator for handling rings in ring container */ 22562306a36Sopenharmony_ci#define ixgbevf_for_each_ring(pos, head) \ 22662306a36Sopenharmony_ci for (pos = (head).ring; pos != NULL; pos = pos->next) 22762306a36Sopenharmony_ci 22862306a36Sopenharmony_ci/* MAX_MSIX_Q_VECTORS of these are allocated, 22962306a36Sopenharmony_ci * but we only use one per queue-specific vector. 23062306a36Sopenharmony_ci */ 23162306a36Sopenharmony_cistruct ixgbevf_q_vector { 23262306a36Sopenharmony_ci struct ixgbevf_adapter *adapter; 23362306a36Sopenharmony_ci /* index of q_vector within array, also used for finding the bit in 23462306a36Sopenharmony_ci * EICR and friends that represents the vector for this ring 23562306a36Sopenharmony_ci */ 23662306a36Sopenharmony_ci u16 v_idx; 23762306a36Sopenharmony_ci u16 itr; /* Interrupt throttle rate written to EITR */ 23862306a36Sopenharmony_ci struct napi_struct napi; 23962306a36Sopenharmony_ci struct ixgbevf_ring_container rx, tx; 24062306a36Sopenharmony_ci struct rcu_head rcu; /* to avoid race with update stats on free */ 24162306a36Sopenharmony_ci char name[IFNAMSIZ + 9]; 24262306a36Sopenharmony_ci 24362306a36Sopenharmony_ci /* for dynamic allocation of rings associated with this q_vector */ 24462306a36Sopenharmony_ci struct ixgbevf_ring ring[0] ____cacheline_internodealigned_in_smp; 24562306a36Sopenharmony_ci#ifdef CONFIG_NET_RX_BUSY_POLL 24662306a36Sopenharmony_ci unsigned int state; 24762306a36Sopenharmony_ci#define IXGBEVF_QV_STATE_IDLE 0 24862306a36Sopenharmony_ci#define IXGBEVF_QV_STATE_NAPI 1 /* NAPI owns this QV */ 24962306a36Sopenharmony_ci#define IXGBEVF_QV_STATE_POLL 2 /* poll owns this QV */ 25062306a36Sopenharmony_ci#define IXGBEVF_QV_STATE_DISABLED 4 /* QV is disabled */ 25162306a36Sopenharmony_ci#define IXGBEVF_QV_OWNED (IXGBEVF_QV_STATE_NAPI | IXGBEVF_QV_STATE_POLL) 25262306a36Sopenharmony_ci#define IXGBEVF_QV_LOCKED (IXGBEVF_QV_OWNED | IXGBEVF_QV_STATE_DISABLED) 25362306a36Sopenharmony_ci#define IXGBEVF_QV_STATE_NAPI_YIELD 8 /* NAPI yielded this QV */ 25462306a36Sopenharmony_ci#define IXGBEVF_QV_STATE_POLL_YIELD 16 /* poll yielded this QV */ 25562306a36Sopenharmony_ci#define IXGBEVF_QV_YIELD (IXGBEVF_QV_STATE_NAPI_YIELD | \ 25662306a36Sopenharmony_ci IXGBEVF_QV_STATE_POLL_YIELD) 25762306a36Sopenharmony_ci#define IXGBEVF_QV_USER_PEND (IXGBEVF_QV_STATE_POLL | \ 25862306a36Sopenharmony_ci IXGBEVF_QV_STATE_POLL_YIELD) 25962306a36Sopenharmony_ci spinlock_t lock; 26062306a36Sopenharmony_ci#endif /* CONFIG_NET_RX_BUSY_POLL */ 26162306a36Sopenharmony_ci}; 26262306a36Sopenharmony_ci 26362306a36Sopenharmony_ci/* microsecond values for various ITR rates shifted by 2 to fit itr register 26462306a36Sopenharmony_ci * with the first 3 bits reserved 0 26562306a36Sopenharmony_ci */ 26662306a36Sopenharmony_ci#define IXGBE_MIN_RSC_ITR 24 26762306a36Sopenharmony_ci#define IXGBE_100K_ITR 40 26862306a36Sopenharmony_ci#define IXGBE_20K_ITR 200 26962306a36Sopenharmony_ci#define IXGBE_12K_ITR 336 27062306a36Sopenharmony_ci 27162306a36Sopenharmony_ci/* Helper macros to switch between ints/sec and what the register uses. 27262306a36Sopenharmony_ci * And yes, it's the same math going both ways. The lowest value 27362306a36Sopenharmony_ci * supported by all of the ixgbe hardware is 8. 27462306a36Sopenharmony_ci */ 27562306a36Sopenharmony_ci#define EITR_INTS_PER_SEC_TO_REG(_eitr) \ 27662306a36Sopenharmony_ci ((_eitr) ? (1000000000 / ((_eitr) * 256)) : 8) 27762306a36Sopenharmony_ci#define EITR_REG_TO_INTS_PER_SEC EITR_INTS_PER_SEC_TO_REG 27862306a36Sopenharmony_ci 27962306a36Sopenharmony_ci/* ixgbevf_test_staterr - tests bits in Rx descriptor status and error fields */ 28062306a36Sopenharmony_cistatic inline __le32 ixgbevf_test_staterr(union ixgbe_adv_rx_desc *rx_desc, 28162306a36Sopenharmony_ci const u32 stat_err_bits) 28262306a36Sopenharmony_ci{ 28362306a36Sopenharmony_ci return rx_desc->wb.upper.status_error & cpu_to_le32(stat_err_bits); 28462306a36Sopenharmony_ci} 28562306a36Sopenharmony_ci 28662306a36Sopenharmony_cistatic inline u16 ixgbevf_desc_unused(struct ixgbevf_ring *ring) 28762306a36Sopenharmony_ci{ 28862306a36Sopenharmony_ci u16 ntc = ring->next_to_clean; 28962306a36Sopenharmony_ci u16 ntu = ring->next_to_use; 29062306a36Sopenharmony_ci 29162306a36Sopenharmony_ci return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1; 29262306a36Sopenharmony_ci} 29362306a36Sopenharmony_ci 29462306a36Sopenharmony_cistatic inline void ixgbevf_write_tail(struct ixgbevf_ring *ring, u32 value) 29562306a36Sopenharmony_ci{ 29662306a36Sopenharmony_ci writel(value, ring->tail); 29762306a36Sopenharmony_ci} 29862306a36Sopenharmony_ci 29962306a36Sopenharmony_ci#define IXGBEVF_RX_DESC(R, i) \ 30062306a36Sopenharmony_ci (&(((union ixgbe_adv_rx_desc *)((R)->desc))[i])) 30162306a36Sopenharmony_ci#define IXGBEVF_TX_DESC(R, i) \ 30262306a36Sopenharmony_ci (&(((union ixgbe_adv_tx_desc *)((R)->desc))[i])) 30362306a36Sopenharmony_ci#define IXGBEVF_TX_CTXTDESC(R, i) \ 30462306a36Sopenharmony_ci (&(((struct ixgbe_adv_tx_context_desc *)((R)->desc))[i])) 30562306a36Sopenharmony_ci 30662306a36Sopenharmony_ci#define IXGBE_MAX_JUMBO_FRAME_SIZE 9728 /* Maximum Supported Size 9.5KB */ 30762306a36Sopenharmony_ci 30862306a36Sopenharmony_ci#define OTHER_VECTOR 1 30962306a36Sopenharmony_ci#define NON_Q_VECTORS (OTHER_VECTOR) 31062306a36Sopenharmony_ci 31162306a36Sopenharmony_ci#define MAX_MSIX_Q_VECTORS 2 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_ci#define MIN_MSIX_Q_VECTORS 1 31462306a36Sopenharmony_ci#define MIN_MSIX_COUNT (MIN_MSIX_Q_VECTORS + NON_Q_VECTORS) 31562306a36Sopenharmony_ci 31662306a36Sopenharmony_ci#define IXGBEVF_RX_DMA_ATTR \ 31762306a36Sopenharmony_ci (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING) 31862306a36Sopenharmony_ci 31962306a36Sopenharmony_ci/* board specific private data structure */ 32062306a36Sopenharmony_cistruct ixgbevf_adapter { 32162306a36Sopenharmony_ci /* this field must be first, see ixgbevf_process_skb_fields */ 32262306a36Sopenharmony_ci unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)]; 32362306a36Sopenharmony_ci 32462306a36Sopenharmony_ci struct ixgbevf_q_vector *q_vector[MAX_MSIX_Q_VECTORS]; 32562306a36Sopenharmony_ci 32662306a36Sopenharmony_ci /* Interrupt Throttle Rate */ 32762306a36Sopenharmony_ci u16 rx_itr_setting; 32862306a36Sopenharmony_ci u16 tx_itr_setting; 32962306a36Sopenharmony_ci 33062306a36Sopenharmony_ci /* interrupt masks */ 33162306a36Sopenharmony_ci u32 eims_enable_mask; 33262306a36Sopenharmony_ci u32 eims_other; 33362306a36Sopenharmony_ci 33462306a36Sopenharmony_ci /* XDP */ 33562306a36Sopenharmony_ci int num_xdp_queues; 33662306a36Sopenharmony_ci struct ixgbevf_ring *xdp_ring[MAX_XDP_QUEUES]; 33762306a36Sopenharmony_ci 33862306a36Sopenharmony_ci /* TX */ 33962306a36Sopenharmony_ci int num_tx_queues; 34062306a36Sopenharmony_ci struct ixgbevf_ring *tx_ring[MAX_TX_QUEUES]; /* One per active queue */ 34162306a36Sopenharmony_ci u64 restart_queue; 34262306a36Sopenharmony_ci u32 tx_timeout_count; 34362306a36Sopenharmony_ci u64 tx_ipsec; 34462306a36Sopenharmony_ci 34562306a36Sopenharmony_ci /* RX */ 34662306a36Sopenharmony_ci int num_rx_queues; 34762306a36Sopenharmony_ci struct ixgbevf_ring *rx_ring[MAX_TX_QUEUES]; /* One per active queue */ 34862306a36Sopenharmony_ci u64 hw_csum_rx_error; 34962306a36Sopenharmony_ci u64 hw_rx_no_dma_resources; 35062306a36Sopenharmony_ci int num_msix_vectors; 35162306a36Sopenharmony_ci u64 alloc_rx_page_failed; 35262306a36Sopenharmony_ci u64 alloc_rx_buff_failed; 35362306a36Sopenharmony_ci u64 alloc_rx_page; 35462306a36Sopenharmony_ci u64 rx_ipsec; 35562306a36Sopenharmony_ci 35662306a36Sopenharmony_ci struct msix_entry *msix_entries; 35762306a36Sopenharmony_ci 35862306a36Sopenharmony_ci /* OS defined structs */ 35962306a36Sopenharmony_ci struct net_device *netdev; 36062306a36Sopenharmony_ci struct bpf_prog *xdp_prog; 36162306a36Sopenharmony_ci struct pci_dev *pdev; 36262306a36Sopenharmony_ci 36362306a36Sopenharmony_ci /* structs defined in ixgbe_vf.h */ 36462306a36Sopenharmony_ci struct ixgbe_hw hw; 36562306a36Sopenharmony_ci u16 msg_enable; 36662306a36Sopenharmony_ci /* Interrupt Throttle Rate */ 36762306a36Sopenharmony_ci u32 eitr_param; 36862306a36Sopenharmony_ci 36962306a36Sopenharmony_ci struct ixgbevf_hw_stats stats; 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_ci unsigned long state; 37262306a36Sopenharmony_ci u64 tx_busy; 37362306a36Sopenharmony_ci unsigned int tx_ring_count; 37462306a36Sopenharmony_ci unsigned int xdp_ring_count; 37562306a36Sopenharmony_ci unsigned int rx_ring_count; 37662306a36Sopenharmony_ci 37762306a36Sopenharmony_ci u8 __iomem *io_addr; /* Mainly for iounmap use */ 37862306a36Sopenharmony_ci u32 link_speed; 37962306a36Sopenharmony_ci bool link_up; 38062306a36Sopenharmony_ci 38162306a36Sopenharmony_ci struct timer_list service_timer; 38262306a36Sopenharmony_ci struct work_struct service_task; 38362306a36Sopenharmony_ci 38462306a36Sopenharmony_ci spinlock_t mbx_lock; 38562306a36Sopenharmony_ci unsigned long last_reset; 38662306a36Sopenharmony_ci 38762306a36Sopenharmony_ci u32 *rss_key; 38862306a36Sopenharmony_ci u8 rss_indir_tbl[IXGBEVF_X550_VFRETA_SIZE]; 38962306a36Sopenharmony_ci u32 flags; 39062306a36Sopenharmony_ci bool link_state; 39162306a36Sopenharmony_ci 39262306a36Sopenharmony_ci#define IXGBEVF_FLAGS_LEGACY_RX BIT(1) 39362306a36Sopenharmony_ci 39462306a36Sopenharmony_ci#ifdef CONFIG_XFRM 39562306a36Sopenharmony_ci struct ixgbevf_ipsec *ipsec; 39662306a36Sopenharmony_ci#endif /* CONFIG_XFRM */ 39762306a36Sopenharmony_ci}; 39862306a36Sopenharmony_ci 39962306a36Sopenharmony_cienum ixbgevf_state_t { 40062306a36Sopenharmony_ci __IXGBEVF_TESTING, 40162306a36Sopenharmony_ci __IXGBEVF_RESETTING, 40262306a36Sopenharmony_ci __IXGBEVF_DOWN, 40362306a36Sopenharmony_ci __IXGBEVF_DISABLED, 40462306a36Sopenharmony_ci __IXGBEVF_REMOVING, 40562306a36Sopenharmony_ci __IXGBEVF_SERVICE_SCHED, 40662306a36Sopenharmony_ci __IXGBEVF_SERVICE_INITED, 40762306a36Sopenharmony_ci __IXGBEVF_RESET_REQUESTED, 40862306a36Sopenharmony_ci __IXGBEVF_QUEUE_RESET_REQUESTED, 40962306a36Sopenharmony_ci}; 41062306a36Sopenharmony_ci 41162306a36Sopenharmony_cienum ixgbevf_boards { 41262306a36Sopenharmony_ci board_82599_vf, 41362306a36Sopenharmony_ci board_82599_vf_hv, 41462306a36Sopenharmony_ci board_X540_vf, 41562306a36Sopenharmony_ci board_X540_vf_hv, 41662306a36Sopenharmony_ci board_X550_vf, 41762306a36Sopenharmony_ci board_X550_vf_hv, 41862306a36Sopenharmony_ci board_X550EM_x_vf, 41962306a36Sopenharmony_ci board_X550EM_x_vf_hv, 42062306a36Sopenharmony_ci board_x550em_a_vf, 42162306a36Sopenharmony_ci}; 42262306a36Sopenharmony_ci 42362306a36Sopenharmony_cienum ixgbevf_xcast_modes { 42462306a36Sopenharmony_ci IXGBEVF_XCAST_MODE_NONE = 0, 42562306a36Sopenharmony_ci IXGBEVF_XCAST_MODE_MULTI, 42662306a36Sopenharmony_ci IXGBEVF_XCAST_MODE_ALLMULTI, 42762306a36Sopenharmony_ci IXGBEVF_XCAST_MODE_PROMISC, 42862306a36Sopenharmony_ci}; 42962306a36Sopenharmony_ci 43062306a36Sopenharmony_ciextern const struct ixgbevf_info ixgbevf_82599_vf_info; 43162306a36Sopenharmony_ciextern const struct ixgbevf_info ixgbevf_X540_vf_info; 43262306a36Sopenharmony_ciextern const struct ixgbevf_info ixgbevf_X550_vf_info; 43362306a36Sopenharmony_ciextern const struct ixgbevf_info ixgbevf_X550EM_x_vf_info; 43462306a36Sopenharmony_ciextern const struct ixgbe_mbx_operations ixgbevf_mbx_ops; 43562306a36Sopenharmony_ciextern const struct ixgbe_mbx_operations ixgbevf_mbx_ops_legacy; 43662306a36Sopenharmony_ciextern const struct ixgbevf_info ixgbevf_x550em_a_vf_info; 43762306a36Sopenharmony_ci 43862306a36Sopenharmony_ciextern const struct ixgbevf_info ixgbevf_82599_vf_hv_info; 43962306a36Sopenharmony_ciextern const struct ixgbevf_info ixgbevf_X540_vf_hv_info; 44062306a36Sopenharmony_ciextern const struct ixgbevf_info ixgbevf_X550_vf_hv_info; 44162306a36Sopenharmony_ciextern const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info; 44262306a36Sopenharmony_ciextern const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops; 44362306a36Sopenharmony_ci 44462306a36Sopenharmony_ci/* needed by ethtool.c */ 44562306a36Sopenharmony_ciextern const char ixgbevf_driver_name[]; 44662306a36Sopenharmony_ci 44762306a36Sopenharmony_ciint ixgbevf_open(struct net_device *netdev); 44862306a36Sopenharmony_ciint ixgbevf_close(struct net_device *netdev); 44962306a36Sopenharmony_civoid ixgbevf_up(struct ixgbevf_adapter *adapter); 45062306a36Sopenharmony_civoid ixgbevf_down(struct ixgbevf_adapter *adapter); 45162306a36Sopenharmony_civoid ixgbevf_reinit_locked(struct ixgbevf_adapter *adapter); 45262306a36Sopenharmony_civoid ixgbevf_reset(struct ixgbevf_adapter *adapter); 45362306a36Sopenharmony_civoid ixgbevf_set_ethtool_ops(struct net_device *netdev); 45462306a36Sopenharmony_ciint ixgbevf_setup_rx_resources(struct ixgbevf_adapter *adapter, 45562306a36Sopenharmony_ci struct ixgbevf_ring *rx_ring); 45662306a36Sopenharmony_ciint ixgbevf_setup_tx_resources(struct ixgbevf_ring *); 45762306a36Sopenharmony_civoid ixgbevf_free_rx_resources(struct ixgbevf_ring *); 45862306a36Sopenharmony_civoid ixgbevf_free_tx_resources(struct ixgbevf_ring *); 45962306a36Sopenharmony_civoid ixgbevf_update_stats(struct ixgbevf_adapter *adapter); 46062306a36Sopenharmony_ciint ethtool_ioctl(struct ifreq *ifr); 46162306a36Sopenharmony_ci 46262306a36Sopenharmony_ciextern void ixgbevf_write_eitr(struct ixgbevf_q_vector *q_vector); 46362306a36Sopenharmony_ci 46462306a36Sopenharmony_ci#ifdef CONFIG_IXGBEVF_IPSEC 46562306a36Sopenharmony_civoid ixgbevf_init_ipsec_offload(struct ixgbevf_adapter *adapter); 46662306a36Sopenharmony_civoid ixgbevf_stop_ipsec_offload(struct ixgbevf_adapter *adapter); 46762306a36Sopenharmony_civoid ixgbevf_ipsec_restore(struct ixgbevf_adapter *adapter); 46862306a36Sopenharmony_civoid ixgbevf_ipsec_rx(struct ixgbevf_ring *rx_ring, 46962306a36Sopenharmony_ci union ixgbe_adv_rx_desc *rx_desc, 47062306a36Sopenharmony_ci struct sk_buff *skb); 47162306a36Sopenharmony_ciint ixgbevf_ipsec_tx(struct ixgbevf_ring *tx_ring, 47262306a36Sopenharmony_ci struct ixgbevf_tx_buffer *first, 47362306a36Sopenharmony_ci struct ixgbevf_ipsec_tx_data *itd); 47462306a36Sopenharmony_ci#else 47562306a36Sopenharmony_cistatic inline void ixgbevf_init_ipsec_offload(struct ixgbevf_adapter *adapter) 47662306a36Sopenharmony_ci{ } 47762306a36Sopenharmony_cistatic inline void ixgbevf_stop_ipsec_offload(struct ixgbevf_adapter *adapter) 47862306a36Sopenharmony_ci{ } 47962306a36Sopenharmony_cistatic inline void ixgbevf_ipsec_restore(struct ixgbevf_adapter *adapter) { } 48062306a36Sopenharmony_cistatic inline void ixgbevf_ipsec_rx(struct ixgbevf_ring *rx_ring, 48162306a36Sopenharmony_ci union ixgbe_adv_rx_desc *rx_desc, 48262306a36Sopenharmony_ci struct sk_buff *skb) { } 48362306a36Sopenharmony_cistatic inline int ixgbevf_ipsec_tx(struct ixgbevf_ring *tx_ring, 48462306a36Sopenharmony_ci struct ixgbevf_tx_buffer *first, 48562306a36Sopenharmony_ci struct ixgbevf_ipsec_tx_data *itd) 48662306a36Sopenharmony_ci{ return 0; } 48762306a36Sopenharmony_ci#endif /* CONFIG_IXGBEVF_IPSEC */ 48862306a36Sopenharmony_ci 48962306a36Sopenharmony_ci#define ixgbevf_hw_to_netdev(hw) \ 49062306a36Sopenharmony_ci (((struct ixgbevf_adapter *)(hw)->back)->netdev) 49162306a36Sopenharmony_ci 49262306a36Sopenharmony_ci#define hw_dbg(hw, format, arg...) \ 49362306a36Sopenharmony_ci netdev_dbg(ixgbevf_hw_to_netdev(hw), format, ## arg) 49462306a36Sopenharmony_ci 49562306a36Sopenharmony_cis32 ixgbevf_poll_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size); 49662306a36Sopenharmony_cis32 ixgbevf_write_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size); 49762306a36Sopenharmony_ci 49862306a36Sopenharmony_ci#endif /* _IXGBEVF_H_ */ 499