/*****************************************************************************
* Copyright (c) 2005 Digi International Inc., All Rights Reserved
* 
* This software contains proprietary and confidential information of Digi
* International Inc.  By accepting transfer of this copy, Recipient agrees
* to retain this software in confidence, to prevent disclosure to others,
* and to make no use of this software other than that for which it was
* delivered.  This is an unpublished copyrighted work of Digi International
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
* prohibited.
* 
* Restricted Rights Legend
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7031 or
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -
* Restricted Rights at 48 CFR 52.227-19, as applicable.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
*
*****************************************************************************/

#ifndef mii_h

#define mii_h
#include "Npttypes.h"


#ifndef ENABLE_RMII_TEST_CODE
#define ETH_ENABLE_LINK_MONITOR
#endif

/*ad*
 * The MII driver API provides functions to control an external Ethernet 10/100 PHY device. 
 * The MII.c module will need to be changed to add a PHY device of a new type.
 *
 * MII API functions include:
 * <list type="unordered">
 *  <item> @link customizeMiiIdentifyPhy </item>
 *  <item> @link customizeGetPhyStatus </item>
 *  <item> @link customizeMiiConfigure </item>
 *  <item> @link customizeMiiReset </item>
 *  <item> @link customizeMiiAutonegotiate </item>
 *  <item> @link customizeMiiRestartAutoneg </item>
 *  <item> @link customizeMiiAutonegotiationComplete </item>
 *  <item> @link customizeMiiCheckLink </item>
 *  <item> @link customizeMiiCheckSpeed </item>
 *  <item> @link customizeMiiCheckDuplex </item>
 *  <item> @link customizeMiiSetLoopback </item>
 *  <item> @link customizeMiiForceSpeedDuplex </item>
 * </list>
 *
 * If Link Monitor is running (default) the API following functions 
 * should be used instead:
 * <list type="unordered">
 *  <item> @link naEthGetPhyStatus </item>
 *  <item> @link naEthConfigureMii </item>
 *  <item> @link naEthAutonegotiate </item>
 *  <item> @link naEthForceMiiSpeedDuplex </item>
 * </list>
 *
 * The link change callback can be registered by calling naEthRegisterLinkStatusCallback
 * to let the application know, when Ethernet link goes up or down. 
 *
 *
 * @external
 * @category BSP:Device_Drivers:MII
 * @include "MII.h"
 * @library bsp
 * @platform connectem,connectme,connectsp,net50_d,net50bga_a,ns7520_a,ns9360_a,ns9750_a,connectcore9c_a,connectcorewi9c_a
 * @since 6.0
 * @see @link BSP:Device_Drivers:EthernetDriver:naEthRegisterLinkStatusCallback
 * @overview MII Driver
*ad*/

/*
 * Define MII_PHY (0) if you are using ENDEC PHY 
 */
#define MII_PHY (1)				/* Use MII            */ 

/*ad*
 * These types are the supported PHY types.
 *
 * @external
 * @category BSP:Device_Drivers:MII
 * @since 6.0
 * @name phy_types "PHY Types"
 *
 * @param ENABLE_PHY  1 
 * @param INTEL_PHY   3
 * @param ICS_PHY     6
 * @param TDK_PHY     7
 *
*ad*/

#define     ENABLE_PHY  1
#define     INTEL_PHY   3
#define     ICS_PHY     6
#define     TDK_PHY     7

/* Unsupported PHY types */
#define     LEVEL1_PHY  2
#define     AMD_PHY     4
#define     ALTIMA_PHY  5
#define     MICREL_PHY  8

/*ad*
 * This value indicates a PHY address or PHY identifier error.
 *
 * @external
 * @category BSP:Device_Drivers:MII
 * @since 6.0
 *
*ad*/
#define     PHY_ERROR   0xffff

/*ad*
 * These types are the supported configuration values for speed and duplex.
 * 
 * These values are used by customizeMiiConfigure and customizeMiiForceSpeedDuplex. 
 * MII_CONFIG_AUTO allpies for both speed and duplex.
 *
 * @external
 * @category BSP:Device_Drivers:MII
 * @since 7.0
 * @name phy_config "Speed and Duplex Configuration Values"
 *
 * @param MII_CONFIG_10    0    
 * @param MII_CONFIG_100   1
 * @param MII_CONFIG_HD    0
 * @param MII_CONFIG_FD    1
 * @param MII_CONFIG_AUTO  2
 *
*ad*/
#define MII_CONFIG_10               0
#define MII_CONFIG_100              1
#define MII_CONFIG_HD               0
#define MII_CONFIG_FD               1
#define MII_CONFIG_AUTO             2

#define MII_MAX_SPEED_SETTINGS      3
#define MII_MAX_DUPLEX_SETTINGS     3

#define MII_DEFAULT_SPEED           MII_CONFIG_AUTO   

