vDPA/ifcvf: allocate the adapter in dev_add()
commit 93139037b582134deb1ed894bbc4bc1d34ff35e7 upstream. The adapter is the container of the vdpa_device, this commits allocate the adapter in dev_add() rather than in probe(). So that the vdpa_device() could be re-created when the userspace creates the vdpa device, and free-ed in dev_del() Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com> Cc: stable@vger.kernel.org Message-Id: <20221125145724.1129962-11-lingshan.zhu@intel.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
dd5d2d8821
commit
beb15de99a
@ -746,12 +746,20 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ifcvf_mgmt_dev = container_of(mdev, struct ifcvf_vdpa_mgmt_dev, mdev);
|
ifcvf_mgmt_dev = container_of(mdev, struct ifcvf_vdpa_mgmt_dev, mdev);
|
||||||
if (!ifcvf_mgmt_dev->adapter)
|
vf = &ifcvf_mgmt_dev->vf;
|
||||||
return -EOPNOTSUPP;
|
pdev = vf->pdev;
|
||||||
|
adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa,
|
||||||
|
&pdev->dev, &ifc_vdpa_ops, 1, 1, NULL, false);
|
||||||
|
if (IS_ERR(adapter)) {
|
||||||
|
IFCVF_ERR(pdev, "Failed to allocate vDPA structure");
|
||||||
|
return PTR_ERR(adapter);
|
||||||
|
}
|
||||||
|
|
||||||
adapter = ifcvf_mgmt_dev->adapter;
|
ifcvf_mgmt_dev->adapter = adapter;
|
||||||
vf = adapter->vf;
|
adapter->pdev = pdev;
|
||||||
pdev = adapter->pdev;
|
adapter->vdpa.dma_dev = &pdev->dev;
|
||||||
|
adapter->vdpa.mdev = mdev;
|
||||||
|
adapter->vf = vf;
|
||||||
vdpa_dev = &adapter->vdpa;
|
vdpa_dev = &adapter->vdpa;
|
||||||
|
|
||||||
if (name)
|
if (name)
|
||||||
@ -769,7 +777,6 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void ifcvf_vdpa_dev_del(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev)
|
static void ifcvf_vdpa_dev_del(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev)
|
||||||
{
|
{
|
||||||
struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev;
|
struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev;
|
||||||
@ -788,7 +795,6 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
|
|||||||
{
|
{
|
||||||
struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev;
|
struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev;
|
||||||
struct device *dev = &pdev->dev;
|
struct device *dev = &pdev->dev;
|
||||||
struct ifcvf_adapter *adapter;
|
|
||||||
struct ifcvf_hw *vf;
|
struct ifcvf_hw *vf;
|
||||||
u32 dev_type;
|
u32 dev_type;
|
||||||
int ret, i;
|
int ret, i;
|
||||||
@ -825,24 +831,10 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa,
|
|
||||||
dev, &ifc_vdpa_ops, 1, 1, NULL, false);
|
|
||||||
if (IS_ERR(adapter)) {
|
|
||||||
IFCVF_ERR(pdev, "Failed to allocate vDPA structure");
|
|
||||||
ret = PTR_ERR(adapter);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
adapter->pdev = pdev;
|
|
||||||
adapter->vdpa.dma_dev = &pdev->dev;
|
|
||||||
adapter->vdpa.mdev = &ifcvf_mgmt_dev->mdev;
|
|
||||||
ifcvf_mgmt_dev->adapter = adapter;
|
|
||||||
|
|
||||||
vf = &ifcvf_mgmt_dev->vf;
|
vf = &ifcvf_mgmt_dev->vf;
|
||||||
vf->dev_type = get_dev_type(pdev);
|
vf->dev_type = get_dev_type(pdev);
|
||||||
vf->base = pcim_iomap_table(pdev);
|
vf->base = pcim_iomap_table(pdev);
|
||||||
vf->pdev = pdev;
|
vf->pdev = pdev;
|
||||||
adapter->vf = vf;
|
|
||||||
|
|
||||||
ret = ifcvf_init_hw(vf, pdev);
|
ret = ifcvf_init_hw(vf, pdev);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
Loading…
Reference in New Issue
Block a user