[BACK]Return to miivar.h CVS log [TXT][DIR] Up to [local] / sys / dev / mii

Annotation of sys/dev/mii/miivar.h, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: miivar.h,v 1.27 2006/12/28 09:24:27 kettenis Exp $    */
                      2: /*     $NetBSD: miivar.h,v 1.17 2000/03/06 20:56:57 thorpej Exp $      */
                      3:
                      4: /*-
                      5:  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
                      6:  * All rights reserved.
                      7:  *
                      8:  * This code is derived from software contributed to The NetBSD Foundation
                      9:  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
                     10:  * NASA Ames Research Center.
                     11:  *
                     12:  * Redistribution and use in source and binary forms, with or without
                     13:  * modification, are permitted provided that the following conditions
                     14:  * are met:
                     15:  * 1. Redistributions of source code must retain the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer.
                     17:  * 2. Redistributions in binary form must reproduce the above copyright
                     18:  *    notice, this list of conditions and the following disclaimer in the
                     19:  *    documentation and/or other materials provided with the distribution.
                     20:  * 3. All advertising materials mentioning features or use of this software
                     21:  *    must display the following acknowledgement:
                     22:  *     This product includes software developed by the NetBSD
                     23:  *     Foundation, Inc. and its contributors.
                     24:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     25:  *    contributors may be used to endorse or promote products derived
                     26:  *    from this software without specific prior written permission.
                     27:  *
                     28:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     29:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     30:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     31:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     32:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     33:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     34:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     35:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     36:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     37:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     38:  * POSSIBILITY OF SUCH DAMAGE.
                     39:  */
                     40:
                     41: #ifndef _DEV_MII_MIIVAR_H_
                     42: #define        _DEV_MII_MIIVAR_H_
                     43:
                     44: #include <sys/queue.h>
                     45: #include <sys/timeout.h>
                     46:
                     47: /*
                     48:  * Media Independent Interface autoconfiguration definitions.
                     49:  *
                     50:  * This file exports an interface which attempts to be compatible
                     51:  * with the BSD/OS 3.0 interface.
                     52:  */
                     53:
                     54: struct mii_softc;
                     55:
                     56: /*
                     57:  * Callbacks from MII layer into network interface device driver.
                     58:  */
                     59: typedef        int (*mii_readreg_t)(struct device *, int, int);
                     60: typedef        void (*mii_writereg_t)(struct device *, int, int, int);
                     61: typedef        void (*mii_statchg_t)(struct device *);
                     62:
                     63: /*
                     64:  * A network interface driver has one of these structures in its softc.
                     65:  * It is the interface from the network interface driver to the MII
                     66:  * layer.
                     67:  */
                     68: struct mii_data {
                     69:        struct ifmedia mii_media;       /* media information */
                     70:        struct ifnet *mii_ifp;          /* pointer back to network interface */
                     71:
                     72:        int mii_flags;                  /* misc. flags; see below */
                     73:
                     74:        /*
                     75:         * For network interfaces with multiple PHYs, a list of all
                     76:         * PHYs is required so they can all be notified when a media
                     77:         * request is made.
                     78:         */
                     79:        LIST_HEAD(mii_listhead, mii_softc) mii_phys;
                     80:        int mii_instance;
                     81:
                     82:        /*
                     83:         * PHY driver fills this in with active media status.
                     84:         */
                     85:        int mii_media_status;
                     86:        int mii_media_active;
                     87:
                     88:        /*
                     89:         * Calls from MII layer into network interface driver.
                     90:         */
                     91:        mii_readreg_t mii_readreg;
                     92:        mii_writereg_t mii_writereg;
                     93:        mii_statchg_t mii_statchg;
                     94: };
                     95: typedef struct mii_data mii_data_t;
                     96:
                     97: struct mii_phy_funcs {
                     98:        int (*pf_service)(struct mii_softc *, struct mii_data *, int);
                     99:        void (*pf_status)(struct mii_softc *);
                    100:        void (*pf_reset)(struct mii_softc *);
                    101: };
                    102:
                    103: /*
                    104:  * Requests that can be made to the downcall.
                    105:  */
                    106: #define        MII_TICK        1       /* once-per-second tick */
                    107: #define        MII_MEDIACHG    2       /* user changed media; perform the switch */
                    108: #define        MII_POLLSTAT    3       /* user requested media status; fill it in */
                    109: #define        MII_DOWN        4       /* interface is down */
                    110:
                    111: /*
                    112:  * Each PHY driver's softc has one of these as the first member.
                    113:  * XXX This would be better named "phy_softc", but this is the name
                    114:  * XXX BSDI used, and we would like to have the same interface.
                    115:  */
                    116: struct mii_softc {
                    117:        struct device mii_dev;          /* generic device glue */
                    118:
                    119:        LIST_ENTRY(mii_softc) mii_list; /* entry on parent's PHY list */
                    120:
                    121:        int mii_phy;                    /* our MII address */
                    122:        int mii_model;                  /* MII_MODEL(ma->mii_id2) */
                    123:        int mii_rev;                    /* MII_REV(ma->mii_id2) */
                    124:        int mii_offset;                 /* first PHY, second PHY, etc. */
                    125:        int mii_inst;                   /* instance for ifmedia */
                    126:
                    127:        /* Our PHY functions. */
                    128:        const struct mii_phy_funcs *mii_funcs;
                    129:
                    130:        struct mii_data *mii_pdata;     /* pointer to parent's mii_data */
                    131:
                    132:        int mii_flags;                  /* misc. flags; see below */
                    133:        int mii_capabilities;           /* capabilities from BMSR */
                    134:        int mii_extcapabilities;        /* extended capabilities */
                    135:        int mii_ticks;                  /* MII_TICK counter */
                    136:        int mii_anegticks;              /* ticks before retrying aneg */
                    137:
                    138:        struct timeout mii_phy_timo;    /* timeout handle */
                    139:
                    140:        int mii_media_active;           /* last active media */
                    141:        int mii_media_status;           /* last active status */
                    142: };
                    143: typedef struct mii_softc mii_softc_t;
                    144:
                    145: /* Default mii_anegticks values. */
                    146: #define MII_ANEGTICKS          5
                    147: #define MII_ANEGTICKS_GIGE     10
                    148:
                    149: /* mii_flags */
                    150: #define        MIIF_INITDONE   0x0001          /* has been initialized (mii_data) */
                    151: #define        MIIF_NOISOLATE  0x0002          /* do not isolate the PHY */
                    152: #define        MIIF_NOLOOP     0x0004          /* no loopback capability */
                    153: #define        MIIF_DOINGAUTO  0x0008          /* doing autonegotiation (mii_softc) */
                    154: #define MIIF_AUTOTSLEEP        0x0010          /* use tsleep(), not timeout() */
                    155: #define MIIF_HAVEFIBER 0x0020          /* from parent: has fiber interface */
                    156: #define        MIIF_HAVE_GTCR  0x0040          /* has 100base-T2/1000base-T CR */
                    157: #define        MIIF_IS_1000X   0x0080          /* is a 1000BASE-X device */
                    158: #define        MIIF_DOPAUSE    0x0100          /* advertise PAUSE capability */
                    159: #define        MIIF_IS_HPNA    0x0200          /* is a HomePNA device */
                    160: #define        MIIF_FORCEANEG  0x0400          /* force autonegotiation */
                    161:
                    162: #define        MIIF_INHERIT_MASK       (MIIF_NOISOLATE|MIIF_NOLOOP|MIIF_AUTOTSLEEP)
                    163:
                    164: /*
                    165:  * Special `locators' passed to mii_attach().  If one of these is not
                    166:  * an `any' value, we look for *that* PHY and configure it.  If both
                    167:  * are not `any', that is an error, and mii_attach() will panic.
                    168:  */
                    169: #define        MII_OFFSET_ANY          -1
                    170: #define        MII_PHY_ANY             -1
                    171:
                    172: /*
                    173:  * Used to attach a PHY to a parent.
                    174:  */
                    175: struct mii_attach_args {
                    176:        struct mii_data *mii_data;      /* pointer to parent data */
                    177:        int mii_phyno;                  /* MII address */
                    178:        int mii_id1;                    /* PHY ID register 1 */
                    179:        int mii_id2;                    /* PHY ID register 2 */
                    180:        int mii_capmask;                /* capability mask from BMSR */
                    181:        int mii_flags;                  /* flags from parent */
                    182: };
                    183: typedef struct mii_attach_args mii_attach_args_t;
                    184:
                    185: /*
                    186:  * Used to match a PHY.
                    187:  */
                    188: struct mii_phydesc {
                    189:        u_int32_t mpd_oui;              /* the PHY's OUI */
                    190:        u_int32_t mpd_model;            /* the PHY's model */
                    191:        const char *mpd_name;           /* the PHY's name */
                    192: };
                    193:
                    194: /*
                    195:  * An array of these structures map MII media types to BMCR/ANAR settings.
                    196:  */
                    197: struct mii_media {
                    198:        int     mm_bmcr;                /* BMCR settings for this media */
                    199:        int     mm_anar;                /* ANAR settings for this media */
                    200:        int     mm_gtcr;                /* 100base-T2 or 1000base-T CR */
                    201: };
                    202:
                    203: #define        MII_MEDIA_NONE          0
                    204: #define        MII_MEDIA_10_T          1
                    205: #define        MII_MEDIA_10_T_FDX      2
                    206: #define        MII_MEDIA_100_T4        3
                    207: #define        MII_MEDIA_100_TX        4
                    208: #define        MII_MEDIA_100_TX_FDX    5
                    209: #define        MII_MEDIA_1000_X        6
                    210: #define        MII_MEDIA_1000_X_FDX    7
                    211: #define        MII_MEDIA_1000_T        8
                    212: #define        MII_MEDIA_1000_T_FDX    9
                    213: #define        MII_NMEDIA              10
                    214:
                    215: #ifdef _KERNEL
                    216:
                    217: #define        PHY_READ(p, r) \
                    218:        (*(p)->mii_pdata->mii_readreg)((p)->mii_dev.dv_parent, \
                    219:            (p)->mii_phy, (r))
                    220:
                    221: #define        PHY_WRITE(p, r, v) \
                    222:        (*(p)->mii_pdata->mii_writereg)((p)->mii_dev.dv_parent, \
                    223:            (p)->mii_phy, (r), (v))
                    224:
                    225: #define        PHY_SERVICE(p, d, o) \
                    226:        (*(p)->mii_funcs->pf_service)((p), (d), (o))
                    227:
                    228: #define        PHY_STATUS(p) \
                    229:        (*(p)->mii_funcs->pf_status)((p))
                    230:
                    231: #define        PHY_RESET(p) \
                    232:        (*(p)->mii_funcs->pf_reset)((p))
                    233:
                    234: #define mii_phy_probe(x, y, z) \
                    235:        mii_attach((x), (y), (z), MII_PHY_ANY, MII_OFFSET_ANY, 0)
                    236:
                    237: #define MII_OUI(id1, id2)      (((id1) << 6) | ((id2) >> 10))
                    238: #define MII_MODEL(id2)         (((id2) & IDR2_MODEL) >> 4)
                    239: #define MII_REV(id2)           ((id2) & IDR2_REV)
                    240:
                    241: void   mii_attach(struct device *, struct mii_data *, int, int,
                    242:            int, int);
                    243: void   mii_activate(struct mii_data *, enum devact, int, int);
                    244: void   mii_detach(struct mii_data *, int, int);
                    245:
                    246: int    mii_mediachg(struct mii_data *);
                    247: void   mii_tick(struct mii_data *);
                    248: void   mii_pollstat(struct mii_data *);
                    249: void   mii_down(struct mii_data *);
                    250: int    mii_anar(int);
                    251:
                    252: int    mii_phy_activate(struct device *, enum devact);
                    253: int    mii_phy_detach(struct device *, int);
                    254:
                    255: const struct mii_phydesc *mii_phy_match(const struct mii_attach_args *,
                    256:            const struct mii_phydesc *);
                    257:
                    258: void   mii_phy_add_media(struct mii_softc *);
                    259: void   mii_phy_delete_media(struct mii_softc *);
                    260:
                    261: void   mii_phy_setmedia(struct mii_softc *);
                    262: int    mii_phy_auto(struct mii_softc *, int);
                    263: void   mii_phy_auto_timeout(void *);
                    264: void   mii_phy_reset(struct mii_softc *);
                    265: void   mii_phy_down(struct mii_softc *);
                    266: int    mii_phy_tick(struct mii_softc *);
                    267:
                    268: void   mii_phy_status(struct mii_softc *);
                    269: void   mii_phy_update(struct mii_softc *, int);
                    270: int    mii_phy_statusmsg(struct mii_softc *);
                    271:
                    272: int    mii_phy_flowstatus(struct mii_softc *);
                    273:
                    274: void   ukphy_status(struct mii_softc *);
                    275:
                    276: #endif /* _KERNEL */
                    277:
                    278: #endif /* _DEV_MII_MIIVAR_H_ */

CVSweb