ixgbevf.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright(c) 1999 - 2018 Intel Corporation. */
  3. #ifndef _IXGBEVF_H_
  4. #define _IXGBEVF_H_
  5. #include <linux/types.h>
  6. #include <linux/bitops.h>
  7. #include <linux/timer.h>
  8. #include <linux/io.h>
  9. #include <linux/netdevice.h>
  10. #include <linux/if_vlan.h>
  11. #include <linux/u64_stats_sync.h>
  12. #include <net/xdp.h>
  13. #include "vf.h"
  14. #define IXGBE_MAX_TXD_PWR 14
  15. #define IXGBE_MAX_DATA_PER_TXD BIT(IXGBE_MAX_TXD_PWR)
  16. /* Tx Descriptors needed, worst case */
  17. #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IXGBE_MAX_DATA_PER_TXD)
  18. #define DESC_NEEDED (MAX_SKB_FRAGS + 4)
  19. /* wrapper around a pointer to a socket buffer,
  20. * so a DMA handle can be stored along with the buffer
  21. */
  22. struct ixgbevf_tx_buffer {
  23. union ixgbe_adv_tx_desc *next_to_watch;
  24. unsigned long time_stamp;
  25. union {
  26. struct sk_buff *skb;
  27. /* XDP uses address ptr on irq_clean */
  28. void *data;
  29. };
  30. unsigned int bytecount;
  31. unsigned short gso_segs;
  32. __be16 protocol;
  33. DEFINE_DMA_UNMAP_ADDR(dma);
  34. DEFINE_DMA_UNMAP_LEN(len);
  35. u32 tx_flags;
  36. };
  37. struct ixgbevf_rx_buffer {
  38. dma_addr_t dma;
  39. struct page *page;
  40. #if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536)
  41. __u32 page_offset;
  42. #else
  43. __u16 page_offset;
  44. #endif
  45. __u16 pagecnt_bias;
  46. };
  47. struct ixgbevf_stats {
  48. u64 packets;
  49. u64 bytes;
  50. };
  51. struct ixgbevf_tx_queue_stats {
  52. u64 restart_queue;
  53. u64 tx_busy;
  54. u64 tx_done_old;
  55. };
  56. struct ixgbevf_rx_queue_stats {
  57. u64 alloc_rx_page_failed;
  58. u64 alloc_rx_buff_failed;
  59. u64 alloc_rx_page;
  60. u64 csum_err;
  61. };
  62. enum ixgbevf_ring_state_t {
  63. __IXGBEVF_RX_3K_BUFFER,
  64. __IXGBEVF_RX_BUILD_SKB_ENABLED,
  65. __IXGBEVF_TX_DETECT_HANG,
  66. __IXGBEVF_HANG_CHECK_ARMED,
  67. __IXGBEVF_TX_XDP_RING,
  68. __IXGBEVF_TX_XDP_RING_PRIMED,
  69. };
  70. #define ring_is_xdp(ring) \
  71. test_bit(__IXGBEVF_TX_XDP_RING, &(ring)->state)
  72. #define set_ring_xdp(ring) \
  73. set_bit(__IXGBEVF_TX_XDP_RING, &(ring)->state)
  74. #define clear_ring_xdp(ring) \
  75. clear_bit(__IXGBEVF_TX_XDP_RING, &(ring)->state)
  76. struct ixgbevf_ring {
  77. struct ixgbevf_ring *next;
  78. struct ixgbevf_q_vector *q_vector; /* backpointer to q_vector */
  79. struct net_device *netdev;
  80. struct bpf_prog *xdp_prog;
  81. struct device *dev;
  82. void *desc; /* descriptor ring memory */
  83. dma_addr_t dma; /* phys. address of descriptor ring */
  84. unsigned int size; /* length in bytes */
  85. u16 count; /* amount of descriptors */
  86. u16 next_to_use;
  87. u16 next_to_clean;
  88. u16 next_to_alloc;
  89. union {
  90. struct ixgbevf_tx_buffer *tx_buffer_info;
  91. struct ixgbevf_rx_buffer *rx_buffer_info;
  92. };
  93. unsigned long state;
  94. struct ixgbevf_stats stats;
  95. struct u64_stats_sync syncp;
  96. union {
  97. struct ixgbevf_tx_queue_stats tx_stats;
  98. struct ixgbevf_rx_queue_stats rx_stats;
  99. };
  100. struct xdp_rxq_info xdp_rxq;
  101. u64 hw_csum_rx_error;
  102. u8 __iomem *tail;
  103. struct sk_buff *skb;
  104. /* holds the special value that gets the hardware register offset
  105. * associated with this ring, which is different for DCB and RSS modes
  106. */
  107. u16 reg_idx;
  108. int queue_index; /* needed for multiqueue queue management */
  109. } ____cacheline_internodealigned_in_smp;
  110. /* How many Rx Buffers do we bundle into one write to the hardware ? */
  111. #define IXGBEVF_RX_BUFFER_WRITE 16 /* Must be power of 2 */
  112. #define MAX_RX_QUEUES IXGBE_VF_MAX_RX_QUEUES
  113. #define MAX_TX_QUEUES IXGBE_VF_MAX_TX_QUEUES
  114. #define MAX_XDP_QUEUES IXGBE_VF_MAX_TX_QUEUES
  115. #define IXGBEVF_MAX_RSS_QUEUES 2
  116. #define IXGBEVF_82599_RETA_SIZE 128 /* 128 entries */
  117. #define IXGBEVF_X550_VFRETA_SIZE 64 /* 64 entries */
  118. #define IXGBEVF_RSS_HASH_KEY_SIZE 40
  119. #define IXGBEVF_VFRSSRK_REGS 10 /* 10 registers for RSS key */
  120. #define IXGBEVF_DEFAULT_TXD 1024
  121. #define IXGBEVF_DEFAULT_RXD 512
  122. #define IXGBEVF_MAX_TXD 4096
  123. #define IXGBEVF_MIN_TXD 64
  124. #define IXGBEVF_MAX_RXD 4096
  125. #define IXGBEVF_MIN_RXD 64
  126. /* Supported Rx Buffer Sizes */
  127. #define IXGBEVF_RXBUFFER_256 256 /* Used for packet split */
  128. #define IXGBEVF_RXBUFFER_2048 2048
  129. #define IXGBEVF_RXBUFFER_3072 3072
  130. #define IXGBEVF_RX_HDR_SIZE IXGBEVF_RXBUFFER_256
  131. #define MAXIMUM_ETHERNET_VLAN_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
  132. #define IXGBEVF_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN)
  133. #if (PAGE_SIZE < 8192)
  134. #define IXGBEVF_MAX_FRAME_BUILD_SKB \
  135. (SKB_WITH_OVERHEAD(IXGBEVF_RXBUFFER_2048) - IXGBEVF_SKB_PAD)
  136. #else
  137. #define IXGBEVF_MAX_FRAME_BUILD_SKB IXGBEVF_RXBUFFER_2048
  138. #endif
  139. #define IXGBE_TX_FLAGS_CSUM BIT(0)
  140. #define IXGBE_TX_FLAGS_VLAN BIT(1)
  141. #define IXGBE_TX_FLAGS_TSO BIT(2)
  142. #define IXGBE_TX_FLAGS_IPV4 BIT(3)
  143. #define IXGBE_TX_FLAGS_VLAN_MASK 0xffff0000
  144. #define IXGBE_TX_FLAGS_VLAN_PRIO_MASK 0x0000e000
  145. #define IXGBE_TX_FLAGS_VLAN_SHIFT 16
  146. #define ring_uses_large_buffer(ring) \
  147. test_bit(__IXGBEVF_RX_3K_BUFFER, &(ring)->state)
  148. #define set_ring_uses_large_buffer(ring) \
  149. set_bit(__IXGBEVF_RX_3K_BUFFER, &(ring)->state)
  150. #define clear_ring_uses_large_buffer(ring) \
  151. clear_bit(__IXGBEVF_RX_3K_BUFFER, &(ring)->state)
  152. #define ring_uses_build_skb(ring) \
  153. test_bit(__IXGBEVF_RX_BUILD_SKB_ENABLED, &(ring)->state)
  154. #define set_ring_build_skb_enabled(ring) \
  155. set_bit(__IXGBEVF_RX_BUILD_SKB_ENABLED, &(ring)->state)
  156. #define clear_ring_build_skb_enabled(ring) \
  157. clear_bit(__IXGBEVF_RX_BUILD_SKB_ENABLED, &(ring)->state)
  158. static inline unsigned int ixgbevf_rx_bufsz(struct ixgbevf_ring *ring)
  159. {
  160. #if (PAGE_SIZE < 8192)
  161. if (ring_uses_large_buffer(ring))
  162. return IXGBEVF_RXBUFFER_3072;
  163. if (ring_uses_build_skb(ring))
  164. return IXGBEVF_MAX_FRAME_BUILD_SKB;
  165. #endif
  166. return IXGBEVF_RXBUFFER_2048;
  167. }
  168. static inline unsigned int ixgbevf_rx_pg_order(struct ixgbevf_ring *ring)
  169. {
  170. #if (PAGE_SIZE < 8192)
  171. if (ring_uses_large_buffer(ring))
  172. return 1;
  173. #endif
  174. return 0;
  175. }
  176. #define ixgbevf_rx_pg_size(_ring) (PAGE_SIZE << ixgbevf_rx_pg_order(_ring))
  177. #define check_for_tx_hang(ring) \
  178. test_bit(__IXGBEVF_TX_DETECT_HANG, &(ring)->state)
  179. #define set_check_for_tx_hang(ring) \
  180. set_bit(__IXGBEVF_TX_DETECT_HANG, &(ring)->state)
  181. #define clear_check_for_tx_hang(ring) \
  182. clear_bit(__IXGBEVF_TX_DETECT_HANG, &(ring)->state)
  183. struct ixgbevf_ring_container {
  184. struct ixgbevf_ring *ring; /* pointer to linked list of rings */
  185. unsigned int total_bytes; /* total bytes processed this int */
  186. unsigned int total_packets; /* total packets processed this int */
  187. u8 count; /* total number of rings in vector */
  188. u8 itr; /* current ITR setting for ring */
  189. };
  190. /* iterator for handling rings in ring container */
  191. #define ixgbevf_for_each_ring(pos, head) \
  192. for (pos = (head).ring; pos != NULL; pos = pos->next)
  193. /* MAX_MSIX_Q_VECTORS of these are allocated,
  194. * but we only use one per queue-specific vector.
  195. */
  196. struct ixgbevf_q_vector {
  197. struct ixgbevf_adapter *adapter;
  198. /* index of q_vector within array, also used for finding the bit in
  199. * EICR and friends that represents the vector for this ring
  200. */
  201. u16 v_idx;
  202. u16 itr; /* Interrupt throttle rate written to EITR */
  203. struct napi_struct napi;
  204. struct ixgbevf_ring_container rx, tx;
  205. struct rcu_head rcu; /* to avoid race with update stats on free */
  206. char name[IFNAMSIZ + 9];
  207. /* for dynamic allocation of rings associated with this q_vector */
  208. struct ixgbevf_ring ring[0] ____cacheline_internodealigned_in_smp;
  209. #ifdef CONFIG_NET_RX_BUSY_POLL
  210. unsigned int state;
  211. #define IXGBEVF_QV_STATE_IDLE 0
  212. #define IXGBEVF_QV_STATE_NAPI 1 /* NAPI owns this QV */
  213. #define IXGBEVF_QV_STATE_POLL 2 /* poll owns this QV */
  214. #define IXGBEVF_QV_STATE_DISABLED 4 /* QV is disabled */
  215. #define IXGBEVF_QV_OWNED (IXGBEVF_QV_STATE_NAPI | IXGBEVF_QV_STATE_POLL)
  216. #define IXGBEVF_QV_LOCKED (IXGBEVF_QV_OWNED | IXGBEVF_QV_STATE_DISABLED)
  217. #define IXGBEVF_QV_STATE_NAPI_YIELD 8 /* NAPI yielded this QV */
  218. #define IXGBEVF_QV_STATE_POLL_YIELD 16 /* poll yielded this QV */
  219. #define IXGBEVF_QV_YIELD (IXGBEVF_QV_STATE_NAPI_YIELD | \
  220. IXGBEVF_QV_STATE_POLL_YIELD)
  221. #define IXGBEVF_QV_USER_PEND (IXGBEVF_QV_STATE_POLL | \
  222. IXGBEVF_QV_STATE_POLL_YIELD)
  223. spinlock_t lock;
  224. #endif /* CONFIG_NET_RX_BUSY_POLL */
  225. };
  226. /* microsecond values for various ITR rates shifted by 2 to fit itr register
  227. * with the first 3 bits reserved 0
  228. */
  229. #define IXGBE_MIN_RSC_ITR 24
  230. #define IXGBE_100K_ITR 40
  231. #define IXGBE_20K_ITR 200
  232. #define IXGBE_12K_ITR 336
  233. /* Helper macros to switch between ints/sec and what the register uses.
  234. * And yes, it's the same math going both ways. The lowest value
  235. * supported by all of the ixgbe hardware is 8.
  236. */
  237. #define EITR_INTS_PER_SEC_TO_REG(_eitr) \
  238. ((_eitr) ? (1000000000 / ((_eitr) * 256)) : 8)
  239. #define EITR_REG_TO_INTS_PER_SEC EITR_INTS_PER_SEC_TO_REG
  240. /* ixgbevf_test_staterr - tests bits in Rx descriptor status and error fields */
  241. static inline __le32 ixgbevf_test_staterr(union ixgbe_adv_rx_desc *rx_desc,
  242. const u32 stat_err_bits)
  243. {
  244. return rx_desc->wb.upper.status_error & cpu_to_le32(stat_err_bits);
  245. }
  246. static inline u16 ixgbevf_desc_unused(struct ixgbevf_ring *ring)
  247. {
  248. u16 ntc = ring->next_to_clean;
  249. u16 ntu = ring->next_to_use;
  250. return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1;
  251. }
  252. static inline void ixgbevf_write_tail(struct ixgbevf_ring *ring, u32 value)
  253. {
  254. writel(value, ring->tail);
  255. }
  256. #define IXGBEVF_RX_DESC(R, i) \
  257. (&(((union ixgbe_adv_rx_desc *)((R)->desc))[i]))
  258. #define IXGBEVF_TX_DESC(R, i) \
  259. (&(((union ixgbe_adv_tx_desc *)((R)->desc))[i]))
  260. #define IXGBEVF_TX_CTXTDESC(R, i) \
  261. (&(((struct ixgbe_adv_tx_context_desc *)((R)->desc))[i]))
  262. #define IXGBE_MAX_JUMBO_FRAME_SIZE 9728 /* Maximum Supported Size 9.5KB */
  263. #define OTHER_VECTOR 1
  264. #define NON_Q_VECTORS (OTHER_VECTOR)
  265. #define MAX_MSIX_Q_VECTORS 2
  266. #define MIN_MSIX_Q_VECTORS 1
  267. #define MIN_MSIX_COUNT (MIN_MSIX_Q_VECTORS + NON_Q_VECTORS)
  268. #define IXGBEVF_RX_DMA_ATTR \
  269. (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
  270. /* board specific private data structure */
  271. struct ixgbevf_adapter {
  272. /* this field must be first, see ixgbevf_process_skb_fields */
  273. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  274. struct ixgbevf_q_vector *q_vector[MAX_MSIX_Q_VECTORS];
  275. /* Interrupt Throttle Rate */
  276. u16 rx_itr_setting;
  277. u16 tx_itr_setting;
  278. /* interrupt masks */
  279. u32 eims_enable_mask;
  280. u32 eims_other;
  281. /* XDP */
  282. int num_xdp_queues;
  283. struct ixgbevf_ring *xdp_ring[MAX_XDP_QUEUES];
  284. /* TX */
  285. int num_tx_queues;
  286. struct ixgbevf_ring *tx_ring[MAX_TX_QUEUES]; /* One per active queue */
  287. u64 restart_queue;
  288. u32 tx_timeout_count;
  289. /* RX */
  290. int num_rx_queues;
  291. struct ixgbevf_ring *rx_ring[MAX_TX_QUEUES]; /* One per active queue */
  292. u64 hw_csum_rx_error;
  293. u64 hw_rx_no_dma_resources;
  294. int num_msix_vectors;
  295. u64 alloc_rx_page_failed;
  296. u64 alloc_rx_buff_failed;
  297. u64 alloc_rx_page;
  298. struct msix_entry *msix_entries;
  299. /* OS defined structs */
  300. struct net_device *netdev;
  301. struct bpf_prog *xdp_prog;
  302. struct pci_dev *pdev;
  303. /* structs defined in ixgbe_vf.h */
  304. struct ixgbe_hw hw;
  305. u16 msg_enable;
  306. /* Interrupt Throttle Rate */
  307. u32 eitr_param;
  308. struct ixgbevf_hw_stats stats;
  309. unsigned long state;
  310. u64 tx_busy;
  311. unsigned int tx_ring_count;
  312. unsigned int xdp_ring_count;
  313. unsigned int rx_ring_count;
  314. u8 __iomem *io_addr; /* Mainly for iounmap use */
  315. u32 link_speed;
  316. bool link_up;
  317. struct timer_list service_timer;
  318. struct work_struct service_task;
  319. spinlock_t mbx_lock;
  320. unsigned long last_reset;
  321. u32 *rss_key;
  322. u8 rss_indir_tbl[IXGBEVF_X550_VFRETA_SIZE];
  323. u32 flags;
  324. #define IXGBEVF_FLAGS_LEGACY_RX BIT(1)
  325. };
  326. enum ixbgevf_state_t {
  327. __IXGBEVF_TESTING,
  328. __IXGBEVF_RESETTING,
  329. __IXGBEVF_DOWN,
  330. __IXGBEVF_DISABLED,
  331. __IXGBEVF_REMOVING,
  332. __IXGBEVF_SERVICE_SCHED,
  333. __IXGBEVF_SERVICE_INITED,
  334. __IXGBEVF_RESET_REQUESTED,
  335. __IXGBEVF_QUEUE_RESET_REQUESTED,
  336. };
  337. enum ixgbevf_boards {
  338. board_82599_vf,
  339. board_82599_vf_hv,
  340. board_X540_vf,
  341. board_X540_vf_hv,
  342. board_X550_vf,
  343. board_X550_vf_hv,
  344. board_X550EM_x_vf,
  345. board_X550EM_x_vf_hv,
  346. board_x550em_a_vf,
  347. };
  348. enum ixgbevf_xcast_modes {
  349. IXGBEVF_XCAST_MODE_NONE = 0,
  350. IXGBEVF_XCAST_MODE_MULTI,
  351. IXGBEVF_XCAST_MODE_ALLMULTI,
  352. IXGBEVF_XCAST_MODE_PROMISC,
  353. };
  354. extern const struct ixgbevf_info ixgbevf_82599_vf_info;
  355. extern const struct ixgbevf_info ixgbevf_X540_vf_info;
  356. extern const struct ixgbevf_info ixgbevf_X550_vf_info;
  357. extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_info;
  358. extern const struct ixgbe_mbx_operations ixgbevf_mbx_ops;
  359. extern const struct ixgbevf_info ixgbevf_x550em_a_vf_info;
  360. extern const struct ixgbevf_info ixgbevf_82599_vf_hv_info;
  361. extern const struct ixgbevf_info ixgbevf_X540_vf_hv_info;
  362. extern const struct ixgbevf_info ixgbevf_X550_vf_hv_info;
  363. extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info;
  364. extern const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops;
  365. /* needed by ethtool.c */
  366. extern const char ixgbevf_driver_name[];
  367. extern const char ixgbevf_driver_version[];
  368. int ixgbevf_open(struct net_device *netdev);
  369. int ixgbevf_close(struct net_device *netdev);
  370. void ixgbevf_up(struct ixgbevf_adapter *adapter);
  371. void ixgbevf_down(struct ixgbevf_adapter *adapter);
  372. void ixgbevf_reinit_locked(struct ixgbevf_adapter *adapter);
  373. void ixgbevf_reset(struct ixgbevf_adapter *adapter);
  374. void ixgbevf_set_ethtool_ops(struct net_device *netdev);
  375. int ixgbevf_setup_rx_resources(struct ixgbevf_adapter *adapter,
  376. struct ixgbevf_ring *rx_ring);
  377. int ixgbevf_setup_tx_resources(struct ixgbevf_ring *);
  378. void ixgbevf_free_rx_resources(struct ixgbevf_ring *);
  379. void ixgbevf_free_tx_resources(struct ixgbevf_ring *);
  380. void ixgbevf_update_stats(struct ixgbevf_adapter *adapter);
  381. int ethtool_ioctl(struct ifreq *ifr);
  382. extern void ixgbevf_write_eitr(struct ixgbevf_q_vector *q_vector);
  383. void ixgbe_napi_add_all(struct ixgbevf_adapter *adapter);
  384. void ixgbe_napi_del_all(struct ixgbevf_adapter *adapter);
  385. #define ixgbevf_hw_to_netdev(hw) \
  386. (((struct ixgbevf_adapter *)(hw)->back)->netdev)
  387. #define hw_dbg(hw, format, arg...) \
  388. netdev_dbg(ixgbevf_hw_to_netdev(hw), format, ## arg)
  389. #endif /* _IXGBEVF_H_ */