make robocfg work on brcm63xx as well (#4599)

SVN-Revision: 14826
master
Florian Fainelli 16 years ago
parent 04909ca614
commit 2d6c8c64a3
  1. 114
      package/robocfg/src/robocfg.c

@ -19,6 +19,7 @@
* 02110-1301, USA. * 02110-1301, USA.
*/ */
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -247,59 +248,106 @@ void usage()
mdix[0].name, mdix[1].name, mdix[2].name); mdix[0].name, mdix[1].name, mdix[2].name);
} }
int static robo_t robo;
main(int argc, char *argv[]) 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; struct ethtool_drvinfo info;
unsigned int phyid;
int ret;
if ((robo.fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { fprintf(stderr, "probing %s\n", dev);
perror("socket");
exit(1);
}
/* the only interface for now */
strcpy(robo.ifr.ifr_name, "eth0");
strcpy(robo.ifr.ifr_name, dev);
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
info.cmd = ETHTOOL_GDRVINFO; info.cmd = ETHTOOL_GDRVINFO;
robo.ifr.ifr_data = (caddr_t)&info; robo.ifr.ifr_data = (caddr_t)&info;
if (ioctl(robo.fd, SIOCETHTOOL, (caddr_t)&robo.ifr) < 0) { ret = ioctl(robo.fd, SIOCETHTOOL, (caddr_t)&robo.ifr);
perror("SIOCETHTOOL: your ethernet module is either unsupported or outdated"); if (ret < 0) {
// exit(1); perror("SIOCETHTOOL");
} else return ret;
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); if ( strcmp(info.driver, "et0") &&
exit(1); 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 */ /* 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; 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 { } else {
/* got phy address check for robo address */
struct mii_ioctl_data *mii = (struct mii_ioctl_data *)&robo.ifr.ifr_data; struct mii_ioctl_data *mii = (struct mii_ioctl_data *)&robo.ifr.ifr_data;
if (mii->phy_id != ROBO_PHY_ADDR) { mii->phy_id = ROBO_PHY_ADDR;
fprintf(stderr, "Invalid phy address (%d)\n", mii->phy_id); mii->reg_num = 2;
exit(1); ret = ioctl(robo.fd, SIOCGMIIREG, &robo.ifr);
if (ret < 0) {
perror("SIOCGMIIREG");
return ret;
} }
} phyid = mii->val_out & 0xffff;
phyid = mdio_read(&robo, ROBO_PHY_ADDR, 0x2) | mii->phy_id = ROBO_PHY_ADDR;
(mdio_read(&robo, ROBO_PHY_ADDR, 0x3) << 16); mii->reg_num = 3;
ret = ioctl(robo.fd, SIOCGMIIREG, &robo.ifr);
if (ret < 0) {
perror("SIOCGMIIREG");
return ret;
}
phyid |= mii->val_out << 16;
}
if (phyid == 0xffffffff || phyid == 0x55210022) { if (phyid == 0xffffffff || phyid == 0x55210022) {
fprintf(stderr, "No Robo switch in managed mode found\n"); 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); exit(1);
} }
if (bcm53xx_probe("eth1")) {
if (bcm53xx_probe("eth0")) {
perror("bcm53xx_probe");
exit(1);
}
}
robo5350 = robo_vlan5350(&robo); robo5350 = robo_vlan5350(&robo);
for (i = 1; i < argc;) { for (i = 1; i < argc;) {

Loading…
Cancel
Save