ramips: mt7621: support openwrt,netdev-name for renaming interfaces
authorRobert Marko <robimarko@gmail.com>
Sun, 24 Nov 2024 20:15:08 +0000 (21:15 +0100)
committerRobert Marko <robimarko@gmail.com>
Mon, 25 Nov 2024 15:41:30 +0000 (16:41 +0100)
Edgerouter X currently has its eth1 port on the switch missing since there
is a naming conflict currently.

So, as the root cause is mixing kernel support for DSA interfaces having
predictable names set via "label" property vs others having it assigned
dynamically lets avoid the conflict by using our own custom property as
suggested upstream [1].

So, add support via "openwrt,netdev-name" property and use it on ERX.

Fixes: 2a25c6ace8d8 ("ramips: get rid of downstream network device label patch")
Fixes: #15643
Link: https://github.com/openwrt/openwrt/pull/17062
Signed-off-by: Robert Marko <robimarko@gmail.com>
target/linux/ramips/dts/mt7621_ubnt_edgerouter-x-sfp.dts
target/linux/ramips/dts/mt7621_ubnt_edgerouter-x.dts
target/linux/ramips/dts/mt7621_ubnt_edgerouter-x.dtsi
target/linux/ramips/mt7621/base-files/lib/preinit/04_set_netdev_label

index 50a77c3877a055d39c1a14267dfb89aa62f0c781..9f1e0a8d20c675cd18d1fa8de8e2f575fe83e847 100644 (file)
        ports {
                port@5 {
                        reg = <5>;
-                       label = "eth5";
+                       openwrt,netdev-name = "eth5";
                        phy-handle = <&ephy7>;
                        phy-mode = "rgmii-rxid";
                        nvmem-cells = <&macaddr_factory_22 5>;
                        nvmem-cell-names = "mac-address";
+                       /delete-property/ label;
                };
        };
 };
index 80467c88e98343b99e246400b4da3256e2d14b1e..c0230e13b42393908982af2158c450a4b0c31c45 100644 (file)
@@ -7,7 +7,7 @@
 
 &gmac1 {
        status = "okay";
-       label = "eth0";
+       openwrt,netdev-name = "eth0";
        phy-handle = <&ethphy0>;
 
        nvmem-cells = <&macaddr_factory_22 0>;
index dc9908ba34c6a1006187dd9287bc125bf2e947a3..40433c1c43b23d84728e2693fdfb42d92ca6151e 100644 (file)
 &gmac0 {
        nvmem-cells = <&macaddr_factory_22 0>;
        nvmem-cell-names = "mac-address";
-       label = "dsa";
+       openwrt,netdev-name = "dsa";
 };
 
 &switch0 {
        ports {
                port@0 {
                        status = "okay";
-                       label = "eth0";
+                       openwrt,netdev-name = "eth0";
+                       /delete-property/ label;
                };
 
                port@1 {
                        status = "okay";
-                       label = "eth1";
+                       openwrt,netdev-name = "eth1";
                        nvmem-cells = <&macaddr_factory_22 1>;
                        nvmem-cell-names = "mac-address";
+                       /delete-property/ label;
                };
 
                port@2 {
                        status = "okay";
-                       label = "eth2";
+                       openwrt,netdev-name = "eth2";
                        nvmem-cells = <&macaddr_factory_22 2>;
                        nvmem-cell-names = "mac-address";
+                       /delete-property/ label;
                };
 
                port@3 {
                        status = "okay";
-                       label = "eth3";
+                       openwrt,netdev-name = "eth3";
                        nvmem-cells = <&macaddr_factory_22 3>;
                        nvmem-cell-names = "mac-address";
+                       /delete-property/ label;
                };
 
                port@4 {
                        status = "okay";
-                       label = "eth4";
+                       openwrt,netdev-name = "eth4";
                        nvmem-cells = <&macaddr_factory_22 4>;
                        nvmem-cell-names = "mac-address";
+                       /delete-property/ label;
                };
        };
 };
index 110e023b962d3dfb86883d7bd840458ecece67ce..2c5e420f93bd17b4f2340edc32b88610a7b5fd90 100644 (file)
@@ -10,6 +10,14 @@ set_netdev_labels() {
                [ "$netdev" = "$label" ] && continue
                ip link set "$netdev" name "$label"
        done
+
+       for dir in /sys/class/net/*; do
+               [ -r "$dir/of_node/openwrt,netdev-name" ] || continue
+               read -r label < "$dir/of_node/openwrt,netdev-name"
+               netdev="${dir##*/}"
+               [ "$netdev" = "$label" ] && continue
+               ip link set "$netdev" name "$label"
+       done
 }
 
 boot_hook_add preinit_main set_netdev_labels