diff mbox series

[RFC,16/16] nvme: Support atomic writes

Message ID 20230503183821.1473305-17-john.g.garry@oracle.com (mailing list archive)
State Handled Elsewhere
Headers show
Series block atomic writes | expand

Commit Message

John Garry May 3, 2023, 6:38 p.m. UTC
From: Alan Adamson <alan.adamson@oracle.com>

Support reading atomic write registers to fill in request_queue
properties.

Use following method to calculate limits:
atomic_write_max_bytes = flp2(NAWUPF ?: AWUPF)
atomic_write_unit_min = logical_block_size
atomic_write_unit_max = flp2(NAWUPF ?: AWUPF)
atomic_write_boundary = NABSPF

Signed-off-by: Alan Adamson <alan.adamson@oracle.com>
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/nvme/host/core.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Comments

Bart Van Assche May 3, 2023, 6:49 p.m. UTC | #1
On 5/3/23 11:38, John Garry wrote:
> +			if (!(boundary & (boundary - 1))) {

Please use is_power_of_2() instead of open-coding it.

Thanks,

Bart.
John Garry May 4, 2023, 8:19 a.m. UTC | #2
On 03/05/2023 19:49, Bart Van Assche wrote:
> On 5/3/23 11:38, John Garry wrote:
>> +            if (!(boundary & (boundary - 1))) {
> 
> Please use is_power_of_2() instead of open-coding it.

Sure, that can be changed, thanks
diff mbox series

Patch

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index d6a9bac91a4c..289561915ad3 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1879,6 +1879,39 @@  static void nvme_update_disk_info(struct gendisk *disk,
 	blk_queue_io_min(disk->queue, phys_bs);
 	blk_queue_io_opt(disk->queue, io_opt);
 
+	atomic_bs = rounddown_pow_of_two(atomic_bs);
+	if (id->nsfeat & NVME_NS_FEAT_ATOMICS && id->nawupf) {
+		if (id->nabo) {
+			dev_err(ns->ctrl->device, "Support atomic NABO=%x\n",
+				id->nabo);
+		} else {
+			u32 boundary = 0;
+
+			if (le16_to_cpu(id->nabspf))
+				boundary = (le16_to_cpu(id->nabspf) + 1) * bs;
+
+			if (!(boundary & (boundary - 1))) {
+				blk_queue_atomic_write_max_bytes(disk->queue,
+							atomic_bs);
+				blk_queue_atomic_write_unit_min(disk->queue, 1);
+				blk_queue_atomic_write_unit_max(disk->queue,
+					atomic_bs / bs);
+				blk_queue_atomic_write_boundary(disk->queue,
+								boundary);
+			} else {
+				dev_err(ns->ctrl->device, "Unsupported atomic boundary=0x%x\n",
+					boundary);
+			}
+		}
+	} else if (ns->ctrl->subsys->awupf) {
+		blk_queue_atomic_write_max_bytes(disk->queue,
+				atomic_bs);
+		blk_queue_atomic_write_unit_min(disk->queue, 1);
+		blk_queue_atomic_write_unit_max(disk->queue,
+				atomic_bs / bs);
+		blk_queue_atomic_write_boundary(disk->queue, 0);
+	}
+
 	/*
 	 * Register a metadata profile for PI, or the plain non-integrity NVMe
 	 * metadata masquerading as Type 0 if supported, otherwise reject block