Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 6 Nov 2011 17:23:49 +0000 (UTC)
From:      Marius Strobl <marius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r227229 - in stable/9/sys: conf dev/fxp dev/mii dev/usb/net dev/xl modules/fxp modules/mii modules/usb/rue modules/xl
Message-ID:  <201111061723.pA6HNntX032551@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marius
Date: Sun Nov  6 17:23:49 2011
New Revision: 227229
URL: http://svn.freebsd.org/changeset/base/227229

Log:
  MFC: r226154, r226165
  
  - Follow the lead of dcphy(4) and pnphy(4) and move the reminder of the PHY
    drivers that only ever attach to a particular MAC driver, i.e. inphy(4),
    ruephy(4) and xlphy(4), to the directory where the respective MAC driver
    lives and only compile it into the kernel when the latter is also there,
    also removing it from miibus.ko and moving it into the module of the
    respective MAC driver.
  - While at it, rename exphy.c, which comes from NetBSD where the MAC driver
    it corresponds to also is named ex(4) instead of xl(4) but that in FreeBSD
    actually identifies itself as xlphy(4), and its function names accordingly
    for consistency.
  - Additionally while at it, fix some minor style issues like whitespace
    in the register headers and add multi-inclusion protection to inphyreg.h.
  
  Approved by:	re (kib)

Added:
  stable/9/sys/dev/fxp/inphy.c
     - copied unchanged from r226154, head/sys/dev/fxp/inphy.c
  stable/9/sys/dev/fxp/inphyreg.h
     - copied unchanged from r226154, head/sys/dev/fxp/inphyreg.h
  stable/9/sys/dev/usb/net/ruephy.c
     - copied unchanged from r226154, head/sys/dev/usb/net/ruephy.c
  stable/9/sys/dev/usb/net/ruephyreg.h
     - copied unchanged from r226154, head/sys/dev/usb/net/ruephyreg.h
  stable/9/sys/dev/xl/xlphy.c
     - copied unchanged from r226154, head/sys/dev/xl/xlphy.c
Deleted:
  stable/9/sys/dev/mii/exphy.c
  stable/9/sys/dev/mii/inphy.c
  stable/9/sys/dev/mii/inphyreg.h
  stable/9/sys/dev/mii/ruephy.c
  stable/9/sys/dev/mii/ruephyreg.h
Modified:
  stable/9/sys/conf/NOTES
  stable/9/sys/conf/files
  stable/9/sys/modules/fxp/Makefile
  stable/9/sys/modules/mii/Makefile
  stable/9/sys/modules/usb/rue/Makefile
  stable/9/sys/modules/xl/Makefile
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/amd64/include/xen/   (props changed)
  stable/9/sys/boot/   (props changed)
  stable/9/sys/boot/i386/efi/   (props changed)
  stable/9/sys/boot/ia64/efi/   (props changed)
  stable/9/sys/boot/ia64/ski/   (props changed)
  stable/9/sys/boot/powerpc/boot1.chrp/   (props changed)
  stable/9/sys/boot/powerpc/ofw/   (props changed)
  stable/9/sys/cddl/contrib/opensolaris/   (props changed)
  stable/9/sys/conf/   (props changed)
  stable/9/sys/contrib/dev/acpica/   (props changed)
  stable/9/sys/contrib/octeon-sdk/   (props changed)
  stable/9/sys/contrib/pf/   (props changed)
  stable/9/sys/contrib/x86emu/   (props changed)

Modified: stable/9/sys/conf/NOTES
==============================================================================
--- stable/9/sys/conf/NOTES	Sun Nov  6 17:20:44 2011	(r227228)
+++ stable/9/sys/conf/NOTES	Sun Nov  6 17:23:49 2011	(r227229)
@@ -1862,10 +1862,8 @@ device  	bmtphy		# Broadcom BCM5201/BCM5
 device  	brgphy		# Broadcom BCM54xx/57xx 1000baseTX
 device  	ciphy		# Cicada/Vitesse CS/VSC8xxx
 device  	e1000phy	# Marvell 88E1000 1000/100/10-BT
