[Lkw] [PATCH 05/10] nvme-cmb: Patch #4, Interfacing with hardware

Damian Gonzalez damian.gonzalez at mi.unc.edu.ar
Fri Sep 15 18:32:52 EDT 2023


Signed-off-by: Damian Gonzalez <damian.gonzalez at mi.unc.edu.ar>
---
 drivers/block/nvme-cmb.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/block/nvme-cmb.c b/drivers/block/nvme-cmb.c
index 381b98510..3e600e82c 100644
--- a/drivers/block/nvme-cmb.c
+++ b/drivers/block/nvme-cmb.c
@@ -2,10 +2,12 @@
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
+#include <linux/nvme.h>
 
 MODULE_LICENSE("GPL");
 
 struct nvme_cmb_dev {
+    void __iomem *bar;
 };
 
 static int nvme_cmb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
@@ -27,9 +29,23 @@ static int nvme_cmb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (error)
 		goto out_disable_device;
 
+	dev->bar = pci_ioremap_bar(pdev, 0);
+	if (!dev->bar) {
+		error = -ENOMEM;
+		goto out_release_regions;
+	}
+
+	if (readl(dev->bar + NVME_REG_CSTS) == ~0) {
+		error = -EIO;
+		goto out_iounmap;
+	}
     dev_set_drvdata(&pdev->dev, dev);
 	return 0;
 
+out_iounmap:
+	iounmap(dev->bar);
+out_release_regions:
+	pci_release_mem_regions(pdev);
 out_disable_device:
 	pci_disable_device(pdev);
 out_free_dev:
@@ -43,6 +59,7 @@ static void nvme_cmb_remove(struct pci_dev *pdev)
 
 	dev_info(&pdev->dev, "unbinding NVMe device\n");
 
+    iounmap(dev->bar);
 	pci_release_mem_regions(pdev);
 	pci_disable_device(pdev);
     kfree(dev);
-- 
2.39.2




More information about the LKW mailing list