mlxsw: use devlink helper to generate physical port name
authorJiri Pirko <jiri@mellanox.com>
Fri, 18 May 2018 07:29:04 +0000 (09:29 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sat, 19 May 2018 20:30:39 +0000 (16:30 -0400)
Since devlink knows the info needed to generate the physical port name
in a generic way for all devlink users, use the helper to do the job.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/core.c
drivers/net/ethernet/mellanox/mlxsw/core.h
drivers/net/ethernet/mellanox/mlxsw/spectrum.c
drivers/net/ethernet/mellanox/mlxsw/switchx2.c

index a720aa11bcc05f751de4a56b03da364f354cdfa2..a38faec45b30213dfa84e9b0b4642dcf28f3cabe 100644 (file)
@@ -1763,6 +1763,17 @@ enum devlink_port_type mlxsw_core_port_type_get(struct mlxsw_core *mlxsw_core,
 }
 EXPORT_SYMBOL(mlxsw_core_port_type_get);
 
+int mlxsw_core_port_get_phys_port_name(struct mlxsw_core *mlxsw_core,
+                                      u8 local_port, char *name, size_t len)
+{
+       struct mlxsw_core_port *mlxsw_core_port =
+                                       &mlxsw_core->ports[local_port];
+       struct devlink_port *devlink_port = &mlxsw_core_port->devlink_port;
+
+       return devlink_port_get_phys_port_name(devlink_port, name, len);
+}
+EXPORT_SYMBOL(mlxsw_core_port_get_phys_port_name);
+
 static void mlxsw_core_buf_dump_dbg(struct mlxsw_core *mlxsw_core,
                                    const char *buf, size_t size)
 {
index e65287c15afd9e36768cdca3f084b5e5f723e0c3..4eac7fbd07d5d394b28acc53f133c41edb895921 100644 (file)
@@ -209,6 +209,8 @@ void mlxsw_core_port_clear(struct mlxsw_core *mlxsw_core, u8 local_port,
                           void *port_driver_priv);
 enum devlink_port_type mlxsw_core_port_type_get(struct mlxsw_core *mlxsw_core,
                                                u8 local_port);
+int mlxsw_core_port_get_phys_port_name(struct mlxsw_core *mlxsw_core,
+                                      u8 local_port, char *name, size_t len);
 
 int mlxsw_core_schedule_dw(struct delayed_work *dwork, unsigned long delay);
 bool mlxsw_core_schedule_work(struct work_struct *work);
index 96f6d8af1fd8fc791984b39e4384b1916722cf0d..bb252b36994d6e615a0bb6b8337f920c9ee19f17 100644 (file)
@@ -1238,21 +1238,10 @@ static int mlxsw_sp_port_get_phys_port_name(struct net_device *dev, char *name,
                                            size_t len)
 {
        struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
-       u8 module = mlxsw_sp_port->mapping.module;
-       u8 width = mlxsw_sp_port->mapping.width;
-       u8 lane = mlxsw_sp_port->mapping.lane;
-       int err;
-
-       if (!mlxsw_sp_port->split)
-               err = snprintf(name, len, "p%d", module + 1);
-       else
-               err = snprintf(name, len, "p%ds%d", module + 1,
-                              lane / width);
 
-       if (err >= len)
-               return -EINVAL;
-
-       return 0;
+       return mlxsw_core_port_get_phys_port_name(mlxsw_sp_port->mlxsw_sp->core,
+                                                 mlxsw_sp_port->local_port,
+                                                 name, len);
 }
 
 static struct mlxsw_sp_port_mall_tc_entry *
index 551e05067b1e7bc4610d55fa52d337401198abff..3922c1cfe5f5a78e91c11fcdd6cc04ab6a98bb25 100644 (file)
@@ -417,13 +417,10 @@ static int mlxsw_sx_port_get_phys_port_name(struct net_device *dev, char *name,
                                            size_t len)
 {
        struct mlxsw_sx_port *mlxsw_sx_port = netdev_priv(dev);
-       int err;
-
-       err = snprintf(name, len, "p%d", mlxsw_sx_port->mapping.module + 1);
-       if (err >= len)
-               return -EINVAL;
 
-       return 0;
+       return mlxsw_core_port_get_phys_port_name(mlxsw_sx_port->mlxsw_sx->core,
+                                                 mlxsw_sx_port->local_port,
+                                                 name, len);
 }
 
 static const struct net_device_ops mlxsw_sx_port_netdev_ops = {