/*ad*
 * These types are the supported status masks for a return value of  
 * customizeGetPhyStatus.
 *
 * @external
 * @category BSP:Device_Drivers:MII
 * @since 7.0
 * @name phy_status "PHY Status Masks"
 *
 * @param MII_PHY_STATUS_LINK                 0x00010000
 * @param MII_PHY_STATUS_AUTONEG              0x00020000
 * @param MII_PHY_STATUS_AUTONEG_COMPLETE     0x00040000 
 * @param MII_PHY_STATUS_AUTONEG_ABLE         0x00080000 
 * @param MII_PHY_STATUS_10                   0x00100000
 * @param MII_PHY_STATUS_100                  0x00200000
 * @param MII_PHY_STATUS_HD                   0x00400000 
 * @param MII_PHY_STATUS_FD                   0x00800000 
 * @param MII_PHY_STATUS_FORCED               0x01000000 
 * @param MII_PHY_STATUS_LOOPBACK             0x02000000
 * @param MII_PHY_STATUS_ERROR                0x80000000
 *
*ad*/
#define MII_PHY_STATUS_LINK                 0x00010000
#define MII_PHY_STATUS_AUTONEG              0x00020000
#define MII_PHY_STATUS_AUTONEG_COMPLETE     0x00040000   
#define MII_PHY_STATUS_AUTONEG_ABLE         0x00080000   
#define MII_PHY_STATUS_10                   0x00100000
#define MII_PHY_STATUS_100                  0x00200000
#define MII_PHY_STATUS_HD                   0x00400000  
#define MII_PHY_STATUS_FD                   0x00800000   
#define MII_PHY_STATUS_FORCED               0x01000000    
#define MII_PHY_STATUS_LOOPBACK             0x02000000
#define MII_PHY_STATUS_ERROR                0x80000000

/*ad*
 * These types are the autonegotiation advertisement masks. 
 * 
 * These values are used by customizeMiiAutonegotiate, customizeMiiRestartAutoneg,
 * and customizeMiiSetAuto. They are also present in the return code of 
 * customizeGetPhyStatus.
 *
 * @external
 * @category BSP:Device_Drivers:MII
 * @since 7.0
 * @name phy_anadvert "Autonegotiation Advertisement Masks"
 *
 * @param MII_AUTONEG_100FD	    0x0100
 * @param MII_AUTONEG_100HD	    0x0080
 * @param MII_AUTONEG_10FD	    0x0040
 * @param MII_AUTONEG_10HD	    0x0020
 * @param MII_AUTONEG_ALL_CAPS  0x01e0
 *
*ad*/
#define	MII_AUTONEG_100FD	    0x0100	/* 100bt full duplex capable */
#define	MII_AUTONEG_100HD	    0x0080	/* 100bt capable */
#define	MII_AUTONEG_10FD	    0x0040	/* 10bt full duplex capable */
#define	MII_AUTONEG_10HD	    0x0020	/* 10bt capable */
#define MII_AUTONEG_ALL_CAPS    0x01e0  /* 100bt_fd + 100bt + 10bt_fd + 10bt */



WORD32  customizeGetPhyStatus(void);
BOOLEAN customizeMiiCheckLink(void);
WORD16  customizeMiiCheckSpeed(void);
WORD16  customizeMiiCheckDuplex(void);
WORD16  customizeMiiIdentifyPhy(WORD16 * addr);
WORD16  customizeMiiReset(void);
WORD16  customizeMiiAutonegotiate(WORD16 autoneg);
WORD16  customizeMiiNegotiate(void);
WORD16  customizeMiiRestartAutoneg(WORD16 autoneg);
BOOLEAN customizeMiiAutonegotiationComplete(void);
WORD16  customizeMiiSetLoopback(BOOLEAN loopback, unsigned speed);
WORD16  customizeMiiSetAuto(WORD16 autoneg);
WORD16  customizeMiiForceSpeedDuplex(unsigned speed, unsigned duplex);
WORD16  customizeMiiConfigure(unsigned speed, unsigned duplex);
void    customizeMiiInit(void);
BOOLEAN customizeMiiNeedReconfigure(unsigned speed, unsigned duplex);
BOOLEAN customizeEnableMiiInterrupt(void);
BOOLEAN customizeDisableMiiInterrupt(void);
BOOLEAN customizeIsMiiInterruptActiveLow(void);
void customizeMiiPhySleep(void);
void customizeMiiPhyWakeup(void);
void    customizeLinkChangeIsr(void);
int     mii_check_negotiable(void);
int     mii_get_LED (WORD16 *value);
int     mii_set_LED (WORD16 id, WORD16 option);

#define customizeMiiSetSpeed    customizeMiiForceSpeedDuplex

#ifdef  ETH_ENABLE_LINK_MONITOR

typedef void (* naEthSetLinkEventFnType) (void);
void customizeMiiSetLinkEventFn(const naEthSetLinkEventFnType linkFn);

WORD32 naEthGetPhyStatus(void);
WORD16 naEthAutonegotiate(WORD16 anadvert);
WORD16 naEthConfigureMii(unsigned speed, unsigned duplex);
WORD16 naEthForceMiiSpeedDuplex(unsigned speed, unsigned duplex);

#endif

#if defined(AUTODOC_ONLY)
/**
 * Has been renamed customizeMiiForceSpeedDuplex.
 *
 * @external
 * @category BSP:Device_Drivers:MII
 * @since 6.0
 * @deprecated  7.0
 *
 * @param speed   1 - 100Mbit,     0 - 10Mbit.
 * @param duplex  1 - full duplex, 0 - half duplex.
 *
 * @return  0           Speed and duplex forced.
 * @return  PHY_ERROR   Error identifying PHY.    
 *
**/
WORD16  customizeMiiSetSpeed(unsigned speed, unsigned duplex);
#endif

#if MII_PHY == FALSE
int customizePhyReset(void);
#endif

#endif


