svn commit: r253630 - in stable/9: sbin/nvmecontrol sys/dev/nvme

Jim Harris jimharris at FreeBSD.org
Wed Jul 24 22:46:28 UTC 2013


Author: jimharris
Date: Wed Jul 24 22:46:27 2013
New Revision: 253630
URL: http://svnweb.freebsd.org/changeset/base/253630

Log:
  MFC r253474:
  
    Fix nvme(4) and nvd(4) to support non 512-byte sector sizes.
  
    Recent testing with QEMU that has variable sector size support for
    NVMe uncovered some of these issues.  Chatham prototype boards supported
    only 512 byte sectors.
  
  Approved by:	re (kib)
  Sponsored by:	Intel

Modified:
  stable/9/sbin/nvmecontrol/devlist.c
  stable/9/sys/dev/nvme/nvme_ns.c
  stable/9/sys/dev/nvme/nvme_ns_cmd.c
Directory Properties:
  stable/9/sbin/nvmecontrol/   (props changed)
  stable/9/sys/   (props changed)
  stable/9/sys/dev/   (props changed)

Modified: stable/9/sbin/nvmecontrol/devlist.c
==============================================================================
--- stable/9/sbin/nvmecontrol/devlist.c	Wed Jul 24 22:44:46 2013	(r253629)
+++ stable/9/sbin/nvmecontrol/devlist.c	Wed Jul 24 22:46:27 2013	(r253630)
@@ -53,7 +53,7 @@ static inline uint32_t
 ns_get_sector_size(struct nvme_namespace_data *nsdata)
 {
 
-	return (1 << nsdata->lbaf[0].lbads);
+	return (1 << nsdata->lbaf[nsdata->flbas.format].lbads);
 }
 
 void

Modified: stable/9/sys/dev/nvme/nvme_ns.c
==============================================================================
--- stable/9/sys/dev/nvme/nvme_ns.c	Wed Jul 24 22:44:46 2013	(r253629)
+++ stable/9/sys/dev/nvme/nvme_ns.c	Wed Jul 24 22:46:27 2013	(r253630)
@@ -155,7 +155,7 @@ nvme_ns_get_max_io_xfer_size(struct nvme
 uint32_t
 nvme_ns_get_sector_size(struct nvme_namespace *ns)
 {
-	return (1 << ns->data.lbaf[0].lbads);
+	return (1 << ns->data.lbaf[ns->data.flbas.format].lbads);
 }
 
 uint64_t
@@ -310,6 +310,16 @@ nvme_ns_construct(struct nvme_namespace 
 	}
 #endif
 
+	/*
+	 * Note: format is a 0-based value, so > is appropriate here,
+	 *  not >=.
+	 */
+	if (ns->data.flbas.format > ns->data.nlbaf) {
+		printf("lba format %d exceeds number supported (%d)\n",
+		    ns->data.flbas.format, ns->data.nlbaf+1);
+		return (1);
+	}
+
 	if (ctrlr->cdata.oncs.dsm)
 		ns->flags |= NVME_NS_DEALLOCATE_SUPPORTED;
 

Modified: stable/9/sys/dev/nvme/nvme_ns_cmd.c
==============================================================================
--- stable/9/sys/dev/nvme/nvme_ns_cmd.c	Wed Jul 24 22:44:46 2013	(r253629)
+++ stable/9/sys/dev/nvme/nvme_ns_cmd.c	Wed Jul 24 22:46:27 2013	(r253630)
@@ -36,7 +36,8 @@ nvme_ns_cmd_read(struct nvme_namespace *
 	struct nvme_request	*req;
 	struct nvme_command	*cmd;
 
-	req = nvme_allocate_request_vaddr(payload, lba_count*512, cb_fn, cb_arg);
+	req = nvme_allocate_request_vaddr(payload,
+	    lba_count*nvme_ns_get_sector_size(ns), cb_fn, cb_arg);
 
 	if (req == NULL)
 		return (ENOMEM);
@@ -89,8 +90,8 @@ nvme_ns_cmd_write(struct nvme_namespace 
 	struct nvme_request	*req;
 	struct nvme_command	*cmd;
 
-	req = nvme_allocate_request_vaddr(payload, lba_count*512, cb_fn,
-	    cb_arg);
+	req = nvme_allocate_request_vaddr(payload,
+	    lba_count*nvme_ns_get_sector_size(ns), cb_fn, cb_arg);
 
 	if (req == NULL)
 		return (ENOMEM);


More information about the svn-src-stable mailing list