e1000.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*******************************************************************************
  2. Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the Free
  5. Software Foundation; either version 2 of the License, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc., 59
  13. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. The full GNU General Public License is included in this distribution in the
  15. file called LICENSE.
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. /* Linux PRO/1000 Ethernet Driver main header file */
  21. #ifndef _E1000_H_
  22. #define _E1000_H_
  23. #include <linux/stddef.h>
  24. #include <linux/config.h>
  25. #include <linux/module.h>
  26. #include <linux/types.h>
  27. #include <asm/byteorder.h>
  28. #include <linux/init.h>
  29. #include <linux/mm.h>
  30. #include <linux/errno.h>
  31. #include <linux/ioport.h>
  32. #include <linux/pci.h>
  33. #include <linux/kernel.h>
  34. #include <linux/netdevice.h>
  35. #include <linux/etherdevice.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/delay.h>
  38. #include <linux/timer.h>
  39. #include <linux/slab.h>
  40. #include <linux/vmalloc.h>
  41. #include <linux/interrupt.h>
  42. #include <linux/string.h>
  43. #include <linux/pagemap.h>
  44. #include <linux/dma-mapping.h>
  45. #include <linux/bitops.h>
  46. #include <asm/io.h>
  47. #include <asm/irq.h>
  48. #include <linux/capability.h>
  49. #include <linux/in.h>
  50. #include <linux/ip.h>
  51. #include <linux/tcp.h>
  52. #include <linux/udp.h>
  53. #include <net/pkt_sched.h>
  54. #include <linux/list.h>
  55. #include <linux/reboot.h>
  56. #ifdef NETIF_F_TSO
  57. #include <net/checksum.h>
  58. #endif
  59. #include <linux/workqueue.h>
  60. #include <linux/mii.h>
  61. #include <linux/ethtool.h>
  62. #include <linux/if_vlan.h>
  63. #define BAR_0 0
  64. #define BAR_1 1
  65. #define BAR_5 5
  66. #define INTEL_E1000_ETHERNET_DEVICE(device_id) {\
  67. PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
  68. struct e1000_adapter;
  69. #include "e1000_hw.h"
  70. #ifdef CONFIG_E1000_MQ
  71. #include <linux/cpu.h>
  72. #include <linux/smp.h>
  73. #endif
  74. #ifdef DBG
  75. #define E1000_DBG(args...) printk(KERN_DEBUG "e1000: " args)
  76. #else
  77. #define E1000_DBG(args...)
  78. #endif
  79. #define E1000_ERR(args...) printk(KERN_ERR "e1000: " args)
  80. #define PFX "e1000: "
  81. #define DPRINTK(nlevel, klevel, fmt, args...) \
  82. (void)((NETIF_MSG_##nlevel & adapter->msg_enable) && \
  83. printk(KERN_##klevel PFX "%s: %s: " fmt, adapter->netdev->name, \
  84. __FUNCTION__ , ## args))
  85. #define E1000_MAX_INTR 10
  86. /* TX/RX descriptor defines */
  87. #define E1000_DEFAULT_TXD 256
  88. #define E1000_MAX_TXD 256
  89. #define E1000_MIN_TXD 80
  90. #define E1000_MAX_82544_TXD 4096
  91. #define E1000_DEFAULT_RXD 256
  92. #define E1000_MAX_RXD 256
  93. #define E1000_MIN_RXD 80
  94. #define E1000_MAX_82544_RXD 4096
  95. /* Supported Rx Buffer Sizes */
  96. #define E1000_RXBUFFER_128 128 /* Used for packet split */
  97. #define E1000_RXBUFFER_256 256 /* Used for packet split */
  98. #define E1000_RXBUFFER_2048 2048
  99. #define E1000_RXBUFFER_4096 4096
  100. #define E1000_RXBUFFER_8192 8192
  101. #define E1000_RXBUFFER_16384 16384
  102. /* SmartSpeed delimiters */
  103. #define E1000_SMARTSPEED_DOWNSHIFT 3
  104. #define E1000_SMARTSPEED_MAX 15
  105. /* Packet Buffer allocations */
  106. #define E1000_PBA_BYTES_SHIFT 0xA
  107. #define E1000_TX_HEAD_ADDR_SHIFT 7
  108. #define E1000_PBA_TX_MASK 0xFFFF0000
  109. /* Flow Control Watermarks */
  110. #define E1000_FC_HIGH_DIFF 0x1638 /* High: 5688 bytes below Rx FIFO size */
  111. #define E1000_FC_LOW_DIFF 0x1640 /* Low: 5696 bytes below Rx FIFO size */
  112. #define E1000_FC_PAUSE_TIME 0x0680 /* 858 usec */
  113. /* How many Tx Descriptors do we need to call netif_wake_queue ? */
  114. #define E1000_TX_QUEUE_WAKE 16
  115. /* How many Rx Buffers do we bundle into one write to the hardware ? */
  116. #define E1000_RX_BUFFER_WRITE 16 /* Must be power of 2 */
  117. #define AUTO_ALL_MODES 0
  118. #define E1000_EEPROM_82544_APM 0x0004
  119. #define E1000_EEPROM_APME 0x0400
  120. #ifndef E1000_MASTER_SLAVE
  121. /* Switch to override PHY master/slave setting */
  122. #define E1000_MASTER_SLAVE e1000_ms_hw_default
  123. #endif
  124. #define E1000_MNG_VLAN_NONE -1
  125. /* Number of packet split data buffers (not including the header buffer) */
  126. #define PS_PAGE_BUFFERS MAX_PS_BUFFERS-1
  127. /* only works for sizes that are powers of 2 */
  128. #define E1000_ROUNDUP(i, size) ((i) = (((i) + (size) - 1) & ~((size) - 1)))
  129. /* wrapper around a pointer to a socket buffer,
  130. * so a DMA handle can be stored along with the buffer */
  131. struct e1000_buffer {
  132. struct sk_buff *skb;
  133. dma_addr_t dma;
  134. unsigned long time_stamp;
  135. uint16_t length;
  136. uint16_t next_to_watch;
  137. };
  138. #ifdef CONFIG_E1000_MQ
  139. struct e1000_queue_stats {
  140. uint64_t packets;
  141. uint64_t bytes;
  142. };
  143. #endif
  144. struct e1000_ps_page { struct page *ps_page[PS_PAGE_BUFFERS]; };
  145. struct e1000_ps_page_dma { uint64_t ps_page_dma[PS_PAGE_BUFFERS]; };
  146. struct e1000_tx_ring {
  147. /* pointer to the descriptor ring memory */
  148. void *desc;
  149. /* physical address of the descriptor ring */
  150. dma_addr_t dma;
  151. /* length of descriptor ring in bytes */
  152. unsigned int size;
  153. /* number of descriptors in the ring */
  154. unsigned int count;
  155. /* next descriptor to associate a buffer with */
  156. unsigned int next_to_use;
  157. /* next descriptor to check for DD status bit */
  158. unsigned int next_to_clean;
  159. /* array of buffer information structs */
  160. struct e1000_buffer *buffer_info;
  161. spinlock_t tx_lock;
  162. uint16_t tdh;
  163. uint16_t tdt;
  164. boolean_t last_tx_tso;
  165. #ifdef CONFIG_E1000_MQ
  166. struct e1000_queue_stats tx_stats;
  167. #endif
  168. };
  169. struct e1000_rx_ring {
  170. /* pointer to the descriptor ring memory */
  171. void *desc;
  172. /* physical address of the descriptor ring */
  173. dma_addr_t dma;
  174. /* length of descriptor ring in bytes */
  175. unsigned int size;
  176. /* number of descriptors in the ring */
  177. unsigned int count;
  178. /* next descriptor to associate a buffer with */
  179. unsigned int next_to_use;
  180. /* next descriptor to check for DD status bit */
  181. unsigned int next_to_clean;
  182. /* array of buffer information structs */
  183. struct e1000_buffer *buffer_info;
  184. /* arrays of page information for packet split */
  185. struct e1000_ps_page *ps_page;
  186. struct e1000_ps_page_dma *ps_page_dma;
  187. struct sk_buff *rx_skb_top;
  188. struct sk_buff *rx_skb_prev;
  189. /* cpu for rx queue */
  190. int cpu;
  191. uint16_t rdh;
  192. uint16_t rdt;
  193. #ifdef CONFIG_E1000_MQ
  194. struct e1000_queue_stats rx_stats;
  195. #endif
  196. };
  197. #define E1000_DESC_UNUSED(R) \
  198. ((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
  199. (R)->next_to_clean - (R)->next_to_use - 1)
  200. #define E1000_RX_DESC_PS(R, i) \
  201. (&(((union e1000_rx_desc_packet_split *)((R).desc))[i]))
  202. #define E1000_RX_DESC_EXT(R, i) \
  203. (&(((union e1000_rx_desc_extended *)((R).desc))[i]))
  204. #define E1000_GET_DESC(R, i, type) (&(((struct type *)((R).desc))[i]))
  205. #define E1000_RX_DESC(R, i) E1000_GET_DESC(R, i, e1000_rx_desc)
  206. #define E1000_TX_DESC(R, i) E1000_GET_DESC(R, i, e1000_tx_desc)
  207. #define E1000_CONTEXT_DESC(R, i) E1000_GET_DESC(R, i, e1000_context_desc)
  208. /* board specific private data structure */
  209. struct e1000_adapter {
  210. struct timer_list tx_fifo_stall_timer;
  211. struct timer_list watchdog_timer;
  212. struct timer_list phy_info_timer;
  213. struct vlan_group *vlgrp;
  214. uint16_t mng_vlan_id;
  215. uint32_t bd_number;
  216. uint32_t rx_buffer_len;
  217. uint32_t part_num;
  218. uint32_t wol;
  219. uint32_t smartspeed;
  220. uint32_t en_mng_pt;
  221. uint16_t link_speed;
  222. uint16_t link_duplex;
  223. spinlock_t stats_lock;
  224. #ifdef CONFIG_E1000_NAPI
  225. spinlock_t tx_queue_lock;
  226. #endif
  227. atomic_t irq_sem;
  228. struct work_struct tx_timeout_task;
  229. struct work_struct watchdog_task;
  230. uint8_t fc_autoneg;
  231. struct timer_list blink_timer;
  232. unsigned long led_status;
  233. /* TX */
  234. struct e1000_tx_ring *tx_ring; /* One per active queue */
  235. #ifdef CONFIG_E1000_MQ
  236. struct e1000_tx_ring **cpu_tx_ring; /* per-cpu */
  237. #endif
  238. unsigned long tx_queue_len;
  239. uint32_t txd_cmd;
  240. uint32_t tx_int_delay;
  241. uint32_t tx_abs_int_delay;
  242. uint32_t gotcl;
  243. uint64_t gotcl_old;
  244. uint64_t tpt_old;
  245. uint64_t colc_old;
  246. uint32_t tx_timeout_count;
  247. uint32_t tx_fifo_head;
  248. uint32_t tx_head_addr;
  249. uint32_t tx_fifo_size;
  250. uint8_t tx_timeout_factor;
  251. atomic_t tx_fifo_stall;
  252. boolean_t pcix_82544;
  253. boolean_t detect_tx_hung;
  254. /* RX */
  255. #ifdef CONFIG_E1000_NAPI
  256. boolean_t (*clean_rx) (struct e1000_adapter *adapter,
  257. struct e1000_rx_ring *rx_ring,
  258. int *work_done, int work_to_do);
  259. #else
  260. boolean_t (*clean_rx) (struct e1000_adapter *adapter,
  261. struct e1000_rx_ring *rx_ring);
  262. #endif
  263. void (*alloc_rx_buf) (struct e1000_adapter *adapter,
  264. struct e1000_rx_ring *rx_ring,
  265. int cleaned_count);
  266. struct e1000_rx_ring *rx_ring; /* One per active queue */
  267. #ifdef CONFIG_E1000_NAPI
  268. struct net_device *polling_netdev; /* One per active queue */
  269. #endif
  270. #ifdef CONFIG_E1000_MQ
  271. struct net_device **cpu_netdev; /* per-cpu */
  272. struct call_async_data_struct rx_sched_call_data;
  273. cpumask_t cpumask;
  274. #endif
  275. int num_tx_queues;
  276. int num_rx_queues;
  277. uint64_t hw_csum_err;
  278. uint64_t hw_csum_good;
  279. uint64_t rx_hdr_split;
  280. uint32_t alloc_rx_buff_failed;
  281. uint32_t rx_int_delay;
  282. uint32_t rx_abs_int_delay;
  283. boolean_t rx_csum;
  284. unsigned int rx_ps_pages;
  285. uint32_t gorcl;
  286. uint64_t gorcl_old;
  287. uint16_t rx_ps_bsize0;
  288. /* Interrupt Throttle Rate */
  289. uint32_t itr;
  290. /* OS defined structs */
  291. struct net_device *netdev;
  292. struct pci_dev *pdev;
  293. struct net_device_stats net_stats;
  294. /* structs defined in e1000_hw.h */
  295. struct e1000_hw hw;
  296. struct e1000_hw_stats stats;
  297. struct e1000_phy_info phy_info;
  298. struct e1000_phy_stats phy_stats;
  299. uint32_t test_icr;
  300. struct e1000_tx_ring test_tx_ring;
  301. struct e1000_rx_ring test_rx_ring;
  302. u32 *config_space;
  303. int msg_enable;
  304. #ifdef CONFIG_PCI_MSI
  305. boolean_t have_msi;
  306. #endif
  307. };
  308. #endif /* _E1000_H_ */