Skip to content

Commit 8fb49c0

Browse files
committed
Merge branch 'Expose-port-split-attributes'
Ido Schimmel says: ==================== Expose port split attributes Danielle says: Currently, user space has no way of knowing if a port can be split and into how many ports. Among other things, this makes it impossible to write generic tests for port split functionality. Therefore, this set exposes two new devlink port attributes to user space: Number of lanes and whether the port can be split or not. Patch set overview: Patches #1-#4 cleanup 'struct devlink_port_attrs' and reduce the number of parameters passed between drivers and devlink via devlink_port_attrs_set() Patch #5 adds devlink port lanes attributes Patches #6-#7 add devlink port splittable attribute Patch #8 exploits the fact that devlink is now aware of port's number of lanes and whether the port can be split or not and moves some checks from drivers to devlink Patch #9 adds a port split test Changes since v2: * Remove some local variables from patch #3 * Reword function description in patch #5 * Fix a bug in patch #8 * Add a test for the splittable attribute in patch #9 Changes since v1: * Rename 'width' attribute to 'lanes' * Add 'splittable' attribute * Move checks from drivers to devlink ==================== Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2 parents faea30e + f3348a8 commit 8fb49c0

File tree

19 files changed

+424
-132
lines changed

19 files changed

+424
-132
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ static void bnxt_dl_params_unregister(struct bnxt *bp)
691691

692692
int bnxt_dl_register(struct bnxt *bp)
693693
{
694+
struct devlink_port_attrs attrs = {};
694695
struct devlink *dl;
695696
int rc;
696697

@@ -719,9 +720,11 @@ int bnxt_dl_register(struct bnxt *bp)
719720
if (!BNXT_PF(bp))
720721
return 0;
721722

722-
devlink_port_attrs_set(&bp->dl_port, DEVLINK_PORT_FLAVOUR_PHYSICAL,
723-
bp->pf.port_id, false, 0, bp->dsn,
724-
sizeof(bp->dsn));
723+
attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
724+
attrs.phys.port_number = bp->pf.port_id;
725+
memcpy(attrs.switch_id.id, bp->dsn, sizeof(bp->dsn));
726+
attrs.switch_id.id_len = sizeof(bp->dsn);
727+
devlink_port_attrs_set(&bp->dl_port, &attrs);
725728
rc = devlink_port_register(dl, &bp->dl_port, bp->pf.port_id);
726729
if (rc) {
727730
netdev_err(bp->dev, "devlink_port_register failed\n");

drivers/net/ethernet/intel/ice/ice_devlink.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,17 @@ int ice_devlink_create_port(struct ice_pf *pf)
312312
struct devlink *devlink = priv_to_devlink(pf);
313313
struct ice_vsi *vsi = ice_get_main_vsi(pf);
314314
struct device *dev = ice_pf_to_dev(pf);
315+
struct devlink_port_attrs attrs = {};
315316
int err;
316317

317318
if (!vsi) {
318319
dev_err(dev, "%s: unable to find main VSI\n", __func__);
319320
return -EIO;
320321
}
321322

322-
devlink_port_attrs_set(&pf->devlink_port, DEVLINK_PORT_FLAVOUR_PHYSICAL,
323-
pf->hw.pf_id, false, 0, NULL, 0);
323+
attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
324+
attrs.phys.port_number = pf->hw.pf_id;
325+
devlink_port_attrs_set(&pf->devlink_port, &attrs);
324326
err = devlink_port_register(devlink, &pf->devlink_port, pf->hw.pf_id);
325327
if (err) {
326328
dev_err(dev, "devlink_port_register failed: %d\n", err);

drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
int mlx5e_devlink_port_register(struct mlx5e_priv *priv)
77
{
88
struct devlink *devlink = priv_to_devlink(priv->mdev);
9+
struct devlink_port_attrs attrs = {};
910

10-
if (mlx5_core_is_pf(priv->mdev))
11-
devlink_port_attrs_set(&priv->dl_port,
12-
DEVLINK_PORT_FLAVOUR_PHYSICAL,
13-
PCI_FUNC(priv->mdev->pdev->devfn),
14-
false, 0,
15-
NULL, 0);
16-
else
17-
devlink_port_attrs_set(&priv->dl_port,
18-
DEVLINK_PORT_FLAVOUR_VIRTUAL,
19-
0, false, 0, NULL, 0);
11+
if (mlx5_core_is_pf(priv->mdev)) {
12+
attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
13+
attrs.phys.port_number = PCI_FUNC(priv->mdev->pdev->devfn);
14+
} else {
15+
attrs.flavour = DEVLINK_PORT_FLAVOUR_VIRTUAL;
16+
}
17+
18+
devlink_port_attrs_set(&priv->dl_port, &attrs);
2019

2120
return devlink_port_register(devlink, &priv->dl_port, 1);
2221
}

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,7 @@ static int register_devlink_port(struct mlx5_core_dev *dev,
11851185
{
11861186
struct devlink *devlink = priv_to_devlink(dev);
11871187
struct mlx5_eswitch_rep *rep = rpriv->rep;
1188+
struct devlink_port_attrs attrs = {};
11881189
struct netdev_phys_item_id ppid = {};
11891190
unsigned int dl_port_index = 0;
11901191
u16 pfnum;
@@ -1195,19 +1196,16 @@ static int register_devlink_port(struct mlx5_core_dev *dev,
11951196
mlx5e_rep_get_port_parent_id(rpriv->netdev, &ppid);
11961197
dl_port_index = mlx5_esw_vport_to_devlink_port_index(dev, rep->vport);
11971198
pfnum = PCI_FUNC(dev->pdev->devfn);
1198-
1199+
attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
1200+
attrs.phys.port_number = pfnum;
1201+
memcpy(attrs.switch_id.id, &ppid.id[0], ppid.id_len);
1202+
attrs.switch_id.id_len = ppid.id_len;
11991203
if (rep->vport == MLX5_VPORT_UPLINK)
1200-
devlink_port_attrs_set(&rpriv->dl_port,
1201-
DEVLINK_PORT_FLAVOUR_PHYSICAL,
1202-
pfnum, false, 0,
1203-
&ppid.id[0], ppid.id_len);
1204+
devlink_port_attrs_set(&rpriv->dl_port, &attrs);
12041205
else if (rep->vport == MLX5_VPORT_PF)
1205-
devlink_port_attrs_pci_pf_set(&rpriv->dl_port,
1206-
&ppid.id[0], ppid.id_len,
1207-
pfnum);
1206+
devlink_port_attrs_pci_pf_set(&rpriv->dl_port, pfnum);
12081207
else if (mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport))
12091208
devlink_port_attrs_pci_vf_set(&rpriv->dl_port,
1210-
&ppid.id[0], ppid.id_len,
12111209
pfnum, rep->vport - 1);
12121210

12131211
return devlink_port_register(devlink, &rpriv->dl_port, dl_port_index);

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,19 +2122,27 @@ static int __mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port,
21222122
enum devlink_port_flavour flavour,
21232123
u32 port_number, bool split,
21242124
u32 split_port_subnumber,
2125+
bool splittable, u32 lanes,
21252126
const unsigned char *switch_id,
21262127
unsigned char switch_id_len)
21272128
{
21282129
struct devlink *devlink = priv_to_devlink(mlxsw_core);
21292130
struct mlxsw_core_port *mlxsw_core_port =
21302131
&mlxsw_core->ports[local_port];
21312132
struct devlink_port *devlink_port = &mlxsw_core_port->devlink_port;
2133+
struct devlink_port_attrs attrs = {};
21322134
int err;
21332135

2136+
attrs.split = split;
2137+
attrs.lanes = lanes;
2138+
attrs.splittable = splittable;
2139+
attrs.flavour = flavour;
2140+
attrs.phys.port_number = port_number;
2141+
attrs.phys.split_subport_number = split_port_subnumber;
2142+
memcpy(attrs.switch_id.id, switch_id, switch_id_len);
2143+
attrs.switch_id.id_len = switch_id_len;
21342144
mlxsw_core_port->local_port = local_port;
2135-
devlink_port_attrs_set(devlink_port, flavour, port_number,
2136-
split, split_port_subnumber,
2137-
switch_id, switch_id_len);
2145+
devlink_port_attrs_set(devlink_port, &attrs);
21382146
err = devlink_port_register(devlink, devlink_port, local_port);
21392147
if (err)
21402148
memset(mlxsw_core_port, 0, sizeof(*mlxsw_core_port));
@@ -2154,12 +2162,14 @@ static void __mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u8 local_port)
21542162
int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port,
21552163
u32 port_number, bool split,
21562164
u32 split_port_subnumber,
2165+
bool splittable, u32 lanes,
21572166
const unsigned char *switch_id,
21582167
unsigned char switch_id_len)
21592168
{
21602169
return __mlxsw_core_port_init(mlxsw_core, local_port,
21612170
DEVLINK_PORT_FLAVOUR_PHYSICAL,
21622171
port_number, split, split_port_subnumber,
2172+
splittable, lanes,
21632173
switch_id, switch_id_len);
21642174
}
21652175
EXPORT_SYMBOL(mlxsw_core_port_init);
@@ -2181,7 +2191,7 @@ int mlxsw_core_cpu_port_init(struct mlxsw_core *mlxsw_core,
21812191

21822192
err = __mlxsw_core_port_init(mlxsw_core, MLXSW_PORT_CPU_PORT,
21832193
DEVLINK_PORT_FLAVOUR_CPU,
2184-
0, false, 0,
2194+
0, false, 0, false, 0,
21852195
switch_id, switch_id_len);
21862196
if (err)
21872197
return err;

drivers/net/ethernet/mellanox/mlxsw/core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ void mlxsw_core_lag_mapping_clear(struct mlxsw_core *mlxsw_core,
191191

192192
void *mlxsw_core_port_driver_priv(struct mlxsw_core_port *mlxsw_core_port);
193193
int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port,
194-
u32 port_number, bool split,
195-
u32 split_port_subnumber,
194+
u32 port_number, bool split, u32 split_port_subnumber,
195+
bool splittable, u32 lanes,
196196
const unsigned char *switch_id,
197197
unsigned char switch_id_len);
198198
void mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u8 local_port);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ mlxsw_m_port_create(struct mlxsw_m *mlxsw_m, u8 local_port, u8 module)
164164
int err;
165165

166166
err = mlxsw_core_port_init(mlxsw_m->core, local_port,
167-
module + 1, false, 0,
168-
mlxsw_m->base_mac,
167+
module + 1, false, 0, false,
168+
0, mlxsw_m->base_mac,
169169
sizeof(mlxsw_m->base_mac));
170170
if (err) {
171171
dev_err(mlxsw_m->bus_info->dev, "Port %d: Failed to init core port\n",

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,12 +1733,16 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,
17331733
struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
17341734
bool split = !!split_base_local_port;
17351735
struct mlxsw_sp_port *mlxsw_sp_port;
1736+
u32 lanes = port_mapping->width;
17361737
struct net_device *dev;
1738+
bool splittable;
17371739
int err;
17381740

1741+
splittable = lanes > 1 && !split;
17391742
err = mlxsw_core_port_init(mlxsw_sp->core, local_port,
17401743
port_mapping->module + 1, split,
1741-
port_mapping->lane / port_mapping->width,
1744+
port_mapping->lane / lanes,
1745+
splittable, lanes,
17421746
mlxsw_sp->base_mac,
17431747
sizeof(mlxsw_sp->base_mac));
17441748
if (err) {
@@ -2232,13 +2236,6 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
22322236
return -EINVAL;
22332237
}
22342238

2235-
/* Split ports cannot be split. */
2236-
if (mlxsw_sp_port->split) {
2237-
netdev_err(mlxsw_sp_port->dev, "Port cannot be split further\n");
2238-
NL_SET_ERR_MSG_MOD(extack, "Port cannot be split further");
2239-
return -EINVAL;
2240-
}
2241-
22422239
max_width = mlxsw_core_module_max_width(mlxsw_core,
22432240
mlxsw_sp_port->mapping.module);
22442241
if (max_width < 0) {
@@ -2247,19 +2244,13 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
22472244
return max_width;
22482245
}
22492246

2250-
/* Split port with non-max and 1 module width cannot be split. */
2251-
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) {
22522249
netdev_err(mlxsw_sp_port->dev, "Port cannot be split\n");
22532250
NL_SET_ERR_MSG_MOD(extack, "Port cannot be split");
22542251
return -EINVAL;
22552252
}
22562253

2257-
if (count == 1 || !is_power_of_2(count) || count > max_width) {
2258-
netdev_err(mlxsw_sp_port->dev, "Invalid split count\n");
2259-
NL_SET_ERR_MSG_MOD(extack, "Invalid split count");
2260-
return -EINVAL;
2261-
}
2262-
22632254
offset = mlxsw_sp_local_ports_offset(mlxsw_core, count, max_width);
22642255
if (offset < 0) {
22652256
netdev_err(mlxsw_sp_port->dev, "Cannot obtain local port offset\n");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static int mlxsw_sib_port_create(struct mlxsw_sib *mlxsw_sib, u8 local_port,
281281
int err;
282282

283283
err = mlxsw_core_port_init(mlxsw_sib->core, local_port,
284-
module + 1, false, 0,
284+
module + 1, false, 0, false, 0,
285285
mlxsw_sib->hw_id, sizeof(mlxsw_sib->hw_id));
286286
if (err) {
287287
dev_err(mlxsw_sib->bus_info->dev, "Port %d: Failed to init core port\n",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ static int mlxsw_sx_port_eth_create(struct mlxsw_sx *mlxsw_sx, u8 local_port,
11071107
int err;
11081108

11091109
err = mlxsw_core_port_init(mlxsw_sx->core, local_port,
1110-
module + 1, false, 0,
1110+
module + 1, false, 0, false, 0,
11111111
mlxsw_sx->hw_id, sizeof(mlxsw_sx->hw_id));
11121112
if (err) {
11131113
dev_err(mlxsw_sx->bus_info->dev, "Port %d: Failed to init core port\n",

0 commit comments

Comments
 (0)