-device  	exphy		# 3Com internal PHY
 device  	gentbi		# Generic 10-bit 1000BASE-{LX,SX} fiber ifaces
 device  	icsphy		# ICS ICS1889-1893
-device  	inphy		# Intel 82553/82555
 device  	ip1000phy	# IC Plus IP1000A/IP1001
 device  	jmphy		# JMicron JMP211/JMP202
 device  	lxtphy		# Level One LXT-970
@@ -1879,7 +1877,6 @@ device  	rdcphy		# RDC Semiconductor R60
 device  	rgephy		# RealTek 8169S/8110S/8211B/8211C
 device  	rlphy		# RealTek 8139
 device  	rlswitch	# RealTek 8305
-device  	ruephy		# RealTek RTL8150
 device  	smcphy		# SMSC LAN91C111
 device  	tdkphy		# TDK 89Q2120
 device  	tlphy		# Texas Instruments ThunderLAN

Modified: stable/9/sys/conf/files
==============================================================================
--- stable/9/sys/conf/files	Sun Nov  6 17:20:44 2011	(r227228)
+++ stable/9/sys/conf/files	Sun Nov  6 17:23:49 2011	(r227229)
@@ -1092,6 +1092,7 @@ dev/firewire/sbp_targ.c		optional sbp_ta
 dev/flash/at45d.c		optional at45d
 dev/flash/mx25l.c		optional mx25l
 dev/fxp/if_fxp.c		optional fxp
+dev/fxp/inphy.c			optional fxp
 dev/gem/if_gem.c		optional gem
 dev/gem/if_gem_pci.c		optional gem pci
 dev/gem/if_gem_sbus.c		optional gem sbus
@@ -1418,12 +1419,8 @@ dev/mii/bmtphy.c		optional miibus | bmtp
 dev/mii/brgphy.c		optional miibus | brgphy
 dev/mii/ciphy.c			optional miibus | ciphy
 dev/mii/e1000phy.c		optional miibus | e1000phy
-# XXX only xl cards?
-dev/mii/exphy.c			optional miibus | exphy
 dev/mii/gentbi.c		optional miibus | gentbi
 dev/mii/icsphy.c		optional miibus | icsphy
-# XXX only fxp cards?
-dev/mii/inphy.c			optional miibus | inphy
 dev/mii/ip1000phy.c		optional miibus | ip1000phy
 dev/mii/jmphy.c			optional miibus | jmphy
 dev/mii/lxtphy.c		optional miibus | lxtphy
@@ -1440,8 +1437,6 @@ dev/mii/rdcphy.c		optional miibus | rdcp
 dev/mii/rgephy.c		optional miibus | rgephy
 dev/mii/rlphy.c			optional miibus | rlphy
 dev/mii/rlswitch.c		optional rlswitch
-# XXX rue only?
-dev/mii/ruephy.c		optional miibus | ruephy
 dev/mii/smcphy.c		optional miibus | smcphy
 dev/mii/tdkphy.c		optional miibus | tdkphy
 dev/mii/tlphy.c			optional miibus | tlphy
@@ -1924,6 +1919,7 @@ dev/usb/net/if_mos.c		optional mos
 dev/usb/net/if_rue.c		optional rue
 dev/usb/net/if_udav.c		optional udav
 dev/usb/net/if_usie.c		optional usie
+dev/usb/net/ruephy.c		optional rue
 dev/usb/net/usb_ethernet.c	optional aue | axe | cdce | cue | kue | mos | \
 					 rue | udav
 dev/usb/net/uhso.c		optional uhso
@@ -2062,6 +2058,7 @@ wpi.fw			optional wpifw					\
 dev/xe/if_xe.c			optional xe
 dev/xe/if_xe_pccard.c		optional xe pccard
 dev/xl/if_xl.c			optional xl pci
+dev/xl/xlphy.c			optional xl pci
 fs/coda/coda_fbsd.c		optional vcoda
 fs/coda/coda_psdev.c		optional vcoda
 fs/coda/coda_subr.c		optional vcoda

