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 *
| 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: head/sys/dev/mii/miivar.h 214605 2010-10-31 22:41:53Z marius $
| 32 * $FreeBSD: head/sys/dev/mii/miivar.h 215297 2010-11-14 13:26:10Z marius $
|
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 configuration defintions. 42 */ 43 44struct mii_softc; 45 46/* 47 * Callbacks from MII layer into network interface device driver. 48 */ 49typedef int (*mii_readreg_t)(struct device *, int, int); 50typedef void (*mii_writereg_t)(struct device *, int, int, int); 51typedef 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 */ 58struct 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 int mii_instance; 69 70 /* 71 * PHY driver fills this in with active media status. 72 */ 73 int mii_media_status; 74 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}; 83typedef struct mii_data mii_data_t; 84 85/* 86 * This call is used by the MII layer to call into the PHY driver 87 * to perform a `service request'. 88 */ 89typedef int (*mii_downcall_t)(struct mii_softc *, struct mii_data *, int); 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 */ 103struct 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 int mii_phy; /* our MII address */ 109 int mii_inst; /* instance for ifmedia */ 110 111 mii_downcall_t mii_service; /* our downcall */ 112 struct mii_data *mii_pdata; /* pointer to parent's mii_data */ 113 114 int mii_flags; /* misc. flags; see below */ 115 int mii_capabilities; /* capabilities from BMSR */ 116 int mii_extcapabilities; /* extended capabilities */ 117 int mii_ticks; /* MII_TICK counter */ 118 int mii_anegticks; /* ticks before retrying aneg */ 119 int mii_media_active; /* last active media */ 120 int mii_media_status; /* last active status */ 121}; 122typedef struct mii_softc mii_softc_t; 123 124/* mii_flags */ 125#define MIIF_INITDONE 0x00000001 /* has been initialized (mii_data) */ 126#define MIIF_NOISOLATE 0x00000002 /* do not isolate the PHY */ 127#define MIIF_NOLOOP 0x00000004 /* no loopback capability */
| 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 configuration defintions. 42 */ 43 44struct mii_softc; 45 46/* 47 * Callbacks from MII layer into network interface device driver. 48 */ 49typedef int (*mii_readreg_t)(struct device *, int, int); 50typedef void (*mii_writereg_t)(struct device *, int, int, int); 51typedef 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 */ 58struct 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 int mii_instance; 69 70 /* 71 * PHY driver fills this in with active media status. 72 */ 73 int mii_media_status; 74 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}; 83typedef struct mii_data mii_data_t; 84 85/* 86 * This call is used by the MII layer to call into the PHY driver 87 * to perform a `service request'. 88 */ 89typedef int (*mii_downcall_t)(struct mii_softc *, struct mii_data *, int); 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 */ 103struct 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 int mii_phy; /* our MII address */ 109 int mii_inst; /* instance for ifmedia */ 110 111 mii_downcall_t mii_service; /* our downcall */ 112 struct mii_data *mii_pdata; /* pointer to parent's mii_data */ 113 114 int mii_flags; /* misc. flags; see below */ 115 int mii_capabilities; /* capabilities from BMSR */ 116 int mii_extcapabilities; /* extended capabilities */ 117 int mii_ticks; /* MII_TICK counter */ 118 int mii_anegticks; /* ticks before retrying aneg */ 119 int mii_media_active; /* last active media */ 120 int mii_media_status; /* last active status */ 121}; 122typedef struct mii_softc mii_softc_t; 123 124/* mii_flags */ 125#define MIIF_INITDONE 0x00000001 /* has been initialized (mii_data) */ 126#define MIIF_NOISOLATE 0x00000002 /* do not isolate the PHY */ 127#define MIIF_NOLOOP 0x00000004 /* no loopback capability */
|
| 128#define MIIF_DOINGAUTO 0x00000008 /* doing autonegotiation (mii_softc) */
|
128#define MIIF_AUTOTSLEEP 0x00000010 /* use tsleep(), not callout() */ 129#define MIIF_HAVEFIBER 0x00000020 /* from parent: has fiber interface */ 130#define MIIF_HAVE_GTCR 0x00000040 /* has 100base-T2/1000base-T CR */ 131#define MIIF_IS_1000X 0x00000080 /* is a 1000BASE-X device */ 132#define MIIF_DOPAUSE 0x00000100 /* advertise PAUSE capability */ 133#define MIIF_IS_HPNA 0x00000200 /* is a HomePNA device */ 134#define MIIF_FORCEANEG 0x00000400 /* force auto-negotiation */
| 129#define MIIF_AUTOTSLEEP 0x00000010 /* use tsleep(), not callout() */ 130#define MIIF_HAVEFIBER 0x00000020 /* from parent: has fiber interface */ 131#define MIIF_HAVE_GTCR 0x00000040 /* has 100base-T2/1000base-T CR */ 132#define MIIF_IS_1000X 0x00000080 /* is a 1000BASE-X device */ 133#define MIIF_DOPAUSE 0x00000100 /* advertise PAUSE capability */ 134#define MIIF_IS_HPNA 0x00000200 /* is a HomePNA device */ 135#define MIIF_FORCEANEG 0x00000400 /* force auto-negotiation */
|
| 136#define MIIF_NOMANPAUSE 0x00100000 /* no manual PAUSE selection */ 137#define MIIF_FORCEPAUSE 0x00200000 /* force PAUSE advertisment */
|
135#define MIIF_MACPRIV0 0x01000000 /* private to the MAC driver */ 136#define MIIF_MACPRIV1 0x02000000 /* private to the MAC driver */ 137#define MIIF_MACPRIV2 0x04000000 /* private to the MAC driver */ 138#define MIIF_PHYPRIV0 0x10000000 /* private to the PHY driver */ 139#define MIIF_PHYPRIV1 0x20000000 /* private to the PHY driver */ 140#define MIIF_PHYPRIV2 0x40000000 /* private to the PHY driver */ 141 142/* Default mii_anegticks values */ 143#define MII_ANEGTICKS 5 144#define MII_ANEGTICKS_GIGE 17 145 146#define MIIF_INHERIT_MASK (MIIF_NOISOLATE|MIIF_NOLOOP|MIIF_AUTOTSLEEP) 147 148/* 149 * Special `locators' passed to mii_attach(). If one of these is not 150 * an `any' value, we look for *that* PHY and configure it. If both 151 * are not `any', that is an error, and mii_attach() will fail. 152 */ 153#define MII_OFFSET_ANY -1 154#define MII_PHY_ANY -1 155 156/* 157 * Used to attach a PHY to a parent. 158 */ 159struct mii_attach_args { 160 struct mii_data *mii_data; /* pointer to parent data */ 161 int mii_phyno; /* MII address */ 162 int mii_id1; /* PHY ID register 1 */ 163 int mii_id2; /* PHY ID register 2 */ 164 int mii_capmask; /* capability mask from BMSR */ 165}; 166typedef struct mii_attach_args mii_attach_args_t; 167 168/* 169 * Used to match a PHY. 170 */ 171struct mii_phydesc { 172 u_int32_t mpd_oui; /* the PHY's OUI */ 173 u_int32_t mpd_model; /* the PHY's model */ 174 const char *mpd_name; /* the PHY's name */ 175}; 176#define MII_PHY_DESC(a, b) { MII_OUI_ ## a, MII_MODEL_ ## a ## _ ## b, \ 177 MII_STR_ ## a ## _ ## b } 178#define MII_PHY_END { 0, 0, NULL } 179 180/* 181 * An array of these structures map MII media types to BMCR/ANAR settings. 182 */ 183struct mii_media { 184 int mm_bmcr; /* BMCR settings for this media */ 185 int mm_anar; /* ANAR settings for this media */ 186 int mm_gtcr; /* 100base-T2 or 1000base-T CR */ 187}; 188 189#define MII_MEDIA_NONE 0 190#define MII_MEDIA_10_T 1 191#define MII_MEDIA_10_T_FDX 2 192#define MII_MEDIA_100_T4 3 193#define MII_MEDIA_100_TX 4 194#define MII_MEDIA_100_TX_FDX 5 195#define MII_MEDIA_1000_X 6 196#define MII_MEDIA_1000_X_FDX 7 197#define MII_MEDIA_1000_T 8 198#define MII_MEDIA_1000_T_FDX 9 199#define MII_NMEDIA 10 200 201#ifdef _KERNEL 202 203#define PHY_READ(p, r) \ 204 MIIBUS_READREG((p)->mii_dev, (p)->mii_phy, (r)) 205 206#define PHY_WRITE(p, r, v) \ 207 MIIBUS_WRITEREG((p)->mii_dev, (p)->mii_phy, (r), (v)) 208 209enum miibus_device_ivars { 210 MIIBUS_IVAR_FLAGS 211}; 212 213/* 214 * Simplified accessors for miibus 215 */ 216#define MIIBUS_ACCESSOR(var, ivar, type) \ 217 __BUS_ACCESSOR(miibus, var, MIIBUS, ivar, type) 218 219MIIBUS_ACCESSOR(flags, FLAGS, int) 220 221extern devclass_t miibus_devclass; 222extern driver_t miibus_driver; 223 224int miibus_probe(device_t); 225int miibus_attach(device_t); 226int miibus_detach(device_t); 227 228int mii_attach(device_t, device_t *, struct ifnet *, ifm_change_cb_t, 229 ifm_stat_cb_t, int, int, int, int); 230void mii_down(struct mii_data *); 231int mii_mediachg(struct mii_data *); 232void mii_tick(struct mii_data *); 233void mii_pollstat(struct mii_data *); 234void mii_phy_add_media(struct mii_softc *); 235 236int mii_phy_auto(struct mii_softc *); 237int mii_phy_detach(device_t dev); 238void mii_phy_down(struct mii_softc *);
| 138#define MIIF_MACPRIV0 0x01000000 /* private to the MAC driver */ 139#define MIIF_MACPRIV1 0x02000000 /* private to the MAC driver */ 140#define MIIF_MACPRIV2 0x04000000 /* private to the MAC driver */ 141#define MIIF_PHYPRIV0 0x10000000 /* private to the PHY driver */ 142#define MIIF_PHYPRIV1 0x20000000 /* private to the PHY driver */ 143#define MIIF_PHYPRIV2 0x40000000 /* private to the PHY driver */ 144 145/* Default mii_anegticks values */ 146#define MII_ANEGTICKS 5 147#define MII_ANEGTICKS_GIGE 17 148 149#define MIIF_INHERIT_MASK (MIIF_NOISOLATE|MIIF_NOLOOP|MIIF_AUTOTSLEEP) 150 151/* 152 * Special `locators' passed to mii_attach(). If one of these is not 153 * an `any' value, we look for *that* PHY and configure it. If both 154 * are not `any', that is an error, and mii_attach() will fail. 155 */ 156#define MII_OFFSET_ANY -1 157#define MII_PHY_ANY -1 158 159/* 160 * Used to attach a PHY to a parent. 161 */ 162struct mii_attach_args { 163 struct mii_data *mii_data; /* pointer to parent data */ 164 int mii_phyno; /* MII address */ 165 int mii_id1; /* PHY ID register 1 */ 166 int mii_id2; /* PHY ID register 2 */ 167 int mii_capmask; /* capability mask from BMSR */ 168}; 169typedef struct mii_attach_args mii_attach_args_t; 170 171/* 172 * Used to match a PHY. 173 */ 174struct mii_phydesc { 175 u_int32_t mpd_oui; /* the PHY's OUI */ 176 u_int32_t mpd_model; /* the PHY's model */ 177 const char *mpd_name; /* the PHY's name */ 178}; 179#define MII_PHY_DESC(a, b) { MII_OUI_ ## a, MII_MODEL_ ## a ## _ ## b, \ 180 MII_STR_ ## a ## _ ## b } 181#define MII_PHY_END { 0, 0, NULL } 182 183/* 184 * An array of these structures map MII media types to BMCR/ANAR settings. 185 */ 186struct mii_media { 187 int mm_bmcr; /* BMCR settings for this media */ 188 int mm_anar; /* ANAR settings for this media */ 189 int mm_gtcr; /* 100base-T2 or 1000base-T CR */ 190}; 191 192#define MII_MEDIA_NONE 0 193#define MII_MEDIA_10_T 1 194#define MII_MEDIA_10_T_FDX 2 195#define MII_MEDIA_100_T4 3 196#define MII_MEDIA_100_TX 4 197#define MII_MEDIA_100_TX_FDX 5 198#define MII_MEDIA_1000_X 6 199#define MII_MEDIA_1000_X_FDX 7 200#define MII_MEDIA_1000_T 8 201#define MII_MEDIA_1000_T_FDX 9 202#define MII_NMEDIA 10 203 204#ifdef _KERNEL 205 206#define PHY_READ(p, r) \ 207 MIIBUS_READREG((p)->mii_dev, (p)->mii_phy, (r)) 208 209#define PHY_WRITE(p, r, v) \ 210 MIIBUS_WRITEREG((p)->mii_dev, (p)->mii_phy, (r), (v)) 211 212enum miibus_device_ivars { 213 MIIBUS_IVAR_FLAGS 214}; 215 216/* 217 * Simplified accessors for miibus 218 */ 219#define MIIBUS_ACCESSOR(var, ivar, type) \ 220 __BUS_ACCESSOR(miibus, var, MIIBUS, ivar, type) 221 222MIIBUS_ACCESSOR(flags, FLAGS, int) 223 224extern devclass_t miibus_devclass; 225extern driver_t miibus_driver; 226 227int miibus_probe(device_t); 228int miibus_attach(device_t); 229int miibus_detach(device_t); 230 231int mii_attach(device_t, device_t *, struct ifnet *, ifm_change_cb_t, 232 ifm_stat_cb_t, int, int, int, int); 233void mii_down(struct mii_data *); 234int mii_mediachg(struct mii_data *); 235void mii_tick(struct mii_data *); 236void mii_pollstat(struct mii_data *); 237void mii_phy_add_media(struct mii_softc *); 238 239int mii_phy_auto(struct mii_softc *); 240int mii_phy_detach(device_t dev); 241void mii_phy_down(struct mii_softc *);
|
| 242u_int mii_phy_flowstatus(struct mii_softc *);
|
239void mii_phy_reset(struct mii_softc *); 240void mii_phy_setmedia(struct mii_softc *sc); 241void mii_phy_update(struct mii_softc *, int); 242int mii_phy_tick(struct mii_softc *); 243 244const struct mii_phydesc * mii_phy_match(const struct mii_attach_args *ma, 245 const struct mii_phydesc *mpd); 246const struct mii_phydesc * mii_phy_match_gen(const struct mii_attach_args *ma, 247 const struct mii_phydesc *mpd, size_t endlen); 248int mii_phy_dev_probe(device_t dev, const struct mii_phydesc *mpd, int mrv); 249 250void ukphy_status(struct mii_softc *); 251#endif /* _KERNEL */ 252 253#endif /* _DEV_MII_MIIVAR_H_ */
| 243void mii_phy_reset(struct mii_softc *); 244void mii_phy_setmedia(struct mii_softc *sc); 245void mii_phy_update(struct mii_softc *, int); 246int mii_phy_tick(struct mii_softc *); 247 248const struct mii_phydesc * mii_phy_match(const struct mii_attach_args *ma, 249 const struct mii_phydesc *mpd); 250const struct mii_phydesc * mii_phy_match_gen(const struct mii_attach_args *ma, 251 const struct mii_phydesc *mpd, size_t endlen); 252int mii_phy_dev_probe(device_t dev, const struct mii_phydesc *mpd, int mrv); 253 254void ukphy_status(struct mii_softc *); 255#endif /* _KERNEL */ 256 257#endif /* _DEV_MII_MIIVAR_H_ */
|