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/pnaphy.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) 2000 Berkeley Software Design, Inc.
    3  * Copyright (c) 1997, 1998, 1999, 2000
    4  *      Bill Paul <wpaul@osd.bsdi.com>.  All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following 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  * 3. All advertising materials mentioning features or use of this software
   15  *    must display the following acknowledgement:
   16  *      This product includes software developed by Bill Paul.
   17  * 4. Neither the name of the author nor the names of any co-contributors
   18  *    may be used to endorse or promote products derived from this software
   19  *    without specific prior written permission.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
   22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   24  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
   25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
   31  * THE POSSIBILITY OF SUCH DAMAGE.
   32  *
   33  * $FreeBSD: releng/5.0/sys/dev/mii/pnaphy.c 106107 2002-10-29 00:20:47Z semenu $
   34  */
   35 
   36 /*
   37  * driver for homePNA PHYs
   38  * This is really just a stub that allows us to identify homePNA-based
   39  * transceicers and display the link status. MII-based homePNA PHYs
   40  * only support one media type and no autonegotiation. If we were
   41  * really clever, we could tweak some of the vendor-specific registers
   42  * to optimize the link.
   43  */
   44 
   45 #include <sys/param.h>
   46 #include <sys/systm.h>
   47 #include <sys/kernel.h>
   48 #include <sys/socket.h>
   49 #include <sys/errno.h>
   50 #include <sys/module.h>
   51 #include <sys/bus.h>
   52 
   53 #include <net/if.h>
   54 #include <net/if_media.h>
   55 
   56 
   57 #include <dev/mii/mii.h>
   58 #include <dev/mii/miivar.h>
   59 #include <dev/mii/miidevs.h>
   60 
   61 #include "miibus_if.h"
   62 
   63 #if !defined(lint)
   64 static const char rcsid[] =
   65   "$FreeBSD: releng/5.0/sys/dev/mii/pnaphy.c 106107 2002-10-29 00:20:47Z semenu $";
   66 #endif
   67 
   68 static int pnaphy_probe(device_t);
   69 static int pnaphy_attach(device_t);
   70 
   71 static device_method_t pnaphy_methods[] = {
   72         /* device interface */
   73         DEVMETHOD(device_probe,         pnaphy_probe),
   74         DEVMETHOD(device_attach,        pnaphy_attach),
   75         DEVMETHOD(device_detach,        mii_phy_detach),
   76         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
   77         { 0, 0 }
   78 };
   79 
   80 static devclass_t pnaphy_devclass;
   81 
   82 static driver_t pnaphy_driver = {
   83         "pnaphy",
   84         pnaphy_methods,
   85         sizeof(struct mii_softc)
   86 };
   87 
   88 DRIVER_MODULE(pnaphy, miibus, pnaphy_driver, pnaphy_devclass, 0, 0);
   89 
   90 static int      pnaphy_service(struct mii_softc *, struct mii_data *,int);
   91 
   92 static int
   93 pnaphy_probe(dev)
   94         device_t                dev;
   95 {
   96 
   97         struct mii_attach_args  *ma;
   98 
   99         ma = device_get_ivars(dev);
  100 
  101         if (MII_OUI(ma->mii_id1, ma->mii_id2) == MII_OUI_AMD &&
  102             MII_MODEL(ma->mii_id2) == MII_MODEL_AMD_79c978) {
  103                 device_set_desc(dev, MII_STR_AMD_79c978);
  104                 return(0);
  105         }
  106 
  107         return(ENXIO);
  108 }
  109 
  110 static int
  111 pnaphy_attach(dev)
  112         device_t                dev;
  113 {
  114         struct mii_softc *sc;
  115         struct mii_attach_args *ma;
  116         struct mii_data *mii;
  117         const char *sep = "";
  118 
  119         sc = device_get_softc(dev);
  120         ma = device_get_ivars(dev);
  121         sc->mii_dev = device_get_parent(dev);
  122         mii = device_get_softc(sc->mii_dev);
  123         LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
  124 
  125         sc->mii_inst = mii->mii_instance;
  126         sc->mii_phy = ma->mii_phyno;
  127         sc->mii_service = pnaphy_service;
  128         sc->mii_pdata = mii;
  129 
  130         mii->mii_instance++;
  131 
  132         sc->mii_flags |= MIIF_NOISOLATE;
  133 
  134 #define ADD(m, c)       ifmedia_add(&mii->mii_media, (m), (c), NULL)
  135 #define PRINT(s)        printf("%s%s", sep, s); sep = ", "
  136 
  137         mii_phy_reset(sc);
  138 
  139         sc->mii_capabilities =
  140             PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
  141         device_printf(dev, " ");
  142         if ((sc->mii_capabilities & BMSR_MEDIAMASK) == 0)
  143                 printf("no media present");
  144         else {
  145                 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_HPNA_1, 0, sc->mii_inst), 0);
  146                 PRINT("HomePNA");
  147         }
  148         ADD(IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, sc->mii_inst),
  149             BMCR_ISO);
  150 
  151         printf("\n");
  152 
  153 #undef ADD
  154 #undef PRINT
  155 
  156         MIIBUS_MEDIAINIT(sc->mii_dev);
  157 
  158         return(0);
  159 }
  160 
  161 static int
  162 pnaphy_service(sc, mii, cmd)
  163         struct mii_softc *sc;
  164         struct mii_data *mii;
  165         int cmd;
  166 {
  167         struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
  168         int reg;
  169 
  170         switch (cmd) {
  171         case MII_POLLSTAT:
  172                 /*
  173                  * If we're not polling our PHY instance, just return.
  174                  */
  175                 if (IFM_INST(ife->ifm_media) != sc->mii_inst)
  176                         return (0);
  177                 break;
  178 
  179         case MII_MEDIACHG:
  180                 /*
  181                  * If the media indicates a different PHY instance,
  182                  * isolate ourselves.
  183                  */
  184                 if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
  185                         reg = PHY_READ(sc, MII_BMCR);
  186                         PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
  187                         return (0);
  188                 }
  189 
  190                 /*
  191                  * If the interface is not up, don't do anything.
  192                  */
  193                 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
  194                         break;
  195 
  196                 switch (IFM_SUBTYPE(ife->ifm_media)) {
  197                 case IFM_AUTO:
  198                 case IFM_10_T:
  199                 case IFM_100_TX:
  200                 case IFM_100_T4:
  201                         return (EINVAL);
  202                 default:
  203                         /*
  204                          * BMCR data is stored in the ifmedia entry.
  205                          */
  206                         PHY_WRITE(sc, MII_ANAR,
  207                             mii_anar(ife->ifm_media));
  208                         PHY_WRITE(sc, MII_BMCR, ife->ifm_data);
  209                 }
  210                 break;
  211 
  212         case MII_TICK:
  213                 /*
  214                  * If we're not currently selected, just return.
  215                  */
  216                 if (IFM_INST(ife->ifm_media) != sc->mii_inst)
  217                         return (0);
  218                 if (mii_phy_tick(sc) == EJUSTRETURN)
  219                         return (0);
  220                 break;
  221         }
  222 
  223         /* Update the media status. */
  224         ukphy_status(sc);
  225         if (IFM_SUBTYPE(mii->mii_media_active) == IFM_10_T)
  226                 mii->mii_media_active = IFM_ETHER|IFM_HPNA_1;
  227 
  228         /* Callback if something changed. */
  229         mii_phy_update(sc, cmd);
  230         return (0);
  231 }

Cache object: 55a71864f593f276c9a4f4f1af2ef8fc


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