mii.h File Reference

#include <gpxe/netdevice.h>

Go to the source code of this file.

Data Structures

struct  mii_if_info

Defines

#define MII_BMCR   0x00
#define MII_BMSR   0x01
#define MII_PHYSID1   0x02
#define MII_PHYSID2   0x03
#define MII_ADVERTISE   0x04
#define MII_LPA   0x05
#define MII_EXPANSION   0x06
#define MII_CTRL1000   0x09
#define MII_STAT1000   0x0a
#define MII_ESTATUS   0x0f
#define MII_DCOUNTER   0x12
#define MII_FCSCOUNTER   0x13
#define MII_NWAYTEST   0x14
#define MII_RERRCOUNTER   0x15
#define MII_SREVISION   0x16
#define MII_RESV1   0x17
#define MII_LBRERROR   0x18
#define MII_PHYADDR   0x19
#define MII_RESV2   0x1a
#define MII_TPISTATUS   0x1b
#define MII_NCONFIG   0x1c
#define BMCR_RESV   0x003f
#define BMCR_SPEED1000   0x0040
#define BMCR_CTST   0x0080
#define BMCR_FULLDPLX   0x0100
#define BMCR_ANRESTART   0x0200
#define BMCR_ISOLATE   0x0400
#define BMCR_PDOWN   0x0800
#define BMCR_ANENABLE   0x1000
#define BMCR_SPEED100   0x2000
#define BMCR_LOOPBACK   0x4000
#define BMCR_RESET   0x8000
#define BMSR_ERCAP   0x0001
#define BMSR_JCD   0x0002
#define BMSR_LSTATUS   0x0004
#define BMSR_ANEGCAPABLE   0x0008
#define BMSR_RFAULT   0x0010
#define BMSR_ANEGCOMPLETE   0x0020
#define BMSR_RESV   0x00c0
#define BMSR_ESTATEN   0x0100
#define BMSR_100HALF2   0x0200
#define BMSR_100FULL2   0x0400
#define BMSR_10HALF   0x0800
#define BMSR_10FULL   0x1000
#define BMSR_100HALF   0x2000
#define BMSR_100FULL   0x4000
#define BMSR_100BASE4   0x8000
#define ADVERTISE_SLCT   0x001f
#define ADVERTISE_CSMA   0x0001
#define ADVERTISE_10HALF   0x0020
#define ADVERTISE_1000XFULL   0x0020
#define ADVERTISE_10FULL   0x0040
#define ADVERTISE_1000XHALF   0x0040
#define ADVERTISE_100HALF   0x0080
#define ADVERTISE_1000XPAUSE   0x0080
#define ADVERTISE_100FULL   0x0100
#define ADVERTISE_1000XPSE_ASYM   0x0100
#define ADVERTISE_100BASE4   0x0200
#define ADVERTISE_PAUSE_CAP   0x0400
#define ADVERTISE_PAUSE_ASYM   0x0800
#define ADVERTISE_RESV   0x1000
#define ADVERTISE_RFAULT   0x2000
#define ADVERTISE_LPACK   0x4000
#define ADVERTISE_NPAGE   0x8000
#define ADVERTISE_FULL
#define ADVERTISE_ALL
#define LPA_SLCT   0x001f
#define LPA_10HALF   0x0020
#define LPA_1000XFULL   0x0020
#define LPA_10FULL   0x0040
#define LPA_1000XHALF   0x0040
#define LPA_100HALF   0x0080
#define LPA_1000XPAUSE   0x0080
#define LPA_100FULL   0x0100
#define LPA_1000XPAUSE_ASYM   0x0100
#define LPA_100BASE4   0x0200
#define LPA_PAUSE_CAP   0x0400
#define LPA_PAUSE_ASYM   0x0800
#define LPA_RESV   0x1000
#define LPA_RFAULT   0x2000
#define LPA_LPACK   0x4000
#define LPA_NPAGE   0x8000
#define LPA_DUPLEX   (LPA_10FULL | LPA_100FULL)
#define LPA_100   (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
#define EXPANSION_NWAY   0x0001
#define EXPANSION_LCWP   0x0002
#define EXPANSION_ENABLENPAGE   0x0004
#define EXPANSION_NPCAPABLE   0x0008
#define EXPANSION_MFAULTS   0x0010
#define EXPANSION_RESV   0xffe0
#define ESTATUS_1000_TFULL   0x2000
#define ESTATUS_1000_THALF   0x1000
#define NWAYTEST_RESV1   0x00ff
#define NWAYTEST_LOOPBACK   0x0100
#define NWAYTEST_RESV2   0xfe00
#define ADVERTISE_1000FULL   0x0200
#define ADVERTISE_1000HALF   0x0100
#define LPA_1000LOCALRXOK   0x2000
#define LPA_1000REMRXOK   0x1000
#define LPA_1000FULL   0x0800
#define LPA_1000HALF   0x0400

Functions

 FILE_LICENCE (GPL2_ONLY)
int mii_link_ok (struct mii_if_info *mii)
 mii_link_ok - is link status up/ok : the MII interface
void mii_check_link (struct mii_if_info *mii)
 mii_check_link - check MII link status : MII interface
unsigned int mii_check_media (struct mii_if_info *mii, unsigned int ok_to_print, unsigned int init_media)
 mii_check_media - check the MII interface for a duplex change : the MII interface : OK to print link up/down messages : OK to save duplex mode in
static unsigned int mii_nway_result (unsigned int negotiated)
 mii_nway_result : value of MII ANAR and'd with ANLPAR
static unsigned int mii_duplex (unsigned int duplex_lock, unsigned int negotiated)
 mii_duplex : Non-zero if duplex is locked at full : value of MII ANAR and'd with ANLPAR


Define Documentation

#define MII_BMCR   0x00

Definition at line 20 of file mii.h.

#define MII_BMSR   0x01

Definition at line 21 of file mii.h.

#define MII_PHYSID1   0x02

Definition at line 22 of file mii.h.

#define MII_PHYSID2   0x03

Definition at line 23 of file mii.h.

#define MII_ADVERTISE   0x04

Definition at line 24 of file mii.h.

#define MII_LPA   0x05

Definition at line 25 of file mii.h.

#define MII_EXPANSION   0x06

Definition at line 26 of file mii.h.

#define MII_CTRL1000   0x09

#define MII_STAT1000   0x0a

#define MII_ESTATUS   0x0f

Definition at line 29 of file mii.h.

#define MII_DCOUNTER   0x12

Definition at line 30 of file mii.h.

#define MII_FCSCOUNTER   0x13

Definition at line 31 of file mii.h.

#define MII_NWAYTEST   0x14

Definition at line 32 of file mii.h.

#define MII_RERRCOUNTER   0x15

Definition at line 33 of file mii.h.

#define MII_SREVISION   0x16

Definition at line 34 of file mii.h.

#define MII_RESV1   0x17

Definition at line 35 of file mii.h.

#define MII_LBRERROR   0x18

Definition at line 36 of file mii.h.

#define MII_PHYADDR   0x19

Definition at line 37 of file mii.h.

#define MII_RESV2   0x1a

Definition at line 38 of file mii.h.

#define MII_TPISTATUS   0x1b

Definition at line 39 of file mii.h.

#define MII_NCONFIG   0x1c

Definition at line 40 of file mii.h.

#define BMCR_RESV   0x003f

Definition at line 43 of file mii.h.

#define BMCR_SPEED1000   0x0040

Definition at line 44 of file mii.h.

Referenced by bnx2_setup_serdes_phy().

#define BMCR_CTST   0x0080

Definition at line 45 of file mii.h.

#define BMCR_FULLDPLX   0x0100

#define BMCR_ANRESTART   0x0200

#define BMCR_ISOLATE   0x0400

Definition at line 48 of file mii.h.

Referenced by sis190_default_phy(), and TLan_PhyPowerDown().

#define BMCR_PDOWN   0x0800

Definition at line 49 of file mii.h.

Referenced by TLan_PhyPowerDown().

#define BMCR_ANENABLE   0x1000

#define BMCR_SPEED100   0x2000

Definition at line 51 of file mii.h.

#define BMCR_LOOPBACK   0x4000

#define BMCR_RESET   0x8000

Definition at line 53 of file mii.h.

#define BMSR_ERCAP   0x0001

Definition at line 56 of file mii.h.

#define BMSR_JCD   0x0002

Definition at line 57 of file mii.h.

#define BMSR_LSTATUS   0x0004

#define BMSR_ANEGCAPABLE   0x0008

Definition at line 59 of file mii.h.

Referenced by TLan_PhyStartLink().

#define BMSR_RFAULT   0x0010

Definition at line 60 of file mii.h.

#define BMSR_ANEGCOMPLETE   0x0020

#define BMSR_RESV   0x00c0

Definition at line 62 of file mii.h.

#define BMSR_ESTATEN   0x0100

Definition at line 63 of file mii.h.

#define BMSR_100HALF2   0x0200

Definition at line 64 of file mii.h.

#define BMSR_100FULL2   0x0400

Definition at line 65 of file mii.h.

#define BMSR_10HALF   0x0800

