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