net/mlx5: Introduce new device index wrapper
authorRongwei Liu <rongweil@nvidia.com>
Thu, 16 Sep 2021 07:46:17 +0000 (10:46 +0300)
committerSaeed Mahameed <saeedm@nvidia.com>
Sat, 16 Oct 2021 00:37:46 +0000 (17:37 -0700)
Downstream patches.

Signed-off-by: Rongwei Liu <rongweil@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c
drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
drivers/net/ethernet/mellanox/mlx5/core/lag.c
drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
include/linux/mlx5/driver.h

index 86e079310ac399f87162919a2c545e35ba49d576..ae52e7f38306158cb56d8f56e025c72e12263464 100644 (file)
@@ -24,7 +24,7 @@ int mlx5e_devlink_port_register(struct mlx5e_priv *priv)
 
        if (mlx5_core_is_pf(priv->mdev)) {
                attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
-               attrs.phys.port_number = PCI_FUNC(priv->mdev->pdev->devfn);
+               attrs.phys.port_number = mlx5_get_dev_index(priv->mdev);
                if (MLX5_ESWITCH_MANAGER(priv->mdev)) {
                        mlx5e_devlink_get_port_parent_id(priv->mdev, &ppid);
                        memcpy(attrs.switch_id.id, ppid.id, ppid.id_len);
index 20af557ae30cb8a541f15c5d38ae8b1c9c1399de..7f9b96d9537ebdb794154de76eee97fd8e20a87c 100644 (file)
@@ -36,7 +36,7 @@ static struct devlink_port *mlx5_esw_dl_port_alloc(struct mlx5_eswitch *esw, u16
                return NULL;
 
        mlx5_esw_get_port_parent_id(dev, &ppid);
-       pfnum = PCI_FUNC(dev->pdev->devfn);
+       pfnum = mlx5_get_dev_index(dev);
        external = mlx5_core_is_ecpf_esw_manager(dev);
        if (external)
                controller_num = dev->priv.eswitch->offloads.host_number + 1;
@@ -149,7 +149,7 @@ int mlx5_esw_devlink_sf_port_register(struct mlx5_eswitch *esw, struct devlink_p
        if (IS_ERR(vport))
                return PTR_ERR(vport);
 
-       pfnum = PCI_FUNC(dev->pdev->devfn);
+       pfnum = mlx5_get_dev_index(dev);
        mlx5_esw_get_port_parent_id(dev, &ppid);
        memcpy(dl_port->attrs.switch_id.id, &ppid.id[0], ppid.id_len);
        dl_port->attrs.switch_id.id_len = ppid.id_len;
index ca7e31a1a431e3c4fd39be2a2201ec427245afd2..3e5a7d74020bb6f314e194fdaffdb81d515aa78f 100644 (file)
@@ -2798,7 +2798,7 @@ u32 mlx5_esw_match_metadata_alloc(struct mlx5_eswitch *esw)
        int id;
 
        /* Only 4 bits of pf_num */
-       pf_num = PCI_FUNC(esw->dev->pdev->devfn);
+       pf_num = mlx5_get_dev_index(esw->dev);
        if (pf_num > max_pf_num)
                return 0;
 
index ca5690b0a7abbf3628e7d56d96f9d9ee6233099a..f35c8ba48aac8a096b790c7b106087fdd147451c 100644 (file)
@@ -688,7 +688,7 @@ static void mlx5_ldev_add_netdev(struct mlx5_lag *ldev,
                                 struct mlx5_core_dev *dev,
                                 struct net_device *netdev)
 {
-       unsigned int fn = PCI_FUNC(dev->pdev->devfn);
+       unsigned int fn = mlx5_get_dev_index(dev);
 
        if (fn >= MLX5_MAX_PORTS)
                return;
@@ -718,7 +718,7 @@ static void mlx5_ldev_remove_netdev(struct mlx5_lag *ldev,
 static void mlx5_ldev_add_mdev(struct mlx5_lag *ldev,
                               struct mlx5_core_dev *dev)
 {
-       unsigned int fn = PCI_FUNC(dev->pdev->devfn);
+       unsigned int fn = mlx5_get_dev_index(dev);
 
        if (fn >= MLX5_MAX_PORTS)
                return;
index 13891fdc607e8c785d5a69267b307d354d0e0e60..e1bb3acf45e675b33a3bd830e0cb777a61c5b963 100644 (file)
@@ -323,7 +323,7 @@ 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;
        }
-       if (new_attr->pfnum != PCI_FUNC(dev->pdev->devfn)) {
+       if (new_attr->pfnum != mlx5_get_dev_index(dev)) {
                NL_SET_ERR_MSG_MOD(extack, "Invalid pfnum supplied");
                return -EOPNOTSUPP;
        }
index 7c8b5f06c2cd7aebd163211fef210aa3dd91e7fc..aecc38b90de53b472b970973a25e00ba5e52db3d 100644 (file)
@@ -1243,6 +1243,11 @@ static inline int mlx5_core_native_port_num(struct mlx5_core_dev *dev)
        return MLX5_CAP_GEN(dev, native_port_num);
 }
 
+static inline int mlx5_get_dev_index(struct mlx5_core_dev *dev)
+{
+       return PCI_FUNC(dev->pdev->devfn);
+}
+
 enum {
        MLX5_TRIGGERED_CMD_COMP = (u64)1 << 32,
 };