Skip to content

Commit 52244d9

Browse files
Gal Pressmandavem330
authored andcommitted
net/mlx5e: Report correct auto negotiation and allow toggling
Previous to this patch auto negotiation was reported off although it was on by default in hardware. This patch reports the correct information to ethtool and allows the user to toggle it on/off. Added another parameter to set port proto function in order to pass the auto negotiation field to the hardware. Signed-off-by: Gal Pressman <galp@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 665bc53 commit 52244d9

3 files changed

Lines changed: 80 additions & 13 deletions

File tree

‎drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c‎

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,8 @@ static int mlx5e_get_link_ksettings(struct net_device *netdev,
702702
u32 eth_proto_admin;
703703
u32 eth_proto_lp;
704704
u32 eth_proto_oper;
705+
u8 an_disable_admin;
706+
u8 an_status;
705707
int err;
706708

707709
err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN, 1);
@@ -712,10 +714,12 @@ static int mlx5e_get_link_ksettings(struct net_device *netdev,
712714
goto err_query_ptys;
713715
}
714716

715-
eth_proto_cap = MLX5_GET(ptys_reg, out, eth_proto_capability);
716-
eth_proto_admin = MLX5_GET(ptys_reg, out, eth_proto_admin);
717-
eth_proto_oper = MLX5_GET(ptys_reg, out, eth_proto_oper);
718-
eth_proto_lp = MLX5_GET(ptys_reg, out, eth_proto_lp_advertise);
717+
eth_proto_cap = MLX5_GET(ptys_reg, out, eth_proto_capability);
718+
eth_proto_admin = MLX5_GET(ptys_reg, out, eth_proto_admin);
719+
eth_proto_oper = MLX5_GET(ptys_reg, out, eth_proto_oper);
720+
eth_proto_lp = MLX5_GET(ptys_reg, out, eth_proto_lp_advertise);
721+
an_disable_admin = MLX5_GET(ptys_reg, out, an_disable_admin);
722+
an_status = MLX5_GET(ptys_reg, out, an_status);
719723

