diff mbox series

[net-next,V10,01/14] devlink: Prepare code to fill multiple port function attributes

Message ID 20210122193658.282884-2-saeed@kernel.org (mailing list archive)
State Not Applicable
Headers show
Series [net-next,V10,01/14] devlink: Prepare code to fill multiple port function attributes | expand

Commit Message

Saeed Mahameed Jan. 22, 2021, 7:36 p.m. UTC
From: Parav Pandit <parav@nvidia.com>

Prepare code to fill zero or more port function optional attributes.
Subsequent patch makes use of this to fill more port function
attributes.

Signed-off-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Vu Pham <vuhuong@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
---
 net/core/devlink.c | 64 ++++++++++++++++++++++++----------------------
 1 file changed, 33 insertions(+), 31 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org Jan. 29, 2021, 1:40 a.m. UTC | #1
Hello:

This series was applied to netdev/net-next.git (refs/heads/master):

On Fri, 22 Jan 2021 11:36:45 -0800 you wrote:
> From: Parav Pandit <parav@nvidia.com>
> 
> Prepare code to fill zero or more port function optional attributes.
> Subsequent patch makes use of this to fill more port function
> attributes.
> 
> Signed-off-by: Parav Pandit <parav@nvidia.com>
> Reviewed-by: Jiri Pirko <jiri@nvidia.com>
> Reviewed-by: Vu Pham <vuhuong@nvidia.com>
> Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
> 
> [...]

Here is the summary with links:
  - [net-next,V10,01/14] devlink: Prepare code to fill multiple port function attributes
    https://git.kernel.org/netdev/net-next/c/1230d94820c9
  - [net-next,V10,02/14] devlink: Introduce PCI SF port flavour and port attribute
    https://git.kernel.org/netdev/net-next/c/b8288837ef6b
  - [net-next,V10,03/14] devlink: Support add and delete devlink port
    https://git.kernel.org/netdev/net-next/c/cd76dcd68d96
  - [net-next,V10,04/14] devlink: Support get and set state of port function
    https://git.kernel.org/netdev/net-next/c/a556dded9c23
  - [net-next,V10,05/14] net/mlx5: Introduce vhca state event notifier
    https://git.kernel.org/netdev/net-next/c/f3196bb0f14c
  - [net-next,V10,06/14] net/mlx5: SF, Add auxiliary device support
    https://git.kernel.org/netdev/net-next/c/90d010b8634b
  - [net-next,V10,07/14] net/mlx5: SF, Add auxiliary device driver
    https://git.kernel.org/netdev/net-next/c/1958fc2f0712
  - [net-next,V10,08/14] net/mlx5: E-switch, Prepare eswitch to handle SF vport
    https://git.kernel.org/netdev/net-next/c/d7f33a457bee
  - [net-next,V10,09/14] net/mlx5: E-switch, Add eswitch helpers for SF vport
    https://git.kernel.org/netdev/net-next/c/d970812b91d0
  - [net-next,V10,10/14] net/mlx5: SF, Add port add delete functionality
    https://git.kernel.org/netdev/net-next/c/8f0105418668
  - [net-next,V10,11/14] net/mlx5: SF, Port function state change support
    https://git.kernel.org/netdev/net-next/c/6a3273217469
  - [net-next,V10,12/14] devlink: Add devlink port documentation
    https://git.kernel.org/netdev/net-next/c/c736111cf8d5
  - [net-next,V10,13/14] devlink: Extend devlink port documentation for subfunctions
    https://git.kernel.org/netdev/net-next/c/6474ce7ecd80
  - [net-next,V10,14/14] net/mlx5: Add devlink subfunction port documentation
    https://git.kernel.org/netdev/net-next/c/142d93d12dc1

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
diff mbox series

Patch

diff --git a/net/core/devlink.c b/net/core/devlink.c
index ee828e4b1007..c39496311b71 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -712,6 +712,31 @@  static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 	return 0;
 }
 
+static int
+devlink_port_fn_hw_addr_fill(struct devlink *devlink, const struct devlink_ops *ops,
+			     struct devlink_port *port, struct sk_buff *msg,
+			     struct netlink_ext_ack *extack, bool *msg_updated)
+{
+	u8 hw_addr[MAX_ADDR_LEN];
+	int hw_addr_len;
+	int err;
+
+	if (!ops->port_function_hw_addr_get)
+		return 0;
+
+	err = ops->port_function_hw_addr_get(devlink, port, hw_addr, &hw_addr_len, extack);
+	if (err) {
+		if (err == -EOPNOTSUPP)
+			return 0;
+		return err;
+	}
+	err = nla_put(msg, DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR, hw_addr_len, hw_addr);
+	if (err)
+		return err;
+	*msg_updated = true;
+	return 0;
+}
+
 static int
 devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *port,
 				   struct netlink_ext_ack *extack)
@@ -719,36 +744,17 @@  devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *por
 	struct devlink *devlink = port->devlink;
 	const struct devlink_ops *ops;
 	struct nlattr *function_attr;
-	bool empty_nest = true;
-	int err = 0;
+	bool msg_updated = false;
+	int err;
 
 	function_attr = nla_nest_start_noflag(msg, DEVLINK_ATTR_PORT_FUNCTION);
 	if (!function_attr)
 		return -EMSGSIZE;
 
 	ops = devlink->ops;
-	if (ops->port_function_hw_addr_get) {
-		int hw_addr_len;
-		u8 hw_addr[MAX_ADDR_LEN];
-
-		err = ops->port_function_hw_addr_get(devlink, port, hw_addr, &hw_addr_len, extack);
-		if (err == -EOPNOTSUPP) {
-			/* Port function attributes are optional for a port. If port doesn't
-			 * support function attribute, returning -EOPNOTSUPP is not an error.
-			 */
-			err = 0;
-			goto out;
-		} else if (err) {
-			goto out;
-		}
-		err = nla_put(msg, DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR, hw_addr_len, hw_addr);
-		if (err)
-			goto out;
-		empty_nest = false;
-	}
-
-out:
-	if (err || empty_nest)
+	err = devlink_port_fn_hw_addr_fill(devlink, ops, port, msg,
+					   extack, &msg_updated);
+	if (err || !msg_updated)
 		nla_nest_cancel(msg, function_attr);
 	else
 		nla_nest_end(msg, function_attr);
@@ -986,7 +992,6 @@  devlink_port_function_hw_addr_set(struct devlink *devlink, struct devlink_port *
 	const struct devlink_ops *ops;
 	const u8 *hw_addr;
 	int hw_addr_len;
-	int err;
 
 	hw_addr = nla_data(attr);
 	hw_addr_len = nla_len(attr);
@@ -1011,12 +1016,7 @@  devlink_port_function_hw_addr_set(struct devlink *devlink, struct devlink_port *
 		return -EOPNOTSUPP;
 	}
 
-	err = ops->port_function_hw_addr_set(devlink, port, hw_addr, hw_addr_len, extack);
-	if (err)
-		return err;
-
-	devlink_port_notify(port, DEVLINK_CMD_PORT_NEW);
-	return 0;
+	return ops->port_function_hw_addr_set(devlink, port, hw_addr, hw_addr_len, extack);
 }
 
 static int
@@ -1037,6 +1037,8 @@  devlink_port_function_set(struct devlink *devlink, struct devlink_port *port,
 	if (attr)
 		err = devlink_port_function_hw_addr_set(devlink, port, attr, extack);
 
+	if (!err)
+		devlink_port_notify(port, DEVLINK_CMD_PORT_NEW);
 	return err;
 }