Skip to content

Commit 7d83352

Browse files
Jiri PirkoSaeed Mahameed
authored andcommitted
net/mlx5: Store vport in struct mlx5_devlink_port and use it in port ops
Instead of using internal devlink_port->index to perform vport lookup in every devlink port op, store the vport pointer to the container struct mlx5_devlink_port and use it directly in port ops. Signed-off-by: Jiri Pirko <jiri@nvidia.com> Reviewed-by: Shay Drory <shayd@nvidia.com> Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
1 parent eb555e3 commit 7d83352

File tree

3 files changed

+29
-53
lines changed

3 files changed

+29
-53
lines changed

drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ int mlx5_esw_offloads_pf_vf_devlink_port_init(struct mlx5_eswitch *esw,
7171
&dl_port->dl_port);
7272

7373
vport->dl_port = dl_port;
74+
mlx5_devlink_port_init(dl_port, vport);
7475
return 0;
7576
}
7677

@@ -115,6 +116,7 @@ int mlx5_esw_offloads_sf_devlink_port_init(struct mlx5_eswitch *esw, struct mlx5
115116
mlx5_esw_offloads_sf_devlink_port_attrs_set(esw, &dl_port->dl_port, controller, sfnum);
116117

117118
vport->dl_port = dl_port;
119+
mlx5_devlink_port_init(dl_port, vport);
118120
return 0;
119121
}
120122

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,29 @@ enum mlx5_eswitch_vport_event {
172172
MLX5_VPORT_PROMISC_CHANGE = BIT(3),
173173
};
174174

175+
struct mlx5_vport;
176+
175177
struct mlx5_devlink_port {
176178
struct devlink_port dl_port;
179+
struct mlx5_vport *vport;
177180
};
178181

