diff mbox series

[v3,2/2] iproute2: add support for cpu set

Message ID 20220203004412.19866-3-ansuelsmth@gmail.com
State Superseded
Delegated to: Ansuel Smith
Headers show
Series Add DSA MultiCPU port support | expand

Commit Message

Christian Marangi Feb. 3, 2022, 12:44 a.m. UTC
Add support for cpu set useful to set CPU port for dsa devices.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
 ...101-iplink_allow_to_change_cpu_value.patch | 81 +++++++++++++++++++
 1 file changed, 81 insertions(+)
 create mode 100644 package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch

Comments

Daniel Golle Feb. 20, 2022, 7:44 p.m. UTC | #1
On Thu, Feb 03, 2022 at 01:44:12AM +0100, Ansuel Smith wrote:
> Add support for cpu set useful to set CPU port for dsa devices.

Please also document the newly added 'cpu' parameter in the command-
line output -- the manpage isn't even installed/available for OpenWrt
users.

> 
> Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
> ---
>  ...101-iplink_allow_to_change_cpu_value.patch | 81 +++++++++++++++++++
>  1 file changed, 81 insertions(+)
>  create mode 100644 package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch
> 
> diff --git a/package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch b/package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch
> new file mode 100644
> index 00000000..1bb2bb1f
> --- /dev/null
> +++ b/package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch
> @@ -0,0 +1,81 @@
> +From 8642516618b60a2827215f2bed54d4d0aa1da48a Mon Sep 17 00:00:00 2001
> +From: Ansuel Smith <ansuelsmth@gmail.com>
> +Date: Sun, 23 Jan 2022 00:31:49 +0100
> +Subject: [PATCH] iplink: allow to change cpu of dsa device
> +
> +Allow to change the cpu port linked to a given dsa interface.
> +This is useful in the case of multi-CPU port DSA to assign the correct
> +port to the different user ports.
> +
> +Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
> +---
> + include/uapi/linux/if_link.h | 1 +
> + ip/iplink.c                  | 7 +++++++
> + man/man8/ip-link.8.in        | 7 +++++++
> + 3 files changed, 15 insertions(+)
> +
> +diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
> +index 41708e26..901b5544 100644
> +--- a/include/uapi/linux/if_link.h
> ++++ b/include/uapi/linux/if_link.h
> +@@ -341,6 +341,7 @@ enum {
> + 	IFLA_ALT_IFNAME, /* Alternative ifname */
> + 	IFLA_PERM_ADDRESS,
> + 	IFLA_PROTO_DOWN_REASON,
> ++	IFLA_CPU,
> + 
> + 	/* device (sysfs) name as parent, used instead
> + 	 * of IFLA_LINK where there's no parent netdev
> +diff --git a/ip/iplink.c b/ip/iplink.c
> +index a3ea775d..254c35c5 100644
> +--- a/ip/iplink.c
> ++++ b/ip/iplink.c
> +@@ -595,6 +595,7 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
> + 	int index = 0;
> + 	int group = -1;
> + 	int addr_len = 0;
> ++	int cpu = -1;
> + 	int err;
> + 
> + 	ret = argc;
> +@@ -625,6 +626,12 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
> + 		} else if (matches(*argv, "link") == 0) {
> + 			NEXT_ARG();
> + 			link = *argv;
> ++		} else if (matches(*argv, "cpu") == 0) {
> ++			NEXT_ARG();
> ++			cpu = ll_name_to_index(*argv);
> ++			if (!cpu)
> ++				return nodev(*argv);
> ++			addattr32(&req->n, sizeof(*req), IFLA_CPU, cpu);
> + 		} else if (matches(*argv, "address") == 0) {
> + 			NEXT_ARG();
> + 			addr_len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
> +diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
> +index 19a0c9ca..406db8ad 100644
> +--- a/man/man8/ip-link.8.in
> ++++ b/man/man8/ip-link.8.in
> +@@ -152,6 +152,9 @@ ip-link \- network device configuration
> + .br
> + .RB "[ " nomaster " ]"
> + .br
> ++.RB "[ " cpu
> ++.IR DEVICE " ]"
> ++.br
> + .RB "[ " vrf
> + .IR NAME " ]"
> + .br
> +@@ -2299,6 +2302,10 @@ set master device of the device (enslave device).
> + .BI nomaster
> + unset master device of the device (release device).
> + 
> ++.TP
> ++.BI cpu " DEVICE"
> ++set cpu device of the dsa device.
> ++
> + .TP
> + .BI addrgenmode " eui64|none|stable_secret|random"
> + set the IPv6 address generation mode
> +-- 
> +2.33.1
> +
> -- 
> 2.34.1
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Christian Marangi Feb. 21, 2022, 12:37 a.m. UTC | #2
>
> On Thu, Feb 03, 2022 at 01:44:12AM +0100, Ansuel Smith wrote:
> > Add support for cpu set useful to set CPU port for dsa devices.
>
> Please also document the newly added 'cpu' parameter in the command-
> line output -- the manpage isn't even installed/available for OpenWrt
> users.
>

Should I wait for other review or should I send v3?

> >
> > Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
> > ---
> >  ...101-iplink_allow_to_change_cpu_value.patch | 81 +++++++++++++++++++
> >  1 file changed, 81 insertions(+)
> >  create mode 100644 package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch
> >
> > diff --git a/package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch b/package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch
> > new file mode 100644
> > index 00000000..1bb2bb1f
> > --- /dev/null
> > +++ b/package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch
> > @@ -0,0 +1,81 @@
> > +From 8642516618b60a2827215f2bed54d4d0aa1da48a Mon Sep 17 00:00:00 2001
> > +From: Ansuel Smith <ansuelsmth@gmail.com>
> > +Date: Sun, 23 Jan 2022 00:31:49 +0100
> > +Subject: [PATCH] iplink: allow to change cpu of dsa device
> > +
> > +Allow to change the cpu port linked to a given dsa interface.
> > +This is useful in the case of multi-CPU port DSA to assign the correct
> > +port to the different user ports.
> > +
> > +Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
> > +---
> > + include/uapi/linux/if_link.h | 1 +
> > + ip/iplink.c                  | 7 +++++++
> > + man/man8/ip-link.8.in        | 7 +++++++
> > + 3 files changed, 15 insertions(+)
> > +
> > +diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
> > +index 41708e26..901b5544 100644
> > +--- a/include/uapi/linux/if_link.h
> > ++++ b/include/uapi/linux/if_link.h
> > +@@ -341,6 +341,7 @@ enum {
> > +     IFLA_ALT_IFNAME, /* Alternative ifname */
> > +     IFLA_PERM_ADDRESS,
> > +     IFLA_PROTO_DOWN_REASON,
> > ++    IFLA_CPU,
> > +
> > +     /* device (sysfs) name as parent, used instead
> > +      * of IFLA_LINK where there's no parent netdev
> > +diff --git a/ip/iplink.c b/ip/iplink.c
> > +index a3ea775d..254c35c5 100644
> > +--- a/ip/iplink.c
> > ++++ b/ip/iplink.c
> > +@@ -595,6 +595,7 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
> > +     int index = 0;
> > +     int group = -1;
> > +     int addr_len = 0;
> > ++    int cpu = -1;
> > +     int err;
> > +
> > +     ret = argc;
> > +@@ -625,6 +626,12 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
> > +             } else if (matches(*argv, "link") == 0) {
> > +                     NEXT_ARG();
> > +                     link = *argv;
> > ++            } else if (matches(*argv, "cpu") == 0) {
> > ++                    NEXT_ARG();
> > ++                    cpu = ll_name_to_index(*argv);
> > ++                    if (!cpu)
> > ++                            return nodev(*argv);
> > ++                    addattr32(&req->n, sizeof(*req), IFLA_CPU, cpu);
> > +             } else if (matches(*argv, "address") == 0) {
> > +                     NEXT_ARG();
> > +                     addr_len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
> > +diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
> > +index 19a0c9ca..406db8ad 100644
> > +--- a/man/man8/ip-link.8.in
> > ++++ b/man/man8/ip-link.8.in
> > +@@ -152,6 +152,9 @@ ip-link \- network device configuration
> > + .br
> > + .RB "[ " nomaster " ]"
> > + .br
> > ++.RB "[ " cpu
> > ++.IR DEVICE " ]"
> > ++.br
> > + .RB "[ " vrf
> > + .IR NAME " ]"
> > + .br
> > +@@ -2299,6 +2302,10 @@ set master device of the device (enslave device).
> > + .BI nomaster
> > + unset master device of the device (release device).
> > +
> > ++.TP
> > ++.BI cpu " DEVICE"
> > ++set cpu device of the dsa device.
> > ++
> > + .TP
> > + .BI addrgenmode " eui64|none|stable_secret|random"
> > + set the IPv6 address generation mode
> > +--
> > +2.33.1
> > +
> > --
> > 2.34.1
> >
> >
> > _______________________________________________
> > openwrt-devel mailing list
> > openwrt-devel@lists.openwrt.org
> > https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Daniel Golle Feb. 21, 2022, 2:30 a.m. UTC | #3
On Mon, Feb 21, 2022 at 01:37:10AM +0100, Ansuel Smith wrote:
> >
> > On Thu, Feb 03, 2022 at 01:44:12AM +0100, Ansuel Smith wrote:
> > > Add support for cpu set useful to set CPU port for dsa devices.
> >
> > Please also document the newly added 'cpu' parameter in the command-
> > line output -- the manpage isn't even installed/available for OpenWrt
> > users.
> >
> 
> Should I wait for other review or should I send v3?

Give it a test-run and make sure
ip link XXX set cpu YYY
actually works -- when I tried it gave me
RTNETLINK answers: Not supported
eventhough the DSA driver does set the .port_change_cpu_port
function. If it works for you with whatever DSA driver you are trying
with, I will figure why it didn't work on MT7530...


> 
> > >
> > > Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
> > > ---
> > >  ...101-iplink_allow_to_change_cpu_value.patch | 81 +++++++++++++++++++
> > >  1 file changed, 81 insertions(+)
> > >  create mode 100644 package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch
> > >
> > > diff --git a/package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch b/package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch
> > > new file mode 100644
> > > index 00000000..1bb2bb1f
> > > --- /dev/null
> > > +++ b/package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch
> > > @@ -0,0 +1,81 @@
> > > +From 8642516618b60a2827215f2bed54d4d0aa1da48a Mon Sep 17 00:00:00 2001
> > > +From: Ansuel Smith <ansuelsmth@gmail.com>
> > > +Date: Sun, 23 Jan 2022 00:31:49 +0100
> > > +Subject: [PATCH] iplink: allow to change cpu of dsa device
> > > +
> > > +Allow to change the cpu port linked to a given dsa interface.
> > > +This is useful in the case of multi-CPU port DSA to assign the correct
> > > +port to the different user ports.
> > > +
> > > +Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
> > > +---
> > > + include/uapi/linux/if_link.h | 1 +
> > > + ip/iplink.c                  | 7 +++++++
> > > + man/man8/ip-link.8.in        | 7 +++++++
> > > + 3 files changed, 15 insertions(+)
> > > +
> > > +diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
> > > +index 41708e26..901b5544 100644
> > > +--- a/include/uapi/linux/if_link.h
> > > ++++ b/include/uapi/linux/if_link.h
> > > +@@ -341,6 +341,7 @@ enum {
> > > +     IFLA_ALT_IFNAME, /* Alternative ifname */
> > > +     IFLA_PERM_ADDRESS,
> > > +     IFLA_PROTO_DOWN_REASON,
> > > ++    IFLA_CPU,
> > > +
> > > +     /* device (sysfs) name as parent, used instead
> > > +      * of IFLA_LINK where there's no parent netdev
> > > +diff --git a/ip/iplink.c b/ip/iplink.c
> > > +index a3ea775d..254c35c5 100644
> > > +--- a/ip/iplink.c
> > > ++++ b/ip/iplink.c
> > > +@@ -595,6 +595,7 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
> > > +     int index = 0;
> > > +     int group = -1;
> > > +     int addr_len = 0;
> > > ++    int cpu = -1;
> > > +     int err;
> > > +
> > > +     ret = argc;
> > > +@@ -625,6 +626,12 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
> > > +             } else if (matches(*argv, "link") == 0) {
> > > +                     NEXT_ARG();
> > > +                     link = *argv;
> > > ++            } else if (matches(*argv, "cpu") == 0) {
> > > ++                    NEXT_ARG();
> > > ++                    cpu = ll_name_to_index(*argv);
> > > ++                    if (!cpu)
> > > ++                            return nodev(*argv);
> > > ++                    addattr32(&req->n, sizeof(*req), IFLA_CPU, cpu);
> > > +             } else if (matches(*argv, "address") == 0) {
> > > +                     NEXT_ARG();
> > > +                     addr_len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
> > > +diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
> > > +index 19a0c9ca..406db8ad 100644
> > > +--- a/man/man8/ip-link.8.in
> > > ++++ b/man/man8/ip-link.8.in
> > > +@@ -152,6 +152,9 @@ ip-link \- network device configuration
> > > + .br
> > > + .RB "[ " nomaster " ]"
> > > + .br
> > > ++.RB "[ " cpu
> > > ++.IR DEVICE " ]"
> > > ++.br
> > > + .RB "[ " vrf
> > > + .IR NAME " ]"
> > > + .br
> > > +@@ -2299,6 +2302,10 @@ set master device of the device (enslave device).
> > > + .BI nomaster
> > > + unset master device of the device (release device).
> > > +
> > > ++.TP
> > > ++.BI cpu " DEVICE"
> > > ++set cpu device of the dsa device.
> > > ++
> > > + .TP
> > > + .BI addrgenmode " eui64|none|stable_secret|random"
> > > + set the IPv6 address generation mode
> > > +--
> > > +2.33.1
> > > +
> > > --
> > > 2.34.1
> > >
> > >
> > > _______________________________________________
> > > openwrt-devel mailing list
> > > openwrt-devel@lists.openwrt.org
> > > https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Arınç ÜNAL Feb. 21, 2022, 12:27 p.m. UTC | #4
On 21/02/2022 05:30, Daniel Golle wrote:
> On Mon, Feb 21, 2022 at 01:37:10AM +0100, Ansuel Smith wrote:
>>>
>>> On Thu, Feb 03, 2022 at 01:44:12AM +0100, Ansuel Smith wrote:
>>>> Add support for cpu set useful to set CPU port for dsa devices.
>>>
>>> Please also document the newly added 'cpu' parameter in the command-
>>> line output -- the manpage isn't even installed/available for OpenWrt
>>> users.
>>>
>>
>> Should I wait for other review or should I send v3?
> 
> Give it a test-run and make sure
> ip link XXX set cpu YYY
> actually works -- when I tried it gave me
> RTNETLINK answers: Not supported
> eventhough the DSA driver does set the .port_change_cpu_port
> function. If it works for you with whatever DSA driver you are trying
> with, I will figure why it didn't work on MT7530...

MT7530 DSA driver does not support port 5 as the CPU port if that's what 
you tried.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/net/dsa/mt7530.txt#n63

Arınç
Daniel Golle Feb. 21, 2022, 12:53 p.m. UTC | #5
On Mon, Feb 21, 2022 at 03:27:19PM +0300, Arınç ÜNAL wrote:
> On 21/02/2022 05:30, Daniel Golle wrote:
> > On Mon, Feb 21, 2022 at 01:37:10AM +0100, Ansuel Smith wrote:
> > > > 
> > > > On Thu, Feb 03, 2022 at 01:44:12AM +0100, Ansuel Smith wrote:
> > > > > Add support for cpu set useful to set CPU port for dsa devices.
> > > > 
> > > > Please also document the newly added 'cpu' parameter in the command-
> > > > line output -- the manpage isn't even installed/available for OpenWrt
> > > > users.
> > > > 
> > > 
> > > Should I wait for other review or should I send v3?
> > 
> > Give it a test-run and make sure
> > ip link XXX set cpu YYY
> > actually works -- when I tried it gave me
> > RTNETLINK answers: Not supported
> > eventhough the DSA driver does set the .port_change_cpu_port
> > function. If it works for you with whatever DSA driver you are trying
> > with, I will figure why it didn't work on MT7530...
> 
> MT7530 DSA driver does not support port 5 as the CPU port if that's what you
> tried.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/net/dsa/mt7530.txt#n63

There is a patch by @LGA1150 adding that:
https://github.com/frank-w/BPI-R2-4.14/commit/47499f9ef4dc6a0888329412347c539ef1d4a514

I works quite nicely with their tree, I also got it running before when
using the device-tree default-cpu hack we now dropped:
https://github.com/frank-w/BPI-R2-4.14/commit/a740207fdbc4cc4c29e74d0735a180d58197f252
diff mbox series

Patch

diff --git a/package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch b/package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch
new file mode 100644
index 00000000..1bb2bb1f
--- /dev/null
+++ b/package/network/utils/iproute2/patches/101-iplink_allow_to_change_cpu_value.patch
@@ -0,0 +1,81 @@ 
+From 8642516618b60a2827215f2bed54d4d0aa1da48a Mon Sep 17 00:00:00 2001
+From: Ansuel Smith <ansuelsmth@gmail.com>
+Date: Sun, 23 Jan 2022 00:31:49 +0100
+Subject: [PATCH] iplink: allow to change cpu of dsa device
+
+Allow to change the cpu port linked to a given dsa interface.
+This is useful in the case of multi-CPU port DSA to assign the correct
+port to the different user ports.
+
+Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
+---
+ include/uapi/linux/if_link.h | 1 +
+ ip/iplink.c                  | 7 +++++++
+ man/man8/ip-link.8.in        | 7 +++++++
+ 3 files changed, 15 insertions(+)
+
+diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
+index 41708e26..901b5544 100644
+--- a/include/uapi/linux/if_link.h
++++ b/include/uapi/linux/if_link.h
+@@ -341,6 +341,7 @@ enum {
+ 	IFLA_ALT_IFNAME, /* Alternative ifname */
+ 	IFLA_PERM_ADDRESS,
+ 	IFLA_PROTO_DOWN_REASON,
++	IFLA_CPU,
+ 
+ 	/* device (sysfs) name as parent, used instead
+ 	 * of IFLA_LINK where there's no parent netdev
+diff --git a/ip/iplink.c b/ip/iplink.c
+index a3ea775d..254c35c5 100644
+--- a/ip/iplink.c
++++ b/ip/iplink.c
+@@ -595,6 +595,7 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
+ 	int index = 0;
+ 	int group = -1;
+ 	int addr_len = 0;
++	int cpu = -1;
+ 	int err;
+ 
+ 	ret = argc;
+@@ -625,6 +626,12 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
+ 		} else if (matches(*argv, "link") == 0) {
+ 			NEXT_ARG();
+ 			link = *argv;
++		} else if (matches(*argv, "cpu") == 0) {
++			NEXT_ARG();
++			cpu = ll_name_to_index(*argv);
++			if (!cpu)
++				return nodev(*argv);
++			addattr32(&req->n, sizeof(*req), IFLA_CPU, cpu);
+ 		} else if (matches(*argv, "address") == 0) {
+ 			NEXT_ARG();
+ 			addr_len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
+diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
+index 19a0c9ca..406db8ad 100644
+--- a/man/man8/ip-link.8.in
++++ b/man/man8/ip-link.8.in
+@@ -152,6 +152,9 @@ ip-link \- network device configuration
+ .br
+ .RB "[ " nomaster " ]"
+ .br
++.RB "[ " cpu
++.IR DEVICE " ]"
++.br
+ .RB "[ " vrf
+ .IR NAME " ]"
+ .br
+@@ -2299,6 +2302,10 @@ set master device of the device (enslave device).
+ .BI nomaster
+ unset master device of the device (release device).
+ 
++.TP
++.BI cpu " DEVICE"
++set cpu device of the dsa device.
++
+ .TP
+ .BI addrgenmode " eui64|none|stable_secret|random"
+ set the IPv6 address generation mode
+-- 
+2.33.1
+