Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Jul 2019 17:48:36 +0000 (UTC)
From:      Chuck Tuffli <chuck@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r350380 - stable/12/usr.sbin/bhyve
Message-ID:  <201907271748.x6RHmaZ2090103@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: chuck
Date: Sat Jul 27 17:48:35 2019
New Revision: 350380
URL: https://svnweb.freebsd.org/changeset/base/350380

Log:
  MFC r345956
  
  bhyve: Fix NVMe BAR size calculation
  
  The NVMe specification defines bits 13:4 of BAR0 as Reserved (i.e. 0x0).
  Most drivers do not enforce this, but the Windows NVMe driver does and
  will refuse to start the device (i.e. error 10) if any of these bits are
  set.
  
  Approved by:	imp (mentor)

Modified:
  stable/12/usr.sbin/bhyve/pci_nvme.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.sbin/bhyve/pci_nvme.c
==============================================================================
--- stable/12/usr.sbin/bhyve/pci_nvme.c	Sat Jul 27 17:43:59 2019	(r350379)
+++ stable/12/usr.sbin/bhyve/pci_nvme.c	Sat Jul 27 17:48:35 2019	(r350380)
@@ -85,6 +85,9 @@ static int nvme_debug = 0;
 
 #define	NVME_IOSLOTS		8
 
+/* The NVMe spec defines bits 13:4 in BAR0 as reserved */
+#define NVME_MMIO_SPACE_MIN	(1 << 14)
+
 #define	NVME_QUEUES		16
 #define	NVME_MAX_QENTRIES	2048
 
@@ -1897,9 +1900,16 @@ pci_nvme_init(struct vmctx *ctx, struct pci_devinst *p
 	pci_set_cfgdata8(pi, PCIR_PROGIF,
 	                 PCIP_STORAGE_NVM_ENTERPRISE_NVMHCI_1_0);
 
-	/* allocate size of nvme registers + doorbell space for all queues */
+	/*
+	 * Allocate size of NVMe registers + doorbell space for all queues.
+	 *
+	 * The specification requires a minimum memory I/O window size of 16K.
+	 * The Windows driver will refuse to start a device with a smaller
+	 * window.
+	 */
 	pci_membar_sz = sizeof(struct nvme_registers) +
-	                2*sizeof(uint32_t)*(sc->max_queues + 1);
+	    2 * sizeof(uint32_t) * (sc->max_queues + 1);
+	pci_membar_sz = MAX(pci_membar_sz, NVME_MMIO_SPACE_MIN);
 
 	DPRINTF(("nvme membar size: %u\r\n", pci_membar_sz));
 



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