720724
ethtool_link_ksettings_zero_link_mode(link_ksettings, supported);
721725
ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising);
@@ -729,6 +733,18 @@ static int mlx5e_get_link_ksettings(struct net_device *netdev,
729733
link_ksettings->base.port = get_connector_port(eth_proto_oper);
730734
get_lp_advertising(eth_proto_lp, link_ksettings);
731735

736+
if (an_status == MLX5_AN_COMPLETE)
737+
ethtool_link_ksettings_add_link_mode(link_ksettings,
738+
lp_advertising, Autoneg);
739+
740+
link_ksettings->base.autoneg = an_disable_admin ? AUTONEG_DISABLE :
741+
AUTONEG_ENABLE;
742+
ethtool_link_ksettings_add_link_mode(link_ksettings, supported,
743+
Autoneg);
744+
if (!an_disable_admin)
745+
ethtool_link_ksettings_add_link_mode(link_ksettings,
746+
advertising, Autoneg);
747+
732748
err_query_ptys:
733749
return err;
734750
}
@@ -764,9 +780,14 @@ static int mlx5e_set_link_ksettings(struct net_device *netdev,
764780
{
765781
struct mlx5e_priv *priv = netdev_priv(netdev);
766782
struct mlx5_core_dev *mdev = priv->mdev;
783+
u32 eth_proto_cap, eth_proto_admin;
784+
bool an_changes = false;
785+
u8 an_disable_admin;
786+
u8 an_disable_cap;
787+
bool an_disable;
767788
u32 link_modes;
789+
u8 an_status;
768790
u32 speed;
769-
u32 eth_proto_cap, eth_proto_admin;
770791
int err;
771792

772793
speed = link_ksettings->base.speed;
@@ -797,10 +818,17 @@ static int mlx5e_set_link_ksettings(struct net_device *netdev,
797818
goto out;
798819
}
799820

800-
if (link_modes == eth_proto_admin)
821+
mlx5_query_port_autoneg(mdev, MLX5_PTYS_EN, &an_status,
822+
&an_disable_cap, &an_disable_admin);
823+
824+
an_disable = link_ksettings->base.autoneg == AUTONEG_DISABLE;
825+
an_changes = ((!an_disable && an_disable_admin) ||
826+
(an_disable && !an_disable_admin));
827+
828+
if (!an_changes && link_modes == eth_proto_admin)
801829
goto out;
802830

803-
mlx5_set_port_proto(mdev, link_modes, MLX5_PTYS_EN);
831+
mlx5_set_port_ptys(mdev, an_disable, link_modes, MLX5_PTYS_EN);
804832
mlx5_toggle_port_link(mdev);
805833

806834
out:

‎drivers/net/ethernet/mellanox/mlx5/core/port.c‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,24 @@ int mlx5_query_port_proto_oper(struct mlx5_core_dev *dev,
202202
}
203203
EXPORT_SYMBOL_GPL(mlx5_query_port_proto_oper);
204204

205-
int mlx5_set_port_proto(struct mlx5_core_dev *dev, u32 proto_admin,
206-
int proto_mask)
205+
int mlx5_set_port_ptys(struct mlx5_core_dev *dev, bool an_disable,
206+
u32 proto_admin, int proto_mask)
207207
{
208-
u32 in[MLX5_ST_SZ_DW(ptys_reg)];
209208
u32 out[MLX5_ST_SZ_DW(ptys_reg)];
209+
u32 in[MLX5_ST_SZ_DW(ptys_reg)];
210+
u8 an_disable_admin;
211+
u8 an_disable_cap;
212+
u8 an_status;
213+
214+
mlx5_query_port_autoneg(dev, proto_mask, &an_status,
215+
&an_disable_cap, &an_disable_admin);
216+
if (!an_disable_cap && an_disable)
217+
return -EPERM;
210218

211219
memset(in, 0, sizeof(in));
212220

213221
MLX5_SET(ptys_reg, in, local_port, 1);
222+
MLX5_SET(ptys_reg, in, an_disable_admin, an_disable);
214223
MLX5_SET(ptys_reg, in, proto_mask, proto_mask);
215224
if (proto_mask == MLX5_PTYS_EN)
216225
MLX5_SET(ptys_reg, in, eth_proto_admin, proto_admin);
@@ -220,7 +229,7 @@ int mlx5_set_port_proto(struct mlx5_core_dev *dev, u32 proto_admin,
220229
return mlx5_core_access_reg(dev, in, sizeof(in), out,
221230
sizeof(out), MLX5_REG_PTYS, 0, 1);
222231
}
223-
EXPORT_SYMBOL_GPL(mlx5_set_port_proto);
232+
EXPORT_SYMBOL_GPL(mlx5_set_port_ptys);
224233

225234
/* This function should be used after setting a port register only */
226235
void mlx5_toggle_port_link(struct mlx5_core_dev *dev)
@@ -530,6 +539,25 @@ int mlx5_query_port_pfc(struct mlx5_core_dev *dev, u8 *pfc_en_tx, u8 *pfc_en_rx)
530539
}
531540
EXPORT_SYMBOL_GPL(mlx5_query_port_pfc);
532541

542+
void mlx5_query_port_autoneg(struct mlx5_core_dev *dev, int proto_mask,
543+
u8 *an_status,
544+
u8 *an_disable_cap, u8 *an_disable_admin)
545+
{
546+
u32 out[MLX5_ST_SZ_DW(ptys_reg)];
547+
548+
*an_status = 0;
549+
*an_disable_cap = 0;
550+
*an_disable_admin = 0;
551+
552+
if (mlx5_query_port_ptys(dev, out, sizeof(out), proto_mask, 1))
553+
return;
554+
555+
*an_status = MLX5_GET(ptys_reg, out, an_status);
556+
*an_disable_cap = MLX5_GET(ptys_reg, out, an_disable_cap);
557+
*an_disable_admin = MLX5_GET(ptys_reg, out, an_disable_admin);
558+
}
559+
EXPORT_SYMBOL_GPL(mlx5_query_port_autoneg);
560+
533561
int mlx5_max_tc(struct mlx5_core_dev *mdev)
534562
{
535563
u8 num_tc = MLX5_CAP_GEN(mdev, max_tc) ? : 8;

‎include/linux/mlx5/port.h‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ enum mlx5_module_id {
4747
MLX5_MODULE_ID_QSFP28 = 0x11,
4848
};
4949

50+
enum mlx5_an_status {
51+
MLX5_AN_UNAVAILABLE = 0,
52+
MLX5_AN_COMPLETE = 1,
53+
MLX5_AN_FAILED = 2,
54+
MLX5_AN_LINK_UP = 3,
55+
MLX5_AN_LINK_DOWN = 4,
56+
};
57+
5058
#define MLX5_EEPROM_MAX_BYTES 32
5159
#define MLX5_EEPROM_IDENTIFIER_BYTE_MASK 0x000000ff
5260
#define MLX5_I2C_ADDR_LOW 0x50
@@ -65,14 +73,17 @@ int mlx5_query_port_link_width_oper(struct mlx5_core_dev *dev,
6573
int mlx5_query_port_proto_oper(struct mlx5_core_dev *dev,
6674
u8 *proto_oper, int proto_mask,
6775
u8 local_port);
68-
int mlx5_set_port_proto(struct mlx5_core_dev *dev, u32 proto_admin,
69-
int proto_mask);
76+
int mlx5_set_port_ptys(struct mlx5_core_dev *dev, bool an_disable,
77+
u32 proto_admin, int proto_mask);
7078
void mlx5_toggle_port_link(struct mlx5_core_dev *dev);
7179
int mlx5_set_port_admin_status(struct mlx5_core_dev *dev,
7280
enum mlx5_port_status status);
7381
int mlx5_query_port_admin_status(struct mlx5_core_dev *dev,
7482
enum mlx5_port_status *status);
7583
int mlx5_set_port_beacon(struct mlx5_core_dev *dev, u16 beacon_duration);
84+
void mlx5_query_port_autoneg(struct mlx5_core_dev *dev, int proto_mask,
85+
u8 *an_status,
86+
u8 *an_disable_cap, u8 *an_disable_admin);
7687

7788
int mlx5_set_port_mtu(struct mlx5_core_dev *dev, u16 mtu, u8 port);
7889
void mlx5_query_port_max_mtu(struct mlx5_core_dev *dev, u16 *max_mtu, u8 port);

0 commit comments

Comments
 (0)