summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflorian <florian@3c298f89-4303-0410-b956-a3cf2f4a3e73>2009-03-09 21:57:47 +0000
committerflorian <florian@3c298f89-4303-0410-b956-a3cf2f4a3e73>2009-03-09 21:57:47 +0000
commit009d09e1755519d00223162a1ec665b3acdb396c (patch)
treedaa38941d27d5231cfff98ab025c62921374a918
parent9df07ac5e1fa5aff5839a88e541d87a591c42f0c (diff)
[package] make robocfg work on brcm63xx as well (#4599)
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@14826 3c298f89-4303-0410-b956-a3cf2f4a3e73
-rw-r--r--package/robocfg/src/robocfg.c118
1 files changed, 83 insertions, 35 deletions
diff --git a/package/robocfg/src/robocfg.c b/package/robocfg/src/robocfg.c
index b8fc49f49..7a4094dd4 100644
--- a/package/robocfg/src/robocfg.c
+++ b/package/robocfg/src/robocfg.c
@@ -19,6 +19,7 @@
* 02110-1301, USA.
*/
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -247,59 +248,106 @@ void usage()
mdix[0].name, mdix[1].name, mdix[2].name);
}
-int
-main(int argc, char *argv[])
+static robo_t robo;
+int bcm53xx_probe(const char *dev)
{
- u16 val16;
- u16 mac[3];
- int i = 0, j;
- int robo5350 = 0;
- u32 phyid;
-
- static robo_t robo;
struct ethtool_drvinfo info;
-
- if ((robo.fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- perror("socket");
- exit(1);
- }
+ unsigned int phyid;
+ int ret;
- /* the only interface for now */
- strcpy(robo.ifr.ifr_name, "eth0");
+ fprintf(stderr, "probing %s\n", dev);
+ strcpy(robo.ifr.ifr_name, dev);
memset(&info, 0, sizeof(info));
info.cmd = ETHTOOL_GDRVINFO;
robo.ifr.ifr_data = (caddr_t)&info;
- if (ioctl(robo.fd, SIOCETHTOOL, (caddr_t)&robo.ifr) < 0) {
- perror("SIOCETHTOOL: your ethernet module is either unsupported or outdated");
-// exit(1);
- } else
- if (strcmp(info.driver, "et0") && strcmp(info.driver, "b44")) {
- fprintf(stderr, "No suitable module found for %s (managed by %s)\n",
- robo.ifr.ifr_name, info.driver);
- exit(1);
+ ret = ioctl(robo.fd, SIOCETHTOOL, (caddr_t)&robo.ifr);
+ if (ret < 0) {
+ perror("SIOCETHTOOL");
+ return ret;
}
-
+
+ if ( strcmp(info.driver, "et0") &&
+ strcmp(info.driver, "b44") &&
+ strcmp(info.driver, "bcm63xx_enet") ) {
+ fprintf(stderr, "driver not supported %s\n", info.driver);
+ return -ENOSYS;
+ }
+
/* try access using MII ioctls - get phy address */
- if (ioctl(robo.fd, SIOCGMIIPHY, &robo.ifr) < 0) {
+ robo.et = 0;
+ if (ioctl(robo.fd, SIOCGMIIPHY, &robo.ifr) < 0)
robo.et = 1;
+
+ if (robo.et) {
+ unsigned int args[2] = { 2 };
+
+ robo.ifr.ifr_data = (caddr_t) args;
+ ret = ioctl(robo.fd, SIOCGETCPHYRD, (caddr_t)&robo.ifr);
+ if (ret < 0) {
+ perror("SIOCGETCPHYRD");
+ return ret;
+ }
+ phyid = args[1] & 0xffff;
+
+ args[0] = 3;
+ robo.ifr.ifr_data = (caddr_t) args;
+ ret = ioctl(robo.fd, SIOCGETCPHYRD, (caddr_t)&robo.ifr);
+ if (ret < 0) {
+ perror("SIOCGETCPHYRD");
+ return ret;
+ }
+ phyid |= args[1] << 16;
} else {
- /* got phy address check for robo address */
struct mii_ioctl_data *mii = (struct mii_ioctl_data *)&robo.ifr.ifr_data;
- if (mii->phy_id != ROBO_PHY_ADDR) {
- fprintf(stderr, "Invalid phy address (%d)\n", mii->phy_id);
- exit(1);
+ mii->phy_id = ROBO_PHY_ADDR;
+ mii->reg_num = 2;
+ ret = ioctl(robo.fd, SIOCGMIIREG, &robo.ifr);
+ if (ret < 0) {
+ perror("SIOCGMIIREG");
+ return ret;
}
+ phyid = mii->val_out & 0xffff;
+
+ mii->phy_id = ROBO_PHY_ADDR;
+ mii->reg_num = 3;
+ ret = ioctl(robo.fd, SIOCGMIIREG, &robo.ifr);
+ if (ret < 0) {
+ perror("SIOCGMIIREG");
+ return ret;
+ }
+ phyid |= mii->val_out << 16;
}
- phyid = mdio_read(&robo, ROBO_PHY_ADDR, 0x2) |
- (mdio_read(&robo, ROBO_PHY_ADDR, 0x3) << 16);
-
if (phyid == 0xffffffff || phyid == 0x55210022) {
- fprintf(stderr, "No Robo switch in managed mode found\n");
- exit(1);
+ perror("phyid");
+ return -EIO;
}
+ return 0;
+}
+
+int
+main(int argc, char *argv[])
+{
+ u16 val16;
+ u16 mac[3];
+ int i = 0, j;
+ int robo5350 = 0;
+ u32 phyid;
+
+ if ((robo.fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ perror("socket");
+ exit(1);
+ }
+
+ if (bcm53xx_probe("eth1")) {
+ if (bcm53xx_probe("eth0")) {
+ perror("bcm53xx_probe");
+ exit(1);
+ }
+ }
+
robo5350 = robo_vlan5350(&robo);
for (i = 1; i < argc;) {