projects
/
openwrt.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ar71x: use raw squashfs images for TP-Link boards
[openwrt.git]
/
package
/
switch
/
src
/
switch-robo.c
diff --git
a/package/switch/src/switch-robo.c
b/package/switch/src/switch-robo.c
index
7884bd8
..
ec9e337
100644
(file)
--- a/
package/switch/src/switch-robo.c
+++ b/
package/switch/src/switch-robo.c
@@
-34,6
+34,10
@@
#include "switch-core.h"
#include "etc53xx.h"
#include "switch-core.h"
#include "etc53xx.h"
+#ifdef CONFIG_BCM47XX
+#include <nvram.h>
+#endif
+
#define DRIVER_NAME "bcm53xx"
#define DRIVER_VERSION "0.02"
#define PFX "roboswitch: "
#define DRIVER_NAME "bcm53xx"
#define DRIVER_VERSION "0.02"
#define PFX "roboswitch: "
@@
-63,14
+67,6
@@
#define SIOCGETCPHYRD (SIOCDEVPRIVATE + 9)
#define SIOCSETCPHYWR (SIOCDEVPRIVATE + 10)
#define SIOCGETCPHYRD (SIOCDEVPRIVATE + 9)
#define SIOCSETCPHYWR (SIOCDEVPRIVATE + 10)
-/* Only available on brcm47xx */
-#ifdef BROADCOM
-extern char *nvram_get(const char *name);
-#define getvar(str) (nvram_get(str)?:"")
-#else
-#define getvar(str) ""
-#endif
-
/* Data structure for a Roboswitch device. */
struct robo_switch {
char *device; /* The device name string (ethX) */
/* Data structure for a Roboswitch device. */
struct robo_switch {
char *device; /* The device name string (ethX) */
@@
-125,7
+121,7
@@
static u16 mdio_read(__u16 phy_id, __u8 reg)
"[%s:%d] SIOCGETCPHYRD failed!\n", __FILE__, __LINE__);
return 0xffff;
}
"[%s:%d] SIOCGETCPHYRD failed!\n", __FILE__, __LINE__);
return 0xffff;
}
-
+
return args[1];
} else {
struct mii_ioctl_data *mii = (struct mii_ioctl_data *) &robo.ifr.ifr_data;
return args[1];
} else {
struct mii_ioctl_data *mii = (struct mii_ioctl_data *) &robo.ifr.ifr_data;
@@
-155,7
+151,7
@@
static void mdio_write(__u16 phy_id, __u8 reg, __u16 val)
return;
}
return;
}
-
+
if (do_ioctl(SIOCSETCPHYWR, args) < 0) {
printk(KERN_ERR PFX
"[%s:%d] SIOCGETCPHYWR failed!\n", __FILE__, __LINE__);
if (do_ioctl(SIOCSETCPHYWR, args) < 0) {
printk(KERN_ERR PFX
"[%s:%d] SIOCGETCPHYWR failed!\n", __FILE__, __LINE__);
@@
-179,13
+175,13
@@
static void mdio_write(__u16 phy_id, __u8 reg, __u16 val)
static int robo_reg(__u8 page, __u8 reg, __u8 op)
{
int i = 3;
static int robo_reg(__u8 page, __u8 reg, __u8 op)
{
int i = 3;
-
+
/* set page number */
/* set page number */
- mdio_write(robo.phy_addr, REG_MII_PAGE,
+ mdio_write(robo.phy_addr, REG_MII_PAGE,
(page << 8) | REG_MII_PAGE_ENABLE);
(page << 8) | REG_MII_PAGE_ENABLE);
-
+
/* set register address */
/* set register address */
- mdio_write(robo.phy_addr, REG_MII_ADDR,
+ mdio_write(robo.phy_addr, REG_MII_ADDR,
(reg << 8) | op);
/* check if operation completed */
(reg << 8) | op);
/* check if operation completed */
@@
-195,7
+191,7
@@
static int robo_reg(__u8 page, __u8 reg, __u8 op)
}
printk(KERN_ERR PFX "[%s:%d] timeout in robo_reg!\n", __FILE__, __LINE__);
}
printk(KERN_ERR PFX "[%s:%d] timeout in robo_reg!\n", __FILE__, __LINE__);
-
+
return 0;
}
return 0;
}
@@
-203,9
+199,9
@@
static int robo_reg(__u8 page, __u8 reg, __u8 op)
static void robo_read(__u8 page, __u8 reg, __u16 *val, int count)
{
int i;
static void robo_read(__u8 page, __u8 reg, __u16 *val, int count)
{
int i;
-
+
robo_reg(page, reg, REG_MII_ADDR_READ);
robo_reg(page, reg, REG_MII_ADDR_READ);
-
+
for (i = 0; i < count; i++)
val[i] = mdio_read(robo.phy_addr, REG_MII_DATA0 + i);
}
for (i = 0; i < count; i++)
val[i] = mdio_read(robo.phy_addr, REG_MII_DATA0 + i);
}
@@
-214,14
+210,14
@@
static void robo_read(__u8 page, __u8 reg, __u16 *val, int count)
static __u16 robo_read16(__u8 page, __u8 reg)
{
robo_reg(page, reg, REG_MII_ADDR_READ);
static __u16 robo_read16(__u8 page, __u8 reg)
{
robo_reg(page, reg, REG_MII_ADDR_READ);
-
+
return mdio_read(robo.phy_addr, REG_MII_DATA0);
}
static __u32 robo_read32(__u8 page, __u8 reg)
{
robo_reg(page, reg, REG_MII_ADDR_READ);
return mdio_read(robo.phy_addr, REG_MII_DATA0);
}
static __u32 robo_read32(__u8 page, __u8 reg)
{
robo_reg(page, reg, REG_MII_ADDR_READ);
-
+
return mdio_read(robo.phy_addr, REG_MII_DATA0) +
(mdio_read(robo.phy_addr, REG_MII_DATA0 + 1) << 16);
}
return mdio_read(robo.phy_addr, REG_MII_DATA0) +
(mdio_read(robo.phy_addr, REG_MII_DATA0 + 1) << 16);
}
@@
-239,7
+235,7
@@
static void robo_write32(__u8 page, __u8 reg, __u32 val32)
/* write data */
mdio_write(robo.phy_addr, REG_MII_DATA0, val32 & 65535);
mdio_write(robo.phy_addr, REG_MII_DATA0 + 1, val32 >> 16);
/* write data */
mdio_write(robo.phy_addr, REG_MII_DATA0, val32 & 65535);
mdio_write(robo.phy_addr, REG_MII_DATA0 + 1, val32 >> 16);
-
+
robo_reg(page, reg, REG_MII_ADDR_WRITE);
}
robo_reg(page, reg, REG_MII_ADDR_WRITE);
}
@@
-249,7
+245,7
@@
static int robo_vlan5350(void)
/* set vlan access id to 15 and read it back */
__u16 val16 = 15;
robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS_5350, val16);
/* set vlan access id to 15 and read it back */
__u16 val16 = 15;
robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS_5350, val16);
-
+
/* 5365 will refuse this as it does not have this reg */
return (robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS_5350) == val16);
}
/* 5365 will refuse this as it does not have this reg */
return (robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS_5350) == val16);
}
@@
-258,6
+254,9
@@
static int robo_switch_enable(void)
{
unsigned int i, last_port;
u16 val;
{
unsigned int i, last_port;
u16 val;
+#ifdef CONFIG_BCM47XX
+ char buf[20];
+#endif
val = robo_read16(ROBO_CTRL_PAGE, ROBO_SWITCH_MODE);
if (!(val & (1 << 1))) {
val = robo_read16(ROBO_CTRL_PAGE, ROBO_SWITCH_MODE);
if (!(val & (1 << 1))) {
@@
-278,10
+277,13
@@
static int robo_switch_enable(void)
robo_write16(ROBO_CTRL_PAGE, i, 0);
}
robo_write16(ROBO_CTRL_PAGE, i, 0);
}
+#ifdef CONFIG_BCM47XX
/* WAN port LED, except for Netgear WGT634U */
/* WAN port LED, except for Netgear WGT634U */
- if (strcmp(getvar("nvram_type"), "cfe") != 0)
- robo_write16(ROBO_CTRL_PAGE, 0x16, 0x1F);
-
+ if (nvram_getenv("nvram_type", buf, sizeof(buf)) >= 0) {
+ if (strcmp(buf, "cfe") != 0)
+ robo_write16(ROBO_CTRL_PAGE, 0x16, 0x1F);
+ }
+#endif
return 0;
}
return 0;
}
@@
-301,7
+303,7
@@
static int robo_probe(char *devname)
{
__u32 phyid;
unsigned int i;
{
__u32 phyid;
unsigned int i;
- int err;
+ int err
= 1
;
printk(KERN_INFO PFX "Probing device %s: ", devname);
strcpy(robo.ifr.ifr_name, devname);
printk(KERN_INFO PFX "Probing device %s: ", devname);
strcpy(robo.ifr.ifr_name, devname);
@@
-331,7
+333,7
@@
static int robo_probe(char *devname)
(mii->phy_id != ROBO_PHY_ADDR_BCM63XX) &&
(mii->phy_id != ROBO_PHY_ADDR_TG3)) {
printk("Invalid phy address (%d)\n", mii->phy_id);
(mii->phy_id != ROBO_PHY_ADDR_BCM63XX) &&
(mii->phy_id != ROBO_PHY_ADDR_TG3)) {
printk("Invalid phy address (%d)\n", mii->phy_id);
-
return 1
;
+
goto done
;
}
robo.use_et = 0;
/* The robo has a fixed PHY address that is different from the
}
robo.use_et = 0;
/* The robo has a fixed PHY address that is different from the
@@
-344,7
+346,7
@@
static int robo_probe(char *devname)
if (phyid == 0xffffffff || phyid == 0x55210022) {
printk("No Robo switch in managed mode found, phy_id = 0x%08x\n", phyid);
if (phyid == 0xffffffff || phyid == 0x55210022) {
printk("No Robo switch in managed mode found, phy_id = 0x%08x\n", phyid);
-
return 1
;
+
goto done
;
}
/* Get the device ID */
}
/* Get the device ID */
@@
-361,11
+363,18
@@
static int robo_probe(char *devname)
robo_switch_reset();
err = robo_switch_enable();
if (err)
robo_switch_reset();
err = robo_switch_enable();
if (err)
- return err;
+ goto done;
+ err = 0;
printk("found a 5%s%x!%s\n", robo.devid & 0xff00 ? "" : "3", robo.devid,
robo.is_5350 ? " It's a 5350." : "");
printk("found a 5%s%x!%s\n", robo.devid & 0xff00 ? "" : "3", robo.devid,
robo.is_5350 ? " It's a 5350." : "");
- return 0;
+
+done:
+ if (err) {
+ dev_put(robo.dev);
+ robo.dev = NULL;
+ }
+ return err;
}
}
@@
-376,7
+385,7
@@
static int handle_vlan_port_read(void *driver, char *buf, int nr)
int j;
val16 = (nr) /* vlan */ | (0 << 12) /* read */ | (1 << 13) /* enable */;
int j;
val16 = (nr) /* vlan */ | (0 << 12) /* read */ | (1 << 13) /* enable */;
-
+
if (robo.is_5350) {
u32 val32;
robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS_5350, val16);
if (robo.is_5350) {
u32 val32;
robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS_5350, val16);
@@
-398,7
+407,7
@@
static int handle_vlan_port_read(void *driver, char *buf, int nr)
}
len += sprintf(buf + len, "\n");
}
}
len += sprintf(buf + len, "\n");
}
- } else {
+ } else {
robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS, val16);
/* actual read */
val16 = robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_READ);
robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS, val16);
/* actual read */
val16 = robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_READ);
@@
-431,7
+440,7
@@
static int handle_vlan_port_write(void *driver, char *buf, int nr)
switch_vlan_config *c = switch_parse_vlan(d, buf);
int j;
__u16 val16;
switch_vlan_config *c = switch_parse_vlan(d, buf);
int j;
__u16 val16;
-
+
if (c == NULL)
return -EINVAL;
if (c == NULL)
return -EINVAL;
@@
-490,7
+499,7
@@
static int handle_enable_vlan_read(void *driver, char *buf, int nr)
static int handle_enable_vlan_write(void *driver, char *buf, int nr)
{
int disable = ((buf[0] != '1') ? 1 : 0);
static int handle_enable_vlan_write(void *driver, char *buf, int nr)
{
int disable = ((buf[0] != '1') ? 1 : 0);
-
+
robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL0, disable ? 0 :
(1 << 7) /* 802.1Q VLAN */ | (3 << 5) /* mac check and hash */);
robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL1, disable ? 0 :
robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL0, disable ? 0 :
(1 << 7) /* 802.1Q VLAN */ | (3 << 5) /* mac check and hash */);
robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL1, disable ? 0 :
@@
-514,7
+523,7
@@
static int handle_reset(void *driver, char *buf, int nr)
switch_vlan_config *c = switch_parse_vlan(d, buf);
int j;
__u16 val16;
switch_vlan_config *c = switch_parse_vlan(d, buf);
int j;
__u16 val16;
-
+
if (c == NULL)
return -EINVAL;
if (c == NULL)
return -EINVAL;
@@
-560,7
+569,7
@@
static int __init robo_init(void)
notfound = robo_probe(device);
}
device[3]--;
notfound = robo_probe(device);
}
device[3]--;
-
+
if (notfound) {
kfree(device);
return -ENODEV;
if (notfound) {
kfree(device);
return -ENODEV;
@@
-610,6
+619,8
@@
static int __init robo_init(void)
static void __exit robo_exit(void)
{
switch_unregister_driver(DRIVER_NAME);
static void __exit robo_exit(void)
{
switch_unregister_driver(DRIVER_NAME);
+ if (robo.dev)
+ dev_put(robo.dev);
kfree(robo.device);
}
kfree(robo.device);
}
This page took
0.034701 seconds
and
4
git commands to generate.