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/qsphy.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 /*      OpenBSD: qsphy.c,v 1.6 2000/08/26 20:04:18 nate Exp */
    2 /*      NetBSD: qsphy.c,v 1.19 2000/02/02 23:34:57 thorpej Exp  */
    3 
    4 /*-
    5  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
    6  * All rights reserved.
    7  *
    8  * This code is derived from software contributed to The NetBSD Foundation
    9  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
   10  * NASA Ames Research Center.
   11  *
   12  * Redistribution and use in source and binary forms, with or without
   13  * modification, are permitted provided that the following conditions
   14  * are met:
   15  * 1. Redistributions of source code must retain the above copyright
   16  *    notice, this list of conditions and the following disclaimer.
   17  * 2. Redistributions in binary form must reproduce the above copyright
   18  *    notice, this list of conditions and the following disclaimer in the
   19  *    documentation and/or other materials provided with the distribution.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   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 THE
   31  * POSSIBILITY OF SUCH DAMAGE.
   32  */
   33  
   34 /*-
   35  * Copyright (c) 1997 Manuel Bouyer.  All rights reserved.
   36  *
   37  * Redistribution and use in source and binary forms, with or without
   38  * modification, are permitted provided that the following conditions
   39  * are met:
   40  * 1. Redistributions of source code must retain the above copyright
   41  *    notice, this list of conditions and the following disclaimer.
   42  * 2. Redistributions in binary form must reproduce the above copyright
   43  *    notice, this list of conditions and the following disclaimer in the
   44  *    documentation and/or other materials provided with the distribution.
   45  *
   46  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   47  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   48  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   49  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   50  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   51  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   52  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   53  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   54  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   55  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   56  */
   57 
   58 #include <sys/cdefs.h>
   59 __FBSDID("$FreeBSD$");
   60 
   61 /*
   62  * driver for Quality Semiconductor's QS6612 ethernet 10/100 PHY
   63  * datasheet from www.qualitysemi.com
   64  */
   65 
   66 #include <sys/param.h>
   67 #include <sys/systm.h>
   68 #include <sys/kernel.h>
   69 #include <sys/socket.h>
   70 #include <sys/errno.h>
   71 #include <sys/module.h>
   72 #include <sys/bus.h>
   73 
   74 #include <net/if.h>
   75 #include <net/if_media.h>
   76 
   77 #include <dev/mii/mii.h>
   78 #include <dev/mii/miivar.h>
   79 #include "miidevs.h"
   80 
   81 #include <dev/mii/qsphyreg.h>
   82 
   83 #include "miibus_if.h"
   84 
   85 static int qsphy_probe(device_t);
   86 static int qsphy_attach(device_t);
   87 
   88 static device_method_t qsphy_methods[] = {
   89         /* device interface */
   90         DEVMETHOD(device_probe,         qsphy_probe),
   91         DEVMETHOD(device_attach,        qsphy_attach),
   92         DEVMETHOD(device_detach,        mii_phy_detach),
   93         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
   94         DEVMETHOD_END
   95 };
   96 
   97 static devclass_t qsphy_devclass;
   98 
   99 static driver_t qsphy_driver = {
  100         "qsphy",
  101         qsphy_methods,
  102         sizeof(struct mii_softc)
  103 };
  104 
  105 DRIVER_MODULE(qsphy, miibus, qsphy_driver, qsphy_devclass, 0, 0);
  106 
  107 static int      qsphy_service(struct mii_softc *, struct mii_data *, int);
  108 static void     qsphy_reset(struct mii_softc *);
  109 static void     qsphy_status(struct mii_softc *);
  110 
  111 static const struct mii_phydesc qsphys[] = {
  112         MII_PHY_DESC(QUALSEMI, QS6612),
  113         MII_PHY_END
  114 };
  115 
  116 static int
  117 qsphy_probe(device_t dev)
  118 {
  119 
  120         return (mii_phy_dev_probe(dev, qsphys, BUS_PROBE_DEFAULT));
  121 }
  122 
  123 static int
  124 qsphy_attach(device_t dev)
  125 {
  126         struct mii_softc *sc;
  127         struct mii_attach_args *ma;
  128         struct mii_data *mii;
  129 
  130         sc = device_get_softc(dev);
  131         ma = device_get_ivars(dev);
  132         sc->mii_dev = device_get_parent(dev);
  133         mii = ma->mii_data;
  134         LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
  135 
  136         sc->mii_flags = miibus_get_flags(dev);
  137         sc->mii_inst = mii->mii_instance++;
  138         sc->mii_phy = ma->mii_phyno;
  139         sc->mii_service = qsphy_service;
  140         sc->mii_pdata = mii;
  141 
  142         sc->mii_flags |= MIIF_NOMANPAUSE;
  143 
  144         qsphy_reset(sc);
  145 
  146         sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
  147         device_printf(dev, " ");
  148         mii_phy_add_media(sc);
  149         printf("\n");
  150 
  151         MIIBUS_MEDIAINIT(sc->mii_dev);
  152         return (0);
  153 }
  154 
  155 static int
  156 qsphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
  157 {
  158 
  159         switch (cmd) {
  160         case MII_POLLSTAT:
  161                 break;
  162 
  163         case MII_MEDIACHG:
  164                 /*
  165                  * If the interface is not up, don't do anything.
  166                  */
  167                 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
  168                         break;
  169 
  170                 mii_phy_setmedia(sc);
  171                 break;
  172 
  173         case MII_TICK:
  174                 /*
  175                  * Is the interface even up?
  176                  */
  177                 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
  178                         return (0);
  179 
  180                 /*
  181                  * This PHY's autonegotiation doesn't need to be kicked.
  182                  */
  183                 break;
  184         }
  185 
  186         /* Update the media status. */
  187         qsphy_status(sc);
  188 
  189         /* Callback if something changed. */
  190         mii_phy_update(sc, cmd);
  191         return (0);
  192 }
  193 
  194 static void
  195 qsphy_status(struct mii_softc *sc)
  196 {
  197         struct mii_data *mii = sc->mii_pdata;
  198         int bmsr, bmcr, pctl;
  199 
  200         mii->mii_media_status = IFM_AVALID;
  201         mii->mii_media_active = IFM_ETHER;
  202 
  203         bmsr = PHY_READ(sc, MII_BMSR) |
  204             PHY_READ(sc, MII_BMSR);
  205         if (bmsr & BMSR_LINK)
  206                 mii->mii_media_status |= IFM_ACTIVE;
  207 
  208         bmcr = PHY_READ(sc, MII_BMCR);
  209         if (bmcr & BMCR_ISO) {
  210                 mii->mii_media_active |= IFM_NONE;
  211                 mii->mii_media_status = 0;
  212                 return;
  213         }
  214 
  215         if (bmcr & BMCR_LOOP)
  216                 mii->mii_media_active |= IFM_LOOP;
  217 
  218         pctl = PHY_READ(sc, MII_QSPHY_PCTL);
  219         switch (pctl & PCTL_OPMASK) {
  220         case PCTL_10_T:
  221                 mii->mii_media_active |= IFM_10_T|IFM_HDX;
  222                 break;
  223         case PCTL_10_T_FDX:
  224                 mii->mii_media_active |= IFM_10_T|IFM_FDX;
  225                 break;
  226         case PCTL_100_TX:
  227                 mii->mii_media_active |= IFM_100_TX|IFM_HDX;
  228                 break;
  229         case PCTL_100_TX_FDX:
  230                 mii->mii_media_active |= IFM_100_TX|IFM_FDX;
  231                 break;
  232         case PCTL_100_T4:
  233                 mii->mii_media_active |= IFM_100_T4|IFM_HDX;
  234                 break;
  235         case PCTL_AN:
  236                 mii->mii_media_active |= IFM_NONE;
  237                 break;
  238         default:
  239                 /* Erg... this shouldn't happen. */
  240                 mii->mii_media_active |= IFM_NONE;
  241                 break;
  242         }
  243         if ((mii->mii_media_active & IFM_FDX) != 0)
  244                 mii->mii_media_active |= mii_phy_flowstatus(sc);
  245 }
  246 
  247 static void
  248 qsphy_reset(struct mii_softc *sc)
  249 {
  250 
  251         mii_phy_reset(sc);
  252         PHY_WRITE(sc, MII_QSPHY_IMASK, 0);
  253 }

Cache object: a574796f096bcd49b6836342b2eb387e


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