Definition at line 66 of file mii.h.

#define BMSR_10FULL   0x1000

Definition at line 67 of file mii.h.

#define BMSR_100HALF   0x2000

Definition at line 68 of file mii.h.

Referenced by sis190_init_phy().

#define BMSR_100FULL   0x4000

Definition at line 69 of file mii.h.

Referenced by sis190_init_phy().

#define BMSR_100BASE4   0x8000

Definition at line 70 of file mii.h.

#define ADVERTISE_SLCT   0x001f

Definition at line 73 of file mii.h.

Referenced by sis190_set_speed_auto().

#define ADVERTISE_CSMA   0x0001

#define ADVERTISE_10HALF   0x0020

#define ADVERTISE_1000XFULL   0x0020

Definition at line 76 of file mii.h.

Referenced by bnx2_5706s_linkup(), and bnx2_setup_serdes_phy().

#define ADVERTISE_10FULL   0x0040

#define ADVERTISE_1000XHALF   0x0040

Definition at line 78 of file mii.h.

Referenced by bnx2_5706s_linkup(), and bnx2_setup_serdes_phy().

#define ADVERTISE_100HALF   0x0080

#define ADVERTISE_1000XPAUSE   0x0080

Definition at line 80 of file mii.h.

Referenced by bnx2_phy_get_pause_adv(), and bnx2_resolve_flow_ctrl().

#define ADVERTISE_100FULL   0x0100

#define ADVERTISE_1000XPSE_ASYM   0x0100

Definition at line 82 of file mii.h.

Referenced by bnx2_phy_get_pause_adv(), and bnx2_resolve_flow_ctrl().

#define ADVERTISE_100BASE4   0x0200

Definition at line 83 of file mii.h.

#define ADVERTISE_PAUSE_CAP   0x0400

#define ADVERTISE_PAUSE_ASYM   0x0800

#define ADVERTISE_RESV   0x1000

Definition at line 86 of file mii.h.

#define ADVERTISE_RFAULT   0x2000

Definition at line 87 of file mii.h.

#define ADVERTISE_LPACK   0x4000

Definition at line 88 of file mii.h.

#define ADVERTISE_NPAGE   0x8000

Definition at line 89 of file mii.h.

#define ADVERTISE_FULL

Value:

Definition at line 91 of file mii.h.

Referenced by mii_check_media().

#define ADVERTISE_ALL

Value:

Definition at line 93 of file mii.h.

#define LPA_SLCT   0x001f

Definition at line 97 of file mii.h.

#define LPA_10HALF   0x0020

Definition at line 98 of file mii.h.

Referenced by gmii_nway_result(), mii_nway_result(), sis190_phy_task(), and update_linkspeed().

#define LPA_1000XFULL   0x0020

Definition at line 99 of file mii.h.

#define LPA_10FULL   0x0040

Definition at line 100 of file mii.h.

Referenced by gmii_nway_result(), mii_nway_result(), sis190_phy_task(), and update_linkspeed().

#define LPA_1000XHALF   0x0040

Definition at line 101 of file mii.h.

#define LPA_100HALF   0x0080

Definition at line 102 of file mii.h.

Referenced by gmii_nway_result(), mii_nway_result(), sis190_phy_task(), and update_linkspeed().

#define LPA_1000XPAUSE   0x0080

Definition at line 103 of file mii.h.

#define LPA_100FULL   0x0100

Definition at line 104 of file mii.h.

Referenced by gmii_nway_result(), mii_nway_result(), sis190_phy_task(), and update_linkspeed().

#define LPA_1000XPAUSE_ASYM   0x0100

Definition at line 105 of file mii.h.

#define LPA_100BASE4   0x0200

Definition at line 106 of file mii.h.

Referenced by gmii_nway_result(), and mii_nway_result().

#define LPA_PAUSE_CAP   0x0400

#define LPA_PAUSE_ASYM   0x0800

#define LPA_RESV   0x1000

Definition at line 109 of file mii.h.

#define LPA_RFAULT   0x2000

Definition at line 110 of file mii.h.

#define LPA_LPACK   0x4000

Definition at line 111 of file mii.h.

#define LPA_NPAGE   0x8000

Definition at line 112 of file mii.h.

Referenced by sis190_phy_task().

#define LPA_DUPLEX   (LPA_10FULL | LPA_100FULL)

Definition at line 114 of file mii.h.

Referenced by mii_duplex().

#define LPA_100   (LPA_100FULL | LPA_100HALF | LPA_100BASE4)

Definition at line 115 of file mii.h.

#define EXPANSION_NWAY   0x0001

