[Zrouter-src-freebsd] ZRouter.org: push to FreeBSD HEAD tree

zrouter-src-freebsd at zrouter.org zrouter-src-freebsd at zrouter.org
Tue Jan 10 00:53:40 UTC 2012


details:   http://zrouter.org/hg/FreeBSD/head//rev/bc9ce31dd25a
changeset: 266:bc9ce31dd25a
user:      ray at terran.dlink.ua
date:      Tue Jan 10 02:53:33 2012 +0200
description:
switch framework update

diffstat:

 head/sys/dev/switch/floatphy.c      |  366 ++++++++++++++++++++++++++++++++++++
 head/sys/dev/switch/switch.c        |   47 +++-
 head/sys/dev/switch/switch_iicbus.c |    7 +-
 head/sys/dev/switch/switch_mii.c    |  158 +-------------
 head/sys/dev/switch/switchpub_if.m  |   66 ++++++
 head/sys/dev/switch/switchvar.h     |   13 +-
 6 files changed, 504 insertions(+), 153 deletions(-)

diffs (825 lines):

diff -r 4e8fd22d4a56 -r bc9ce31dd25a head/sys/dev/switch/floatphy.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/dev/switch/floatphy.c	Tue Jan 10 02:53:33 2012 +0200
@@ -0,0 +1,366 @@
+/*-
+ * Copyright (c) 2011, Aleksandr Rybalko
+ * 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 unmodified, 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$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/socket.h>
+#include <sys/bus.h>
+
+/* Required for struct switch_softc */
+#include <machine/bus.h>
+
+#include <net/if.h>
+#include <net/if_media.h>
+
+/* MII interface */
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+#include "miibus_if.h"
+#include "miidevs.h"
+
+/* Switch interface */
+#include <dev/switch/switchvar.h>
+#include "switch_if.h"
+#include "switchb_if.h"
+#include "switchpub_if.h"
+
+/*
+ * Float PHY satellite driver, used for devices that have PHY but can't
+ * communicate directly to it
+ */
+
+static int 	floatphy_probe(device_t dev);
+static int 	floatphy_attach(device_t dev);
+
+struct floatphy_softc {
+	struct mii_softc miisc;
+	device_t	dev;
+	device_t	master;
+	const char	*master_name;
+	int		master_unit;
+	uint32_t	master_phys;
+	uint32_t	flags;
+	int		speed; /* TODO: Maybe better to save media type? */
+};
+
+static device_method_t floatphy_methods[] = {
+	/* device interface */
+	DEVMETHOD(device_probe,		floatphy_probe),
+	DEVMETHOD(device_attach,	floatphy_attach),
+	DEVMETHOD(device_detach,	mii_phy_detach),
+	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
+	{ 0, 0 }
+};
+
+static devclass_t floatphy_devclass;
+
+static driver_t floatphy_driver = {
+	"floatphy",
+	floatphy_methods,
+	sizeof(struct floatphy_softc)
+};
+
+DRIVER_MODULE(floatphy, miibus, floatphy_driver, floatphy_devclass, 0, 0);
+DRIVER_MODULE(floatphy, mii, floatphy_driver, floatphy_devclass, 0, 0);
+
+static int	floatphy_service(struct mii_softc *, struct mii_data *, int);
+static void	floatphy_status(struct mii_softc *);
+
+static const struct mii_phy_funcs floatphy_funcs = {
+	floatphy_service,
+	floatphy_status,
+	mii_phy_reset
+};
+
+static void
+floatphy_speedtocap(struct floatphy_softc *sc)
+{
+	struct mii_softc *miisc;
+
+	miisc = (struct mii_softc *)sc;
+	/* limit capability to hinted speed value */
+	switch (sc->speed) {
+	case 1000:
+		miisc->mii_capabilities = BMSR_EXTCAP;
+		miisc->mii_extcapabilities = EXTSR_1000TFDX;
+		break;
+	case 100:
+		miisc->mii_capabilities = BMSR_100TXFDX;
+		miisc->mii_extcapabilities = 0;
+		break;
+	case 10:
+		miisc->mii_capabilities = BMSR_10TFDX;
+		miisc->mii_extcapabilities = 0;
+		break;
+	/* Do nothing if not hinted (0 value) */
+	}
+}
+
+static int
+floatphy_probe(device_t dev)
+{
+
+	return (BUS_PROBE_NOWILDCARD);
+}
+
+static int
+floatphy_attach(device_t dev)
+{
+	struct floatphy_softc *sc;
+	struct mii_softc *miisc;
+	const char *devname;
+	int devunit;
+
+	sc = device_get_softc(dev);
+	sc->dev = dev;
+	miisc = (struct mii_softc *)sc;
+	mii_phy_dev_attach(dev, 0, &floatphy_funcs, 0);
+
+	/*
+	 * hint.floatphy.0.master="ar8x16_switch0"
+	 * hint.floatphy.0.master_phys=0x0000000f # Sense PHY0-PHY4
+	 * hint.floatphy.0.flags=0x00000001
+	 * hint.floatphy.0.speed=1000
+	 * Flags:
+	 *	0x00000000	Notify parent about link up if any of PHYs in
+	 *		master_phys mask stay in link.
+	 *	0x00000001	Same, but if all in link.
+	 *	0x00000002	???
+	 *	0x00000003	???
+	 *	0x00000004	use hint .speed always, otherwise if master
+	 *		is found, use master info.
+	 *	0x00000008	???
+	 */
+	devname = device_get_name(dev);
+	devunit = device_get_unit(dev);
+	sc->master_name = "switch";
+	/* master_unit, master_phys, flags, speed is 0 */
+	resource_string_value(devname, devunit, "master", &sc->master_name);
+	resource_int_value(devname, devunit, "master_unit", &sc->master_unit);
+	resource_int_value(devname, devunit, "master_phys", &sc->master_phys);
+	resource_int_value(devname, devunit,"flags", &sc->flags);
+	resource_int_value(devname, devunit,"speed", &sc->speed);
+
+	miisc->mii_capabilities = BMSR_100TXFDX | BMSR_100TXHDX |
+	    BMSR_EXTCAP | BMSR_ANEG;
+	miisc->mii_extcapabilities = EXTSR_1000TFDX | EXTSR_1000THDX |
+	    EXTSR_1000XFDX | EXTSR_1000XHDX;
+
+	floatphy_speedtocap(sc);
+
+	device_printf(dev, " ");
+	mii_phy_add_media(miisc);
+	printf("\n");
+
+	MIIBUS_MEDIAINIT(miisc->mii_dev);
+	return (0);
+}
+
+static int
+floatphy_find_master(struct floatphy_softc *sc)
+{
+	device_t switchdev;
+
+	if (sc->master)
+		return (0);
+
+	if (sc->master_name) {
+		switchdev = devclass_get_device(
+		    devclass_find(sc->master_name), sc->master_unit);
+		if (switchdev) {
+			device_printf(sc->dev, "found master %s\n",
+			    device_get_nameunit(switchdev));
+			sc->master = switchdev;
+			return (0);
+		}
+		return (ENOENT);
+	}
+	return (ENXIO);
+}
+
+#define	BMSR_MEDIAMASK100	(BMSR_100T4|BMSR_100TXFDX|BMSR_100TXHDX| \
+				    BMSR_100T2FDX|BMSR_100T2HDX)
+#define	BMSR_MEDIAMASK10	(BMSR_10TFDX|BMSR_10THDX)
+
+#define	SWITCH_PHY_REG(_p, _r)	(0x40000000 + ((_p) << 8) + (_r))
+
+static int
+floatphy_query_link(struct floatphy_softc *sc)
+{
+	uint32_t reg, value, out;
+	int error, p;
+
+	/* TODO: Check if we lost master */
+
+	out = 0;
+	/* If no master, always return linked */
+	if (floatphy_find_master(sc) != 0)
+		return (1);
+
+	/* TODO: Ask PHY driver and return here */
+	for (p = 0; p < 32; p ++) {
+
+		if (!(sc->master_phys & (1 << p)))
+			/* Skip PHY's which not in mask */
+			continue;
+
+		reg = SWITCH_PHY_REG(p, MII_BMSR);
+		error = SWITCHPUB_GET_REG(sc->master, reg,
+		    &value);
+		/* TODO: handle error */
+
+		if ((sc->flags & 0x00000004) == 0) {
+			/* We can update speed */
+			if (value & BMSR_MEDIAMASK10)
+				sc->speed = 10;
+			if (value & BMSR_MEDIAMASK100)
+				sc->speed = 100;
+			if (value & BMSR_EXTCAP)
+				/* XXX: hope EXTCAP reg will not have 10G */
+				sc->speed = 1000;
+		}
+		switch (sc->flags & 0x00000003) {
+		case 0:	/* If any ports linkup */
+			if (value & BMSR_LINK)
+				/* First linked sutisfy */
+				return (1);
+			break;
+		case 1:	/* If all ports linkup */
+			out &= (value & BMSR_LINK);
+			break;
+		}
+	}
+
+	if (((sc->flags & 0x00000003) == 1) && out)
+		return (1);
+
+	return (0);
+}
+
+static int
+floatphy_service(struct mii_softc *miisc, struct mii_data *mii, int cmd)
+{
+	struct ifmedia_entry *ife;
+	struct floatphy_softc *sc;
+	uint32_t media;
+	int link;
+
+	ife = mii->mii_media.ifm_cur;
+	sc = (struct floatphy_softc *)miisc;
+
+	switch (cmd) {
+	case MII_POLLSTAT:
+		break;
+	case MII_MEDIACHG:
+		if (sc->flags & 0x00000004) {
+			/* XXX */
+			printf("Speed locked, can't do MII_MEDIACHG\n");
+			return (0);
+		}
+
+		link = (floatphy_query_link(sc) == 1) ? IFM_ACTIVE : 0;
+		/* XXX: get FDX link status */
+		switch (sc->speed) {
+		case 1000:
+			media = IFM_1000_T | IFM_FDX;
+			break;
+		case 100:
+			media = IFM_100_TX | IFM_FDX;
+			break;
+		case 10:
+			media = IFM_10_T | IFM_FDX;
+			break;
+		default:
+			media = IFM_100_TX | IFM_FDX;
+			break;
+		}
+
+		switch (IFM_SUBTYPE(ife->ifm_media)) {
+		case IFM_AUTO:
+			mii->mii_media_status = IFM_AVALID | link;
+			mii->mii_media_active = IFM_ETHER | media;
+			break;
+		case IFM_NONE:
+			mii->mii_media_status = IFM_AVALID;
+			mii->mii_media_active = IFM_ETHER | media;
+			break;
+		default:
+			mii->mii_media_status = IFM_AVALID | link;
+			mii->mii_media_active = IFM_ETHER | media;
+			break;
+		}
+		break;
+
+	case MII_TICK:
+		if (mii_phy_tick(miisc) == EJUSTRETURN)
+			return (0);
+		break;
+	}
+
+	/* Update the media status. */
+	PHY_STATUS(miisc);
+
+	/* Callback if something changed. */
+	mii_phy_update(miisc, cmd);
+	return (0);
+}
+
+static void
+floatphy_status(struct mii_softc *miisc)
+{
+	struct floatphy_softc *sc;
+	struct mii_data *mii;
+	struct ifmedia_entry *ife;
+
+	sc = (struct floatphy_softc *)miisc;
+	mii = miisc->mii_pdata;
+	ife = mii->mii_media.ifm_cur;
+	mii->mii_media_status = IFM_AVALID | IFM_ACTIVE;
+
+	if (!(sc->flags & 0x04)) {
+		mii->mii_media_active = ife->ifm_media;
+		if (miisc->mii_capabilities & BMSR_MEDIAMASK10) {
+			mii->mii_media_active = IFM_ETHER | IFM_10_T | IFM_FDX;
+		}
+		else if (miisc->mii_capabilities & BMSR_MEDIAMASK100) {
+			mii->mii_media_active = IFM_ETHER | IFM_100_TX | IFM_FDX;
+		}
+		else if ((miisc->mii_capabilities & BMSR_EXTCAP) &&
+			miisc->mii_extcapabilities & EXTSR_MEDIAMASK) {
+			mii->mii_media_active = IFM_ETHER | IFM_1000_T | IFM_FDX;
+		}
+//		mii_phy_update(sc, MII_MEDIACHG);
+//		PHY_STATUS(sc);
+		return;
+	}
+
+	mii->mii_media_active = ife->ifm_media;
+}
diff -r 4e8fd22d4a56 -r bc9ce31dd25a head/sys/dev/switch/switch.c
--- a/head/sys/dev/switch/switch.c	Fri Jan 06 19:51:58 2012 +0200
+++ b/head/sys/dev/switch/switch.c	Tue Jan 10 02:53:33 2012 +0200
@@ -47,7 +47,7 @@
 #include "switch_if.h"
 #include "switchb_if.h"
 
-#define CREATE_CHILD_MDIO_BUS
+//#define CREATE_CHILD_MDIO_BUS
 #ifdef CREATE_CHILD_MDIO_BUS
 #include <sys/socket.h>
 #include <net/if.h>
@@ -60,9 +60,6 @@
 #include <dev/mii/mii.h>
 #include <dev/mii/miivar.h>
 
-//MODULE_DEPEND(arge, ether, 1, 1, 1);
-//MODULE_DEPEND(arge, miibus, 1, 1, 1);
-
 #include "miibus_if.h"
 #endif
 
@@ -70,12 +67,13 @@
 static	d_close_t	switch_close;
 static	d_ioctl_t	switch_ioctl;
 
-static int switch_config_sub(struct switch_softc *, struct switch_config *);
-static int switch_caps_sub(struct switch_softc *, struct switch_caps *);
-static int switch_getreg_sub(struct switch_softc *, struct switch_reg *);
-static int switch_setreg_sub(struct switch_softc *, struct switch_reg *);
-static int vlan_config_sub(struct switch_softc *, struct vlan_config *);
-static int vlan_vlan_config_sub(struct switch_softc *,
+static int	switch_config_sub(struct switch_softc *,
+    struct switch_config *);
+static int	switch_caps_sub(struct switch_softc *, struct switch_caps *);
+static int	switch_getreg_sub(struct switch_softc *, struct switch_reg *);
+static int	switch_setreg_sub(struct switch_softc *, struct switch_reg *);
+static int	vlan_config_sub(struct switch_softc *, struct vlan_config *);
+static int	vlan_vlan_config_sub(struct switch_softc *,
     struct vlan_vlan_config *);
 
 static struct cdevsw switch_cdevsw = {
@@ -500,7 +498,9 @@
 switch_init(struct switch_softc *sc)
 {
 	char 	*var;
+#ifdef CREATE_CHILD_MDIO_BUS
 	int	error;
+#endif /* CREATE_CHILD_MDIO_BUS */
 
 	if (sc->child) {
 		device_printf(sc->sc_dev, "Only one child allowed\n");
@@ -592,4 +592,31 @@
 	return (0);
 }
 
+int
+switchpub_get_reg(device_t dev, uint32_t reg, uint32_t *value)
+{
+	struct switch_softc *sc;
+	int error;
 
+	sc = device_get_softc(dev);
+	SWITCH_LOCK(sc);
+	error = SWITCH_GET_REG(sc->child, reg, value);
+	SWITCH_UNLOCK(sc);
+
+	return (0);
+}
+
+int
+switchpub_set_reg(device_t dev, uint32_t reg, uint32_t *value)
+{
+	struct switch_softc *sc;
+	int error;
+
+	sc = device_get_softc(dev);
+	SWITCH_LOCK(sc);
+	error = SWITCH_SET_REG(sc->child, reg, value);
+	SWITCH_UNLOCK(sc);
+
+	return (error);
+}
+
diff -r 4e8fd22d4a56 -r bc9ce31dd25a head/sys/dev/switch/switch_iicbus.c
--- a/head/sys/dev/switch/switch_iicbus.c	Fri Jan 06 19:51:58 2012 +0200
+++ b/head/sys/dev/switch/switch_iicbus.c	Tue Jan 10 02:53:33 2012 +0200
@@ -66,6 +66,7 @@
 
 	sc->sc_dev = dev;
 
+
 	return (error);
 }
 
@@ -83,6 +84,6 @@
 };
 static devclass_t switch_i2c_devclass;
 
-DRIVER_MODULE(switch, iicbus, switch_i2c_driver, switch_i2c_devclass, 0, 0);
-MODULE_VERSION(switch, 1);
-MODULE_DEPEND(switch, iicbus, 1, 1, 1);
+DRIVER_MODULE(switch_iicbus, iicbus, switch_i2c_driver, switch_i2c_devclass, 0, 0);
+MODULE_VERSION(switch_iicbus, 1);
+MODULE_DEPEND(switch_iicbus, iicbus, 1, 1, 1);
diff -r 4e8fd22d4a56 -r bc9ce31dd25a head/sys/dev/switch/switch_mii.c
--- a/head/sys/dev/switch/switch_mii.c	Fri Jan 06 19:51:58 2012 +0200
+++ b/head/sys/dev/switch/switch_mii.c	Tue Jan 10 02:53:33 2012 +0200
@@ -50,13 +50,7 @@
 #include <dev/switch/switchvar.h>
 #include "switch_if.h"
 #include "switchb_if.h"
-
-struct switch_mii_softc {
-	struct mii_softc sc_mii;		/* generic PHY */
-	device_t sc_miidev;			/* generic PHY dev */
-	device_t sc_dev;
-	struct switch_softc sc_switch;		/* switch softc */
-};
+#include "switchpub_if.h"
 
 static int 	switch_mii_probe(device_t);
 static int 	switch_mii_attach(device_t);
@@ -74,10 +68,14 @@
 	DEVMETHOD(switchb_read4,	switch_mii_read4),
 	DEVMETHOD(switchb_write4,	switch_mii_write4),
 
+	/* switch public interface (used by floatphy) */
+	DEVMETHOD(switchpub_get_reg,	switchpub_get_reg),
+	DEVMETHOD(switchpub_set_reg,	switchpub_set_reg),
+
 	/* Child MDIO bus interface */
-	DEVMETHOD(miibus_readreg,	switch_miibus_readreg),
-	DEVMETHOD(miibus_writereg,	switch_miibus_writereg),
-	DEVMETHOD(miibus_statchg,	switch_miibus_statchg),
+//	DEVMETHOD(miibus_readreg,	switch_miibus_readreg),
+//	DEVMETHOD(miibus_writereg,	switch_miibus_writereg),
+//	DEVMETHOD(miibus_statchg,	switch_miibus_statchg),
 	{ 0, 0 }
 };
 