Copied: stable/9/sys/dev/fxp/inphy.c (from r226154, head/sys/dev/fxp/inphy.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/9/sys/dev/fxp/inphy.c	Sun Nov  6 17:23:49 2011	(r227229, copy of r226154, head/sys/dev/fxp/inphy.c)
@@ -0,0 +1,197 @@
+/*-
+ * Copyright (c) 2001 Jonathan Lemon
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * driver for Intel 82553 and 82555 PHYs
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/socket.h>
+#include <sys/bus.h>
+
+#include <net/if.h>
+#include <net/if_media.h>
+
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+#include "miidevs.h"
+
+#include <dev/fxp/inphyreg.h>
+
+#include "miibus_if.h"
+
+static int 	inphy_probe(device_t dev);
+static int 	inphy_attach(device_t dev);
+
+static device_method_t inphy_methods[] = {
+	/* device interface */
+	DEVMETHOD(device_probe,		inphy_probe),
+	DEVMETHOD(device_attach,	inphy_attach),
+	DEVMETHOD(device_detach,	mii_phy_detach),
+	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
+	{ 0, 0 }
+};
+
+static devclass_t inphy_devclass;
+
+static driver_t inphy_driver = {
+	"inphy",
+	inphy_methods,
+	sizeof(struct mii_softc)
+};
+
+DRIVER_MODULE(inphy, miibus, inphy_driver, inphy_devclass, 0, 0);
+
+static int	inphy_service(struct mii_softc *, struct mii_data *, int);
+static void	inphy_status(struct mii_softc *);
+static void	inphy_reset(struct mii_softc *);
+
+static const struct mii_phydesc inphys[] = {
+	MII_PHY_DESC(xxINTEL, I82553),
+	MII_PHY_DESC(yyINTEL, I82553),
+	MII_PHY_DESC(yyINTEL, I82555),
+	MII_PHY_DESC(yyINTEL, I82562EM),
+	MII_PHY_DESC(yyINTEL, I82562ET),
+	MII_PHY_END
+};
+
+static const struct mii_phy_funcs inphy_funcs = {
+	inphy_service,
+	inphy_status,
+	inphy_reset
+};
+
+static int
+inphy_probe(device_t dev)
+{
+
+	return (mii_phy_dev_probe(dev, inphys, BUS_PROBE_DEFAULT));
+}
+
+static int
+inphy_attach(device_t dev)
+{
+
+	mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &inphy_funcs, 1);
+	return (0);
+}
+
+static int
+inphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
+{
+
+	switch (cmd) {
+	case MII_POLLSTAT:
+		break;
+
+	case MII_MEDIACHG:
+		/*
+		 * If the interface is not up, don't do anything.
+		 */
+		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
+			break;
+
+		mii_phy_setmedia(sc);
+		break;
+
+	case MII_TICK:
+		if (mii_phy_tick(sc) == EJUSTRETURN)
+			return (0);
+		break;
+	}
+
+	/* Update the media status. */
+	PHY_STATUS(sc);
+
+	/* Callback if something changed. */
+	mii_phy_update(sc, cmd);
+	return (0);
+}
+
+static void
+inphy_status(struct mii_softc *sc)
+{
+	struct mii_data *mii = sc->mii_pdata;
+	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
+	int bmsr, bmcr, scr;
+
+	mii->mii_media_status = IFM_AVALID;
+	mii->mii_media_active = IFM_ETHER;
+
+	bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
+	if (bmsr & BMSR_LINK)
+		mii->mii_media_status |= IFM_ACTIVE;
+
+	bmcr = PHY_READ(sc, MII_BMCR);
+	if (bmcr & BMCR_ISO) {
+		mii->mii_media_active |= IFM_NONE;
+		mii->mii_media_status = 0;
+		return;
+	}
+
+	if (bmcr & BMCR_LOOP)
+		mii->mii_media_active |= IFM_LOOP;
+
+	if (bmcr & BMCR_AUTOEN) {
+		if ((bmsr & BMSR_ACOMP) == 0) {
+			mii->mii_media_active |= IFM_NONE;
+			return;
+		}
+
+		scr = PHY_READ(sc, MII_INPHY_SCR);
+		if (scr & SCR_S100)
+			mii->mii_media_active |= IFM_100_TX;
+		else
+			mii->mii_media_active |= IFM_10_T;
+		if (scr & SCR_FDX)
+			mii->mii_media_active |=
+			    IFM_FDX | mii_phy_flowstatus(sc);
+		else
+			mii->mii_media_active |= IFM_HDX;
+	} else
+		mii->mii_media_active = ife->ifm_media;
+}
+
+static void
+inphy_reset(struct mii_softc *sc)
+{
+
+	mii_phy_reset(sc);
+
+	/* Ensure Bay flow control is disabled. */
+	PHY_WRITE(sc, MII_INPHY_SCR,
+	    PHY_READ(sc, MII_INPHY_SCR) & ~SCR_FLOWCTL);
+}

Copied: stable/9/sys/dev/fxp/inphyreg.h (from r226154, head/sys/dev/fxp/inphyreg.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/9/sys/dev/fxp/inphyreg.h	Sun Nov  6 17:23:49 2011	(r227229, copy of r226154, head/sys/dev/fxp/inphyreg.h)
@@ -0,0 +1,40 @@
+/*-
+ * Copyright (c) 2001 Jonathan Lemon
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	$FreeBSD$
+ */
+
+#ifndef _INPHYREG_H
+#define	_INPHYREG_H
+
+#define	MII_INPHY_SCR		0x10	/* status and control register */
+#define	SCR_FLOWCTL		0x8000
+#define	SCR_S100		0x0002	/* autonegotiated speed */
+#define	SCR_FDX			0x0001	/* autonegotiated duplex */
+
+#endif

Copied: stable/9/sys/dev/usb/net/ruephy.c (from r226154, head/sys/dev/usb/net/ruephy.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/9/sys/dev/usb/net/ruephy.c	Sun Nov  6 17:23:49 2011	(r227229, copy of r226154, head/sys/dev/usb/net/ruephy.c)
@@ -0,0 +1,232 @@
+/*-
+ * Copyright (c) 2001-2003, Shunsuke Akiyama <akiyama@FreeBSD.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * driver for RealTek RTL8150 internal PHY
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
+#include <sys/socket.h>
+#include <sys/bus.h>
+
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <net/if_media.h>
+
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+#include "miidevs.h"
+
+#include <dev/usb/net/ruephyreg.h>
+
+#include "miibus_if.h"
+
+static int ruephy_probe(device_t);
+static int ruephy_attach(device_t);
+
+static device_method_t ruephy_methods[] = {
+	/* device interface */
+	DEVMETHOD(device_probe,		ruephy_probe),
+	DEVMETHOD(device_attach,	ruephy_attach),
+	DEVMETHOD(device_detach,	mii_phy_detach),
+	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
+	{ 0, 0 }
+};
+
+static devclass_t ruephy_devclass;
+
+static driver_t ruephy_driver = {
+	"ruephy",
+	ruephy_methods,
+	sizeof(struct mii_softc)
+};
+
+DRIVER_MODULE(ruephy, miibus, ruephy_driver, ruephy_devclass, 0, 0);
+
+static int ruephy_service(struct mii_softc *, struct mii_data *, int);
+static void ruephy_reset(struct mii_softc *);
+static void ruephy_status(struct mii_softc *);
+
+/*
+ * The RealTek RTL8150 internal PHY doesn't have vendor/device ID
+ * registers; rue(4) fakes up a return value of all zeros.
+ */
+static const struct mii_phydesc ruephys[] = {
+	{ 0, 0, "RealTek RTL8150 internal media interface" },
+	MII_PHY_END
+};
+
+static const struct mii_phy_funcs ruephy_funcs = {
+	ruephy_service,
+	ruephy_status,
+	ruephy_reset
+};
+
+static int
+ruephy_probe(device_t dev)
+{
+
+	if (strcmp(device_get_name(device_get_parent(device_get_parent(dev))),
+	    "rue") == 0)
+		return (mii_phy_dev_probe(dev, ruephys, BUS_PROBE_DEFAULT));
+	return (ENXIO);
+}
+
+static int
+ruephy_attach(device_t dev)
+{
+
+	mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
+	    &ruephy_funcs, 1);
+	return (0);
+}
+
+static int
+ruephy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
+{
+	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
+	int reg;
+
+	switch (cmd) {
+	case MII_POLLSTAT:
+		break;
+
+	case MII_MEDIACHG:
+		/*
+		 * If the interface is not up, don't do anything.
+		 */
+		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
+			break;
+
+		mii_phy_setmedia(sc);
+		break;
+
+	case MII_TICK:
+		/*
+		 * Is the interface even up?
+		 */
+		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
+			return (0);
+
+		/*
+		 * Only used for autonegotiation.
+		 */
+		if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
+			break;
+
+		/*
+		 * Check to see if we have link.  If we do, we don't
+		 * need to restart the autonegotiation process.  Read
+		 * the MSR twice in case it's latched.
+		 */
+		reg = PHY_READ(sc, RUEPHY_MII_MSR) |
+		    PHY_READ(sc, RUEPHY_MII_MSR);
+		if (reg & RUEPHY_MSR_LINK)
+			break;
+
+		/* Only retry autonegotiation every mii_anegticks seconds. */
+		if (sc->mii_ticks <= sc->mii_anegticks)
+			break;
+
+		sc->mii_ticks = 0;
+		PHY_RESET(sc);
+		if (mii_phy_auto(sc) == EJUSTRETURN)
+			return (0);
+		break;
+	}
+
+	/* Update the media status. */
+	PHY_STATUS(sc);
+
+	/* Callback if something changed. */
+	mii_phy_update(sc, cmd);
+
+	return (0);
+}
+
+static void
+ruephy_reset(struct mii_softc *sc)
+{
+
+	mii_phy_reset(sc);
+
+	/*
+	 * XXX RealTek RTL8150 PHY doesn't set the BMCR properly after
+	 * XXX reset, which breaks autonegotiation.
+	 */
+	PHY_WRITE(sc, MII_BMCR, (BMCR_S100 | BMCR_AUTOEN | BMCR_FDX));
+}
+
+static void
+ruephy_status(struct mii_softc *phy)
+{
+	struct mii_data *mii = phy->mii_pdata;
+	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
+	int bmsr, bmcr, msr;
+
+	mii->mii_media_status = IFM_AVALID;
+	mii->mii_media_active = IFM_ETHER;
+
+	msr = PHY_READ(phy, RUEPHY_MII_MSR) | PHY_READ(phy, RUEPHY_MII_MSR);
+	if (msr & RUEPHY_MSR_LINK)
+		mii->mii_media_status |= IFM_ACTIVE;
+
+	bmcr = PHY_READ(phy, MII_BMCR);
+	if (bmcr & BMCR_ISO) {
+		mii->mii_media_active |= IFM_NONE;
+		mii->mii_media_status = 0;
+		return;
+	}
+
+	bmsr = PHY_READ(phy, MII_BMSR) | PHY_READ(phy, MII_BMSR);
+	if (bmcr & BMCR_AUTOEN) {
+		if ((bmsr & BMSR_ACOMP) == 0) {
+			/* Erg, still trying, I guess... */
+			mii->mii_media_active |= IFM_NONE;
+			return;
+		}
+
+		if (msr & RUEPHY_MSR_SPEED100)
+			mii->mii_media_active |= IFM_100_TX;
+		else
+			mii->mii_media_active |= IFM_10_T;
+
+		if (msr & RUEPHY_MSR_DUPLEX)
+			mii->mii_media_active |=
+			    IFM_FDX | mii_phy_flowstatus(phy);
+		else
+			mii->mii_media_active |= IFM_HDX;
+	} else
+		mii->mii_media_active = ife->ifm_media;
+}

