igc.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (c) 2018 Intel Corporation */
  3. #ifndef _IGC_H_
  4. #define _IGC_H_
  5. #include <linux/kobject.h>
  6. #include <linux/pci.h>
  7. #include <linux/netdevice.h>
  8. #include <linux/vmalloc.h>
  9. #include <linux/ethtool.h>
  10. #include <linux/sctp.h>
  11. #define IGC_ERR(args...) pr_err("igc: " args)
  12. #define PFX "igc: "
  13. #include <linux/timecounter.h>
  14. #include <linux/net_tstamp.h>
  15. #include <linux/ptp_clock_kernel.h>
  16. #include "igc_hw.h"
  17. /* main */
  18. extern char igc_driver_name[];
  19. extern char igc_driver_version[];
  20. /* Interrupt defines */
  21. #define IGC_START_ITR 648 /* ~6000 ints/sec */
  22. #define IGC_FLAG_HAS_MSI BIT(0)
  23. #define IGC_FLAG_QUEUE_PAIRS BIT(4)
  24. #define IGC_FLAG_HAS_MSIX BIT(13)
  25. #define IGC_START_ITR 648 /* ~6000 ints/sec */
  26. #define IGC_4K_ITR 980
  27. #define IGC_20K_ITR 196
  28. #define IGC_70K_ITR 56
  29. /* Transmit and receive queues */
  30. #define IGC_MAX_RX_QUEUES 4
  31. #define IGC_MAX_TX_QUEUES 4
  32. #define MAX_Q_VECTORS 8
  33. #define MAX_STD_JUMBO_FRAME_SIZE 9216
  34. /* Supported Rx Buffer Sizes */
  35. #define IGC_RXBUFFER_256 256
  36. #define IGC_RXBUFFER_2048 2048
  37. #define IGC_RXBUFFER_3072 3072
  38. #define IGC_RX_HDR_LEN IGC_RXBUFFER_256
  39. /* RX and TX descriptor control thresholds.
  40. * PTHRESH - MAC will consider prefetch if it has fewer than this number of
  41. * descriptors available in its onboard memory.
  42. * Setting this to 0 disables RX descriptor prefetch.
  43. * HTHRESH - MAC will only prefetch if there are at least this many descriptors
  44. * available in host memory.
  45. * If PTHRESH is 0, this should also be 0.
  46. * WTHRESH - RX descriptor writeback threshold - MAC will delay writing back
  47. * descriptors until either it has this many to write back, or the
  48. * ITR timer expires.
  49. */
  50. #define IGC_RX_PTHRESH 8
  51. #define IGC_RX_HTHRESH 8
  52. #define IGC_TX_PTHRESH 8
  53. #define IGC_TX_HTHRESH 1
  54. #define IGC_RX_WTHRESH 4
  55. #define IGC_TX_WTHRESH 16
  56. #define IGC_RX_DMA_ATTR \
  57. (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
  58. #define IGC_TS_HDR_LEN 16
  59. #define IGC_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN)
  60. #if (PAGE_SIZE < 8192)
  61. #define IGC_MAX_FRAME_BUILD_SKB \
  62. (SKB_WITH_OVERHEAD(IGC_RXBUFFER_2048) - IGC_SKB_PAD - IGC_TS_HDR_LEN)
  63. #else
  64. #define IGC_MAX_FRAME_BUILD_SKB (IGC_RXBUFFER_2048 - IGC_TS_HDR_LEN)
  65. #endif
  66. enum igc_state_t {
  67. __IGC_TESTING,
  68. __IGC_RESETTING,
  69. __IGC_DOWN,
  70. __IGC_PTP_TX_IN_PROGRESS,
  71. };
  72. /* wrapper around a pointer to a socket buffer,
  73. * so a DMA handle can be stored along with the buffer
  74. */
  75. struct igc_tx_buffer {
  76. union igc_adv_tx_desc *next_to_watch;
  77. unsigned long time_stamp;
  78. struct sk_buff *skb;
  79. unsigned int bytecount;
  80. u16 gso_segs;
  81. __be16 protocol;
  82. DEFINE_DMA_UNMAP_ADDR(dma);
  83. DEFINE_DMA_UNMAP_LEN(len);
  84. u32 tx_flags;
  85. };
  86. struct igc_rx_buffer {
  87. dma_addr_t dma;
  88. struct page *page;
  89. #if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536)
  90. __u32 page_offset;
  91. #else
  92. __u16 page_offset;
  93. #endif
  94. __u16 pagecnt_bias;
  95. };
  96. struct igc_tx_queue_stats {
  97. u64 packets;
  98. u64 bytes;
  99. u64 restart_queue;
  100. };
  101. struct igc_rx_queue_stats {
  102. u64 packets;
  103. u64 bytes;
  104. u64 drops;
  105. u64 csum_err;
  106. u64 alloc_failed;
  107. };
  108. struct igc_rx_packet_stats {
  109. u64 ipv4_packets; /* IPv4 headers processed */
  110. u64 ipv4e_packets; /* IPv4E headers with extensions processed */
  111. u64 ipv6_packets; /* IPv6 headers processed */
  112. u64 ipv6e_packets; /* IPv6E headers with extensions processed */
  113. u64 tcp_packets; /* TCP headers processed */
  114. u64 udp_packets; /* UDP headers processed */
  115. u64 sctp_packets; /* SCTP headers processed */
  116. u64 nfs_packets; /* NFS headers processe */
  117. u64 other_packets;
  118. };
  119. struct igc_ring_container {
  120. struct igc_ring *ring; /* pointer to linked list of rings */
  121. unsigned int total_bytes; /* total bytes processed this int */
  122. unsigned int total_packets; /* total packets processed this int */
  123. u16 work_limit; /* total work allowed per interrupt */
  124. u8 count; /* total number of rings in vector */
  125. u8 itr; /* current ITR setting for ring */
  126. };
  127. struct igc_ring {
  128. struct igc_q_vector *q_vector; /* backlink to q_vector */
  129. struct net_device *netdev; /* back pointer to net_device */
  130. struct device *dev; /* device for dma mapping */
  131. union { /* array of buffer info structs */
  132. struct igc_tx_buffer *tx_buffer_info;
  133. struct igc_rx_buffer *rx_buffer_info;
  134. };
  135. void *desc; /* descriptor ring memory */
  136. unsigned long flags; /* ring specific flags */
  137. void __iomem *tail; /* pointer to ring tail register */
  138. dma_addr_t dma; /* phys address of the ring */
  139. unsigned int size; /* length of desc. ring in bytes */
  140. u16 count; /* number of desc. in the ring */
  141. u8 queue_index; /* logical index of the ring*/
  142. u8 reg_idx; /* physical index of the ring */
  143. /* everything past this point are written often */
  144. u16 next_to_clean;
  145. u16 next_to_use;
  146. u16 next_to_alloc;
  147. union {
  148. /* TX */
  149. struct {
  150. struct igc_tx_queue_stats tx_stats;
  151. };
  152. /* RX */
  153. struct {
  154. struct igc_rx_queue_stats rx_stats;
  155. struct igc_rx_packet_stats pkt_stats;
  156. struct sk_buff *skb;
  157. };
  158. };
  159. } ____cacheline_internodealigned_in_smp;
  160. struct igc_q_vector {
  161. struct igc_adapter *adapter; /* backlink */
  162. void __iomem *itr_register;
  163. u32 eims_value; /* EIMS mask value */
  164. u16 itr_val;
  165. u8 set_itr;
  166. struct igc_ring_container rx, tx;
  167. struct napi_struct napi;
  168. struct rcu_head rcu; /* to avoid race with update stats on free */
  169. char name[IFNAMSIZ + 9];
  170. struct net_device poll_dev;
  171. /* for dynamic allocation of rings associated with this q_vector */
  172. struct igc_ring ring[0] ____cacheline_internodealigned_in_smp;
  173. };
  174. struct igc_mac_addr {
  175. u8 addr[ETH_ALEN];
  176. u8 queue;
  177. u8 state; /* bitmask */
  178. };
  179. #define IGC_MAC_STATE_DEFAULT 0x1
  180. #define IGC_MAC_STATE_MODIFIED 0x2
  181. #define IGC_MAC_STATE_IN_USE 0x4
  182. /* Board specific private data structure */
  183. struct igc_adapter {
  184. struct net_device *netdev;
  185. unsigned long state;
  186. unsigned int flags;
  187. unsigned int num_q_vectors;
  188. struct msix_entry *msix_entries;
  189. /* TX */
  190. u16 tx_work_limit;
  191. int num_tx_queues;
  192. struct igc_ring *tx_ring[IGC_MAX_TX_QUEUES];
  193. /* RX */
  194. int num_rx_queues;
  195. struct igc_ring *rx_ring[IGC_MAX_RX_QUEUES];
  196. struct timer_list watchdog_timer;
  197. struct timer_list dma_err_timer;
  198. struct timer_list phy_info_timer;
  199. u16 link_speed;
  200. u16 link_duplex;
  201. u8 port_num;
  202. u8 __iomem *io_addr;
  203. /* Interrupt Throttle Rate */
  204. u32 rx_itr_setting;
  205. u32 tx_itr_setting;
  206. struct work_struct reset_task;
  207. struct work_struct watchdog_task;
  208. struct work_struct dma_err_task;
  209. int msg_enable;
  210. u32 max_frame_size;
  211. /* OS defined structs */
  212. struct pci_dev *pdev;
  213. /* structs defined in igc_hw.h */
  214. struct igc_hw hw;
  215. struct igc_hw_stats stats;
  216. struct igc_q_vector *q_vector[MAX_Q_VECTORS];
  217. u32 eims_enable_mask;
  218. u32 eims_other;
  219. u16 tx_ring_count;
  220. u16 rx_ring_count;
  221. u32 rss_queues;
  222. struct igc_mac_addr *mac_table;
  223. };
  224. /* igc_desc_unused - calculate if we have unused descriptors */
  225. static inline u16 igc_desc_unused(const struct igc_ring *ring)
  226. {
  227. u16 ntc = ring->next_to_clean;
  228. u16 ntu = ring->next_to_use;
  229. return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1;
  230. }
  231. static inline struct netdev_queue *txring_txq(const struct igc_ring *tx_ring)
  232. {
  233. return netdev_get_tx_queue(tx_ring->netdev, tx_ring->queue_index);
  234. }
  235. enum igc_ring_flags_t {
  236. IGC_RING_FLAG_RX_3K_BUFFER,
  237. IGC_RING_FLAG_RX_BUILD_SKB_ENABLED,
  238. IGC_RING_FLAG_RX_SCTP_CSUM,
  239. IGC_RING_FLAG_RX_LB_VLAN_BSWAP,
  240. IGC_RING_FLAG_TX_CTX_IDX,
  241. IGC_RING_FLAG_TX_DETECT_HANG
  242. };
  243. #define ring_uses_large_buffer(ring) \
  244. test_bit(IGC_RING_FLAG_RX_3K_BUFFER, &(ring)->flags)
  245. #define ring_uses_build_skb(ring) \
  246. test_bit(IGC_RING_FLAG_RX_BUILD_SKB_ENABLED, &(ring)->flags)
  247. static inline unsigned int igc_rx_bufsz(struct igc_ring *ring)
  248. {
  249. #if (PAGE_SIZE < 8192)
  250. if (ring_uses_large_buffer(ring))
  251. return IGC_RXBUFFER_3072;
  252. if (ring_uses_build_skb(ring))
  253. return IGC_MAX_FRAME_BUILD_SKB + IGC_TS_HDR_LEN;
  254. #endif
  255. return IGC_RXBUFFER_2048;
  256. }
  257. static inline unsigned int igc_rx_pg_order(struct igc_ring *ring)
  258. {
  259. #if (PAGE_SIZE < 8192)
  260. if (ring_uses_large_buffer(ring))
  261. return 1;
  262. #endif
  263. return 0;
  264. }
  265. #define igc_rx_pg_size(_ring) (PAGE_SIZE << igc_rx_pg_order(_ring))
  266. #define IGC_RX_DESC(R, i) \
  267. (&(((union igc_adv_rx_desc *)((R)->desc))[i]))
  268. #define IGC_TX_DESC(R, i) \
  269. (&(((union igc_adv_tx_desc *)((R)->desc))[i]))
  270. #define IGC_TX_CTXTDESC(R, i) \
  271. (&(((struct igc_adv_tx_context_desc *)((R)->desc))[i]))
  272. #endif /* _IGC_H_ */