Permalink
Browse files

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
  • Loading branch information...
1 parent 690bbda commit 92265d55beab9857b32e2ca43e24a96bc39039ef @jimharris jimharris committed Jul 24, 2013
Showing with 16 additions and 5 deletions.
  1. +1 −1 sbin/nvmecontrol/devlist.c
  2. +11 −1 sys/dev/nvme/nvme_ns.c
  3. +4 −3 sys/dev/nvme/nvme_ns_cmd.c
View
2 sbin/nvmecontrol/devlist.c
@@ -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
View
12 sys/dev/nvme/nvme_ns.c
@@ -155,7 +155,7 @@ nvme_ns_get_max_io_xfer_size(struct nvme_namespace *ns)
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 *ns, uint16_t id,
}
#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;
View
7 sys/dev/nvme/nvme_ns_cmd.c
@@ -36,7 +36,8 @@ nvme_ns_cmd_read(struct nvme_namespace *ns, void *payload, uint64_t lba,
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 *ns, void *payload, uint64_t lba,
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);

0 comments on commit 92265d5

Please sign in to comment.