Copied: stable/9/sys/dev/usb/net/ruephyreg.h (from r226154, head/sys/dev/usb/net/ruephyreg.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/9/sys/dev/usb/net/ruephyreg.h	Sun Nov  6 17:23:49 2011	(r227229, copy of r226154, head/sys/dev/usb/net/ruephyreg.h)
@@ -0,0 +1,38 @@
+/*-
+ * Copyright (c) 2001-2003, Shunsuke Akiyama <akiyama@FreeBSD.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _RUEPHYREG_H_
+#define	_RUEPHYREG_H_
+
+#define	RUEPHY_MII_MSR		0x0137	/* B, R/W */
+#define	RUEPHY_MSR_RXFCE	0x40
+#define	RUEPHY_MSR_DUPLEX	0x10
+#define	RUEPHY_MSR_SPEED100	0x08
+#define	RUEPHY_MSR_LINK		0x04
+
+#endif	/* _RUEPHYREG_H_ */

Copied: stable/9/sys/dev/xl/xlphy.c (from r226154, head/sys/dev/xl/xlphy.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/9/sys/dev/xl/xlphy.c	Sun Nov  6 17:23:49 2011	(r227229, copy of r226154, head/sys/dev/xl/xlphy.c)
@@ -0,0 +1,197 @@
+/*	$NetBSD: exphy.c,v 1.16 1999/04/23 04:24:32 thorpej Exp $	*/
+
+/*-
+ * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center, and by Frank van der Linden.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*-
+ * Copyright (c) 1997 Manuel Bouyer.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * driver for 3Com internal PHYs
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/module.h>
+#include <sys/bus.h>
+
+#include <net/if.h>
+#include <net/if_media.h>
+
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+#include "miidevs.h"
+
+#include "miibus_if.h"
+
+static int xlphy_probe(device_t);
+static int xlphy_attach(device_t);
+
+static device_method_t xlphy_methods[] = {
+	/* device interface */
+	DEVMETHOD(device_probe,		xlphy_probe),
+	DEVMETHOD(device_attach,	xlphy_attach),
+	DEVMETHOD(device_detach,	mii_phy_detach),
+	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
+	{ 0, 0 }
+};
+
+static devclass_t xlphy_devclass;
+
+static driver_t xlphy_driver = {
+	"xlphy",
+	xlphy_methods,
+	sizeof(struct mii_softc)
+};
+
+DRIVER_MODULE(xlphy, miibus, xlphy_driver, xlphy_devclass, 0, 0);
+
+static int	xlphy_service(struct mii_softc *, struct mii_data *, int);
+static void	xlphy_reset(struct mii_softc *);
+
+/*
+ * Some 3Com internal PHYs report zero for OUI and model, others use
+ * actual values.
+ * Note that the 3Com internal PHYs having OUI 0x105a and model 0 are
+ * handled fine by ukphy(4); they can be isolated and don't require
+ * special treatment after reset.
+ */
+static const struct mii_phydesc xlphys[] = {
+	{ 0, 0, "3Com internal media interface" },
+	MII_PHY_DESC(xxBROADCOM, 3C905C),
+	MII_PHY_END
+};
+
+static const struct mii_phy_funcs xlphy_funcs = {
+	xlphy_service,
+	ukphy_status,
+	xlphy_reset
+};
+
+static int
+xlphy_probe(device_t dev)
+{
+
+	if (strcmp(device_get_name(device_get_parent(device_get_parent(dev))),
+	    "xl") == 0)
+		return (mii_phy_dev_probe(dev, xlphys, BUS_PROBE_DEFAULT));
+	return (ENXIO);
+}
+
+static int
+xlphy_attach(device_t dev)
+{
+
+	/*
+	 * The 3Com PHY can never be isolated.
+	 */
+	mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
+	    &xlphy_funcs, 1);
+	return (0);
+}
+
+static int
+xlphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
+{
+
+	switch (cmd) {
+	case MII_POLLSTAT:
+		break;
+
+	case MII_MEDIACHG:
+		/*
+		 * If the interface is not up, don't do anything.
+		 */
+		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
+			break;
+
+		mii_phy_setmedia(sc);
+		break;
+
+	case MII_TICK:
+		/*
+		 * Is the interface even up?
+		 */
+		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
+			return (0);
+
+		/*
+		 * The 3Com PHY's autonegotiation doesn't need to be
+		 * kicked; it continues in the background.
+		 */
+		break;
+	}
+
+	/* Update the media status. */
+	PHY_STATUS(sc);
+
+	/* Callback if something changed. */
+	mii_phy_update(sc, cmd);
+	return (0);
+}
+
+static void
+xlphy_reset(struct mii_softc *sc)
+{
+
+	mii_phy_reset(sc);
+
+	/*
+	 * XXX 3Com PHY doesn't set the BMCR properly after
+	 * XXX reset, which breaks autonegotiation.
+	 */
+	PHY_WRITE(sc, MII_BMCR, BMCR_S100|BMCR_AUTOEN|BMCR_FDX);
+}

