]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net/mlx5: Initialize host PF host number earlier
authorMoshe Shemesh <moshe@nvidia.com>
Thu, 21 May 2026 11:08:34 +0000 (14:08 +0300)
committerJakub Kicinski <kuba@kernel.org>
Mon, 25 May 2026 20:48:51 +0000 (13:48 -0700)
Move host_number from esw->offloads to esw->esw_funcs as hpf_host_number
and initialize it during vports_init instead of offloads_enable. This
makes the host PF host number available earlier in the initialization
sequence, which is required for upcoming SF hardware table support for
satellite PFs.

Add a mlx5_esw_get_hpf_host_number() accessor to retrieve the stored
host number.

Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260521110843.367329-4-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

index 0730f0c883fe44b82ddc88c1fa13c9a9ac09e5e2..e723f05cd4d3b81666968fa1db8acdf1974faf8d 100644 (file)
@@ -34,7 +34,7 @@ static void mlx5_esw_offloads_pf_vf_devlink_port_attrs_set(struct mlx5_eswitch *
        pfnum = PCI_FUNC(dev->pdev->devfn);
        external = mlx5_core_is_ecpf_esw_manager(dev);
        if (external)
-               controller_num = dev->priv.eswitch->offloads.host_number + 1;
+               controller_num = mlx5_esw_get_hpf_host_number(dev) + 1;
 
        if (vport_num == MLX5_VPORT_HOST_PF) {
                memcpy(dl_port->attrs.switch_id.id, ppid.id, ppid.id_len);
index f7fa5ef742018deca209350f1c8463bd959f1902..959b85e2f61e6e2c8aa63e09baa5dec1bc406e33 100644 (file)
@@ -2083,6 +2083,35 @@ int mlx5_esw_sf_max_hpf_functions(struct mlx5_core_dev *dev, u16 *max_sfs,
                                            sf_base_id);
 }
 
+u16 mlx5_esw_get_hpf_host_number(struct mlx5_core_dev *dev)
+{
+       struct mlx5_eswitch *esw = dev->priv.eswitch;
+
+       if (!mlx5_esw_allowed(esw))
+               return 0;
+
+       return esw->esw_funcs.hpf_host_number;
+}
+
+static int mlx5_esw_hpf_host_number_init(struct mlx5_eswitch *esw)
+{
+       struct mlx5_esw_pf_info host_pf_info;
+       const u32 *query_host_out;
+
+       if (!mlx5_core_is_ecpf_esw_manager(esw->dev))
+               return 0;
+
+       query_host_out = mlx5_esw_query_functions(esw->dev);
+       if (IS_ERR(query_host_out))
+               return PTR_ERR(query_host_out);
+
+       /* Mark non local controller with non zero controller number. */
+       host_pf_info = mlx5_esw_get_host_pf_info(esw->dev, query_host_out);
+       esw->esw_funcs.hpf_host_number = host_pf_info.host_number;
+       kvfree(query_host_out);
+       return 0;
+}
+
 int mlx5_esw_vport_alloc(struct mlx5_eswitch *esw, int index, u16 vport_num)
 {
        struct mlx5_vport *vport;
@@ -2232,6 +2261,10 @@ static int mlx5_esw_vports_init(struct mlx5_eswitch *esw)
 
        xa_init(&esw->vports);
 
+       err = mlx5_esw_hpf_host_number_init(esw);
+       if (err)
+               goto err;
+
        if (mlx5_esw_host_functions_enabled(dev)) {
                err = mlx5_esw_vport_alloc(esw, idx, MLX5_VPORT_HOST_PF);
                if (err)
index 2f5a6b390ffb53d5691a353ab5ce79475dc516d2..0f552ef468d891ec325393f3b506c11f3d419b84 100644 (file)
@@ -333,7 +333,6 @@ struct mlx5_esw_offload {
        u64 num_block_mode;
        enum devlink_eswitch_encap_mode encap;
        struct ida vport_metadata_ida;
-       unsigned int host_number; /* ECPF supports one external host */
 };
 
 /* E-Switch MC FDB table hash node */
@@ -360,6 +359,7 @@ struct mlx5_esw_functions {
        bool                    host_funcs_disabled;
        u16                     num_vfs;
        u16                     num_ec_vfs;
+       u16                     hpf_host_number;
        struct mlx5_esw_spf     *spfs;
        int                     num_spfs;
 };
@@ -880,6 +880,8 @@ struct devlink_port *mlx5_esw_offloads_devlink_port(struct mlx5_eswitch *esw, u1
 
 int mlx5_esw_sf_max_hpf_functions(struct mlx5_core_dev *dev, u16 *max_sfs, u16 *sf_base_id);
 
+u16 mlx5_esw_get_hpf_host_number(struct mlx5_core_dev *dev);
+
 int mlx5_esw_vport_vhca_id_map(struct mlx5_eswitch *esw,
                               struct mlx5_vport *vport);
 void mlx5_esw_vport_vhca_id_unmap(struct mlx5_eswitch *esw,
index b06b10d443bdaaf63783b55c0821ad3e42b0a309..f17db51abe2d4be80a8850fc94a38392d2860c2b 100644 (file)
@@ -3819,25 +3819,6 @@ int mlx5_esw_funcs_changed_handler(struct notifier_block *nb,
        return NOTIFY_OK;
 }
 
-static int mlx5_esw_host_number_init(struct mlx5_eswitch *esw)
-{
-       struct mlx5_esw_pf_info host_pf_info;
-       const u32 *query_host_out;
-
-       if (!mlx5_core_is_ecpf_esw_manager(esw->dev))
-               return 0;
-
-       query_host_out = mlx5_esw_query_functions(esw->dev);
-       if (IS_ERR(query_host_out))
-               return PTR_ERR(query_host_out);
-
-       /* Mark non local controller with non zero controller number. */
-       host_pf_info = mlx5_esw_get_host_pf_info(esw->dev, query_host_out);
-       esw->offloads.host_number = host_pf_info.host_number;
-       kvfree(query_host_out);
-       return 0;
-}
-
 bool mlx5_esw_offloads_controller_valid(const struct mlx5_eswitch *esw, u32 controller)
 {
        /* Local controller is always valid */
@@ -3848,7 +3829,7 @@ bool mlx5_esw_offloads_controller_valid(const struct mlx5_eswitch *esw, u32 cont
                return false;
 
        /* External host number starts with zero in device */
-       return (controller == esw->offloads.host_number + 1);
+       return (controller == mlx5_esw_get_hpf_host_number(esw->dev) + 1);
 }
 
 int esw_offloads_enable(struct mlx5_eswitch *esw)
@@ -3867,10 +3848,6 @@ int esw_offloads_enable(struct mlx5_eswitch *esw)
        if (err)
                goto err_roce;
 
-       err = mlx5_esw_host_number_init(esw);
-       if (err)
-               goto err_metadata;
-
        err = esw_offloads_metadata_init(esw);
        if (err)
                goto err_metadata;