ixgbevf.h 14 KB

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