Failed to connect to the switch, trying to get the MT7621 switch working on

I'm using OpenWrt 22.03.4, and added switch0 to /etc/board.d/02_network:

ramips_setup_interfaces()
{
        local board="$1"

        case $board in
        my-board)
                ucidef_add_switch "switch0" \
                        "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6u@eth0" "5u@wan"
                ;;
        ...
}
...
  1. Run sh /bin/board_detect generate /etc/board.json:
# cat /etc/board.json
{
        "model": { ... },
        "switch": {
                "switch0": {
                        "enable": true,
                        "reset": true,
                        "ports": [
                                {
                                        "num": 1,
                                        "role": "lan"
                                },
                                {
                                        "num": 2,
                                        "role": "lan"
                                },
                                {
                                        "num": 3,
                                        "role": "lan"
                                },
                                {
                                        "num": 4,
                                        "role": "lan"
                                },
                                {
                                        "num": 0,
                                        "role": "wan"
                                },
                                {
                                        "num": 6,
                                        "device": "eth0",
                                        "need_tag": false,
                                        "want_untag": true
                                },
                                {
                                        "num": 5,
                                        "device": "wan",
                                        "need_tag": false,
                                        "want_untag": true
                                }
                        ],
                        "roles": [
                                {
                                        "role": "lan",
                                        "ports": "1 2 3 4 6",
                                        "device": "eth0"
                                },
                                {
                                        "role": "wan",
                                        "ports": "0 5",
                                        "device": "wan"
                                }
                        ]
                }
        },
        "network": {
                "lan": {
                        "device": "eth0",
                        "protocol": "static"
                },
                "wan": {
                        "device": "wan",
                        "protocol": "dhcp"
                }
        },
        "system": {
                "hostname": "foo"
        }
}
  1. Run swconfig list, nothing is output:
# swconfig list
  1. The openwrt generate network config as follows:
# cat /etc/config/network

config interface 'loopback'
        option device 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'auto'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0'

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option ipaddr '192.168.77.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config interface 'wan'
        option device 'wan'
        option proto 'dhcp'

config interface 'wan6'
        option device 'wan'
        option proto 'dhcpv6'

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '1'

config switch_vlan
        option device 'switch0'
        option vlan '1'
        option ports '1 2 3 4 6'

config switch_vlan
        option device 'switch0'
        option vlan '2'
        option ports '0 5'
  1. Run /etc/init.d/network restart got an error:
# /etc/init.d/network restart
...
Failed to connect to the switch. Use the "list" command to see which switches are available.
...

The device ethernet list:

# ifconfig
br-lan    Link encap:Ethernet  HWaddr 46:0E:70:E2:D3:E2
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1504  Metric:1
          ...

eth0      Link encap:Ethernet  HWaddr 46:0E:70:E2:D3:E2
          UP BROADCAST RUNNING MULTICAST  MTU:1504  Metric:1
          ...

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          ...

wan       Link encap:Ethernet  HWaddr 6E:6C:0B:D2:F4:BE
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          ...

I simply configured switch0 to /etc/config/network:

# cat /etc/config/network

config interface 'loopback'
        option device 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'auto'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0'

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config interface 'wan'
        option device 'wan'
        option proto 'dhcp'

config interface 'wan6'
        option device 'wan'
        option proto 'dhcpv6'

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '1'

Run /etc/init.d/network restart, still got an error:

Failed to connect to the switch. Use the "list" command to see which switches are available.

Is the config wrong? how to solve this issue?

Your device uses DSA driver instead of swconfig driver for switch. swconfig command is for swconfig drivers and not for DSA drivers.

Oh, I saw the .config CONFIG_PACKAGE_kmod-swconfig is disabled:

# CONFIG_PACKAGE_kmod-swconfig is not set
CONFIG_PACKAGE_swconfig=y

I'll try enabling CONFIG_PACKAGE_kmod-swconfig.

Note: DSA should be used for all new devices added to OpenWrt in the future that have a switch supported by DSA...

I compiled CONFIG_PACKAGE_kmod-swconfig into the kernel and burned it into the device:

# lsmod | fgrep sw
swconfig               10813  0

Use simple network config:

# cat /etc/config/network

config interface 'loopback'
        option device 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'auto'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0'

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config interface 'wan'
        option device 'wan'
        option proto 'dhcp'

config interface 'wan6'
        option device 'wan'
        option proto 'dhcpv6'

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '1'

Run /etc/init.d/network restart, got an error:

# /etc/init.d/network restart
...
Failed to connect to the switch. Use the "list" command to see which switches are available.
...

Is there a kernel driver that isn't compiled in?

The device use MT7621 CPU, this is dts:

&gmac0 {
        nvmem-cells = <&macaddr_factory_e000>;
        nvmem-cell-names = "mac-address";
};

&gmac1 {
        status = "okay";
        label = "wan";
        phy-handle = <&ethphy0>;

        nvmem-cells = <&macaddr_factory_e006>;
        nvmem-cell-names = "mac-address";
        mac-address-increment = <1>;
};

&mdio {
        ethphy0: ethernet-phy@0 {
                reg = <0>;
        };
};

&switch0 {
        status = "okay";

        ports {
                port@1 {
                        status = "okay";
                        label = "lan1";
                };

                port@2 {
                        status = "okay";
                        label = "lan2";
                };

                port@3 {
                        status = "okay";
                        label = "lan3";
                };

                port@4 {
                        status = "okay";
                        label = "lan4";
                };
        };
};

I try to install iproute2, but .config not found iproute2

Hi @musashino , I see that openwrt MT76x8 call ucidef_add_switch to generate switch0:

Also see that openwrt MT7621 is call ucidef_set_interfaces_lan_wan function , is openwrt doesn't have support for mt7621 CPU switch yet?

If you are using mt7621.dtsi as a base of your .dts, and if your base is 21.02 or newer, then you shouldn't use swconfig at all. This is one of the first targets OpenWRT transitioned to DSA.

Instad in board.d/02_network you use:

		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"

in ip link you should see:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1504 ...
3: wan: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 ...
4: lan4@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 ...
5: lan3@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 ...
6: lan2@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
7: lan1@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...

So: you should not use eth0 at all, and instead configure everything using lan* and wan interfaces.

2 Likes

Oh, now I get it. Thank you.

I use board.d/02_network:

		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"

Switch is work fine.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.