Commit 2132b71f authored by Aya Levin's avatar Aya Levin Committed by Saeed Mahameed

net/mlx5e: Advertise globaly supported FEC modes

Ethtool advertise supported link modes on an interface. Per each FEC
mode, query if there is a link type which supports it. If so, add this
FEC mode to the supported FEC modes list. Prior to this patch, ethtool
advertised only the supported FEC modes on the current link type.
Add an explicit mapping between internal FEC modes and ethtool link mode
bits. With this change, adding new FEC modes in the downstream patch
would be easier.
Signed-off-by: default avatarAya Levin <ayal@mellanox.com>
Reviewed-by: default avatarEran Ben Elisha <eranbe@mellanox.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
parent 4bd9d507
...@@ -441,13 +441,13 @@ static int mlx5e_get_fec_cap_field(u32 *pplm, ...@@ -441,13 +441,13 @@ static int mlx5e_get_fec_cap_field(u32 *pplm,
return 0; return 0;
} }
int mlx5e_get_fec_caps(struct mlx5_core_dev *dev, u8 *fec_caps) bool mlx5e_fec_in_caps(struct mlx5_core_dev *dev, int fec_policy)
{ {
u32 out[MLX5_ST_SZ_DW(pplm_reg)] = {}; u32 out[MLX5_ST_SZ_DW(pplm_reg)] = {};
u32 in[MLX5_ST_SZ_DW(pplm_reg)] = {}; u32 in[MLX5_ST_SZ_DW(pplm_reg)] = {};
int sz = MLX5_ST_SZ_BYTES(pplm_reg); int sz = MLX5_ST_SZ_BYTES(pplm_reg);
u32 current_fec_speed;
int err; int err;
int i;
if (!MLX5_CAP_GEN(dev, pcam_reg)) if (!MLX5_CAP_GEN(dev, pcam_reg))
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -458,13 +458,16 @@ int mlx5e_get_fec_caps(struct mlx5_core_dev *dev, u8 *fec_caps) ...@@ -458,13 +458,16 @@ int mlx5e_get_fec_caps(struct mlx5_core_dev *dev, u8 *fec_caps)
MLX5_SET(pplm_reg, in, local_port, 1); MLX5_SET(pplm_reg, in, local_port, 1);
err = mlx5_core_access_reg(dev, in, sz, out, sz, MLX5_REG_PPLM, 0, 0); err = mlx5_core_access_reg(dev, in, sz, out, sz, MLX5_REG_PPLM, 0, 0);
if (err) if (err)
return err; return false;
err = mlx5e_port_linkspeed(dev, &current_fec_speed); for (i = 0; i < MLX5E_FEC_SUPPORTED_SPEEDS; i++) {
if (err) u8 fec_caps;
return err;
return mlx5e_get_fec_cap_field(out, fec_caps, current_fec_speed); mlx5e_get_fec_cap_field(out, &fec_caps, fec_supported_speeds[i]);
if (fec_caps & fec_policy)
return true;
}
return false;
} }
int mlx5e_get_fec_mode(struct mlx5_core_dev *dev, u32 *fec_mode_active, int mlx5e_get_fec_mode(struct mlx5_core_dev *dev, u32 *fec_mode_active,
......
...@@ -60,7 +60,7 @@ int mlx5e_port_set_pbmc(struct mlx5_core_dev *mdev, void *in); ...@@ -60,7 +60,7 @@ int mlx5e_port_set_pbmc(struct mlx5_core_dev *mdev, void *in);
int mlx5e_port_query_priority2buffer(struct mlx5_core_dev *mdev, u8 *buffer); int mlx5e_port_query_priority2buffer(struct mlx5_core_dev *mdev, u8 *buffer);
int mlx5e_port_set_priority2buffer(struct mlx5_core_dev *mdev, u8 *buffer); int mlx5e_port_set_priority2buffer(struct mlx5_core_dev *mdev, u8 *buffer);
int mlx5e_get_fec_caps(struct mlx5_core_dev *dev, u8 *fec_caps); bool mlx5e_fec_in_caps(struct mlx5_core_dev *dev, int fec_policy);
int mlx5e_get_fec_mode(struct mlx5_core_dev *dev, u32 *fec_mode_active, int mlx5e_get_fec_mode(struct mlx5_core_dev *dev, u32 *fec_mode_active,
u8 *fec_configured_mode); u8 *fec_configured_mode);
int mlx5e_set_fec_mode(struct mlx5_core_dev *dev, u8 fec_policy); int mlx5e_set_fec_mode(struct mlx5_core_dev *dev, u8 fec_policy);
......
...@@ -650,45 +650,44 @@ static u32 pplm2ethtool_fec(u_long fec_mode, unsigned long size) ...@@ -650,45 +650,44 @@ static u32 pplm2ethtool_fec(u_long fec_mode, unsigned long size)
return 0; return 0;
} }
/* we use ETHTOOL_FEC_* offset and apply it to ETHTOOL_LINK_MODE_FEC_*_BIT */ #define MLX5E_ADVERTISE_SUPPORTED_FEC(mlx5_fec, ethtool_fec) \
static u32 ethtool_fec2ethtool_caps(u_long ethtool_fec_code) do { \
{ if (mlx5e_fec_in_caps(dev, 1 << (mlx5_fec))) \
u32 offset; __set_bit(ethtool_fec, \
link_ksettings->link_modes.supported);\
offset = find_first_bit(&ethtool_fec_code, sizeof(u32)); } while (0)
offset -= ETHTOOL_FEC_OFF_BIT;
offset += ETHTOOL_LINK_MODE_FEC_NONE_BIT; static const u32 pplm_fec_2_ethtool_linkmodes[] = {
[MLX5E_FEC_NOFEC] = ETHTOOL_LINK_MODE_FEC_NONE_BIT,
return offset; [MLX5E_FEC_FIRECODE] = ETHTOOL_LINK_MODE_FEC_BASER_BIT,
} [MLX5E_FEC_RS_528_514] = ETHTOOL_LINK_MODE_FEC_RS_BIT,
};
static int get_fec_supported_advertised(struct mlx5_core_dev *dev, static int get_fec_supported_advertised(struct mlx5_core_dev *dev,
struct ethtool_link_ksettings *link_ksettings) struct ethtool_link_ksettings *link_ksettings)
{ {
u_long fec_caps = 0; u_long active_fec = 0;
u32 active_fec = 0;
u32 offset;
u32 bitn; u32 bitn;
int err; int err;
err = mlx5e_get_fec_caps(dev, (u8 *)&fec_caps); err = mlx5e_get_fec_mode(dev, (u32 *)&active_fec, NULL);
if (err) if (err)
return (err == -EOPNOTSUPP) ? 0 : err; return (err == -EOPNOTSUPP) ? 0 : err;
err = mlx5e_get_fec_mode(dev, &active_fec, NULL); MLX5E_ADVERTISE_SUPPORTED_FEC(MLX5E_FEC_NOFEC,
if (err) ETHTOOL_LINK_MODE_FEC_NONE_BIT);
return err; MLX5E_ADVERTISE_SUPPORTED_FEC(MLX5E_FEC_FIRECODE,
ETHTOOL_LINK_MODE_FEC_BASER_BIT);
for_each_set_bit(bitn, &fec_caps, ARRAY_SIZE(pplm_fec_2_ethtool)) { MLX5E_ADVERTISE_SUPPORTED_FEC(MLX5E_FEC_RS_528_514,
u_long ethtool_bitmask = pplm_fec_2_ethtool[bitn]; ETHTOOL_LINK_MODE_FEC_RS_BIT);
offset = ethtool_fec2ethtool_caps(ethtool_bitmask); /* active fec is a bit set, find out which bit is set and
__set_bit(offset, link_ksettings->link_modes.supported); * advertise the corresponding ethtool bit
} */
bitn = find_first_bit(&active_fec, sizeof(u32) * BITS_PER_BYTE);
active_fec = pplm2ethtool_fec(active_fec, sizeof(u32) * BITS_PER_BYTE); if (bitn < ARRAY_SIZE(pplm_fec_2_ethtool_linkmodes))
offset = ethtool_fec2ethtool_caps(active_fec); __set_bit(pplm_fec_2_ethtool_linkmodes[bitn],
__set_bit(offset, link_ksettings->link_modes.advertising); link_ksettings->link_modes.advertising);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment