Skip to content

Commit 2bf9a58

Browse files
idoschdavem330
authored andcommitted
mlxsw: spectrum: Add support for physical port names
Export to userspace the front panel name of the port, so that udev can rename the ports accordingly. The convention suggested by switchdev documentation is used: 1) Non-split: pX 2) Split: pXsY Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 75f3a10 commit 2bf9a58

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

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

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ mlxsw_sp_port_system_port_mapping_set(struct mlxsw_sp_port *mlxsw_sp_port)
305305
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sspr), sspr_pl);
306306
}
307307

308-
static int mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp,
309-
u8 local_port, u8 *p_module,
310-
u8 *p_width)
308+
static int __mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp,
309+
u8 local_port, u8 *p_module,
310+
u8 *p_width, u8 *p_lane)
311311
{
312312
char pmlp_pl[MLXSW_REG_PMLP_LEN];
313313
int err;
@@ -318,9 +318,20 @@ static int mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp,
318318
return err;
319319
*p_module = mlxsw_reg_pmlp_module_get(pmlp_pl, 0);
320320
*p_width = mlxsw_reg_pmlp_width_get(pmlp_pl);
321+
*p_lane = mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, 0);
321322
return 0;
322323
}
323324

325+
static int mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp,
326+
u8 local_port, u8 *p_module,
327+
u8 *p_width)
328+
{
329+
u8 lane;
330+
331+
return __mlxsw_sp_port_module_info_get(mlxsw_sp, local_port, p_module,
332+
p_width, &lane);
333+
}
334+
324335
static int mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u8 local_port,
325336
u8 module, u8 width, u8 lane)
326337
{
@@ -861,6 +872,33 @@ int mlxsw_sp_port_kill_vid(struct net_device *dev,
861872
return 0;
862873
}
863874

875+
static int mlxsw_sp_port_get_phys_port_name(struct net_device *dev, char *name,
876+
size_t len)
877+
{
878+
struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
879+
u8 module, width, lane;
880+
int err;
881+
882+
err = __mlxsw_sp_port_module_info_get(mlxsw_sp_port->mlxsw_sp,
883+
mlxsw_sp_port->local_port,
884+
&module, &width, &lane);
885+
if (err) {
886+
netdev_err(dev, "Failed to retrieve module information\n");
887+
return err;
888+
}
889+
890+
if (!mlxsw_sp_port->split)
891+
err = snprintf(name, len, "p%d", module + 1);
892+
else
893+
err = snprintf(name, len, "p%ds%d", module + 1,
894+
lane / width);
895+
896+
if (err >= len)
897+
return -EINVAL;
898+
899+
return 0;
900+
}
901+
864902
static const struct net_device_ops mlxsw_sp_port_netdev_ops = {
865903
.ndo_open = mlxsw_sp_port_open,
866904
.ndo_stop = mlxsw_sp_port_stop,
@@ -877,6 +915,7 @@ static const struct net_device_ops mlxsw_sp_port_netdev_ops = {
877915
.ndo_bridge_setlink = switchdev_port_bridge_setlink,
878916
.ndo_bridge_getlink = switchdev_port_bridge_getlink,
879917
.ndo_bridge_dellink = switchdev_port_bridge_dellink,
918+
.ndo_get_phys_port_name = mlxsw_sp_port_get_phys_port_name,
880919
};
881920

882921
static void mlxsw_sp_port_get_drvinfo(struct net_device *dev,

0 commit comments

Comments
 (0)