/**********************************************************************
**                                                                   **
**                I N T E L   P R O P R I E T A R Y                  **
**                                                                   **
**   COPYRIGHT (c)  1998 - 2003       BY  INTEL  CORPORATION.  ALL   **
**   RIGHTS RESERVED.   NO PART OF THIS PROGRAM OR PUBLICATION MAY   **
**   BE  REPRODUCED,   TRANSMITTED,   TRANSCRIBED,   STORED  IN  A   **
**   RETRIEVAL SYSTEM, OR TRANSLATED INTO ANY LANGUAGE OR COMPUTER   **
**   LANGUAGE IN ANY FORM OR BY ANY MEANS, ELECTRONIC, MECHANICAL,   **
**   MAGNETIC,  OPTICAL,  CHEMICAL, MANUAL, OR OTHERWISE,  WITHOUT   **
**   THE PRIOR WRITTEN PERMISSION OF :                               **
**                                                                   **
**                      INTEL  CORPORATION                           **
**                                                                   **
**                2200 MISSION COLLEGE BOULEVARD                     **
**                                                                   **
**             SANTA  CLARA,  CALIFORNIA  95052-8119                 **
**                                                                   **
**********************************************************************/

/*************************************************************************
*                                                                        *
* INTEL CORPORATION PROPRIETARY INFORMATION                              *
* This software is supplied under the terms of a license agreement       *
* with Intel Corporation and may not be copied nor disclosed             *
* except in accordance with the terms of that agreement.                 *
*                                                                        *
* Module Name:                                                           *
*   e1000.h                                                              *
*                                                                        *
* Abstract:                                                              *
*   This header file contains some high level software constants, macros *
*   and structures that are used by the driver.                          *
*                                                                        *
**************************************************************************/

#ifndef _E1000_H_
#define _E1000_H_

#define EIO				5
#define ENOMEM				12
#define EBUSY				16
#define PCI_VENDOR_ID_INTEL		0x8086

struct e1000_adapter;

#include "e1000_hw.h"

#if DBG
    #define E1000_DBG			EdbgOutputDebugString
#else
    extern void e1000_dummy_print (const char *,  ...);
    #define E1000_DBG			e1000_dummy_print
#endif

#define E1000_ERR			EdbgOutputDebugString

#define E1000_DEFAULT_TXD		16
#define E1000_DEFAULT_RXD		8

#define MAXIMUM_ETHERNET_VLAN_SIZE	1522

#define E1000_RXBUFFER_128		128
#define E1000_RXBUFFER_256		256
#define E1000_RXBUFFER_512		512
#define E1000_RXBUFFER_1024		1024
#define E1000_RXBUFFER_2048		2048
#define E1000_RXBUFFER_4096		4096
#define E1000_RXBUFFER_8192		8192
#define E1000_RXBUFFER_16384		16384

/* SmartSpeed delimiters */
#define E1000_SMARTSPEED_DOWNSHIFT	3
#define E1000_SMARTSPEED_MAX		15

/* Packet Buffer allocations */
#define E1000_PBA_BYTES_SHIFT		0xA
#define E1000_TX_HEAD_ADDR_SHIFT	7
#define E1000_PBA_TX_MASK		0xFFFF0000

/* Flow Control Watermarks */
#define E1000_FC_HIGH_DIFF		0x1638
#define E1000_FC_LOW_DIFF		0x1640
#define E1000_FC_PAUSE_TIME		0x0680

#define AUTO_ALL_MODES			0
#define E1000_EEPROM_82544_APM		0x0004
#define E1000_EEPROM_ICH8_APME		0x0004
#define E1000_EEPROM_APME		0x0400

#ifndef E1000_MASTER_SLAVE
#define E1000_MASTER_SLAVE		e1000_ms_hw_default
#endif

#define E1000_MNG_VLAN_NONE		-1

struct e1000_buffer {
	uint32_t buffer;
	uint16_t next_to_watch;
};

struct e1000_tx_ring {
	uint16_t tdh;
	uint16_t tdt;
	void *desc;
	unsigned int size;
	unsigned int count;
	unsigned int next_to_use;
	unsigned int next_to_clean;
	struct e1000_buffer *buffer_info;
};

struct e1000_rx_ring {
	uint16_t rdh;
	uint16_t rdt;
	void *desc;
	unsigned int size;
	unsigned int count;
	unsigned int next_to_use;
	unsigned int next_to_clean;
	struct e1000_buffer *buffer_info;
};

#define E1000_DESC_UNUSED(R) \
	((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
	(R)->next_to_clean - (R)->next_to_use - 1)

#define E1000_GET_DESC(R, i, type)	(&(((struct type *)((R).desc))[i]))
#define E1000_RX_DESC(R, i)		E1000_GET_DESC(R, i, e1000_rx_desc)
#define E1000_TX_DESC(R, i)		E1000_GET_DESC(R, i, e1000_tx_desc)
#define E1000_CONTEXT_DESC(R, i)	E1000_GET_DESC(R, i, e1000_context_desc)

struct e1000_adapter {
    	uint16_t mng_vlan_id;
	uint32_t rx_buffer_len;
	uint32_t part_num;
	uint32_t wol;
	uint32_t ksp3_port_a;
	uint32_t smartspeed;
	uint32_t en_mng_pt;
	uint16_t link_speed;
	uint16_t link_duplex;
	uint8_t fc_autoneg;

	/* TX */
	struct e1000_tx_ring *tx_ring;      /* One per active queue */
	unsigned long tx_queue_len;
	uint32_t txd_cmd;
	uint32_t gotcl;
	uint64_t gotcl_old;
	uint64_t tpt_old;
	uint64_t colc_old;
	uint32_t tx_timeout_count;
	uint32_t tx_fifo_head;
	uint32_t tx_head_addr;
	uint32_t tx_fifo_size;
	uint8_t  tx_timeout_factor;
	boolean_t pcix_82544;
	boolean_t detect_tx_hung;

	/* RX */
	struct e1000_rx_ring *rx_ring;      /* One per active queue */

	uint64_t hw_csum_err;
	uint64_t hw_csum_good;
	uint64_t rx_hdr_split;
	uint32_t alloc_rx_buff_failed;
	boolean_t rx_csum;
	uint32_t gorcl;
	uint64_t gorcl_old;

	/* Interrupt Throttle Rate */
	uint32_t itr;

	/* OS defined structs */
	uint32_t dwMemOffset;

	/* structs defined in e1000_hw.h */
	struct e1000_hw hw;
	struct e1000_hw_stats stats;
	struct e1000_phy_info phy_info;
	struct e1000_phy_stats phy_stats;

	boolean_t smart_power_down;	/* phy smart power down */
	unsigned long flags;
};

#endif /* _E1000_H_ */
