Commit facc9699 authored by Saeed Mahameed's avatar Saeed Mahameed Committed by David S. Miller

net/mlx5e: Fix HW MTU settings

Previously we configured HW MTU to be netdev->mtu, actually we
need to configure netdev->mtu + (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN).

Also, query MTU can not fail, hence make the relevant helper a
void functionm, add mlx5e_set_dev_port_mtu, helper function to
handle MTU setting.
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
Signed-off-by: default avatarOr Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7ec0bb22
...@@ -446,15 +446,11 @@ static int mlx5_query_hca_port(struct ib_device *ibdev, u8 port, ...@@ -446,15 +446,11 @@ static int mlx5_query_hca_port(struct ib_device *ibdev, u8 port,
if (err) if (err)
goto out; goto out;
err = mlx5_query_port_max_mtu(mdev, &max_mtu, port); mlx5_query_port_max_mtu(mdev, &max_mtu, port);
if (err)
goto out;
props->max_mtu = mlx5_mtu_to_ib_mtu(max_mtu); props->max_mtu = mlx5_mtu_to_ib_mtu(max_mtu);
err = mlx5_query_port_oper_mtu(mdev, &oper_mtu, port); mlx5_query_port_oper_mtu(mdev, &oper_mtu, port);
if (err)
goto out;
props->active_mtu = mlx5_mtu_to_ib_mtu(oper_mtu); props->active_mtu = mlx5_mtu_to_ib_mtu(oper_mtu);
......
...@@ -57,7 +57,6 @@ ...@@ -57,7 +57,6 @@
#define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS 0x20 #define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS 0x20
#define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES 0x80 #define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES 0x80
#define MLX5E_PARAMS_DEFAULT_RX_HASH_LOG_TBL_SZ 0x7 #define MLX5E_PARAMS_DEFAULT_RX_HASH_LOG_TBL_SZ 0x7
#define MLX5E_PARAMS_MIN_MTU 46
#define MLX5E_TX_CQ_POLL_BUDGET 128 #define MLX5E_TX_CQ_POLL_BUDGET 128
#define MLX5E_UPDATE_STATS_INTERVAL 200 /* msecs */ #define MLX5E_UPDATE_STATS_INTERVAL 200 /* msecs */
......
...@@ -277,6 +277,9 @@ static void mlx5e_send_nop(struct mlx5e_sq *sq) ...@@ -277,6 +277,9 @@ static void mlx5e_send_nop(struct mlx5e_sq *sq)
mlx5e_tx_notify_hw(sq, wqe); mlx5e_tx_notify_hw(sq, wqe);
} }
#define MLX5E_HW2SW_MTU(hwmtu) (hwmtu - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
#define MLX5E_SW2HW_MTU(swmtu) (swmtu + (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
static int mlx5e_create_rq(struct mlx5e_channel *c, static int mlx5e_create_rq(struct mlx5e_channel *c,
struct mlx5e_rq_param *param, struct mlx5e_rq_param *param,
struct mlx5e_rq *rq) struct mlx5e_rq *rq)
...@@ -305,7 +308,7 @@ static int mlx5e_create_rq(struct mlx5e_channel *c, ...@@ -305,7 +308,7 @@ static int mlx5e_create_rq(struct mlx5e_channel *c,
} }
rq->wqe_sz = (priv->params.lro_en) ? priv->params.lro_wqe_sz : rq->wqe_sz = (priv->params.lro_en) ? priv->params.lro_wqe_sz :
priv->netdev->mtu + ETH_HLEN + VLAN_HLEN; MLX5E_SW2HW_MTU(priv->netdev->mtu);
for (i = 0; i < wq_sz; i++) { for (i = 0; i < wq_sz; i++) {
struct mlx5e_rx_wqe *wqe = mlx5_wq_ll_get_wqe(&rq->wq, i); struct mlx5e_rx_wqe *wqe = mlx5_wq_ll_get_wqe(&rq->wq, i);
...@@ -1367,11 +1370,30 @@ static void mlx5e_close_tirs(struct mlx5e_priv *priv) ...@@ -1367,11 +1370,30 @@ static void mlx5e_close_tirs(struct mlx5e_priv *priv)
mlx5e_close_tir(priv, i); mlx5e_close_tir(priv, i);
} }
int mlx5e_open_locked(struct net_device *netdev) static int mlx5e_set_dev_port_mtu(struct net_device *netdev)
{ {
struct mlx5e_priv *priv = netdev_priv(netdev); struct mlx5e_priv *priv = netdev_priv(netdev);
struct mlx5_core_dev *mdev = priv->mdev; struct mlx5_core_dev *mdev = priv->mdev;
int actual_mtu; int hw_mtu;
int err;
err = mlx5_set_port_mtu(mdev, MLX5E_SW2HW_MTU(netdev->mtu), 1);
if (err)
return err;
mlx5_query_port_oper_mtu(mdev, &hw_mtu, 1);
if (MLX5E_HW2SW_MTU(hw_mtu) != netdev->mtu)
netdev_warn(netdev, "%s: Port MTU %d is different than netdev mtu %d\n",
__func__, MLX5E_HW2SW_MTU(hw_mtu), netdev->mtu);
netdev->mtu = MLX5E_HW2SW_MTU(hw_mtu);
return 0;
}
int mlx5e_open_locked(struct net_device *netdev)
{
struct mlx5e_priv *priv = netdev_priv(netdev);
int num_txqs; int num_txqs;
int err; int err;
...@@ -1380,25 +1402,9 @@ int mlx5e_open_locked(struct net_device *netdev) ...@@ -1380,25 +1402,9 @@ int mlx5e_open_locked(struct net_device *netdev)
netif_set_real_num_tx_queues(netdev, num_txqs); netif_set_real_num_tx_queues(netdev, num_txqs);
netif_set_real_num_rx_queues(netdev, priv->params.num_channels); netif_set_real_num_rx_queues(netdev, priv->params.num_channels);
err = mlx5_set_port_mtu(mdev, netdev->mtu); err = mlx5e_set_dev_port_mtu(netdev);
if (err) { if (err)
netdev_err(netdev, "%s: mlx5_set_port_mtu failed %d\n",
__func__, err);
return err; return err;
}
err = mlx5_query_port_oper_mtu(mdev, &actual_mtu, 1);
if (err) {
netdev_err(netdev, "%s: mlx5_query_port_oper_mtu failed %d\n",
__func__, err);
return err;
}
if (actual_mtu != netdev->mtu)
netdev_warn(netdev, "%s: Failed to set MTU to %d\n",
__func__, netdev->mtu);
netdev->mtu = actual_mtu;
err = mlx5e_open_tises(priv); err = mlx5e_open_tises(priv);
if (err) { if (err) {
...@@ -1613,15 +1619,14 @@ static int mlx5e_change_mtu(struct net_device *netdev, int new_mtu) ...@@ -1613,15 +1619,14 @@ static int mlx5e_change_mtu(struct net_device *netdev, int new_mtu)
struct mlx5e_priv *priv = netdev_priv(netdev); struct mlx5e_priv *priv = netdev_priv(netdev);
struct mlx5_core_dev *mdev = priv->mdev; struct mlx5_core_dev *mdev = priv->mdev;
int max_mtu; int max_mtu;
int err = 0; int err;
err = mlx5_query_port_max_mtu(mdev, &max_mtu, 1); mlx5_query_port_max_mtu(mdev, &max_mtu, 1);
if (err)
return err;
if (new_mtu > max_mtu || new_mtu < MLX5E_PARAMS_MIN_MTU) { if (new_mtu > max_mtu) {
netdev_err(netdev, "%s: Bad MTU size, mtu must be [%d-%d]\n", netdev_err(netdev,
__func__, MLX5E_PARAMS_MIN_MTU, max_mtu); "%s: Bad MTU (%d) > (%d) Max\n",
__func__, new_mtu, max_mtu);
return -EINVAL; return -EINVAL;
} }
......
...@@ -248,22 +248,18 @@ int mlx5_query_port_status(struct mlx5_core_dev *dev, u8 *status) ...@@ -248,22 +248,18 @@ int mlx5_query_port_status(struct mlx5_core_dev *dev, u8 *status)
return err; return err;
} }
static int mlx5_query_port_mtu(struct mlx5_core_dev *dev, static void mlx5_query_port_mtu(struct mlx5_core_dev *dev, int *admin_mtu,
int *admin_mtu, int *max_mtu, int *oper_mtu, int *max_mtu, int *oper_mtu, u8 port)
u8 local_port)
{ {
u32 in[MLX5_ST_SZ_DW(pmtu_reg)]; u32 in[MLX5_ST_SZ_DW(pmtu_reg)];
u32 out[MLX5_ST_SZ_DW(pmtu_reg)]; u32 out[MLX5_ST_SZ_DW(pmtu_reg)];
int err;
memset(in, 0, sizeof(in)); memset(in, 0, sizeof(in));
MLX5_SET(pmtu_reg, in, local_port, local_port); MLX5_SET(pmtu_reg, in, local_port, port);
err = mlx5_core_access_reg(dev, in, sizeof(in), out, mlx5_core_access_reg(dev, in, sizeof(in), out,
sizeof(out), MLX5_REG_PMTU, 0, 0); sizeof(out), MLX5_REG_PMTU, 0, 0);
if (err)
return err;
if (max_mtu) if (max_mtu)
*max_mtu = MLX5_GET(pmtu_reg, out, max_mtu); *max_mtu = MLX5_GET(pmtu_reg, out, max_mtu);
...@@ -271,11 +267,9 @@ static int mlx5_query_port_mtu(struct mlx5_core_dev *dev, ...@@ -271,11 +267,9 @@ static int mlx5_query_port_mtu(struct mlx5_core_dev *dev,
*oper_mtu = MLX5_GET(pmtu_reg, out, oper_mtu); *oper_mtu = MLX5_GET(pmtu_reg, out, oper_mtu);
if (admin_mtu) if (admin_mtu)
*admin_mtu = MLX5_GET(pmtu_reg, out, admin_mtu); *admin_mtu = MLX5_GET(pmtu_reg, out, admin_mtu);
return 0;
} }
int mlx5_set_port_mtu(struct mlx5_core_dev *dev, int mtu) int mlx5_set_port_mtu(struct mlx5_core_dev *dev, int mtu, u8 port)
{ {
u32 in[MLX5_ST_SZ_DW(pmtu_reg)]; u32 in[MLX5_ST_SZ_DW(pmtu_reg)];
u32 out[MLX5_ST_SZ_DW(pmtu_reg)]; u32 out[MLX5_ST_SZ_DW(pmtu_reg)];
...@@ -283,24 +277,24 @@ int mlx5_set_port_mtu(struct mlx5_core_dev *dev, int mtu) ...@@ -283,24 +277,24 @@ int mlx5_set_port_mtu(struct mlx5_core_dev *dev, int mtu)
memset(in, 0, sizeof(in)); memset(in, 0, sizeof(in));
MLX5_SET(pmtu_reg, in, admin_mtu, mtu); MLX5_SET(pmtu_reg, in, admin_mtu, mtu);
MLX5_SET(pmtu_reg, in, local_port, 1); MLX5_SET(pmtu_reg, in, local_port, port);
return mlx5_core_access_reg(dev, in, sizeof(in), out, sizeof(out), return mlx5_core_access_reg(dev, in, sizeof(in), out,
MLX5_REG_PMTU, 0, 1); sizeof(out), MLX5_REG_PMTU, 0, 1);
} }
EXPORT_SYMBOL_GPL(mlx5_set_port_mtu); EXPORT_SYMBOL_GPL(mlx5_set_port_mtu);
int mlx5_query_port_max_mtu(struct mlx5_core_dev *dev, int *max_mtu, void mlx5_query_port_max_mtu(struct mlx5_core_dev *dev, int *max_mtu,
u8 local_port) u8 port)
{ {
return mlx5_query_port_mtu(dev, NULL, max_mtu, NULL, local_port); mlx5_query_port_mtu(dev, NULL, max_mtu, NULL, port);
} }
EXPORT_SYMBOL_GPL(mlx5_query_port_max_mtu); EXPORT_SYMBOL_GPL(mlx5_query_port_max_mtu);
int mlx5_query_port_oper_mtu(struct mlx5_core_dev *dev, int *oper_mtu, void mlx5_query_port_oper_mtu(struct mlx5_core_dev *dev, int *oper_mtu,
u8 local_port) u8 port)
{ {
return mlx5_query_port_mtu(dev, NULL, NULL, oper_mtu, local_port); mlx5_query_port_mtu(dev, NULL, NULL, oper_mtu, port);
} }
EXPORT_SYMBOL_GPL(mlx5_query_port_oper_mtu); EXPORT_SYMBOL_GPL(mlx5_query_port_oper_mtu);
......
...@@ -756,11 +756,11 @@ int mlx5_set_port_status(struct mlx5_core_dev *dev, ...@@ -756,11 +756,11 @@ int mlx5_set_port_status(struct mlx5_core_dev *dev,
enum mlx5_port_status status); enum mlx5_port_status status);
int mlx5_query_port_status(struct mlx5_core_dev *dev, u8 *status); int mlx5_query_port_status(struct mlx5_core_dev *dev, u8 *status);
int mlx5_set_port_mtu(struct mlx5_core_dev *dev, int mtu); int mlx5_set_port_mtu(struct mlx5_core_dev *dev, int mtu, u8 port);
int mlx5_query_port_max_mtu(struct mlx5_core_dev *dev, int *max_mtu, void mlx5_query_port_max_mtu(struct mlx5_core_dev *dev, int *max_mtu, u8 port);
u8 local_port); void mlx5_query_port_oper_mtu(struct mlx5_core_dev *dev, int *oper_mtu,
int mlx5_query_port_oper_mtu(struct mlx5_core_dev *dev, int *oper_mtu, u8 port);
u8 local_port);
int mlx5_query_port_vl_hw_cap(struct mlx5_core_dev *dev, int mlx5_query_port_vl_hw_cap(struct mlx5_core_dev *dev,
u8 *vl_hw_cap, u8 local_port); u8 *vl_hw_cap, u8 local_port);
......
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