Skip to contentSkip to conversation

NVMe: Add translation for block limits

PATCH RESEND Superseded Keith Busch 2 participants 4 messages Apr 7, 2015 – Apr 9, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 NVMe: Add translation for block limits

Adds SCSI-to-NVMe translation for VPD B0h, block limits inquiry data.

Signed-off-by Keith Busch <keith.busch at intel.com>
---
 drivers/block/nvme-scsi.c |   28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/block/nvme-scsi.c +27 -1
index e10196e..6b736b0 100644
@@ -55,6 +55,7 @@ static int sg_version_num = 30534;	/* 2 digits for each component */
 #define VPD_SERIAL_NUMBER				0x80
 #define VPD_DEVICE_IDENTIFIERS				0x83
 #define VPD_EXTENDED_INQUIRY				0x86
+#define VPD_BLOCK_LIMITS				0xB0
 #define VPD_BLOCK_DEV_CHARACTERISTICS			0xB1
 
 /* CDB offsets */
@@ -132,9 +133,10 @@ static int sg_version_num = 30534;	/* 2 digits for each component */
 #define INQ_UNIT_SERIAL_NUMBER_PAGE			0x80
 #define INQ_DEVICE_IDENTIFICATION_PAGE			0x83
 #define INQ_EXTENDED_INQUIRY_DATA_PAGE			0x86
+#define INQ_BDEV_LIMITS_PAGE				0xB0
 #define INQ_BDEV_CHARACTERISTICS_PAGE			0xB1
 #define INQ_SERIAL_NUMBER_LENGTH			0x14
-#define INQ_NUM_SUPPORTED_VPD_PAGES			5
+#define INQ_NUM_SUPPORTED_VPD_PAGES			6
 #define VERSION_SPC_4					0x06
 #define ACA_UNSUPPORTED					0
 #define STANDARD_INQUIRY_LENGTH				36
@@ -747,6 +749,7 @@ static int nvme_trans_supported_vpd_pages(struct nvme_ns *ns,
 	inq_response[6] = INQ_DEVICE_IDENTIFICATION_PAGE;
 	inq_response[7] = INQ_EXTENDED_INQUIRY_DATA_PAGE;
 	inq_response[8] = INQ_BDEV_CHARACTERISTICS_PAGE;
+	inq_response[9] = INQ_BDEV_LIMITS_PAGE;
 
 	xfer_len = min(alloc_len, STANDARD_INQUIRY_LENGTH);
 	res = nvme_trans_copy_to_user(hdr, inq_response, xfer_len);
@@ -938,6 +941,25 @@ static int nvme_trans_ext_inq_page(struct nvme_ns *ns, struct sg_io_hdr *hdr,
 	return res;
 }
 
+static int nvme_trans_bdev_limits_page(struct nvme_ns *ns, struct sg_io_hdr *hdr,
+					u8 *inq_response, int alloc_len)
+{
+	__be32 max_sectors = cpu_to_be32(queue_max_hw_sectors(ns->queue));
+	__be32 max_discard = cpu_to_be32(ns->queue->limits.max_discard_sectors);
+	__be32 discard_desc_count = cpu_to_be32(0x100);
+
+	memset(inq_response, 0, STANDARD_INQUIRY_LENGTH);
+	inq_response[1] = VPD_BLOCK_LIMITS;
+	inq_response[3] = 0x3c; /* Page Length */
+	memcpy(&inq_response[8], &max_sectors, sizeof(u32));
+	memcpy(&inq_response[20], &max_discard, sizeof(u32));
+
+	if (max_discard)
+		memcpy(&inq_response[24], &discard_desc_count, sizeof(u32));
+
+	return nvme_trans_copy_to_user(hdr, inq_response, 0x3c);
+}
+
 static int nvme_trans_bdev_char_page(struct nvme_ns *ns, struct sg_io_hdr *hdr,
 					int alloc_len)
 {
@@ -2268,6 +2290,10 @@ static int nvme_trans_inquiry(struct nvme_ns *ns, struct sg_io_hdr *hdr,
 		case VPD_EXTENDED_INQUIRY:
 			res = nvme_trans_ext_inq_page(ns, hdr, alloc_len);
 			break;
+		case VPD_BLOCK_LIMITS:
+			res = nvme_trans_bdev_limits_page(ns, hdr, inq_response,
+								alloc_len);
+			break;
 		case VPD_BLOCK_DEV_CHARACTERISTICS:
 			res = nvme_trans_bdev_char_page(ns, hdr, alloc_len);
 			break;
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH RESEND 1/1 NVMe: Add translation for block limits

Keith,

+static int nvme_trans_bdev_limits_page(struct nvme_ns *ns, struct sg_io_hdr *hdr,
+ u8 *inq_response, int alloc_len)
+{
+ __be32 max_sectors = cpu_to_be32(queue_max_hw_sectors(ns->queue));

max_hw_sectors is in 512-byte units, the VPD page in logical blocks.

+ __be32 max_discard = cpu_to_be32(ns->queue->limits.max_discard_sectors);

Same.

+ __be32 discard_desc_count = cpu_to_be32(0x100);

max_discard_sectors is the maximum number of 512-byte contiguous blocks that can be discarded in a single command using however many range descriptors will fit in the command's payload.

So max_discard_sectors for an NVMe device would technically be:

256 * 0xffffffff << (ilog2(ns block size) - 9)

You only report 0xffffffff going the other way so it is not a big deal. Just wanted to make it clear since you're converting a value from Linux' block limit to NVMe/SCSI.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#2 lore raw

PATCH RESEND 1/1 NVMe: Add translation for block limits

Quoted 6 lines · Martin K. Petersen
drivers/block/nvme-scsi.c +4 -0
+static int nvme_trans_bdev_limits_page(struct nvme_ns *ns, struct sg_io_hdr *hdr,
+					u8 *inq_response, int alloc_len)
+{
+	__be32 max_sectors = cpu_to_be32(queue_max_hw_sectors(ns->queue));

max_hw_sectors is in 512-byte units, the VPD page in logical blocks.

Yes, this one is screwed up. For shame, I'm quick to point out the same mistake in other patches.

Quoted 10 lines
drivers/block/nvme-scsi.c +1 -0
+	__be32 max_discard = cpu_to_be32(ns->queue->limits.max_discard_sectors);

Same.

drivers/block/nvme-scsi.c +1 -0
+	__be32 discard_desc_count = cpu_to_be32(0x100);

max_discard_sectors is the maximum number of 512-byte contiguous blocks that can be discarded in a single command using however many range descriptors will fit in the command's payload.

Quoted 7 lines

So max_discard_sectors for an NVMe device would technically be:

256 * 0xffffffff << (ilog2(ns block size) - 9)

You only report 0xffffffff going the other way so it is not a big deal. Just wanted to make it clear since you're converting a value from Linux' block limit to NVMe/SCSI.

This I'm not sure about. There is no max discard size in NVMe, so any non-zero value is valid, so the largest possible number is still valid regardless of physical block size.

The 256 max descriptors is straight from the "spec" (if you can call it that), but convienent because it fits in a 4k page.

#3 lore raw

PATCH RESEND 1/1 NVMe: Add translation for block limits

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Keith" == Keith Busch <keith.busch at intel.com> writes:

Keith> The 256 max descriptors is straight from the "spec" (if you can Keith> call it that), but convienent because it fits in a 4k page.

Yep.

It doesn't really matter since we're not keying off of the SCSI translated values for NVMe devices. So I'm perfectly happy with you reporting 0xffffffff as max_discard_sectors to the block layer.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering