* [PATCH 1/5] miitool: change behaviour closer to linux' mii-tool
2013-12-25 7:50 [PATCH 0/5] miitool patches Antony Pavlov
@ 2013-12-25 7:50 ` Antony Pavlov
2014-01-06 8:52 ` Sascha Hauer
2013-12-25 7:50 ` [PATCH 2/5] miitool: add initial GbE support Antony Pavlov
` (3 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Antony Pavlov @ 2013-12-25 7:50 UTC (permalink / raw)
To: barebox
miitool without arguments will try to show status for all phys.
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
commands/miitool.c | 86 +++++++++++++++++++++++++---------------------
drivers/net/phy/mdio_bus.c | 10 +-----
include/linux/phy.h | 4 +--
3 files changed, 49 insertions(+), 51 deletions(-)
diff --git a/commands/miitool.c b/commands/miitool.c
index a00514d..7666e8a 100644
--- a/commands/miitool.c
+++ b/commands/miitool.c
@@ -36,24 +36,11 @@
#include <getopt.h>
#include <linux/stat.h>
#include <xfuncs.h>
+#include <net.h>
#include <linux/mii.h>
#include <linux/phy.h>
+#include <linux/err.h>
-static u16 mdio_read(int fd, int offset)
-{
- int ret;
- u16 buf;
-
- ret = lseek(fd, offset << 1, SEEK_SET);
- if (ret < 0)
- return 0;
-
- ret = read(fd, &buf, sizeof(u16));
- if (ret < 0)
- return 0;
-
- return buf;
-}
/* Table of known MII's */
static const struct {
@@ -102,7 +89,8 @@ static char *media_list(int mask, int best)
return buf;
}
-static int show_basic_mii(int fd, int verbose)
+static int show_basic_mii(struct mii_bus *mii, struct phy_device *phydev,
+ int verbose)
{
char buf[100];
int i, mii_val[32];
@@ -110,15 +98,19 @@ static int show_basic_mii(int fd, int verbose)
/* Some bits in the BMSR are latched, but we can't rely on being
the only reader, so only the current values are meaningful */
- mdio_read(fd, MII_BMSR);
- for (i = 0; i < ((verbose > 1) ? 32 : 8); i++)
- mii_val[i] = mdio_read(fd, i);
+ mii->read(mii, phydev->addr, MII_BMSR);
+
+ for (i = 0; i < 32; i++)
+ mii_val[i] = mii->read(mii, phydev->addr, i);
if (mii_val[MII_BMCR] == 0xffff) {
fprintf(stderr, " No MII transceiver present!.\n");
return -1;
}
+ printf("%s: %s%d: ", phydev->cdev.name,
+ mii->parent->name, mii->parent->id);
+
/* Descriptive rename. */
bmcr = mii_val[MII_BMCR];
bmsr = mii_val[MII_BMSR];
@@ -212,14 +204,39 @@ static int show_basic_mii(int fd, int verbose)
return 0;
}
+static void mdiobus_show(struct device_d *dev, char *phydevname, int verbose)
+{
+ struct mii_bus *mii = to_mii_bus(dev);
+ int i, ret;
+
+ for (i = 0; i < PHY_MAX_ADDR; i++) {
+ struct phy_device *phydev;
+
+ phydev = mdiobus_scan(mii, i);
+ if (IS_ERR(phydev))
+ continue;
+ if (phydev->registered) {
+
+ show_basic_mii(mii, phydev, verbose);
+
+ if (phydevname &&
+ !strcmp(phydev->cdev.name, phydevname)) {
+ return;
+ }
+ }
+
+ }
+
+ return;
+}
+
static int do_miitool(int argc, char *argv[])
{
- char *filename;
+ char *phydevname;
+ struct mii_bus *mii;
int opt;
int argc_min;
- int fd;
int verbose;
- int scan = 0;
verbose = 0;
while ((opt = getopt(argc, argv, "vs")) > 0) {
@@ -227,9 +244,6 @@ static int do_miitool(int argc, char *argv[])
case 'v':
verbose++;
break;
- case 's':
- scan = 1;
- break;
default:
return COMMAND_ERROR_USAGE;
}
@@ -237,23 +251,15 @@ static int do_miitool(int argc, char *argv[])
argc_min = optind + 1;
- if (scan)
- mdiobus_detect_all();
-
- if (argc < argc_min)
- return scan ? 0 : COMMAND_ERROR_USAGE;
-
- filename = argv[optind];
-
- fd = open(filename, O_RDONLY);
- if (fd < 0) {
- printf("unable to read %s\n", filename);
- return COMMAND_ERROR;
+ phydevname = NULL;
+ if (argc >= argc_min) {
+ phydevname = argv[optind];
}
- show_basic_mii(fd, verbose);
-
- close(fd);
+ for_each_mii_bus(mii) {
+ mdiobus_detect(&mii->dev);
+ mdiobus_show(&mii->dev, phydevname, verbose);
+ }
return COMMAND_SUCCESS;
}
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index b29a980..895ead0 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -27,7 +27,7 @@
LIST_HEAD(mii_bus_list);
-static int mdiobus_detect(struct device_d *dev)
+int mdiobus_detect(struct device_d *dev)
{
struct mii_bus *mii = to_mii_bus(dev);
int i, ret;
@@ -49,14 +49,6 @@ static int mdiobus_detect(struct device_d *dev)
return 0;
}
-void mdiobus_detect_all(void)
-{
- struct mii_bus *mii;
-
- for_each_mii_bus(mii)
- mdiobus_detect(&mii->dev);
-}
-
/**
* mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
* @bus: target mii_bus
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 6c9d090..9994e11 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -94,10 +94,10 @@ int mdiobus_register(struct mii_bus *bus);
void mdiobus_unregister(struct mii_bus *bus);
struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
-void mdiobus_detect_all(void);
-
extern struct list_head mii_bus_list;
+int mdiobus_detect(struct device_d *dev);
+
#define for_each_mii_bus(mii) \
list_for_each_entry(mii, &mii_bus_list, list)
--
1.8.5.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/5] miitool: change behaviour closer to linux' mii-tool
2013-12-25 7:50 ` [PATCH 1/5] miitool: change behaviour closer to linux' mii-tool Antony Pavlov
@ 2014-01-06 8:52 ` Sascha Hauer
0 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2014-01-06 8:52 UTC (permalink / raw)
To: Antony Pavlov; +Cc: barebox
On Wed, Dec 25, 2013 at 11:50:01AM +0400, Antony Pavlov wrote:
> miitool without arguments will try to show status for all phys.
>
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> +static void mdiobus_show(struct device_d *dev, char *phydevname, int verbose)
> +{
> + struct mii_bus *mii = to_mii_bus(dev);
> + int i, ret;
Applied this series with this unused variable removed...
> @@ -227,9 +244,6 @@ static int do_miitool(int argc, char *argv[])
> case 'v':
> verbose++;
> break;
> - case 's':
> - scan = 1;
> - break;
...and also removed 's' from the options string.
This behaviour looks definitely better than what I did with the
additional 's' option.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/5] miitool: add initial GbE support
2013-12-25 7:50 [PATCH 0/5] miitool patches Antony Pavlov
2013-12-25 7:50 ` [PATCH 1/5] miitool: change behaviour closer to linux' mii-tool Antony Pavlov
@ 2013-12-25 7:50 ` Antony Pavlov
2013-12-25 7:50 ` [PATCH 3/5] miitool: drop internal table of known MII, use phy drivers instead Antony Pavlov
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2013-12-25 7:50 UTC (permalink / raw)
To: barebox
The GbE support based on the patch for generic 'mii-tool', see
http://ftp.debian.org/debian/pool/main/n/net-tools/net-tools_1.60-24.2.diff.gz
We need to note Jean-Christophe PLAGNIOL-VILLARD for his
initial GbE support patch:
http://lists.infradead.org/pipermail/barebox/2013-February/012634.html
Generic 'mii-tool' GbE support patch has some disadvantages:
1. 1000baseT-HD is prefered to 1000baseT-FD;
2. show GbE-features for 10/100 only phys (e.g. Level One LXT971).
This patch fixes this disadvantages.
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Cc: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
commands/miitool.c | 72 ++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 56 insertions(+), 16 deletions(-)
diff --git a/commands/miitool.c b/commands/miitool.c
index 7666e8a..6e8ae80 100644
--- a/commands/miitool.c
+++ b/commands/miitool.c
@@ -54,25 +54,45 @@ static const struct {
const struct {
char *name;
- u_short value;
+ u_short value[2];
} media[] = {
/* The order through 100baseT4 matches bits in the BMSR */
- { "10baseT-HD", ADVERTISE_10HALF },
- { "10baseT-FD", ADVERTISE_10FULL },
- { "100baseTx-HD", ADVERTISE_100HALF },
- { "100baseTx-FD", ADVERTISE_100FULL },
- { "100baseT4", LPA_100BASE4 },
- { "100baseTx", ADVERTISE_100FULL | ADVERTISE_100HALF },
- { "10baseT", ADVERTISE_10FULL | ADVERTISE_10HALF },
+ { "10baseT-HD", {ADVERTISE_10HALF} },
+ { "10baseT-FD", {ADVERTISE_10FULL} },
+ { "100baseTx-HD", {ADVERTISE_100HALF} },
+ { "100baseTx-FD", {ADVERTISE_100FULL} },
+ { "100baseT4", {LPA_100BASE4} },
+ { "100baseTx", {ADVERTISE_100FULL | ADVERTISE_100HALF} },
+ { "10baseT", {ADVERTISE_10FULL | ADVERTISE_10HALF} },
+ { "1000baseT-HD", {0, ADVERTISE_1000HALF} },
+ { "1000baseT-FD", {0, ADVERTISE_1000FULL} },
+ { "1000baseT", {0, ADVERTISE_1000HALF | ADVERTISE_1000FULL} },
};
#define NMEDIA (sizeof(media)/sizeof(media[0]))
-static char *media_list(int mask, int best)
+static const char *media_list(unsigned mask, unsigned mask2, int best)
{
static char buf[100];
int i;
*buf = '\0';
+
+ if (mask & BMCR_SPEED1000) {
+ if (mask2 & ADVERTISE_1000FULL) {
+ strcat(buf, " ");
+ strcat(buf, "1000baseT-FD");
+ if (best)
+ goto out;
+ }
+
+ if (mask2 & ADVERTISE_1000HALF) {
+ strcat(buf, " ");
+ strcat(buf, "1000baseT-HD");
+ if (best)
+ goto out;
+ }
+ }
+
mask >>= 5;
for (i = 4; i >= 0; i--) {
if (mask & (1 << i)) {
@@ -83,6 +103,7 @@ static char *media_list(int mask, int best)
}
}
+out:
if (mask & (1 << 5))
strcat(buf, " flow-control");
@@ -94,7 +115,9 @@ static int show_basic_mii(struct mii_bus *mii, struct phy_device *phydev,
{
char buf[100];
int i, mii_val[32];
- int bmcr, bmsr, advert, lkpar;
+ unsigned bmcr, bmsr, advert, lkpar, bmcr2 = 0, lpa2 = 0;
+ struct phy_driver *phydrv;
+ int is_phy_gbit;
/* Some bits in the BMSR are latched, but we can't rely on being
the only reader, so only the current values are meaningful */
@@ -103,7 +126,7 @@ static int show_basic_mii(struct mii_bus *mii, struct phy_device *phydev,
for (i = 0; i < 32; i++)
mii_val[i] = mii->read(mii, phydev->addr, i);
- if (mii_val[MII_BMCR] == 0xffff) {
+ if (mii_val[MII_BMCR] == 0xffff || mii_val[MII_BMSR] == 0x0000) {
fprintf(stderr, " No MII transceiver present!.\n");
return -1;
}
@@ -117,13 +140,23 @@ static int show_basic_mii(struct mii_bus *mii, struct phy_device *phydev,
advert = mii_val[MII_ADVERTISE];
lkpar = mii_val[MII_LPA];
+ phydrv = to_phy_driver(phydev->dev.driver);
+ is_phy_gbit = phydrv->features &
+ (SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full);
+
+ if (is_phy_gbit) {
+ bmcr2 = mii_val[MII_CTRL1000];
+ lpa2 = mii_val[MII_STAT1000];
+ }
+
*buf = '\0';
if (bmcr & BMCR_ANENABLE) {
if (bmsr & BMSR_ANEGCOMPLETE) {
if (advert & lkpar) {
sprintf(buf, "%s%s, ", (lkpar & LPA_LPACK) ?
"negotiated" : "no autonegotiation,",
- media_list(advert & lkpar, 1));
+ media_list(advert & lkpar,
+ bmcr2 & lpa2 >> 2, 1));
} else {
sprintf(buf, "autonegotiation failed, ");
}
@@ -131,8 +164,14 @@ static int show_basic_mii(struct mii_bus *mii, struct phy_device *phydev,
sprintf(buf, "autonegotiation restarted, ");
}
} else {
+ int speed1000;
+
+ speed1000 = ((bmcr2
+ & (ADVERTISE_1000HALF
+ | ADVERTISE_1000FULL)) & lpa2 >> 2);
sprintf(buf, "%s Mbit, %s duplex, ",
- (bmcr & BMCR_SPEED100) ? "100" : "10",
+ speed1000 ? "1000"
+ : (bmcr & BMCR_SPEED100) ? "100" : "10",
(bmcr & BMCR_FULLDPLX) ? "full" : "half");
}
@@ -189,15 +228,16 @@ static int show_basic_mii(struct mii_bus *mii, struct phy_device *phydev,
if (bmsr & BMSR_RFAULT)
printf("remote fault, ");
printf((bmsr & BMSR_LSTATUS) ? "link ok" : "no link");
- printf("\n capabilities:%s", media_list(bmsr >> 6, 0));
- printf("\n advertising: %s", media_list(advert, 0));
+ printf("\n capabilities:%s", media_list(bmsr >> 6, bmcr2, 0));
+ printf("\n advertising: %s", media_list(advert, lpa2 >> 2, 0));
#define LPA_ABILITY_MASK (LPA_10HALF | LPA_10FULL \
| LPA_100HALF | LPA_100FULL \
| LPA_100BASE4 | LPA_PAUSE_CAP)
if (lkpar & LPA_ABILITY_MASK)
- printf("\n link partner:%s", media_list(lkpar, 0));
+ printf("\n link partner:%s",
+ media_list(lkpar, bmcr2, 0));
printf("\n");
}
--
1.8.5.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/5] miitool: drop internal table of known MII, use phy drivers instead
2013-12-25 7:50 [PATCH 0/5] miitool patches Antony Pavlov
2013-12-25 7:50 ` [PATCH 1/5] miitool: change behaviour closer to linux' mii-tool Antony Pavlov
2013-12-25 7:50 ` [PATCH 2/5] miitool: add initial GbE support Antony Pavlov
@ 2013-12-25 7:50 ` Antony Pavlov
2013-12-25 7:50 ` [PATCH 4/5] net/phy: add driver for LXT PHYs Antony Pavlov
2013-12-25 7:50 ` [PATCH 5/5] net/phy/phy.c: fix whitespace Antony Pavlov
4 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2013-12-25 7:50 UTC (permalink / raw)
To: barebox
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
commands/miitool.c | 30 +++++-------------------------
1 file changed, 5 insertions(+), 25 deletions(-)
diff --git a/commands/miitool.c b/commands/miitool.c
index 6e8ae80..63feca8 100644
--- a/commands/miitool.c
+++ b/commands/miitool.c
@@ -41,17 +41,6 @@
#include <linux/phy.h>
#include <linux/err.h>
-
-/* Table of known MII's */
-static const struct {
- u_short id1, id2;
- u_short mask1, mask2;
- char *name;
-} mii_id[] = {
- { 0x0013, 0x78e0, 0xffff, 0xfff0, "Level One LXT971A" },
-};
-#define NMII (sizeof(mii_id)/sizeof(mii_id[0]))
-
const struct {
char *name;
u_short value[2];
@@ -189,20 +178,11 @@ static int show_basic_mii(struct mii_bus *mii, struct phy_device *phydev,
}
if (verbose) {
- printf(" product info: ");
- for (i = 0; i < NMII; i++)
- if ((mii_id[i].id1 == (mii_val[2] & mii_id[i].mask1)) &&
- (mii_id[i].id2 ==
- (mii_val[3] & mii_id[i].mask2)))
- break;
-
- if (i < NMII)
- printf("%s rev %d\n", mii_id[i].name, mii_val[3]&0x0f);
- else
- printf("vendor %02x:%02x:%02x, model %d rev %d\n",
- mii_val[2] >> 10, (mii_val[2] >> 2) & 0xff,
- ((mii_val[2] << 6)|(mii_val[3] >> 10)) & 0xff,
- (mii_val[3] >> 4) & 0x3f, mii_val[3] & 0x0f);
+ printf(" product info: %s ", phydrv->drv.name);
+ printf("(vendor %02x:%02x:%02x, model %d rev %d)\n",
+ mii_val[2] >> 10, (mii_val[2] >> 2) & 0xff,
+ ((mii_val[2] << 6) | (mii_val[3] >> 10)) & 0xff,
+ (mii_val[3] >> 4) & 0x3f, mii_val[3] & 0x0f);
printf(" basic mode: ");
if (bmcr & BMCR_RESET)
--
1.8.5.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 4/5] net/phy: add driver for LXT PHYs
2013-12-25 7:50 [PATCH 0/5] miitool patches Antony Pavlov
` (2 preceding siblings ...)
2013-12-25 7:50 ` [PATCH 3/5] miitool: drop internal table of known MII, use phy drivers instead Antony Pavlov
@ 2013-12-25 7:50 ` Antony Pavlov
2013-12-25 7:50 ` [PATCH 5/5] net/phy/phy.c: fix whitespace Antony Pavlov
4 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2013-12-25 7:50 UTC (permalink / raw)
To: barebox
Based on Linux kernel 3.12 driver.
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
drivers/net/phy/Kconfig | 5 +++++
drivers/net/phy/Makefile | 1 +
drivers/net/phy/lxt.c | 31 +++++++++++++++++++++++++++++++
3 files changed, 37 insertions(+)
create mode 100644 drivers/net/phy/lxt.c
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 83966f9..7ebdaa0 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -13,6 +13,11 @@ config AT803X_PHY
---help---
Currently supports the AT8030, AT8031 and AT8035 PHYs.
+config LXT_PHY
+ bool "Driver for the Intel LXT PHYs"
+ ---help---
+ Currently supports the lxt971 PHY.
+
config MICREL_PHY
bool "Driver for Micrel PHYs"
---help---
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index 47e2b42..451573e 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -1,4 +1,5 @@
obj-y += phy.o mdio_bus.o
obj-$(CONFIG_AT803X_PHY) += at803x.o
+obj-$(CONFIG_LXT_PHY) += lxt.o
obj-$(CONFIG_MICREL_PHY) += micrel.o
obj-$(CONFIG_SMSC_PHY) += smsc.o
diff --git a/drivers/net/phy/lxt.c b/drivers/net/phy/lxt.c
new file mode 100644
index 0000000..9e5ddbb
--- /dev/null
+++ b/drivers/net/phy/lxt.c
@@ -0,0 +1,31 @@
+/*
+ * drivers/net/phy/lxt.c
+ *
+ * Driver for Intel LXT PHYs
+ *
+ * base on Andy Fleming's linux lxt.c driver
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+
+#include <common.h>
+#include <init.h>
+#include <linux/phy.h>
+
+static struct phy_driver lxt97x_driver[] = {
+{
+ .phy_id = 0x001378e0,
+ .phy_id_mask = 0xfffffff0,
+ .drv.name = "LXT971",
+ .features = PHY_BASIC_FEATURES,
+} };
+
+static int lxt97x_phy_init(void)
+{
+ return phy_drivers_register(lxt97x_driver,
+ ARRAY_SIZE(lxt97x_driver));
+}
+fs_initcall(lxt97x_phy_init);
--
1.8.5.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 5/5] net/phy/phy.c: fix whitespace
2013-12-25 7:50 [PATCH 0/5] miitool patches Antony Pavlov
` (3 preceding siblings ...)
2013-12-25 7:50 ` [PATCH 4/5] net/phy: add driver for LXT PHYs Antony Pavlov
@ 2013-12-25 7:50 ` Antony Pavlov
4 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2013-12-25 7:50 UTC (permalink / raw)
To: barebox
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
drivers/net/phy/phy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 681fb51..6ca1bb2 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -773,7 +773,7 @@ int phy_driver_register(struct phy_driver *phydrv)
return register_driver(&phydrv->drv);
}
-
+
int phy_drivers_register(struct phy_driver *new_driver, int n)
{
int i, ret = 0;
--
1.8.5.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread