Commit 1230d948 authored by Parav Pandit's avatar Parav Pandit Committed by Saeed Mahameed

devlink: Prepare code to fill multiple port function attributes

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: default avatarParav Pandit <parav@nvidia.com>
Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
Reviewed-by: default avatarVu Pham <vuhuong@nvidia.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
parent 7b8fc010
...@@ -712,6 +712,31 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg, ...@@ -712,6 +712,31 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
return 0; 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 static int
devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *port, devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *port,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
...@@ -719,36 +744,17 @@ devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *por ...@@ -719,36 +744,17 @@ devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *por
struct devlink *devlink = port->devlink; struct devlink *devlink = port->devlink;
const struct devlink_ops *ops; const struct devlink_ops *ops;
struct nlattr *function_attr; struct nlattr *function_attr;
bool empty_nest = true; bool msg_updated = false;
int err = 0; int err;
function_attr = nla_nest_start_noflag(msg, DEVLINK_ATTR_PORT_FUNCTION); function_attr = nla_nest_start_noflag(msg, DEVLINK_ATTR_PORT_FUNCTION);
if (!function_attr) if (!function_attr)
return -EMSGSIZE; return -EMSGSIZE;
ops = devlink->ops; ops = devlink->ops;
if (ops->port_function_hw_addr_get) { err = devlink_port_fn_hw_addr_fill(devlink, ops, port, msg,
int hw_addr_len; extack, &msg_updated);
u8 hw_addr[MAX_ADDR_LEN]; if (err || !msg_updated)
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)
nla_nest_cancel(msg, function_attr); nla_nest_cancel(msg, function_attr);
else else
nla_nest_end(msg, function_attr); nla_nest_end(msg, function_attr);
...@@ -986,7 +992,6 @@ devlink_port_function_hw_addr_set(struct devlink *devlink, struct devlink_port * ...@@ -986,7 +992,6 @@ devlink_port_function_hw_addr_set(struct devlink *devlink, struct devlink_port *
const struct devlink_ops *ops; const struct devlink_ops *ops;
const u8 *hw_addr; const u8 *hw_addr;
int hw_addr_len; int hw_addr_len;
int err;
hw_addr = nla_data(attr); hw_addr = nla_data(attr);
hw_addr_len = nla_len(attr); hw_addr_len = nla_len(attr);
...@@ -1011,12 +1016,7 @@ devlink_port_function_hw_addr_set(struct devlink *devlink, struct devlink_port * ...@@ -1011,12 +1016,7 @@ devlink_port_function_hw_addr_set(struct devlink *devlink, struct devlink_port *
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
err = ops->port_function_hw_addr_set(devlink, port, hw_addr, hw_addr_len, extack); return 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;
} }
static int static int
...@@ -1037,6 +1037,8 @@ devlink_port_function_set(struct devlink *devlink, struct devlink_port *port, ...@@ -1037,6 +1037,8 @@ devlink_port_function_set(struct devlink *devlink, struct devlink_port *port,
if (attr) if (attr)
err = devlink_port_function_hw_addr_set(devlink, port, attr, extack); err = devlink_port_function_hw_addr_set(devlink, port, attr, extack);
if (!err)
devlink_port_notify(port, DEVLINK_CMD_PORT_NEW);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment