[PATCH rdma-core] vmw_pvrdma: Check vendor and device ID on driver init

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Whenever a new RDMA device appears, the RDMA stack tries to attach each
driver to the new device to see which is the correct driver. We need to
check the vendor ID and device ID to make sure we don't accidentally
attach to another device.

Reviewed-by: Aditya Sarwade <asarwade@xxxxxxxxxx>
Signed-off-by: Bryan Tan <bryantan@xxxxxxxxxx>
Signed-off-by: Adit Ranadive <aditr@xxxxxxxxxx>
---
 providers/vmw_pvrdma/pvrdma_main.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/providers/vmw_pvrdma/pvrdma_main.c b/providers/vmw_pvrdma/pvrdma_main.c
index 9a7e07b..7190efa 100644
--- a/providers/vmw_pvrdma/pvrdma_main.c
+++ b/providers/vmw_pvrdma/pvrdma_main.c
@@ -45,6 +45,12 @@
 
 #include "pvrdma.h"
 
+/*
+ * VMware PVRDMA vendor id and PCI device id.
+ */
+#define PCI_VENDOR_ID_VMWARE		0x15AD
+#define PCI_DEVICE_ID_VMWARE_PVRDMA	0x0820
+
 static struct ibv_context_ops pvrdma_ctx_ops = {
 	.query_device = pvrdma_query_device,
 	.query_port = pvrdma_query_port,
@@ -166,7 +172,22 @@ static struct pvrdma_device *pvrdma_driver_init_shared(
 						int abi_version)
 {
 	struct pvrdma_device *dev;
-	char name[16];
+	char value[8];
+	unsigned int vendor_id, device_id;
+
+	if (ibv_read_sysfs_file(uverbs_sys_path, "device/vendor",
+				value, sizeof(value)) < 0)
+		return NULL;
+	vendor_id = strtol(value, NULL, 16);
+
+	if (ibv_read_sysfs_file(uverbs_sys_path, "device/device",
+				value, sizeof(value)) < 0)
+		return NULL;
+	device_id = strtol(value, NULL, 16);
+
+	if (vendor_id != PCI_VENDOR_ID_VMWARE ||
+	    device_id != PCI_DEVICE_ID_VMWARE_PVRDMA)
+		return NULL;
 
 	/* We support only a single ABI version for now. */
 	if (abi_version != PVRDMA_UVERBS_ABI_VERSION) {
@@ -177,12 +198,6 @@ static struct pvrdma_device *pvrdma_driver_init_shared(
 		return NULL;
 	}
 
-	if (ibv_read_sysfs_file(uverbs_sys_path,
-				"ibdev", name, sizeof(name)) < 0) {
-		fprintf(stderr, PFX "not ib device\n");
-		return NULL;
-	}
-
 	dev = malloc(sizeof(*dev));
 	if (!dev) {
 		fprintf(stderr, PFX "couldn't allocate device for %s\n",
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux