fp@1360: /*******************************************************************************
fp@1360: 
fp@1360:   Intel PRO/1000 Linux driver
fp@1360:   Copyright(c) 1999 - 2006 Intel Corporation.
fp@1360: 
fp@1360:   This program is free software; you can redistribute it and/or modify it
fp@1360:   under the terms and conditions of the GNU General Public License,
fp@1360:   version 2, as published by the Free Software Foundation.
fp@1360: 
fp@1360:   This program is distributed in the hope it will be useful, but WITHOUT
fp@1360:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fp@1360:   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
fp@1360:   more details.
fp@1360: 
fp@1360:   You should have received a copy of the GNU General Public License along with
fp@1360:   this program; if not, write to the Free Software Foundation, Inc.,
fp@1360:   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
fp@1360: 
fp@1360:   The full GNU General Public License is included in this distribution in
fp@1360:   the file called "COPYING".
fp@1360: 
fp@1360:   Contact Information:
fp@1360:   Linux NICS <linux.nics@intel.com>
fp@1360:   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
fp@1360:   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
fp@1360: 
fp@1360: *******************************************************************************/
fp@1360: 
fp@1360: 
fp@1360: /* Linux PRO/1000 Ethernet Driver main header file */
fp@1360: 
fp@1360: #ifndef _E1000_H_
fp@1360: #define _E1000_H_
fp@1360: 
fp@1360: #include <linux/stddef.h>
fp@1360: #include <linux/module.h>
fp@1360: #include <linux/types.h>
fp@1360: #include <asm/byteorder.h>
fp@1360: #include <linux/init.h>
fp@1360: #include <linux/mm.h>
fp@1360: #include <linux/errno.h>
fp@1360: #include <linux/ioport.h>
fp@1360: #include <linux/pci.h>
fp@1360: #include <linux/kernel.h>
fp@1360: #include <linux/netdevice.h>
fp@1360: #include <linux/etherdevice.h>
fp@1360: #include <linux/skbuff.h>
fp@1360: #include <linux/delay.h>
fp@1360: #include <linux/timer.h>
fp@1360: #include <linux/slab.h>
fp@1360: #include <linux/vmalloc.h>
fp@1360: #include <linux/interrupt.h>
fp@1360: #include <linux/string.h>
fp@1360: #include <linux/pagemap.h>
fp@1360: #include <linux/dma-mapping.h>
fp@1360: #include <linux/bitops.h>
fp@1360: #include <asm/io.h>
fp@1360: #include <asm/irq.h>
fp@1360: #include <linux/capability.h>
fp@1360: #include <linux/in.h>
fp@1360: #include <linux/ip.h>
fp@1360: #include <linux/ipv6.h>
fp@1360: #include <linux/tcp.h>
fp@1360: #include <linux/udp.h>
fp@1360: #include <net/pkt_sched.h>
fp@1360: #include <linux/list.h>
fp@1360: #include <linux/reboot.h>
fp@1360: #include <net/checksum.h>
fp@1360: #include <linux/mii.h>
fp@1360: #include <linux/ethtool.h>
fp@1360: #include <linux/if_vlan.h>
fp@1360: 
fp@1360: #define BAR_0		0
fp@1360: #define BAR_1		1
fp@1360: #define BAR_5		5
fp@1360: 
fp@1360: #define INTEL_E1000_ETHERNET_DEVICE(device_id) {\
fp@1360: 	PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
fp@1360: 
fp@1360: struct e1000_adapter;
fp@1360: 
fp@1360: #include "e1000_hw.h"
fp@1360: 
fp@1360: #ifdef DBG
fp@1360: #define E1000_DBG(args...) printk(KERN_DEBUG "e1000: " args)
fp@1360: #else
fp@1360: #define E1000_DBG(args...)
fp@1360: #endif
fp@1360: 
fp@1360: #define E1000_ERR(args...) printk(KERN_ERR "e1000: " args)
fp@1360: 
fp@1360: #define PFX "e1000: "
fp@1360: #define DPRINTK(nlevel, klevel, fmt, args...) \
fp@1360: 	(void)((NETIF_MSG_##nlevel & adapter->msg_enable) && \
fp@1360: 	printk(KERN_##klevel PFX "%s: %s: " fmt, adapter->netdev->name, \
fp@1360: 		__FUNCTION__ , ## args))
fp@1360: 
fp@1360: #define E1000_MAX_INTR 10
fp@1360: 
fp@1360: /* TX/RX descriptor defines */
fp@1360: #define E1000_DEFAULT_TXD                  256
fp@1360: #define E1000_MAX_TXD                      256
fp@1360: #define E1000_MIN_TXD                       80
fp@1360: #define E1000_MAX_82544_TXD               4096
fp@1360: 
fp@1360: #define E1000_DEFAULT_RXD                  256
fp@1360: #define E1000_MAX_RXD                      256
fp@1360: #define E1000_MIN_RXD                       80
fp@1360: #define E1000_MAX_82544_RXD               4096
fp@1360: 
fp@1360: /* this is the size past which hardware will drop packets when setting LPE=0 */
fp@1360: #define MAXIMUM_ETHERNET_VLAN_SIZE 1522
fp@1360: 
fp@1360: /* Supported Rx Buffer Sizes */
fp@1360: #define E1000_RXBUFFER_128   128    /* Used for packet split */
fp@1360: #define E1000_RXBUFFER_256   256    /* Used for packet split */
fp@1360: #define E1000_RXBUFFER_512   512
fp@1360: #define E1000_RXBUFFER_1024  1024
fp@1360: #define E1000_RXBUFFER_2048  2048
fp@1360: #define E1000_RXBUFFER_4096  4096
fp@1360: #define E1000_RXBUFFER_8192  8192
fp@1360: #define E1000_RXBUFFER_16384 16384
fp@1360: 
fp@1360: /* SmartSpeed delimiters */
fp@1360: #define E1000_SMARTSPEED_DOWNSHIFT 3
fp@1360: #define E1000_SMARTSPEED_MAX       15
fp@1360: 
fp@1360: /* Packet Buffer allocations */
fp@1360: #define E1000_PBA_BYTES_SHIFT 0xA
fp@1360: #define E1000_TX_HEAD_ADDR_SHIFT 7
fp@1360: #define E1000_PBA_TX_MASK 0xFFFF0000
fp@1360: 
fp@1360: /* Flow Control Watermarks */
fp@1360: #define E1000_FC_HIGH_DIFF 0x1638  /* High: 5688 bytes below Rx FIFO size */
fp@1360: #define E1000_FC_LOW_DIFF 0x1640   /* Low:  5696 bytes below Rx FIFO size */
fp@1360: 
fp@1360: #define E1000_FC_PAUSE_TIME 0x0680 /* 858 usec */
fp@1360: 
fp@1360: /* How many Tx Descriptors do we need to call netif_wake_queue ? */
fp@1360: #define E1000_TX_QUEUE_WAKE	16
fp@1360: /* How many Rx Buffers do we bundle into one write to the hardware ? */
fp@1360: #define E1000_RX_BUFFER_WRITE	16	/* Must be power of 2 */
fp@1360: 
fp@1360: #define AUTO_ALL_MODES            0
fp@1360: #define E1000_EEPROM_82544_APM    0x0004
fp@1360: #define E1000_EEPROM_ICH8_APME    0x0004
fp@1360: #define E1000_EEPROM_APME         0x0400
fp@1360: 
fp@1360: #ifndef E1000_MASTER_SLAVE
fp@1360: /* Switch to override PHY master/slave setting */
fp@1360: #define E1000_MASTER_SLAVE	e1000_ms_hw_default
fp@1360: #endif
fp@1360: 
fp@1360: #define E1000_MNG_VLAN_NONE -1
fp@1360: /* Number of packet split data buffers (not including the header buffer) */
fp@1360: #define PS_PAGE_BUFFERS MAX_PS_BUFFERS-1
fp@1360: 
fp@1360: /* wrapper around a pointer to a socket buffer,
fp@1360:  * so a DMA handle can be stored along with the buffer */
fp@1360: struct e1000_buffer {
fp@1360: 	struct sk_buff *skb;
fp@1360: 	dma_addr_t dma;
fp@1360: 	unsigned long time_stamp;
fp@1360: 	u16 length;
fp@1360: 	u16 next_to_watch;
fp@1360: };
fp@1360: 
fp@1360: 
fp@1360: struct e1000_ps_page { struct page *ps_page[PS_PAGE_BUFFERS]; };
fp@1360: struct e1000_ps_page_dma { u64 ps_page_dma[PS_PAGE_BUFFERS]; };
fp@1360: 
fp@1360: struct e1000_tx_ring {
fp@1360: 	/* pointer to the descriptor ring memory */
fp@1360: 	void *desc;
fp@1360: 	/* physical address of the descriptor ring */
fp@1360: 	dma_addr_t dma;
fp@1360: 	/* length of descriptor ring in bytes */
fp@1360: 	unsigned int size;
fp@1360: 	/* number of descriptors in the ring */
fp@1360: 	unsigned int count;
fp@1360: 	/* next descriptor to associate a buffer with */
fp@1360: 	unsigned int next_to_use;
fp@1360: 	/* next descriptor to check for DD status bit */
fp@1360: 	unsigned int next_to_clean;
fp@1360: 	/* array of buffer information structs */
fp@1360: 	struct e1000_buffer *buffer_info;
fp@1360: 
fp@1360: 	spinlock_t tx_lock;
fp@1360: 	u16 tdh;
fp@1360: 	u16 tdt;
fp@1360: 	bool last_tx_tso;
fp@1360: };
fp@1360: 
fp@1360: struct e1000_rx_ring {
fp@1360: 	/* pointer to the descriptor ring memory */
fp@1360: 	void *desc;
fp@1360: 	/* physical address of the descriptor ring */
fp@1360: 	dma_addr_t dma;
fp@1360: 	/* length of descriptor ring in bytes */
fp@1360: 	unsigned int size;
fp@1360: 	/* number of descriptors in the ring */
fp@1360: 	unsigned int count;
fp@1360: 	/* next descriptor to associate a buffer with */
fp@1360: 	unsigned int next_to_use;
fp@1360: 	/* next descriptor to check for DD status bit */
fp@1360: 	unsigned int next_to_clean;
fp@1360: 	/* array of buffer information structs */
fp@1360: 	struct e1000_buffer *buffer_info;
fp@1360: 	/* arrays of page information for packet split */
fp@1360: 	struct e1000_ps_page *ps_page;
fp@1360: 	struct e1000_ps_page_dma *ps_page_dma;
fp@1360: 
fp@1360: 	/* cpu for rx queue */
fp@1360: 	int cpu;
fp@1360: 
fp@1360: 	u16 rdh;
fp@1360: 	u16 rdt;
fp@1360: };
fp@1360: 
fp@1360: #define E1000_DESC_UNUSED(R) \
fp@1360: 	((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
fp@1360: 	(R)->next_to_clean - (R)->next_to_use - 1)
fp@1360: 
fp@1360: #define E1000_RX_DESC_PS(R, i)	    \
fp@1360: 	(&(((union e1000_rx_desc_packet_split *)((R).desc))[i]))
fp@1360: #define E1000_RX_DESC_EXT(R, i)	    \
fp@1360: 	(&(((union e1000_rx_desc_extended *)((R).desc))[i]))
fp@1360: #define E1000_GET_DESC(R, i, type)	(&(((struct type *)((R).desc))[i]))
fp@1360: #define E1000_RX_DESC(R, i)		E1000_GET_DESC(R, i, e1000_rx_desc)
fp@1360: #define E1000_TX_DESC(R, i)		E1000_GET_DESC(R, i, e1000_tx_desc)
fp@1360: #define E1000_CONTEXT_DESC(R, i)	E1000_GET_DESC(R, i, e1000_context_desc)
fp@1360: 
fp@1360: /* board specific private data structure */
fp@1360: 
fp@1360: struct e1000_adapter {
fp@1360: 	struct timer_list tx_fifo_stall_timer;
fp@1360: 	struct timer_list watchdog_timer;
fp@1360: 	struct timer_list phy_info_timer;
fp@1360: 	struct vlan_group *vlgrp;
fp@1360: 	u16 mng_vlan_id;
fp@1360: 	u32 bd_number;
fp@1360: 	u32 rx_buffer_len;
fp@1360: 	u32 wol;
fp@1360: 	u32 smartspeed;
fp@1360: 	u32 en_mng_pt;
fp@1360: 	u16 link_speed;
fp@1360: 	u16 link_duplex;
fp@1360: 	spinlock_t stats_lock;
fp@1360: #ifdef CONFIG_E1000_NAPI
fp@1360: 	spinlock_t tx_queue_lock;
fp@1360: #endif
fp@1360: 	unsigned int total_tx_bytes;
fp@1360: 	unsigned int total_tx_packets;
fp@1360: 	unsigned int total_rx_bytes;
fp@1360: 	unsigned int total_rx_packets;
fp@1360: 	/* Interrupt Throttle Rate */
fp@1360: 	u32 itr;
fp@1360: 	u32 itr_setting;
fp@1360: 	u16 tx_itr;
fp@1360: 	u16 rx_itr;
fp@1360: 
fp@1360: 	struct work_struct reset_task;
fp@1360: 	u8 fc_autoneg;
fp@1360: 
fp@1360: 	struct timer_list blink_timer;
fp@1360: 	unsigned long led_status;
fp@1360: 
fp@1360: 	/* TX */
fp@1360: 	struct e1000_tx_ring *tx_ring;      /* One per active queue */
fp@1360: 	unsigned int restart_queue;
fp@1360: 	unsigned long tx_queue_len;
fp@1360: 	u32 txd_cmd;
fp@1360: 	u32 tx_int_delay;
fp@1360: 	u32 tx_abs_int_delay;
fp@1360: 	u32 gotcl;
fp@1360: 	u64 gotcl_old;
fp@1360: 	u64 tpt_old;
fp@1360: 	u64 colc_old;
fp@1360: 	u32 tx_timeout_count;
fp@1360: 	u32 tx_fifo_head;
fp@1360: 	u32 tx_head_addr;
fp@1360: 	u32 tx_fifo_size;
fp@1360: 	u8  tx_timeout_factor;
fp@1360: 	atomic_t tx_fifo_stall;
fp@1360: 	bool pcix_82544;
fp@1360: 	bool detect_tx_hung;
fp@1360: 
fp@1360: 	/* RX */
fp@1360: #ifdef CONFIG_E1000_NAPI
fp@1360: 	bool (*clean_rx) (struct e1000_adapter *adapter,
fp@1360: 			  struct e1000_rx_ring *rx_ring,
fp@1360: 			  int *work_done, int work_to_do);
fp@1360: #else
fp@1360: 	bool (*clean_rx) (struct e1000_adapter *adapter,
fp@1360: 			  struct e1000_rx_ring *rx_ring);
fp@1360: #endif
fp@1360: 	void (*alloc_rx_buf) (struct e1000_adapter *adapter,
fp@1360: 			      struct e1000_rx_ring *rx_ring,
fp@1360: 				int cleaned_count);
fp@1360: 	struct e1000_rx_ring *rx_ring;      /* One per active queue */
fp@1360: #ifdef CONFIG_E1000_NAPI
fp@1360: 	struct napi_struct napi;
fp@1360: 	struct net_device *polling_netdev;  /* One per active queue */
fp@1360: #endif
fp@1360: 	int num_tx_queues;
fp@1360: 	int num_rx_queues;
fp@1360: 
fp@1360: 	u64 hw_csum_err;
fp@1360: 	u64 hw_csum_good;
fp@1360: 	u64 rx_hdr_split;
fp@1360: 	u32 alloc_rx_buff_failed;
fp@1360: 	u32 rx_int_delay;
fp@1360: 	u32 rx_abs_int_delay;
fp@1360: 	bool rx_csum;
fp@1360: 	unsigned int rx_ps_pages;
fp@1360: 	u32 gorcl;
fp@1360: 	u64 gorcl_old;
fp@1360: 	u16 rx_ps_bsize0;
fp@1360: 
fp@1360: 
fp@1360: 	/* OS defined structs */
fp@1360: 	struct net_device *netdev;
fp@1360: 	struct pci_dev *pdev;
fp@1360: 	struct net_device_stats net_stats;
fp@1360: 
fp@1360: 	/* structs defined in e1000_hw.h */
fp@1360: 	struct e1000_hw hw;
fp@1360: 	struct e1000_hw_stats stats;
fp@1360: 	struct e1000_phy_info phy_info;
fp@1360: 	struct e1000_phy_stats phy_stats;
fp@1360: 
fp@1360: 	u32 test_icr;
fp@1360: 	struct e1000_tx_ring test_tx_ring;
fp@1360: 	struct e1000_rx_ring test_rx_ring;
fp@1360: 
fp@1360: 	int msg_enable;
fp@1360: 	bool have_msi;
fp@1360: 
fp@1360: 	/* to not mess up cache alignment, always add to the bottom */
fp@1360: 	bool tso_force;
fp@1360: 	bool smart_power_down;	/* phy smart power down */
fp@1360: 	bool quad_port_a;
fp@1360: 	unsigned long flags;
fp@1360: 	u32 eeprom_wol;
fp@1360: };
fp@1360: 
fp@1360: enum e1000_state_t {
fp@1360: 	__E1000_TESTING,
fp@1360: 	__E1000_RESETTING,
fp@1360: 	__E1000_DOWN
fp@1360: };
fp@1360: 
fp@1360: extern char e1000_driver_name[];
fp@1360: extern const char e1000_driver_version[];
fp@1360: 
fp@1360: extern void e1000_power_up_phy(struct e1000_adapter *);
fp@1360: extern void e1000_set_ethtool_ops(struct net_device *netdev);
fp@1360: extern void e1000_check_options(struct e1000_adapter *adapter);
fp@1360: 
fp@1360: 
fp@1360: #endif /* _E1000_H_ */