182+
static inline void mlx5_devlink_port_init(struct mlx5_devlink_port *dl_port,
183+
struct mlx5_vport *vport)
184+
{
185+
dl_port->vport = vport;
186+
}
187+
188+
static inline struct mlx5_devlink_port *mlx5_devlink_port_get(struct devlink_port *dl_port)
189+
{
190+
return container_of(dl_port, struct mlx5_devlink_port, dl_port);
191+
}
192+
193+
static inline struct mlx5_vport *mlx5_devlink_port_vport_get(struct devlink_port *dl_port)
194+
{
195+
return mlx5_devlink_port_get(dl_port)->vport;
196+
}
197+
179198
struct mlx5_vport {
180199
struct mlx5_core_dev *dev;
181200
struct hlist_head uc_list[MLX5_L2_ADDR_HASH_SIZE];

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

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4223,17 +4223,7 @@ int mlx5_devlink_port_fn_hw_addr_get(struct devlink_port *port,
42234223
struct netlink_ext_ack *extack)
42244224
{
42254225
struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
4226-
struct mlx5_vport *vport;
4227-
u16 vport_num;
4228-
4229-
4230-
vport_num = mlx5_esw_devlink_port_index_to_vport_num(port->index);
4231-
4232-
vport = mlx5_eswitch_get_vport(esw, vport_num);
4233-
if (IS_ERR(vport)) {
4234-
NL_SET_ERR_MSG_MOD(extack, "Invalid port");
4235-
return PTR_ERR(vport);
4236-
}
4226+
struct mlx5_vport *vport = mlx5_devlink_port_vport_get(port);
42374227

42384228
mutex_lock(&esw->state_lock);
42394229
ether_addr_copy(hw_addr, vport->info.mac);
@@ -4247,26 +4237,16 @@ int mlx5_devlink_port_fn_hw_addr_set(struct devlink_port *port,
42474237
struct netlink_ext_ack *extack)
42484238
{
42494239
struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
4250-
u16 vport_num;
4240+
struct mlx5_vport *vport = mlx5_devlink_port_vport_get(port);
42514241

4252-
vport_num = mlx5_esw_devlink_port_index_to_vport_num(port->index);
4253-
return mlx5_eswitch_set_vport_mac(esw, vport_num, hw_addr);
4254-
}
4255-
4256-
static struct mlx5_vport *
4257-
mlx5_devlink_port_fn_get_vport(struct devlink_port *port, struct mlx5_eswitch *esw)
4258-
{
4259-
u16 vport_num;
4260-
4261-
vport_num = mlx5_esw_devlink_port_index_to_vport_num(port->index);
4262-
return mlx5_eswitch_get_vport(esw, vport_num);
4242+
return mlx5_eswitch_set_vport_mac(esw, vport->vport, hw_addr);
42634243
}
42644244

42654245
int mlx5_devlink_port_fn_migratable_get(struct devlink_port *port, bool *is_enabled,
42664246
struct netlink_ext_ack *extack)
42674247
{
42684248
struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
4269-
struct mlx5_vport *vport;
4249+
struct mlx5_vport *vport = mlx5_devlink_port_vport_get(port);
42704250

42714251
if (!MLX5_CAP_GEN(esw->dev, migration)) {
42724252
NL_SET_ERR_MSG_MOD(extack, "Device doesn't support migration");
@@ -4278,12 +4258,6 @@ int mlx5_devlink_port_fn_migratable_get(struct devlink_port *port, bool *is_enab
42784258
return -EOPNOTSUPP;
42794259
}
42804260

4281-
vport = mlx5_devlink_port_fn_get_vport(port, esw);
4282-
if (IS_ERR(vport)) {
4283-
NL_SET_ERR_MSG_MOD(extack, "Invalid port");
4284-
return PTR_ERR(vport);
4285-
}
4286-
42874261
mutex_lock(&esw->state_lock);
42884262
*is_enabled = vport->info.mig_enabled;
42894263
mutex_unlock(&esw->state_lock);
@@ -4294,8 +4268,8 @@ int mlx5_devlink_port_fn_migratable_set(struct devlink_port *port, bool enable,
42944268
struct netlink_ext_ack *extack)
42954269
{
42964270
struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
4271+
struct mlx5_vport *vport = mlx5_devlink_port_vport_get(port);
42974272
int query_out_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out);
4298-
struct mlx5_vport *vport;
42994273
void *query_ctx;
43004274
void *hca_caps;
43014275
int err;
@@ -4310,12 +4284,6 @@ int mlx5_devlink_port_fn_migratable_set(struct devlink_port *port, bool enable,
43104284
return -EOPNOTSUPP;
43114285
}
43124286

4313-
vport = mlx5_devlink_port_fn_get_vport(port, esw);
4314-
if (IS_ERR(vport)) {
4315-
NL_SET_ERR_MSG_MOD(extack, "Invalid port");
4316-
return PTR_ERR(vport);
4317-
}
4318-
43194287
mutex_lock(&esw->state_lock);
43204288

43214289
if (vport->info.mig_enabled == enable) {
@@ -4359,19 +4327,13 @@ int mlx5_devlink_port_fn_roce_get(struct devlink_port *port, bool *is_enabled,
43594327
struct netlink_ext_ack *extack)
43604328
{
43614329
struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
4362-
struct mlx5_vport *vport;
4330+
struct mlx5_vport *vport = mlx5_devlink_port_vport_get(port);
43634331

43644332
if (!MLX5_CAP_GEN(esw->dev, vhca_resource_manager)) {
43654333
NL_SET_ERR_MSG_MOD(extack, "Device doesn't support VHCA management");
43664334
return -EOPNOTSUPP;
43674335
}
43684336

4369-
vport = mlx5_devlink_port_fn_get_vport(port, esw);
4370-
if (IS_ERR(vport)) {
4371-
NL_SET_ERR_MSG_MOD(extack, "Invalid port");
4372-
return PTR_ERR(vport);
4373-
}
4374-
43754337
mutex_lock(&esw->state_lock);
43764338
*is_enabled = vport->info.roce_enabled;
43774339
mutex_unlock(&esw->state_lock);
@@ -4382,25 +4344,18 @@ int mlx5_devlink_port_fn_roce_set(struct devlink_port *port, bool enable,
43824344
struct netlink_ext_ack *extack)
43834345
{
43844346
struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
4347+
struct mlx5_vport *vport = mlx5_devlink_port_vport_get(port);
43854348
int query_out_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out);
4386-
struct mlx5_vport *vport;
4349+
u16 vport_num = vport->vport;
43874350
void *query_ctx;
43884351
void *hca_caps;
4389-
u16 vport_num;
43904352
int err;
43914353

43924354
if (!MLX5_CAP_GEN(esw->dev, vhca_resource_manager)) {
43934355
NL_SET_ERR_MSG_MOD(extack, "Device doesn't support VHCA management");
43944356
return -EOPNOTSUPP;
43954357
}
43964358

4397-
vport = mlx5_devlink_port_fn_get_vport(port, esw);
4398-
if (IS_ERR(vport)) {
4399-
NL_SET_ERR_MSG_MOD(extack, "Invalid port");
4400-
return PTR_ERR(vport);
4401-
}
4402-
vport_num = vport->vport;
4403-
44044359
mutex_lock(&esw->state_lock);
44054360

44064361
if (vport->info.roce_enabled == enable) {

0 commit comments

Comments
 (0)