1 /*******************************************************************************
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
26 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *******************************************************************************/
31 /* Linux PRO/1000 Ethernet Driver main header file */
36 #include <linux/stddef.h>
37 #include <linux/module.h>
38 #include <linux/types.h>
39 #include <asm/byteorder.h>
40 #include <linux/init.h>
42 #include <linux/errno.h>
43 #include <linux/ioport.h>
44 #include <linux/pci.h>
45 #include <linux/kernel.h>
46 #include <linux/netdevice.h>
47 #include <linux/etherdevice.h>
48 #include <linux/skbuff.h>
49 #include <linux/delay.h>
50 #include <linux/timer.h>
51 #include <linux/slab.h>
52 #include <linux/vmalloc.h>
53 #include <linux/interrupt.h>
54 #include <linux/string.h>
55 #include <linux/pagemap.h>
56 #include <linux/dma-mapping.h>
57 #include <linux/bitops.h>
60 #include <linux/capability.h>
63 #include <linux/tcp.h>
64 #include <linux/udp.h>
65 #include <net/pkt_sched.h>
66 #include <linux/list.h>
67 #include <linux/reboot.h>
69 #include <net/checksum.h>
71 #include <linux/mii.h>
72 #include <linux/ethtool.h>
73 #include <linux/if_vlan.h>
79 #define INTEL_E1000_ETHERNET_DEVICE(device_id) {\
80 PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
87 #define E1000_DBG(args...) printk(KERN_DEBUG "e1000: " args)
89 #define E1000_DBG(args...)
92 #define E1000_ERR(args...) printk(KERN_ERR "e1000: " args)
95 #define DPRINTK(nlevel, klevel, fmt, args...) \
96 (void)((NETIF_MSG_##nlevel & adapter->msg_enable) && \
97 printk(KERN_##klevel PFX "%s: %s: " fmt, adapter->netdev->name, \
98 __FUNCTION__ , ## args))
100 #define E1000_MAX_INTR 10
102 /* TX/RX descriptor defines */
103 #define E1000_DEFAULT_TXD 256
104 #define E1000_MAX_TXD 256
105 #define E1000_MIN_TXD 80
106 #define E1000_MAX_82544_TXD 4096
108 #define E1000_DEFAULT_RXD 256
109 #define E1000_MAX_RXD 256
110 #define E1000_MIN_RXD 80
111 #define E1000_MAX_82544_RXD 4096
113 /* Supported Rx Buffer Sizes */
114 #define E1000_RXBUFFER_128 128 /* Used for packet split */
115 #define E1000_RXBUFFER_256 256 /* Used for packet split */
116 #define E1000_RXBUFFER_512 512
117 #define E1000_RXBUFFER_1024 1024
118 #define E1000_RXBUFFER_2048 2048
119 #define E1000_RXBUFFER_4096 4096
120 #define E1000_RXBUFFER_8192 8192
121 #define E1000_RXBUFFER_16384 16384
123 /* SmartSpeed delimiters */
124 #define E1000_SMARTSPEED_DOWNSHIFT 3
125 #define E1000_SMARTSPEED_MAX 15
127 /* Packet Buffer allocations */
128 #define E1000_PBA_BYTES_SHIFT 0xA
129 #define E1000_TX_HEAD_ADDR_SHIFT 7
130 #define E1000_PBA_TX_MASK 0xFFFF0000
132 /* Flow Control Watermarks */
133 #define E1000_FC_HIGH_DIFF 0x1638 /* High: 5688 bytes below Rx FIFO size */
134 #define E1000_FC_LOW_DIFF 0x1640 /* Low: 5696 bytes below Rx FIFO size */
136 #define E1000_FC_PAUSE_TIME 0x0680 /* 858 usec */
138 /* How many Tx Descriptors do we need to call netif_wake_queue ? */
139 #define E1000_TX_QUEUE_WAKE 16
140 /* How many Rx Buffers do we bundle into one write to the hardware ? */
141 #define E1000_RX_BUFFER_WRITE 16 /* Must be power of 2 */
143 #define AUTO_ALL_MODES 0
144 #define E1000_EEPROM_82544_APM 0x0004
145 #define E1000_EEPROM_ICH8_APME 0x0004
146 #define E1000_EEPROM_APME 0x0400
148 #ifndef E1000_MASTER_SLAVE
149 /* Switch to override PHY master/slave setting */
150 #define E1000_MASTER_SLAVE e1000_ms_hw_default
153 #define E1000_MNG_VLAN_NONE -1
154 /* Number of packet split data buffers (not including the header buffer) */
155 #define PS_PAGE_BUFFERS MAX_PS_BUFFERS-1
157 /* only works for sizes that are powers of 2 */
158 #define E1000_ROUNDUP(i, size) ((i) = (((i) + (size) - 1) & ~((size) - 1)))
160 /* wrapper around a pointer to a socket buffer,
161 * so a DMA handle can be stored along with the buffer */
162 struct e1000_buffer
{
165 unsigned long time_stamp
;
167 uint16_t next_to_watch
;
171 struct e1000_ps_page
{ struct page
*ps_page
[PS_PAGE_BUFFERS
]; };
172 struct e1000_ps_page_dma
{ uint64_t ps_page_dma
[PS_PAGE_BUFFERS
]; };
174 struct e1000_tx_ring
{
175 /* pointer to the descriptor ring memory */
177 /* physical address of the descriptor ring */
179 /* length of descriptor ring in bytes */
181 /* number of descriptors in the ring */
183 /* next descriptor to associate a buffer with */
184 unsigned int next_to_use
;
185 /* next descriptor to check for DD status bit */
186 unsigned int next_to_clean
;
187 /* array of buffer information structs */
188 struct e1000_buffer
*buffer_info
;
193 boolean_t last_tx_tso
;
196 struct e1000_rx_ring
{
197 /* pointer to the descriptor ring memory */
199 /* physical address of the descriptor ring */
201 /* length of descriptor ring in bytes */
203 /* number of descriptors in the ring */
205 /* next descriptor to associate a buffer with */
206 unsigned int next_to_use
;
207 /* next descriptor to check for DD status bit */
208 unsigned int next_to_clean
;
209 /* array of buffer information structs */
210 struct e1000_buffer
*buffer_info
;
211 /* arrays of page information for packet split */
212 struct e1000_ps_page
*ps_page
;
213 struct e1000_ps_page_dma
*ps_page_dma
;
215 /* cpu for rx queue */
222 #define E1000_DESC_UNUSED(R) \
223 ((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
224 (R)->next_to_clean - (R)->next_to_use - 1)
226 #define E1000_RX_DESC_PS(R, i) \
227 (&(((union e1000_rx_desc_packet_split *)((R).desc))[i]))
228 #define E1000_RX_DESC_EXT(R, i) \
229 (&(((union e1000_rx_desc_extended *)((R).desc))[i]))
230 #define E1000_GET_DESC(R, i, type) (&(((struct type *)((R).desc))[i]))
231 #define E1000_RX_DESC(R, i) E1000_GET_DESC(R, i, e1000_rx_desc)
232 #define E1000_TX_DESC(R, i) E1000_GET_DESC(R, i, e1000_tx_desc)
233 #define E1000_CONTEXT_DESC(R, i) E1000_GET_DESC(R, i, e1000_context_desc)
235 /* board specific private data structure */
237 struct e1000_adapter
{
238 struct timer_list tx_fifo_stall_timer
;
239 struct timer_list watchdog_timer
;
240 struct timer_list phy_info_timer
;
241 struct vlan_group
*vlgrp
;
242 uint16_t mng_vlan_id
;
244 uint32_t rx_buffer_len
;
247 uint32_t ksp3_port_a
;
251 uint16_t link_duplex
;
252 spinlock_t stats_lock
;
253 #ifdef CONFIG_E1000_NAPI
254 spinlock_t tx_queue_lock
;
257 struct work_struct reset_task
;
260 struct timer_list blink_timer
;
261 unsigned long led_status
;
264 struct e1000_tx_ring
*tx_ring
; /* One per active queue */
265 unsigned long tx_queue_len
;
267 uint32_t tx_int_delay
;
268 uint32_t tx_abs_int_delay
;
273 uint32_t tx_timeout_count
;
274 uint32_t tx_fifo_head
;
275 uint32_t tx_head_addr
;
276 uint32_t tx_fifo_size
;
277 uint8_t tx_timeout_factor
;
278 atomic_t tx_fifo_stall
;
279 boolean_t pcix_82544
;
280 boolean_t detect_tx_hung
;
283 #ifdef CONFIG_E1000_NAPI
284 boolean_t (*clean_rx
) (struct e1000_adapter
*adapter
,
285 struct e1000_rx_ring
*rx_ring
,
286 int *work_done
, int work_to_do
);
288 boolean_t (*clean_rx
) (struct e1000_adapter
*adapter
,
289 struct e1000_rx_ring
*rx_ring
);
291 void (*alloc_rx_buf
) (struct e1000_adapter
*adapter
,
292 struct e1000_rx_ring
*rx_ring
,
294 struct e1000_rx_ring
*rx_ring
; /* One per active queue */
295 #ifdef CONFIG_E1000_NAPI
296 struct net_device
*polling_netdev
; /* One per active queue */
301 uint64_t hw_csum_err
;
302 uint64_t hw_csum_good
;
303 uint64_t rx_hdr_split
;
304 uint32_t alloc_rx_buff_failed
;
305 uint32_t rx_int_delay
;
306 uint32_t rx_abs_int_delay
;
308 unsigned int rx_ps_pages
;
311 uint16_t rx_ps_bsize0
;
313 /* Interrupt Throttle Rate */
316 /* OS defined structs */
317 struct net_device
*netdev
;
318 struct pci_dev
*pdev
;
319 struct net_device_stats net_stats
;
321 /* structs defined in e1000_hw.h */
323 struct e1000_hw_stats stats
;
324 struct e1000_phy_info phy_info
;
325 struct e1000_phy_stats phy_stats
;
328 struct e1000_tx_ring test_tx_ring
;
329 struct e1000_rx_ring test_rx_ring
;
332 uint32_t *config_space
;
334 #ifdef CONFIG_PCI_MSI
337 /* to not mess up cache alignment, always add to the bottom */
341 boolean_t smart_power_down
; /* phy smart power down */
346 __E1000_DRIVER_TESTING
,
351 extern char e1000_driver_name
[];
352 extern char e1000_driver_version
[];
353 int e1000_up(struct e1000_adapter
*adapter
);
354 void e1000_down(struct e1000_adapter
*adapter
);
355 void e1000_reset(struct e1000_adapter
*adapter
);
356 void e1000_reinit_locked(struct e1000_adapter
*adapter
);
357 int e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
);
358 void e1000_free_all_tx_resources(struct e1000_adapter
*adapter
);
359 int e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
);
360 void e1000_free_all_rx_resources(struct e1000_adapter
*adapter
);
361 void e1000_update_stats(struct e1000_adapter
*adapter
);
362 int e1000_set_spd_dplx(struct e1000_adapter
*adapter
, uint16_t spddplx
);
364 /* e1000_ethtool.c */
365 void e1000_set_ethtool_ops(struct net_device
*netdev
);
368 void e1000_check_options(struct e1000_adapter
*adapter
);
371 #endif /* _E1000_H_ */