/****************************************************************************/
/* Copyright 2010, © Bendor Research Pty. Ltd. All rights reserved.			*/
/* Permission is granted to use this software for any purpose whatsoever	*/
/* as long as this copyright notice is preserved. The code is provided		*/
/* "as is", with no explicit, implicit or implied warranty or guarantee		*/
/* of any kind and Bendor Research Pty. Ltd. can not be held liable for		*/
/* any loss or damages arising out of the use of this software.				*/
/****************************************************************************/
/*																			*/
/*	Definitions for the Media Independent Interface (IEEE 802.3)			*/
/*	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~			*/
/*																			*/
/*	2006 Mar	ZK		Original											*/
/*																			*/
/****************************************************************************/

#ifndef _MII_H
#define _MII_H

/*
*	Registers
*/

#define	MII_CTRL		0		// Basic control register
#define	MII_STAT		1		// Basic status register
#define	MII_PHY_IDH		2		// PHY identifier most significat word
#define	MII_PHY_IDL		3		// PHY identifier least significant word
#define	MII_AN_ADV		4		// Auto-negotiation advertisement
#define	MII_AN_LPA		5		// Auto-neg. link parner ability
#define	MII_AN_EXP		6		// Auto-neg. expansion
#define	MII_AN_NPT		7		// Auto-neg. next page transmit
#define	MII_AN_LPR		8		// Auto-neg. link partner received next page
#define	MII_MS_CTRL		9		// Master-slave control (1000BASE-T)
#define	MII_MS_STAT		10		// Master-slave status (1000BASE-T)
#define	MII_PSE_CTRL	11		// PSE control
#define	MII_PSE_STAT	12		// PSE control
#define	MII_MMD_CTRL	13		// MMD access control
#define	MII_MMD_ADDR	14		// MMD access address data register
#define	MII_EXT_STAT	15		// Extended status

/*
*	Control register bit definitions
*/

#define	MII_CTRL_RESET		0x8000	// PHY reset
#define	MII_CTRL_LOOPBACK	0x4000	// Loopback mode
#define	MII_CTRL_SPEED_MSK	0x2040	// Speed selection mask
#define	MII_CTRL_SPEED_10	0x0000	// Speed is 10Mb/s
#define	MII_CTRL_SPEED_100	0x2000	// Speed is 100Mb/s
#define	MII_CTRL_SPEED_1000	0x0040	// Speed is 1GB/s
#define	MII_CTRL_AUTO_ENA	0x1000	// Auto negotiation enable
#define	MII_CTRL_POWERDOWN	0x0800	// Power down the interface
#define	MII_CTRL_ISOLATE	0x0400	// Isolate the interface
#define	MII_CTRL_AUTO_RES	0x0200	// Restart auto negotiation
#define	MII_CTRL_HALFDUPLEX	0x0100	// Half duplex mode (if 1, duplex if 0)
#define	MII_CTRL_COLL_TEST	0x0080	// Enable collision test
#define	MII_CTRL_UNIDIR		0x0020	// Enable unidirection mode

/*
*	Status register bit definitions
*/

#define	MII_STAT_100T4		0x8000	// PHY can perform 100BASE-T4
#define	MII_STAT_100X_FULL	0x4000	// PHY can perform 100BASE-X full duplex
#define	MII_STAT_100X_HALF	0x2000	// PHY can perform 100BASE-X half duplex
#define	MII_STAT_10_FULL	0x1000	// PHY can perform 100BASE-T4
#define	MII_STAT_10_HALF	0x0800	// PHY can perform 100BASE-T4
#define	MII_STAT_100T2_FULL	0x0400	// PHY can perform 100BASE-T4
#define	MII_STAT_100T2_HALF	0x0200	// PHY can perform 100BASE-T4
#define	MII_STAT_EXT_STAT	0x0100	// Extended status reg exists
#define	MII_STAT_UNIDIR		0x0080	// PHY is able to transmit unidirectionally
#define	MII_STAT_PRESUPP	0x0040	// Management with suppressed preamble is OK
#define	MII_STAT_AUTO_DONE	0x0020	// Auto negotiation is complete
#define	MII_STAT_RMT_FAULT	0x0010	// Remote fault
#define	MII_STAT_AUTO_ABLE	0x0008	// PHY can do auto negotiation
#define	MII_STAT_LINK_UP	0x0004	// Link is up
#define	MII_STAT_JABBER		0x0002	// Jabber detected
#define	MII_STAT_EXTEND		0x0001	// Extended register capabilities

/*
*	Auto-negotiation capability registers
*/

#define	MII_AN_NEXTPAGE		0x8000	// Next page capable
#define	MII_AN_REMOTEFAULT	0x2000	// Remote fault supported
#define	MII_AN_EXTNEXTPAGE	0x1000	// Extended next page
#define	MII_AN_ABILITY_MSK	0x0fe0	// Technology ability field mask

/*
*	Selector values
*/

#define	MII_AN_SELECT_MSK	0x001f	// Selector field mask
#define	MII_AN_SELECT_802_3	0x0001	// Selector field value for IEEE-802.3
#define	MII_AN_SELECT_802_9	0x0002	// Selector field value for IEEE-802.9
#define	MII_AN_SELECT_802_5	0x0003	// Selector field value for IEEE-802.5
#define	MII_AN_SELECT_1394	0x0004	// Selector field value for IEEE-1394

/*
*	Ability values for 802.3 selector value
*/

#define	MII_AN_802_3_ABILITY_10B_T		0x0020	// 10BASE-T
#define	MII_AN_802_3_ABILITY_10B_TD		0x0040	// 10BASE-T full duplex
#define	MII_AN_802_3_ABILITY_100B_TX	0x0080	// 100BASE-TX
#define	MII_AN_802_3_ABILITY_100B_TXD	0x0100	// 100BASE-TX full duplex
#define	MII_AN_802_3_ABILITY_100B_T4	0x0200	// 100BASE-T4
#define	MII_AN_802_3_ABILITY_PAUSE		0x0400	// Pause
#define	MII_AN_802_3_ABILITY_ASYM		0x0800	// Asymetric pause

/*
*	Master-slave control register bit definitions
*/

#define	MII_MS_CTRL_TXTEST_MSK	0xc000	// PHY transmitter test mode mask
#define	MII_MS_CTRL_TXTEST_M1	0x4000	// PHY transmitter test mode 1
#define	MII_MS_CTRL_TXTEST_M2	0x8000	// PHY transmitter test mode 2
#define	MII_MS_CTRL_TXTEST_M3	0xc000	// PHY transmitter test mode 3
#define	MII_MS_CTRL_TXTEST_OFF	0x0000	// PHY transmitter is not in test mode
#define	MII_MS_CTRL_RXTEST		0x2000	// PHY receiver in test mode
#define	MII_MS_CTRL_MANUAL_ENA	0x1000	// Manual configuration enable
#define	MII_MS_CTRL_MANUAL_VAL	0x0800	// Manual configuration value
#define	MII_MS_CTRL_REPEATER	0x0400	// T2 repeater mode(1) of DTE(0)

/*
*	Master-slave status register bit definitions
*/

#define	MII_MS_STAT_CFG_FAULT	0x8000	// Manual configuration fault
#define	MII_MS_STAT_CFG_DONE	0x4000	// Manual configuration complete
#define	MII_MS_STAT_LOCALRXOK	0x2000	// Local receiver is OK
#define	MII_MS_STAT_REMOTERXOK	0x1000	// Remote receiver is OK
#define	MII_MS_STAT_IDLEERR_MSK	0x00ff	// Idle error count mask


#endif

