Home | History | Annotate | Download | only in e1000
      1 /*******************************************************************************
      2 
      3   Intel PRO/1000 Linux driver
      4   Copyright(c) 1999 - 2006 Intel Corporation.
      5 
      6   This program is free software; you can redistribute it and/or modify it
      7   under the terms and conditions of the GNU General Public License,
      8   version 2, as published by the Free Software Foundation.
      9 
     10   This program is distributed in the hope it will be useful, but WITHOUT
     11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     12   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
     13   more details.
     14 
     15   You should have received a copy of the GNU General Public License along with
     16   this program; if not, write to the Free Software Foundation, Inc.,
     17   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
     18 
     19   The full GNU General Public License is included in this distribution in
     20   the file called "COPYING".
     21 
     22   Contact Information:
     23   Linux NICS <linux.nics (at) intel.com>
     24   e1000-devel Mailing List <e1000-devel (at) lists.sourceforge.net>
     25   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
     26 
     27 *******************************************************************************/
     28 
     29 FILE_LICENCE ( GPL2_ONLY );
     30 
     31 /* Linux PRO/1000 Ethernet Driver main header file */
     32 
     33 #ifndef _E1000_H_
     34 #define _E1000_H_
     35 
     36 #include <stdint.h>
     37 #include <stdlib.h>
     38 #include <stdio.h>
     39 #include <string.h>
     40 #include <gpxe/io.h>
     41 #include <errno.h>
     42 #include <byteswap.h>
     43 #include <gpxe/pci.h>
     44 #include <gpxe/malloc.h>
     45 #include <gpxe/if_ether.h>
     46 #include <gpxe/ethernet.h>
     47 #include <gpxe/iobuf.h>
     48 #include <gpxe/netdevice.h>
     49 
     50 #define BAR_0		0
     51 #define BAR_1		1
     52 #define BAR_5		5
     53 
     54 struct e1000_adapter;
     55 
     56 #include "e1000_hw.h"
     57 
     58 /* Supported Rx Buffer Sizes */
     59 #define E1000_RXBUFFER_128   128    /* Used for packet split */
     60 #define E1000_RXBUFFER_256   256    /* Used for packet split */
     61 #define E1000_RXBUFFER_512   512
     62 #define E1000_RXBUFFER_1024  1024
     63 #define E1000_RXBUFFER_2048  2048
     64 #define E1000_RXBUFFER_4096  4096
     65 #define E1000_RXBUFFER_8192  8192
     66 #define E1000_RXBUFFER_16384 16384
     67 
     68 /* SmartSpeed delimiters */
     69 #define E1000_SMARTSPEED_DOWNSHIFT 3
     70 #define E1000_SMARTSPEED_MAX       15
     71 
     72 /* Packet Buffer allocations */
     73 #define E1000_PBA_BYTES_SHIFT 0xA
     74 #define E1000_TX_HEAD_ADDR_SHIFT 7
     75 #define E1000_PBA_TX_MASK 0xFFFF0000
     76 
     77 /* Flow Control Watermarks */
     78 #define E1000_FC_HIGH_DIFF 0x1638  /* High: 5688 bytes below Rx FIFO size */
     79 #define E1000_FC_LOW_DIFF 0x1640   /* Low:  5696 bytes below Rx FIFO size */
     80 
     81 #define E1000_FC_PAUSE_TIME 0x0680 /* 858 usec */
     82 
     83 /* this is the size past which hardware will drop packets when setting LPE=0 */
     84 #define MAXIMUM_ETHERNET_VLAN_SIZE 1522
     85 
     86 /* How many Tx Descriptors do we need to call netif_wake_queue ? */
     87 #define E1000_TX_QUEUE_WAKE	16
     88 /* How many Rx Buffers do we bundle into one write to the hardware ? */
     89 #define E1000_RX_BUFFER_WRITE	16	/* Must be power of 2 */
     90 
     91 #define AUTO_ALL_MODES            0
     92 #define E1000_EEPROM_82544_APM    0x0004
     93 #define E1000_EEPROM_ICH8_APME    0x0004
     94 #define E1000_EEPROM_APME         0x0400
     95 
     96 #ifndef E1000_MASTER_SLAVE
     97 /* Switch to override PHY master/slave setting */
     98 #define E1000_MASTER_SLAVE	e1000_ms_hw_default
     99 #endif
    100 
    101 /* wrapper around a pointer to a socket buffer,
    102  * so a DMA handle can be stored along with the buffer */
    103 struct e1000_buffer {
    104 	struct sk_buff *skb;
    105 	unsigned long time_stamp;
    106 	uint16_t length;
    107 	uint16_t next_to_watch;
    108 };
    109 
    110 struct e1000_tx_ring {
    111 	/* pointer to the descriptor ring memory */
    112 	void *desc;
    113 	/* length of descriptor ring in bytes */
    114 	unsigned int size;
    115 	/* number of descriptors in the ring */
    116 	unsigned int count;
    117 	/* next descriptor to associate a buffer with */
    118 	unsigned int next_to_use;
    119 	/* next descriptor to check for DD status bit */
    120 	unsigned int next_to_clean;
    121 	/* array of buffer information structs */
    122 	struct e1000_buffer *buffer_info;
    123 
    124 	uint16_t tdh;
    125 	uint16_t tdt;
    126 	boolean_t last_tx_tso;
    127 };
    128 
    129 struct e1000_rx_ring {
    130 	/* pointer to the descriptor ring memory */
    131 	void *desc;
    132 	/* length of descriptor ring in bytes */
    133 	unsigned int size;
    134 	/* number of descriptors in the ring */
    135 	unsigned int count;
    136 	/* next descriptor to associate a buffer with */
    137 	unsigned int next_to_use;
    138 	/* next descriptor to check for DD status bit */
    139 	unsigned int next_to_clean;
    140 	/* array of buffer information structs */
    141 	struct e1000_buffer *buffer_info;
    142 	/* arrays of page information for packet split */
    143 	struct e1000_ps_page *ps_page;
    144 	struct e1000_ps_page_dma *ps_page_dma;
    145 
    146 	/* cpu for rx queue */
    147 	int cpu;
    148 
    149 	uint16_t rdh;
    150 	uint16_t rdt;
    151 };
    152 
    153 #define E1000_DESC_UNUSED(R) \
    154 	((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
    155 	(R)->next_to_clean - (R)->next_to_use - 1)
    156 
    157 #define E1000_RX_DESC_PS(R, i)	    \
    158 	(&(((union e1000_rx_desc_packet_split *)((R).desc))[i]))
    159 #define E1000_RX_DESC_EXT(R, i)	    \
    160 	(&(((union e1000_rx_desc_extended *)((R).desc))[i]))
    161 #define E1000_GET_DESC(R, i, type)	(&(((struct type *)((R).desc))[i]))
    162 #define E1000_RX_DESC(R, i)		E1000_GET_DESC(R, i, e1000_rx_desc)
    163 #define E1000_TX_DESC(R, i)		E1000_GET_DESC(R, i, e1000_tx_desc)
    164 #define E1000_CONTEXT_DESC(R, i)	E1000_GET_DESC(R, i, e1000_context_desc)
    165 
    166 /* board specific private data structure */
    167 
    168 struct e1000_adapter {
    169 	struct vlan_group *vlgrp;
    170 	uint16_t mng_vlan_id;
    171 	uint32_t bd_number;
    172 	uint32_t rx_buffer_len;
    173 	uint32_t wol;
    174 	uint32_t smartspeed;
    175 	uint32_t en_mng_pt;
    176 	uint16_t link_speed;
    177 	uint16_t link_duplex;
    178 
    179 	unsigned int total_tx_bytes;
    180 	unsigned int total_tx_packets;
    181 	unsigned int total_rx_bytes;
    182 	unsigned int total_rx_packets;
    183 	/* Interrupt Throttle Rate */
    184 	uint32_t itr;
    185 	uint32_t itr_setting;
    186 	uint16_t tx_itr;
    187 	uint16_t rx_itr;
    188 
    189 	uint8_t fc_autoneg;
    190 
    191 	unsigned long led_status;
    192 
    193 	/* TX */
    194 	struct e1000_tx_ring *tx_ring;      /* One per active queue */
    195 	unsigned int restart_queue;
    196 	unsigned long tx_queue_len;
    197 	uint32_t txd_cmd;
    198 	uint32_t tx_int_delay;
    199 	uint32_t tx_abs_int_delay;
    200 	uint32_t gotcl;
    201 	uint64_t gotcl_old;
    202 	uint64_t tpt_old;
    203 	uint64_t colc_old;
    204 	uint32_t tx_timeout_count;
    205 	uint32_t tx_fifo_head;
    206 	uint32_t tx_head_addr;
    207 	uint32_t tx_fifo_size;
    208 	uint8_t  tx_timeout_factor;
    209 	boolean_t pcix_82544;
    210 	boolean_t detect_tx_hung;
    211 
    212 	/* RX */
    213 	boolean_t (*clean_rx) (struct e1000_adapter *adapter,
    214 			       struct e1000_rx_ring *rx_ring);
    215 	void (*alloc_rx_buf) (struct e1000_adapter *adapter,
    216 			      struct e1000_rx_ring *rx_ring,
    217 				int cleaned_count);
    218 	struct e1000_rx_ring *rx_ring;      /* One per active queue */
    219 	int num_tx_queues;
    220 	int num_rx_queues;
    221 
    222 	uint64_t hw_csum_err;
    223 	uint64_t hw_csum_good;
    224 	uint64_t rx_hdr_split;
    225 	uint32_t alloc_rx_buff_failed;
    226 	uint32_t rx_int_delay;
    227 	uint32_t rx_abs_int_delay;
    228 	boolean_t rx_csum;
    229 	unsigned int rx_ps_pages;
    230 	uint32_t gorcl;
    231 	uint64_t gorcl_old;
    232 	uint16_t rx_ps_bsize0;
    233 
    234 
    235 	/* OS defined structs */
    236 	struct net_device *netdev;
    237 	struct pci_device *pdev;
    238 	struct net_device_stats net_stats;
    239 
    240 	/* structs defined in e1000_hw.h */
    241 	struct e1000_hw hw;
    242 	struct e1000_hw_stats stats;
    243 	struct e1000_phy_info phy_info;
    244 	struct e1000_phy_stats phy_stats;
    245 
    246 	uint32_t test_icr;
    247 	struct e1000_tx_ring test_tx_ring;
    248 	struct e1000_rx_ring test_rx_ring;
    249 
    250 	int msg_enable;
    251 	boolean_t have_msi;
    252 
    253 	/* to not mess up cache alignment, always add to the bottom */
    254 	boolean_t tso_force;
    255 	boolean_t smart_power_down;	/* phy smart power down */
    256 	boolean_t quad_port_a;
    257 	unsigned long flags;
    258 	uint32_t eeprom_wol;
    259 
    260 #define NUM_TX_DESC	8
    261 #define NUM_RX_DESC	8
    262 
    263 	struct io_buffer *tx_iobuf[NUM_TX_DESC];
    264 	struct io_buffer *rx_iobuf[NUM_RX_DESC];
    265 
    266 	struct e1000_tx_desc *tx_base;
    267 	struct e1000_rx_desc *rx_base;
    268 
    269 	uint32_t tx_ring_size;
    270 	uint32_t rx_ring_size;
    271 
    272 	uint32_t tx_head;
    273 	uint32_t tx_tail;
    274 	uint32_t tx_fill_ctr;
    275 
    276 	uint32_t rx_curr;
    277 
    278 	uint32_t ioaddr;
    279 	uint32_t irqno;
    280 
    281 };
    282 
    283 enum e1000_state_t {
    284 	__E1000_TESTING,
    285 	__E1000_RESETTING,
    286 	__E1000_DOWN
    287 };
    288 
    289 #define E1000_MNG2HOST_PORT_623 (1 << 5)
    290 #define E1000_MNG2HOST_PORT_664 (1 << 6)
    291 
    292 #define E1000_ERT_2048 0x100
    293 
    294 #define IORESOURCE_IO		0x00000100
    295 #define IORESOURCE_MEM          0x00000200
    296 #define IORESOURCE_PREFETCH     0x00001000
    297 
    298 #endif /* _E1000_H_ */
    299 
    300 /*
    301  * Local variables:
    302  *  c-basic-offset: 8
    303  *  c-indent-level: 8
    304  *  tab-width: 8
    305  * End:
    306  */
    307