Definition at line 118 of file mii.h.

Referenced by sis190_phy_task().

#define EXPANSION_LCWP   0x0002

Definition at line 119 of file mii.h.

#define EXPANSION_ENABLENPAGE   0x0004

Definition at line 120 of file mii.h.

#define EXPANSION_NPCAPABLE   0x0008

Definition at line 121 of file mii.h.

#define EXPANSION_MFAULTS   0x0010

Definition at line 122 of file mii.h.

#define EXPANSION_RESV   0xffe0

Definition at line 123 of file mii.h.

#define ESTATUS_1000_TFULL   0x2000

Definition at line 125 of file mii.h.

#define ESTATUS_1000_THALF   0x1000

Definition at line 126 of file mii.h.

#define NWAYTEST_RESV1   0x00ff

Definition at line 129 of file mii.h.

#define NWAYTEST_LOOPBACK   0x0100

Definition at line 130 of file mii.h.

#define NWAYTEST_RESV2   0xfe00

Definition at line 131 of file mii.h.

#define ADVERTISE_1000FULL   0x0200

#define ADVERTISE_1000HALF   0x0100

Definition at line 135 of file mii.h.

Referenced by bnx2_copper_linkup(), phy_init(), rtl8169_set_speed_xmii(), and sis190_phy_task().

#define LPA_1000LOCALRXOK   0x2000

Definition at line 138 of file mii.h.

#define LPA_1000REMRXOK   0x1000

Definition at line 139 of file mii.h.

#define LPA_1000FULL   0x0800

Definition at line 140 of file mii.h.

Referenced by mii_check_media(), sis190_phy_task(), and update_linkspeed().

#define LPA_1000HALF   0x0400

Definition at line 141 of file mii.h.

Referenced by mii_check_media(), and sis190_phy_task().


Function Documentation

FILE_LICENCE ( GPL2_ONLY   ) 

int mii_link_ok ( struct mii_if_info mii  ) 

mii_link_ok - is link status up/ok : the MII interface

Returns 1 if the MII reports link status up/ok, 0 otherwise.

Definition at line 41 of file mii.c.

References BMSR_LSTATUS, mii_if_info::dev, mii_if_info::mdio_read, MII_BMSR, and mii_if_info::phy_id.

Referenced by mii_check_link(), and mii_check_media().

00042 {
00043         /* first, a dummy read, needed to latch some MII phys */
00044         mii->mdio_read ( mii->dev, mii->phy_id, MII_BMSR );
00045         if ( mii->mdio_read ( mii->dev, mii->phy_id, MII_BMSR ) & BMSR_LSTATUS )
00046                 return 1;
00047         return 0;
00048 }

void mii_check_link ( struct mii_if_info mii  ) 

mii_check_link - check MII link status : MII interface

If the link status changed (previous != current), call netif_carrier_on() if current link status is Up or call netif_carrier_off() if current link status is Down.

Definition at line 59 of file mii.c.

References mii_if_info::dev, mii_link_ok(), netdev_link_down(), netdev_link_ok(), and netdev_link_up().

00060 {
00061         int cur_link = mii_link_ok ( mii );
00062         int prev_link = netdev_link_ok ( mii->dev );
00063 
00064         if ( cur_link && !prev_link )
00065                 netdev_link_up ( mii->dev );
00066         else if (prev_link && !cur_link)
00067                 netdev_link_down ( mii->dev );
00068 }

unsigned int mii_check_media ( struct mii_if_info mii,
unsigned int  ok_to_print,
unsigned int  init_media 
)

mii_check_media - check the MII interface for a duplex change : the MII interface : OK to print link up/down messages : OK to save duplex mode in

Returns 1 if the duplex mode changed, 0 if not. If the media type is forced, always returns 0.

Definition at line 81 of file mii.c.

References ADVERTISE_100FULL, ADVERTISE_100HALF, ADVERTISE_FULL, mii_if_info::advertising, DBG, mii_if_info::dev, mii_if_info::force_media, mii_if_info::full_duplex, LPA_1000FULL, LPA_1000HALF, mii_if_info::mdio_read, media, MII_ADVERTISE, mii_link_ok(), MII_LPA, mii_nway_result(), MII_STAT1000, net_device::name, netdev_link_down(), netdev_link_ok(), netdev_link_up(), mii_if_info::phy_id, and mii_if_info::supports_gmii.