@@ -86,7 +84,7 @@
 static driver_t switch_mii_driver = {
 	"switch",
 	switch_mii_methods,
-	sizeof(struct switch_mii_softc)
+	sizeof(struct switch_softc)
 };
 
 DRIVER_MODULE(switch, miibus, switch_mii_driver, switch_mii_devclass, 0, 0);
@@ -113,8 +111,8 @@
 static int
 switch_mii_attach(device_t dev)
 {
-	struct mii_softc *sc;
-	struct switch_mii_softc *ssc;
+	struct mii_softc	*sc;
+	struct switch_softc	*ssc;
 	struct mii_attach_args	*ma;
 	struct mii_data		*mii;
 	int phymask, err;
@@ -159,11 +157,12 @@
 	mii_phy_add_media(sc);
 	printf("\n");
 
-	ssc->sc_switch.sc_dev = dev;
+	ssc->sc_dev = dev;
 	/* Satisfy all MDIO attached switch drivers */
-	ssc->sc_switch.phys = 0xffffffff;
-	SWITCH_LOCK_INIT(&ssc->sc_switch);
-	err = switch_init(&ssc->sc_switch);
+	ssc->phys = 0xffffffff;
+
+	SWITCH_LOCK_INIT(ssc);
+	err = switch_init(ssc);
 	if (err)
 		return (err);
 
@@ -176,7 +175,7 @@
 switch_mii_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
 {
 	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
-	struct switch_mii_softc *ssc = (struct switch_mii_softc *)sc;
+	struct switch_softc *ssc = (struct switch_softc *)sc;
 
 	switch (cmd) {
 	case MII_POLLSTAT:
@@ -225,7 +224,7 @@
 
 	case MII_TICK:
 		/* Call switch to do periodic work */
-		switch_tick(&ssc->sc_switch);
+		switch_tick(ssc);
 		break;
 	}
 
@@ -259,7 +258,7 @@
 static uint32_t
 switch_mii_read4(device_t dev, uint32_t r)
 {
-	struct switch_mii_softc *ssc;
+	struct switch_softc *ssc;
 	int phy, reg;
 
 	ssc = device_get_softc(dev);
@@ -272,7 +271,7 @@
 static void
 switch_mii_write4(device_t dev, uint32_t r, uint32_t val)
 {
-	struct switch_mii_softc *ssc;
+	struct switch_softc *ssc;
 	int phy, reg;
 
 	ssc = device_get_softc(dev);
@@ -282,120 +281,3 @@
 	MIIBUS_WRITEREG(ssc->sc_miidev, phy, reg, (val & 0xffff));
 }
 
-/*
- * Float PHY satellite driver, used for devices that have PHY but can't
- * communicate directly to it
- */
-
-static int 	floatphy_probe(device_t dev);
-static int 	floatphy_attach(device_t dev);
-
-static device_method_t floatphy_methods[] = {
-	/* device interface */
-	DEVMETHOD(device_probe,		floatphy_probe),
-	DEVMETHOD(device_attach,	floatphy_attach),
-	DEVMETHOD(device_detach,	mii_phy_detach),
-	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
-	{ 0, 0 }
-};
-
-static devclass_t floatphy_devclass;
-
-static driver_t floatphy_driver = {
-	"floatphy",
-	floatphy_methods,
-	sizeof(struct mii_softc)
-};
-
-DRIVER_MODULE(floatphy, miibus, floatphy_driver, floatphy_devclass, 0, 0);
-DRIVER_MODULE(floatphy, mii, floatphy_driver, floatphy_devclass, 0, 0);
-
-static int	floatphy_service(struct mii_softc *, struct mii_data *, int);
-static void	floatphy_status(struct mii_softc *);
-
-
-static const struct mii_phy_funcs floatphy_funcs = {
-	floatphy_service,
-	floatphy_status,
-	mii_phy_reset
-};
-
-static int
-floatphy_probe(device_t dev)
-{
-
-	return (BUS_PROBE_NOWILDCARD);
-}
-
-static int
-floatphy_attach(device_t dev)
-{
-	struct mii_softc *sc;
-
-	sc = device_get_softc(dev);
-	mii_phy_dev_attach(dev, 0, &floatphy_funcs, 0);
-	sc->mii_capabilities = BMSR_100TXFDX | BMSR_100TXHDX | BMSR_EXTCAP;
-	sc->mii_extcapabilities = EXTSR_1000TFDX | EXTSR_1000THDX |
-	    EXTSR_1000XFDX | EXTSR_1000XHDX;
-
-	device_printf(dev, " ");
-	mii_phy_add_media(sc);
-	printf("\n");
-
-	MIIBUS_MEDIAINIT(sc->mii_dev);
-	return (0);
-}
-
-static int
-floatphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
-{
-	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
-
-	switch (cmd) {
-	case MII_POLLSTAT:
-		break;
-	case MII_MEDIACHG:
-		switch (IFM_SUBTYPE(ife->ifm_media)) {
-		case IFM_AUTO:
-			mii->mii_media_status = IFM_AVALID | IFM_ACTIVE;
-			mii->mii_media_active = IFM_ETHER | IFM_1000_T |
-			    IFM_FDX;
-			break;
-		case IFM_NONE:
-			mii->mii_media_status = IFM_AVALID;
-			mii->mii_media_active = IFM_ETHER |
-			    IFM_SUBTYPE(ife->ifm_media) | IFM_FDX;
-			break;
-		default:
-			mii->mii_media_status = IFM_AVALID | IFM_ACTIVE;
-			mii->mii_media_active = IFM_ETHER |
-			    IFM_SUBTYPE(ife->ifm_media) |
-			    (ife->ifm_media & IFM_FDX)?IFM_FDX:IFM_HDX;
-			break;
-		}
-		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
-floatphy_status(struct mii_softc *sc)
-{
-	struct mii_data *mii = sc->mii_pdata;
-	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
-
-	mii->mii_media_status = IFM_AVALID | IFM_ACTIVE;
-	mii->mii_media_active = ife->ifm_media;
-}
-
diff -r 4e8fd22d4a56 -r bc9ce31dd25a head/sys/dev/switch/switchpub_if.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/dev/switch/switchpub_if.m	Tue Jan 10 02:53:33 2012 +0200
@@ -0,0 +1,66 @@
+#-
+# Copyright (c) 2010-2011 Aleksandr Rybalko <ray at ddteam.net>
+# 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$
+#
+
+#include <sys/bus.h>
+#include <machine/bus.h>
+#include <dev/switch/switchvar.h>
+
+INTERFACE switchpub;
+
+CODE {
+	static int
+	null_get_reg(device_t dev, uint32_t reg, uint32_t *value)
+	{
+		return (0);
+	}
+
+	static int
+	null_set_reg(device_t dev, uint32_t reg, uint32_t *value)
+	{
+		return (0);
+	}
+};
+
+#
+# Get switch register value
+#
+METHOD int get_reg {
+	device_t dev;
+	uint32_t reg;
+	uint32_t *value;
+} DEFAULT null_get_reg;
+
+#
+# Set switch register value, return old value
+#
+METHOD int set_reg {
+	device_t dev;
+	uint32_t reg;
+	uint32_t *value;
+} DEFAULT null_set_reg;
+
diff -r 4e8fd22d4a56 -r bc9ce31dd25a head/sys/dev/switch/switchvar.h
--- a/head/sys/dev/switch/switchvar.h	Fri Jan 06 19:51:58 2012 +0200
+++ b/head/sys/dev/switch/switchvar.h	Tue Jan 10 02:53:33 2012 +0200
@@ -33,6 +33,13 @@
 #include <sys/param.h>
 #include <sys/lock.h>
 #include <sys/mutex.h>
+#include <sys/socket.h>
+
+#include <net/if.h>
+#include <net/if_media.h>
+
+//#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
 
 /* Switch capability list */
 struct switch_capability {
@@ -54,7 +61,7 @@
 };
 
 struct switch_softc {
-
+	struct mii_softc	sc_mii;
 	struct mtx		sc_mtx;		/* bus mutex */
 	struct resource		*mem_res;
 	int			mem_rid;
@@ -69,6 +76,7 @@
 	void 			*sc_cookie;
 
 	device_t 		sc_dev;
+	device_t 		sc_miidev;
 	device_t 		child;
 	struct cdev 		*sc_cdev;
 	device_t    		child_miibus;
@@ -82,13 +90,14 @@
 int switch_init(struct switch_softc *sc);
 int switch_deinit(struct switch_softc *sc);
 int switch_tick(struct switch_softc *sc);
+int switchpub_get_reg(device_t dev, uint32_t reg, uint32_t *value);
+int switchpub_set_reg(device_t dev, uint32_t reg, uint32_t *value);
 
 /* Child MDIO access */
 int	switch_miibus_writereg(device_t dev, int phy, int reg, int value);
 int	switch_miibus_readreg(device_t dev, int phy, int reg);
 void	switch_miibus_statchg(device_t dev);
 
-
 #define	SWITCH_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
 #define	SWITCH_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
 #define	SWITCH_LOCK_INIT(_sc) \


More information about the Zrouter-src-freebsd mailing list