The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/mii/miivar.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: miivar.h,v 1.8 1999/04/23 04:24:32 thorpej Exp $       */
    2 
    3 /*-
    4  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
    9  * NASA Ames Research Center.
   10  *
   11  * Redistribution and use in source and binary forms, with or without
   12  * modification, are permitted provided that the following conditions
   13  * are met:
   14  * 1. Redistributions of source code must retain the above copyright
   15  *    notice, this list of conditions and the following disclaimer.
   16  * 2. Redistributions in binary form must reproduce the above copyright
   17  *    notice, this list of conditions and the following disclaimer in the
   18  *    documentation and/or other materials provided with the distribution.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   30  * POSSIBILITY OF SUCH DAMAGE.
   31  *
   32  * $FreeBSD$
   33  */
   34 
   35 #ifndef _DEV_MII_MIIVAR_H_
   36 #define _DEV_MII_MIIVAR_H_
   37 
   38 #include <sys/queue.h>
   39 
   40 /*
   41  * Media Independent Interface data structure defintions
   42  */
   43 
   44 struct mii_softc;
   45 
   46 /*
   47  * Callbacks from MII layer into network interface device driver.
   48  */
   49 typedef int (*mii_readreg_t)(struct device *, int, int);
   50 typedef void (*mii_writereg_t)(struct device *, int, int, int);
   51 typedef void (*mii_statchg_t)(struct device *);
   52 
   53 /*
   54  * A network interface driver has one of these structures in its softc.
   55  * It is the interface from the network interface driver to the MII
   56  * layer.
   57  */
   58 struct mii_data {
   59         struct ifmedia mii_media;       /* media information */
   60         struct ifnet *mii_ifp;          /* pointer back to network interface */
   61 
   62         /*
   63          * For network interfaces with multiple PHYs, a list of all
   64          * PHYs is required so they can all be notified when a media
   65          * request is made.
   66          */
   67         LIST_HEAD(mii_listhead, mii_softc) mii_phys;
   68         u_int mii_instance;
   69 
   70         /*
   71          * PHY driver fills this in with active media status.
   72          */
   73         u_int mii_media_status;
   74         u_int mii_media_active;
   75 
   76         /*
   77          * Calls from MII layer into network interface driver.
   78          */
   79         mii_readreg_t mii_readreg;
   80         mii_writereg_t mii_writereg;
   81         mii_statchg_t mii_statchg;
   82 };
   83 typedef struct mii_data mii_data_t;
   84 
   85 /*
   86  * Functions provided by the PHY to perform various functions.
   87  */
   88 struct mii_phy_funcs {
   89         int (*pf_service)(struct mii_softc *, struct mii_data *, int);
   90         void (*pf_status)(struct mii_softc *);
   91         void (*pf_reset)(struct mii_softc *);
   92 };
   93 
   94 /*
   95  * Requests that can be made to the downcall.
   96  */
   97 #define MII_TICK        1       /* once-per-second tick */
   98 #define MII_MEDIACHG    2       /* user changed media; perform the switch */
   99 #define MII_POLLSTAT    3       /* user requested media status; fill it in */
  100 
  101 /*
  102  * Each PHY driver's softc has one of these as the first member.
  103  * XXX This would be better named "phy_softc", but this is the name
  104  * XXX BSDI used, and we would like to have the same interface.
  105  */
  106 struct mii_softc {
  107         device_t mii_dev;               /* generic device glue */
  108 
  109         LIST_ENTRY(mii_softc) mii_list; /* entry on parent's PHY list */
  110 
  111         uint32_t mii_mpd_oui;           /* the PHY's OUI (MII_OUI())*/
  112         uint32_t mii_mpd_model;         /* the PHY's model (MII_MODEL())*/
  113         uint32_t mii_mpd_rev;           /* the PHY's revision (MII_REV())*/
  114         u_int mii_capmask;              /* capability mask for BMSR */
  115         u_int mii_phy;                  /* our MII address */
  116         u_int mii_offset;               /* first PHY, second PHY, etc. */
  117         u_int mii_inst;                 /* instance for ifmedia */
  118 
  119         /* Our PHY functions. */
  120         const struct mii_phy_funcs *mii_funcs;
  121 
  122         struct mii_data *mii_pdata;     /* pointer to parent's mii_data */
  123 
  124         u_int mii_flags;                /* misc. flags; see below */
  125         u_int mii_capabilities;         /* capabilities from BMSR */
  126         u_int mii_extcapabilities;      /* extended capabilities */
  127         u_int mii_ticks;                /* MII_TICK counter */
  128         u_int mii_anegticks;            /* ticks before retrying aneg */
  129         u_int mii_media_active;         /* last active media */
  130         u_int mii_media_status;         /* last active status */
  131 };
  132 typedef struct mii_softc mii_softc_t;
  133 
  134 /* mii_flags */
  135 #define MIIF_INITDONE   0x00000001      /* has been initialized (mii_data) */
  136 #define MIIF_NOISOLATE  0x00000002      /* do not isolate the PHY */
  137 #if 0
  138 #define MIIF_NOLOOP     0x00000004      /* no loopback capability */
  139 #endif
  140 #define MIIF_DOINGAUTO  0x00000008      /* doing autonegotiation (mii_softc) */
  141 #define MIIF_AUTOTSLEEP 0x00000010      /* use tsleep(), not callout() */
  142 #define MIIF_HAVEFIBER  0x00000020      /* from parent: has fiber interface */
  143 #define MIIF_HAVE_GTCR  0x00000040      /* has 100base-T2/1000base-T CR */
  144 #define MIIF_IS_1000X   0x00000080      /* is a 1000BASE-X device */
  145 #define MIIF_DOPAUSE    0x00000100      /* advertise PAUSE capability */
  146 #define MIIF_IS_HPNA    0x00000200      /* is a HomePNA device */
  147 #define MIIF_FORCEANEG  0x00000400      /* force auto-negotiation */
  148 #define MIIF_NOMANPAUSE 0x00100000      /* no manual PAUSE selection */
  149 #define MIIF_FORCEPAUSE 0x00200000      /* force PAUSE advertisement */
  150 #define MIIF_MACPRIV0   0x01000000      /* private to the MAC driver */
  151 #define MIIF_MACPRIV1   0x02000000      /* private to the MAC driver */
  152 #define MIIF_MACPRIV2   0x04000000      /* private to the MAC driver */
  153 #define MIIF_PHYPRIV0   0x10000000      /* private to the PHY driver */
  154 #define MIIF_PHYPRIV1   0x20000000      /* private to the PHY driver */
  155 #define MIIF_PHYPRIV2   0x40000000      /* private to the PHY driver */
  156 
  157 /* Default mii_anegticks values */
  158 #define MII_ANEGTICKS           5
  159 #define MII_ANEGTICKS_GIGE      17
  160 
  161 #define MIIF_INHERIT_MASK       (MIIF_NOISOLATE|MIIF_NOLOOP|MIIF_AUTOTSLEEP)
  162 
  163 /*
  164  * Special `locators' passed to mii_attach().  If one of these is not
  165  * an `any' value, we look for *that* PHY and configure it.  If both
  166  * are not `any', that is an error, and mii_attach() will fail.
  167  */
  168 #define MII_OFFSET_ANY          -1
  169 #define MII_PHY_ANY             -1
  170 
  171 /*
  172  * Used to attach a PHY to a parent.
  173  */
  174 struct mii_attach_args {
  175         struct mii_data *mii_data;      /* pointer to parent data */
  176         u_int mii_phyno;                /* MII address */
  177         u_int mii_offset;               /* first PHY, second PHY, etc. */
  178         uint32_t mii_id1;               /* PHY ID register 1 */
  179         uint32_t mii_id2;               /* PHY ID register 2 */
  180         u_int mii_capmask;              /* capability mask for BMSR */
  181 };
  182 typedef struct mii_attach_args mii_attach_args_t;
  183 
  184 /*
  185  * Used to match a PHY.
  186  */
  187 struct mii_phydesc {
  188         uint32_t mpd_oui;               /* the PHY's OUI */
  189         uint32_t mpd_model;             /* the PHY's model */
  190         const char *mpd_name;           /* the PHY's name */
  191 };
  192 #define MII_PHY_DESC(a, b) { MII_OUI_ ## a, MII_MODEL_ ## a ## _ ## b, \
  193         MII_STR_ ## a ## _ ## b }
  194 #define MII_PHY_END     { 0, 0, NULL }
  195 
  196 /*
  197  * An array of these structures map MII media types to BMCR/ANAR settings.
  198  */
  199 struct mii_media {
  200         u_int   mm_bmcr;                /* BMCR settings for this media */
  201         u_int   mm_anar;                /* ANAR settings for this media */
  202         u_int   mm_gtcr;                /* 100base-T2 or 1000base-T CR */
  203 };
  204 
  205 #define MII_MEDIA_NONE          0
  206 #define MII_MEDIA_10_T          1
  207 #define MII_MEDIA_10_T_FDX      2
  208 #define MII_MEDIA_100_T4        3
  209 #define MII_MEDIA_100_TX        4
  210 #define MII_MEDIA_100_TX_FDX    5
  211 #define MII_MEDIA_1000_X        6
  212 #define MII_MEDIA_1000_X_FDX    7
  213 #define MII_MEDIA_1000_T        8
  214 #define MII_MEDIA_1000_T_FDX    9
  215 #define MII_NMEDIA              10
  216 
  217 #ifdef _KERNEL
  218 
  219 #define PHY_READ(p, r) \
  220         MIIBUS_READREG((p)->mii_dev, (p)->mii_phy, (r))
  221 
  222 #define PHY_WRITE(p, r, v) \
  223         MIIBUS_WRITEREG((p)->mii_dev, (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 enum miibus_device_ivars {
  235         MIIBUS_IVAR_FLAGS
  236 };
  237 
  238 /*
  239  * Simplified accessors for miibus
  240  */
  241 #define MIIBUS_ACCESSOR(var, ivar, type)                                \
  242         __BUS_ACCESSOR(miibus, var, MIIBUS, ivar, type)
  243 
  244 MIIBUS_ACCESSOR(flags,          FLAGS,          u_int)
  245 
  246 extern devclass_t       miibus_devclass;
  247 extern driver_t         miibus_driver;
  248 
  249 int     mii_attach(device_t, device_t *, struct ifnet *, ifm_change_cb_t,
  250             ifm_stat_cb_t, int, int, int, int);
  251 void    mii_down(struct mii_data *);
  252 int     mii_mediachg(struct mii_data *);
  253 void    mii_tick(struct mii_data *);
  254 void    mii_pollstat(struct mii_data *);
  255 void    mii_phy_add_media(struct mii_softc *);
  256 
  257 int     mii_phy_auto(struct mii_softc *);
  258 int     mii_phy_detach(device_t dev);
  259 void    mii_phy_down(struct mii_softc *);
  260 u_int   mii_phy_flowstatus(struct mii_softc *);
  261 void    mii_phy_reset(struct mii_softc *);
  262 void    mii_phy_setmedia(struct mii_softc *sc);
  263 void    mii_phy_update(struct mii_softc *, int);
  264 int     mii_phy_tick(struct mii_softc *);
  265 
  266 const struct mii_phydesc * mii_phy_match(const struct mii_attach_args *ma,
  267     const struct mii_phydesc *mpd);
  268 const struct mii_phydesc * mii_phy_match_gen(const struct mii_attach_args *ma,
  269     const struct mii_phydesc *mpd, size_t endlen);
  270 int mii_phy_dev_probe(device_t dev, const struct mii_phydesc *mpd, int mrv);
  271 void mii_phy_dev_attach(device_t dev, u_int flags,
  272     const struct mii_phy_funcs *mpf, int add_media);
  273 
  274 void    ukphy_status(struct mii_softc *);
  275 
  276 u_int   mii_oui(u_int, u_int);
  277 #define MII_OUI(id1, id2)       mii_oui(id1, id2)
  278 #define MII_MODEL(id2)          (((id2) & IDR2_MODEL) >> 4)
  279 #define MII_REV(id2)            ((id2) & IDR2_REV)
  280 
  281 #endif /* _KERNEL */
  282 
  283 #endif /* _DEV_MII_MIIVAR_H_ */

Cache object: 500d1804bbb627783ca4c368ee7d73d7


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.