00084 {
00085         unsigned int old_carrier, new_carrier;
00086         int advertise, lpa, media, duplex;
00087         int lpa2 = 0;
00088 
00089         /* if forced media, go no further */
00090         if (mii->force_media)
00091                 return 0; /* duplex did not change */
00092 
00093         /* check current and old link status */
00094         old_carrier = netdev_link_ok ( mii->dev ) ? 1 : 0;
00095         new_carrier = (unsigned int) mii_link_ok ( mii );
00096 
00097         /* if carrier state did not change, this is a "bounce",
00098          * just exit as everything is already set correctly
00099          */
00100         if ( ( ! init_media ) && ( old_carrier == new_carrier ) )
00101                 return 0; /* duplex did not change */
00102 
00103         /* no carrier, nothing much to do */
00104         if ( ! new_carrier ) {
00105                 netdev_link_down ( mii->dev );
00106                 if ( ok_to_print )
00107                         DBG ( "%s: link down\n", mii->dev->name);
00108                 return 0; /* duplex did not change */
00109         }
00110 
00111         /*
00112          * we have carrier, see who's on the other end
00113          */
00114         netdev_link_up ( mii->dev );
00115 
00116         /* get MII advertise and LPA values */
00117         if ( ( ! init_media ) && ( mii->advertising ) ) {
00118                 advertise = mii->advertising;
00119         } else {
00120                 advertise = mii->mdio_read ( mii->dev, mii->phy_id, MII_ADVERTISE );
00121                 mii->advertising = advertise;
00122         }
00123         lpa = mii->mdio_read ( mii->dev, mii->phy_id, MII_LPA );
00124         if ( mii->supports_gmii )
00125                 lpa2 = mii->mdio_read ( mii->dev, mii->phy_id, MII_STAT1000 );
00126 
00127         /* figure out media and duplex from advertise and LPA values */
00128         media = mii_nway_result ( lpa & advertise );
00129         duplex = ( media & ADVERTISE_FULL ) ? 1 : 0;
00130         if ( lpa2 & LPA_1000FULL )
00131                 duplex = 1;
00132 
00133         if ( ok_to_print )
00134                 DBG ( "%s: link up, %sMbps, %s-duplex, lpa 0x%04X\n",
00135                        mii->dev->name,
00136                        lpa2 & ( LPA_1000FULL | LPA_1000HALF ) ? "1000" :
00137                        media & ( ADVERTISE_100FULL | ADVERTISE_100HALF ) ? "100" : "10",
00138                        duplex ? "full" : "half",
00139                        lpa);
00140 
00141         if ( ( init_media ) || ( mii->full_duplex != duplex ) ) {
00142                 mii->full_duplex = duplex;
00143                 return 1; /* duplex changed */
00144         }
00145 
00146         return 0; /* duplex did not change */
00147 }

static unsigned int mii_nway_result ( unsigned int  negotiated  )  [inline, static]

mii_nway_result : value of MII ANAR and'd with ANLPAR

Given a set of MII abilities, check each bit and returns the currently supported media, in the priority order defined by IEEE 802.3u. We use LPA_xxx constants but note this is not the value of LPA solely, as described above.

The one exception to IEEE 802.3u is that 100baseT4 is placed between 100T-full and 100T-half. If your phy does not support 100T4 this is fine. If your phy places 100T4 elsewhere in the priority order, you will need to roll your own function.

Definition at line 182 of file mii.h.

References LPA_100BASE4, LPA_100FULL, LPA_100HALF, LPA_10FULL, and LPA_10HALF.

Referenced by mii_check_media(), and mii_duplex().

00183 {
00184         unsigned int ret;
00185 
00186         if (negotiated & LPA_100FULL)
00187                 ret = LPA_100FULL;
00188         else if (negotiated & LPA_100BASE4)
00189                 ret = LPA_100BASE4;
00190         else if (negotiated & LPA_100HALF)
00191                 ret = LPA_100HALF;
00192         else if (negotiated & LPA_10FULL)
00193                 ret = LPA_10FULL;
00194         else
00195                 ret = LPA_10HALF;
00196 
00197         return ret;
00198 }

static unsigned int mii_duplex ( unsigned int  duplex_lock,
unsigned int  negotiated 
) [inline, static]

mii_duplex : Non-zero if duplex is locked at full : value of MII ANAR and'd with ANLPAR

A small helper function for a common case. Returns one if the media is operating or locked at full duplex, and returns zero otherwise.

Definition at line 209 of file mii.h.

References LPA_DUPLEX, and mii_nway_result().

00211 {
00212         if (duplex_lock)
00213                 return 1;
00214         if (mii_nway_result(negotiated) & LPA_DUPLEX)
00215                 return 1;
00216         return 0;
00217 }


Generated on Tue Apr 6 20:01:53 2010 for gPXE by  doxygen 1.5.7.1