e1000.h 9.4 KB

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