DIR-300 B1, how to reset switch after boot?

Hi all,
there is a way to reset the switch after booting?

OpenWrt 15.05.1 and LEDE 17.01.3 have a bug on boot with DIR-300 B1 so after boot I always unplug and reconnect the LAN cable.

Thanks

# swconfig dev switch0 set reset 1

But it might do just "nothing". Interestingly, the ramips target's 7_set_preinit_iface_ramips boot script should do that already.

https://github.com/lede-project/source/blob/master/target/linux/ramips/base-files/lib/preinit/07_set_preinit_iface_ramips

so, isn't that working?

Have you reported this regression on bugs.lede-project.org ?

1 Like

@chunkeey
Thanks I have done more tests and seems that the problem is also with dir-615 h1

On wan side I have a server dhcp active and when dir-300 b1/dir-615 h1 are booting all clients on lan take IP addresses from wan dhcp server, after boot no one have connection.

With this I can't access anymore to dir-300 :frowning:

I have tested this problem on OpenWrt 15.05.1 and LEDE 17.01.1-2-3
DD-WRT and stock firmware are OK

With LEDE 17.01.3 safemode finaly works (SSH and not telnet).

Wait, this sounds more like WAN<->LAN leakage. There's already a bug report about it with a patch for the mt7530:

That's understandable. Doing a reset will wipe out the VLAN configuration too.
Nothing will be getting to/from the CPU-port. I don't think that there's a dedicated

The question is, does the reset trigger a disconnect event (link down / dhcp search)
on the clients?

1 Like

Yes is exactly what happens with DIR-300 B1 (RT3050) and DIR-615 H1 (RT3352).

Yes, clients disconnects and after a second take IP from wan.
Then devices are not reachable and I have to restart them.

I found a temporary solution, add to /etc/rc.local

ifconfig eth0.1 down
sleep 10
ifconfig eth0.1 up

Many thanks for your help Christian.

1 Like

Hi,

I fixed this bug in the device driver a few months ago primarily to fix the following issues:

  1. support 1000Mbps
  2. prevent lan-wan leak
  3. fix the issue in which lan PC may acquire a WAN IP from dhcp (this happens at boot b/c of #2)

Someone, please submit it upstream to a Lede developer. thanks,

TP

------ target/linux/ramips/files/drivers/net/ethernet/ralink/gsw_mt7620a.c
@@ -43,6 +43,8 @@
 #include <ralink_regs.h>
 #include <asm/mach-ralink/mt7620.h>
 
+#include <gpio.h>
+
 #include "ralink_soc_eth.h"
 #include "gsw_mt7620a.h"
 #include "mt7530.h"
@@ -469,10 +471,57 @@ void mt7620_port_init(struct fe_priv *priv, struct device_node *np)
 	}
 }
 
+static void reset_mt7530_gsw(struct mt7620_gsw *gsw)
+{
+	u32 val;
+	int active_low = 0;
+	int reset_gpio = 10;
+	int delay=100000;
+	printk("mt7530: entering reset gws\r\n");
+	if (!gpio_request(reset_gpio, "gsw-reset")) {
+		printk("mt7530: reseting gws\r\n");
+        gpio_direction_output(reset_gpio, active_low ? 1 : 0);
+        udelay(delay);
+        gpio_set_value(reset_gpio, active_low ? 0 : 1);
+        udelay(delay);
+        gpio_set_value(reset_gpio, active_low ? 1 : 0);
+        udelay(delay);
+        gpio_set_value(reset_gpio, active_low ? 0 : 1);
+        udelay(125000);
+     }
+//#ifdef _notuse_
+    if ((rt_sysc_r32(SYSC_REG_CHIP_REV_ID) & 0xFFFF) == 0x0101) {
+        /* (GE1, Force 1000M/FD, FC ON) */
+        gsw_w32(gsw, 0x2005e30b, 0x100);
+        mt7530_mdio_w32(gsw, 0x3600, 0x5e30b); // use 0x5e337 for force link;
+    } else {
+        /* (GE1, Force 1000M/FD, FC ON) */
+        gsw_w32(gsw, 0x2005e33b, 0x100);
+        mt7530_mdio_w32(gsw, 0x3600, 0x5e33b);  // use 0x5e337 for 100mb Force link;
+    }
+
+    /* (GE2, Link down) */
+    gsw_w32(gsw, 0x8000, 0x200);
+
+    //val = 0x117ccf; //Enable Port 6, P5 as GMAC5, P5 disable
+    val = mt7530_mdio_r32(gsw, 0x7804);
+    val &= ~(1<<8); //Enable Port 6
+    val |= (1<<6); //Disable Port 5
+    val |= (1<<13); //Port 5 as GMAC, no Internal PHY
+
+	val |= (1<<16);//change HW-TRAP
+	printk("change HW-TRAP to 0x%x\n", val);
+	mt7530_mdio_w32(gsw, 0x7804, val);
+//#endif
+}
+
 static void gsw_hw_init_mt7620(struct mt7620_gsw *gsw, struct device_node *np)
 {
 	u32 is_BGA = mt7620_is_bga();
 
+	// pham: reset the external switch
+	reset_mt7530_gsw(gsw);
+
 	rt_sysc_w32(rt_sysc_r32(SYSC_REG_CFG1) | BIT(8), SYSC_REG_CFG1);
 	gsw_w32(gsw, gsw_r32(gsw, GSW_REG_CKGCR) & ~(0x3 << 4), GSW_REG_CKGCR);
1 Like

As not said does not work, some PC does not change IP :rage:

@tpham3783
Thanks for your patch, is valid only for mt7620 devices?

There's another way but this will require something like this phytool:

(any utility will do, as long as it uses SIOCGMIIREG ioctl to access the MDIO).

Each (physical) port of the switch is represented as a standard ethernet PHY on the MDIO. You can put each port into BMCR_PDOWN (0x0800) | BMCR_ISOLATE (0x0400) state. This should disable the link (in the same way as physicallly removing the ethernet cable would).

Then, you can reenable the port by clearing the PDOWN and ISOLATE flags and optionally restart the autonegotation by writing BMCR_ANENABLE (0x1000) | BMCR_ANRESTART (0x0200).

Thanks Christian but this is too difficult for me :pensive:

This problem could be solved in boot loader configuration, e.g. for UBoot:

  • Run uboot configuration using make menuconfig
  • Enable Partition LAN/WAN
  • Choose W/LLLL for LAN/WAN Board Layout

Then you should compile and reflash uboot on your router.

1 Like

Thanks!
Tomorrow I will try and let you know