diff mbox series

[V4,7/7] vDPA/ifcvf: deduce VIRTIO device ID from pdev ids

Message ID 20210315074501.15868-8-lingshan.zhu@intel.com
State New
Headers show
Series vDPA/ifcvf: enables Intel C5000X-PL virtio-net | expand

Commit Message

Zhu Lingshan March 15, 2021, 7:45 a.m. UTC
This commit checks the device ids from pdev, then deduce
VIRTIO device ID from the probed device.

Here we checks all four device ids than only subsystem_device_id,
help detecting a certain device for furture enabling.

Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com>
---
 drivers/vdpa/ifcvf/ifcvf_base.c | 42 +++++++++++++++++++++++++++++++++
 drivers/vdpa/ifcvf/ifcvf_base.h |  1 +
 drivers/vdpa/ifcvf/ifcvf_main.c |  8 ++++++-
 3 files changed, 50 insertions(+), 1 deletion(-)

Comments

Jason Wang March 17, 2021, 4:07 a.m. UTC | #1
在 2021/3/15 下午3:45, Zhu Lingshan 写道:
>   static u32 ifcvf_vdpa_get_device_id(struct vdpa_device *vdpa_dev)

>   {

> -	return VIRTIO_ID_NET;

> +	struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);

> +	u32 ret = -EOPNOTSUPP;

> +

> +	if (ifcvf_probed_virtio_net(vf))

> +		ret = VIRTIO_ID_NET;



So the point is to simplify the future extension.

How about simply?

if (device_id>0x1040)
     return devce_id - 0x1040;
else
     return device_id;

Since I don't think you plan to introduce device whose vendor id is not 
1AF4 and the subsys vendor/device id is not interesting to vDPA bus.

Thanks


> +

> +	return ret;

>   }
diff mbox series

Patch

diff --git a/drivers/vdpa/ifcvf/ifcvf_base.c b/drivers/vdpa/ifcvf/ifcvf_base.c
index 4f257c4b2f76..1a6ad7a11f16 100644
--- a/drivers/vdpa/ifcvf/ifcvf_base.c
+++ b/drivers/vdpa/ifcvf/ifcvf_base.c
@@ -408,3 +408,45 @@  void ifcvf_notify_queue(struct ifcvf_hw *hw, u16 qid)
 {
 	ifc_iowrite16(qid, hw->vring[qid].notify_addr);
 }
+
+static int ifcvf_probed_N3000(struct pci_dev *pdev)
+{
+	int ret = false;
+
+	if (pdev->device == N3000_DEVICE_ID &&
+	    pdev->vendor == N3000_VENDOR_ID &&
+	    pdev->subsystem_device == N3000_SUBSYS_DEVICE_ID &&
+	    pdev->subsystem_vendor == N3000_SUBSYS_VENDOR_ID)
+		ret = true;
+
+	return ret;
+}
+
+static int ifcvf_probed_C5000X_PL(struct pci_dev *pdev)
+{
+	int ret = false;
+
+	if (pdev->device == C5000X_PL_DEVICE_ID &&
+	    pdev->vendor == C5000X_PL_VENDOR_ID &&
+	    pdev->subsystem_device == C5000X_PL_SUBSYS_DEVICE_ID &&
+	    pdev->subsystem_vendor == C5000X_PL_SUBSYS_VENDOR_ID)
+		ret = true;
+
+	return ret;
+}
+
+int ifcvf_probed_virtio_net(struct ifcvf_hw *hw)
+{
+	struct ifcvf_adapter *adapter;
+	struct pci_dev *pdev;
+	int ret = false;
+
+	adapter = vf_to_adapter(hw);
+	pdev = adapter->pdev;
+
+	if (ifcvf_probed_N3000(pdev) ||
+	    ifcvf_probed_C5000X_PL(pdev))
+		ret = true;
+
+	return ret;
+}
diff --git a/drivers/vdpa/ifcvf/ifcvf_base.h b/drivers/vdpa/ifcvf/ifcvf_base.h
index f77239fc1644..b2eeb16b9c2c 100644
--- a/drivers/vdpa/ifcvf/ifcvf_base.h
+++ b/drivers/vdpa/ifcvf/ifcvf_base.h
@@ -127,4 +127,5 @@  int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features);
 u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);
 int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);
 struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw);
+int ifcvf_probed_virtio_net(struct ifcvf_hw *hw);
 #endif /* _IFCVF_H_ */
diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c
index ea93ea7fd5df..b0787f79dac3 100644
--- a/drivers/vdpa/ifcvf/ifcvf_main.c
+++ b/drivers/vdpa/ifcvf/ifcvf_main.c
@@ -323,7 +323,13 @@  static u32 ifcvf_vdpa_get_generation(struct vdpa_device *vdpa_dev)
 
 static u32 ifcvf_vdpa_get_device_id(struct vdpa_device *vdpa_dev)
 {
-	return VIRTIO_ID_NET;
+	struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
+	u32 ret = -EOPNOTSUPP;
+
+	if (ifcvf_probed_virtio_net(vf))
+		ret = VIRTIO_ID_NET;
+
+	return ret;
 }
 
 static u32 ifcvf_vdpa_get_vendor_id(struct vdpa_device *vdpa_dev)