Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Aug 2018 04:56:37 +0000 (UTC)
From:      Marcelo Araujo <araujo@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r338089 - head/usr.sbin/bhyve
Message-ID:  <201808200456.w7K4ubkR004360@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: araujo
Date: Mon Aug 20 04:56:37 2018
New Revision: 338089
URL: https://svnweb.freebsd.org/changeset/base/338089

Log:
  NVMe spec version 1.3c says that "serial number" field must be 7-bit ASCII,
  with unused bytes padded by space characters. Same for firmware number and
  namespace number.
  
  Discussed with:	imp@
  Sponsored by:	iXsystems Inc.

Modified:
  head/usr.sbin/bhyve/pci_nvme.c

Modified: head/usr.sbin/bhyve/pci_nvme.c
==============================================================================
--- head/usr.sbin/bhyve/pci_nvme.c	Mon Aug 20 04:50:11 2018	(r338088)
+++ head/usr.sbin/bhyve/pci_nvme.c	Mon Aug 20 04:56:37 2018	(r338089)
@@ -254,6 +254,14 @@ static void pci_nvme_io_partial(struct blockif_req *br
 	 (NVME_STATUS_SC_MASK << NVME_STATUS_SC_SHIFT))
 
 static __inline void
+cpywithpad(char *dst, int dst_size, const char *src, char pad)
+{
+	int len = strnlen(src, dst_size);
+	memcpy(dst, src, len);
+	memset(dst + len, pad, dst_size - len);
+}
+
+static __inline void
 pci_nvme_status_tc(uint16_t *status, uint16_t type, uint16_t code)
 {
 
@@ -287,21 +295,9 @@ pci_nvme_init_ctrldata(struct pci_nvme_softc *sc)
 	cd->vid = 0xFB5D;
 	cd->ssvid = 0x0000;
 
-	cd->mn[0] = 'b';
-	cd->mn[1] = 'h';
-	cd->mn[2] = 'y';
-	cd->mn[3] = 'v';
-	cd->mn[4] = 'e';
-	cd->mn[5] = '-';
-	cd->mn[6] = 'N';
-	cd->mn[7] = 'V';
-	cd->mn[8] = 'M';
-	cd->mn[9] = 'e';
+	cpywithpad((char *)cd->mn, sizeof(cd->mn), "bhyve-NVMe", ' ');
+	cpywithpad((char *)cd->fr, sizeof(cd->fr), "1.0", ' ');
 
-	cd->fr[0] = '1';
-	cd->fr[1] = '.';
-	cd->fr[2] = '0';
-
 	/* Num of submission commands that we can handle at a time (2^rab) */
 	cd->rab   = 4;
 
@@ -1715,12 +1711,11 @@ pci_nvme_parse_opts(struct pci_nvme_softc *sc, char *o
 		} else if (!strcmp("ser", xopts)) {
 			/*
 			 * This field indicates the Product Serial Number in
-			 * 8-bit ASCII, unused bytes should be NULL characters.
-			 * Ref: NVM Express Management Interface 1.0a.
+			 * 7-bit ASCII, unused bytes should be space characters.
+			 * Ref: NVMe v1.3c.
 			 */
-			memset(sc->ctrldata.sn, 0, sizeof(sc->ctrldata.sn));
-			strncpy(sc->ctrldata.sn, config,
-			        sizeof(sc->ctrldata.sn));
+			cpywithpad((char *)sc->ctrldata.sn,
+			           sizeof(sc->ctrldata.sn), config, ' ');
 		} else if (!strcmp("ram", xopts)) {
 			uint64_t sz = strtoull(&xopts[4], NULL, 10);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808200456.w7K4ubkR004360>