From owner-svn-src-head@freebsd.org Thu Jul 23 15:35:09 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8683C9A848C; Thu, 23 Jul 2015 15:35:09 +0000 (UTC) (envelope-from jimharris@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6A4741852; Thu, 23 Jul 2015 15:35:09 +0000 (UTC) (envelope-from jimharris@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t6NFZ9R9018633; Thu, 23 Jul 2015 15:35:09 GMT (envelope-from jimharris@FreeBSD.org) Received: (from jimharris@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t6NFZ98w018632; Thu, 23 Jul 2015 15:35:09 GMT (envelope-from jimharris@FreeBSD.org) Message-Id: <201507231535.t6NFZ98w018632@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jimharris set sender to jimharris@FreeBSD.org using -f From: Jim Harris Date: Thu, 23 Jul 2015 15:35:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285815 - head/sys/dev/nvme X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jul 2015 15:35:09 -0000 Author: jimharris Date: Thu Jul 23 15:35:08 2015 New Revision: 285815 URL: https://svnweb.freebsd.org/changeset/base/285815 Log: nvme: properly handle case where pci_alloc_msix does not alloc all vectors Reported by: Sean Kelly MFC after: 3 days Sponsored by: Intel Modified: head/sys/dev/nvme/nvme_ctrlr.c Modified: head/sys/dev/nvme/nvme_ctrlr.c ============================================================================== --- head/sys/dev/nvme/nvme_ctrlr.c Thu Jul 23 15:32:58 2015 (r285814) +++ head/sys/dev/nvme/nvme_ctrlr.c Thu Jul 23 15:35:08 2015 (r285815) @@ -930,7 +930,8 @@ nvme_ctrlr_construct(struct nvme_control { union cap_lo_register cap_lo; union cap_hi_register cap_hi; - int i, num_vectors, per_cpu_io_queues, rid; + int i, per_cpu_io_queues, rid; + int num_vectors_requested, num_vectors_allocated; int status, timeout_period; ctrlr->dev = dev; @@ -988,7 +989,7 @@ nvme_ctrlr_construct(struct nvme_control } /* One vector per IO queue, plus one vector for admin queue. */ - num_vectors = ctrlr->num_io_queues + 1; + num_vectors_requested = ctrlr->num_io_queues + 1; /* * If we cannot even allocate 2 vectors (one for admin, one for @@ -997,15 +998,36 @@ nvme_ctrlr_construct(struct nvme_control if (pci_msix_count(dev) < 2) { ctrlr->msix_enabled = 0; goto intx; - } else if (pci_msix_count(dev) < num_vectors) { + } else if (pci_msix_count(dev) < num_vectors_requested) { ctrlr->per_cpu_io_queues = FALSE; ctrlr->num_io_queues = 1; - num_vectors = 2; /* one for admin, one for I/O */ + num_vectors_requested = 2; /* one for admin, one for I/O */ } - if (pci_alloc_msix(dev, &num_vectors) != 0) { + num_vectors_allocated = num_vectors_requested; + if (pci_alloc_msix(dev, &num_vectors_allocated) != 0) { ctrlr->msix_enabled = 0; goto intx; + } else if (num_vectors_allocated < num_vectors_requested) { + if (num_vectors_allocated < 2) { + pci_release_msi(dev); + ctrlr->msix_enabled = 0; + goto intx; + } else { + ctrlr->per_cpu_io_queues = FALSE; + ctrlr->num_io_queues = 1; + /* + * Release whatever vectors were allocated, and just + * reallocate the two needed for the admin and single + * I/O qpair. + */ + num_vectors_allocated = 2; + pci_release_msi(dev); + if (pci_alloc_msix(dev, &num_vectors_allocated) != 0) + panic("could not reallocate any vectors\n"); + if (num_vectors_allocated != 2) + panic("could not reallocate 2 vectors\n"); + } } /* @@ -1022,7 +1044,7 @@ nvme_ctrlr_construct(struct nvme_control * vendors wishing to import this driver into kernels based on * older versions of FreeBSD. */ - for (i = 0; i < num_vectors; i++) { + for (i = 0; i < num_vectors_allocated; i++) { rid = i + 1; ctrlr->msi_res[i] = bus_alloc_resource_any(ctrlr->dev, SYS_RES_IRQ, &rid, RF_ACTIVE);