Skip to content

Commit 82901ad

Browse files
daniellertsdavem330
authored andcommitted
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 <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a0f49b5 commit 82901ad

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,13 +2236,6 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
22362236
return -EINVAL;
22372237
}
22382238

2239-
/* Split ports cannot be split. */
2240-
if (mlxsw_sp_port->split) {
2241-
netdev_err(mlxsw_sp_port->dev, "Port cannot be split further\n");
2242-
NL_SET_ERR_MSG_MOD(extack, "Port cannot be split further");
2243-
return -EINVAL;
2244-
}
2245-
22462239
max_width = mlxsw_core_module_max_width(mlxsw_core,
22472240
mlxsw_sp_port->mapping.module);
22482241
if (max_width < 0) {
@@ -2251,19 +2244,13 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
22512244
return max_width;
22522245
}
22532246

2254-
/* Split port with non-max and 1 module width cannot be split. */
2255-
if (mlxsw_sp_port->mapping.width != max_width || max_width == 1) {
2247+
/* Split port with non-max cannot be split. */
2248+
if (mlxsw_sp_port->mapping.width != max_width) {
22562249
netdev_err(mlxsw_sp_port->dev, "Port cannot be split\n");
22572250
NL_SET_ERR_MSG_MOD(extack, "Port cannot be split");
22582251
return -EINVAL;
22592252
}
22602253

2261-
if (count == 1 || !is_power_of_2(count) || count > max_width) {
2262-
netdev_err(mlxsw_sp_port->dev, "Invalid split count\n");
2263-
NL_SET_ERR_MSG_MOD(extack, "Invalid split count");
2264-
return -EINVAL;
2265-
}
2266-
22672254
offset = mlxsw_sp_local_ports_offset(mlxsw_core, count, max_width);
22682255
if (offset < 0) {
22692256
netdev_err(mlxsw_sp_port->dev, "Cannot obtain local port offset\n");

drivers/net/ethernet/netronome/nfp/nfp_devlink.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ nfp_devlink_port_split(struct devlink *devlink, unsigned int port_index,
7070
unsigned int lanes;
7171
int ret;
7272

73-
if (count < 2)
74-
return -EINVAL;
75-
7673
mutex_lock(&pf->lock);
7774

7875
rtnl_lock();
@@ -81,7 +78,7 @@ nfp_devlink_port_split(struct devlink *devlink, unsigned int port_index,
8178
if (ret)
8279
goto out;
8380

84-
if (eth_port.is_split || eth_port.port_lanes % count) {
81+
if (eth_port.port_lanes % count) {
8582
ret = -EINVAL;
8683
goto out;
8784
}

net/core/devlink.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,15 +940,35 @@ static int devlink_nl_cmd_port_split_doit(struct sk_buff *skb,
940940
struct genl_info *info)
941941
{
942942
struct devlink *devlink = info->user_ptr[0];
943+
struct devlink_port *devlink_port;
943944
u32 port_index;
944945
u32 count;
945946

946947
if (!info->attrs[DEVLINK_ATTR_PORT_INDEX] ||
947948
!info->attrs[DEVLINK_ATTR_PORT_SPLIT_COUNT])
948949
return -EINVAL;
949950

951+
devlink_port = devlink_port_get_from_info(devlink, info);
950952
port_index = nla_get_u32(info->attrs[DEVLINK_ATTR_PORT_INDEX]);
951953
count = nla_get_u32(info->attrs[DEVLINK_ATTR_PORT_SPLIT_COUNT]);
954+
955+
if (IS_ERR(devlink_port))
956+
return -EINVAL;
957+
958+
if (!devlink_port->attrs.splittable) {
959+
/* Split ports cannot be split. */
960+
if (devlink_port->attrs.split)
961+
NL_SET_ERR_MSG_MOD(info->extack, "Port cannot be split further");
962+
else
963+
NL_SET_ERR_MSG_MOD(info->extack, "Port cannot be split");
964+
return -EINVAL;
965+
}
966+
967+
if (count < 2 || !is_power_of_2(count) || count > devlink_port->attrs.lanes) {
968+
NL_SET_ERR_MSG_MOD(info->extack, "Invalid split count");
969+
return -EINVAL;
970+
}
971+
952972
return devlink_port_split(devlink, port_index, count, info->extack);
953973
}
954974

0 commit comments

Comments
 (0)