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

Cache object: c3641683607ad71e029301ed9c7cfa1c


[ 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.