Modified: stable/9/sys/modules/fxp/Makefile
==============================================================================
--- stable/9/sys/modules/fxp/Makefile	Sun Nov  6 17:20:44 2011	(r227228)
+++ stable/9/sys/modules/fxp/Makefile	Sun Nov  6 17:23:49 2011	(r227229)
@@ -3,6 +3,6 @@
 .PATH: ${.CURDIR}/../../dev/fxp
 
 KMOD=	if_fxp
-SRCS=	if_fxp.c device_if.h bus_if.h pci_if.h miibus_if.h
+SRCS=	device_if.h bus_if.h if_fxp.c inphy.c miibus_if.h miidevs.h pci_if.h
 
 .include <bsd.kmod.mk>

Modified: stable/9/sys/modules/mii/Makefile
==============================================================================
--- stable/9/sys/modules/mii/Makefile	Sun Nov  6 17:20:44 2011	(r227228)
+++ stable/9/sys/modules/mii/Makefile	Sun Nov  6 17:23:49 2011	(r227229)
@@ -5,10 +5,10 @@
 KMOD=	miibus
 SRCS=	acphy.c amphy.c atphy.c axphy.c bmtphy.c brgphy.c bus_if.h
 SRCS+=	ciphy.c device_if.h
-SRCS+=	e1000phy.c exphy.c gentbi.c icsphy.c inphy.c ip1000phy.c jmphy.c
+SRCS+=	e1000phy.c gentbi.c icsphy.c ip1000phy.c jmphy.c
 SRCS+=	lxtphy.c miibus_if.c miibus_if.h mii.c miidevs.h mii_physubr.c
 SRCS+=	mlphy.c nsgphy.c nsphy.c nsphyter.c pci_if.h pnaphy.c qsphy.c
