igc.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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. #include <linux/ptp_clock_kernel.h>
  12. #include <linux/timecounter.h>
  13. #include <linux/net_tstamp.h>
  14. #include <linux/bitfield.h>
  15. #include "igc_hw.h"
  16. void igc_ethtool_set_ops(struct net_device *);
  17. /* Transmit and receive queues */
  18. #define IGC_MAX_RX_QUEUES 4
  19. #define IGC_MAX_TX_QUEUES 4
  20. #define MAX_Q_VECTORS 8
  21. #define MAX_STD_JUMBO_FRAME_SIZE 9216
  22. #define MAX_ETYPE_FILTER 8
  23. #define IGC_RETA_SIZE 128
  24. /* SDP support */
  25. #define IGC_N_EXTTS 2
  26. #define IGC_N_PEROUT 2
  27. #define IGC_N_SDP 4
  28. #define MAX_FLEX_FILTER 32
  29. enum igc_mac_filter_type {
  30. IGC_MAC_FILTER_TYPE_DST = 0,
  31. IGC_MAC_FILTER_TYPE_SRC
  32. };
  33. struct igc_tx_queue_stats {
  34. u64 packets;
  35. u64 bytes;
  36. u64 restart_queue;
  37. u64 restart_queue2;
  38. };
  39. struct igc_rx_queue_stats {
  40. u64 packets;
  41. u64 bytes;
  42. u64 drops;
  43. u64 csum_err;
  44. u64 alloc_failed;
  45. };
  46. struct igc_rx_packet_stats {
  47. u64 ipv4_packets; /* IPv4 headers processed */
  48. u64 ipv4e_packets; /* IPv4E headers with extensions processed */
  49. u64 ipv6_packets; /* IPv6 headers processed */
  50. u64 ipv6e_packets; /* IPv6E headers with extensions processed */
  51. u64 tcp_packets; /* TCP headers processed */
  52. u64 udp_packets; /* UDP headers processed */
  53. u64 sctp_packets; /* SCTP headers processed */
  54. u64 nfs_packets; /* NFS headers processe */
  55. u64 other_packets;
  56. };
  57. struct igc_ring_container {
  58. struct igc_ring *ring; /* pointer to linked list of rings */
  59. unsigned int total_bytes; /* total bytes processed this int */
  60. unsigned int total_packets; /* total packets processed this int */
  61. u16 work_limit; /* total work allowed per interrupt */
  62. u8 count; /* total number of rings in vector */
  63. u8 itr; /* current ITR setting for ring */
  64. };
  65. struct igc_ring {
  66. struct igc_q_vector *q_vector; /* backlink to q_vector */
  67. struct net_device *netdev; /* back pointer to net_device */
  68. struct device *dev; /* device for dma mapping */
  69. union { /* array of buffer info structs */
  70. struct igc_tx_buffer *tx_buffer_info;
  71. struct igc_rx_buffer *rx_buffer_info;
  72. };
  73. void *desc; /* descriptor ring memory */
  74. unsigned long flags; /* ring specific flags */
  75. void __iomem *tail; /* pointer to ring tail register */
  76. dma_addr_t dma; /* phys address of the ring */
  77. unsigned int size; /* length of desc. ring in bytes */
  78. u16 count; /* number of desc. in the ring */
  79. u8 queue_index; /* logical index of the ring*/
  80. u8 reg_idx; /* physical index of the ring */
  81. bool launchtime_enable; /* true if LaunchTime is enabled */
  82. ktime_t last_tx_cycle; /* end of the cycle with a launchtime transmission */
  83. ktime_t last_ff_cycle; /* Last cycle with an active first flag */
  84. u32 start_time;
  85. u32 end_time;
  86. /* CBS parameters */
  87. bool cbs_enable; /* indicates if CBS is enabled */
  88. s32 idleslope; /* idleSlope in kbps */
  89. s32 sendslope; /* sendSlope in kbps */
  90. s32 hicredit; /* hiCredit in bytes */
  91. s32 locredit; /* loCredit in bytes */
  92. /* everything past this point are written often */
  93. u16 next_to_clean;
  94. u16 next_to_use;
  95. u16 next_to_alloc;
  96. union {
  97. /* TX */
  98. struct {
  99. struct igc_tx_queue_stats tx_stats;
  100. struct u64_stats_sync tx_syncp;
  101. struct u64_stats_sync tx_syncp2;
  102. };
  103. /* RX */
  104. struct {
  105. struct igc_rx_queue_stats rx_stats;
  106. struct igc_rx_packet_stats pkt_stats;
  107. struct u64_stats_sync rx_syncp;
  108. struct sk_buff *skb;
  109. };
  110. };
  111. struct xdp_rxq_info xdp_rxq;
  112. struct xsk_buff_pool *xsk_pool;
  113. } ____cacheline_internodealigned_in_smp;
  114. /* Board specific private data structure */
  115. struct igc_adapter {
  116. struct net_device *netdev;
  117. struct ethtool_eee eee;
  118. u16 eee_advert;
  119. unsigned long state;
  120. unsigned int flags;
  121. unsigned int num_q_vectors;
  122. struct msix_entry *msix_entries;
  123. /* TX */
  124. u16 tx_work_limit;
  125. u32 tx_timeout_count;
  126. int num_tx_queues;
  127. struct igc_ring *tx_ring[IGC_MAX_TX_QUEUES];
  128. /* RX */
  129. int num_rx_queues;
  130. struct igc_ring *rx_ring[IGC_MAX_RX_QUEUES];
  131. struct timer_list watchdog_timer;
  132. struct timer_list dma_err_timer;
  133. struct timer_list phy_info_timer;
  134. u32 wol;
  135. u32 en_mng_pt;
  136. u16 link_speed;
  137. u16 link_duplex;
  138. u8 port_num;
  139. u8 __iomem *io_addr;
  140. /* Interrupt Throttle Rate */
  141. u32 rx_itr_setting;
  142. u32 tx_itr_setting;
  143. struct work_struct reset_task;
  144. struct work_struct watchdog_task;
  145. struct work_struct dma_err_task;
  146. bool fc_autoneg;
  147. u8 tx_timeout_factor;
  148. int msg_enable;
  149. u32 max_frame_size;
  150. u32 min_frame_size;
  151. int tc_setup_type;
  152. ktime_t base_time;
  153. ktime_t cycle_time;
  154. bool qbv_enable;
  155. u32 qbv_config_change_errors;
  156. /* OS defined structs */
  157. struct pci_dev *pdev;
  158. /* lock for statistics */
  159. spinlock_t stats64_lock;
  160. struct rtnl_link_stats64 stats64;
  161. /* structs defined in igc_hw.h */
  162. struct igc_hw hw;
  163. struct igc_hw_stats stats;
  164. struct igc_q_vector *q_vector[MAX_Q_VECTORS];
  165. u32 eims_enable_mask;
  166. u32 eims_other;
  167. u16 tx_ring_count;
  168. u16 rx_ring_count;
  169. u32 tx_hwtstamp_timeouts;
  170. u32 tx_hwtstamp_skipped;
  171. u32 rx_hwtstamp_cleared;
  172. u32 rss_queues;
  173. u32 rss_indir_tbl_init;
  174. /* Any access to elements in nfc_rule_list is protected by the
  175. * nfc_rule_lock.
  176. */
  177. struct mutex nfc_rule_lock;
  178. struct list_head nfc_rule_list;
  179. unsigned int nfc_rule_count;
  180. u8 rss_indir_tbl[IGC_RETA_SIZE];
  181. unsigned long link_check_timeout;
  182. struct igc_info ei;
  183. u32 test_icr;
  184. struct ptp_clock *ptp_clock;
  185. struct ptp_clock_info ptp_caps;
  186. struct work_struct ptp_tx_work;
  187. /* Access to ptp_tx_skb and ptp_tx_start are protected by the
  188. * ptp_tx_lock.
  189. */
  190. spinlock_t ptp_tx_lock;
  191. struct sk_buff *ptp_tx_skb;
  192. struct hwtstamp_config tstamp_config;
  193. unsigned long ptp_tx_start;
  194. unsigned int ptp_flags;
  195. /* System time value lock */
  196. spinlock_t tmreg_lock;
  197. struct cyclecounter cc;
  198. struct timecounter tc;
  199. struct timespec64 prev_ptp_time; /* Pre-reset PTP clock */
  200. ktime_t ptp_reset_start; /* Reset time in clock mono */
  201. struct system_time_snapshot snapshot;
  202. char fw_version[32];
  203. struct bpf_prog *xdp_prog;
  204. bool pps_sys_wrap_on;
  205. struct ptp_pin_desc sdp_config[IGC_N_SDP];
  206. struct {
  207. struct timespec64 start;
  208. struct timespec64 period;
  209. } perout[IGC_N_PEROUT];
  210. };
  211. void igc_up(struct igc_adapter *adapter);
  212. void igc_down(struct igc_adapter *adapter);
  213. int igc_open(struct net_device *netdev);
  214. int igc_close(struct net_device *netdev);
  215. int igc_setup_tx_resources(struct igc_ring *ring);
  216. int igc_setup_rx_resources(struct igc_ring *ring);
  217. void igc_free_tx_resources(struct igc_ring *ring);
  218. void igc_free_rx_resources(struct igc_ring *ring);
  219. unsigned int igc_get_max_rss_queues(struct igc_adapter *adapter);
  220. void igc_set_flag_queue_pairs(struct igc_adapter *adapter,
  221. const u32 max_rss_queues);
  222. int igc_reinit_queues(struct igc_adapter *adapter);
  223. void igc_write_rss_indir_tbl(struct igc_adapter *adapter);
  224. bool igc_has_link(struct igc_adapter *adapter);
  225. void igc_reset(struct igc_adapter *adapter);
  226. void igc_update_stats(struct igc_adapter *adapter);
  227. void igc_disable_rx_ring(struct igc_ring *ring);
  228. void igc_enable_rx_ring(struct igc_ring *ring);
  229. void igc_disable_tx_ring(struct igc_ring *ring);
  230. void igc_enable_tx_ring(struct igc_ring *ring);
  231. int igc_xsk_wakeup(struct net_device *dev, u32 queue_id, u32 flags);
  232. /* igc_dump declarations */
  233. void igc_rings_dump(struct igc_adapter *adapter);
  234. void igc_regs_dump(struct igc_adapter *adapter);
  235. extern char igc_driver_name[];
  236. #define IGC_REGS_LEN 740
  237. /* flags controlling PTP/1588 function */
  238. #define IGC_PTP_ENABLED BIT(0)
  239. /* Flags definitions */
  240. #define IGC_FLAG_HAS_MSI BIT(0)
  241. #define IGC_FLAG_QUEUE_PAIRS BIT(3)
  242. #define IGC_FLAG_DMAC BIT(4)
  243. #define IGC_FLAG_PTP BIT(8)
  244. #define IGC_FLAG_WOL_SUPPORTED BIT(8)
  245. #define IGC_FLAG_NEED_LINK_UPDATE BIT(9)
  246. #define IGC_FLAG_MEDIA_RESET BIT(10)
  247. #define IGC_FLAG_MAS_ENABLE BIT(12)
  248. #define IGC_FLAG_HAS_MSIX BIT(13)
  249. #define IGC_FLAG_EEE BIT(14)
  250. #define IGC_FLAG_VLAN_PROMISC BIT(15)
  251. #define IGC_FLAG_RX_LEGACY BIT(16)
  252. #define IGC_FLAG_TSN_QBV_ENABLED BIT(17)
  253. #define IGC_FLAG_TSN_QAV_ENABLED BIT(18)
  254. #define IGC_FLAG_TSN_ANY_ENABLED \
  255. (IGC_FLAG_TSN_QBV_ENABLED | IGC_FLAG_TSN_QAV_ENABLED)
  256. #define IGC_FLAG_RSS_FIELD_IPV4_UDP BIT(6)
  257. #define IGC_FLAG_RSS_FIELD_IPV6_UDP BIT(7)
  258. #define IGC_MRQC_ENABLE_RSS_MQ 0x00000002
  259. #define IGC_MRQC_RSS_FIELD_IPV4_UDP 0x00400000
  260. #define IGC_MRQC_RSS_FIELD_IPV6_UDP 0x00800000
  261. /* RX-desc Write-Back format RSS Type's */
  262. enum igc_rss_type_num {
  263. IGC_RSS_TYPE_NO_HASH = 0,
  264. IGC_RSS_TYPE_HASH_TCP_IPV4 = 1,
  265. IGC_RSS_TYPE_HASH_IPV4 = 2,
  266. IGC_RSS_TYPE_HASH_TCP_IPV6 = 3,
  267. IGC_RSS_TYPE_HASH_IPV6_EX = 4,
  268. IGC_RSS_TYPE_HASH_IPV6 = 5,
  269. IGC_RSS_TYPE_HASH_TCP_IPV6_EX = 6,
  270. IGC_RSS_TYPE_HASH_UDP_IPV4 = 7,
  271. IGC_RSS_TYPE_HASH_UDP_IPV6 = 8,
  272. IGC_RSS_TYPE_HASH_UDP_IPV6_EX = 9,
  273. IGC_RSS_TYPE_MAX = 10,
  274. };
  275. #define IGC_RSS_TYPE_MAX_TABLE 16
  276. #define IGC_RSS_TYPE_MASK GENMASK(3,0) /* 4-bits (3:0) = mask 0x0F */
  277. /* igc_rss_type - Rx descriptor RSS type field */
  278. static inline u32 igc_rss_type(const union igc_adv_rx_desc *rx_desc)
  279. {
  280. /* RSS Type 4-bits (3:0) number: 0-9 (above 9 is reserved)
  281. * Accessing the same bits via u16 (wb.lower.lo_dword.hs_rss.pkt_info)
  282. * is slightly slower than via u32 (wb.lower.lo_dword.data)
  283. */
  284. return le32_get_bits(rx_desc->wb.lower.lo_dword.data, IGC_RSS_TYPE_MASK);
  285. }
  286. /* Interrupt defines */
  287. #define IGC_START_ITR 648 /* ~6000 ints/sec */
  288. #define IGC_4K_ITR 980
  289. #define IGC_20K_ITR 196
  290. #define IGC_70K_ITR 56
  291. #define IGC_DEFAULT_ITR 3 /* dynamic */
  292. #define IGC_MAX_ITR_USECS 10000
  293. #define IGC_MIN_ITR_USECS 10
  294. #define NON_Q_VECTORS 1
  295. #define MAX_MSIX_ENTRIES 10
  296. /* TX/RX descriptor defines */
  297. #define IGC_DEFAULT_TXD 256
  298. #define IGC_DEFAULT_TX_WORK 128
  299. #define IGC_MIN_TXD 64
  300. #define IGC_MAX_TXD 4096
  301. #define IGC_DEFAULT_RXD 256
  302. #define IGC_MIN_RXD 64
  303. #define IGC_MAX_RXD 4096
  304. /* Supported Rx Buffer Sizes */
  305. #define IGC_RXBUFFER_256 256
  306. #define IGC_RXBUFFER_2048 2048
  307. #define IGC_RXBUFFER_3072 3072
  308. #define AUTO_ALL_MODES 0
  309. #define IGC_RX_HDR_LEN IGC_RXBUFFER_256
  310. /* Transmit and receive latency (for PTP timestamps) */
  311. #define IGC_I225_TX_LATENCY_10 240
  312. #define IGC_I225_TX_LATENCY_100 58
  313. #define IGC_I225_TX_LATENCY_1000 80
  314. #define IGC_I225_TX_LATENCY_2500 1325
  315. #define IGC_I225_RX_LATENCY_10 6450
  316. #define IGC_I225_RX_LATENCY_100 185
  317. #define IGC_I225_RX_LATENCY_1000 300
  318. #define IGC_I225_RX_LATENCY_2500 1485
  319. /* RX and TX descriptor control thresholds.
  320. * PTHRESH - MAC will consider prefetch if it has fewer than this number of
  321. * descriptors available in its onboard memory.
  322. * Setting this to 0 disables RX descriptor prefetch.
  323. * HTHRESH - MAC will only prefetch if there are at least this many descriptors
  324. * available in host memory.
  325. * If PTHRESH is 0, this should also be 0.
  326. * WTHRESH - RX descriptor writeback threshold - MAC will delay writing back
  327. * descriptors until either it has this many to write back, or the
  328. * ITR timer expires.
  329. */
  330. #define IGC_RX_PTHRESH 8
  331. #define IGC_RX_HTHRESH 8
  332. #define IGC_TX_PTHRESH 8
  333. #define IGC_TX_HTHRESH 1
  334. #define IGC_RX_WTHRESH 4
  335. #define IGC_TX_WTHRESH 16
  336. #define IGC_RX_DMA_ATTR \
  337. (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
  338. #define IGC_TS_HDR_LEN 16
  339. #define IGC_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN)
  340. #if (PAGE_SIZE < 8192)
  341. #define IGC_MAX_FRAME_BUILD_SKB \
  342. (SKB_WITH_OVERHEAD(IGC_RXBUFFER_2048) - IGC_SKB_PAD - IGC_TS_HDR_LEN)
  343. #else
  344. #define IGC_MAX_FRAME_BUILD_SKB (IGC_RXBUFFER_2048 - IGC_TS_HDR_LEN)
  345. #endif
  346. /* How many Rx Buffers do we bundle into one write to the hardware ? */
  347. #define IGC_RX_BUFFER_WRITE 16 /* Must be power of 2 */
  348. /* VLAN info */
  349. #define IGC_TX_FLAGS_VLAN_MASK 0xffff0000
  350. #define IGC_TX_FLAGS_VLAN_SHIFT 16
  351. /* igc_test_staterr - tests bits within Rx descriptor status and error fields */
  352. static inline __le32 igc_test_staterr(union igc_adv_rx_desc *rx_desc,
  353. const u32 stat_err_bits)
  354. {
  355. return rx_desc->wb.upper.status_error & cpu_to_le32(stat_err_bits);
  356. }
  357. enum igc_state_t {
  358. __IGC_TESTING,
  359. __IGC_RESETTING,
  360. __IGC_DOWN,
  361. };
  362. enum igc_tx_flags {
  363. /* cmd_type flags */
  364. IGC_TX_FLAGS_VLAN = 0x01,
  365. IGC_TX_FLAGS_TSO = 0x02,
  366. IGC_TX_FLAGS_TSTAMP = 0x04,
  367. /* olinfo flags */
  368. IGC_TX_FLAGS_IPV4 = 0x10,
  369. IGC_TX_FLAGS_CSUM = 0x20,
  370. };
  371. enum igc_boards {
  372. board_base,
  373. };
  374. /* The largest size we can write to the descriptor is 65535. In order to
  375. * maintain a power of two alignment we have to limit ourselves to 32K.
  376. */
  377. #define IGC_MAX_TXD_PWR 15
  378. #define IGC_MAX_DATA_PER_TXD BIT(IGC_MAX_TXD_PWR)
  379. /* Tx Descriptors needed, worst case */
  380. #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IGC_MAX_DATA_PER_TXD)
  381. #define DESC_NEEDED (MAX_SKB_FRAGS + 4)
  382. enum igc_tx_buffer_type {
  383. IGC_TX_BUFFER_TYPE_SKB,
  384. IGC_TX_BUFFER_TYPE_XDP,
  385. IGC_TX_BUFFER_TYPE_XSK,
  386. };
  387. /* wrapper around a pointer to a socket buffer,
  388. * so a DMA handle can be stored along with the buffer
  389. */
  390. struct igc_tx_buffer {
  391. union igc_adv_tx_desc *next_to_watch;
  392. unsigned long time_stamp;
  393. enum igc_tx_buffer_type type;
  394. union {
  395. struct sk_buff *skb;
  396. struct xdp_frame *xdpf;
  397. };
  398. unsigned int bytecount;
  399. u16 gso_segs;
  400. __be16 protocol;
  401. DEFINE_DMA_UNMAP_ADDR(dma);
  402. DEFINE_DMA_UNMAP_LEN(len);
  403. u32 tx_flags;
  404. };
  405. struct igc_rx_buffer {
  406. union {
  407. struct {
  408. dma_addr_t dma;
  409. struct page *page;
  410. #if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536)
  411. __u32 page_offset;
  412. #else
  413. __u16 page_offset;
  414. #endif
  415. __u16 pagecnt_bias;
  416. };
  417. struct xdp_buff *xdp;
  418. };
  419. };
  420. struct igc_q_vector {
  421. struct igc_adapter *adapter; /* backlink */
  422. void __iomem *itr_register;
  423. u32 eims_value; /* EIMS mask value */
  424. u16 itr_val;
  425. u8 set_itr;
  426. struct igc_ring_container rx, tx;
  427. struct napi_struct napi;
  428. struct rcu_head rcu; /* to avoid race with update stats on free */
  429. char name[IFNAMSIZ + 9];
  430. struct net_device poll_dev;
  431. /* for dynamic allocation of rings associated with this q_vector */
  432. struct igc_ring ring[] ____cacheline_internodealigned_in_smp;
  433. };
  434. enum igc_filter_match_flags {
  435. IGC_FILTER_FLAG_ETHER_TYPE = BIT(0),
  436. IGC_FILTER_FLAG_VLAN_TCI = BIT(1),
  437. IGC_FILTER_FLAG_SRC_MAC_ADDR = BIT(2),
  438. IGC_FILTER_FLAG_DST_MAC_ADDR = BIT(3),
  439. IGC_FILTER_FLAG_USER_DATA = BIT(4),
  440. IGC_FILTER_FLAG_VLAN_ETYPE = BIT(5),
  441. };
  442. struct igc_nfc_filter {
  443. u8 match_flags;
  444. u16 etype;
  445. __be16 vlan_etype;
  446. u16 vlan_tci;
  447. u8 src_addr[ETH_ALEN];
  448. u8 dst_addr[ETH_ALEN];
  449. u8 user_data[8];
  450. u8 user_mask[8];
  451. u8 flex_index;
  452. u8 rx_queue;
  453. u8 prio;
  454. u8 immediate_irq;
  455. u8 drop;
  456. };
  457. struct igc_nfc_rule {
  458. struct list_head list;
  459. struct igc_nfc_filter filter;
  460. u32 location;
  461. u16 action;
  462. bool flex;
  463. };
  464. /* IGC supports a total of 32 NFC rules: 16 MAC address based, 8 VLAN priority
  465. * based, 8 ethertype based and 32 Flex filter based rules.
  466. */
  467. #define IGC_MAX_RXNFC_RULES 64
  468. struct igc_flex_filter {
  469. u8 index;
  470. u8 data[128];
  471. u8 mask[16];
  472. u8 length;
  473. u8 rx_queue;
  474. u8 prio;
  475. u8 immediate_irq;
  476. u8 drop;
  477. };
  478. /* igc_desc_unused - calculate if we have unused descriptors */
  479. static inline u16 igc_desc_unused(const struct igc_ring *ring)
  480. {
  481. u16 ntc = ring->next_to_clean;
  482. u16 ntu = ring->next_to_use;
  483. return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1;
  484. }
  485. static inline s32 igc_get_phy_info(struct igc_hw *hw)
  486. {
  487. if (hw->phy.ops.get_phy_info)
  488. return hw->phy.ops.get_phy_info(hw);
  489. return 0;
  490. }
  491. static inline s32 igc_reset_phy(struct igc_hw *hw)
  492. {
  493. if (hw->phy.ops.reset)
  494. return hw->phy.ops.reset(hw);
  495. return 0;
  496. }
  497. static inline struct netdev_queue *txring_txq(const struct igc_ring *tx_ring)
  498. {
  499. return netdev_get_tx_queue(tx_ring->netdev, tx_ring->queue_index);
  500. }
  501. enum igc_ring_flags_t {
  502. IGC_RING_FLAG_RX_3K_BUFFER,
  503. IGC_RING_FLAG_RX_BUILD_SKB_ENABLED,
  504. IGC_RING_FLAG_RX_SCTP_CSUM,
  505. IGC_RING_FLAG_RX_LB_VLAN_BSWAP,
  506. IGC_RING_FLAG_TX_CTX_IDX,
  507. IGC_RING_FLAG_TX_DETECT_HANG,
  508. IGC_RING_FLAG_AF_XDP_ZC,
  509. };
  510. #define ring_uses_large_buffer(ring) \
  511. test_bit(IGC_RING_FLAG_RX_3K_BUFFER, &(ring)->flags)
  512. #define set_ring_uses_large_buffer(ring) \
  513. set_bit(IGC_RING_FLAG_RX_3K_BUFFER, &(ring)->flags)
  514. #define clear_ring_uses_large_buffer(ring) \
  515. clear_bit(IGC_RING_FLAG_RX_3K_BUFFER, &(ring)->flags)
  516. #define ring_uses_build_skb(ring) \
  517. test_bit(IGC_RING_FLAG_RX_BUILD_SKB_ENABLED, &(ring)->flags)
  518. static inline unsigned int igc_rx_bufsz(struct igc_ring *ring)
  519. {
  520. #if (PAGE_SIZE < 8192)
  521. if (ring_uses_large_buffer(ring))
  522. return IGC_RXBUFFER_3072;
  523. if (ring_uses_build_skb(ring))
  524. return IGC_MAX_FRAME_BUILD_SKB + IGC_TS_HDR_LEN;
  525. #endif
  526. return IGC_RXBUFFER_2048;
  527. }
  528. static inline unsigned int igc_rx_pg_order(struct igc_ring *ring)
  529. {
  530. #if (PAGE_SIZE < 8192)
  531. if (ring_uses_large_buffer(ring))
  532. return 1;
  533. #endif
  534. return 0;
  535. }
  536. static inline s32 igc_read_phy_reg(struct igc_hw *hw, u32 offset, u16 *data)
  537. {
  538. if (hw->phy.ops.read_reg)
  539. return hw->phy.ops.read_reg(hw, offset, data);
  540. return -EOPNOTSUPP;
  541. }
  542. void igc_reinit_locked(struct igc_adapter *);
  543. struct igc_nfc_rule *igc_get_nfc_rule(struct igc_adapter *adapter,
  544. u32 location);
  545. int igc_add_nfc_rule(struct igc_adapter *adapter, struct igc_nfc_rule *rule);
  546. void igc_del_nfc_rule(struct igc_adapter *adapter, struct igc_nfc_rule *rule);
  547. void igc_ptp_init(struct igc_adapter *adapter);
  548. void igc_ptp_reset(struct igc_adapter *adapter);
  549. void igc_ptp_suspend(struct igc_adapter *adapter);
  550. void igc_ptp_stop(struct igc_adapter *adapter);
  551. ktime_t igc_ptp_rx_pktstamp(struct igc_adapter *adapter, __le32 *buf);
  552. int igc_ptp_set_ts_config(struct net_device *netdev, struct ifreq *ifr);
  553. int igc_ptp_get_ts_config(struct net_device *netdev, struct ifreq *ifr);
  554. void igc_ptp_tx_hang(struct igc_adapter *adapter);
  555. void igc_ptp_read(struct igc_adapter *adapter, struct timespec64 *ts);
  556. #define igc_rx_pg_size(_ring) (PAGE_SIZE << igc_rx_pg_order(_ring))
  557. #define IGC_TXD_DCMD (IGC_ADVTXD_DCMD_EOP | IGC_ADVTXD_DCMD_RS)
  558. #define IGC_RX_DESC(R, i) \
  559. (&(((union igc_adv_rx_desc *)((R)->desc))[i]))
  560. #define IGC_TX_DESC(R, i) \
  561. (&(((union igc_adv_tx_desc *)((R)->desc))[i]))
  562. #define IGC_TX_CTXTDESC(R, i) \
  563. (&(((struct igc_adv_tx_context_desc *)((R)->desc))[i]))
  564. #endif /* _IGC_H_ */