e1000.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright(c) 1999 - 2006 Intel Corporation. */
  3. /* Linux PRO/1000 Ethernet Driver main header file */
  4. #ifndef _E1000_H_
  5. #define _E1000_H_
  6. #include <linux/stddef.h>
  7. #include <linux/module.h>
  8. #include <linux/types.h>
  9. #include <asm/byteorder.h>
  10. #include <linux/mm.h>
  11. #include <linux/errno.h>
  12. #include <linux/ioport.h>
  13. #include <linux/pci.h>
  14. #include <linux/kernel.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/etherdevice.h>
  17. #include <linux/skbuff.h>
  18. #include <linux/delay.h>
  19. #include <linux/timer.h>
  20. #include <linux/slab.h>
  21. #include <linux/vmalloc.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/string.h>
  24. #include <linux/pagemap.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/bitops.h>
  27. #include <asm/io.h>
  28. #include <asm/irq.h>
  29. #include <linux/capability.h>
  30. #include <linux/in.h>
  31. #include <linux/ip.h>
  32. #include <linux/ipv6.h>
  33. #include <linux/tcp.h>
  34. #include <linux/udp.h>
  35. #include <net/pkt_sched.h>
  36. #include <linux/list.h>
  37. #include <linux/reboot.h>
  38. #include <net/checksum.h>
  39. #include <linux/mii.h>
  40. #include <linux/ethtool.h>
  41. #include <linux/if_vlan.h>
  42. #define BAR_0 0
  43. #define BAR_1 1
  44. #define BAR_5 5
  45. #define INTEL_E1000_ETHERNET_DEVICE(device_id) {\
  46. PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
  47. struct e1000_adapter;
  48. #include "e1000_hw.h"
  49. #define E1000_MAX_INTR 10
  50. /*
  51. * Count for polling __E1000_RESET condition every 10-20msec.
  52. */
  53. #define E1000_CHECK_RESET_COUNT 50
  54. /* TX/RX descriptor defines */
  55. #define E1000_DEFAULT_TXD 256
  56. #define E1000_MAX_TXD 256
  57. #define E1000_MIN_TXD 48
  58. #define E1000_MAX_82544_TXD 4096
  59. #define E1000_DEFAULT_RXD 256
  60. #define E1000_MAX_RXD 256
  61. #define E1000_MIN_RXD 48
  62. #define E1000_MAX_82544_RXD 4096
  63. #define E1000_MIN_ITR_USECS 10 /* 100000 irq/sec */
  64. #define E1000_MAX_ITR_USECS 10000 /* 100 irq/sec */
  65. /* this is the size past which hardware will drop packets when setting LPE=0 */
  66. #define MAXIMUM_ETHERNET_VLAN_SIZE 1522
  67. /* Supported Rx Buffer Sizes */
  68. #define E1000_RXBUFFER_128 128 /* Used for packet split */
  69. #define E1000_RXBUFFER_256 256 /* Used for packet split */
  70. #define E1000_RXBUFFER_512 512
  71. #define E1000_RXBUFFER_1024 1024
  72. #define E1000_RXBUFFER_2048 2048
  73. #define E1000_RXBUFFER_4096 4096
  74. #define E1000_RXBUFFER_8192 8192
  75. #define E1000_RXBUFFER_16384 16384
  76. /* SmartSpeed delimiters */
  77. #define E1000_SMARTSPEED_DOWNSHIFT 3
  78. #define E1000_SMARTSPEED_MAX 15
  79. /* Packet Buffer allocations */
  80. #define E1000_PBA_BYTES_SHIFT 0xA
  81. #define E1000_TX_HEAD_ADDR_SHIFT 7
  82. #define E1000_PBA_TX_MASK 0xFFFF0000
  83. /* Flow Control Watermarks */
  84. #define E1000_FC_HIGH_DIFF 0x1638 /* High: 5688 bytes below Rx FIFO size */
  85. #define E1000_FC_LOW_DIFF 0x1640 /* Low: 5696 bytes below Rx FIFO size */
  86. #define E1000_FC_PAUSE_TIME 0xFFFF /* pause for the max or until send xon */
  87. /* How many Tx Descriptors do we need to call netif_wake_queue ? */
  88. #define E1000_TX_QUEUE_WAKE 16
  89. /* How many Rx Buffers do we bundle into one write to the hardware ? */
  90. #define E1000_RX_BUFFER_WRITE 16 /* Must be power of 2 */
  91. #define AUTO_ALL_MODES 0
  92. #define E1000_EEPROM_82544_APM 0x0004
  93. #define E1000_EEPROM_APME 0x0400
  94. #ifndef E1000_MASTER_SLAVE
  95. /* Switch to override PHY master/slave setting */
  96. #define E1000_MASTER_SLAVE e1000_ms_hw_default
  97. #endif
  98. #define E1000_MNG_VLAN_NONE (-1)
  99. /* wrapper around a pointer to a socket buffer,
  100. * so a DMA handle can be stored along with the buffer
  101. */
  102. struct e1000_tx_buffer {
  103. struct sk_buff *skb;
  104. dma_addr_t dma;
  105. unsigned long time_stamp;
  106. u16 length;
  107. u16 next_to_watch;
  108. bool mapped_as_page;
  109. unsigned short segs;
  110. unsigned int bytecount;
  111. };
  112. struct e1000_rx_buffer {
  113. union {
  114. struct page *page; /* jumbo: alloc_page */
  115. u8 *data; /* else, netdev_alloc_frag */
  116. } rxbuf;
  117. dma_addr_t dma;
  118. };
  119. struct e1000_tx_ring {
  120. /* pointer to the descriptor ring memory */
  121. void *desc;
  122. /* physical address of the descriptor ring */
  123. dma_addr_t dma;
  124. /* length of descriptor ring in bytes */
  125. unsigned int size;
  126. /* number of descriptors in the ring */
  127. unsigned int count;
  128. /* next descriptor to associate a buffer with */
  129. unsigned int next_to_use;
  130. /* next descriptor to check for DD status bit */
  131. unsigned int next_to_clean;
  132. /* array of buffer information structs */
  133. struct e1000_tx_buffer *buffer_info;
  134. u16 tdh;
  135. u16 tdt;
  136. bool last_tx_tso;
  137. };
  138. struct e1000_rx_ring {
  139. /* pointer to the descriptor ring memory */
  140. void *desc;
  141. /* physical address of the descriptor ring */
  142. dma_addr_t dma;
  143. /* length of descriptor ring in bytes */
  144. unsigned int size;
  145. /* number of descriptors in the ring */
  146. unsigned int count;
  147. /* next descriptor to associate a buffer with */
  148. unsigned int next_to_use;
  149. /* next descriptor to check for DD status bit */
  150. unsigned int next_to_clean;
  151. /* array of buffer information structs */
  152. struct e1000_rx_buffer *buffer_info;
  153. struct sk_buff *rx_skb_top;
  154. /* cpu for rx queue */
  155. int cpu;
  156. u16 rdh;
  157. u16 rdt;
  158. };
  159. #define E1000_DESC_UNUSED(R) \
  160. ({ \
  161. unsigned int clean = smp_load_acquire(&(R)->next_to_clean); \
  162. unsigned int use = READ_ONCE((R)->next_to_use); \
  163. (clean > use ? 0 : (R)->count) + clean - use - 1; \
  164. })
  165. #define E1000_RX_DESC_EXT(R, i) \
  166. (&(((union e1000_rx_desc_extended *)((R).desc))[i]))
  167. #define E1000_GET_DESC(R, i, type) (&(((struct type *)((R).desc))[i]))
  168. #define E1000_RX_DESC(R, i) E1000_GET_DESC(R, i, e1000_rx_desc)
  169. #define E1000_TX_DESC(R, i) E1000_GET_DESC(R, i, e1000_tx_desc)
  170. #define E1000_CONTEXT_DESC(R, i) E1000_GET_DESC(R, i, e1000_context_desc)
  171. /* board specific private data structure */
  172. struct e1000_adapter {
  173. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  174. u16 mng_vlan_id;
  175. u32 bd_number;
  176. u32 rx_buffer_len;
  177. u32 wol;
  178. u32 smartspeed;
  179. u32 en_mng_pt;
  180. u16 link_speed;
  181. u16 link_duplex;
  182. spinlock_t stats_lock;
  183. unsigned int total_tx_bytes;
  184. unsigned int total_tx_packets;
  185. unsigned int total_rx_bytes;
  186. unsigned int total_rx_packets;
  187. /* Interrupt Throttle Rate */
  188. u32 itr;
  189. u32 itr_setting;
  190. u16 tx_itr;
  191. u16 rx_itr;
  192. u8 fc_autoneg;
  193. /* TX */
  194. struct e1000_tx_ring *tx_ring; /* One per active queue */
  195. unsigned int restart_queue;
  196. u32 txd_cmd;
  197. u32 tx_int_delay;
  198. u32 tx_abs_int_delay;
  199. u32 gotcl;
  200. u64 gotcl_old;
  201. u64 tpt_old;
  202. u64 colc_old;
  203. u32 tx_timeout_count;
  204. u32 tx_fifo_head;
  205. u32 tx_head_addr;
  206. u32 tx_fifo_size;
  207. u8 tx_timeout_factor;
  208. atomic_t tx_fifo_stall;
  209. bool pcix_82544;
  210. bool detect_tx_hung;
  211. bool dump_buffers;
  212. /* RX */
  213. bool (*clean_rx)(struct e1000_adapter *adapter,
  214. struct e1000_rx_ring *rx_ring,
  215. int *work_done, int work_to_do);
  216. void (*alloc_rx_buf)(struct e1000_adapter *adapter,
  217. struct e1000_rx_ring *rx_ring,
  218. int cleaned_count);
  219. struct e1000_rx_ring *rx_ring; /* One per active queue */
  220. struct napi_struct napi;
  221. int num_tx_queues;
  222. int num_rx_queues;
  223. u64 hw_csum_err;
  224. u64 hw_csum_good;
  225. u32 alloc_rx_buff_failed;
  226. u32 rx_int_delay;
  227. u32 rx_abs_int_delay;
  228. bool rx_csum;
  229. u32 gorcl;
  230. u64 gorcl_old;
  231. /* OS defined structs */
  232. struct net_device *netdev;
  233. struct pci_dev *pdev;
  234. /* structs defined in e1000_hw.h */
  235. struct e1000_hw hw;
  236. struct e1000_hw_stats stats;
  237. struct e1000_phy_info phy_info;
  238. struct e1000_phy_stats phy_stats;
  239. u32 test_icr;
  240. struct e1000_tx_ring test_tx_ring;
  241. struct e1000_rx_ring test_rx_ring;
  242. int msg_enable;
  243. /* to not mess up cache alignment, always add to the bottom */
  244. bool tso_force;
  245. bool smart_power_down; /* phy smart power down */
  246. bool quad_port_a;
  247. unsigned long flags;
  248. u32 eeprom_wol;
  249. /* for ioport free */
  250. int bars;
  251. int need_ioport;
  252. bool discarding;
  253. struct work_struct reset_task;
  254. struct delayed_work watchdog_task;
  255. struct delayed_work fifo_stall_task;
  256. struct delayed_work phy_info_task;
  257. };
  258. enum e1000_state_t {
  259. __E1000_TESTING,
  260. __E1000_RESETTING,
  261. __E1000_DOWN,
  262. __E1000_DISABLED
  263. };
  264. #undef pr_fmt
  265. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  266. struct net_device *e1000_get_hw_dev(struct e1000_hw *hw);
  267. #define e_dbg(format, arg...) \
  268. netdev_dbg(e1000_get_hw_dev(hw), format, ## arg)
  269. #define e_err(msglvl, format, arg...) \
  270. netif_err(adapter, msglvl, adapter->netdev, format, ## arg)
  271. #define e_info(msglvl, format, arg...) \
  272. netif_info(adapter, msglvl, adapter->netdev, format, ## arg)
  273. #define e_warn(msglvl, format, arg...) \
  274. netif_warn(adapter, msglvl, adapter->netdev, format, ## arg)
  275. #define e_notice(msglvl, format, arg...) \
  276. netif_notice(adapter, msglvl, adapter->netdev, format, ## arg)
  277. #define e_dev_info(format, arg...) \
  278. dev_info(&adapter->pdev->dev, format, ## arg)
  279. #define e_dev_warn(format, arg...) \
  280. dev_warn(&adapter->pdev->dev, format, ## arg)
  281. #define e_dev_err(format, arg...) \
  282. dev_err(&adapter->pdev->dev, format, ## arg)
  283. extern char e1000_driver_name[];
  284. extern const char e1000_driver_version[];
  285. int e1000_open(struct net_device *netdev);
  286. int e1000_close(struct net_device *netdev);
  287. int e1000_up(struct e1000_adapter *adapter);
  288. void e1000_down(struct e1000_adapter *adapter);
  289. void e1000_reinit_locked(struct e1000_adapter *adapter);
  290. void e1000_reset(struct e1000_adapter *adapter);
  291. int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx);
  292. int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
  293. int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
  294. void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
  295. void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
  296. void e1000_update_stats(struct e1000_adapter *adapter);
  297. bool e1000_has_link(struct e1000_adapter *adapter);
  298. void e1000_power_up_phy(struct e1000_adapter *);
  299. void e1000_set_ethtool_ops(struct net_device *netdev);
  300. void e1000_check_options(struct e1000_adapter *adapter);
  301. char *e1000_get_hw_dev_name(struct e1000_hw *hw);
  302. #endif /* _E1000_H_ */