Skip to content

Commit 472a1e4

Browse files
Tariq ToukanSaeed Mahameed
authored andcommitted
net/mlx5e: Save MTU in channels params
Knowing the MTU is required for RQ creation flow. By our design, channels creation flow is totally isolated from priv/netdev, and can be completed with access to channels params and mdev. Adding the MTU to the channels params helps preserving that. In addition, we save it in RQ to make its access faster in datapath checks. Signed-off-by: Tariq Toukan <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 5337889 commit 472a1e4

File tree

5 files changed

+52
-45
lines changed

5 files changed

+52
-45
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757

5858
#define MLX5E_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)
5959

60-
#define MLX5E_HW2SW_MTU(priv, hwmtu) ((hwmtu) - ((priv)->hard_mtu))
61-
#define MLX5E_SW2HW_MTU(priv, swmtu) ((swmtu) + ((priv)->hard_mtu))
60+
#define MLX5E_HW2SW_MTU(params, hwmtu) ((hwmtu) - ((params)->hard_mtu))
61+
#define MLX5E_SW2HW_MTU(params, swmtu) ((swmtu) + ((params)->hard_mtu))
6262

6363
#define MLX5E_MAX_DSCP 64
6464
#define MLX5E_MAX_NUM_TC 8
@@ -251,6 +251,8 @@ struct mlx5e_params {
251251
u32 lro_timeout;
252252
u32 pflags;
253253
struct bpf_prog *xdp_prog;
254+
unsigned int sw_mtu;
255+
int hard_mtu;
254256
};
255257

