X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/cceb94e7755324dc8492f94c59cbcb86ebc36a48..7b3bd12cf8ee18257abac8deb8c5854070569fdf:/package/switch/src/switch-robo.c?ds=sidebyside diff --git a/package/switch/src/switch-robo.c b/package/switch/src/switch-robo.c index a0051a32f..2fca36057 100644 --- a/package/switch/src/switch-robo.c +++ b/package/switch/src/switch-robo.c @@ -21,7 +21,6 @@ * 02110-1301, USA. */ -#include #include #include #include @@ -58,17 +57,13 @@ #define ROBO_DEVICE_ID_5395 0x95 #define ROBO_DEVICE_ID_5397 0x97 #define ROBO_DEVICE_ID_5398 0x98 +#define ROBO_DEVICE_ID_53115 0x3115 /* Private et.o ioctls */ #define SIOCGETCPHYRD (SIOCDEVPRIVATE + 9) #define SIOCSETCPHYWR (SIOCDEVPRIVATE + 10) -/* linux 2.4 does not have 'bool' */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) -#define bool int -#endif - -/* Only available on brcm-2.4/brcm47xx */ +/* Only available on brcm47xx */ #ifdef BROADCOM extern char *nvram_get(const char *name); #define getvar(str) (nvram_get(str)?:"") @@ -101,7 +96,11 @@ static int do_ioctl(int cmd, void *buf) robo.ifr.ifr_data = (caddr_t) buf; set_fs(KERNEL_DS); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31) + ret = robo.dev->netdev_ops->ndo_do_ioctl(robo.dev, &robo.ifr, cmd); +#else ret = robo.dev->do_ioctl(robo.dev, &robo.ifr, cmd); +#endif set_fs(old_fs); return ret; @@ -126,7 +125,7 @@ static u16 mdio_read(__u16 phy_id, __u8 reg) "[%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; @@ -156,7 +155,7 @@ static void mdio_write(__u16 phy_id, __u8 reg, __u16 val) return; } - + if (do_ioctl(SIOCSETCPHYWR, args) < 0) { printk(KERN_ERR PFX "[%s:%d] SIOCGETCPHYWR failed!\n", __FILE__, __LINE__); @@ -180,13 +179,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; - + /* 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); - + /* 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 */ @@ -196,7 +195,7 @@ static int robo_reg(__u8 page, __u8 reg, __u8 op) } printk(KERN_ERR PFX "[%s:%d] timeout in robo_reg!\n", __FILE__, __LINE__); - + return 0; } @@ -204,9 +203,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; - + 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); } @@ -215,14 +214,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); - + 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); } @@ -240,7 +239,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); - + robo_reg(page, reg, REG_MII_ADDR_WRITE); } @@ -250,7 +249,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); - + /* 5365 will refuse this as it does not have this reg */ return (robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS_5350) == val16); } @@ -293,6 +292,7 @@ static void robo_switch_reset(void) (robo.devid == ROBO_DEVICE_ID_5398)) { /* Trigger a software reset. */ robo_write16(ROBO_CTRL_PAGE, 0x79, 0x83); + mdelay(500); robo_write16(ROBO_CTRL_PAGE, 0x79, 0); } } @@ -363,7 +363,8 @@ static int robo_probe(char *devname) if (err) return err; - printk("found!\n"); + printk("found a 5%s%x!%s\n", robo.devid & 0xff00 ? "" : "3", robo.devid, + robo.is_5350 ? " It's a 5350." : ""); return 0; } @@ -375,7 +376,7 @@ static int handle_vlan_port_read(void *driver, char *buf, int nr) 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); @@ -397,7 +398,7 @@ static int handle_vlan_port_read(void *driver, char *buf, int nr) } 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); @@ -430,7 +431,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; - + if (c == NULL) return -EINVAL; @@ -441,6 +442,17 @@ static int handle_vlan_port_write(void *driver, char *buf, int nr) } /* write config now */ + + if (robo.devid != ROBO_DEVICE_ID_5325) { + __u8 regoff = ((robo.devid == ROBO_DEVICE_ID_5395) || + (robo.devid == ROBO_DEVICE_ID_53115)) ? 0x20 : 0; + + robo_write32(ROBO_ARLIO_PAGE, 0x63 + regoff, (c->untag << 9) | c->port); + robo_write16(ROBO_ARLIO_PAGE, 0x61 + regoff, nr); + robo_write16(ROBO_ARLIO_PAGE, 0x60 + regoff, 1 << 7); + return 0; + } + val16 = (nr) /* vlan */ | (1 << 12) /* write */ | (1 << 13) /* enable */; if (robo.is_5350) { robo_write32(ROBO_VLAN_PAGE, ROBO_VLAN_WRITE_5350, @@ -478,11 +490,16 @@ 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); - + 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 : - (1 << 1) | (1 << 2) | (1 << 3) /* RSV multicast */); + (robo.devid == ROBO_DEVICE_ID_5325 ? (1 << 1) : + 0) | (1 << 2) | (1 << 3)); /* RSV multicast */ + + if (robo.devid != ROBO_DEVICE_ID_5325) + return 0; + robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL4, disable ? 0 : (1 << 6) /* drop invalid VID frames */); robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL5, disable ? 0 : @@ -497,7 +514,7 @@ static int handle_reset(void *driver, char *buf, int nr) switch_vlan_config *c = switch_parse_vlan(d, buf); int j; __u16 val16; - + if (c == NULL) return -EINVAL; @@ -543,7 +560,7 @@ static int __init robo_init(void) notfound = robo_probe(device); } device[3]--; - + if (notfound) { kfree(device); return -ENODEV; @@ -581,6 +598,10 @@ static int __init robo_init(void) .port_handlers = NULL, .vlan_handlers = vlan, }; + if (robo.devid != ROBO_DEVICE_ID_5325) { + driver.ports = 9; + driver.cpuport = 8; + } return switch_register_driver(&driver); }