Skip to content

Commit 3ef14e4

Browse files
author
Saeed Mahameed
committed
net/mlx5e: Separate between netdev objects and mlx5e profiles initialization
1) Initialize netdevice features and structures on netdevice allocation and outside of the mlx5e profile. 2) As now mlx5e netdevice private params will be setup on profile init only after netdevice features are already set, we add a call to netde_update_features() to resolve any conflict. This is nice since we reuse the fix_features ndo code if a profile wants different default features, instead of duplicating features conflict resolution code on profile initialization. 3) With this we achieve total separation between mlx5e profiles and netdevices, and will allow replacing mlx5e profiles on the fly to reuse the same netdevice for multiple profiles. e.g. for uplink representor profile as shown in the following patch 4) Profile callbacks are not allowed to touch netdev->features directly anymore, since in downstream patch we will detach/attach netdev dynamically to profile, hence we move the code dealing with netdev->features from profile->init() to fix_features ndo, and we will call netdev_update_features() on mlx5e_attach_netdev(profile, netdev); Signed-off-by: Saeed Mahameed <[email protected]> Reviewed-by: Roi Dayan <[email protected]>
1 parent 9ae4bdc commit 3ef14e4

File tree

6 files changed

+121
-114
lines changed

6 files changed

+121
-114
lines changed

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,7 @@ extern const struct mlx5e_rx_handlers mlx5e_rx_handlers_nic;
895895

896896
struct mlx5e_profile {
897897
int (*init)(struct mlx5_core_dev *mdev,
898-
struct net_device *netdev,
899-
const struct mlx5e_profile *profile, void *ppriv);
898+
struct net_device *netdev);
900899
void (*cleanup)(struct mlx5e_priv *priv);
901900
int (*init_rx)(struct mlx5e_priv *priv);
902901
void (*cleanup_rx)(struct mlx5e_priv *priv);
@@ -1155,24 +1154,22 @@ int mlx5e_ethtool_set_pauseparam(struct mlx5e_priv *priv,
11551154
struct ethtool_pauseparam *pauseparam);
11561155

