1ae06c70bSJeff Kirsher /* SPDX-License-Identifier: GPL-2.0 */
251dce24bSJeff Kirsher /* Copyright(c) 1999 - 2018 Intel Corporation. */
3dee1ad47SJeff Kirsher
4dee1ad47SJeff Kirsher #ifndef _IXGBEVF_H_
5dee1ad47SJeff Kirsher #define _IXGBEVF_H_
6dee1ad47SJeff Kirsher
7dee1ad47SJeff Kirsher #include <linux/types.h>
8dee1ad47SJeff Kirsher #include <linux/bitops.h>
9dee1ad47SJeff Kirsher #include <linux/timer.h>
10dee1ad47SJeff Kirsher #include <linux/io.h>
11dee1ad47SJeff Kirsher #include <linux/netdevice.h>
12dee1ad47SJeff Kirsher #include <linux/if_vlan.h>
134197aa7bSEric Dumazet #include <linux/u64_stats_sync.h>
14c7aec596STony Nguyen #include <net/xdp.h>
15dee1ad47SJeff Kirsher
16dee1ad47SJeff Kirsher #include "vf.h"
170062e7ccSShannon Nelson #include "ipsec.h"
18dee1ad47SJeff Kirsher
19e08400b7SEmil Tantilov #define IXGBE_MAX_TXD_PWR 14
20e08400b7SEmil Tantilov #define IXGBE_MAX_DATA_PER_TXD BIT(IXGBE_MAX_TXD_PWR)
21e08400b7SEmil Tantilov
22e08400b7SEmil Tantilov /* Tx Descriptors needed, worst case */
23e08400b7SEmil Tantilov #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IXGBE_MAX_DATA_PER_TXD)
24e08400b7SEmil Tantilov #define DESC_NEEDED (MAX_SKB_FRAGS + 4)
25e08400b7SEmil Tantilov
26dee1ad47SJeff Kirsher /* wrapper around a pointer to a socket buffer,
27dec0d8e4SJeff Kirsher * so a DMA handle can be stored along with the buffer
28dec0d8e4SJeff Kirsher */
29dee1ad47SJeff Kirsher struct ixgbevf_tx_buffer {
30e757e3e1SAlexander Duyck union ixgbe_adv_tx_desc *next_to_watch;
317ad1a093SEmil Tantilov unsigned long time_stamp;
3221092e9cSTony Nguyen union {
337ad1a093SEmil Tantilov struct sk_buff *skb;
3421092e9cSTony Nguyen /* XDP uses address ptr on irq_clean */
3521092e9cSTony Nguyen void *data;
3621092e9cSTony Nguyen };
377ad1a093SEmil Tantilov unsigned int bytecount;
387ad1a093SEmil Tantilov unsigned short gso_segs;
397ad1a093SEmil Tantilov __be16 protocol;
409bdfefd2SEmil Tantilov DEFINE_DMA_UNMAP_ADDR(dma);
419bdfefd2SEmil Tantilov DEFINE_DMA_UNMAP_LEN(len);
427ad1a093SEmil Tantilov u32 tx_flags;
43dee1ad47SJeff Kirsher };
44dee1ad47SJeff Kirsher
45dee1ad47SJeff Kirsher struct ixgbevf_rx_buffer {
46dee1ad47SJeff Kirsher dma_addr_t dma;
47bad17234SEmil Tantilov struct page *page;
4835074d69SEmil Tantilov #if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536)
4935074d69SEmil Tantilov __u32 page_offset;
5035074d69SEmil Tantilov #else
5135074d69SEmil Tantilov __u16 page_offset;
5235074d69SEmil Tantilov #endif
5335074d69SEmil Tantilov __u16 pagecnt_bias;
54dee1ad47SJeff Kirsher };
55dee1ad47SJeff Kirsher
56095e2617SEmil Tantilov struct ixgbevf_stats {
57095e2617SEmil Tantilov u64 packets;
58095e2617SEmil Tantilov u64 bytes;
59095e2617SEmil Tantilov };
60095e2617SEmil Tantilov
61095e2617SEmil Tantilov struct ixgbevf_tx_queue_stats {
62095e2617SEmil Tantilov u64 restart_queue;
63095e2617SEmil Tantilov u64 tx_busy;
64095e2617SEmil Tantilov u64 tx_done_old;
65095e2617SEmil Tantilov };
66095e2617SEmil Tantilov
67095e2617SEmil Tantilov struct ixgbevf_rx_queue_stats {
68095e2617SEmil Tantilov u64 alloc_rx_page_failed;
69095e2617SEmil Tantilov u64 alloc_rx_buff_failed;
702a35efe5SEmil Tantilov u64 alloc_rx_page;
71095e2617SEmil Tantilov u64 csum_err;
72095e2617SEmil Tantilov };
73095e2617SEmil Tantilov
74e08400b7SEmil Tantilov enum ixgbevf_ring_state_t {
75f15c5ba5SEmil Tantilov __IXGBEVF_RX_3K_BUFFER,
761ab37e12SEmil Tantilov __IXGBEVF_RX_BUILD_SKB_ENABLED,
77e08400b7SEmil Tantilov __IXGBEVF_TX_DETECT_HANG,
78e08400b7SEmil Tantilov __IXGBEVF_HANG_CHECK_ARMED,
7921092e9cSTony Nguyen __IXGBEVF_TX_XDP_RING,
804be87727SAlexander Duyck __IXGBEVF_TX_XDP_RING_PRIMED,
81e08400b7SEmil Tantilov };
82e08400b7SEmil Tantilov
8321092e9cSTony Nguyen #define ring_is_xdp(ring) \
8421092e9cSTony Nguyen test_bit(__IXGBEVF_TX_XDP_RING, &(ring)->state)
8521092e9cSTony Nguyen #define set_ring_xdp(ring) \
8621092e9cSTony Nguyen set_bit(__IXGBEVF_TX_XDP_RING, &(ring)->state)
8721092e9cSTony Nguyen #define clear_ring_xdp(ring) \
8821092e9cSTony Nguyen clear_bit(__IXGBEVF_TX_XDP_RING, &(ring)->state)
8921092e9cSTony Nguyen
90dee1ad47SJeff Kirsher struct ixgbevf_ring {
916b43c446SAlexander Duyck struct ixgbevf_ring *next;
9221c046e4SEmil Tantilov struct ixgbevf_q_vector *q_vector; /* backpointer to q_vector */
93fb40195cSAlexander Duyck struct net_device *netdev;
94c7aec596STony Nguyen struct bpf_prog *xdp_prog;
95fb40195cSAlexander Duyck struct device *dev;
96dee1ad47SJeff Kirsher void *desc; /* descriptor ring memory */
97dee1ad47SJeff Kirsher dma_addr_t dma; /* phys. address of descriptor ring */
98dee1ad47SJeff Kirsher unsigned int size; /* length in bytes */
99bad17234SEmil Tantilov u16 count; /* amount of descriptors */
100bad17234SEmil Tantilov u16 next_to_use;
101bad17234SEmil Tantilov u16 next_to_clean;
102bad17234SEmil Tantilov u16 next_to_alloc;
103dee1ad47SJeff Kirsher
104dee1ad47SJeff Kirsher union {
105dee1ad47SJeff Kirsher struct ixgbevf_tx_buffer *tx_buffer_info;
106dee1ad47SJeff Kirsher struct ixgbevf_rx_buffer *rx_buffer_info;
107dee1ad47SJeff Kirsher };
108e08400b7SEmil Tantilov unsigned long state;
109095e2617SEmil Tantilov struct ixgbevf_stats stats;
1104197aa7bSEric Dumazet struct u64_stats_sync syncp;
111095e2617SEmil Tantilov union {
112095e2617SEmil Tantilov struct ixgbevf_tx_queue_stats tx_stats;
113095e2617SEmil Tantilov struct ixgbevf_rx_queue_stats rx_stats;
114095e2617SEmil Tantilov };
115c7aec596STony Nguyen struct xdp_rxq_info xdp_rxq;
11655fb277cSGreg Rose u64 hw_csum_rx_error;
1175cdab2f6SDon Skidmore u8 __iomem *tail;
118bad17234SEmil Tantilov struct sk_buff *skb;
119dee1ad47SJeff Kirsher
120dec0d8e4SJeff Kirsher /* holds the special value that gets the hardware register offset
121dec0d8e4SJeff Kirsher * associated with this ring, which is different for DCB and RSS modes
122dec0d8e4SJeff Kirsher */
123dec0d8e4SJeff Kirsher u16 reg_idx;
124095e2617SEmil Tantilov int queue_index; /* needed for multiqueue queue management */
12521c046e4SEmil Tantilov } ____cacheline_internodealigned_in_smp;
126dee1ad47SJeff Kirsher
127dee1ad47SJeff Kirsher /* How many Rx Buffers do we bundle into one write to the hardware ? */
128dee1ad47SJeff Kirsher #define IXGBEVF_RX_BUFFER_WRITE 16 /* Must be power of 2 */
129dee1ad47SJeff Kirsher
13056e94095SAlexander Duyck #define MAX_RX_QUEUES IXGBE_VF_MAX_RX_QUEUES
13156e94095SAlexander Duyck #define MAX_TX_QUEUES IXGBE_VF_MAX_TX_QUEUES
13221092e9cSTony Nguyen #define MAX_XDP_QUEUES IXGBE_VF_MAX_TX_QUEUES
1332dc571aaSEmil Tantilov #define IXGBEVF_MAX_RSS_QUEUES 2
1349cba434fSEmil Tantilov #define IXGBEVF_82599_RETA_SIZE 128 /* 128 entries */
1359cba434fSEmil Tantilov #define IXGBEVF_X550_VFRETA_SIZE 64 /* 64 entries */
136ad1431e2SVlad Zolotarov #define IXGBEVF_RSS_HASH_KEY_SIZE 40
1379cba434fSEmil Tantilov #define IXGBEVF_VFRSSRK_REGS 10 /* 10 registers for RSS key */
138dee1ad47SJeff Kirsher
139dee1ad47SJeff Kirsher #define IXGBEVF_DEFAULT_TXD 1024
140dee1ad47SJeff Kirsher #define IXGBEVF_DEFAULT_RXD 512
141dee1ad47SJeff Kirsher #define IXGBEVF_MAX_TXD 4096
142dee1ad47SJeff Kirsher #define IXGBEVF_MIN_TXD 64
143dee1ad47SJeff Kirsher #define IXGBEVF_MAX_RXD 4096
144dee1ad47SJeff Kirsher #define IXGBEVF_MIN_RXD 64
145dee1ad47SJeff Kirsher
146dee1ad47SJeff Kirsher /* Supported Rx Buffer Sizes */
147dee1ad47SJeff Kirsher #define IXGBEVF_RXBUFFER_256 256 /* Used for packet split */
148bad17234SEmil Tantilov #define IXGBEVF_RXBUFFER_2048 2048
149f15c5ba5SEmil Tantilov #define IXGBEVF_RXBUFFER_3072 3072
150dee1ad47SJeff Kirsher
151dee1ad47SJeff Kirsher #define IXGBEVF_RX_HDR_SIZE IXGBEVF_RXBUFFER_256
152dee1ad47SJeff Kirsher
153dee1ad47SJeff Kirsher #define MAXIMUM_ETHERNET_VLAN_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
154dee1ad47SJeff Kirsher
155f15c5ba5SEmil Tantilov #define IXGBEVF_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN)
156f15c5ba5SEmil Tantilov #if (PAGE_SIZE < 8192)
157f15c5ba5SEmil Tantilov #define IXGBEVF_MAX_FRAME_BUILD_SKB \
158f15c5ba5SEmil Tantilov (SKB_WITH_OVERHEAD(IXGBEVF_RXBUFFER_2048) - IXGBEVF_SKB_PAD)
159f15c5ba5SEmil Tantilov #else
160f15c5ba5SEmil Tantilov #define IXGBEVF_MAX_FRAME_BUILD_SKB IXGBEVF_RXBUFFER_2048
161f15c5ba5SEmil Tantilov #endif
162f15c5ba5SEmil Tantilov
1638d055cc0SJacob Keller #define IXGBE_TX_FLAGS_CSUM BIT(0)
1648d055cc0SJacob Keller #define IXGBE_TX_FLAGS_VLAN BIT(1)
1658d055cc0SJacob Keller #define IXGBE_TX_FLAGS_TSO BIT(2)
1668d055cc0SJacob Keller #define IXGBE_TX_FLAGS_IPV4 BIT(3)
1670062e7ccSShannon Nelson #define IXGBE_TX_FLAGS_IPSEC BIT(4)
168dee1ad47SJeff Kirsher #define IXGBE_TX_FLAGS_VLAN_MASK 0xffff0000
169dee1ad47SJeff Kirsher #define IXGBE_TX_FLAGS_VLAN_PRIO_MASK 0x0000e000
170dee1ad47SJeff Kirsher #define IXGBE_TX_FLAGS_VLAN_SHIFT 16
171dee1ad47SJeff Kirsher
172f15c5ba5SEmil Tantilov #define ring_uses_large_buffer(ring) \
173f15c5ba5SEmil Tantilov test_bit(__IXGBEVF_RX_3K_BUFFER, &(ring)->state)
174f15c5ba5SEmil Tantilov #define set_ring_uses_large_buffer(ring) \
175f15c5ba5SEmil Tantilov set_bit(__IXGBEVF_RX_3K_BUFFER, &(ring)->state)
176f15c5ba5SEmil Tantilov #define clear_ring_uses_large_buffer(ring) \
177f15c5ba5SEmil Tantilov clear_bit(__IXGBEVF_RX_3K_BUFFER, &(ring)->state)
178f15c5ba5SEmil Tantilov
1791ab37e12SEmil Tantilov #define ring_uses_build_skb(ring) \
1801ab37e12SEmil Tantilov test_bit(__IXGBEVF_RX_BUILD_SKB_ENABLED, &(ring)->state)
1811ab37e12SEmil Tantilov #define set_ring_build_skb_enabled(ring) \
1821ab37e12SEmil Tantilov set_bit(__IXGBEVF_RX_BUILD_SKB_ENABLED, &(ring)->state)
1831ab37e12SEmil Tantilov #define clear_ring_build_skb_enabled(ring) \
1841ab37e12SEmil Tantilov clear_bit(__IXGBEVF_RX_BUILD_SKB_ENABLED, &(ring)->state)
1851ab37e12SEmil Tantilov
ixgbevf_rx_bufsz(struct ixgbevf_ring * ring)186f15c5ba5SEmil Tantilov static inline unsigned int ixgbevf_rx_bufsz(struct ixgbevf_ring *ring)
187f15c5ba5SEmil Tantilov {
188f15c5ba5SEmil Tantilov #if (PAGE_SIZE < 8192)
189f15c5ba5SEmil Tantilov if (ring_uses_large_buffer(ring))
190f15c5ba5SEmil Tantilov return IXGBEVF_RXBUFFER_3072;
1911ab37e12SEmil Tantilov
1921ab37e12SEmil Tantilov if (ring_uses_build_skb(ring))
1931ab37e12SEmil Tantilov return IXGBEVF_MAX_FRAME_BUILD_SKB;
194f15c5ba5SEmil Tantilov #endif
195f15c5ba5SEmil Tantilov return IXGBEVF_RXBUFFER_2048;
196f15c5ba5SEmil Tantilov }
197f15c5ba5SEmil Tantilov
ixgbevf_rx_pg_order(struct ixgbevf_ring * ring)198f15c5ba5SEmil Tantilov static inline unsigned int ixgbevf_rx_pg_order(struct ixgbevf_ring *ring)
199f15c5ba5SEmil Tantilov {
200f15c5ba5SEmil Tantilov #if (PAGE_SIZE < 8192)
201f15c5ba5SEmil Tantilov if (ring_uses_large_buffer(ring))
202f15c5ba5SEmil Tantilov return 1;
203f15c5ba5SEmil Tantilov #endif
204f15c5ba5SEmil Tantilov return 0;
205f15c5ba5SEmil Tantilov }
206f15c5ba5SEmil Tantilov
207f15c5ba5SEmil Tantilov #define ixgbevf_rx_pg_size(_ring) (PAGE_SIZE << ixgbevf_rx_pg_order(_ring))
208f15c5ba5SEmil Tantilov
209f15c5ba5SEmil Tantilov #define check_for_tx_hang(ring) \
210f15c5ba5SEmil Tantilov test_bit(__IXGBEVF_TX_DETECT_HANG, &(ring)->state)
211f15c5ba5SEmil Tantilov #define set_check_for_tx_hang(ring) \
212f15c5ba5SEmil Tantilov set_bit(__IXGBEVF_TX_DETECT_HANG, &(ring)->state)
213f15c5ba5SEmil Tantilov #define clear_check_for_tx_hang(ring) \
214f15c5ba5SEmil Tantilov clear_bit(__IXGBEVF_TX_DETECT_HANG, &(ring)->state)
215f15c5ba5SEmil Tantilov
2166b43c446SAlexander Duyck struct ixgbevf_ring_container {
2176b43c446SAlexander Duyck struct ixgbevf_ring *ring; /* pointer to linked list of rings */
2185f3600ebSAlexander Duyck unsigned int total_bytes; /* total bytes processed this int */
2195f3600ebSAlexander Duyck unsigned int total_packets; /* total packets processed this int */
2206b43c446SAlexander Duyck u8 count; /* total number of rings in vector */
2216b43c446SAlexander Duyck u8 itr; /* current ITR setting for ring */
2226b43c446SAlexander Duyck };
2236b43c446SAlexander Duyck
2246b43c446SAlexander Duyck /* iterator for handling rings in ring container */
2256b43c446SAlexander Duyck #define ixgbevf_for_each_ring(pos, head) \
2266b43c446SAlexander Duyck for (pos = (head).ring; pos != NULL; pos = pos->next)
2276b43c446SAlexander Duyck
228dee1ad47SJeff Kirsher /* MAX_MSIX_Q_VECTORS of these are allocated,
229dee1ad47SJeff Kirsher * but we only use one per queue-specific vector.
230dee1ad47SJeff Kirsher */
231dee1ad47SJeff Kirsher struct ixgbevf_q_vector {
232dee1ad47SJeff Kirsher struct ixgbevf_adapter *adapter;
233dec0d8e4SJeff Kirsher /* index of q_vector within array, also used for finding the bit in
234dec0d8e4SJeff Kirsher * EICR and friends that represents the vector for this ring
235dec0d8e4SJeff Kirsher */
236dec0d8e4SJeff Kirsher u16 v_idx;
2375f3600ebSAlexander Duyck u16 itr; /* Interrupt throttle rate written to EITR */
238dee1ad47SJeff Kirsher struct napi_struct napi;
2396b43c446SAlexander Duyck struct ixgbevf_ring_container rx, tx;
24021c046e4SEmil Tantilov struct rcu_head rcu; /* to avoid race with update stats on free */
241fa71ae27SAlexander Duyck char name[IFNAMSIZ + 9];
24221c046e4SEmil Tantilov
24321c046e4SEmil Tantilov /* for dynamic allocation of rings associated with this q_vector */
24421c046e4SEmil Tantilov struct ixgbevf_ring ring[0] ____cacheline_internodealigned_in_smp;
245c777cdfaSJacob Keller #ifdef CONFIG_NET_RX_BUSY_POLL
246c777cdfaSJacob Keller unsigned int state;
247c777cdfaSJacob Keller #define IXGBEVF_QV_STATE_IDLE 0
248c777cdfaSJacob Keller #define IXGBEVF_QV_STATE_NAPI 1 /* NAPI owns this QV */
249c777cdfaSJacob Keller #define IXGBEVF_QV_STATE_POLL 2 /* poll owns this QV */
250c777cdfaSJacob Keller #define IXGBEVF_QV_STATE_DISABLED 4 /* QV is disabled */
251c777cdfaSJacob Keller #define IXGBEVF_QV_OWNED (IXGBEVF_QV_STATE_NAPI | IXGBEVF_QV_STATE_POLL)
252c777cdfaSJacob Keller #define IXGBEVF_QV_LOCKED (IXGBEVF_QV_OWNED | IXGBEVF_QV_STATE_DISABLED)
253c777cdfaSJacob Keller #define IXGBEVF_QV_STATE_NAPI_YIELD 8 /* NAPI yielded this QV */
254c777cdfaSJacob Keller #define IXGBEVF_QV_STATE_POLL_YIELD 16 /* poll yielded this QV */
255dec0d8e4SJeff Kirsher #define IXGBEVF_QV_YIELD (IXGBEVF_QV_STATE_NAPI_YIELD | \
256dec0d8e4SJeff Kirsher IXGBEVF_QV_STATE_POLL_YIELD)
257dec0d8e4SJeff Kirsher #define IXGBEVF_QV_USER_PEND (IXGBEVF_QV_STATE_POLL | \
258dec0d8e4SJeff Kirsher IXGBEVF_QV_STATE_POLL_YIELD)
259c777cdfaSJacob Keller spinlock_t lock;
260c777cdfaSJacob Keller #endif /* CONFIG_NET_RX_BUSY_POLL */
261dee1ad47SJeff Kirsher };
262dec0d8e4SJeff Kirsher
263dec0d8e4SJeff Kirsher /* microsecond values for various ITR rates shifted by 2 to fit itr register
2645f3600ebSAlexander Duyck * with the first 3 bits reserved 0
2655f3600ebSAlexander Duyck */
2665f3600ebSAlexander Duyck #define IXGBE_MIN_RSC_ITR 24
2675f3600ebSAlexander Duyck #define IXGBE_100K_ITR 40
2685f3600ebSAlexander Duyck #define IXGBE_20K_ITR 200
2698a9ca110SAlexander Duyck #define IXGBE_12K_ITR 336
2705f3600ebSAlexander Duyck
271dee1ad47SJeff Kirsher /* Helper macros to switch between ints/sec and what the register uses.
272dee1ad47SJeff Kirsher * And yes, it's the same math going both ways. The lowest value
273dee1ad47SJeff Kirsher * supported by all of the ixgbe hardware is 8.
274dee1ad47SJeff Kirsher */
275dee1ad47SJeff Kirsher #define EITR_INTS_PER_SEC_TO_REG(_eitr) \
276dee1ad47SJeff Kirsher ((_eitr) ? (1000000000 / ((_eitr) * 256)) : 8)
277dee1ad47SJeff Kirsher #define EITR_REG_TO_INTS_PER_SEC EITR_INTS_PER_SEC_TO_REG
278dee1ad47SJeff Kirsher
279ec62fe26SEmil Tantilov /* ixgbevf_test_staterr - tests bits in Rx descriptor status and error fields */
ixgbevf_test_staterr(union ixgbe_adv_rx_desc * rx_desc,const u32 stat_err_bits)280ec62fe26SEmil Tantilov static inline __le32 ixgbevf_test_staterr(union ixgbe_adv_rx_desc *rx_desc,
281ec62fe26SEmil Tantilov const u32 stat_err_bits)
282ec62fe26SEmil Tantilov {
283ec62fe26SEmil Tantilov return rx_desc->wb.upper.status_error & cpu_to_le32(stat_err_bits);
284ec62fe26SEmil Tantilov }
285ec62fe26SEmil Tantilov
ixgbevf_desc_unused(struct ixgbevf_ring * ring)286f880d07bSDon Skidmore static inline u16 ixgbevf_desc_unused(struct ixgbevf_ring *ring)
287f880d07bSDon Skidmore {
288f880d07bSDon Skidmore u16 ntc = ring->next_to_clean;
289f880d07bSDon Skidmore u16 ntu = ring->next_to_use;
290f880d07bSDon Skidmore
291f880d07bSDon Skidmore return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1;
292f880d07bSDon Skidmore }
293dee1ad47SJeff Kirsher
ixgbevf_write_tail(struct ixgbevf_ring * ring,u32 value)29406380db6SMark Rustad static inline void ixgbevf_write_tail(struct ixgbevf_ring *ring, u32 value)
29506380db6SMark Rustad {
29606380db6SMark Rustad writel(value, ring->tail);
29706380db6SMark Rustad }
29806380db6SMark Rustad
299908421f6SAlexander Duyck #define IXGBEVF_RX_DESC(R, i) \
300908421f6SAlexander Duyck (&(((union ixgbe_adv_rx_desc *)((R)->desc))[i]))
301908421f6SAlexander Duyck #define IXGBEVF_TX_DESC(R, i) \
302908421f6SAlexander Duyck (&(((union ixgbe_adv_tx_desc *)((R)->desc))[i]))
303908421f6SAlexander Duyck #define IXGBEVF_TX_CTXTDESC(R, i) \
304908421f6SAlexander Duyck (&(((struct ixgbe_adv_tx_context_desc *)((R)->desc))[i]))
305dee1ad47SJeff Kirsher
306c88887e0SAlexander Duyck #define IXGBE_MAX_JUMBO_FRAME_SIZE 9728 /* Maximum Supported Size 9.5KB */
307dee1ad47SJeff Kirsher
308dee1ad47SJeff Kirsher #define OTHER_VECTOR 1
309dee1ad47SJeff Kirsher #define NON_Q_VECTORS (OTHER_VECTOR)
310dee1ad47SJeff Kirsher
311dee1ad47SJeff Kirsher #define MAX_MSIX_Q_VECTORS 2
312dee1ad47SJeff Kirsher
313fa71ae27SAlexander Duyck #define MIN_MSIX_Q_VECTORS 1
314dee1ad47SJeff Kirsher #define MIN_MSIX_COUNT (MIN_MSIX_Q_VECTORS + NON_Q_VECTORS)
315dee1ad47SJeff Kirsher
31616b35949SEmil Tantilov #define IXGBEVF_RX_DMA_ATTR \
31716b35949SEmil Tantilov (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
31816b35949SEmil Tantilov
319dee1ad47SJeff Kirsher /* board specific private data structure */
320dee1ad47SJeff Kirsher struct ixgbevf_adapter {
321dff80520SEmil Tantilov /* this field must be first, see ixgbevf_process_skb_fields */
322dee1ad47SJeff Kirsher unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
323dff80520SEmil Tantilov
324dee1ad47SJeff Kirsher struct ixgbevf_q_vector *q_vector[MAX_MSIX_Q_VECTORS];
325dee1ad47SJeff Kirsher
326dee1ad47SJeff Kirsher /* Interrupt Throttle Rate */
3275f3600ebSAlexander Duyck u16 rx_itr_setting;
3285f3600ebSAlexander Duyck u16 tx_itr_setting;
3295f3600ebSAlexander Duyck
3305f3600ebSAlexander Duyck /* interrupt masks */
3315f3600ebSAlexander Duyck u32 eims_enable_mask;
3325f3600ebSAlexander Duyck u32 eims_other;
333dee1ad47SJeff Kirsher
33421092e9cSTony Nguyen /* XDP */
33521092e9cSTony Nguyen int num_xdp_queues;
33621092e9cSTony Nguyen struct ixgbevf_ring *xdp_ring[MAX_XDP_QUEUES];
33721092e9cSTony Nguyen
338dee1ad47SJeff Kirsher /* TX */
339dee1ad47SJeff Kirsher int num_tx_queues;
34097031922SEmil Tantilov struct ixgbevf_ring *tx_ring[MAX_TX_QUEUES]; /* One per active queue */
341dee1ad47SJeff Kirsher u64 restart_queue;
342dee1ad47SJeff Kirsher u32 tx_timeout_count;
3430062e7ccSShannon Nelson u64 tx_ipsec;
344dee1ad47SJeff Kirsher
345dee1ad47SJeff Kirsher /* RX */
346dee1ad47SJeff Kirsher int num_rx_queues;
34797031922SEmil Tantilov struct ixgbevf_ring *rx_ring[MAX_TX_QUEUES]; /* One per active queue */
348dee1ad47SJeff Kirsher u64 hw_csum_rx_error;
349dee1ad47SJeff Kirsher u64 hw_rx_no_dma_resources;
350dee1ad47SJeff Kirsher int num_msix_vectors;
3512a35efe5SEmil Tantilov u64 alloc_rx_page_failed;
3522a35efe5SEmil Tantilov u64 alloc_rx_buff_failed;
3532a35efe5SEmil Tantilov u64 alloc_rx_page;
3540062e7ccSShannon Nelson u64 rx_ipsec;
355dee1ad47SJeff Kirsher
35697031922SEmil Tantilov struct msix_entry *msix_entries;
35797031922SEmil Tantilov
358dee1ad47SJeff Kirsher /* OS defined structs */
359dee1ad47SJeff Kirsher struct net_device *netdev;
360c7aec596STony Nguyen struct bpf_prog *xdp_prog;
361dee1ad47SJeff Kirsher struct pci_dev *pdev;
362dee1ad47SJeff Kirsher
363dee1ad47SJeff Kirsher /* structs defined in ixgbe_vf.h */
364dee1ad47SJeff Kirsher struct ixgbe_hw hw;
365dee1ad47SJeff Kirsher u16 msg_enable;
366dee1ad47SJeff Kirsher /* Interrupt Throttle Rate */
367dee1ad47SJeff Kirsher u32 eitr_param;
368dee1ad47SJeff Kirsher
36997031922SEmil Tantilov struct ixgbevf_hw_stats stats;
37097031922SEmil Tantilov
371dee1ad47SJeff Kirsher unsigned long state;
372dee1ad47SJeff Kirsher u64 tx_busy;
373dee1ad47SJeff Kirsher unsigned int tx_ring_count;
37421092e9cSTony Nguyen unsigned int xdp_ring_count;
375dee1ad47SJeff Kirsher unsigned int rx_ring_count;
376dee1ad47SJeff Kirsher
377dbf8b0d8SMark Rustad u8 __iomem *io_addr; /* Mainly for iounmap use */
378dee1ad47SJeff Kirsher u32 link_speed;
379dee1ad47SJeff Kirsher bool link_up;
380dee1ad47SJeff Kirsher
3819ac5c5ccSEmil Tantilov struct timer_list service_timer;
3829ac5c5ccSEmil Tantilov struct work_struct service_task;
3839ac5c5ccSEmil Tantilov
3841c55ed76SAlexander Duyck spinlock_t mbx_lock;
385e66c92adSEmil Tantilov unsigned long last_reset;
3869cba434fSEmil Tantilov
387e60ae003STony Nguyen u32 *rss_key;
3889cba434fSEmil Tantilov u8 rss_indir_tbl[IXGBEVF_X550_VFRETA_SIZE];
389bc04347fSEmil Tantilov u32 flags;
390*443ebdd6SSlawomir Mrozowicz bool link_state;
391*443ebdd6SSlawomir Mrozowicz
392bc04347fSEmil Tantilov #define IXGBEVF_FLAGS_LEGACY_RX BIT(1)
3930062e7ccSShannon Nelson
3940062e7ccSShannon Nelson #ifdef CONFIG_XFRM
3950062e7ccSShannon Nelson struct ixgbevf_ipsec *ipsec;
3960062e7ccSShannon Nelson #endif /* CONFIG_XFRM */
397dee1ad47SJeff Kirsher };
398dee1ad47SJeff Kirsher
399dee1ad47SJeff Kirsher enum ixbgevf_state_t {
400dee1ad47SJeff Kirsher __IXGBEVF_TESTING,
401dee1ad47SJeff Kirsher __IXGBEVF_RESETTING,
4022e7cfbddSMark Rustad __IXGBEVF_DOWN,
403bc0c7151SMark Rustad __IXGBEVF_DISABLED,
4042e7cfbddSMark Rustad __IXGBEVF_REMOVING,
4059ac5c5ccSEmil Tantilov __IXGBEVF_SERVICE_SCHED,
4069ac5c5ccSEmil Tantilov __IXGBEVF_SERVICE_INITED,
407d5dd7c3fSEmil Tantilov __IXGBEVF_RESET_REQUESTED,
408d5dd7c3fSEmil Tantilov __IXGBEVF_QUEUE_RESET_REQUESTED,
409dee1ad47SJeff Kirsher };
410dee1ad47SJeff Kirsher
411dee1ad47SJeff Kirsher enum ixgbevf_boards {
412dee1ad47SJeff Kirsher board_82599_vf,
413c6d45171SKY Srinivasan board_82599_vf_hv,
414dee1ad47SJeff Kirsher board_X540_vf,
415c6d45171SKY Srinivasan board_X540_vf_hv,
41647068b0dSEmil Tantilov board_X550_vf,
417c6d45171SKY Srinivasan board_X550_vf_hv,
41847068b0dSEmil Tantilov board_X550EM_x_vf,
419c6d45171SKY Srinivasan board_X550EM_x_vf_hv,
4201d94f987SDon Skidmore board_x550em_a_vf,
421dee1ad47SJeff Kirsher };
422dee1ad47SJeff Kirsher
4238443c1a4SHiroshi Shimamoto enum ixgbevf_xcast_modes {
4248443c1a4SHiroshi Shimamoto IXGBEVF_XCAST_MODE_NONE = 0,
4258443c1a4SHiroshi Shimamoto IXGBEVF_XCAST_MODE_MULTI,
4268443c1a4SHiroshi Shimamoto IXGBEVF_XCAST_MODE_ALLMULTI,
42741e544cdSDon Skidmore IXGBEVF_XCAST_MODE_PROMISC,
4288443c1a4SHiroshi Shimamoto };
4298443c1a4SHiroshi Shimamoto
4303d8fe98fSStephen Hemminger extern const struct ixgbevf_info ixgbevf_82599_vf_info;
4313d8fe98fSStephen Hemminger extern const struct ixgbevf_info ixgbevf_X540_vf_info;
43247068b0dSEmil Tantilov extern const struct ixgbevf_info ixgbevf_X550_vf_info;
43347068b0dSEmil Tantilov extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_info;
434c8692598SRadoslaw Tyl extern const struct ixgbe_mbx_operations ixgbevf_mbx_ops;
4359c9463c2SRadoslaw Tyl extern const struct ixgbe_mbx_operations ixgbevf_mbx_ops_legacy;
4361d94f987SDon Skidmore extern const struct ixgbevf_info ixgbevf_x550em_a_vf_info;
437dee1ad47SJeff Kirsher
438c6d45171SKY Srinivasan extern const struct ixgbevf_info ixgbevf_82599_vf_hv_info;
439c6d45171SKY Srinivasan extern const struct ixgbevf_info ixgbevf_X540_vf_hv_info;
440c6d45171SKY Srinivasan extern const struct ixgbevf_info ixgbevf_X550_vf_hv_info;
441c6d45171SKY Srinivasan extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info;
442c6d45171SKY Srinivasan extern const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops;
443c6d45171SKY Srinivasan
444dee1ad47SJeff Kirsher /* needed by ethtool.c */
4453d8fe98fSStephen Hemminger extern const char ixgbevf_driver_name[];
446dee1ad47SJeff Kirsher
447324d0867SStefan Assmann int ixgbevf_open(struct net_device *netdev);
448324d0867SStefan Assmann int ixgbevf_close(struct net_device *netdev);
4495ccc921aSJoe Perches void ixgbevf_up(struct ixgbevf_adapter *adapter);
4505ccc921aSJoe Perches void ixgbevf_down(struct ixgbevf_adapter *adapter);
4515ccc921aSJoe Perches void ixgbevf_reinit_locked(struct ixgbevf_adapter *adapter);
4525ccc921aSJoe Perches void ixgbevf_reset(struct ixgbevf_adapter *adapter);
4535ccc921aSJoe Perches void ixgbevf_set_ethtool_ops(struct net_device *netdev);
454c7aec596STony Nguyen int ixgbevf_setup_rx_resources(struct ixgbevf_adapter *adapter,
455c7aec596STony Nguyen struct ixgbevf_ring *rx_ring);
45605d063aaSEmil Tantilov int ixgbevf_setup_tx_resources(struct ixgbevf_ring *);
45705d063aaSEmil Tantilov void ixgbevf_free_rx_resources(struct ixgbevf_ring *);
45805d063aaSEmil Tantilov void ixgbevf_free_tx_resources(struct ixgbevf_ring *);
4595ccc921aSJoe Perches void ixgbevf_update_stats(struct ixgbevf_adapter *adapter);
4605ccc921aSJoe Perches int ethtool_ioctl(struct ifreq *ifr);
461dee1ad47SJeff Kirsher
4623849623eSJacob Keller extern void ixgbevf_write_eitr(struct ixgbevf_q_vector *q_vector);
4633849623eSJacob Keller
46448e01e00SJeff Kirsher #ifdef CONFIG_IXGBEVF_IPSEC
4657f68d430SShannon Nelson void ixgbevf_init_ipsec_offload(struct ixgbevf_adapter *adapter);
4667f68d430SShannon Nelson void ixgbevf_stop_ipsec_offload(struct ixgbevf_adapter *adapter);
4677f68d430SShannon Nelson void ixgbevf_ipsec_restore(struct ixgbevf_adapter *adapter);
4687f68d430SShannon Nelson void ixgbevf_ipsec_rx(struct ixgbevf_ring *rx_ring,
4697f68d430SShannon Nelson union ixgbe_adv_rx_desc *rx_desc,
4707f68d430SShannon Nelson struct sk_buff *skb);
4717f68d430SShannon Nelson int ixgbevf_ipsec_tx(struct ixgbevf_ring *tx_ring,
4727f68d430SShannon Nelson struct ixgbevf_tx_buffer *first,
4737f68d430SShannon Nelson struct ixgbevf_ipsec_tx_data *itd);
4747f68d430SShannon Nelson #else
ixgbevf_init_ipsec_offload(struct ixgbevf_adapter * adapter)4757f68d430SShannon Nelson static inline void ixgbevf_init_ipsec_offload(struct ixgbevf_adapter *adapter)
4767f68d430SShannon Nelson { }
ixgbevf_stop_ipsec_offload(struct ixgbevf_adapter * adapter)4777f68d430SShannon Nelson static inline void ixgbevf_stop_ipsec_offload(struct ixgbevf_adapter *adapter)
4787f68d430SShannon Nelson { }
ixgbevf_ipsec_restore(struct ixgbevf_adapter * adapter)4797f68d430SShannon Nelson static inline void ixgbevf_ipsec_restore(struct ixgbevf_adapter *adapter) { }
ixgbevf_ipsec_rx(struct ixgbevf_ring * rx_ring,union ixgbe_adv_rx_desc * rx_desc,struct sk_buff * skb)4807f68d430SShannon Nelson static inline void ixgbevf_ipsec_rx(struct ixgbevf_ring *rx_ring,
4817f68d430SShannon Nelson union ixgbe_adv_rx_desc *rx_desc,
4827f68d430SShannon Nelson struct sk_buff *skb) { }
ixgbevf_ipsec_tx(struct ixgbevf_ring * tx_ring,struct ixgbevf_tx_buffer * first,struct ixgbevf_ipsec_tx_data * itd)4837f68d430SShannon Nelson static inline int ixgbevf_ipsec_tx(struct ixgbevf_ring *tx_ring,
4847f68d430SShannon Nelson struct ixgbevf_tx_buffer *first,
4857f68d430SShannon Nelson struct ixgbevf_ipsec_tx_data *itd)
4867f68d430SShannon Nelson { return 0; }
48748e01e00SJeff Kirsher #endif /* CONFIG_IXGBEVF_IPSEC */
4887f68d430SShannon Nelson
4894ad6af02SEmil Tantilov #define ixgbevf_hw_to_netdev(hw) \
4904ad6af02SEmil Tantilov (((struct ixgbevf_adapter *)(hw)->back)->netdev)
491dee1ad47SJeff Kirsher
4924ad6af02SEmil Tantilov #define hw_dbg(hw, format, arg...) \
4934ad6af02SEmil Tantilov netdev_dbg(ixgbevf_hw_to_netdev(hw), format, ## arg)
494c8692598SRadoslaw Tyl
495c8692598SRadoslaw Tyl s32 ixgbevf_poll_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size);
496c8692598SRadoslaw Tyl s32 ixgbevf_write_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size);
497c8692598SRadoslaw Tyl
498dee1ad47SJeff Kirsher #endif /* _IXGBEVF_H_ */
499