mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-27 03:10:12 +00:00
Merge branch 'devlink-port_del-new-cleanup'
Jiri Pirko says: ==================== devlink: small port_new/del() cleanup This patchset cleans up couple of leftovers after recent devlink locking changes. Previously, both port_new/dev() commands were called without holding instance lock. Currently all devlink commands are called with instance lock held. The first patch just removes redundant port notification. The second one removes couple of outdated comments. The last patch changes port_dev() to have devlink_port pointer as an arg instead of port_index, which makes it similar to the rest of port related ops. ==================== Reviewed-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
commit
41a45ea49d
4 changed files with 16 additions and 72 deletions
|
@ -282,8 +282,7 @@ int mlx5_devlink_sf_port_fn_state_set(struct devlink_port *dl_port,
|
|||
|
||||
static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
|
||||
const struct devlink_port_new_attrs *new_attr,
|
||||
struct netlink_ext_ack *extack,
|
||||
unsigned int *new_port_index)
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct mlx5_eswitch *esw = dev->priv.eswitch;
|
||||
struct mlx5_sf *sf;
|
||||
|
@ -297,7 +296,6 @@ static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
|
|||
new_attr->controller, new_attr->sfnum);
|
||||
if (err)
|
||||
goto esw_err;
|
||||
*new_port_index = sf->port_index;
|
||||
trace_mlx5_sf_add(dev, sf->port_index, sf->controller, sf->hw_fn_id, new_attr->sfnum);
|
||||
return 0;
|
||||
|
||||
|
@ -338,8 +336,7 @@ mlx5_sf_new_check_attr(struct mlx5_core_dev *dev, const struct devlink_port_new_
|
|||
|
||||
int mlx5_devlink_sf_port_new(struct devlink *devlink,
|
||||
const struct devlink_port_new_attrs *new_attr,
|
||||
struct netlink_ext_ack *extack,
|
||||
unsigned int *new_port_index)
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct mlx5_core_dev *dev = devlink_priv(devlink);
|
||||
struct mlx5_sf_table *table;
|
||||
|
@ -355,7 +352,7 @@ int mlx5_devlink_sf_port_new(struct devlink *devlink,
|
|||
"Port add is only supported in eswitch switchdev mode or SF ports are disabled.");
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
err = mlx5_sf_add(dev, table, new_attr, extack, new_port_index);
|
||||
err = mlx5_sf_add(dev, table, new_attr, extack);
|
||||
mlx5_sf_table_put(table);
|
||||
return err;
|
||||
}
|
||||
|
@ -379,7 +376,8 @@ static void mlx5_sf_dealloc(struct mlx5_sf_table *table, struct mlx5_sf *sf)
|
|||
}
|
||||
}
|
||||
|
||||
int mlx5_devlink_sf_port_del(struct devlink *devlink, unsigned int port_index,
|
||||
int mlx5_devlink_sf_port_del(struct devlink *devlink,
|
||||
struct devlink_port *dl_port,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct mlx5_core_dev *dev = devlink_priv(devlink);
|
||||
|
@ -394,7 +392,7 @@ int mlx5_devlink_sf_port_del(struct devlink *devlink, unsigned int port_index,
|
|||
"Port del is only supported in eswitch switchdev mode or SF ports are disabled.");
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
sf = mlx5_sf_lookup_by_index(table, port_index);
|
||||
sf = mlx5_sf_lookup_by_index(table, dl_port->index);
|
||||
if (!sf) {
|
||||
err = -ENODEV;
|
||||
goto sf_err;
|
||||
|
|
|
@ -20,9 +20,9 @@ void mlx5_sf_table_cleanup(struct mlx5_core_dev *dev);
|
|||
|
||||
int mlx5_devlink_sf_port_new(struct devlink *devlink,
|
||||
const struct devlink_port_new_attrs *add_attr,
|
||||
struct netlink_ext_ack *extack,
|
||||
unsigned int *new_port_index);
|
||||
int mlx5_devlink_sf_port_del(struct devlink *devlink, unsigned int port_index,
|
||||
struct netlink_ext_ack *extack);
|
||||
int mlx5_devlink_sf_port_del(struct devlink *devlink,
|
||||
struct devlink_port *dl_port,
|
||||
struct netlink_ext_ack *extack);
|
||||
int mlx5_devlink_sf_port_fn_state_get(struct devlink_port *dl_port,
|
||||
enum devlink_port_fn_state *state,
|
||||
|
|
|
@ -1500,41 +1500,35 @@ struct devlink_ops {
|
|||
* @devlink: Devlink instance
|
||||
* @attrs: attributes of the new port
|
||||
* @extack: extack for reporting error messages
|
||||
* @new_port_index: index of the new port
|
||||
*
|
||||
* Devlink core will call this device driver function upon user request
|
||||
* to create a new port function of a specified flavor and optional
|
||||
* attributes
|
||||
*
|
||||
* Notes:
|
||||
* - Called without devlink instance lock being held. Drivers must
|
||||
* implement own means of synchronization
|
||||
* - On success, drivers must register a port with devlink core
|
||||
*
|
||||
* Return: 0 on success, negative value otherwise.
|
||||
*/
|
||||
int (*port_new)(struct devlink *devlink,
|
||||
const struct devlink_port_new_attrs *attrs,
|
||||
struct netlink_ext_ack *extack,
|
||||
unsigned int *new_port_index);
|
||||
struct netlink_ext_ack *extack);
|
||||
/**
|
||||
* port_del() - Delete a port function
|
||||
* @devlink: Devlink instance
|
||||
* @port_index: port function index to delete
|
||||
* @port: The devlink port
|
||||
* @extack: extack for reporting error messages
|
||||
*
|
||||
* Devlink core will call this device driver function upon user request
|
||||
* to delete a previously created port function
|
||||
*
|
||||
* Notes:
|
||||
* - Called without devlink instance lock being held. Drivers must
|
||||
* implement own means of synchronization
|
||||
* - On success, drivers must unregister the corresponding devlink
|
||||
* port
|
||||
*
|
||||
* Return: 0 on success, negative value otherwise.
|
||||
*/
|
||||
int (*port_del)(struct devlink *devlink, unsigned int port_index,
|
||||
int (*port_del)(struct devlink *devlink, struct devlink_port *port,
|
||||
struct netlink_ext_ack *extack);
|
||||
/**
|
||||
* port_fn_state_get() - Get the state of a port function
|
||||
|
|
|
@ -1354,45 +1354,12 @@ static int devlink_nl_cmd_port_unsplit_doit(struct sk_buff *skb,
|
|||
return devlink->ops->port_unsplit(devlink, devlink_port, info->extack);
|
||||
}
|
||||
|
||||
static int devlink_port_new_notify(struct devlink *devlink,
|
||||
unsigned int port_index,
|
||||
struct genl_info *info)
|
||||
{
|
||||
struct devlink_port *devlink_port;
|
||||
struct sk_buff *msg;
|
||||
int err;
|
||||
|
||||
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
|
||||
if (!msg)
|
||||
return -ENOMEM;
|
||||
|
||||
lockdep_assert_held(&devlink->lock);
|
||||
devlink_port = devlink_port_get_by_index(devlink, port_index);
|
||||
if (!devlink_port) {
|
||||
err = -ENODEV;
|
||||
goto out;
|
||||
}
|
||||
|
||||
err = devlink_nl_port_fill(msg, devlink_port, DEVLINK_CMD_NEW,
|
||||
info->snd_portid, info->snd_seq, 0, NULL);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
return genlmsg_reply(msg, info);
|
||||
|
||||
out:
|
||||
nlmsg_free(msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int devlink_nl_cmd_port_new_doit(struct sk_buff *skb,
|
||||
struct genl_info *info)
|
||||
{
|
||||
struct netlink_ext_ack *extack = info->extack;
|
||||
struct devlink_port_new_attrs new_attrs = {};
|
||||
struct devlink *devlink = info->user_ptr[0];
|
||||
unsigned int new_port_index;
|
||||
int err;
|
||||
|
||||
if (!devlink->ops->port_new || !devlink->ops->port_del)
|
||||
return -EOPNOTSUPP;
|
||||
|
@ -1423,36 +1390,20 @@ static int devlink_nl_cmd_port_new_doit(struct sk_buff *skb,
|
|||
new_attrs.sfnum_valid = true;
|
||||
}
|
||||
|
||||
err = devlink->ops->port_new(devlink, &new_attrs, extack,
|
||||
&new_port_index);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = devlink_port_new_notify(devlink, new_port_index, info);
|
||||
if (err && err != -ENODEV) {
|
||||
/* Fail to send the response; destroy newly created port. */
|
||||
devlink->ops->port_del(devlink, new_port_index, extack);
|
||||
}
|
||||
return err;
|
||||
return devlink->ops->port_new(devlink, &new_attrs, extack);
|
||||
}
|
||||
|
||||
static int devlink_nl_cmd_port_del_doit(struct sk_buff *skb,
|
||||
struct genl_info *info)
|
||||
{
|
||||
struct devlink_port *devlink_port = info->user_ptr[1];
|
||||
struct netlink_ext_ack *extack = info->extack;
|
||||
struct devlink *devlink = info->user_ptr[0];
|
||||
unsigned int port_index;
|
||||
|
||||
if (!devlink->ops->port_del)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (GENL_REQ_ATTR_CHECK(info, DEVLINK_ATTR_PORT_INDEX)) {
|
||||
NL_SET_ERR_MSG(extack, "Port index is not specified");
|
||||
return -EINVAL;
|
||||
}
|
||||
port_index = nla_get_u32(info->attrs[DEVLINK_ATTR_PORT_INDEX]);
|
||||
|
||||
return devlink->ops->port_del(devlink, port_index, extack);
|
||||
return devlink->ops->port_del(devlink, devlink_port, extack);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -6384,6 +6335,7 @@ const struct genl_small_ops devlink_nl_ops[56] = {
|
|||
.cmd = DEVLINK_CMD_PORT_DEL,
|
||||
.doit = devlink_nl_cmd_port_del_doit,
|
||||
.flags = GENL_ADMIN_PERM,
|
||||
.internal_flags = DEVLINK_NL_FLAG_NEED_PORT,
|
||||
},
|
||||
{
|
||||
.cmd = DEVLINK_CMD_LINECARD_GET,
|
||||
|
|
Loading…
Reference in a new issue