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/axphy.c

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 /*-
    2  * Copyright (c) 2009, M. Warner Losh
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice unmodified, this list of conditions, and the following
   10  *    disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  *
   15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   25  * SUCH DAMAGE.
   26  */
   27 #include <sys/cdefs.h>
   28 __FBSDID("$FreeBSD: releng/8.4/sys/dev/mii/axphy.c 230718 2012-01-29 01:35:14Z marius $");
   29 
   30 /*
   31  * driver for internal phy in the AX88x9x chips.
   32  */
   33 
   34 #include <sys/param.h>
   35 #include <sys/systm.h>
   36 #include <sys/kernel.h>
   37 #include <sys/module.h>
   38 #include <sys/socket.h>
   39 #include <sys/bus.h>
   40 
   41 #include <net/if.h>
   42 #include <net/if_media.h>
   43 
   44 #include <dev/mii/mii.h>
   45 #include <dev/mii/miivar.h>
   46 #include "miidevs.h"
   47 
   48 #include "miibus_if.h"
   49 
   50 static int      axphy_probe(device_t dev);
   51 static int      axphy_attach(device_t dev);
   52 
   53 static device_method_t axphy_methods[] = {
   54         /* device interface */
   55         DEVMETHOD(device_probe,         axphy_probe),
   56         DEVMETHOD(device_attach,        axphy_attach),
   57         DEVMETHOD(device_detach,        mii_phy_detach),
   58         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
   59         DEVMETHOD_END
   60 };
   61 
   62 static devclass_t axphy_devclass;
   63 
   64 static driver_t axphy_driver = {
   65         "axphy",
   66         axphy_methods,
   67         sizeof(struct mii_softc)
   68 };
   69 
   70 DRIVER_MODULE(axphy, miibus, axphy_driver, axphy_devclass, 0, 0);
   71 
   72 static int      axphy_service(struct mii_softc *, struct mii_data *, int);
   73 static void     axphy_status(struct mii_softc *);
   74 
   75 static const struct mii_phydesc axphys[] = {
   76         MII_PHY_DESC(ASIX, AX88X9X),
   77         MII_PHY_END
   78 };
   79 
   80 static int
   81 axphy_probe(device_t dev)
   82 {
   83 
   84         return (mii_phy_dev_probe(dev, axphys, BUS_PROBE_DEFAULT));
   85 }
   86 
   87 static int
   88 axphy_attach(device_t dev)
   89 {
   90         struct mii_softc *sc;
   91         struct mii_attach_args *ma;
   92         struct mii_data *mii;
   93 
   94         sc = device_get_softc(dev);
   95         ma = device_get_ivars(dev);
   96         sc->mii_dev = device_get_parent(dev);
   97         mii = ma->mii_data;
   98         LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
   99 
  100         sc->mii_flags = miibus_get_flags(dev);
  101         sc->mii_inst = mii->mii_instance++;
  102         sc->mii_phy = ma->mii_phyno;
  103         sc->mii_service = axphy_service;
  104         sc->mii_pdata = mii;
  105 
  106         sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOMANPAUSE;
  107 
  108         mii_phy_reset(sc);
  109 
  110         sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
  111         device_printf(dev, " ");
  112         mii_phy_add_media(sc);
  113         printf("\n");
  114 
  115         MIIBUS_MEDIAINIT(sc->mii_dev);
  116         mii_phy_setmedia(sc);
  117 
  118         return (0);
  119 }
  120 
  121 static int
  122 axphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
  123 {
  124 
  125         switch (cmd) {
  126         case MII_POLLSTAT:
  127                 break;
  128 
  129         case MII_MEDIACHG:
  130                 /*
  131                  * If the interface is not up, don't do anything.
  132                  */
  133                 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
  134                         break;
  135 
  136                 mii_phy_setmedia(sc);
  137                 break;
  138 
  139         case MII_TICK:
  140                 if (mii_phy_tick(sc) == EJUSTRETURN)
  141                         return (0);
  142                 break;
  143         }
  144 
  145         /* Update the media status. */
  146         axphy_status(sc);
  147 
  148         /* Callback if something changed. */
  149         mii_phy_update(sc, cmd);
  150         return (0);
  151 }
  152 
  153 static void
  154 axphy_status(struct mii_softc *sc)
  155 {
  156         struct mii_data *mii = sc->mii_pdata;
  157         struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
  158         int bmsr, bmcr;
  159 
  160         mii->mii_media_status = IFM_AVALID;
  161         mii->mii_media_active = IFM_ETHER;
  162 
  163         bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
  164         if (bmsr & BMSR_LINK)
  165                 mii->mii_media_status |= IFM_ACTIVE;
  166 
  167         bmcr = PHY_READ(sc, MII_BMCR);
  168         if (bmcr & BMCR_ISO) {
  169                 mii->mii_media_active |= IFM_NONE;
  170                 mii->mii_media_status = 0;
  171                 return;
  172         }
  173 
  174         if (bmcr & BMCR_LOOP)
  175                 mii->mii_media_active |= IFM_LOOP;
  176 
  177         if (bmcr & BMCR_AUTOEN) {
  178                 if ((bmsr & BMSR_ACOMP) == 0) {
  179                         mii->mii_media_active |= IFM_NONE;
  180                         return;
  181                 }
  182 
  183 #if 0
  184                 scr = PHY_READ(sc, MII_AXPHY_SCR);
  185                 if (scr & SCR_S100)
  186                         mii->mii_media_active |= IFM_100_TX;
  187                 else
  188                         mii->mii_media_active |= IFM_10_T;
  189                 if (scr & SCR_FDX)
  190                         mii->mii_media_active |=
  191                             IFM_FDX | mii_phy_flowstatus(sc);
  192                 else
  193                         mii->mii_media_active |= IFM_HDX;
  194 #endif
  195         } else
  196                 mii->mii_media_active = ife->ifm_media;
  197 }

Cache object: 913ef2ff2f35d663a1fc1d9a4f65a35c


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