diff options
author | Danielle Ratson <danieller@mellanox.com> | 2020-07-09 16:18:21 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2020-07-09 13:15:30 -0700 |
commit | 82901ad16905832b7a79ff4316302bb59ec4b4ba (patch) | |
tree | 6a5f0e1ec66bd2232ec6827f59faaaedd211cb89 /net/core | |
parent | a0f49b54865273c895be3826d6d59cbc5ad725c2 (diff) | |
download | linux-82901ad16905832b7a79ff4316302bb59ec4b4ba.tar.gz linux-82901ad16905832b7a79ff4316302bb59ec4b4ba.tar.bz2 linux-82901ad16905832b7a79ff4316302bb59ec4b4ba.zip |
devlink: Move input checks from driver to devlink
Currently, all the input checks are done in driver.
After adding the split capability to devlink port, move the checks to
devlink.
Signed-off-by: Danielle Ratson <danieller@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/devlink.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/net/core/devlink.c b/net/core/devlink.c index 94c797b74378..346d385ba09f 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -940,6 +940,7 @@ static int devlink_nl_cmd_port_split_doit(struct sk_buff *skb, struct genl_info *info) { struct devlink *devlink = info->user_ptr[0]; + struct devlink_port *devlink_port; u32 port_index; u32 count; @@ -947,8 +948,27 @@ static int devlink_nl_cmd_port_split_doit(struct sk_buff *skb, !info->attrs[DEVLINK_ATTR_PORT_SPLIT_COUNT]) return -EINVAL; + devlink_port = devlink_port_get_from_info(devlink, info); port_index = nla_get_u32(info->attrs[DEVLINK_ATTR_PORT_INDEX]); count = nla_get_u32(info->attrs[DEVLINK_ATTR_PORT_SPLIT_COUNT]); + + if (IS_ERR(devlink_port)) + return -EINVAL; + + if (!devlink_port->attrs.splittable) { + /* Split ports cannot be split. */ + if (devlink_port->attrs.split) + NL_SET_ERR_MSG_MOD(info->extack, "Port cannot be split further"); + else + NL_SET_ERR_MSG_MOD(info->extack, "Port cannot be split"); + return -EINVAL; + } + + if (count < 2 || !is_power_of_2(count) || count > devlink_port->attrs.lanes) { + NL_SET_ERR_MSG_MOD(info->extack, "Invalid split count"); + return -EINVAL; + } + return devlink_port_split(devlink, port_index, count, info->extack); } |