[Lkw] [PATCH] nvme-cmb: Path 9! :)

felipx felipemonterobruni at unc.edu.ar
Fri Sep 15 18:21:30 EDT 2023


Kind of working nvme driver.

Signed-off-by: Your Name <felipemonterobruni at unc.edu.ar>
---
 drivers/block/nvme-cmb.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/block/nvme-cmb.c b/drivers/block/nvme-cmb.c
index 5f1fe1549..2bd91c648 100644
--- a/drivers/block/nvme-cmb.c
+++ b/drivers/block/nvme-cmb.c
@@ -26,7 +26,23 @@ struct nvme_cmb_dev {
 
 static void nvme_cmb_submit_bio(struct bio *bio)
 {
-	bio_io_error(bio);
+	struct nvme_cmb_dev *dev = bio->bi_bdev->bd_disk->private_data;
+	void __iomem *buffer = dev->buffer_bar + dev->buffer_offset;
+	struct bvec_iter iter;
+	struct bio_vec bv;
+
+	bio_for_each_segment(bv, bio, iter) {
+		void __iomem *dev_addr = buffer +
+		    (iter.bi_sector << SECTOR_SHIFT);
+		void *kaddr = bvec_virt(&bv);
+
+		if (bio_op(bio) == REQ_OP_READ)
+			memcpy_fromio(kaddr, dev_addr, bv.bv_len);
+		else
+			memcpy_toio(dev_addr, kaddr, bv.bv_len);
+	}
+
+	bio_endio(bio);
 }
 
 static const struct block_device_operations nvme_cmb_ops = {
@@ -112,8 +128,7 @@ static int nvme_cmb_map_buffer(struct nvme_cmb_dev *dev, struct pci_dev *pdev)
 		return -ENOMEM;
 
 	dev->buffer_offset = unit * NVME_CMB_OFST(cmbloc);
-	dev->buffer_size =
-	    unit * ((cmbsz >> NVME_CMBSZ_SZ_SHIFT) & NVME_CMBSZ_SZ_MASK);
+	dev->buffer_size = unit * ((cmbsz >> NVME_CMBSZ_SZ_SHIFT) & NVME_CMBSZ_SZ_MASK);
 	return 0;
 }
 
@@ -237,4 +252,4 @@ static void __exit nvme_cmb_exit(void)
 }
 
 module_init(nvme_cmb_init);
-module_exit(nvme_cmb_exit);
+module_exit(nvme_cmb_exit);
\ No newline at end of file
-- 
2.39.2




More information about the LKW mailing list