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