[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 22:13:16 UTC 2012
details: http://zrouter.org/hg/FreeBSD/head//rev/3c64dd8a60d3
changeset: 269:3c64dd8a60d3
user: ray at terran.dlink.ua
date: Tue Jan 10 15:44:39 2012 +0200
description:
One more step to make floatphy to work
diffstat:
head/sys/dev/switch/floatphy.c | 111 ++++++++++++++++++++++++++--------------
1 files changed, 72 insertions(+), 39 deletions(-)
diffs (201 lines):
diff -r c6ee3ad91edf -r 3c64dd8a60d3 head/sys/dev/switch/floatphy.c
--- a/head/sys/dev/switch/floatphy.c Tue Jan 10 14:26:35 2012 +0200
+++ b/head/sys/dev/switch/floatphy.c Tue Jan 10 15:44:39 2012 +0200
@@ -33,6 +33,7 @@
#include <sys/module.h>
#include <sys/socket.h>
#include <sys/bus.h>
+#include <sys/sysctl.h>
/* Required for struct switch_softc */
#include <machine/bus.h>
@@ -69,6 +70,7 @@
uint32_t master_phys;
uint32_t flags;
int speed; /* TODO: Maybe better to save media type? */
+ uint32_t debug;
};
static device_method_t floatphy_methods[] = {
@@ -124,6 +126,19 @@
}
}
+static void
+floatphy_sysctl(struct floatphy_softc *sc)
+{
+ struct sysctl_ctx_list *ctx;
+ struct sysctl_oid *tree;
+
+ ctx = device_get_sysctl_ctx(sc->dev);
+ tree = device_get_sysctl_tree(sc->dev);
+ SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
+ "debug", CTLFLAG_RW, &sc->debug, 0,
+ "enable watchdog debugging");
+}
+
static int
floatphy_probe(device_t dev)
{
@@ -175,6 +190,7 @@
EXTSR_1000XFDX | EXTSR_1000XHDX;
floatphy_speedtocap(sc);
+ floatphy_sysctl(sc);
device_printf(dev, " ");
mii_phy_add_media(miisc);
@@ -211,6 +227,9 @@
#define BMSR_MEDIAMASK10 (BMSR_10TFDX|BMSR_10THDX)
#define SWITCH_PHY_REG(_p, _r) (0x40000000 + ((_p) << 8) + (_r))
+#define FLOATPHY_DEBUG_PHYREG 0x00000001
+#define FLOATPHY_DEBUG_LINK 0x00000002
+#define FLOATPHY_DEBUG_SPEED 0x00000002
static int
floatphy_query_link(struct floatphy_softc *sc)
@@ -236,6 +255,13 @@
error = SWITCHPUB_GET_REG(sc->master, reg,
&value);
/* TODO: handle error */
+ if ((value & 0xffff) == 0xffff)
+ /* Isolated or NC PHY */
+ continue;
+
+ if (sc->debug & FLOATPHY_DEBUG_PHYREG)
+ device_printf(sc->dev, "DEBUG: PHY(%d) BMSR=%04x\n",
+ p, value);
if ((sc->flags & 0x00000004) == 0) {
/* We can update speed */
@@ -246,12 +272,21 @@
if (value & BMSR_EXTCAP)
/* XXX: hope EXTCAP reg will not have 10G */
sc->speed = 1000;
+
+ if (sc->debug & FLOATPHY_DEBUG_SPEED)
+ device_printf(sc->dev,
+ "DEBUG: PHY(%d) speed=%d\n",
+ p, sc->speed);
}
switch (sc->flags & 0x00000003) {
case 0: /* If any ports linkup */
- if (value & BMSR_LINK)
+ if (value & BMSR_LINK) {
/* First linked sutisfy */
+ if (sc->debug & FLOATPHY_DEBUG_LINK)
+ device_printf(sc->dev,
+ "DEBUG: PHY(%d) linkup\n", p);
return (1);
+ }
break;
case 1: /* If all ports linkup */
out &= (value & BMSR_LINK);
@@ -259,12 +294,36 @@
}
}
- if (((sc->flags & 0x00000003) == 1) && out)
+ if (((sc->flags & 0x00000003) == 1) && out) {
+ if (sc->debug & FLOATPHY_DEBUG_LINK)
+ device_printf(sc->dev, "DEBUG: ALL(0x%08x) linkup\n",
+ sc->master_phys);
return (1);
+ }
return (0);
}
+static uint32_t
+floatphy_speed_to_media(int speed, int fdx)
+{
+
+ switch (speed) {
+ case 1000:
+ return (IFM_1000_T | fdx);
+ break;
+ case 100:
+ return (IFM_100_TX | fdx);
+ break;
+ case 10:
+ return (IFM_10_T | fdx);
+ break;
+ default:
+ return (IFM_100_TX | fdx);
+ break;
+ }
+}
+
static int
floatphy_service(struct mii_softc *miisc, struct mii_data *mii, int cmd)
{
@@ -280,28 +339,9 @@
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;
- }
+ media = floatphy_speed_to_media(sc->speed, IFM_FDX);
switch (IFM_SUBTYPE(ife->ifm_media)) {
case IFM_AUTO:
@@ -339,28 +379,21 @@
struct floatphy_softc *sc;
struct mii_data *mii;
struct ifmedia_entry *ife;
+ uint32_t media;
+ int link;
sc = (struct floatphy_softc *)miisc;
mii = miisc->mii_pdata;
ife = mii->mii_media.ifm_cur;
- mii->mii_media_status = IFM_AVALID | IFM_ACTIVE;
+ link = (floatphy_query_link(sc) == 1) ? IFM_ACTIVE : 0;
+ media = floatphy_speed_to_media(sc->speed, IFM_FDX);
- if (!(sc->flags & 0x04)) {
+ mii->mii_media_status = IFM_AVALID | link;
+
+ if (sc->flags & 0x00000004) {
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;
+ } else {
+ mii->mii_media_active = IFM_ETHER | media;
+
}
-
- mii->mii_media_active = ife->ifm_media;
}
More information about the Zrouter-src-freebsd
mailing list