mlxsw: spectrum: Add new operation for getting the port's speed
authorShalom Toledo <shalomt@mellanox.com>
Thu, 4 Jul 2019 07:07:37 +0000 (10:07 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 5 Jul 2019 22:28:57 +0000 (15:28 -0700)
New operation for getting the port's speed as part of port-type-speed
operations.

Signed-off-by: Shalom Toledo <shalomt@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Reviewed-by: Petr Machata <petrm@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum.c
drivers/net/ethernet/mellanox/mlxsw/spectrum.h

index 67133ba5301586bbe13021cc492c7c9081f9e44e..7cfca2be09fc090fbf1703f20c30ecb1218e946e 100644 (file)
@@ -2655,28 +2655,33 @@ mlxsw_sp1_from_ptys_link(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto,
        }
 }
 
+static u32
+mlxsw_sp1_from_ptys_speed(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto)
+{
+       int i;
+
+       for (i = 0; i < MLXSW_SP1_PORT_LINK_MODE_LEN; i++) {
+               if (ptys_eth_proto & mlxsw_sp1_port_link_mode[i].mask)
+                       return mlxsw_sp1_port_link_mode[i].speed;
+       }
+
+       return SPEED_UNKNOWN;
+}
+
 static void
 mlxsw_sp1_from_ptys_speed_duplex(struct mlxsw_sp *mlxsw_sp, bool carrier_ok,
                                 u32 ptys_eth_proto,
                                 struct ethtool_link_ksettings *cmd)
 {
-       u32 speed = SPEED_UNKNOWN;
-       u8 duplex = DUPLEX_UNKNOWN;
-       int i;
+       cmd->base.speed = SPEED_UNKNOWN;
+       cmd->base.duplex = DUPLEX_UNKNOWN;
 
        if (!carrier_ok)
-               goto out;
+               return;
 
-       for (i = 0; i < MLXSW_SP1_PORT_LINK_MODE_LEN; i++) {
-               if (ptys_eth_proto & mlxsw_sp1_port_link_mode[i].mask) {
-                       speed = mlxsw_sp1_port_link_mode[i].speed;
-                       duplex = DUPLEX_FULL;
-                       break;
-               }
-       }
-out:
-       cmd->base.speed = speed;
-       cmd->base.duplex = duplex;
+       cmd->base.speed = mlxsw_sp1_from_ptys_speed(mlxsw_sp, ptys_eth_proto);
+       if (cmd->base.speed != SPEED_UNKNOWN)
+               cmd->base.duplex = DUPLEX_FULL;
 }
 
 static u32
@@ -2747,6 +2752,7 @@ static const struct mlxsw_sp_port_type_speed_ops
 mlxsw_sp1_port_type_speed_ops = {
        .from_ptys_supported_port       = mlxsw_sp1_from_ptys_supported_port,
        .from_ptys_link                 = mlxsw_sp1_from_ptys_link,
+       .from_ptys_speed                = mlxsw_sp1_from_ptys_speed,
        .from_ptys_speed_duplex         = mlxsw_sp1_from_ptys_speed_duplex,
        .to_ptys_advert_link            = mlxsw_sp1_to_ptys_advert_link,
        .to_ptys_speed                  = mlxsw_sp1_to_ptys_speed,
@@ -2997,28 +3003,33 @@ mlxsw_sp2_from_ptys_link(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto,
        }
 }
 
+static u32
+mlxsw_sp2_from_ptys_speed(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto)
+{
+       int i;
+
+       for (i = 0; i < MLXSW_SP2_PORT_LINK_MODE_LEN; i++) {
+               if (ptys_eth_proto & mlxsw_sp2_port_link_mode[i].mask)
+                       return mlxsw_sp2_port_link_mode[i].speed;
+       }
+
+       return SPEED_UNKNOWN;
+}
+
 static void
 mlxsw_sp2_from_ptys_speed_duplex(struct mlxsw_sp *mlxsw_sp, bool carrier_ok,
                                 u32 ptys_eth_proto,
                                 struct ethtool_link_ksettings *cmd)
 {
-       u32 speed = SPEED_UNKNOWN;
-       u8 duplex = DUPLEX_UNKNOWN;
-       int i;
+       cmd->base.speed = SPEED_UNKNOWN;
+       cmd->base.duplex = DUPLEX_UNKNOWN;
 
        if (!carrier_ok)
-               goto out;
+               return;
 
-       for (i = 0; i < MLXSW_SP2_PORT_LINK_MODE_LEN; i++) {
-               if (ptys_eth_proto & mlxsw_sp2_port_link_mode[i].mask) {
-                       speed = mlxsw_sp2_port_link_mode[i].speed;
-                       duplex = DUPLEX_FULL;
-                       break;
-               }
-       }
-out:
-       cmd->base.speed = speed;
-       cmd->base.duplex = duplex;
+       cmd->base.speed = mlxsw_sp2_from_ptys_speed(mlxsw_sp, ptys_eth_proto);
+       if (cmd->base.speed != SPEED_UNKNOWN)
+               cmd->base.duplex = DUPLEX_FULL;
 }
 
 static bool
@@ -3129,6 +3140,7 @@ static const struct mlxsw_sp_port_type_speed_ops
 mlxsw_sp2_port_type_speed_ops = {
        .from_ptys_supported_port       = mlxsw_sp2_from_ptys_supported_port,
        .from_ptys_link                 = mlxsw_sp2_from_ptys_link,
+       .from_ptys_speed                = mlxsw_sp2_from_ptys_speed,
        .from_ptys_speed_duplex         = mlxsw_sp2_from_ptys_speed_duplex,
        .to_ptys_advert_link            = mlxsw_sp2_to_ptys_advert_link,
        .to_ptys_speed                  = mlxsw_sp2_to_ptys_speed,
index 7f8427c1a997c42d126ec14972a9cf7be8279ec6..c21cd1a425c7f5e3f6cbf8fb40c37e82eeedebdd 100644 (file)
@@ -279,6 +279,7 @@ struct mlxsw_sp_port_type_speed_ops {
                                         struct ethtool_link_ksettings *cmd);
        void (*from_ptys_link)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto,
                               unsigned long *mode);
+       u32 (*from_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto);
        void (*from_ptys_speed_duplex)(struct mlxsw_sp *mlxsw_sp,
                                       bool carrier_ok, u32 ptys_eth_proto,
                                       struct ethtool_link_ksettings *cmd);