mii.h

Go to the documentation of this file.
00001 /*
00002  * linux/mii.h: definitions for MII-compatible transceivers
00003  * Originally drivers/net/sunhme.h.
00004  *
00005  * Copyright (C) 1996, 1999, 2001 David S. Miller (davem@redhat.com)
00006  *
00007  * Copied Form Linux 2.4.25 an unneeded items removed by:
00008  * Timothy Legge (timlegge at etherboot dot org)
00009  *
00010  * 03/26/2004
00011  */
00012 
00013 FILE_LICENCE ( GPL2_ONLY );
00014 
00015 #ifndef _MII_H_
00016 #define _MII_H_
00017 
00018 /* Generic MII registers. */
00019 
00020 #define MII_BMCR            0x00        /* Basic mode control register */
00021 #define MII_BMSR            0x01        /* Basic mode status register  */
00022 #define MII_PHYSID1         0x02        /* PHYS ID 1                   */
00023 #define MII_PHYSID2         0x03        /* PHYS ID 2                   */
00024 #define MII_ADVERTISE       0x04        /* Advertisement control reg   */
00025 #define MII_LPA             0x05        /* Link partner ability reg    */
00026 #define MII_EXPANSION       0x06        /* Expansion register          */
00027 #define MII_CTRL1000        0x09        /* 1000BASE-T control          */
00028 #define MII_STAT1000        0x0a        /* 1000BASE-T status           */
00029 #define MII_ESTATUS         0x0f        /* Extended Status */
00030 #define MII_DCOUNTER        0x12        /* Disconnect counter          */
00031 #define MII_FCSCOUNTER      0x13        /* False carrier counter       */
00032 #define MII_NWAYTEST        0x14        /* N-way auto-neg test reg     */
00033 #define MII_RERRCOUNTER     0x15        /* Receive error counter       */
00034 #define MII_SREVISION       0x16        /* Silicon revision            */
00035 #define MII_RESV1           0x17        /* Reserved...                 */
00036 #define MII_LBRERROR        0x18        /* Lpback, rx, bypass error    */
00037 #define MII_PHYADDR         0x19        /* PHY address                 */
00038 #define MII_RESV2           0x1a        /* Reserved...                 */
00039 #define MII_TPISTATUS       0x1b        /* TPI status for 10mbps       */
00040 #define MII_NCONFIG         0x1c        /* Network interface config    */
00041 
00042 /* Basic mode control register. */
00043 #define BMCR_RESV               0x003f  /* Unused...                   */
00044 #define BMCR_SPEED1000          0x0040  /* MSB of Speed (1000)         */
00045 #define BMCR_CTST               0x0080  /* Collision test              */
00046 #define BMCR_FULLDPLX           0x0100  /* Full duplex                 */
00047 #define BMCR_ANRESTART          0x0200  /* Auto negotiation restart    */
00048 #define BMCR_ISOLATE            0x0400  /* Disconnect DP83840 from MII */
00049 #define BMCR_PDOWN              0x0800  /* Powerdown the DP83840       */
00050 #define BMCR_ANENABLE           0x1000  /* Enable auto negotiation     */
00051 #define BMCR_SPEED100           0x2000  /* Select 100Mbps              */
00052 #define BMCR_LOOPBACK           0x4000  /* TXD loopback bits           */
00053 #define BMCR_RESET              0x8000  /* Reset the DP83840           */
00054 
00055 /* Basic mode status register. */
00056 #define BMSR_ERCAP              0x0001  /* Ext-reg capability          */
00057 #define BMSR_JCD                0x0002  /* Jabber detected             */
00058 #define BMSR_LSTATUS            0x0004  /* Link status                 */
00059 #define BMSR_ANEGCAPABLE        0x0008  /* Able to do auto-negotiation */
00060 #define BMSR_RFAULT             0x0010  /* Remote fault detected       */
00061 #define BMSR_ANEGCOMPLETE       0x0020  /* Auto-negotiation complete   */
00062 #define BMSR_RESV               0x00c0  /* Unused...                   */
00063 #define BMSR_ESTATEN            0x0100  /* Extended Status in R15 */
00064 #define BMSR_100HALF2           0x0200  /* Can do 100BASE-T2 HDX */
00065 #define BMSR_100FULL2           0x0400  /* Can do 100BASE-T2 FDX */
00066 #define BMSR_10HALF             0x0800  /* Can do 10mbps, half-duplex  */
00067 #define BMSR_10FULL             0x1000  /* Can do 10mbps, full-duplex  */
00068 #define BMSR_100HALF            0x2000  /* Can do 100mbps, half-duplex */
00069 #define BMSR_100FULL            0x4000  /* Can do 100mbps, full-duplex */
00070 #define BMSR_100BASE4           0x8000  /* Can do 100mbps, 4k packets  */
00071 
00072 /* Advertisement control register. */
00073 #define ADVERTISE_SLCT          0x001f  /* Selector bits               */
00074 #define ADVERTISE_CSMA          0x0001  /* Only selector supported     */
00075 #define ADVERTISE_10HALF        0x0020  /* Try for 10mbps half-duplex  */
00076 #define ADVERTISE_1000XFULL     0x0020  /* Try for 1000BASE-X full-duplex */
00077 #define ADVERTISE_10FULL        0x0040  /* Try for 10mbps full-duplex  */
00078 #define ADVERTISE_1000XHALF     0x0040  /* Try for 1000BASE-X half-duplex */
00079 #define ADVERTISE_100HALF       0x0080  /* Try for 100mbps half-duplex */
00080 #define ADVERTISE_1000XPAUSE    0x0080  /* Try for 1000BASE-X pause    */
00081 #define ADVERTISE_100FULL       0x0100  /* Try for 100mbps full-duplex */
00082 #define ADVERTISE_1000XPSE_ASYM 0x0100  /* Try for 1000BASE-X asym pause */
00083 #define ADVERTISE_100BASE4      0x0200  /* Try for 100mbps 4k packets  */
00084 #define ADVERTISE_PAUSE_CAP     0x0400  /* Try for pause               */
00085 #define ADVERTISE_PAUSE_ASYM    0x0800  /* Try for asymetric pause     */
00086 #define ADVERTISE_RESV          0x1000  /* Unused...                   */
00087 #define ADVERTISE_RFAULT        0x2000  /* Say we can detect faults    */
00088 #define ADVERTISE_LPACK         0x4000  /* Ack link partners response  */
00089 #define ADVERTISE_NPAGE         0x8000  /* Next page bit               */
00090 
00091 #define ADVERTISE_FULL (ADVERTISE_100FULL | ADVERTISE_10FULL | \
00092                         ADVERTISE_CSMA)
00093 #define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \
00094                       ADVERTISE_100HALF | ADVERTISE_100FULL)
00095 
00096 /* Link partner ability register. */
00097 #define LPA_SLCT                0x001f  /* Same as advertise selector  */
00098 #define LPA_10HALF              0x0020  /* Can do 10mbps half-duplex   */
00099 #define LPA_1000XFULL           0x0020  /* Can do 1000BASE-X full-duplex */
00100 #define LPA_10FULL              0x0040  /* Can do 10mbps full-duplex   */
00101 #define LPA_1000XHALF           0x0040  /* Can do 1000BASE-X half-duplex */
00102 #define LPA_100HALF             0x0080  /* Can do 100mbps half-duplex  */
00103 #define LPA_1000XPAUSE          0x0080  /* Can do 1000BASE-X pause     */
00104 #define LPA_100FULL             0x0100  /* Can do 100mbps full-duplex  */
00105 #define LPA_1000XPAUSE_ASYM     0x0100  /* Can do 1000BASE-X pause asym*/
00106 #define LPA_100BASE4            0x0200  /* Can do 100mbps 4k packets   */
00107 #define LPA_PAUSE_CAP           0x0400  /* Can pause                   */
00108 #define LPA_PAUSE_ASYM          0x0800  /* Can pause asymetrically     */
00109 #define LPA_RESV                0x1000  /* Unused...                   */
00110 #define LPA_RFAULT              0x2000  /* Link partner faulted        */
00111 #define LPA_LPACK               0x4000  /* Link partner acked us       */
00112 #define LPA_NPAGE               0x8000  /* Next page bit               */
00113 
00114 #define LPA_DUPLEX            (LPA_10FULL | LPA_100FULL)
00115 #define LPA_100                       (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
00116 
00117 /* Expansion register for auto-negotiation. */
00118 #define EXPANSION_NWAY          0x0001  /* Can do N-way auto-nego      */
00119 #define EXPANSION_LCWP          0x0002  /* Got new RX page code word   */
00120 #define EXPANSION_ENABLENPAGE   0x0004  /* This enables npage words    */
00121 #define EXPANSION_NPCAPABLE     0x0008  /* Link partner supports npage */
00122 #define EXPANSION_MFAULTS       0x0010  /* Multiple faults detected    */
00123 #define EXPANSION_RESV          0xffe0  /* Unused...                   */
00124 
00125 #define ESTATUS_1000_TFULL      0x2000  /* Can do 1000BT Full */
00126 #define ESTATUS_1000_THALF      0x1000  /* Can do 1000BT Half */
00127 
00128 /* N-way test register. */
00129 #define NWAYTEST_RESV1          0x00ff  /* Unused...                   */
00130 #define NWAYTEST_LOOPBACK       0x0100  /* Enable loopback for N-way   */
00131 #define NWAYTEST_RESV2          0xfe00  /* Unused...                   */
00132 
00133 /* 1000BASE-T Control register */
00134 #define ADVERTISE_1000FULL      0x0200  /* Advertise 1000BASE-T full duplex */
00135 #define ADVERTISE_1000HALF      0x0100  /* Advertise 1000BASE-T half duplex */
00136 
00137 /* 1000BASE-T Status register */
00138 #define LPA_1000LOCALRXOK       0x2000  /* Link partner local receiver status */
00139 #define LPA_1000REMRXOK         0x1000  /* Link partner remote receiver status */
00140 #define LPA_1000FULL            0x0800  /* Link partner 1000BASE-T full duplex */
00141 #define LPA_1000HALF            0x0400  /* Link partner 1000BASE-T half duplex */
00142 
00143 #include <gpxe/netdevice.h>
00144 
00145 struct mii_if_info {
00146         int phy_id;
00147         int advertising;
00148         int phy_id_mask;
00149         int reg_num_mask;
00150 
00151         unsigned int full_duplex : 1;   /* is full duplex? */
00152         unsigned int force_media : 1;   /* is autoneg. disabled? */
00153         unsigned int supports_gmii : 1; /* are GMII registers supported? */
00154 
00155         struct net_device *dev;
00156         int (*mdio_read) (struct net_device *dev, int phy_id, int location);
00157         void (*mdio_write) (struct net_device *dev, int phy_id, int location, int val);
00158 };
00159 
00160 
00161 extern int mii_link_ok (struct mii_if_info *mii);
00162 extern void mii_check_link (struct mii_if_info *mii);
00163 extern unsigned int mii_check_media (struct mii_if_info *mii,
00164                                        unsigned int ok_to_print,
00165                                        unsigned int init_media);
00166 
00167 
00168 /**
00169  * mii_nway_result
00170  * @negotiated: value of MII ANAR and'd with ANLPAR
00171  *
00172  * Given a set of MII abilities, check each bit and returns the
00173  * currently supported media, in the priority order defined by
00174  * IEEE 802.3u.  We use LPA_xxx constants but note this is not the
00175  * value of LPA solely, as described above.
00176  *
00177  * The one exception to IEEE 802.3u is that 100baseT4 is placed
00178  * between 100T-full and 100T-half.  If your phy does not support
00179  * 100T4 this is fine.  If your phy places 100T4 elsewhere in the
00180  * priority order, you will need to roll your own function.
00181  */
00182 static inline unsigned int mii_nway_result (unsigned int negotiated)
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 }
00199 
00200 /**
00201  * mii_duplex
00202  * @duplex_lock: Non-zero if duplex is locked at full
00203  * @negotiated: value of MII ANAR and'd with ANLPAR
00204  *
00205  * A small helper function for a common case.  Returns one
00206  * if the media is operating or locked at full duplex, and
00207  * returns zero otherwise.
00208  */
00209 static inline unsigned int mii_duplex (unsigned int duplex_lock,
00210                                        unsigned int negotiated)
00211 {
00212         if (duplex_lock)
00213                 return 1;
00214         if (mii_nway_result(negotiated) & LPA_DUPLEX)
00215                 return 1;
00216         return 0;
00217 }
00218 
00219 #endif

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