Skip to content

Commit

Permalink
arm: dts: add second gmac
Browse files Browse the repository at this point in the history
use it with vlan-aware bridge

- create a bridge for use for wan

/etc/systemd/network/11-wanbr.netdev
[NetDev]
Name=wanbr
Kind=bridge

[Bridge]
DefaultPVID=0 # should be different to other vlan-aware bridges (like lanbr)
VLANFiltering=1

- map aux and wan to vlan-aware bridge
- traffic will be tagged inside with vlan-id 99

/etc/systemd/network/12-wan-bind.network
[Match]
Name=wan aux

[Link]
RequiredForOnline=no

[Network]
BindCarrier=eth0
Bridge=wanbr

[BridgeVLAN]
VLAN=99
PVID=99
EgressUntagged=99

- configure eth1 as wan

/etc/systemd/network/15-wan.network
[Match]
Name=eth1

[Network]
BindCarrier=eth0

Address=192.168.0.18/24
Gateway=192.168.0.10
DNS=192.168.0.10

IPForward=yes
  • Loading branch information
frank-w committed Dec 14, 2022
1 parent 5cff381 commit c92b648
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts
Expand Up @@ -186,6 +186,18 @@
};
};

gmac1: mac@1 {
compatible = "mediatek,eth-mac";
reg = <1>;
phy-mode = "rgmii";

fixed-link {
speed = <1000>;
full-duplex;
pause;
};
};

mdio: mdio-bus {
#address-cells = <1>;
#size-cells = <0>;
Expand Down Expand Up @@ -226,6 +238,18 @@
label = "lan3";
};

port@5 {
reg = <5>;
label = "aux";
phy-mode = "rgmii";

fixed-link {
speed = <1000>;
full-duplex;
pause;
};
};

port@6 {
reg = <6>;
label = "cpu";
Expand Down

14 comments on commit c92b648

@arinc9
Copy link
Contributor

@arinc9 arinc9 commented on c92b648 Jan 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @frank-w is this patch for offloading wan traffic to eth1?

@frank-w
Copy link
Owner Author

@frank-w frank-w commented on c92b648 Jan 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this makes Port 5 acessable from userspace to create the vlan-aware Bridge to byass dsa for wan (or other Ports) and map them to eth1...it is No offloading in Terms of hw acceleration

@arinc9
Copy link
Contributor

@arinc9 arinc9 commented on c92b648 Jan 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frank-w Here's what I understand. Port 5 is supposed to be a CPU port, however, by making it a user port, it will be a slave of gmac0 which is wired to port 6's gmac. Because port 5's gmac is wired to gmac1, any frames sent to the slave interface of port 5, aux, will appear on eth1, the interface of gmac1. Since there's bridge offloading on the MT7530 DSA subdriver, frames between interfaces will be offloaded to switch hardware so it won't exhaust the port 6 - gmac0 link.

             CPU
      ┌───────────────┐
      │ gmac1 │ gmac0 │
      └───┼───────┼───┘
          │       │
          └──┐ ┌──┘
  ┌──────────┼─┼┐
  │0 1 2 3 4 5 6│ MT7530
  └┼─┼─┼─┼─┼────┘
   │ │ │ │ └────────────────┐
   │ │ │ └───────────┐      │
   │ │ └───────┐     │      │
   │ └───┐     │     │      │
┌──┼─────┼─────┼─────┼──────┼──┐
│ Wan | Lan0  Lan1  Lan2  Lan3 |
└──────────────────────────────┘

I gotta say, this is very smart. I wonder if this would work on other DSA subdrivers. I'll do some tests on my Marvell DSA switch.

@arinc9
Copy link
Contributor

@arinc9 arinc9 commented on c92b648 Jan 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this on a BPI-R2 running 6.2.0-rc1 (with your build script and uart patches) with your Debian 10 rootfs.
Works fine. Although I didn't enable vlan_filtering or set vlan_default_pvid to 0 on the bridge.
The bridge does not drop the VLAN tagged frames between aux and wan as long as vlan_filtering is off. So VLAN tagged traffic between eth1 and computer connected to wan port is completely transparent.

@frank-w
Copy link
Owner Author

@frank-w frank-w commented on c92b648 Jan 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was the example mtk gave me to use second gmac without patching dsa core. maybe vlan_filtering is only needed if you want to use the vlan outside the bridge too (create tagged frames outside of it).

but good to know it still works...have not tried it again in 6.1 as i still try to get r3 vlan working...

@arinc9
Copy link
Contributor

@arinc9 arinc9 commented on c92b648 Jan 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this is useful, there's no need to do this on MT7530 switch since it supports muxing phy0/4 to its gmac5.
I intend to submit this to mainline:

diff --git a/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts b/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts
index 5008115d2494..7e39a7a53901 100644
--- a/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts
+++ b/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts
@@ -186,13 +186,24 @@ fixed-link {
 		};
 	};
 
+	gmac1: mac@1 {
+		compatible = "mediatek,eth-mac";
+		reg = <1>;
+		phy-mode = "rgmii";
+		phy-handle = <&ethphy0>;
+	};
+
 	mdio: mdio-bus {
 		#address-cells = <1>;
 		#size-cells = <0>;
 
-		switch@0 {
-			compatible = "mediatek,mt7530";
+		ethphy0: ethernet-phy@0 {
 			reg = <0>;
+		};
+
+		switch@1f {
+			compatible = "mediatek,mt7530";
+			reg = <0x1f>;
 			reset-gpios = <&pio 33 0>;
 			core-supply = <&mt6323_vpa_reg>;
 			io-supply = <&mt6323_vemc3v3_reg>;
@@ -201,11 +212,6 @@ ports {
 				#address-cells = <1>;
 				#size-cells = <0>;
 
-				port@0 {
-					reg = <0>;
-					label = "wan";
-				};
-
 				port@1 {
 					reg = <1>;
 					label = "lan0";

Also do you plan to submit 5cff381 to mainline? Serial won't work without it.

@frank-w
Copy link
Owner Author

@frank-w frank-w commented on c92b648 Jan 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should not drop wan-port in mainline also not if using gmac2 for it fixed by dts...this will break existing systems

for the serial-change...i only reordered the uarts so that uart2 (the debug-uart is found first and mapped to ttyS0)...by default this uart is ttyS2 and dts alias section or bootloader should point to it...i made this change to keep it compatible with vendor kernel

@arinc9
Copy link
Contributor

@arinc9 arinc9 commented on c92b648 Jan 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should not drop wan-port in mainline also not if using gmac2 for it fixed by dts...this will break existing systems

The only issue I see is the interface name will change from wan to eth1. That's nothing compared to gaining 2 Gbps routing in total on the device, in my opinion.

for the serial-change...i only reordered the uarts so that uart2 (the debug-uart is found first and mapped to ttyS0)...by default this uart is ttyS2 and dts alias section or bootloader should point to it...i made this change to keep it compatible with vendor kernel

If I understand correctly, vendor kernel uses ttyS0 for console compared to mainline using ttyS2? Your patch here changes that back to ttyS0 so the bootloader can boot both kernels with console working?

@frank-w
Copy link
Owner Author

@frank-w frank-w commented on c92b648 Jan 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,Interface Name will Change and so it Breaks existing userspace settings (Network config,Netfilter)

There is No Mainline Image,only Code and there should be Default bootargs pointing to uart2 or a serial0 alias,so without bootargs in bootloader it should work. But bpi Images have ttyS0 set as bootargs,so this is overridden

@arinc9
Copy link
Contributor

@arinc9 arinc9 commented on c92b648 Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,Interface Name will Change and so it Breaks existing userspace settings (Network config,Netfilter)

Understood. They will have to update their userspace configuration on newer kernels if this goes through. I'll submit the patch and hear everyone's thoughts.

There is No Mainline Image,only Code and there should be Default bootargs pointing to uart2 or a serial0 alias,so without bootargs in bootloader it should work. But bpi Images have ttyS0 set as bootargs,so this is overridden

Thanks, I just removed console= from bootargs and console works fine without swapping uart. As a side effect, now I also see debian stuff starting with [ OK ].

@arinc9
Copy link
Contributor

@arinc9 arinc9 commented on c92b648 Jan 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to ask here, I assume this is you. Were you able to fix this other than pre-up post-down commands?

https://unix.stackexchange.com/questions/629714/buildroot-adding-bridge-via-interfaces

@frank-w
Copy link
Owner Author

@frank-w frank-w commented on c92b648 Jan 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No,did not get it working with standard-syntax i know from debian.

@arinc9
Copy link
Contributor

@arinc9 arinc9 commented on c92b648 Jan 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the ifup ifdown commands don't include the the bridge extensions to the standard interfaces(5) file format.
ifup/ifdown won't do anything with bridge_ports option, for example. Installing bridge-utils or ifupdown doesn't help.

I'm going to ask the buildroot mailing list. If nothing works, I'll check NetworkManager.

@arinc9
Copy link
Contributor

@arinc9 arinc9 commented on c92b648 Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For anyone else seeing this page mentioning the issue with buildroot, there's progress:

https://bugs.busybox.net/show_bug.cgi?id=13466#c4

Please sign in to comment.