Module Name: src Committed By: martin Date: Sun Sep 27 10:33:45 UTC 2020
Modified Files: src/sys/dev/ic [netbsd-8]: ld_nvme.c nvme.c Log Message: Pull up following revision(s) (requested by kardel in ticket #1610): sys/dev/ic/ld_nvme.c: revision 1.24 (patch) sys/dev/ic/nvme.c: revision 1.50 (patch) PR kern/55674: move name space availability check from ld_nvme.c:ld_nvme_attach() to nvme.c:nvme_rescan(). this avoids allocation of ld(4) instances for every possible name space, even if it is not usable. it also reduces the device node flood generated from that strategy. To generate a diff of this commit: cvs rdiff -u -r1.16.2.4 -r1.16.2.5 src/sys/dev/ic/ld_nvme.c cvs rdiff -u -r1.30.2.7 -r1.30.2.8 src/sys/dev/ic/nvme.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ic/ld_nvme.c diff -u src/sys/dev/ic/ld_nvme.c:1.16.2.4 src/sys/dev/ic/ld_nvme.c:1.16.2.5 --- src/sys/dev/ic/ld_nvme.c:1.16.2.4 Mon Oct 28 18:27:47 2019 +++ src/sys/dev/ic/ld_nvme.c Sun Sep 27 10:33:45 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: ld_nvme.c,v 1.16.2.4 2019/10/28 18:27:47 martin Exp $ */ +/* $NetBSD: ld_nvme.c,v 1.16.2.5 2020/09/27 10:33:45 martin Exp $ */ /*- * Copyright (C) 2016 NONAKA Kimihiro <non...@netbsd.org> @@ -26,7 +26,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ld_nvme.c,v 1.16.2.4 2019/10/28 18:27:47 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ld_nvme.c,v 1.16.2.5 2020/09/27 10:33:45 martin Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -86,7 +86,6 @@ ld_nvme_attach(device_t parent, device_t struct nvme_attach_args *naa = aux; struct nvme_namespace *ns; struct nvm_namespace_format *f; - int error; ld->sc_dv = self; sc->sc_nvme = nsc; @@ -95,28 +94,11 @@ ld_nvme_attach(device_t parent, device_t aprint_naive("\n"); aprint_normal("\n"); - error = nvme_ns_identify(sc->sc_nvme, sc->sc_nsid); - if (error) { - aprint_error_dev(self, "couldn't identify namespace\n"); - return; - } - ns = nvme_ns_get(sc->sc_nvme, sc->sc_nsid); KASSERT(ns); - f = &ns->ident->lbaf[NVME_ID_NS_FLBAS(ns->ident->flbas)]; - /* - * NVME1.0e 6.11 Identify command - * - * LBADS values smaller than 9 are not supported, a value - * of zero means that the format is not used. - */ - if (f->lbads < 9) { - if (f->lbads > 0) - aprint_error_dev(self, - "unsupported logical data size %u\n", f->lbads); - return; - } + f = &ns->ident->lbaf[NVME_ID_NS_FLBAS(ns->ident->flbas)]; + KASSERT(f->lbads >= 9); /* only valid LBA data sizes allowed here */ ld->sc_secsize = 1 << f->lbads; ld->sc_secperunit = ns->ident->nsze; Index: src/sys/dev/ic/nvme.c diff -u src/sys/dev/ic/nvme.c:1.30.2.7 src/sys/dev/ic/nvme.c:1.30.2.8 --- src/sys/dev/ic/nvme.c:1.30.2.7 Mon Nov 11 17:17:22 2019 +++ src/sys/dev/ic/nvme.c Sun Sep 27 10:33:45 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: nvme.c,v 1.30.2.7 2019/11/11 17:17:22 martin Exp $ */ +/* $NetBSD: nvme.c,v 1.30.2.8 2020/09/27 10:33:45 martin Exp $ */ /* $OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */ /* @@ -18,7 +18,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.30.2.7 2019/11/11 17:17:22 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.30.2.8 2020/09/27 10:33:45 martin Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -469,23 +469,52 @@ nvme_rescan(device_t self, const char *a { struct nvme_softc *sc = device_private(self); struct nvme_attach_args naa; + struct nvm_namespace_format *f; + struct nvme_namespace *ns; uint64_t cap; int ioq_entries = nvme_ioq_size; int i; + int error; cap = nvme_read8(sc, NVME_CAP); if (ioq_entries > NVME_CAP_MQES(cap)) ioq_entries = NVME_CAP_MQES(cap); - for (i = 0; i < sc->sc_nn; i++) { - if (sc->sc_namespaces[i].dev) + for (i = 1; i <= sc->sc_nn; i++) { + if (sc->sc_namespaces[i - 1].dev) continue; - memset(&naa, 0, sizeof(naa)); - naa.naa_nsid = i + 1; - naa.naa_qentries = (ioq_entries - 1) * sc->sc_nq; - naa.naa_maxphys = sc->sc_mdts; - sc->sc_namespaces[i].dev = config_found(sc->sc_dev, &naa, - nvme_print); + + /* identify to check for availability */ + error = nvme_ns_identify(sc, i); + if (error) { + aprint_error_dev(self, "couldn't identify namespace #%d\n", i); + continue; + } + + ns = nvme_ns_get(sc, i); + KASSERT(ns); + + f = &ns->ident->lbaf[NVME_ID_NS_FLBAS(ns->ident->flbas)]; + + /* + * NVME1.0e 6.11 Identify command + * + * LBADS values smaller than 9 are not supported, a value + * of zero means that the format is not used. + */ + if (f->lbads < 9) { + if (f->lbads > 0) + aprint_error_dev(self, + "unsupported logical data size %u\n", f->lbads); + continue; + } + + memset(&naa, 0, sizeof(naa)); + naa.naa_nsid = i; + naa.naa_qentries = (ioq_entries - 1) * sc->sc_nq; + naa.naa_maxphys = sc->sc_mdts; + sc->sc_namespaces[i - 1].dev = config_found(sc->sc_dev, &naa, + nvme_print); } return 0; }