e1000.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /*******************************************************************************
  2. Copyright(c) 1999 - 2006 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. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. /* Linux PRO/1000 Ethernet Driver main header file */
  22. #ifndef _E1000_H_
  23. #define _E1000_H_
  24. #include <linux/stddef.h>
  25. #include <linux/config.h>
  26. #include <linux/module.h>
  27. #include <linux/types.h>
  28. #include <asm/byteorder.h>
  29. #include <linux/init.h>
  30. #include <linux/mm.h>
  31. #include <linux/errno.h>
  32. #include <linux/ioport.h>
  33. #include <linux/pci.h>
  34. #include <linux/kernel.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/etherdevice.h>
  37. #include <linux/skbuff.h>
  38. #include <linux/delay.h>
  39. #include <linux/timer.h>
  40. #include <linux/slab.h>
  41. #include <linux/vmalloc.h>
  42. #include <linux/interrupt.h>
  43. #include <linux/string.h>
  44. #include <linux/pagemap.h>
  45. #include <linux/dma-mapping.h>
  46. #include <linux/bitops.h>
  47. #include <asm/io.h>
  48. #include <asm/irq.h>
  49. #include <linux/capability.h>
  50. #include <linux/in.h>
  51. #include <linux/ip.h>
  52. #include <linux/tcp.h>
  53. #include <linux/udp.h>
  54. #include <net/pkt_sched.h>
  55. #include <linux/list.h>
  56. #include <linux/reboot.h>
  57. #ifdef NETIF_F_TSO
  58. #include <net/checksum.h>
  59. #endif
  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 DBG
  71. #define E1000_DBG(args...) printk(KERN_DEBUG "e1000: " args)
  72. #else
  73. #define E1000_DBG(args...)
  74. #endif
  75. #define E1000_ERR(args...) printk(KERN_ERR "e1000: " args)
  76. #define PFX "e1000: "
  77. #define DPRINTK(nlevel, klevel, fmt, args...) \
  78. (void)((NETIF_MSG_##nlevel & adapter->msg_enable) && \
  79. printk(KERN_##klevel PFX "%s: %s: " fmt, adapter->netdev->name, \
  80. __FUNCTION__ , ## args))
  81. #define E1000_MAX_INTR 10
  82. /* TX/RX descriptor defines */
  83. #define E1000_DEFAULT_TXD 256
  84. #define E1000_MAX_TXD 256
  85. #define E1000_MIN_TXD 80
  86. #define E1000_MAX_82544_TXD 4096
  87. #define E1000_DEFAULT_RXD 256
  88. #define E1000_MAX_RXD 256
  89. #define E1000_MIN_RXD 80
  90. #define E1000_MAX_82544_RXD 4096
  91. /* Supported Rx Buffer Sizes */
  92. #define E1000_RXBUFFER_128 128 /* Used for packet split */
  93. #define E1000_RXBUFFER_256 256 /* Used for packet split */
  94. #define E1000_RXBUFFER_512 512
  95. #define E1000_RXBUFFER_1024 1024
  96. #define E1000_RXBUFFER_2048 2048
  97. #define E1000_RXBUFFER_4096 4096
  98. #define E1000_RXBUFFER_8192 8192
  99. #define E1000_RXBUFFER_16384 16384
  100. /* SmartSpeed delimiters */
  101. #define E1000_SMARTSPEED_DOWNSHIFT 3
  102. #define E1000_SMARTSPEED_MAX 15
  103. /* Packet Buffer allocations */
  104. #define E1000_PBA_BYTES_SHIFT 0xA
  105. #define E1000_TX_HEAD_ADDR_SHIFT 7
  106. #define E1000_PBA_TX_MASK 0xFFFF0000
  107. /* Flow Control Watermarks */
  108. #define E1000_FC_HIGH_DIFF 0x1638 /* High: 5688 bytes below Rx FIFO size */
  109. #define E1000_FC_LOW_DIFF 0x1640 /* Low: 5696 bytes below Rx FIFO size */
  110. #define E1000_FC_PAUSE_TIME 0x0680 /* 858 usec */
  111. /* How many Tx Descriptors do we need to call netif_wake_queue ? */
  112. #define E1000_TX_QUEUE_WAKE 16
  113. /* How many Rx Buffers do we bundle into one write to the hardware ? */
  114. #define E1000_RX_BUFFER_WRITE 16 /* Must be power of 2 */
  115. #define AUTO_ALL_MODES 0
  116. #define E1000_EEPROM_82544_APM 0x0004
  117. #define E1000_EEPROM_ICH8_APME 0x0004
  118. #define E1000_EEPROM_APME 0x0400
  119. #ifndef E1000_MASTER_SLAVE
  120. /* Switch to override PHY master/slave setting */
  121. #define E1000_MASTER_SLAVE e1000_ms_hw_default
  122. #endif
  123. #define E1000_MNG_VLAN_NONE -1
  124. /* Number of packet split data buffers (not including the header buffer) */
  125. #define PS_PAGE_BUFFERS MAX_PS_BUFFERS-1
  126. /* only works for sizes that are powers of 2 */
  127. #define E1000_ROUNDUP(i, size) ((i) = (((i) + (size) - 1) & ~((size) - 1)))
  128. /* wrapper around a pointer to a socket buffer,
  129. * so a DMA handle can be stored along with the buffer */
  130. struct e1000_buffer {
  131. struct sk_buff *skb;
  132. dma_addr_t dma;
  133. unsigned long time_stamp;
  134. uint16_t length;
  135. uint16_t next_to_watch;
  136. };
  137. struct e1000_ps_page { struct page *ps_page[PS_PAGE_BUFFERS]; };
  138. struct e1000_ps_page_dma { uint64_t ps_page_dma[PS_PAGE_BUFFERS]; };
  139. struct e1000_tx_ring {
  140. /* pointer to the descriptor ring memory */
  141. void *desc;
  142. /* physical address of the descriptor ring */
  143. dma_addr_t dma;
  144. /* length of descriptor ring in bytes */
  145. unsigned int size;
  146. /* number of descriptors in the ring */
  147. unsigned int count;
  148. /* next descriptor to associate a buffer with */
  149. unsigned int next_to_use;
  150. /* next descriptor to check for DD status bit */
  151. unsigned int next_to_clean;
  152. /* array of buffer information structs */
  153. struct e1000_buffer *buffer_info;
  154. spinlock_t tx_lock;
  155. uint16_t tdh;
  156. uint16_t tdt;
  157. boolean_t last_tx_tso;
  158. };
  159. struct e1000_rx_ring {
  160. /* pointer to the descriptor ring memory */
  161. void *desc;
  162. /* physical address of the descriptor ring */
  163. dma_addr_t dma;
  164. /* length of descriptor ring in bytes */
  165. unsigned int size;
  166. /* number of descriptors in the ring */
  167. unsigned int count;
  168. /* next descriptor to associate a buffer with */
  169. unsigned int next_to_use;
  170. /* next descriptor to check for DD status bit */
  171. unsigned int next_to_clean;
  172. /* array of buffer information structs */
  173. struct e1000_buffer *buffer_info;
  174. /* arrays of page information for packet split */
  175. struct e1000_ps_page *ps_page;
  176. struct e1000_ps_page_dma *ps_page_dma;
  177. /* cpu for rx queue */
  178. int cpu;
  179. uint16_t rdh;
  180. uint16_t rdt;
  181. };
  182. #define E1000_DESC_UNUSED(R) \
  183. ((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
  184. (R)->next_to_clean - (R)->next_to_use - 1)
  185. #define E1000_RX_DESC_PS(R, i) \
  186. (&(((union e1000_rx_desc_packet_split *)((R).desc))[i]))
  187. #define E1000_RX_DESC_EXT(R, i) \
  188. (&(((union e1000_rx_desc_extended *)((R).desc))[i]))
  189. #define E1000_GET_DESC(R, i, type) (&(((struct type *)((R).desc))[i]))
  190. #define E1000_RX_DESC(R, i) E1000_GET_DESC(R, i, e1000_rx_desc)
  191. #define E1000_TX_DESC(R, i) E1000_GET_DESC(R, i, e1000_tx_desc)
  192. #define E1000_CONTEXT_DESC(R, i) E1000_GET_DESC(R, i, e1000_context_desc)
  193. /* board specific private data structure */
  194. struct e1000_adapter {
  195. struct timer_list tx_fifo_stall_timer;
  196. struct timer_list watchdog_timer;
  197. struct timer_list phy_info_timer;
  198. struct vlan_group *vlgrp;
  199. uint16_t mng_vlan_id;
  200. uint32_t bd_number;
  201. uint32_t rx_buffer_len;
  202. uint32_t part_num;
  203. uint32_t wol;
  204. uint32_t ksp3_port_a;
  205. uint32_t smartspeed;
  206. uint32_t en_mng_pt;
  207. uint16_t link_speed;
  208. uint16_t link_duplex;
  209. spinlock_t stats_lock;
  210. #ifdef CONFIG_E1000_NAPI
  211. spinlock_t tx_queue_lock;
  212. #endif
  213. atomic_t irq_sem;
  214. struct work_struct reset_task;
  215. uint8_t fc_autoneg;
  216. struct timer_list blink_timer;
  217. unsigned long led_status;
  218. /* TX */
  219. struct e1000_tx_ring *tx_ring; /* One per active queue */
  220. unsigned long tx_queue_len;
  221. uint32_t txd_cmd;
  222. uint32_t tx_int_delay;
  223. uint32_t tx_abs_int_delay;
  224. uint32_t gotcl;
  225. uint64_t gotcl_old;
  226. uint64_t tpt_old;
  227. uint64_t colc_old;
  228. uint32_t tx_timeout_count;
  229. uint32_t tx_fifo_head;
  230. uint32_t tx_head_addr;
  231. uint32_t tx_fifo_size;
  232. uint8_t tx_timeout_factor;
  233. atomic_t tx_fifo_stall;
  234. boolean_t pcix_82544;
  235. boolean_t detect_tx_hung;
  236. /* RX */
  237. #ifdef CONFIG_E1000_NAPI
  238. boolean_t (*clean_rx) (struct e1000_adapter *adapter,
  239. struct e1000_rx_ring *rx_ring,
  240. int *work_done, int work_to_do);
  241. #else
  242. boolean_t (*clean_rx) (struct e1000_adapter *adapter,
  243. struct e1000_rx_ring *rx_ring);
  244. #endif
  245. void (*alloc_rx_buf) (struct e1000_adapter *adapter,
  246. struct e1000_rx_ring *rx_ring,
  247. int cleaned_count);
  248. struct e1000_rx_ring *rx_ring; /* One per active queue */
  249. #ifdef CONFIG_E1000_NAPI
  250. struct net_device *polling_netdev; /* One per active queue */
  251. #endif
  252. int num_tx_queues;
  253. int num_rx_queues;
  254. uint64_t hw_csum_err;
  255. uint64_t hw_csum_good;
  256. uint64_t rx_hdr_split;
  257. uint32_t alloc_rx_buff_failed;
  258. uint32_t rx_int_delay;
  259. uint32_t rx_abs_int_delay;
  260. boolean_t rx_csum;
  261. unsigned int rx_ps_pages;
  262. uint32_t gorcl;
  263. uint64_t gorcl_old;
  264. uint16_t rx_ps_bsize0;
  265. /* Interrupt Throttle Rate */
  266. uint32_t itr;
  267. /* OS defined structs */
  268. struct net_device *netdev;
  269. struct pci_dev *pdev;
  270. struct net_device_stats net_stats;
  271. /* structs defined in e1000_hw.h */
  272. struct e1000_hw hw;
  273. struct e1000_hw_stats stats;
  274. struct e1000_phy_info phy_info;
  275. struct e1000_phy_stats phy_stats;
  276. uint32_t test_icr;
  277. struct e1000_tx_ring test_tx_ring;
  278. struct e1000_rx_ring test_rx_ring;
  279. uint32_t *config_space;
  280. int msg_enable;
  281. #ifdef CONFIG_PCI_MSI
  282. boolean_t have_msi;
  283. #endif
  284. /* to not mess up cache alignment, always add to the bottom */
  285. #ifdef NETIF_F_TSO
  286. boolean_t tso_force;
  287. #endif
  288. boolean_t smart_power_down; /* phy smart power down */
  289. unsigned long flags;
  290. };
  291. enum e1000_state_t {
  292. __E1000_DRIVER_TESTING,
  293. __E1000_RESETTING,
  294. };
  295. /* e1000_main.c */
  296. extern char e1000_driver_name[];
  297. extern char e1000_driver_version[];
  298. int e1000_up(struct e1000_adapter *adapter);
  299. void e1000_down(struct e1000_adapter *adapter);
  300. void e1000_reset(struct e1000_adapter *adapter);
  301. void e1000_reinit_locked(struct e1000_adapter *adapter);
  302. int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
  303. void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
  304. int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
  305. void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
  306. void e1000_update_stats(struct e1000_adapter *adapter);
  307. int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
  308. /* e1000_ethtool.c */
  309. void e1000_set_ethtool_ops(struct net_device *netdev);
  310. /* e1000_param.c */
  311. void e1000_check_options(struct e1000_adapter *adapter);
  312. #endif /* _E1000_H_ */