net/mlx5e: Fix arch depending casting issue in FEC
authorAya Levin <ayal@mellanox.com>
Mon, 13 Apr 2020 08:31:00 +0000 (11:31 +0300)
committerSaeed Mahameed <saeedm@mellanox.com>
Fri, 29 May 2020 20:07:53 +0000 (13:07 -0700)
Change type of active_fec to u32 to match the type expected by
mlx5e_get_fec_mode. Copy active_fec and configured_fec values to
unsigned long before preforming bitwise manipulations.
Take the same approach when configuring FEC over 50G link modes: copy
the policy into an unsigned long and only than preform bitwise
operations.

Fixes: 2132b71f78d2 ("net/mlx5e: Advertise globaly supported FEC modes")
Signed-off-by: Aya Levin <ayal@mellanox.com>
Reviewed-by: Tariq Toukan <tariqt@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/en/port.c
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c

index 2c4a670c8ffd4b076460b5b7d6e8b70c7499e5f3..2a8950b3056f95445bc335835c0d694fa7d01011 100644 (file)
@@ -369,17 +369,19 @@ enum mlx5e_fec_supported_link_mode {
                        *_policy = MLX5_GET(pplm_reg, _buf, fec_override_admin_##link); \
        } while (0)
 
-#define MLX5E_FEC_OVERRIDE_ADMIN_50G_POLICY(buf, policy, write, link)          \
-       do {                                                                    \
-               u16 *__policy = &(policy);                                      \
-               bool _write = (write);                                          \
-                                                                               \
-               if (_write && *__policy)                                        \
-                       *__policy = find_first_bit((u_long *)__policy,          \
-                                                  sizeof(u16) * BITS_PER_BYTE);\
-               MLX5E_FEC_OVERRIDE_ADMIN_POLICY(buf, *__policy, _write, link);  \
-               if (!_write && *__policy)                                       \
-                       *__policy = 1 << *__policy;                             \
+#define MLX5E_FEC_OVERRIDE_ADMIN_50G_POLICY(buf, policy, write, link)                  \
+       do {                                                                            \
+               unsigned long policy_long;                                              \
+               u16 *__policy = &(policy);                                              \
+               bool _write = (write);                                                  \
+                                                                                       \
+               policy_long = *__policy;                                                \
+               if (_write && *__policy)                                                \
+                       *__policy = find_first_bit(&policy_long,                        \
+                                                  sizeof(policy_long) * BITS_PER_BYTE);\
+               MLX5E_FEC_OVERRIDE_ADMIN_POLICY(buf, *__policy, _write, link);          \
+               if (!_write && *__policy)                                               \
+                       *__policy = 1 << *__policy;                                     \
        } while (0)
 
 /* get/set FEC admin field for a given speed */
index 6d703ddee4e27fef265f97aefff8dac422dfc8ed..6f582eb83e54f997cca90bcc14b79cbbdef7e46c 100644 (file)
@@ -665,11 +665,12 @@ static const u32 pplm_fec_2_ethtool_linkmodes[] = {
 static int get_fec_supported_advertised(struct mlx5_core_dev *dev,
                                        struct ethtool_link_ksettings *link_ksettings)
 {
-       u_long active_fec = 0;
+       unsigned long active_fec_long;
+       u32 active_fec;
        u32 bitn;
        int err;
 
-       err = mlx5e_get_fec_mode(dev, (u32 *)&active_fec, NULL);
+       err = mlx5e_get_fec_mode(dev, &active_fec, NULL);
        if (err)
                return (err == -EOPNOTSUPP) ? 0 : err;
 
@@ -682,10 +683,11 @@ static int get_fec_supported_advertised(struct mlx5_core_dev *dev,
        MLX5E_ADVERTISE_SUPPORTED_FEC(MLX5E_FEC_LLRS_272_257_1,
                                      ETHTOOL_LINK_MODE_FEC_LLRS_BIT);
 
+       active_fec_long = active_fec;
        /* active fec is a bit set, find out which bit is set and
         * advertise the corresponding ethtool bit
         */
-       bitn = find_first_bit(&active_fec, sizeof(u32) * BITS_PER_BYTE);
+       bitn = find_first_bit(&active_fec_long, sizeof(active_fec_long) * BITS_PER_BYTE);
        if (bitn < ARRAY_SIZE(pplm_fec_2_ethtool_linkmodes))
                __set_bit(pplm_fec_2_ethtool_linkmodes[bitn],
                          link_ksettings->link_modes.advertising);
@@ -1517,8 +1519,8 @@ static int mlx5e_get_fecparam(struct net_device *netdev,
 {
        struct mlx5e_priv *priv = netdev_priv(netdev);
        struct mlx5_core_dev *mdev = priv->mdev;
-       u16 fec_configured = 0;
-       u32 fec_active = 0;
+       u16 fec_configured;
+       u32 fec_active;
        int err;
 
        err = mlx5e_get_fec_mode(mdev, &fec_active, &fec_configured);
@@ -1526,14 +1528,14 @@ static int mlx5e_get_fecparam(struct net_device *netdev,
        if (err)
                return err;
 
-       fecparam->active_fec = pplm2ethtool_fec((u_long)fec_active,
-                                               sizeof(u32) * BITS_PER_BYTE);
+       fecparam->active_fec = pplm2ethtool_fec((unsigned long)fec_active,
+                                               sizeof(unsigned long) * BITS_PER_BYTE);
 
        if (!fecparam->active_fec)
                return -EOPNOTSUPP;
 
-       fecparam->fec = pplm2ethtool_fec((u_long)fec_configured,
-                                        sizeof(u16) * BITS_PER_BYTE);
+       fecparam->fec = pplm2ethtool_fec((unsigned long)fec_configured,
+                                        sizeof(unsigned long) * BITS_PER_BYTE);
 
        return 0;
 }