public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Bin Meng <bmeng.cn@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 7/8] nvme: Handle zero Maximum Data Transfer Size (MDTS)
Date: Thu,  3 Aug 2017 02:31:02 -0700	[thread overview]
Message-ID: <1501752663-25088-8-git-send-email-bmeng.cn@gmail.com> (raw)
In-Reply-To: <1501752663-25088-1-git-send-email-bmeng.cn@gmail.com>

Maximum Data Transfer Size (MDTS) field indicates the maximum
data transfer size between the host and the controller. The
host should not submit a command that exceeds this transfer
size. The value is in units of the minimum memory page size
and is reported as a power of two (2^n).

The spec also says: a value of 0h indicates no restrictions
on transfer size. On the real NVMe card this is normally not
0 due to hardware restrictions, but with QEMU emulated NVMe
device it reports as 0. In nvme_blk_read/write() below we
have the following algorithm for maximum number of logic
blocks per transfer:

u16 lbas = 1 << (dev->max_transfer_shift - ns->lba_shift);

dev->max_transfer_shift being 0 will for sure cause lbas to
overflow. Let's use 20. With this fix, the NVMe driver works
on QEMU emulated NVMe device.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---

 drivers/nvme/nvme.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c
index bac253a..151fe92 100644
--- a/drivers/nvme/nvme.c
+++ b/drivers/nvme/nvme.c
@@ -563,6 +563,27 @@ static int nvme_get_info_from_identify(struct nvme_dev *dev)
 	memcpy(dev->firmware_rev, ctrl->fr, sizeof(ctrl->fr));
 	if (ctrl->mdts)
 		dev->max_transfer_shift = (ctrl->mdts + shift);
+	else {
+		/*
+		 * Maximum Data Transfer Size (MDTS) field indicates the maximum
+		 * data transfer size between the host and the controller. The
+		 * host should not submit a command that exceeds this transfer
+		 * size. The value is in units of the minimum memory page size
+		 * and is reported as a power of two (2^n).
+		 *
+		 * The spec also says: a value of 0h indicates no restrictions
+		 * on transfer size. But in nvme_blk_read/write() below we have
+		 * the following algorithm for maximum number of logic blocks
+		 * per transfer:
+		 *
+		 * u16 lbas = 1 << (dev->max_transfer_shift - ns->lba_shift);
+		 *
+		 * In order for lbas not to overflow, the maximum number is 15
+		 * which means dev->max_transfer_shift = 15 + 9 (ns->lba_shift).
+		 * Let's use 20 which provides 1MB size.
+		 */
+		dev->max_transfer_shift = 20;
+	}
 
 	/* Apply quirk stuff */
 	dm_pci_read_config16(dev->pdev, PCI_VENDOR_ID, &vendor);
-- 
2.9.2

  parent reply	other threads:[~2017-08-03  9:31 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-03  9:30 [U-Boot] [PATCH 0/8] nvme: Add NVM Express driver support Bin Meng
2017-08-03  9:30 ` [U-Boot] [PATCH 1/8] dm: blk: part: Add UCLASS_NVME and IF_TYPE_NVME Bin Meng
2017-08-10  1:30   ` Tom Rini
2017-08-14  0:07   ` [U-Boot] [U-Boot, " Tom Rini
2017-08-03  9:30 ` [U-Boot] [PATCH 2/8] nvme: Add NVM Express driver support Bin Meng
2017-08-10  1:30   ` Tom Rini
2017-08-14  0:07   ` [U-Boot] [U-Boot,2/8] " Tom Rini
2017-08-03  9:30 ` [U-Boot] [PATCH 3/8] nvme: Add show routine to print detailed information Bin Meng
2017-08-10  1:31   ` Tom Rini
2017-08-14  0:07   ` [U-Boot] [U-Boot, " Tom Rini
2017-08-03  9:30 ` [U-Boot] [PATCH 4/8] nvme: Add nvme commands Bin Meng
2017-08-10  1:31   ` Tom Rini
2017-08-14  0:08   ` [U-Boot] [U-Boot,4/8] " Tom Rini
2017-08-03  9:31 ` [U-Boot] [PATCH 5/8] nvme: Detect devices that are class Storage Express Bin Meng
2017-08-10  1:31   ` Tom Rini
2017-08-14  0:08   ` [U-Boot] [U-Boot, " Tom Rini
2017-08-03  9:31 ` [U-Boot] [PATCH 6/8] nvme: Fix number of blocks detection Bin Meng
2017-08-10  1:31   ` Tom Rini
2017-08-14  0:08   ` [U-Boot] [U-Boot,6/8] " Tom Rini
2017-08-03  9:31 ` Bin Meng [this message]
2017-08-10  1:31   ` [U-Boot] [PATCH 7/8] nvme: Handle zero Maximum Data Transfer Size (MDTS) Tom Rini
2017-08-14  0:08   ` [U-Boot] [U-Boot, " Tom Rini
2017-08-03  9:31 ` [U-Boot] [PATCH 8/8] x86: qemu: Enable NVMe driver Bin Meng
2017-08-10  1:31   ` Tom Rini
2017-08-14  0:08   ` [U-Boot] [U-Boot,8/8] " Tom Rini
2017-08-09 22:40 ` [U-Boot] [PATCH 0/8] nvme: Add NVM Express driver support Bin Meng
2017-08-10  1:31   ` Tom Rini
2017-08-10  1:49     ` Bin Meng
2017-08-10  1:56       ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1501752663-25088-8-git-send-email-bmeng.cn@gmail.com \
    --to=bmeng.cn@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox