Skip to contentSkip to conversation

devlink: Notify eswitch mode changes to devlink monitor

PATCH In review Parav Pandit 2 participants 5 messages Nov 15, 2025 – Nov 19, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 devlink: Notify eswitch mode changes to devlink monitor

When eswitch mode changes, notify such change to the devlink monitoring process.

After this notification, a devlink monitoring process can see following output:

$ devlink mon
[eswitch,set] pci/0000:06:00.0: mode switchdev inline-mode none encap-mode basic
[eswitch,set] pci/0000:06:00.0: mode legacy inline-mode none encap-mode basic
---
 net/devlink/dev.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
net/devlink/dev.c +25 -0
index 02602704bdea..012211455f97 100644
@@ -701,6 +701,30 @@ int devlink_nl_eswitch_get_doit(struct sk_buff *skb, struct genl_info *info)
 	return genlmsg_reply(msg, info);
 }
 
+static void devlink_eswitch_notify(struct devlink *devlink)
+{
+	struct sk_buff *msg;
+	int err;
+
+	WARN_ON(!devl_is_registered(devlink));
+
+	if (!devlink_nl_notify_need(devlink))
+		return;
+
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+	if (!msg)
+		return;
+
+	err = devlink_nl_eswitch_fill(msg, devlink, DEVLINK_CMD_ESWITCH_SET,
+				      0, 0, 0);
+	if (err) {
+		nlmsg_free(msg);
+		return;
+	}
+
+	devlink_nl_notify_send(devlink, msg);
+}
+
 int devlink_nl_eswitch_set_doit(struct sk_buff *skb, struct genl_info *info)
 {
 	struct devlink *devlink = info->user_ptr[0];
@@ -742,6 +766,7 @@ int devlink_nl_eswitch_set_doit(struct sk_buff *skb, struct genl_info *info)
 			return err;
 	}
 
+	devlink_eswitch_notify(devlink);
 	return 0;
 }
 
Signature · 1 line
2.26.2
maintainer
#1 lore raw

net/devlink/dev.c int devlink_nl_eswitch_get_doit(struct sk_buff *skb, struct genl_info *info) · line 718

Quoted 1 line · On Sat, 15 Nov 2025 04:51:25 +0200 Parav Pandit wrote:
net/devlink/dev.c +1 -0
+	err = devlink_nl_eswitch_fill(msg, devlink, DEVLINK_CMD_ESWITCH_SET,

I've never seen action command ID being used for a notification. Either use an existing type which has the same message format, or if no message which naturally fits exists allocate a new ID.

Signature · 1 line
pw-bot: cr
#2 lore raw
Quoted 5 lines

From: Jakub Kicinski <[email protected]>
Sent: 18 November 2025 09:11 AM

Quoted 7 lines

Review

Quoted 1 line · On Sat, 15 Nov 2025 04:51:25 +0200 Parav Pandit wrote:
(quoted diff) +1 -0
+	err = devlink_nl_eswitch_fill(msg, devlink,

DEVLINK_CMD_ESWITCH_SET,

I've never seen action command ID being used for a notification. Either use an existing type which has the same message format, or if no message which naturally fits exists allocate a new ID.

I am not sure fully.
1. devlink_notify() uses DEVLINK_CMD_NEW.

2. devlink_port_notify() uses DEVLINK_CMD_PORT_NEW which is the input cmd on port creation supplied by the user space.

3. devlink_params_notify_register() uses DEVLINK_CMD_PARAM_NEW.

Do you mean #1 and #3 are not user-initiated commands, hence such an action command ID is ok vs #2 is not ok? I probably misunderstanding your comment.

maintainer
#3 lore raw
Quoted 14 lines · On Tue, 18 Nov 2025 05:25:23 +0000 Parav Pandit wrote:
Quoted 10 lines

From: Jakub Kicinski <[email protected]>
Sent: 18 November 2025 09:11 AM

Review

Quoted 1 line · On Sat, 15 Nov 2025 04:51:25 +0200 Parav Pandit wrote:
(quoted diff) +1 -0
+	err = devlink_nl_eswitch_fill(msg, devlink,  

DEVLINK_CMD_ESWITCH_SET,

I've never seen action command ID being used for a notification. Either use an existing type which has the same message format, or if no message which naturally fits exists allocate a new ID.

I am not sure fully.
1. devlink_notify() uses DEVLINK_CMD_NEW.

Quoted 8 lines

2. devlink_port_notify() uses DEVLINK_CMD_PORT_NEW which is the input cmd on port creation supplied by the user space.

3. devlink_params_notify_register() uses DEVLINK_CMD_PARAM_NEW.

Do you mean #1 and #3 are not user-initiated commands, hence such an action command ID is ok vs #2 is not ok? I probably misunderstanding your comment.

Let me put it more simply at some cost to accuracy.. The notification types and command ids usually match the response to a GET command. Please TAL at the messages which are generated in response to a GET for the objects you listed...

Netlink command IDs are not required to match in a request-response pair. In "modern" families we recommend that they do match, not because the old model was wrong, but because a casual contributors usually got it wrong.

#4 lore raw
Quoted 24 lines

From: Jakub Kicinski <[email protected]>
Sent: 19 November 2025 01:46 AM

Quoted 19 lines · On Tue, 18 Nov 2025 05:25:23 +0000 Parav Pandit wrote:
Quoted 10 lines

From: Jakub Kicinski <[email protected]>
Sent: 18 November 2025 09:11 AM

Review

Quoted 1 line · On Sat, 15 Nov 2025 04:51:25 +0200 Parav Pandit wrote:
(quoted diff) +1 -0
+	err = devlink_nl_eswitch_fill(msg, devlink,

DEVLINK_CMD_ESWITCH_SET,

I've never seen action command ID being used for a notification. Either use an existing type which has the same message format, or if no message which naturally fits exists allocate a new ID.

I am not sure fully.
1. devlink_notify() uses DEVLINK_CMD_NEW.

2. devlink_port_notify() uses DEVLINK_CMD_PORT_NEW which is the input cmd on port creation supplied by the user space.

3. devlink_params_notify_register() uses DEVLINK_CMD_PARAM_NEW.

Quoted 9 lines
Quoted 3 lines

Do you mean #1 and #3 are not user-initiated commands, hence such an action command ID is ok vs #2 is not ok? I probably misunderstanding your comment.

Let me put it more simply at some cost to accuracy..
The notification types and command ids usually match the response to a GET command. Please TAL at the messages which are generated in response to a GET for the objects you listed...

Got it.
Will change to reuse the id same as GET method.
In the eswitch case it is DEVLINK_CMD_ESWITCH_GET.
It fits the existing get command.
Ideally a change opcode like DPLL_CMD_DEVICE_CHANGE_X would be good too. But ESWITCH_GET seems good enough as we don't have ESWITCH_NEW/ESWITCH_DEL.

Quoted 3 lines

Netlink command IDs are not required to match in a request-response pair. In "modern" families we recommend that they do match, not because the old model was wrong, but because a casual contributors usually got it wrong.

Sending v1.

Thank you for the good explanation.