lantiq: Tune the XWAY subtarget cflags
[openwrt/staging/yousong.git] / package / switch / src / switch-robo.c
index aaccdd9f6b8873144b52abd9f2e5497231820475..f7159729b8842191aaf8b93c4f4b9ae4234eeccd 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2005 Felix Fietkau <nbd@nbd.name>
  * Copyright (C) 2008 Michael Buesch <mb@bu3sch.de>
+ * Copyright (C) 2013 Hauke Mehrtens <hauke@hauke-m.de>
  * Based on 'robocfg' by Oleg I. Vdovikin
  *
  * This program is free software; you can redistribute it and/or
@@ -40,7 +41,7 @@
 #endif
 
 #define DRIVER_NAME            "bcm53xx"
-#define DRIVER_VERSION         "0.02"
+#define DRIVER_VERSION         "0.03"
 #define PFX                    "roboswitch: "
 
 #define ROBO_PHY_ADDR          0x1E    /* robo switch phy address */
@@ -63,6 +64,7 @@
 #define  ROBO_DEVICE_ID_5397   0x97
 #define  ROBO_DEVICE_ID_5398   0x98
 #define  ROBO_DEVICE_ID_53115  0x3115
+#define  ROBO_DEVICE_ID_53125  0x3125
 
 /* Private et.o ioctls */
 #define SIOCGETCPHYRD           (SIOCDEVPRIVATE + 9)
@@ -248,6 +250,13 @@ static int robo_switch_enable(void)
                robo_write16(ROBO_CTRL_PAGE, ROBO_IM_PORT_CTRL, 0);
        }
 
+       if (robo.devid == ROBO_DEVICE_ID_53125) {
+               /* Make IM port status link by default */
+               val = robo_read16(ROBO_CTRL_PAGE, ROBO_PORT_OVERRIDE_CTRL) | 0xb1;
+               robo_write16(ROBO_CTRL_PAGE, ROBO_PORT_OVERRIDE_CTRL, val);
+               // TODO: init EEE feature
+       }
+
 #ifdef CONFIG_BCM47XX
        /* WAN port LED, except for Netgear WGT634U */
        if (bcm47xx_nvram_getenv("nvram_type", buf, sizeof(buf)) >= 0) {
@@ -486,7 +495,8 @@ static int handle_vlan_port_read_new(switch_driver *d, char *buf, int nr)
        int j;
 
        if ((robo.devid == ROBO_DEVICE_ID_5395) ||
-           (robo.devid == ROBO_DEVICE_ID_53115)) {
+           (robo.devid == ROBO_DEVICE_ID_53115) ||
+           (robo.devid == ROBO_DEVICE_ID_53125)) {
                vtbl_access = ROBO_VTBL_ACCESS_5395;
                vtbl_index = ROBO_VTBL_INDX_5395;
                vtbl_entry = ROBO_VTBL_ENTRY_5395;
@@ -557,7 +567,8 @@ static void handle_vlan_port_write_new(switch_driver *d, switch_vlan_config *c,
 
        /* write config now */
        if ((robo.devid == ROBO_DEVICE_ID_5395) ||
-           (robo.devid == ROBO_DEVICE_ID_53115)) {
+           (robo.devid == ROBO_DEVICE_ID_53115) ||
+           (robo.devid == ROBO_DEVICE_ID_53125)) {
                vtbl_access = ROBO_VTBL_ACCESS_5395;
                vtbl_index = ROBO_VTBL_INDX_5395;
                vtbl_entry = ROBO_VTBL_ENTRY_5395;
@@ -693,12 +704,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)
 {
+       __u16 val16;
        int disable = ((buf[0] != '1') ? 1 : 0);
 
+       val16 = robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL0);
        robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL0, disable ? 0 :
-               (1 << 7) /* 802.1Q VLAN */ | (3 << 5) /* mac check and hash */);
+               val16 | (1 << 7) /* 802.1Q VLAN */ | (3 << 5) /* mac check and hash */);
+
+       val16 = robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL1);
        robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL1, disable ? 0 :
-               (robo.devid == ROBO_DEVICE_ID_5325 ? (1 << 1) :
+               val16 | (robo.devid == ROBO_DEVICE_ID_5325 ? (1 << 1) :
                0) | (1 << 2) | (1 << 3)); /* RSV multicast */
 
        if (robo.devid != ROBO_DEVICE_ID_5325)
@@ -712,15 +727,11 @@ static int handle_enable_vlan_write(void *driver, char *buf, int nr)
        return 0;
 }
 
-static int handle_reset(void *driver, char *buf, int nr)
+static void handle_reset_old(switch_driver *d, char *buf, int nr)
 {
-       switch_driver *d = (switch_driver *) driver;
        int j;
        __u16 val16;
 
-       /* disable switching */
-       set_switch(0);
-
        /* reset vlans */
        for (j = 0; j <= ((robo.is_5365) ? VLAN_ID_MAX_5365 : VLAN_ID_MAX); j++) {
                /* write config now */
@@ -733,6 +744,45 @@ static int handle_reset(void *driver, char *buf, int nr)
                                                            ROBO_VLAN_TABLE_ACCESS,
                             val16);
        }
+}
+
+static void handle_reset_new(switch_driver *d, char *buf, int nr)
+{
+       int j;
+       __u8 vtbl_entry, vtbl_index, vtbl_access;
+
+       if ((robo.devid == ROBO_DEVICE_ID_5395) ||
+           (robo.devid == ROBO_DEVICE_ID_53115) ||
+           (robo.devid == ROBO_DEVICE_ID_53125)) {
+               vtbl_access = ROBO_VTBL_ACCESS_5395;
+               vtbl_index = ROBO_VTBL_INDX_5395;
+               vtbl_entry = ROBO_VTBL_ENTRY_5395;
+       } else {
+               vtbl_access = ROBO_VTBL_ACCESS;
+               vtbl_index = ROBO_VTBL_INDX;
+               vtbl_entry = ROBO_VTBL_ENTRY;
+       }
+
+       for (j = 0; j <= VLAN_ID_MAX; j++) {
+               /* write config now */
+               robo_write32(ROBO_ARLIO_PAGE, vtbl_entry, 0);
+               robo_write16(ROBO_ARLIO_PAGE, vtbl_index, j);
+               robo_write16(ROBO_ARLIO_PAGE, vtbl_access, 1 << 7);
+       }
+}
+
+static int handle_reset(void *driver, char *buf, int nr)
+{
+       int j;
+       switch_driver *d = (switch_driver *) driver;
+
+       /* disable switching */
+       set_switch(0);
+
+       if (robo.devid != ROBO_DEVICE_ID_5325)
+               handle_reset_new(d, buf, nr);
+       else
+               handle_reset_old(d, buf, nr);
 
        /* reset ports to a known good state */
        for (j = 0; j < d->ports; j++) {
@@ -813,6 +863,10 @@ static int __init robo_init(void)
                        driver.ports = 9;
                        driver.cpuport = 8;
                }
+               if (robo.is_5365)
+                       snprintf(driver.dev_name, SWITCH_NAME_BUFSZ, "BCM5365");
+               else
+                       snprintf(driver.dev_name, SWITCH_NAME_BUFSZ, "BCM5%s%x", robo.devid & 0xff00 ? "" : "3", robo.devid);
 
                return switch_register_driver(&driver);
        }