X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/8b6a1ab51008a9be622a449a2b513ab9e0330523..eee99ea9c7a0d6577d1bfeb1009c65bab5b46822:/openwrt/target/linux/package/switch/src/switch-adm.c?ds=sidebyside diff --git a/openwrt/target/linux/package/switch/src/switch-adm.c b/openwrt/target/linux/package/switch/src/switch-adm.c index aebaaf6d2..f2bc8e152 100644 --- a/openwrt/target/linux/package/switch/src/switch-adm.c +++ b/openwrt/target/linux/package/switch/src/switch-adm.c @@ -28,10 +28,11 @@ #include #include -#include "gpio.h" #include "switch-core.h" +#include "gpio.h" #define DRIVER_NAME "adm6996" +#define DRIVER_VERSION "0.01" static int eecs = 2; static int eesk = 3; @@ -57,8 +58,9 @@ MODULE_PARM(force, "i"); #define adm_write16(cs, w) { __u16 val = hton16(w); adm_write(cs, (__u8 *)&val, sizeof(val)*8); } #define adm_write32(cs, i) { uint32 val = hton32(i); adm_write(cs, (__u8 *)&val, sizeof(val)*8); } +#define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0) -extern int getintvar(char **vars, char *name); +extern char *nvram_get(char *name); static void adm_write(int cs, char *buf, unsigned int bits) @@ -240,7 +242,7 @@ static int port_conf[] = { 0x01, 0x03, 0x05, 0x07, 0x08, 0x09 }; /* Bits in VLAN port mapping */ static int vlan_ports[] = { 1 << 0, 1 << 2, 1 << 4, 1 << 6, 1 << 7, 1 << 8 }; -static int handle_vlan_port_read(char *buf, int nr) +static int handle_vlan_port_read(void *driver, char *buf, int nr) { int ports, i, c, len = 0; @@ -261,30 +263,33 @@ static int handle_vlan_port_read(char *buf, int nr) return len; } -static int handle_vlan_port_write(char *buf, int nr) +static int handle_vlan_port_write(void *driver, char *buf, int nr) { - int i, c, ports; - int map = switch_parse_vlan(buf); + int i, cfg, ports; + switch_driver *d = (switch_driver *) driver; + switch_vlan_config *c = switch_parse_vlan(d, buf); - if (map == -1) + if (c == NULL) return -1; ports = adm_rreg(0, 0x13 + nr); - for (i = 0; i <= 5; i++) { - if (map & (1 << i)) { + for (i = 0; i < d->ports; i++) { + if (c->port & (1 << i)) { ports |= vlan_ports[i]; - c = adm_rreg(0, port_conf[i]); + cfg = adm_rreg(0, port_conf[i]); /* Tagging */ - if (map & (1 << (8 + i))) - c |= (1 << 4); + if (c->untag & (1 << i)) + cfg &= ~(1 << 4); else - c &= ~(1 << 4); - - c = (c & ~(0xf << 10)) | (nr << 10); + cfg |= (1 << 4); - adm_wreg(port_conf[i], (__u16) c); + if ((c->untag | c->pvid) & (1 << i)) { + cfg = (cfg & ~(0xf << 10)) | (nr << 10); + } + + adm_wreg(port_conf[i], (__u16) cfg); } else { ports &= ~(vlan_ports[i]); } @@ -294,12 +299,12 @@ static int handle_vlan_port_write(char *buf, int nr) return 0; } -static int handle_port_enable_read(char *buf, int nr) +static int handle_port_enable_read(void *driver, char *buf, int nr) { return sprintf(buf, "%d\n", ((adm_rreg(0, port_conf[nr]) & (1 << 5)) ? 0 : 1)); } -static int handle_port_enable_write(char *buf, int nr) +static int handle_port_enable_write(void *driver, char *buf, int nr) { int reg = adm_rreg(0, port_conf[nr]); @@ -313,7 +318,7 @@ static int handle_port_enable_write(char *buf, int nr) return 0; } -static int handle_port_media_read(char *buf, int nr) +static int handle_port_media_read(void *driver, char *buf, int nr) { int len; int media = 0; @@ -330,7 +335,7 @@ static int handle_port_media_read(char *buf, int nr) return len + sprintf(buf + len, "\n"); } -static int handle_port_media_write(char *buf, int nr) +static int handle_port_media_write(void *driver, char *buf, int nr) { int media = switch_parse_media(buf); int reg = adm_rreg(0, port_conf[nr]); @@ -351,12 +356,12 @@ static int handle_port_media_write(char *buf, int nr) return 0; } -static int handle_vlan_enable_read(char *buf, int nr) +static int handle_vlan_enable_read(void *driver, char *buf, int nr) { return sprintf(buf, "%d\n", ((adm_rreg(0, 0x11) & (1 << 5)) ? 1 : 0)); } -static int handle_vlan_enable_write(char *buf, int nr) +static int handle_vlan_enable_write(void *driver, char *buf, int nr) { int reg = adm_rreg(0, 0x11); @@ -370,7 +375,7 @@ static int handle_vlan_enable_write(char *buf, int nr) return 0; } -static int handle_reset(char *buf, int nr) +static int handle_reset(void *driver, char *buf, int nr) { int i; @@ -412,7 +417,7 @@ static int handle_reset(char *buf, int nr) return 0; } -static int handle_registers(char *buf, int nr) +static int handle_registers(void *driver, char *buf, int nr) { int i, len = 0; @@ -423,7 +428,7 @@ static int handle_registers(char *buf, int nr) return len; } -static int handle_counters(char *buf, int nr) +static int handle_counters(void *driver, char *buf, int nr) { int i, len = 0; @@ -439,11 +444,8 @@ static int detect_adm() int ret = 0; #if defined(BCMGPIO2) || defined(BCMGPIO) -#ifdef LINUX_2_4 - int boardflags = getintvar(NULL, "boardflags"); -#else - extern int boardflags; -#endif + int boardflags = atoi(nvram_get("boardflags")); + if ((boardflags & 0x80) || force) ret = 1; else @@ -465,7 +467,7 @@ static int __init adm_init() {NULL, NULL, NULL} }; switch_config port[] = { - {"enabled", handle_port_enable_read, handle_port_enable_write}, + {"enable", handle_port_enable_read, handle_port_enable_write}, {"media", handle_port_media_read, handle_port_media_write}, {NULL, NULL, NULL} }; @@ -475,7 +477,10 @@ static int __init adm_init() }; switch_driver driver = { name: DRIVER_NAME, + version: DRIVER_VERSION, + interface: "eth0", ports: 6, + cpuport: 5, vlans: 16, driver_handlers: cfg, port_handlers: port,