net/mlx5: Split mdev init and pci init
Separate resources initialization from pci initialization. This provides a better logical separation of mlx5 core device initialization flow and will help to seamlessly support creating different mlx5 device types such as PF, VF and SF mlx5 sub-function virtual device. This patch does not change any functionality. Signed-off-by: Vu Pham <vuhuong@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
This commit is contained in:
Родитель
868bc06b24
Коммит
11f3b84d70
|
@ -729,32 +729,23 @@ static int mlx5_core_set_issi(struct mlx5_core_dev *dev)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mlx5_pci_init(struct mlx5_core_dev *dev)
|
static int mlx5_pci_init(struct mlx5_core_dev *dev, struct pci_dev *pdev,
|
||||||
|
const struct pci_device_id *id)
|
||||||
{
|
{
|
||||||
struct mlx5_priv *priv = &dev->priv;
|
struct mlx5_priv *priv = &dev->priv;
|
||||||
struct pci_dev *pdev = dev->pdev;
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
dev->pdev = pdev;
|
||||||
|
priv->pci_dev_data = id->driver_data;
|
||||||
|
|
||||||
pci_set_drvdata(dev->pdev, dev);
|
pci_set_drvdata(dev->pdev, dev);
|
||||||
strncpy(priv->name, dev_name(&pdev->dev), MLX5_MAX_NAME_LEN);
|
|
||||||
priv->name[MLX5_MAX_NAME_LEN - 1] = 0;
|
|
||||||
|
|
||||||
mutex_init(&priv->pgdir_mutex);
|
|
||||||
INIT_LIST_HEAD(&priv->pgdir_list);
|
|
||||||
spin_lock_init(&priv->mkey_lock);
|
|
||||||
|
|
||||||
mutex_init(&priv->alloc_mutex);
|
|
||||||
|
|
||||||
priv->numa_node = dev_to_node(&dev->pdev->dev);
|
priv->numa_node = dev_to_node(&dev->pdev->dev);
|
||||||
|
|
||||||
if (mlx5_debugfs_root)
|
|
||||||
priv->dbg_root =
|
|
||||||
debugfs_create_dir(pci_name(pdev), mlx5_debugfs_root);
|
|
||||||
|
|
||||||
err = mlx5_pci_enable_device(dev);
|
err = mlx5_pci_enable_device(dev);
|
||||||
if (err) {
|
if (err) {
|
||||||
dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n");
|
dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n");
|
||||||
goto err_dbg;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = request_bar(pdev);
|
err = request_bar(pdev);
|
||||||
|
@ -791,9 +782,6 @@ err_clr_master:
|
||||||
release_bar(dev->pdev);
|
release_bar(dev->pdev);
|
||||||
err_disable:
|
err_disable:
|
||||||
mlx5_pci_disable_device(dev);
|
mlx5_pci_disable_device(dev);
|
||||||
|
|
||||||
err_dbg:
|
|
||||||
debugfs_remove(priv->dbg_root);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -803,7 +791,6 @@ static void mlx5_pci_close(struct mlx5_core_dev *dev)
|
||||||
pci_clear_master(dev->pdev);
|
pci_clear_master(dev->pdev);
|
||||||
release_bar(dev->pdev);
|
release_bar(dev->pdev);
|
||||||
mlx5_pci_disable_device(dev);
|
mlx5_pci_disable_device(dev);
|
||||||
debugfs_remove_recursive(dev->priv.dbg_root);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mlx5_init_once(struct mlx5_core_dev *dev)
|
static int mlx5_init_once(struct mlx5_core_dev *dev)
|
||||||
|
@ -1230,29 +1217,14 @@ static const struct devlink_ops mlx5_devlink_ops = {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MLX5_IB_MOD "mlx5_ib"
|
static int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx, const char *name)
|
||||||
static int init_one(struct pci_dev *pdev,
|
|
||||||
const struct pci_device_id *id)
|
|
||||||
{
|
{
|
||||||
struct mlx5_core_dev *dev;
|
struct mlx5_priv *priv = &dev->priv;
|
||||||
struct devlink *devlink;
|
|
||||||
struct mlx5_priv *priv;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
devlink = devlink_alloc(&mlx5_devlink_ops, sizeof(*dev));
|
strncpy(priv->name, name, MLX5_MAX_NAME_LEN);
|
||||||
if (!devlink) {
|
priv->name[MLX5_MAX_NAME_LEN - 1] = 0;
|
||||||
dev_err(&pdev->dev, "kzalloc failed\n");
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
dev = devlink_priv(devlink);
|
dev->profile = &profile[profile_idx];
|
||||||
priv = &dev->priv;
|
|
||||||
priv->pci_dev_data = id->driver_data;
|
|
||||||
|
|
||||||
pci_set_drvdata(pdev, dev);
|
|
||||||
|
|
||||||
dev->pdev = pdev;
|
|
||||||
dev->profile = &profile[prof_sel];
|
|
||||||
|
|
||||||
INIT_LIST_HEAD(&priv->ctx_list);
|
INIT_LIST_HEAD(&priv->ctx_list);
|
||||||
spin_lock_init(&priv->ctx_lock);
|
spin_lock_init(&priv->ctx_lock);
|
||||||
|
@ -1264,10 +1236,48 @@ static int init_one(struct pci_dev *pdev,
|
||||||
INIT_LIST_HEAD(&priv->bfregs.reg_head.list);
|
INIT_LIST_HEAD(&priv->bfregs.reg_head.list);
|
||||||
INIT_LIST_HEAD(&priv->bfregs.wc_head.list);
|
INIT_LIST_HEAD(&priv->bfregs.wc_head.list);
|
||||||
|
|
||||||
err = mlx5_pci_init(dev);
|
mutex_init(&priv->alloc_mutex);
|
||||||
|
mutex_init(&priv->pgdir_mutex);
|
||||||
|
INIT_LIST_HEAD(&priv->pgdir_list);
|
||||||
|
spin_lock_init(&priv->mkey_lock);
|
||||||
|
|
||||||
|
priv->dbg_root = debugfs_create_dir(name, mlx5_debugfs_root);
|
||||||
|
if (!priv->dbg_root) {
|
||||||
|
pr_err("mlx5_core: %s error, Cannot create debugfs dir, aborting\n", name);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mlx5_mdev_uninit(struct mlx5_core_dev *dev)
|
||||||
|
{
|
||||||
|
debugfs_remove_recursive(dev->priv.dbg_root);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define MLX5_IB_MOD "mlx5_ib"
|
||||||
|
static int init_one(struct pci_dev *pdev, const struct pci_device_id *id)
|
||||||
|
{
|
||||||
|
struct mlx5_core_dev *dev;
|
||||||
|
struct devlink *devlink;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
devlink = devlink_alloc(&mlx5_devlink_ops, sizeof(*dev));
|
||||||
|
if (!devlink) {
|
||||||
|
dev_err(&pdev->dev, "kzalloc failed\n");
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev = devlink_priv(devlink);
|
||||||
|
|
||||||
|
err = mlx5_mdev_init(dev, prof_sel, dev_name(&pdev->dev));
|
||||||
|
if (err)
|
||||||
|
goto mdev_init_err;
|
||||||
|
|
||||||
|
err = mlx5_pci_init(dev, pdev, id);
|
||||||
if (err) {
|
if (err) {
|
||||||
dev_err(&pdev->dev, "mlx5_pci_init failed with error code %d\n", err);
|
dev_err(&pdev->dev, "mlx5_pci_init failed with error code %d\n", err);
|
||||||
goto clean_dev;
|
goto pci_init_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = mlx5_health_init(dev);
|
err = mlx5_health_init(dev);
|
||||||
|
@ -1303,7 +1313,9 @@ err_pagealloc_init:
|
||||||
mlx5_health_cleanup(dev);
|
mlx5_health_cleanup(dev);
|
||||||
close_pci:
|
close_pci:
|
||||||
mlx5_pci_close(dev);
|
mlx5_pci_close(dev);
|
||||||
clean_dev:
|
pci_init_err:
|
||||||
|
mlx5_mdev_uninit(dev);
|
||||||
|
mdev_init_err:
|
||||||
devlink_free(devlink);
|
devlink_free(devlink);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
@ -1326,6 +1338,7 @@ static void remove_one(struct pci_dev *pdev)
|
||||||
mlx5_pagealloc_cleanup(dev);
|
mlx5_pagealloc_cleanup(dev);
|
||||||
mlx5_health_cleanup(dev);
|
mlx5_health_cleanup(dev);
|
||||||
mlx5_pci_close(dev);
|
mlx5_pci_close(dev);
|
||||||
|
mlx5_mdev_uninit(dev);
|
||||||
devlink_free(devlink);
|
devlink_free(devlink);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче