diff mbox series

[v3,virtio,4/8] pds_vdpa: virtio bar setup for vdpa

Message ID 20230322191038.44037-5-shannon.nelson@amd.com (mailing list archive)
State Not Applicable
Headers show
Series pds_vdpa driver | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Nelson, Shannon March 22, 2023, 7:10 p.m. UTC
Prep and use the "modern" virtio bar utilities to get our
virtio config space ready.

Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
---
 drivers/vdpa/pds/aux_drv.c | 25 +++++++++++++++++++++++++
 drivers/vdpa/pds/aux_drv.h |  3 +++
 2 files changed, 28 insertions(+)

Comments

Jason Wang March 23, 2023, 5:11 a.m. UTC | #1
On Thu, Mar 23, 2023 at 3:11 AM Shannon Nelson <shannon.nelson@amd.com> wrote:
>
> Prep and use the "modern" virtio bar utilities to get our
> virtio config space ready.
>
> Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
> ---
>  drivers/vdpa/pds/aux_drv.c | 25 +++++++++++++++++++++++++
>  drivers/vdpa/pds/aux_drv.h |  3 +++
>  2 files changed, 28 insertions(+)
>
> diff --git a/drivers/vdpa/pds/aux_drv.c b/drivers/vdpa/pds/aux_drv.c
> index 881acd869a9d..8f3ae3326885 100644
> --- a/drivers/vdpa/pds/aux_drv.c
> +++ b/drivers/vdpa/pds/aux_drv.c
> @@ -4,6 +4,7 @@
>  #include <linux/auxiliary_bus.h>
>  #include <linux/pci.h>
>  #include <linux/vdpa.h>
> +#include <linux/virtio_pci_modern.h>
>
>  #include <linux/pds/pds_common.h>
>  #include <linux/pds/pds_core_if.h>
> @@ -20,12 +21,22 @@ static const struct auxiliary_device_id pds_vdpa_id_table[] = {
>         {},
>  };
>
> +static int pds_vdpa_device_id_check(struct pci_dev *pdev)
> +{
> +       if (pdev->device != PCI_DEVICE_ID_PENSANDO_VDPA_VF ||
> +           pdev->vendor != PCI_VENDOR_ID_PENSANDO)
> +               return -ENODEV;

Similar to patch 1, if we don't need to override we probably can
rename the device_id_check_override to device_id_check(). Otherwise
it's better to let this function to return device id.

Thanks

> +
> +       return 0;
> +}
> +
>  static int pds_vdpa_probe(struct auxiliary_device *aux_dev,
>                           const struct auxiliary_device_id *id)
>
>  {
>         struct pds_auxiliary_dev *padev =
>                 container_of(aux_dev, struct pds_auxiliary_dev, aux_dev);
> +       struct device *dev = &aux_dev->dev;
>         struct pds_vdpa_aux *vdpa_aux;
>         int err;
>
> @@ -42,8 +53,21 @@ static int pds_vdpa_probe(struct auxiliary_device *aux_dev,
>         if (err)
>                 goto err_free_mem;
>
> +       /* Find the virtio configuration */
> +       vdpa_aux->vd_mdev.pci_dev = padev->vf_pdev;
> +       vdpa_aux->vd_mdev.device_id_check_override = pds_vdpa_device_id_check;
> +       vdpa_aux->vd_mdev.dma_mask_override = DMA_BIT_MASK(PDS_CORE_ADDR_LEN);
> +       err = vp_modern_probe(&vdpa_aux->vd_mdev);
> +       if (err) {
> +               dev_err(dev, "Unable to probe for virtio configuration: %pe\n",
> +                       ERR_PTR(err));
> +               goto err_free_mgmt_info;
> +       }
> +
>         return 0;
>
> +err_free_mgmt_info:
> +       pci_free_irq_vectors(padev->vf_pdev);
>  err_free_mem:
>         kfree(vdpa_aux);
>         auxiliary_set_drvdata(aux_dev, NULL);
> @@ -56,6 +80,7 @@ static void pds_vdpa_remove(struct auxiliary_device *aux_dev)
>         struct pds_vdpa_aux *vdpa_aux = auxiliary_get_drvdata(aux_dev);
>         struct device *dev = &aux_dev->dev;
>
> +       vp_modern_remove(&vdpa_aux->vd_mdev);
>         pci_free_irq_vectors(vdpa_aux->padev->vf_pdev);
>
>         kfree(vdpa_aux);
> diff --git a/drivers/vdpa/pds/aux_drv.h b/drivers/vdpa/pds/aux_drv.h
> index 94ba7abcaa43..8f5140401573 100644
> --- a/drivers/vdpa/pds/aux_drv.h
> +++ b/drivers/vdpa/pds/aux_drv.h
> @@ -4,6 +4,8 @@
>  #ifndef _AUX_DRV_H_
>  #define _AUX_DRV_H_
>
> +#include <linux/virtio_pci_modern.h>
> +
>  #define PDS_VDPA_DRV_DESCRIPTION    "AMD/Pensando vDPA VF Device Driver"
>  #define PDS_VDPA_DRV_NAME           "pds_vdpa"
>
> @@ -16,6 +18,7 @@ struct pds_vdpa_aux {
>
>         int vf_id;
>         struct dentry *dentry;
> +       struct virtio_pci_modern_device vd_mdev;
>
>         int nintrs;
>  };
> --
> 2.17.1
>
Nelson, Shannon March 25, 2023, 12:26 a.m. UTC | #2
On 3/22/23 10:11 PM, Jason Wang wrote:
> On Thu, Mar 23, 2023 at 3:11 AM Shannon Nelson <shannon.nelson@amd.com> wrote:
>>
>> Prep and use the "modern" virtio bar utilities to get our
>> virtio config space ready.
>>
>> Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
>> ---
>>   drivers/vdpa/pds/aux_drv.c | 25 +++++++++++++++++++++++++
>>   drivers/vdpa/pds/aux_drv.h |  3 +++
>>   2 files changed, 28 insertions(+)
>>
>> diff --git a/drivers/vdpa/pds/aux_drv.c b/drivers/vdpa/pds/aux_drv.c
>> index 881acd869a9d..8f3ae3326885 100644
>> --- a/drivers/vdpa/pds/aux_drv.c
>> +++ b/drivers/vdpa/pds/aux_drv.c
>> @@ -4,6 +4,7 @@
>>   #include <linux/auxiliary_bus.h>
>>   #include <linux/pci.h>
>>   #include <linux/vdpa.h>
>> +#include <linux/virtio_pci_modern.h>
>>
>>   #include <linux/pds/pds_common.h>
>>   #include <linux/pds/pds_core_if.h>
>> @@ -20,12 +21,22 @@ static const struct auxiliary_device_id pds_vdpa_id_table[] = {
>>          {},
>>   };
>>
>> +static int pds_vdpa_device_id_check(struct pci_dev *pdev)
>> +{
>> +       if (pdev->device != PCI_DEVICE_ID_PENSANDO_VDPA_VF ||
>> +           pdev->vendor != PCI_VENDOR_ID_PENSANDO)
>> +               return -ENODEV;
> 
> Similar to patch 1, if we don't need to override we probably can
> rename the device_id_check_override to device_id_check(). Otherwise
> it's better to let this function to return device id.

Sure, I'll tweak this.
sln


> 
> Thanks
> 
>> +
>> +       return 0;
>> +}
>> +
>>   static int pds_vdpa_probe(struct auxiliary_device *aux_dev,
>>                            const struct auxiliary_device_id *id)
>>
>>   {
>>          struct pds_auxiliary_dev *padev =
>>                  container_of(aux_dev, struct pds_auxiliary_dev, aux_dev);
>> +       struct device *dev = &aux_dev->dev;
>>          struct pds_vdpa_aux *vdpa_aux;
>>          int err;
>>
>> @@ -42,8 +53,21 @@ static int pds_vdpa_probe(struct auxiliary_device *aux_dev,
>>          if (err)
>>                  goto err_free_mem;
>>
>> +       /* Find the virtio configuration */
>> +       vdpa_aux->vd_mdev.pci_dev = padev->vf_pdev;
>> +       vdpa_aux->vd_mdev.device_id_check_override = pds_vdpa_device_id_check;
>> +       vdpa_aux->vd_mdev.dma_mask_override = DMA_BIT_MASK(PDS_CORE_ADDR_LEN);
>> +       err = vp_modern_probe(&vdpa_aux->vd_mdev);
>> +       if (err) {
>> +               dev_err(dev, "Unable to probe for virtio configuration: %pe\n",
>> +                       ERR_PTR(err));
>> +               goto err_free_mgmt_info;
>> +       }
>> +
>>          return 0;
>>
>> +err_free_mgmt_info:
>> +       pci_free_irq_vectors(padev->vf_pdev);
>>   err_free_mem:
>>          kfree(vdpa_aux);
>>          auxiliary_set_drvdata(aux_dev, NULL);
>> @@ -56,6 +80,7 @@ static void pds_vdpa_remove(struct auxiliary_device *aux_dev)
>>          struct pds_vdpa_aux *vdpa_aux = auxiliary_get_drvdata(aux_dev);
>>          struct device *dev = &aux_dev->dev;
>>
>> +       vp_modern_remove(&vdpa_aux->vd_mdev);
>>          pci_free_irq_vectors(vdpa_aux->padev->vf_pdev);
>>
>>          kfree(vdpa_aux);
>> diff --git a/drivers/vdpa/pds/aux_drv.h b/drivers/vdpa/pds/aux_drv.h
>> index 94ba7abcaa43..8f5140401573 100644
>> --- a/drivers/vdpa/pds/aux_drv.h
>> +++ b/drivers/vdpa/pds/aux_drv.h
>> @@ -4,6 +4,8 @@
>>   #ifndef _AUX_DRV_H_
>>   #define _AUX_DRV_H_
>>
>> +#include <linux/virtio_pci_modern.h>
>> +
>>   #define PDS_VDPA_DRV_DESCRIPTION    "AMD/Pensando vDPA VF Device Driver"
>>   #define PDS_VDPA_DRV_NAME           "pds_vdpa"
>>
>> @@ -16,6 +18,7 @@ struct pds_vdpa_aux {
>>
>>          int vf_id;
>>          struct dentry *dentry;
>> +       struct virtio_pci_modern_device vd_mdev;
>>
>>          int nintrs;
>>   };
>> --
>> 2.17.1
>>
>
diff mbox series

Patch

diff --git a/drivers/vdpa/pds/aux_drv.c b/drivers/vdpa/pds/aux_drv.c
index 881acd869a9d..8f3ae3326885 100644
--- a/drivers/vdpa/pds/aux_drv.c
+++ b/drivers/vdpa/pds/aux_drv.c
@@ -4,6 +4,7 @@ 
 #include <linux/auxiliary_bus.h>
 #include <linux/pci.h>
 #include <linux/vdpa.h>
+#include <linux/virtio_pci_modern.h>
 
 #include <linux/pds/pds_common.h>
 #include <linux/pds/pds_core_if.h>
@@ -20,12 +21,22 @@  static const struct auxiliary_device_id pds_vdpa_id_table[] = {
 	{},
 };
 
+static int pds_vdpa_device_id_check(struct pci_dev *pdev)
+{
+	if (pdev->device != PCI_DEVICE_ID_PENSANDO_VDPA_VF ||
+	    pdev->vendor != PCI_VENDOR_ID_PENSANDO)
+		return -ENODEV;
+
+	return 0;
+}
+
 static int pds_vdpa_probe(struct auxiliary_device *aux_dev,
 			  const struct auxiliary_device_id *id)
 
 {
 	struct pds_auxiliary_dev *padev =
 		container_of(aux_dev, struct pds_auxiliary_dev, aux_dev);
+	struct device *dev = &aux_dev->dev;
 	struct pds_vdpa_aux *vdpa_aux;
 	int err;
 
@@ -42,8 +53,21 @@  static int pds_vdpa_probe(struct auxiliary_device *aux_dev,
 	if (err)
 		goto err_free_mem;
 
+	/* Find the virtio configuration */
+	vdpa_aux->vd_mdev.pci_dev = padev->vf_pdev;
+	vdpa_aux->vd_mdev.device_id_check_override = pds_vdpa_device_id_check;
+	vdpa_aux->vd_mdev.dma_mask_override = DMA_BIT_MASK(PDS_CORE_ADDR_LEN);
+	err = vp_modern_probe(&vdpa_aux->vd_mdev);
+	if (err) {
+		dev_err(dev, "Unable to probe for virtio configuration: %pe\n",
+			ERR_PTR(err));
+		goto err_free_mgmt_info;
+	}
+
 	return 0;
 
+err_free_mgmt_info:
+	pci_free_irq_vectors(padev->vf_pdev);
 err_free_mem:
 	kfree(vdpa_aux);
 	auxiliary_set_drvdata(aux_dev, NULL);
@@ -56,6 +80,7 @@  static void pds_vdpa_remove(struct auxiliary_device *aux_dev)
 	struct pds_vdpa_aux *vdpa_aux = auxiliary_get_drvdata(aux_dev);
 	struct device *dev = &aux_dev->dev;
 
+	vp_modern_remove(&vdpa_aux->vd_mdev);
 	pci_free_irq_vectors(vdpa_aux->padev->vf_pdev);
 
 	kfree(vdpa_aux);
diff --git a/drivers/vdpa/pds/aux_drv.h b/drivers/vdpa/pds/aux_drv.h
index 94ba7abcaa43..8f5140401573 100644
--- a/drivers/vdpa/pds/aux_drv.h
+++ b/drivers/vdpa/pds/aux_drv.h
@@ -4,6 +4,8 @@ 
 #ifndef _AUX_DRV_H_
 #define _AUX_DRV_H_
 
+#include <linux/virtio_pci_modern.h>
+
 #define PDS_VDPA_DRV_DESCRIPTION    "AMD/Pensando vDPA VF Device Driver"
 #define PDS_VDPA_DRV_NAME           "pds_vdpa"
 
@@ -16,6 +18,7 @@  struct pds_vdpa_aux {
 
 	int vf_id;
 	struct dentry *dentry;
+	struct virtio_pci_modern_device vd_mdev;
 
 	int nintrs;
 };