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>
 
        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);
 
                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;
        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;
 
        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;
 
 
                                 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;
 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;
 
                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;
        }
 
        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,
 };