-SRCS+=	rdcphy.c rgephy.c rlphy.c ruephy.c tdkphy.c tlphy.c truephy.c
+SRCS+=	rdcphy.c rgephy.c rlphy.c tdkphy.c tlphy.c truephy.c
 SRCS+=	ukphy.c ukphy_subr.c
 SRCS+=	xmphy.c
 

Modified: stable/9/sys/modules/usb/rue/Makefile
==============================================================================
--- stable/9/sys/modules/usb/rue/Makefile	Sun Nov  6 17:20:44 2011	(r227228)
+++ stable/9/sys/modules/usb/rue/Makefile	Sun Nov  6 17:23:49 2011	(r227229)
@@ -30,8 +30,7 @@ S=     ${.CURDIR}/../../..
 .PATH: $S/dev/usb/net
 
 KMOD=	if_rue
-SRCS=	opt_bus.h opt_usb.h device_if.h bus_if.h usb_if.h usbdevs.h \
-	miibus_if.h opt_inet.h \
-	if_rue.c
+SRCS=	bus_if.h device_if.h miibus_if.h miidevs.h if_rue.c opt_bus.h
+SRCS+=	opt_inet.h opt_usb.h ruephy.c usb_if.h usbdevs.h
 
 .include <bsd.kmod.mk>

Modified: stable/9/sys/modules/xl/Makefile
==============================================================================
--- stable/9/sys/modules/xl/Makefile	Sun Nov  6 17:20:44 2011	(r227228)
+++ stable/9/sys/modules/xl/Makefile	Sun Nov  6 17:23:49 2011	(r227229)
@@ -3,7 +3,6 @@
 .PATH: ${.CURDIR}/../../dev/xl
 
 KMOD=	if_xl
-SRCS=	if_xl.c device_if.h bus_if.h pci_if.h
-SRCS+=	miibus_if.h
+SRCS=	bus_if.h device_if.h if_xl.c miibus_if.h miidevs.h pci_if.h xlphy.c
 
 .include <bsd.kmod.mk>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201111061723.pA6HNntX032551>