11571156
/* mlx5e generic netdev management API */
1157+
static inline unsigned int mlx5e_calc_max_nch(struct mlx5e_priv *priv)
1158+
{
1159+
return priv->netdev->num_rx_queues / max_t(u8, priv->profile->rq_groups, 1);
1160+
}
1161+
11581162
int mlx5e_netdev_init(struct net_device *netdev,
11591163
struct mlx5e_priv *priv,
1160-
struct mlx5_core_dev *mdev,
1161-
const struct mlx5e_profile *profile,
1162-
void *ppriv);
1164+
struct mlx5_core_dev *mdev);
11631165
void mlx5e_netdev_cleanup(struct net_device *netdev, struct mlx5e_priv *priv);
1164-
struct net_device*
1165-
mlx5e_create_netdev(struct mlx5_core_dev *mdev, const struct mlx5e_profile *profile,
1166-
int nch, void *ppriv);
1166+
struct net_device *
1167+
mlx5e_create_netdev(struct mlx5_core_dev *mdev, unsigned int txqs, unsigned int rxqs);
11671168
int mlx5e_attach_netdev(struct mlx5e_priv *priv);
11681169
void mlx5e_detach_netdev(struct mlx5e_priv *priv);
11691170
void mlx5e_destroy_netdev(struct mlx5e_priv *priv);
11701171
void mlx5e_set_netdev_mtu_boundaries(struct mlx5e_priv *priv);
1171-
void mlx5e_build_nic_params(struct mlx5e_priv *priv,
1172-
struct mlx5e_xsk *xsk,
1173-
struct mlx5e_rss_params *rss_params,
1174-
struct mlx5e_params *params,
1175-
u16 mtu);
1172+
void mlx5e_build_nic_params(struct mlx5e_priv *priv, struct mlx5e_xsk *xsk, u16 mtu);
11761173
void mlx5e_build_rq_params(struct mlx5_core_dev *mdev,
11771174
struct mlx5e_params *params);
11781175
void mlx5e_build_rss_params(struct mlx5e_rss_params *rss_params,

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

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4093,6 +4093,7 @@ static netdev_features_t mlx5e_fix_features(struct net_device *netdev,
40934093
if (!params->vlan_strip_disable)
40944094
netdev_warn(netdev, "Dropping C-tag vlan stripping offload due to S-tag vlan\n");
40954095
}
4096+
40964097
if (!MLX5E_GET_PFLAG(params, MLX5E_PFLAG_RX_STRIDING_RQ)) {
40974098
if (features & NETIF_F_LRO) {
40984099
netdev_warn(netdev, "Disabling LRO, not supported in legacy RQ\n");
@@ -4928,15 +4929,15 @@ void mlx5e_build_rss_params(struct mlx5e_rss_params *rss_params,
49284929
tirc_default_config[tt].rx_hash_fields;
49294930
}
49304931

4931-
void mlx5e_build_nic_params(struct mlx5e_priv *priv,
4932-
struct mlx5e_xsk *xsk,
4933-
struct mlx5e_rss_params *rss_params,
4934-
struct mlx5e_params *params,
4935-
u16 mtu)
4932+
void mlx5e_build_nic_params(struct mlx5e_priv *priv, struct mlx5e_xsk *xsk, u16 mtu)
49364933
{
4934+
struct mlx5e_rss_params *rss_params = &priv->rss_params;
4935+
struct mlx5e_params *params = &priv->channels.params;
49374936
struct mlx5_core_dev *mdev = priv->mdev;
49384937
u8 rx_cq_period_mode;
49394938

4939+
priv->max_nch = mlx5e_calc_max_nch(priv);
4940+
49404941
params->sw_mtu = mtu;
49414942
params->hard_mtu = MLX5E_ETH_HARD_MTU;
49424943
params->num_channels = min_t(unsigned int, MLX5E_MAX_NUM_CHANNELS / 2,
@@ -4994,6 +4995,11 @@ void mlx5e_build_nic_params(struct mlx5e_priv *priv,
49944995

49954996
/* AF_XDP */
49964997
params->xsk = xsk;
4998+
4999+
/* Do not update netdev->features directly in here
5000+
* on mlx5e_attach_netdev() we will call mlx5e_update_features()
5001+
* To update netdev->features please modify mlx5e_fix_features()
5002+
*/
49975003
}
49985004

49995005
static void mlx5e_set_netdev_dev_addr(struct net_device *netdev)
@@ -5146,18 +5152,12 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev)
51465152
netdev->hw_features |= NETIF_F_RXFCS;
51475153

51485154
netdev->features = netdev->hw_features;
5149-
if (!priv->channels.params.lro_en)
5150-
netdev->features &= ~NETIF_F_LRO;
51515155

5156+
/* Defaults */
51525157
if (fcs_enabled)
51535158
netdev->features &= ~NETIF_F_RXALL;
5154-
5155-
if (!priv->channels.params.scatter_fcs_en)
5156-
netdev->features &= ~NETIF_F_RXFCS;
5157-
5158-
/* prefere CQE compression over rxhash */
5159-
if (MLX5E_GET_PFLAG(&priv->channels.params, MLX5E_PFLAG_RX_CQE_COMPRESS))
5160-
netdev->features &= ~NETIF_F_RXHASH;
5159+
netdev->features &= ~NETIF_F_LRO;
5160+
netdev->features &= ~NETIF_F_RXFCS;
51615161

51625162
#define FT_CAP(f) MLX5_CAP_FLOWTABLE(mdev, flow_table_properties_nic_receive.f)
51635163
if (FT_CAP(flow_modify_en) &&
@@ -5223,33 +5223,27 @@ void mlx5e_destroy_q_counters(struct mlx5e_priv *priv)
52235223
}
52245224

52255225
static int mlx5e_nic_init(struct mlx5_core_dev *mdev,
5226-
struct net_device *netdev,
5227-
const struct mlx5e_profile *profile,
5228-
void *ppriv)
5226+
struct net_device *netdev)
52295227
{
52305228
struct mlx5e_priv *priv = netdev_priv(netdev);
5231-
struct mlx5e_rss_params *rss = &priv->rss_params;
52325229
int err;
52335230

5234-
err = mlx5e_netdev_init(netdev, priv, mdev, profile, ppriv);
5235-
if (err)
5236-
return err;
5237-
5238-
mlx5e_build_nic_params(priv, &priv->xsk, rss, &priv->channels.params,
5239-
netdev->mtu);
5231+
mlx5e_build_nic_params(priv, &priv->xsk, netdev->mtu);
52405232

52415233
mlx5e_timestamp_init(priv);
52425234

52435235
err = mlx5e_ipsec_init(priv);
52445236
if (err)
52455237
mlx5_core_err(mdev, "IPSec initialization failed, %d\n", err);
5238+
52465239
err = mlx5e_tls_init(priv);
52475240
if (err)
52485241
mlx5_core_err(mdev, "TLS initialization failed, %d\n", err);
5249-
mlx5e_build_nic_netdev(netdev);
5242+
52505243
err = mlx5e_devlink_port_register(priv);
52515244
if (err)
52525245
mlx5_core_err(mdev, "mlx5e_devlink_port_register failed, %d\n", err);
5246+
52535247
mlx5e_health_create_reporters(priv);
52545248

52555249
return 0;
@@ -5261,7 +5255,6 @@ static void mlx5e_nic_cleanup(struct mlx5e_priv *priv)
52615255
mlx5e_devlink_port_unregister(priv);
52625256
mlx5e_tls_cleanup(priv);
52635257
mlx5e_ipsec_cleanup(priv);
5264-
mlx5e_netdev_cleanup(priv->netdev, priv);
52655258
}
52665259

52675260
static int mlx5e_init_nic_rx(struct mlx5e_priv *priv)
@@ -5464,21 +5457,14 @@ static const struct mlx5e_profile mlx5e_nic_profile = {
54645457
};
54655458

54665459
/* mlx5e generic netdev management API (move to en_common.c) */
5467-
5468-
/* mlx5e_netdev_init/cleanup must be called from profile->init/cleanup callbacks */
54695460
int mlx5e_netdev_init(struct net_device *netdev,
54705461
struct mlx5e_priv *priv,
5471-
struct mlx5_core_dev *mdev,
5472-
const struct mlx5e_profile *profile,
5473-
void *ppriv)
5462+
struct mlx5_core_dev *mdev)
54745463
{
54755464
/* priv init */
54765465
priv->mdev = mdev;
54775466
priv->netdev = netdev;
5478-
priv->profile = profile;
5479-
priv->ppriv = ppriv;
54805467
priv->msglevel = MLX5E_MSG_LEVEL;
5481-
priv->max_nch = netdev->num_rx_queues / max_t(u8, profile->rq_groups, 1);
54825468
priv->max_opened_tc = 1;
54835469

54845470
if (!alloc_cpumask_var(&priv->scratchpad.cpumask, GFP_KERNEL))
@@ -5518,35 +5504,24 @@ void mlx5e_netdev_cleanup(struct net_device *netdev, struct mlx5e_priv *priv)
55185504
kvfree(priv->htb.qos_sq_stats);
55195505
}
55205506

5521-
struct net_device *mlx5e_create_netdev(struct mlx5_core_dev *mdev,
5522-
const struct mlx5e_profile *profile,
5523-
int nch,
5524-
void *ppriv)
5507+
struct net_device *
5508+
mlx5e_create_netdev(struct mlx5_core_dev *mdev, unsigned int txqs, unsigned int rxqs)
55255509
{
55265510
struct net_device *netdev;
5527-
unsigned int ptp_txqs = 0;
5528-
int qos_sqs = 0;
55295511
int err;
55305512

5531-
if (MLX5_CAP_GEN(mdev, ts_cqe_to_dest_cqn))
5532-
ptp_txqs = profile->max_tc;
5533-
5534-
if (mlx5_qos_is_supported(mdev))
5535-
qos_sqs = mlx5e_qos_max_leaf_nodes(mdev);
5536-
5537-
netdev = alloc_etherdev_mqs(sizeof(struct mlx5e_priv),
5538-
nch * profile->max_tc + ptp_txqs + qos_sqs,
5539-
nch * profile->rq_groups);
5513+
netdev = alloc_etherdev_mqs(sizeof(struct mlx5e_priv), txqs, rxqs);
55405514
if (!netdev) {
55415515
mlx5_core_err(mdev, "alloc_etherdev_mqs() failed\n");
55425516
return NULL;
55435517
}
55445518

5545-
err = profile->init(mdev, netdev, profile, ppriv);
5519+
err = mlx5e_netdev_init(netdev, netdev_priv(netdev), mdev);
55465520
if (err) {
5547-
mlx5_core_err(mdev, "failed to init mlx5e profile %d\n", err);
5521+
mlx5_core_err(mdev, "mlx5e_netdev_init failed, err=%d\n", err);
55485522
goto err_free_netdev;
55495523
}
5524+
dev_net_set(netdev, mlx5_core_net(mdev));
55505525

55515526
return netdev;
55525527

@@ -5556,14 +5531,23 @@ struct net_device *mlx5e_create_netdev(struct mlx5_core_dev *mdev,
55565531
return NULL;
55575532
}
55585533

5534+
static void mlx5e_update_features(struct net_device *netdev)
5535+
{
5536+
if (netdev->reg_state != NETREG_REGISTERED)
5537+
return; /* features will be updated on netdev registration */
5538+
5539+
rtnl_lock();
5540+
netdev_update_features(netdev);
5541+
rtnl_unlock();
5542+
}
5543+
55595544
int mlx5e_attach_netdev(struct mlx5e_priv *priv)
55605545
{
55615546
const bool take_rtnl = priv->netdev->reg_state == NETREG_REGISTERED;
5562-
const struct mlx5e_profile *profile;
5547+
const struct mlx5e_profile *profile = priv->profile;
55635548
int max_nch;
55645549
int err;
55655550

5566-
profile = priv->profile;
55675551
clear_bit(MLX5E_STATE_DESTROYING, &priv->state);
55685552

55695553
/* max number of channels may have changed */
@@ -5603,6 +5587,8 @@ int mlx5e_attach_netdev(struct mlx5e_priv *priv)
56035587
if (profile->enable)
56045588
profile->enable(priv);
56055589

5590+
mlx5e_update_features(priv->netdev);
5591+
56065592
return 0;
56075593

56085594
err_cleanup_tx:
@@ -5631,11 +5617,9 @@ void mlx5e_detach_netdev(struct mlx5e_priv *priv)
56315617

56325618
void mlx5e_destroy_netdev(struct mlx5e_priv *priv)
56335619
{
5634-
const struct mlx5e_profile *profile = priv->profile;
56355620
struct net_device *netdev = priv->netdev;
56365621

5637-
if (profile->cleanup)
5638-
profile->cleanup(priv);
5622+
mlx5e_netdev_cleanup(netdev, priv);
56395623
free_netdev(netdev);
56405624
}
56415625

@@ -5681,28 +5665,48 @@ static int mlx5e_probe(struct auxiliary_device *adev,
56815665
const struct auxiliary_device_id *id)
56825666
{
56835667
struct mlx5_adev *edev = container_of(adev, struct mlx5_adev, adev);
5668+
const struct mlx5e_profile *profile = &mlx5e_nic_profile;
56845669
struct mlx5_core_dev *mdev = edev->mdev;
56855670
struct net_device *netdev;
56865671
pm_message_t state = {};
5687-
void *priv;
5672+
unsigned int txqs, rxqs, ptp_txqs = 0;
5673+
struct mlx5e_priv *priv;
5674+
int qos_sqs = 0;
56885675
int err;
56895676
int nch;
56905677

5678+
if (MLX5_CAP_GEN(mdev, ts_cqe_to_dest_cqn))
5679+
ptp_txqs = profile->max_tc;
5680+
5681+
if (mlx5_qos_is_supported(mdev))
5682+
qos_sqs = mlx5e_qos_max_leaf_nodes(mdev);
5683+
56915684
nch = mlx5e_get_max_num_channels(mdev);
5692-
netdev = mlx5e_create_netdev(mdev, &mlx5e_nic_profile, nch, NULL);
5685+
txqs = nch * profile->max_tc + ptp_txqs + qos_sqs;
5686+
rxqs = nch * profile->rq_groups;
5687+
netdev = mlx5e_create_netdev(mdev, txqs, rxqs);
56935688
if (!netdev) {
56945689
mlx5_core_err(mdev, "mlx5e_create_netdev failed\n");
56955690
return -ENOMEM;
56965691
}
56975692

5698-
dev_net_set(netdev, mlx5_core_net(mdev));
5693+
mlx5e_build_nic_netdev(netdev);
5694+
56995695
priv = netdev_priv(netdev);
57005696
dev_set_drvdata(&adev->dev, priv);
57015697

5698+
priv->profile = profile;
5699+
priv->ppriv = NULL;
5700+
err = profile->init(mdev, netdev);
5701+
if (err) {
5702+
mlx5_core_err(mdev, "mlx5e_nic_profile init failed, %d\n", err);
5703+
goto err_destroy_netdev;
5704+
}
5705+
57025706
err = mlx5e_resume(adev);
57035707
if (err) {
57045708
mlx5_core_err(mdev, "mlx5e_resume failed, %d\n", err);
5705-
goto err_destroy_netdev;
5709+
goto err_profile_cleanup;
57065710
}
57075711

57085712
err = register_netdev(netdev);
@@ -5718,6 +5722,8 @@ static int mlx5e_probe(struct auxiliary_device *adev,
57185722

57195723
err_resume:
57205724
mlx5e_suspend(adev, state);
5725+
err_profile_cleanup:
5726+
profile->cleanup(priv);
57215727
err_destroy_netdev:
57225728
mlx5e_destroy_netdev(priv);
57235729
return err;
@@ -5731,6 +5737,7 @@ static void mlx5e_remove(struct auxiliary_device *adev)
57315737
mlx5e_dcbnl_delete_app(priv);
57325738
unregister_netdev(priv->netdev);
57335739
mlx5e_suspend(adev, state);
5740+
priv->profile->cleanup(priv);
57345741
mlx5e_destroy_netdev(priv);
57355742
}
57365743

0 commit comments

Comments
 (0)