256258
#ifdef CONFIG_MLX5_CORE_EN_DCB
@@ -534,6 +536,7 @@ struct mlx5e_rq {
534536

535537
/* XDP */
536538
struct bpf_prog *xdp_prog;
539+
unsigned int hw_mtu;
537540
struct mlx5e_xdpsq xdpsq;
538541

539542
/* control */
@@ -767,7 +770,6 @@ struct mlx5e_priv {
767770
struct mlx5e_tir inner_indir_tir[MLX5E_NUM_INDIR_TIRS];
768771
struct mlx5e_tir direct_tir[MLX5E_MAX_NUM_CHANNELS];
769772
u32 tx_rates[MLX5E_MAX_NUM_SQS];
770-
int hard_mtu;
771773

772774
struct mlx5e_flow_steering fs;
773775
struct mlx5e_vxlan_db vxlan;
@@ -1111,7 +1113,7 @@ void mlx5e_detach_netdev(struct mlx5e_priv *priv);
11111113
void mlx5e_destroy_netdev(struct mlx5e_priv *priv);
11121114
void mlx5e_build_nic_params(struct mlx5_core_dev *mdev,
11131115
struct mlx5e_params *params,
1114-
u16 max_channels);
1116+
u16 max_channels, u16 mtu);
11151117
u8 mlx5e_params_calculate_tx_min_inline(struct mlx5_core_dev *mdev);
11161118
void mlx5e_rx_dim_work(struct work_struct *work);
11171119
#endif /* __MLX5_EN_H__ */

drivers/net/ethernet/mellanox/mlx5/core/en_main.c

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ static int mlx5e_alloc_rq(struct mlx5e_channel *c,
419419
rq->channel = c;
420420
rq->ix = c->ix;
421421
rq->mdev = mdev;
422+
rq->hw_mtu = MLX5E_SW2HW_MTU(params, params->sw_mtu);
422423

423424
rq->xdp_prog = params->xdp_prog ? bpf_prog_inc(params->xdp_prog) : NULL;
424425
if (IS_ERR(rq->xdp_prog)) {
@@ -494,7 +495,7 @@ static int mlx5e_alloc_rq(struct mlx5e_channel *c,
494495

495496
byte_count = params->lro_en ?
496497
params->lro_wqe_sz :
497-
MLX5E_SW2HW_MTU(c->priv, c->netdev->mtu);
498+
MLX5E_SW2HW_MTU(params, params->sw_mtu);
498499
#ifdef CONFIG_MLX5_EN_IPSEC
499500
if (MLX5_IPSEC_DEV(mdev))
500501
byte_count += MLX5E_METADATA_ETHER_LEN;
@@ -2498,10 +2499,10 @@ static void mlx5e_build_inner_indir_tir_ctx(struct mlx5e_priv *priv,
24982499
mlx5e_build_indir_tir_ctx_hash(&priv->channels.params, tt, tirc, true);
24992500
}
25002501

2501-
static int mlx5e_set_mtu(struct mlx5e_priv *priv, u16 mtu)
2502+
static int mlx5e_set_mtu(struct mlx5_core_dev *mdev,
2503+
struct mlx5e_params *params, u16 mtu)
25022504
{
2503-
struct mlx5_core_dev *mdev = priv->mdev;
2504-
u16 hw_mtu = MLX5E_SW2HW_MTU(priv, mtu);
2505+
u16 hw_mtu = MLX5E_SW2HW_MTU(params, mtu);
25052506
int err;
25062507

25072508
err = mlx5_set_port_mtu(mdev, hw_mtu, 1);
@@ -2513,35 +2514,37 @@ static int mlx5e_set_mtu(struct mlx5e_priv *priv, u16 mtu)
25132514
return 0;
25142515
}
25152516

2516-
static void mlx5e_query_mtu(struct mlx5e_priv *priv, u16 *mtu)
2517+
static void mlx5e_query_mtu(struct mlx5_core_dev *mdev,
2518+
struct mlx5e_params *params, u16 *mtu)
25172519
{
2518-
struct mlx5_core_dev *mdev = priv->mdev;
25192520
u16 hw_mtu = 0;
25202521
int err;
25212522

25222523
err = mlx5_query_nic_vport_mtu(mdev, &hw_mtu);
25232524
if (err || !hw_mtu) /* fallback to port oper mtu */
25242525
mlx5_query_port_oper_mtu(mdev, &hw_mtu, 1);
25252526

2526-
*mtu = MLX5E_HW2SW_MTU(priv, hw_mtu);
2527+
*mtu = MLX5E_HW2SW_MTU(params, hw_mtu);
25272528
}
25282529

25292530
static int mlx5e_set_dev_port_mtu(struct mlx5e_priv *priv)
25302531
{
2532+
struct mlx5e_params *params = &priv->channels.params;
25312533
struct net_device *netdev = priv->netdev;
2534+
struct mlx5_core_dev *mdev = priv->mdev;
25322535
u16 mtu;
25332536
int err;
25342537

2535-
err = mlx5e_set_mtu(priv, netdev->mtu);
2538+
err = mlx5e_set_mtu(mdev, params, params->sw_mtu);
25362539
if (err)
25372540
return err;
25382541

2539-
mlx5e_query_mtu(priv, &mtu);
2540-
if (mtu != netdev->mtu)
2542+
mlx5e_query_mtu(mdev, params, &mtu);
2543+
if (mtu != params->sw_mtu)
25412544
netdev_warn(netdev, "%s: VPort MTU %d is different than netdev mtu %d\n",
2542-
__func__, mtu, netdev->mtu);
2545+
__func__, mtu, params->sw_mtu);
25432546

2544-
netdev->mtu = mtu;
2547+
params->sw_mtu = mtu;
25452548
return 0;
25462549
}
25472550

@@ -3411,34 +3414,33 @@ static int mlx5e_change_mtu(struct net_device *netdev, int new_mtu)
34113414
{
34123415
struct mlx5e_priv *priv = netdev_priv(netdev);
34133416
struct mlx5e_channels new_channels = {};
3414-
int curr_mtu;
3417+
struct mlx5e_params *params;
34153418
int err = 0;
34163419
bool reset;
34173420

34183421
mutex_lock(&priv->state_lock);
34193422

3420-
reset = !priv->channels.params.lro_en &&
3421-
(priv->channels.params.rq_wq_type !=
3422-
MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ);
3423+
params = &priv->channels.params;
3424+
reset = !params->lro_en &&
3425+
(params->rq_wq_type != MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ);
34233426

34243427
reset = reset && test_bit(MLX5E_STATE_OPENED, &priv->state);
34253428

3426-
curr_mtu = netdev->mtu;
3427-
netdev->mtu = new_mtu;
3428-
34293429
if (!reset) {
3430+
params->sw_mtu = new_mtu;
34303431
mlx5e_set_dev_port_mtu(priv);
3432+
netdev->mtu = params->sw_mtu;
34313433
goto out;
34323434
}
34333435

3434-
new_channels.params = priv->channels.params;
3436+
new_channels.params = *params;
3437+
new_channels.params.sw_mtu = new_mtu;
34353438
err = mlx5e_open_channels(priv, &new_channels);
3436-
if (err) {
3437-
netdev->mtu = curr_mtu;
3439+
if (err)
34383440
goto out;
3439-
}
34403441

34413442
mlx5e_switch_priv_channels(priv, &new_channels, mlx5e_set_dev_port_mtu);
3443+
netdev->mtu = new_channels.params.sw_mtu;
34423444

34433445
out:
34443446
mutex_unlock(&priv->state_lock);
@@ -4111,10 +4113,12 @@ static u32 mlx5e_choose_lro_timeout(struct mlx5_core_dev *mdev, u32 wanted_timeo
41114113

41124114
void mlx5e_build_nic_params(struct mlx5_core_dev *mdev,
41134115
struct mlx5e_params *params,
4114-
u16 max_channels)
4116+
u16 max_channels, u16 mtu)
41154117
{
41164118
u8 cq_period_mode = 0;
41174119

4120+
params->sw_mtu = mtu;
4121+
params->hard_mtu = MLX5E_ETH_HARD_MTU;
41184122
params->num_channels = max_channels;
41194123
params->num_tc = 1;
41204124

@@ -4175,9 +4179,9 @@ static void mlx5e_build_nic_netdev_priv(struct mlx5_core_dev *mdev,
41754179
priv->profile = profile;
41764180
priv->ppriv = ppriv;
41774181
priv->msglevel = MLX5E_MSG_LEVEL;
4178-
priv->hard_mtu = MLX5E_ETH_HARD_MTU;
41794182

4180-
mlx5e_build_nic_params(mdev, &priv->channels.params, profile->max_nch(mdev));
4183+
mlx5e_build_nic_params(mdev, &priv->channels.params,
4184+
profile->max_nch(mdev), netdev->mtu);
41814185

41824186
mutex_init(&priv->state_lock);
41834187

@@ -4454,7 +4458,7 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)
44544458
/* MTU range: 68 - hw-specific max */
44554459
netdev->min_mtu = ETH_MIN_MTU;
44564460
mlx5_query_port_max_mtu(priv->mdev, &max_mtu, 1);
4457-
netdev->max_mtu = MLX5E_HW2SW_MTU(priv, max_mtu);
4461+
netdev->max_mtu = MLX5E_HW2SW_MTU(&priv->channels.params, max_mtu);
44584462
mlx5e_set_dev_port_mtu(priv);
44594463

44604464
mlx5_lag_add(mdev, netdev);

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ static void mlx5e_build_rep_params(struct mlx5_core_dev *mdev,
877877
MLX5_CQ_PERIOD_MODE_START_FROM_CQE :
878878
MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
879879

880+
params->hard_mtu = MLX5E_ETH_HARD_MTU;
880881
params->log_sq_size = MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE;
881882
params->rq_wq_type = MLX5_WQ_TYPE_LINKED_LIST;
882883
params->log_rq_size = MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE;
@@ -926,8 +927,6 @@ static void mlx5e_init_rep(struct mlx5_core_dev *mdev,
926927

927928
priv->channels.params.num_channels = profile->max_nch(mdev);
928929

929-
priv->hard_mtu = MLX5E_ETH_HARD_MTU;
930-
931930
mlx5e_build_rep_params(mdev, &priv->channels.params);
932931
mlx5e_build_rep_netdev(netdev);
933932

drivers/net/ethernet/mellanox/mlx5/core/en_rx.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,7 @@ static inline bool mlx5e_xmit_xdp_frame(struct mlx5e_rq *rq,
766766

767767
prefetchw(wqe);
768768

769-
if (unlikely(dma_len < MLX5E_XDP_MIN_INLINE ||
770-
MLX5E_SW2HW_MTU(rq->channel->priv, rq->netdev->mtu) < dma_len)) {
769+
if (unlikely(dma_len < MLX5E_XDP_MIN_INLINE || rq->hw_mtu < dma_len)) {
771770
rq->stats.xdp_drop++;
772771
return false;
773772
}

drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static void mlx5i_build_nic_params(struct mlx5_core_dev *mdev,
6666
MLX5I_PARAMS_DEFAULT_LOG_RQ_SIZE;
6767

6868
params->lro_en = false;
69+
params->hard_mtu = MLX5_IB_GRH_BYTES + MLX5_IPOIB_HARD_LEN;
6970
}
7071

7172
/* Called directly after IPoIB netdevice was created to initialize SW structs */
@@ -81,10 +82,10 @@ void mlx5i_init(struct mlx5_core_dev *mdev,
8182
priv->netdev = netdev;
8283
priv->profile = profile;
8384
priv->ppriv = ppriv;
84-
priv->hard_mtu = MLX5_IB_GRH_BYTES + MLX5_IPOIB_HARD_LEN;
8585
mutex_init(&priv->state_lock);
8686

87-
mlx5e_build_nic_params(mdev, &priv->channels.params, profile->max_nch(mdev));
87+
mlx5e_build_nic_params(mdev, &priv->channels.params,
88+
profile->max_nch(mdev), netdev->mtu);
8889
mlx5i_build_nic_params(mdev, &priv->channels.params);
8990

9091
mlx5e_timestamp_init(priv);
@@ -368,25 +369,27 @@ static int mlx5i_change_mtu(struct net_device *netdev, int new_mtu)
368369
{
369370
struct mlx5e_priv *priv = mlx5i_epriv(netdev);
370371
struct mlx5e_channels new_channels = {};
371-
int curr_mtu;
372+
struct mlx5e_params *params;
372373
int err = 0;
373374

374375
mutex_lock(&priv->state_lock);
375376

376-
curr_mtu = netdev->mtu;
377-
netdev->mtu = new_mtu;
377+
params = &priv->channels.params;
378378

379-
if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
379+
if (!test_bit(MLX5E_STATE_OPENED, &priv->state)) {
380+
params->sw_mtu = new_mtu;
381+
netdev->mtu = params->sw_mtu;
380382
goto out;
383+
}
381384

382-
new_channels.params = priv->channels.params;
385+
new_channels.params = *params;
386+
new_channels.params.sw_mtu = new_mtu;
383387
err = mlx5e_open_channels(priv, &new_channels);
384-
if (err) {
385-
netdev->mtu = curr_mtu;
388+
if (err)
386389
goto out;
387-
}
388390

389391
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
392+
netdev->mtu = new_channels.params.sw_mtu;
390393

391394
out:
392395
mutex_unlock(&priv->state_lock);

0 commit comments

Comments
 (0)