From nobody Fri Apr 15 20:46:49 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 7DDC65D7163; Fri, 15 Apr 2022 20:46:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Kg7ff168Sz4tm5; Fri, 15 Apr 2022 20:46:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650055610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9whP1iQDpmVY+pp5PA8IIwZqYZSsKhTn2RuGA0vWu0c=; b=SoTIRwJQPs2JDkQz9zERDi/rZ1T1RcSWJwahigtvfEarT9rc9wWgb6EuOFNbC1e40YekoI CkOpYwfWK6yxw4RxDwIHaP8gECIfIpzTRuraGW8Fibw2ABCQPluRB8rHhLkTK9szvVyCsm g2Is7LjOv/lpGOPt9Hhu+Oisl2IBnPaOAXlZXPWBj8nmWKDgpKu+DbOml8ztA1rqO1fbmn 2sIgQVzc8RMnig9tM9FkcL30lruCBTBccxtsqnlf3WHvP2xQWYX3Q0JPUSxh5PUM3LcHD3 MOtumhKAlvAMiWH4a/5MlnSp0n+Wk59uou0BG4v9rlXPOkx9Wk8hMleXm4HskA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9B3C61C1ED; Fri, 15 Apr 2022 20:46:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 23FKknA5079406; Fri, 15 Apr 2022 20:46:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23FKkn9s079405; Fri, 15 Apr 2022 20:46:49 GMT (envelope-from git) Date: Fri, 15 Apr 2022 20:46:49 GMT Message-Id: <202204152046.23FKkn9s079405@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 3740a8db13ba - main - nvme: Further refinements in Host Memory Buffer Sizing List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3740a8db13ba62e47b82e312966194acc84ce0b6 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650055610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9whP1iQDpmVY+pp5PA8IIwZqYZSsKhTn2RuGA0vWu0c=; b=VM0kpZ+aLZ591ta8b9CASAzrGV2eUJDDGCqZPLkc7va0MpaLcemGSFNVQTmlUB42jtmL6d GOmg40VAbSz3wWIxc/5uPCT278VbfCPYTaFELVGCQkqhCvWfq0G8Cd4bYM39u2pk61jkvX pZpXqoLvAWinYg5bMkSN48TSafPbBconIyg0dNHrczpiYg0nSRh/8e0bj+sqS6BQWhfXh5 lqbPpUV/h/I4HJ0i66fk2iuCkvCgopWZlrybLDZOzQHI7GE0m0t9yD7rWAljpU3SSbjViI 8khwP/LbDQagGDsYGxaOYkMnZ3MvUeiLXy9OpwbiMVl/lDiBoZTJqqAmQN4UMw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1650055610; a=rsa-sha256; cv=none; b=o502bDTrf+UAGDmT4znLnzSG8Uryc/EV6tCJ4upBJXpYG8GFA/cCrtk7bNlC0rgx8NT5Qz XPyfFNafF5eXSny0IUPHRLZIxMOXz2FJNh/jqwnu606iOUjzfBqAmGa3tKiF1OHK/XhQEI GoRAglESx6fuR7RNve8eyBprG4bl9XgU97xcBAReuY+z4sAbiK95scipfkOaflZ1kxwMZb J6yolaBoHp9B1+do3SLlSQS8cmAMaGHzmnsmaZrWmplVkVuj+siXnS2vp6BxE45z0wqVVC jEf/WNkjOxwG+IgSR/rOyypGpsb4aVLN1rjJRbAc/zffUd1dRji+xhz3nULvlw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=3740a8db13ba62e47b82e312966194acc84ce0b6 commit 3740a8db13ba62e47b82e312966194acc84ce0b6 Author: Warner Losh AuthorDate: 2022-04-15 20:41:40 +0000 Commit: Warner Losh CommitDate: 2022-04-15 20:46:19 +0000 nvme: Further refinements in Host Memory Buffer Sizing Host Memory Buffer units are a mix. For those in the identify structure, the size is in 4kiB chunks. For specifying the buffer description, though, they are in terms of the drive's MPS. Add comments to this effect and change PAGE_SIZE to ctrlr->page_size where needed, as well as correct a mistaken use of NVME_HPS_UNITS in 214df80a9cb3 as pointed out by rpokala@ after the commit. No functional change is intended, as page_size is still 4k which matches all current hosts' PAGE_SIZE, but to support 16k pages on arm, we need to differentiate these two cases. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D34871 --- sys/dev/nvme/nvme_ctrlr.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c index 2a386269f21a..2c5d521ecaa1 100644 --- a/sys/dev/nvme/nvme_ctrlr.c +++ b/sys/dev/nvme/nvme_ctrlr.c @@ -941,24 +941,32 @@ nvme_ctrlr_hmb_alloc(struct nvme_controller *ctrlr) max = (uint64_t)physmem * PAGE_SIZE / 20; TUNABLE_UINT64_FETCH("hw.nvme.hmb_max", &max); + /* + * Units of Host Memory Buffer in the Identify info are always in terms + * of 4k units. + */ min = (long long unsigned)ctrlr->cdata.hmmin * NVME_HMB_UNITS; if (max == 0 || max < min) return; pref = MIN((long long unsigned)ctrlr->cdata.hmpre * NVME_HMB_UNITS, max); - minc = MAX(ctrlr->cdata.hmminds * NVME_HMB_UNITS, PAGE_SIZE); + minc = MAX(ctrlr->cdata.hmminds * NVME_HMB_UNITS, ctrlr->page_size); if (min > 0 && ctrlr->cdata.hmmaxd > 0) minc = MAX(minc, min / ctrlr->cdata.hmmaxd); ctrlr->hmb_chunk = pref; again: - ctrlr->hmb_chunk = roundup2(ctrlr->hmb_chunk, PAGE_SIZE); + /* + * However, the chunk sizes, number of chunks, and alignment of chunks + * are all based on the current MPS (ctrlr->page_size). + */ + ctrlr->hmb_chunk = roundup2(ctrlr->hmb_chunk, ctrlr->page_size); ctrlr->hmb_nchunks = howmany(pref, ctrlr->hmb_chunk); if (ctrlr->cdata.hmmaxd > 0 && ctrlr->hmb_nchunks > ctrlr->cdata.hmmaxd) ctrlr->hmb_nchunks = ctrlr->cdata.hmmaxd; ctrlr->hmb_chunks = malloc(sizeof(struct nvme_hmb_chunk) * ctrlr->hmb_nchunks, M_NVME, M_WAITOK); err = bus_dma_tag_create(bus_get_dma_tag(ctrlr->dev), - PAGE_SIZE, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, + ctrlr->page_size, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, ctrlr->hmb_chunk, 1, ctrlr->hmb_chunk, 0, NULL, NULL, &ctrlr->hmb_tag); if (err != 0) { nvme_printf(ctrlr, "HMB tag create failed %d\n", err); @@ -1028,7 +1036,7 @@ again: for (i = 0; i < ctrlr->hmb_nchunks; i++) { ctrlr->hmb_desc_vaddr[i].addr = htole64(ctrlr->hmb_chunks[i].hmbc_paddr); - ctrlr->hmb_desc_vaddr[i].size = htole32(ctrlr->hmb_chunk / NVME_HMB_UNITS); + ctrlr->hmb_desc_vaddr[i].size = htole32(ctrlr->hmb_chunk / ctrlr->page_size); } bus_dmamap_sync(ctrlr->hmb_desc_tag, ctrlr->hmb_desc_map, BUS_DMASYNC_PREWRITE); @@ -1051,8 +1059,9 @@ nvme_ctrlr_hmb_enable(struct nvme_controller *ctrlr, bool enable, bool memret) cdw11 |= 2; status.done = 0; nvme_ctrlr_cmd_set_feature(ctrlr, NVME_FEAT_HOST_MEMORY_BUFFER, cdw11, - ctrlr->hmb_nchunks * ctrlr->hmb_chunk / 4096, ctrlr->hmb_desc_paddr, - ctrlr->hmb_desc_paddr >> 32, ctrlr->hmb_nchunks, NULL, 0, + ctrlr->hmb_nchunks * ctrlr->hmb_chunk / ctrlr->page_size, + ctrlr->hmb_desc_paddr, ctrlr->hmb_desc_paddr >> 32, + ctrlr->hmb_nchunks, NULL, 0, nvme_completion_poll_cb, &status); nvme_completion_poll(&status); if (nvme_completion_is_error(&status.cpl))