* [PATCH net-next 1/2] net/mlx5: SF, Pass pfnum through the SF hardware-table allocation path
2026-11-25 21:20 [PATCH net-next 0/2] net/mlx5: Add controller number to SF and VF phys_port_name Tariq Toukan
@ 2026-11-25 21:20 ` Tariq Toukan
2026-11-25 21:20 ` [PATCH net-next 2/2] net/mlx5: Add controller number for SF and ECVF phys_port_name Tariq Toukan
1 sibling, 0 replies; 3+ messages in thread
From: Tariq Toukan @ 2026-11-25 21:20 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Chris Mi, Gal Pressman, Kees Cook,
Leon Romanovsky, linux-rdma, Mark Bloch, Moshe Shemesh,
Or Har-Toov, Parav Pandit, Saeed Mahameed, Shay Drori,
Tariq Toukan
From: Chris Mi <cmi@nvidia.com>
Add a pfnum parameter to the SF allocation/free call chain and store
it on struct mlx5_sf as pf_num, set alongside controller in
mlx5_sf_alloc(), so free/dealloc can resolve the same hwc table that
was used at allocation time.
This is plumbing only. pfnum isn't used for hwc selection yet, and
controller/pfnum validation is unchanged. It prepares the SF hw-table
code to distinguish SFs created on the self PF from SFs created on a
satellite PF sharing the same controller number, implemented in
"net/mlx5: Add controller number for SF and ECVF phys_port_name"
later in this series.
Signed-off-by: Chris Mi <cmi@nvidia.com>
Reviewed-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Shay Drori <shayd@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../mellanox/mlx5/core/esw/devlink_port.c | 20 ++++++----
.../net/ethernet/mellanox/mlx5/core/eswitch.c | 6 ++-
.../net/ethernet/mellanox/mlx5/core/eswitch.h | 14 ++++---
.../mellanox/mlx5/core/eswitch_offloads.c | 9 +++--
.../ethernet/mellanox/mlx5/core/sf/devlink.c | 31 ++++++++++-----
.../ethernet/mellanox/mlx5/core/sf/hw_table.c | 39 +++++++++++--------
.../net/ethernet/mellanox/mlx5/core/sf/priv.h | 12 ++++--
7 files changed, 82 insertions(+), 49 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
index fdc960ea5331..8b46634203b3 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
@@ -148,16 +148,16 @@ static const struct devlink_port_ops mlx5_esw_pf_vf_dl_port_ops = {
.port_fn_max_io_eqs_set = mlx5_devlink_port_fn_max_io_eqs_set,
};
-static void mlx5_esw_offloads_sf_devlink_port_attrs_set(struct mlx5_eswitch *esw,
- struct devlink_port *dl_port,
- u32 controller, u32 sfnum)
+static void
+mlx5_esw_offloads_sf_devlink_port_attrs_set(struct mlx5_eswitch *esw,
+ struct devlink_port *dl_port,
+ u32 controller, u32 pfnum,
+ u32 sfnum)
{
struct mlx5_core_dev *dev = esw->dev;
struct netdev_phys_item_id ppid = {};
u32 hpf_ctrl;
- u16 pfnum;
- pfnum = mlx5_esw_sf_controller_to_pfnum(dev, controller);
hpf_ctrl = mlx5_esw_get_hpf_host_number(dev) + 1;
mlx5_esw_get_port_parent_id(dev, &ppid);
memcpy(dl_port->attrs.switch_id.id, &ppid.id[0], ppid.id_len);
@@ -166,11 +166,15 @@ static void mlx5_esw_offloads_sf_devlink_port_attrs_set(struct mlx5_eswitch *esw
controller == hpf_ctrl);
}
-int mlx5_esw_offloads_sf_devlink_port_init(struct mlx5_eswitch *esw, struct mlx5_vport *vport,
+int mlx5_esw_offloads_sf_devlink_port_init(struct mlx5_eswitch *esw,
+ struct mlx5_vport *vport,
struct mlx5_devlink_port *dl_port,
- u32 controller, u32 sfnum)
+ u32 controller, u32 pfnum,
+ u32 sfnum)
{
- mlx5_esw_offloads_sf_devlink_port_attrs_set(esw, &dl_port->dl_port, controller, sfnum);
+ mlx5_esw_offloads_sf_devlink_port_attrs_set(esw, &dl_port->dl_port,
+ controller, pfnum,
+ sfnum);
vport->dl_port = dl_port;
mlx5_devlink_port_init(dl_port, vport);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
index 76f808e06a88..8c2c55ba5c35 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@ -1370,7 +1370,8 @@ static void mlx5_eswitch_unload_pf_vf_vport(struct mlx5_eswitch *esw, u16 vport_
int mlx5_eswitch_load_sf_vport(struct mlx5_eswitch *esw, u16 vport_num,
enum mlx5_eswitch_vport_event enabled_events,
- struct mlx5_devlink_port *dl_port, u32 controller, u32 sfnum)
+ struct mlx5_devlink_port *dl_port,
+ u32 controller, u32 pfnum, u32 sfnum)
{
struct mlx5_vport *vport;
int err;
@@ -1379,7 +1380,8 @@ int mlx5_eswitch_load_sf_vport(struct mlx5_eswitch *esw, u16 vport_num,
if (IS_ERR(vport))
return PTR_ERR(vport);
- err = mlx5_esw_offloads_init_sf_rep(esw, vport, dl_port, controller, sfnum);
+ err = mlx5_esw_offloads_init_sf_rep(esw, vport, dl_port, controller,
+ pfnum, sfnum);
if (err)
return err;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
index 48eb6acc1e87..463855240032 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
@@ -872,9 +872,10 @@ void mlx5_esw_set_spec_source_port(struct mlx5_eswitch *esw,
int mlx5_esw_offloads_init_pf_vf_rep(struct mlx5_eswitch *esw, struct mlx5_vport *vport);
void mlx5_esw_offloads_cleanup_pf_vf_rep(struct mlx5_eswitch *esw, struct mlx5_vport *vport);
-int mlx5_esw_offloads_init_sf_rep(struct mlx5_eswitch *esw, struct mlx5_vport *vport,
+int mlx5_esw_offloads_init_sf_rep(struct mlx5_eswitch *esw,
+ struct mlx5_vport *vport,
struct mlx5_devlink_port *dl_port,
- u32 controller, u32 sfnum);
+ u32 controller, u32 pfnum, u32 sfnum);
void mlx5_esw_offloads_cleanup_sf_rep(struct mlx5_eswitch *esw, struct mlx5_vport *vport);
int mlx5_esw_offloads_load_rep(struct mlx5_eswitch *esw, struct mlx5_vport *vport);
@@ -882,7 +883,8 @@ void mlx5_esw_offloads_unload_rep(struct mlx5_eswitch *esw, struct mlx5_vport *v
int mlx5_eswitch_load_sf_vport(struct mlx5_eswitch *esw, u16 vport_num,
enum mlx5_eswitch_vport_event enabled_events,
- struct mlx5_devlink_port *dl_port, u32 controller, u32 sfnum);
+ struct mlx5_devlink_port *dl_port,
+ u32 controller, u32 pfnum, u32 sfnum);
void mlx5_eswitch_unload_sf_vport(struct mlx5_eswitch *esw, u16 vport_num);
int mlx5_eswitch_load_vf_vports(struct mlx5_eswitch *esw, u16 num_vfs,
@@ -894,9 +896,11 @@ int mlx5_esw_offloads_pf_vf_devlink_port_init(struct mlx5_eswitch *esw,
void mlx5_esw_offloads_pf_vf_devlink_port_cleanup(struct mlx5_eswitch *esw,
struct mlx5_vport *vport);
-int mlx5_esw_offloads_sf_devlink_port_init(struct mlx5_eswitch *esw, struct mlx5_vport *vport,
+int mlx5_esw_offloads_sf_devlink_port_init(struct mlx5_eswitch *esw,
+ struct mlx5_vport *vport,
struct mlx5_devlink_port *dl_port,
- u32 controller, u32 sfnum);
+ u32 controller, u32 pfnum,
+ u32 sfnum);
void mlx5_esw_offloads_sf_devlink_port_cleanup(struct mlx5_eswitch *esw, struct mlx5_vport *vport);
int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, struct mlx5_vport *vport);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index 1323114ce7f9..3f182e6286d6 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -2915,11 +2915,14 @@ void mlx5_esw_offloads_cleanup_pf_vf_rep(struct mlx5_eswitch *esw, struct mlx5_v
mlx5_esw_offloads_pf_vf_devlink_port_cleanup(esw, vport);
}
-int mlx5_esw_offloads_init_sf_rep(struct mlx5_eswitch *esw, struct mlx5_vport *vport,
+int mlx5_esw_offloads_init_sf_rep(struct mlx5_eswitch *esw,
+ struct mlx5_vport *vport,
struct mlx5_devlink_port *dl_port,
- u32 controller, u32 sfnum)
+ u32 controller, u32 pfnum, u32 sfnum)
{
- return mlx5_esw_offloads_sf_devlink_port_init(esw, vport, dl_port, controller, sfnum);
+ return mlx5_esw_offloads_sf_devlink_port_init(esw, vport, dl_port,
+ controller, pfnum,
+ sfnum);
}
void mlx5_esw_offloads_cleanup_sf_rep(struct mlx5_eswitch *esw, struct mlx5_vport *vport)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
index 4564d460416b..2002b7f376ee 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
@@ -15,6 +15,7 @@ struct mlx5_sf {
struct mlx5_devlink_port dl_port;
unsigned int port_index;
u32 controller;
+ u32 pf_num;
u16 id;
u16 hw_fn_id;
u16 hw_state;
@@ -51,7 +52,8 @@ static void mlx5_sf_function_id_erase(struct mlx5_sf_table *table, struct mlx5_s
static struct mlx5_sf *
mlx5_sf_alloc(struct mlx5_sf_table *table, struct mlx5_eswitch *esw,
- u32 controller, u32 sfnum, struct netlink_ext_ack *extack)
+ u32 controller, u32 pfnum, u32 sfnum,
+ struct netlink_ext_ack *extack)
{
unsigned int dl_port_index;
struct mlx5_sf *sf;
@@ -64,7 +66,8 @@ mlx5_sf_alloc(struct mlx5_sf_table *table, struct mlx5_eswitch *esw,
return ERR_PTR(-EINVAL);
}
- id_err = mlx5_sf_hw_table_sf_alloc(table->dev, controller, sfnum);
+ id_err = mlx5_sf_hw_table_sf_alloc(table->dev, controller, pfnum,
+ sfnum);
if (id_err < 0) {
err = id_err;
goto id_err;
@@ -76,12 +79,13 @@ mlx5_sf_alloc(struct mlx5_sf_table *table, struct mlx5_eswitch *esw,
goto alloc_err;
}
sf->id = id_err;
- hw_fn_id = mlx5_sf_sw_to_hw_id(table->dev, controller, sf->id);
+ hw_fn_id = mlx5_sf_sw_to_hw_id(table->dev, controller, pfnum, sf->id);
dl_port_index = mlx5_esw_vport_to_devlink_port_index(table->dev, hw_fn_id);
sf->port_index = dl_port_index;
sf->hw_fn_id = hw_fn_id;
sf->hw_state = MLX5_VHCA_STATE_ALLOCATED;
sf->controller = controller;
+ sf->pf_num = pfnum;
err = mlx5_sf_function_id_insert(table, sf);
if (err)
@@ -92,7 +96,7 @@ mlx5_sf_alloc(struct mlx5_sf_table *table, struct mlx5_eswitch *esw,
insert_err:
kfree(sf);
alloc_err:
- mlx5_sf_hw_table_sf_free(table->dev, controller, id_err);
+ mlx5_sf_hw_table_sf_free(table->dev, controller, pfnum, id_err);
id_err:
if (err == -EEXIST)
NL_SET_ERR_MSG_MOD(extack, "SF already exist. Choose different sfnum");
@@ -101,7 +105,8 @@ mlx5_sf_alloc(struct mlx5_sf_table *table, struct mlx5_eswitch *esw,
static void mlx5_sf_free(struct mlx5_sf_table *table, struct mlx5_sf *sf)
{
- mlx5_sf_hw_table_sf_free(table->dev, sf->controller, sf->id);
+ mlx5_sf_hw_table_sf_free(table->dev, sf->controller, sf->pf_num,
+ sf->id);
trace_mlx5_sf_free(table->dev, sf->port_index, sf->controller, sf->hw_fn_id);
kfree(sf);
}
@@ -241,13 +246,17 @@ static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
struct mlx5_sf *sf;
int err;
- sf = mlx5_sf_alloc(table, esw, new_attr->controller, new_attr->sfnum, extack);
+ sf = mlx5_sf_alloc(table, esw, new_attr->controller, new_attr->pfnum,
+ new_attr->sfnum, extack);
if (IS_ERR(sf))
return PTR_ERR(sf);
mlx5_esw_reps_block(esw);
- err = mlx5_eswitch_load_sf_vport(esw, sf->hw_fn_id, MLX5_VPORT_UC_ADDR_CHANGE,
- &sf->dl_port, new_attr->controller, new_attr->sfnum);
+ err = mlx5_eswitch_load_sf_vport(esw, sf->hw_fn_id,
+ MLX5_VPORT_UC_ADDR_CHANGE,
+ &sf->dl_port, new_attr->controller,
+ new_attr->pfnum,
+ new_attr->sfnum);
mlx5_esw_reps_unblock(esw);
if (err)
goto esw_err;
@@ -347,10 +356,12 @@ static void mlx5_sf_dealloc(struct mlx5_sf_table *table, struct mlx5_sf *sf)
* firmware gives confirmation that it is detached by the driver.
*/
mlx5_cmd_sf_disable_hca(table->dev, sf->hw_fn_id);
- mlx5_sf_hw_table_sf_deferred_free(table->dev, sf->controller, sf->id);
+ mlx5_sf_hw_table_sf_deferred_free(table->dev, sf->controller,
+ sf->pf_num, sf->id);
kfree(sf);
} else {
- mlx5_sf_hw_table_sf_deferred_free(table->dev, sf->controller, sf->id);
+ mlx5_sf_hw_table_sf_deferred_free(table->dev, sf->controller,
+ sf->pf_num, sf->id);
kfree(sf);
}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
index c36dbd7de877..d8d061683497 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
@@ -37,7 +37,7 @@ struct mlx5_sf_hw_table {
};
static struct mlx5_sf_hwc_table *
-mlx5_sf_controller_to_hwc(struct mlx5_core_dev *dev, u32 controller)
+mlx5_sf_controller_to_hwc(struct mlx5_core_dev *dev, u32 controller, u32 pfnum)
{
struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;
int i;
@@ -50,11 +50,12 @@ mlx5_sf_controller_to_hwc(struct mlx5_core_dev *dev, u32 controller)
return &table->hwc[!!controller];
}
-u16 mlx5_sf_sw_to_hw_id(struct mlx5_core_dev *dev, u32 controller, u16 sw_id)
+u16 mlx5_sf_sw_to_hw_id(struct mlx5_core_dev *dev, u32 controller, u32 pfnum,
+ u16 sw_id)
{
struct mlx5_sf_hwc_table *hwc;
- hwc = mlx5_sf_controller_to_hwc(dev, controller);
+ hwc = mlx5_sf_controller_to_hwc(dev, controller, pfnum);
return hwc->start_fn_id + sw_id;
}
@@ -79,14 +80,14 @@ mlx5_sf_table_fn_to_hwc(struct mlx5_sf_hw_table *table, u16 fn_id)
static int mlx5_sf_hw_table_id_alloc(struct mlx5_core_dev *dev,
struct mlx5_sf_hw_table *table,
- u32 controller,
+ u32 controller, u32 pfnum,
u32 usr_sfnum)
{
struct mlx5_sf_hwc_table *hwc;
int free_idx = -1;
int i;
- hwc = mlx5_sf_controller_to_hwc(dev, controller);
+ hwc = mlx5_sf_controller_to_hwc(dev, controller, pfnum);
if (!hwc->sfs)
return -ENOSPC;
@@ -110,16 +111,17 @@ static int mlx5_sf_hw_table_id_alloc(struct mlx5_core_dev *dev,
static void mlx5_sf_hw_table_id_free(struct mlx5_core_dev *dev,
struct mlx5_sf_hw_table *table,
- u32 controller, int id)
+ u32 controller, u32 pfnum, int id)
{
struct mlx5_sf_hwc_table *hwc;
- hwc = mlx5_sf_controller_to_hwc(dev, controller);
+ hwc = mlx5_sf_controller_to_hwc(dev, controller, pfnum);
hwc->sfs[id].allocated = false;
hwc->sfs[id].pending_delete = false;
}
-int mlx5_sf_hw_table_sf_alloc(struct mlx5_core_dev *dev, u32 controller, u32 usr_sfnum)
+int mlx5_sf_hw_table_sf_alloc(struct mlx5_core_dev *dev, u32 controller,
+ u32 pfnum, u32 usr_sfnum)
{
struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;
u16 hw_fn_id;
@@ -130,13 +132,14 @@ int mlx5_sf_hw_table_sf_alloc(struct mlx5_core_dev *dev, u32 controller, u32 usr
return -EOPNOTSUPP;
mutex_lock(&table->table_lock);
- sw_id = mlx5_sf_hw_table_id_alloc(dev, table, controller, usr_sfnum);
+ sw_id = mlx5_sf_hw_table_id_alloc(dev, table, controller, pfnum,
+ usr_sfnum);
if (sw_id < 0) {
err = sw_id;
goto exist_err;
}
- hw_fn_id = mlx5_sf_sw_to_hw_id(dev, controller, sw_id);
+ hw_fn_id = mlx5_sf_sw_to_hw_id(dev, controller, pfnum, sw_id);
err = mlx5_cmd_alloc_sf(dev, hw_fn_id);
if (err)
goto err;
@@ -161,21 +164,22 @@ int mlx5_sf_hw_table_sf_alloc(struct mlx5_core_dev *dev, u32 controller, u32 usr
vhca_err:
mlx5_cmd_dealloc_sf(dev, hw_fn_id);
err:
- mlx5_sf_hw_table_id_free(dev, table, controller, sw_id);
+ mlx5_sf_hw_table_id_free(dev, table, controller, pfnum, sw_id);
exist_err:
mutex_unlock(&table->table_lock);
return err;
}
-void mlx5_sf_hw_table_sf_free(struct mlx5_core_dev *dev, u32 controller, u16 id)
+void mlx5_sf_hw_table_sf_free(struct mlx5_core_dev *dev, u32 controller,
+ u32 pfnum, u16 id)
{
struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;
u16 hw_fn_id;
mutex_lock(&table->table_lock);
- hw_fn_id = mlx5_sf_sw_to_hw_id(dev, controller, id);
+ hw_fn_id = mlx5_sf_sw_to_hw_id(dev, controller, pfnum, id);
mlx5_cmd_dealloc_sf(dev, hw_fn_id);
- mlx5_sf_hw_table_id_free(dev, table, controller, id);
+ mlx5_sf_hw_table_id_free(dev, table, controller, pfnum, id);
mutex_unlock(&table->table_lock);
}
@@ -188,7 +192,8 @@ static void mlx5_sf_hw_table_hwc_sf_free(struct mlx5_core_dev *dev,
trace_mlx5_sf_hwc_free(dev, hwc->start_fn_id + idx);
}
-void mlx5_sf_hw_table_sf_deferred_free(struct mlx5_core_dev *dev, u32 controller, u16 id)
+void mlx5_sf_hw_table_sf_deferred_free(struct mlx5_core_dev *dev,
+ u32 controller, u32 pfnum, u16 id)
{
struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;
u32 out[MLX5_ST_SZ_DW(query_vhca_state_out)] = {};
@@ -197,8 +202,8 @@ void mlx5_sf_hw_table_sf_deferred_free(struct mlx5_core_dev *dev, u32 controller
u8 state;
int err;
- hw_fn_id = mlx5_sf_sw_to_hw_id(dev, controller, id);
- hwc = mlx5_sf_controller_to_hwc(dev, controller);
+ hw_fn_id = mlx5_sf_sw_to_hw_id(dev, controller, pfnum, id);
+ hwc = mlx5_sf_controller_to_hwc(dev, controller, pfnum);
mutex_lock(&table->table_lock);
err = mlx5_cmd_query_vhca_state(dev, hw_fn_id, out, sizeof(out));
if (err)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/priv.h b/drivers/net/ethernet/mellanox/mlx5/core/sf/priv.h
index 7114f3fc335f..19fc3be82cd4 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/priv.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/priv.h
@@ -12,11 +12,15 @@ int mlx5_cmd_dealloc_sf(struct mlx5_core_dev *dev, u16 function_id);
int mlx5_cmd_sf_enable_hca(struct mlx5_core_dev *dev, u16 func_id);
int mlx5_cmd_sf_disable_hca(struct mlx5_core_dev *dev, u16 func_id);
-u16 mlx5_sf_sw_to_hw_id(struct mlx5_core_dev *dev, u32 controller, u16 sw_id);
+u16 mlx5_sf_sw_to_hw_id(struct mlx5_core_dev *dev, u32 controller, u32 pfnum,
+ u16 sw_id);
-int mlx5_sf_hw_table_sf_alloc(struct mlx5_core_dev *dev, u32 controller, u32 usr_sfnum);
-void mlx5_sf_hw_table_sf_free(struct mlx5_core_dev *dev, u32 controller, u16 id);
-void mlx5_sf_hw_table_sf_deferred_free(struct mlx5_core_dev *dev, u32 controller, u16 id);
+int mlx5_sf_hw_table_sf_alloc(struct mlx5_core_dev *dev, u32 controller,
+ u32 pfnum, u32 usr_sfnum);
+void mlx5_sf_hw_table_sf_free(struct mlx5_core_dev *dev, u32 controller,
+ u32 pfnum, u16 id);
+void mlx5_sf_hw_table_sf_deferred_free(struct mlx5_core_dev *dev,
+ u32 controller, u32 pfnum, u16 id);
bool mlx5_sf_hw_table_supported(const struct mlx5_core_dev *dev);
#endif
--
2.44.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH net-next 2/2] net/mlx5: Add controller number for SF and ECVF phys_port_name
2026-11-25 21:20 [PATCH net-next 0/2] net/mlx5: Add controller number to SF and VF phys_port_name Tariq Toukan
2026-11-25 21:20 ` [PATCH net-next 1/2] net/mlx5: SF, Pass pfnum through the SF hardware-table allocation path Tariq Toukan
@ 2026-11-25 21:20 ` Tariq Toukan
1 sibling, 0 replies; 3+ messages in thread
From: Tariq Toukan @ 2026-11-25 21:20 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Chris Mi, Gal Pressman, Kees Cook,
Leon Romanovsky, linux-rdma, Mark Bloch, Moshe Shemesh,
Or Har-Toov, Parav Pandit, Saeed Mahameed, Shay Drori,
Tariq Toukan
From: Chris Mi <cmi@nvidia.com>
phys_port_name for the SF/VF representors is derived from the
devlink port attributes such as controller number, function
number (pf num) and the SF/VF number itself. However, if SF/VF
controller number is 0, the controller number is not added to
the phys_port_name.
In a BlueField-4 Socket-Direct topology [1], there are two PCI
links. Under single eswitch, there are duplicate function number
(pf num) and SF/VF number. The result is they share the same
phys_port_name [2]. Hence, annotate the non-master PCI link
with its own controller number so its SFs/VFs can be uniquely
identified. This streamlines the design so that all PCI links
which are not on the eswitch PF get their own unique controller
number.
Use the MLX5_PCI_PF_TYPE_QUERY_PF entry from QUERY_ESW_FUNCTIONS
to read the host_number for each PCI link. Controller number is
host_number + 1. The non-master PCI link devices get a non-zero
phys_port_cnum so their SFs/VFs display the controller prefix.
Since self PF and satellite PF share the same controller number,
use pfnum to locate the right hwc table.
For example, if the device controller number is 4, user can create
an SF like this:
$ devlink port add pci/0006:01:00.0 flavour pcisf pfnum 0 sfnum 0
or
$ devlink port add pci/0006:01:00.0 flavour pcisf pfnum 0 sfnum 0
controller 4
But if user specifies other controller number, command fails.
[1]
PCI NET
0002:01:00.0 net-B21c1pf0,net-p0,net-B21pf0sf0
0006:01:00.0 net-B61c1pf1,net-p1,net-B61pf0sf0
0002:01:00.1 net-B21c2pf0
0006:01:00.1 net-B61c2pf1
[2]
Before this enhancement:
$ cat /sys/class/net/B21pf0sf0/phys_port_name
pf0sf0
$ cat /sys/class/net/B61pf0sf0/phys_port_name
pf0sf0
[3]
After this enhancement:
$ cat /sys/class/net/B21pf0sf0/phys_port_name
pf0sf0
$ cat /sys/class/net/B61c4pf0sf0/phys_port_name
c4pf0sf0
$ devlink port show
pci/0002:01:00.0/360450: type eth netdev B21pf0sf0 flavour pcisf
controller 0 pfnum 0 sfnum 0 external false splittable false
function:
hw_addr 00:00:00:00:00:00 state inactive opstate detached
pci/0006:01:00.0/491520: type eth netdev B61c4pf0sf0 flavour pcisf
controller 4 pfnum 0 sfnum 0 external false splittable false
function:
hw_addr 00:00:00:00:00:00 state inactive opstate detached
Signed-off-by: Chris Mi <cmi@nvidia.com>
Reviewed-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Shay Drori <shayd@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../mellanox/mlx5/core/esw/devlink_port.c | 4 +-
.../net/ethernet/mellanox/mlx5/core/eswitch.c | 111 ++++++++++++++++--
.../net/ethernet/mellanox/mlx5/core/eswitch.h | 8 +-
.../mellanox/mlx5/core/eswitch_offloads.c | 7 +-
.../mellanox/mlx5/core/lag/shared_fdb.c | 58 +++++++++
.../ethernet/mellanox/mlx5/core/sf/devlink.c | 31 ++++-
.../ethernet/mellanox/mlx5/core/sf/hw_table.c | 10 ++
7 files changed, 215 insertions(+), 14 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
index 8b46634203b3..fa07a571c1b9 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
@@ -83,7 +83,9 @@ static void mlx5_esw_offloads_pf_vf_devlink_port_attrs_set(struct mlx5_eswitch *
memcpy(dl_port->attrs.switch_id.id, ppid.id, ppid.id_len);
dl_port->attrs.switch_id.id_len = ppid.id_len;
- devlink_port_attrs_pci_vf_set(dl_port, 0, pfnum,
+ controller_num = mlx5_esw_get_self_pf_ctrl_num(esw);
+ pfnum = mlx5_esw_get_self_pf_pfnum(esw);
+ devlink_port_attrs_pci_vf_set(dl_port, controller_num, pfnum,
vport_num - base_vport, false);
} else if (mlx5_esw_is_spf_vport(esw, vport_num)) {
int spf_idx = mlx5_esw_spf_vport_to_idx(esw, vport_num);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
index 8c2c55ba5c35..09a29280c48e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@ -2183,21 +2183,58 @@ u16 mlx5_esw_get_hpf_pf_num(struct mlx5_core_dev *dev)
return PCI_FUNC(dev->pdev->devfn);
}
-u16 mlx5_esw_sf_controller_to_pfnum(struct mlx5_core_dev *dev, u32 controller)
+u32 mlx5_esw_get_self_pf_ctrl_num(struct mlx5_eswitch *esw)
+{
+ struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs;
+
+ return esw_funcs->phys_port_cnum;
+}
+
+u16 mlx5_esw_get_self_pf_pfnum(struct mlx5_eswitch *esw)
+{
+ struct mlx5_core_dev *dev = esw->dev;
+
+ if (mlx5_core_is_ecpf_esw_manager(dev) &&
+ MLX5_CAP_GEN(dev, query_host_net_function_v1))
+ return esw->esw_funcs.self_pf_pfnum;
+
+ return PCI_FUNC(dev->pdev->devfn);
+}
+
+bool mlx5_esw_sf_controller_to_pfnum_valid(struct mlx5_core_dev *dev,
+ u32 controller, u32 pfnum)
{
struct mlx5_eswitch *esw = dev->priv.eswitch;
struct mlx5_esw_functions *esw_funcs;
+ bool known_controller = false;
int i;
- if (!controller)
- return PCI_FUNC(dev->pdev->devfn);
+ if (!MLX5_CAP_GEN(dev, query_host_net_function_v1))
+ return pfnum == PCI_FUNC(dev->pdev->devfn);
esw_funcs = &esw->esw_funcs;
- for (i = 0; i < esw_funcs->num_spfs; i++)
- if (controller == esw_funcs->spfs[i].host_number + 1)
- return esw_funcs->spfs[i].pf_num;
+ if (!controller || controller == esw_funcs->controller_num) {
+ known_controller = true;
+ if (mlx5_esw_get_self_pf_pfnum(esw) == pfnum)
+ return true;
+ }
- return mlx5_esw_get_hpf_pf_num(dev);
+ for (i = 0; i < esw_funcs->num_spfs; i++) {
+ if (controller != esw_funcs->spfs[i].host_number + 1)
+ continue;
+ known_controller = true;
+ if (esw_funcs->spfs[i].pf_num == pfnum)
+ return true;
+ }
+
+ /* controller matched self pf or a satellite PF, but pfnum matched
+ * neither. It's invalid, do not continue on to check the external
+ * host PF.
+ */
+ if (known_controller)
+ return false;
+
+ return mlx5_esw_get_hpf_pf_num(dev) == pfnum;
}
bool mlx5_esw_has_spf_sfs(struct mlx5_core_dev *dev)
@@ -2264,6 +2301,61 @@ void mlx5_esw_vport_free(struct mlx5_eswitch *esw, struct mlx5_vport *vport)
kfree(vport);
}
+static void mlx5_esw_self_pf_cleanup(struct mlx5_eswitch *esw)
+{
+ struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs;
+
+ esw_funcs->controller_num = 0;
+ esw_funcs->phys_port_cnum = 0;
+ esw_funcs->self_pf_pfnum = 0;
+}
+
+static int mlx5_esw_self_pf_init(struct mlx5_eswitch *esw)
+{
+ struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs;
+ struct mlx5_core_dev *dev = esw->dev;
+ int num_entries;
+ const u8 *entry;
+ const u32 *out;
+ int i;
+
+ esw_funcs->self_pf_pfnum = PCI_FUNC(dev->pdev->devfn);
+
+ if (!MLX5_CAP_GEN(dev, query_host_net_function_v1))
+ return 0;
+
+ out = mlx5_esw_query_functions(dev);
+ if (IS_ERR(out))
+ return PTR_ERR(out);
+
+ num_entries = MLX5_GET(query_esw_functions_out, out, net_function_num);
+ if (!num_entries)
+ goto out_free;
+
+ entry = MLX5_ADDR_OF(query_esw_functions_out, out, net_function_params);
+ for (i = 0; i < num_entries; i++) {
+ int pf_type;
+
+ pf_type = MLX5_GET(network_function_params, entry, pci_pf_type);
+ if (pf_type != MLX5_PCI_PF_TYPE_QUERY_PF) {
+ entry += MLX5_UN_SZ_BYTES(net_function_params);
+ continue;
+ }
+
+ esw_funcs->controller_num =
+ MLX5_GET(network_function_params,
+ entry, host_number) + 1;
+ esw_funcs->self_pf_pfnum =
+ MLX5_GET(network_function_params,
+ entry, pci_device_function);
+ break;
+ }
+
+out_free:
+ kvfree(out);
+ return 0;
+}
+
static void mlx5_esw_spfs_cleanup(struct mlx5_eswitch *esw)
{
struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs;
@@ -2371,6 +2463,7 @@ static void mlx5_esw_vports_cleanup(struct mlx5_eswitch *esw)
mlx5_esw_for_each_vport(esw, i, vport)
mlx5_esw_vport_free(esw, vport);
xa_destroy(&esw->vports);
+ mlx5_esw_self_pf_cleanup(esw);
}
static int mlx5_esw_vports_init(struct mlx5_eswitch *esw)
@@ -2381,6 +2474,10 @@ static int mlx5_esw_vports_init(struct mlx5_eswitch *esw)
int err;
int i;
+ err = mlx5_esw_self_pf_init(esw);
+ if (err)
+ return err;
+
xa_init(&esw->vports);
err = mlx5_esw_hpf_info_init(esw);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
index 463855240032..b6b8c35f0289 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
@@ -370,6 +370,9 @@ struct mlx5_esw_functions {
bool has_spf_sfs;
struct mlx5_esw_spf *spfs;
int num_spfs;
+ u32 controller_num;
+ u32 phys_port_cnum;
+ u32 self_pf_pfnum;
};
enum {
@@ -916,7 +919,10 @@ int mlx5_esw_spf_get_host_number(struct mlx5_core_dev *dev, int spf_idx,
u16 *host_number);
u16 mlx5_esw_get_hpf_host_number(struct mlx5_core_dev *dev);
u16 mlx5_esw_get_hpf_pf_num(struct mlx5_core_dev *dev);
-u16 mlx5_esw_sf_controller_to_pfnum(struct mlx5_core_dev *dev, u32 controller);
+u32 mlx5_esw_get_self_pf_ctrl_num(struct mlx5_eswitch *esw);
+u16 mlx5_esw_get_self_pf_pfnum(struct mlx5_eswitch *esw);
+bool mlx5_esw_sf_controller_to_pfnum_valid(struct mlx5_core_dev *dev,
+ u32 controller, u32 pfnum);
bool mlx5_esw_has_spf_sfs(struct mlx5_core_dev *dev);
int mlx5_esw_vport_vhca_id_map(struct mlx5_eswitch *esw,
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index 3f182e6286d6..ff689b10635f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -4141,6 +4141,12 @@ bool mlx5_esw_offloads_controller_valid(const struct mlx5_eswitch *esw, u32 cont
const struct mlx5_esw_functions *esw_funcs;
int i;
+ /* User specifies correct non-zero self PF controller number */
+ esw_funcs = &esw->esw_funcs;
+ if (esw_funcs->phys_port_cnum &&
+ controller == esw_funcs->phys_port_cnum)
+ return true;
+
/* Local controller is always valid */
if (controller == 0)
return true;
@@ -4152,7 +4158,6 @@ bool mlx5_esw_offloads_controller_valid(const struct mlx5_eswitch *esw, u32 cont
if (controller == mlx5_esw_get_hpf_host_number(esw->dev) + 1)
return true;
- esw_funcs = &esw->esw_funcs;
for (i = 0; i < esw_funcs->num_spfs; i++) {
if (controller == esw_funcs->spfs[i].host_number + 1)
return true;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
index 404278a15ef7..fb96e9c3a5d8 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
@@ -190,6 +190,44 @@ void mlx5_lag_destroy_single_fdb(struct mlx5_lag *ldev)
mlx5_lag_destroy_single_fdb_filter(ldev, MLX5_LAG_FILTER_ALL);
}
+static void mlx5_self_controller_set(struct mlx5_lag *ldev, u32 filter)
+{
+ struct mlx5_core_dev *dev, *master_dev = NULL;
+ struct mlx5_esw_functions *esw_funcs;
+ struct mlx5_eswitch *esw;
+ int i;
+
+ mlx5_lag_for_each(i, 0, ldev, filter) {
+ dev = mlx5_lag_fn(ldev, i)->dev;
+ esw = dev->priv.eswitch;
+ esw_funcs = &esw->esw_funcs;
+ if (!mlx5_lag_is_master(dev))
+ esw_funcs->phys_port_cnum = esw_funcs->controller_num;
+ else
+ master_dev = dev;
+ }
+
+ if (!master_dev)
+ return;
+
+ mlx5_lag_for_each(i, 0, ldev, filter) {
+ struct mlx5_esw_functions *master_esw_funcs;
+ u32 host_ctrl_num, master_host_ctrl_num;
+ struct mlx5_eswitch *master_esw;
+
+ dev = mlx5_lag_fn(ldev, i)->dev;
+ esw = dev->priv.eswitch;
+ esw_funcs = &esw->esw_funcs;
+ host_ctrl_num = esw_funcs->controller_num;
+
+ master_esw = master_dev->priv.eswitch;
+ master_esw_funcs = &master_esw->esw_funcs;
+ master_host_ctrl_num = master_esw_funcs->controller_num;
+ if (host_ctrl_num == master_host_ctrl_num)
+ esw_funcs->phys_port_cnum = 0;
+ }
+}
+
/**
* mlx5_lag_shared_fdb_create - Create shared FDB LAG
* @ldev: LAG device
@@ -257,6 +295,9 @@ int mlx5_lag_shared_fdb_create(struct mlx5_lag *ldev,
if (filter == MLX5_LAG_FILTER_PORTS || filter == MLX5_LAG_FILTER_ALL)
mlx5_lag_set_vports_agg_speed(ldev);
+
+ mlx5_self_controller_set(ldev, filter);
+
return 0;
err_rescan_drivers:
@@ -277,6 +318,21 @@ int mlx5_lag_shared_fdb_create(struct mlx5_lag *ldev,
return err;
}
+static void mlx5_self_controller_reset(struct mlx5_lag *ldev, u32 filter)
+{
+ struct mlx5_esw_functions *esw_funcs;
+ struct mlx5_core_dev *dev;
+ struct mlx5_eswitch *esw;
+ int i;
+
+ mlx5_lag_for_each(i, 0, ldev, filter) {
+ dev = mlx5_lag_fn(ldev, i)->dev;
+ esw = dev->priv.eswitch;
+ esw_funcs = &esw->esw_funcs;
+ esw_funcs->phys_port_cnum = 0;
+ }
+}
+
void mlx5_lag_shared_fdb_destroy(struct mlx5_lag *ldev, u32 group_id)
{
u32 filter = group_id ? group_id : MLX5_LAG_FILTER_ALL;
@@ -284,6 +340,8 @@ void mlx5_lag_shared_fdb_destroy(struct mlx5_lag *ldev, u32 group_id)
int err;
int i;
+ mlx5_self_controller_reset(ldev, filter);
+
mlx5_lag_remove_devices_filter(ldev, filter);
if (filter == MLX5_LAG_FILTER_PORTS || filter == MLX5_LAG_FILTER_ALL) {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
index 2002b7f376ee..c8aa1b0b9319 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
@@ -237,6 +237,18 @@ int mlx5_devlink_sf_port_fn_state_set(struct devlink_port *dl_port,
return mlx5_sf_state_set(dev, table, sf, state, extack);
}
+static u32
+mlx5_sf_get_self_controller(struct mlx5_eswitch *esw,
+ const struct devlink_port_new_attrs *new_attr)
+{
+ struct mlx5_esw_functions *esw_funcs = &esw->esw_funcs;
+
+ if (!new_attr->controller_valid && esw_funcs->phys_port_cnum)
+ return esw_funcs->phys_port_cnum;
+
+ return new_attr->controller;
+}
+
static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
const struct devlink_port_new_attrs *new_attr,
struct netlink_ext_ack *extack,
@@ -244,9 +256,11 @@ static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
{
struct mlx5_eswitch *esw = dev->priv.eswitch;
struct mlx5_sf *sf;
+ u32 controller;
int err;
- sf = mlx5_sf_alloc(table, esw, new_attr->controller, new_attr->pfnum,
+ controller = mlx5_sf_get_self_controller(esw, new_attr);
+ sf = mlx5_sf_alloc(table, esw, controller, new_attr->pfnum,
new_attr->sfnum, extack);
if (IS_ERR(sf))
return PTR_ERR(sf);
@@ -254,7 +268,7 @@ static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
mlx5_esw_reps_block(esw);
err = mlx5_eswitch_load_sf_vport(esw, sf->hw_fn_id,
MLX5_VPORT_UC_ADDR_CHANGE,
- &sf->dl_port, new_attr->controller,
+ &sf->dl_port, controller,
new_attr->pfnum,
new_attr->sfnum);
mlx5_esw_reps_unblock(esw);
@@ -274,6 +288,8 @@ static int
mlx5_sf_new_check_attr(struct mlx5_core_dev *dev, const struct devlink_port_new_attrs *new_attr,
struct netlink_ext_ack *extack)
{
+ struct mlx5_esw_functions *esw_funcs;
+ struct mlx5_eswitch *esw;
u32 controller;
if (new_attr->flavour != DEVLINK_PORT_FLAVOUR_PCI_SF) {
@@ -295,9 +311,16 @@ mlx5_sf_new_check_attr(struct mlx5_core_dev *dev, const struct devlink_port_new_
NL_SET_ERR_MSG_MOD(extack, "External controller is unsupported");
return -EOPNOTSUPP;
}
+ esw = dev->priv.eswitch;
+ esw_funcs = &esw->esw_funcs;
+ if (new_attr->controller_valid && !new_attr->controller &&
+ esw_funcs->phys_port_cnum) {
+ NL_SET_ERR_MSG_MOD(extack, "Invalid controller supplied");
+ return -EOPNOTSUPP;
+ }
controller = new_attr->controller_valid ? new_attr->controller : 0;
- if (new_attr->pfnum !=
- mlx5_esw_sf_controller_to_pfnum(dev, controller)) {
+ if (!mlx5_esw_sf_controller_to_pfnum_valid(dev, controller,
+ new_attr->pfnum)) {
NL_SET_ERR_MSG_MOD(extack, "Invalid pfnum supplied");
return -EOPNOTSUPP;
}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
index d8d061683497..b7e8a8d7cc64 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
@@ -40,8 +40,18 @@ static struct mlx5_sf_hwc_table *
mlx5_sf_controller_to_hwc(struct mlx5_core_dev *dev, u32 controller, u32 pfnum)
{
struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;
+ struct mlx5_eswitch *esw = dev->priv.eswitch;
+ struct mlx5_esw_functions *esw_funcs;
int i;
+ /* If shared fdb is destroyed, phys_port_cnum is reset to 0.
+ * So use controller_num directly which is read from firmware.
+ */
+ esw_funcs = &esw->esw_funcs;
+ if (controller == esw_funcs->controller_num &&
+ pfnum == mlx5_esw_get_self_pf_pfnum(esw))
+ return &table->hwc[MLX5_SF_HWC_LOCAL];
+
for (i = MLX5_SF_HWC_FIRST_SPF; i < table->num_hwc; i++) {
if (table->hwc[i].controller == controller)
return &table->hwc[i];
--
2.44.0
^ permalink raw reply related [flat|nested] 3+ messages in thread