From nobody Fri Apr 19 18:07:29 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail header.i=@amazon.com; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=quarantine dis=quarantine) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1601470066; cv=none; d=zohomail.com; s=zohoarc; b=ish+QkbyplplmThH6rhFXL1uOjIceHaoaL3YPdjkrs4Tum6MOh9hQg9keXv1rAYdsyRJu31tzPFVLhseuDM+4Ef6Mxopi+GTN9bBMCQDR7+hOI7Bn/lvGqkGclvjWixx6WBrbyZ+u87bK4DrtL/sQr/LYFfIgsBsd8YW9Sk9LA0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601470066; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Subject:To; bh=zNlqxcCeHT2jPLVSLeUo0WhAbawqOL4IR3Eiu2GVAzE=; b=kH3ZBURJCGK0ndiDCeioOvGw8S+k4ZWIsSFBZDN+v7fjuvTWFJ4eUzKKe+HJXIgZ7uIrgVmMnN7JMnFbcPjIrOUIxw4Xm/I/2BrU1KqnG0P9YD8Dhoe17ldAo6fMa6eep5TkFkporTllg6tXgSan8/ryDDwy60OoLj6JqPQ8ZmM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@amazon.com; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail header.from= (p=quarantine dis=quarantine) header.from= Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1601470066640411.86415100040495; Wed, 30 Sep 2020 05:47:46 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 7B71A10C0082; Wed, 30 Sep 2020 12:47:42 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 59B5B10C0068 for ; Wed, 30 Sep 2020 12:47:17 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 30 Sep 2020 12:47:16 +0000 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by email-inbound-relay-1d-98acfc19.us-east-1.amazon.com (Postfix) with ESMTPS id 61713A1F44 for ; Wed, 30 Sep 2020 12:47:14 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) EX13MTAUWC001.ant.amazon.com (10.43.162.135) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Sep 2020 12:47:14 +0000 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) EX13D20UWC001.ant.amazon.com (10.43.162.244) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Sep 2020 12:47:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1601470038; x=1633006038; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kcZFe2EUxUqrp4MhTBDPdr8R3qrcnhCzWDWUkBiHRvk=; b=bFlql+YJtTRzKrz66dL+Jq4nVlOYT78fuczi5IArEeqtqg+qeZLqwM1g bqfIzmyffDbmrCiS5Hwvqgr9c87lV+Swi4vmtPXzim9OurVD9T0KUGUPj i3jBCaX3e1unJBRfe+KIExLyxA1NTr8EuSoW+X7Ix0sKMt9aAROlsGXnr M=; X-IronPort-AV: E=Sophos;i="5.77,322,1596499200"; d="scan'208";a="79237252" From: Alexander Graf To: Date: Wed, 30 Sep 2020 14:47:02 +0200 Message-ID: <20200930124704.1846-2-graf@amazon.com> In-Reply-To: <20200930124704.1846-1-graf@amazon.com> References: <20200930124704.1846-1-graf@amazon.com> MIME-Version: 1.0 X-ClientProxiedBy: EX13D34UWA002.ant.amazon.com (10.43.160.245) To EX13D20UWC001.ant.amazon.com (10.43.162.244) Message-ID-Hash: ORFEFIVHJ6WPIVSEOQNTGKVHGAWJOK4C X-Message-ID-Hash: ORFEFIVHJ6WPIVSEOQNTGKVHGAWJOK4C X-MailFrom: prvs=535b814ec=graf@amazon.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.3.2b1 Precedence: list Subject: [SeaBIOS] [PATCH v2 1/3] nvme: Record maximum allowed request size List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: -- X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" NVMe has a limit on how many sectors it can handle at most within a single request. Remember that number, so that in a follow-up patch, we can verify that we don't exceed it. Signed-off-by: Alexander Graf --- v1 -> v2: - fix dprintf --- src/hw/nvme-int.h | 8 +++++++- src/hw/nvme.c | 13 +++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/hw/nvme-int.h b/src/hw/nvme-int.h index 9f95dd8..674008a 100644 --- a/src/hw/nvme-int.h +++ b/src/hw/nvme-int.h @@ -117,6 +117,7 @@ struct nvme_namespace { =20 u32 block_size; u32 metadata_size; + u32 max_req_size; =20 /* Page aligned buffer of size NVME_PAGE_SIZE. */ char *dma_buffer; @@ -131,7 +132,12 @@ struct nvme_identify_ctrl { char mn[40]; char fr[8]; =20 - char _boring[516 - 72]; + u8 rab; + u8 ieee[3]; + u8 cmic; + u8 mdts; + + char _boring[516 - 78]; =20 u32 nn; /* number of namespaces */ }; diff --git a/src/hw/nvme.c b/src/hw/nvme.c index 6a01204..7e56134 100644 --- a/src/hw/nvme.c +++ b/src/hw/nvme.c @@ -238,7 +238,8 @@ nvme_admin_identify_ns(struct nvme_ctrl *ctrl, u32 ns_i= d) } =20 static void -nvme_probe_ns(struct nvme_ctrl *ctrl, struct nvme_namespace *ns, u32 ns_id) +nvme_probe_ns(struct nvme_ctrl *ctrl, struct nvme_namespace *ns, u32 ns_id, + u8 mdts) { ns->ctrl =3D ctrl; ns->ns_id =3D ns_id; @@ -281,6 +282,14 @@ nvme_probe_ns(struct nvme_ctrl *ctrl, struct nvme_name= space *ns, u32 ns_id) ns->drive.blksize =3D ns->block_size; ns->drive.sectors =3D ns->lba_count; =20 + if (mdts) { + ns->max_req_size =3D 1U << mdts; + dprintf(3, "NVME NS %u max request size: %d sectors\n", + ns_id, ns->max_req_size); + } else { + ns->max_req_size =3D -1U; + } + ns->dma_buffer =3D zalloc_page_aligned(&ZoneHigh, NVME_PAGE_SIZE); =20 char *desc =3D znprintf(MAXDESCSIZE, "NVMe NS %u: %llu MiB (%llu %u-by= te " @@ -567,7 +576,7 @@ nvme_controller_enable(struct nvme_ctrl *ctrl) /* Populate namespace IDs */ int ns_idx; for (ns_idx =3D 0; ns_idx < ctrl->ns_count; ns_idx++) { - nvme_probe_ns(ctrl, &ctrl->ns[ns_idx], ns_idx + 1); + nvme_probe_ns(ctrl, &ctrl->ns[ns_idx], ns_idx + 1, identify->mdts); } =20 dprintf(3, "NVMe initialization complete!\n"); --=20 2.16.4 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org From nobody Fri Apr 19 18:07:29 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail header.i=@amazon.com; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=quarantine dis=quarantine) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1601470055; cv=none; d=zohomail.com; s=zohoarc; b=XoXJJSM8A9FKMnIhYyW0JCnrrrWTFNqZHkEejNCxbILAaAbdDTQVPRjjz8RHGI0Apb7luV1MLOAs+EJTlImulWx76cNKpPAaM16UvIdDrmzL1jwst0CcG7lkcz1MMOP+c5sgCrmOZXeopHHQ/oAuYMo+2RxK8oT1DKQ5cvUGpUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601470055; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Subject:To; bh=BSUw9xhLkqYSCQ32zUp1iAAVX9uLGXxIR1FOOIicwyw=; b=FCL23Cry+zg9BP+HNaqiZJN+9ICh11UeDBmcmp7ZUX6n+Dj7COCzy2tvcAb/+bXAsdB7fOJA8/eAAlIEqF7kNZG/z6pvKW8CeaqOq3JjDwQCH5IgCtXCPxqgdq7+CgYHNn5Yu5v+NytOqBCWC4G9GPbxlHP9iYua/XTmk0tkt5w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@amazon.com; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail header.from= (p=quarantine dis=quarantine) header.from= Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1601470055521220.4752333944532; Wed, 30 Sep 2020 05:47:35 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 8F30410C0079; Wed, 30 Sep 2020 12:47:31 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id AE09A10C0077 for ; Wed, 30 Sep 2020 12:47:17 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 30 Sep 2020 12:47:16 +0000 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by email-inbound-relay-1e-27fb8269.us-east-1.amazon.com (Postfix) with ESMTPS id D02F9A1C20 for ; Wed, 30 Sep 2020 12:47:15 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) EX13MTAUWC002.ant.amazon.com (10.43.162.240) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Sep 2020 12:47:15 +0000 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) EX13D20UWC001.ant.amazon.com (10.43.162.244) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Sep 2020 12:47:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1601470038; x=1633006038; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hmyXlj/Ti5J5FUG5DEvY8vpTv0+na2E7Yqs21h2XjWU=; b=V6e8yt1kdaj+hPURRecziJ0FQRfeaojSDk5TXQuMLe3znozSXk2BcZqN 6gf1K6UyT72PMDzbWxDZrdBkIwEeoOMw0dwm8sV+brBwj2FF/UJIdcZAt 7tk8PMBuNGWm37TcJXNMU23hwqE0tcNS3U/nBFmfM20cFra4dO7mOErai E=; X-IronPort-AV: E=Sophos;i="5.77,322,1596499200"; d="scan'208";a="58572216" From: Alexander Graf To: Date: Wed, 30 Sep 2020 14:47:03 +0200 Message-ID: <20200930124704.1846-3-graf@amazon.com> In-Reply-To: <20200930124704.1846-1-graf@amazon.com> References: <20200930124704.1846-1-graf@amazon.com> MIME-Version: 1.0 X-ClientProxiedBy: EX13D34UWA002.ant.amazon.com (10.43.160.245) To EX13D20UWC001.ant.amazon.com (10.43.162.244) Message-ID-Hash: 3E6YRRN3WMH5PFZBNO3KUVH53PAPUOWZ X-Message-ID-Hash: 3E6YRRN3WMH5PFZBNO3KUVH53PAPUOWZ X-MailFrom: prvs=535b814ec=graf@amazon.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.3.2b1 Precedence: list Subject: [SeaBIOS] [PATCH v2 2/3] nvme: Allow to set PRP2 List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: -- X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When creating a PRP based I/O request, we pass in the pointer to operate on. Going forward, we will want to be able to pass additional pointers though for mappings above 4k. This patch adds a parameter to nvme_get_next_sqe() to pass in the PRP2 value of an NVMe I/O request, paving the way for a future patch to implement PRP lists. Signed-off-by: Alexander Graf Reviewed-by: Filippo Sironi --- src/hw/nvme.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hw/nvme.c b/src/hw/nvme.c index 7e56134..04bbba4 100644 --- a/src/hw/nvme.c +++ b/src/hw/nvme.c @@ -152,7 +152,7 @@ nvme_wait(struct nvme_sq *sq) /* Returns the next submission queue entry (or NULL if the queue is full).= It also fills out Command Dword 0 and clears the rest. */ static struct nvme_sqe * -nvme_get_next_sqe(struct nvme_sq *sq, u8 opc, void *metadata, void *data) +nvme_get_next_sqe(struct nvme_sq *sq, u8 opc, void *metadata, void *data, = void *data2) { if (((sq->head + 1) & sq->common.mask) =3D=3D sq->tail) { dprintf(3, "submission queue is full"); @@ -166,6 +166,7 @@ nvme_get_next_sqe(struct nvme_sq *sq, u8 opc, void *met= adata, void *data) sqe->cdw0 =3D opc | (sq->tail << 16 /* CID */); sqe->mptr =3D (u32)metadata; sqe->dptr_prp1 =3D (u32)data; + sqe->dptr_prp2 =3D (u32)data2; =20 if (sqe->dptr_prp1 & (NVME_PAGE_SIZE - 1)) { /* Data buffer not page aligned. */ @@ -200,7 +201,7 @@ nvme_admin_identify(struct nvme_ctrl *ctrl, u8 cns, u32= nsid) struct nvme_sqe *cmd_identify; cmd_identify =3D nvme_get_next_sqe(&ctrl->admin_sq, NVME_SQE_OPC_ADMIN_IDENTIFY, NULL, - identify_buf); + identify_buf, NULL); =20 if (!cmd_identify) { warn_internalerror(); @@ -338,7 +339,7 @@ nvme_create_io_cq(struct nvme_ctrl *ctrl, struct nvme_c= q *cq, u16 q_idx) =20 cmd_create_cq =3D nvme_get_next_sqe(&ctrl->admin_sq, NVME_SQE_OPC_ADMIN_CREATE_IO_CQ, NUL= L, - cq->cqe); + cq->cqe, NULL); if (!cmd_create_cq) { goto err_destroy_cq; } @@ -382,7 +383,7 @@ nvme_create_io_sq(struct nvme_ctrl *ctrl, struct nvme_s= q *sq, u16 q_idx, struct =20 cmd_create_sq =3D nvme_get_next_sqe(&ctrl->admin_sq, NVME_SQE_OPC_ADMIN_CREATE_IO_SQ, NUL= L, - sq->sqe); + sq->sqe, NULL); if (!cmd_create_sq) { goto err_destroy_sq; } @@ -429,7 +430,7 @@ nvme_io_readwrite(struct nvme_namespace *ns, u64 lba, c= har *buf, u16 count, struct nvme_sqe *io_read =3D nvme_get_next_sqe(&ns->ctrl->io_sq, write ? NVME_SQE_OPC_IO_W= RITE : NVME_SQE_OPC_IO_R= EAD, - NULL, buf); + NULL, buf, NULL); io_read->nsid =3D ns->ns_id; io_read->dword[10] =3D (u32)lba; io_read->dword[11] =3D (u32)(lba >> 32); --=20 2.16.4 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org From nobody Fri Apr 19 18:07:29 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail header.i=@amazon.com; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=quarantine dis=quarantine) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1601470090; cv=none; d=zohomail.com; s=zohoarc; b=UBosZgfqpZZT9znuUIeeJzFyHASBXrfWdktg/BoqNPSUfLZrg2IRoOK0Y3JQz2gh0FXrQYlbRsmZNatj/6IL8jYbNmCrkix3u3weNlXpeeRyWoLkdwyaUWlCeJvzhypiP3zlc58J4rzCITnO8mDJcqViwwm4KbOBEqBmttT+sRw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601470090; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Subject:To; bh=Hnp/3Zz46QCShpOVPcMb5vny0cK/WC2OvH5sY+E6mvg=; b=kRvPCQyLpHSn0OnUemgx2+3VSQ2iCWFM12+1zVkYtvm52ktq69opqj75dgT/IUPY4wOvDsmZn7dEzJLdy5cv/HNs1s/roVF+cqZtXnDpaYiBWJxT7spfVBd8pzYhxkl2YWHFVDskMmYGp5b4w4Hze//uu9odeuGmzW9obLDE+eM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@amazon.com; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail header.from= (p=quarantine dis=quarantine) header.from= Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1601470090847944.0625092542947; Wed, 30 Sep 2020 05:48:10 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 5097610C0082; Wed, 30 Sep 2020 12:48:07 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 4DEFA10C0068 for ; Wed, 30 Sep 2020 12:47:20 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 30 Sep 2020 12:47:18 +0000 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by email-inbound-relay-1a-821c648d.us-east-1.amazon.com (Postfix) with ESMTPS id E77F7A2068 for ; Wed, 30 Sep 2020 12:47:16 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) EX13MTAUWC001.ant.amazon.com (10.43.162.135) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Sep 2020 12:47:16 +0000 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) EX13D20UWC001.ant.amazon.com (10.43.162.244) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Sep 2020 12:47:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1601470041; x=1633006041; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RP6RdjOYNDk0LMBC+zUUt59lNbVhr1grQOhHCBbCXqw=; b=uVmceMYtTFbZuMK4jiQ1ZgxYcJgaS8OjtOwwwlRPMI2Kolj77m4Vz6qW l71QoiXtp5KP518SOgkzFU50HaYX6USfPZ/j7uG4mNb8063Ojx2F73WK6 oqYfjnjnmANhvVD+mInd/wgMaNuuJyrwozJbV8Bgteyd2MUuRaFOCTm31 o=; X-IronPort-AV: E=Sophos;i="5.77,322,1596499200"; d="scan'208";a="80476406" From: Alexander Graf To: Date: Wed, 30 Sep 2020 14:47:04 +0200 Message-ID: <20200930124704.1846-4-graf@amazon.com> In-Reply-To: <20200930124704.1846-1-graf@amazon.com> References: <20200930124704.1846-1-graf@amazon.com> MIME-Version: 1.0 X-ClientProxiedBy: EX13D34UWA002.ant.amazon.com (10.43.160.245) To EX13D20UWC001.ant.amazon.com (10.43.162.244) Message-ID-Hash: TK47ZZ3B3L7Y3URIMI4JG7XB4UNEI2WT X-Message-ID-Hash: TK47ZZ3B3L7Y3URIMI4JG7XB4UNEI2WT X-MailFrom: prvs=535b814ec=graf@amazon.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.3.2b1 Precedence: list Subject: [SeaBIOS] [PATCH v2 3/3] nvme: Pass large I/O requests as PRP lists List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: --- X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Today, we split every I/O request into at most 4kb chunks and wait for these requests to finish. We encountered issues where the backing storage is netw= ork based, so every I/O request needs to go over the network with associated latency cost. A few ms of latency when loading 100MB initrd in 4kb chunks does add up. NVMe implements a feature to allow I/O requests spanning multiple pages, called PRP lists. This patch takes larger I/O operations and checks if they can be directly passed to the NVMe backing device as PRP list. At least for grub, read operations can always be mapped directly into PRP list items. This reduces the number of I/O operations required during a typical boot path by roughly a factor of 5. Signed-off-by: Alexander Graf --- v1 -> v2: - Fix bounds check on PRP list add logic - Reduce PRP list to 15 entries embedded in the ns struct. This reduces BIOS reserved memory footprint by 4kb. --- src/hw/nvme-int.h | 8 ++++++ src/hw/nvme.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++---= ---- 2 files changed, 82 insertions(+), 10 deletions(-) diff --git a/src/hw/nvme-int.h b/src/hw/nvme-int.h index 674008a..7947b29 100644 --- a/src/hw/nvme-int.h +++ b/src/hw/nvme-int.h @@ -10,6 +10,8 @@ #include "types.h" // u32 #include "pcidevice.h" // struct pci_device =20 +#define NVME_MAX_PRPL_ENTRIES 15 /* Allows requests up to 64kb */ + /* Data structures */ =20 /* The register file of a NVMe host controller. This struct follows the na= ming @@ -121,6 +123,11 @@ struct nvme_namespace { =20 /* Page aligned buffer of size NVME_PAGE_SIZE. */ char *dma_buffer; + + /* Page List */ + u32 prpl_len; + void *prp1; + u64 prpl[NVME_MAX_PRPL_ENTRIES]; }; =20 /* Data structures for NVMe admin identify commands */ @@ -195,6 +202,7 @@ union nvme_identify { #define NVME_CQE_DW3_P (1U << 16) =20 #define NVME_PAGE_SIZE 4096 +#define NVME_PAGE_MASK ~(NVME_PAGE_SIZE - 1) =20 /* Length for the queue entries. */ #define NVME_SQE_SIZE_LOG 6 diff --git a/src/hw/nvme.c b/src/hw/nvme.c index 04bbba4..ec05836 100644 --- a/src/hw/nvme.c +++ b/src/hw/nvme.c @@ -168,11 +168,6 @@ nvme_get_next_sqe(struct nvme_sq *sq, u8 opc, void *me= tadata, void *data, void * sqe->dptr_prp1 =3D (u32)data; sqe->dptr_prp2 =3D (u32)data2; =20 - if (sqe->dptr_prp1 & (NVME_PAGE_SIZE - 1)) { - /* Data buffer not page aligned. */ - warn_internalerror(); - } - return sqe; } =20 @@ -418,19 +413,29 @@ nvme_io_readwrite(struct nvme_namespace *ns, u64 lba,= char *buf, u16 count, int write) { u32 buf_addr =3D (u32)buf; + void *prp2; =20 - if ((buf_addr & 0x3) || - ((buf_addr & ~(NVME_PAGE_SIZE - 1)) !=3D - ((buf_addr + ns->block_size * count - 1) & ~(NVME_PAGE_SIZE - 1))= )) { - /* Buffer is misaligned or crosses page boundary */ + if (buf_addr & 0x3) { + /* Buffer is misaligned */ warn_internalerror(); return DISK_RET_EBADTRACK; } =20 + if ((ns->block_size * count) > (NVME_PAGE_SIZE * 2)) { + /* We need to describe more than 2 pages, rely on PRP List */ + prp2 =3D ns->prpl; + } else if ((ns->block_size * count) > NVME_PAGE_SIZE) { + /* Directly embed the 2nd page if we only need 2 pages */ + prp2 =3D (void *)(long)ns->prpl[0]; + } else { + /* One page is enough, don't expose anything else */ + prp2 =3D NULL; + } + struct nvme_sqe *io_read =3D nvme_get_next_sqe(&ns->ctrl->io_sq, write ? NVME_SQE_OPC_IO_W= RITE : NVME_SQE_OPC_IO_R= EAD, - NULL, buf, NULL); + NULL, buf, prp2); io_read->nsid =3D ns->ns_id; io_read->dword[10] =3D (u32)lba; io_read->dword[11] =3D (u32)(lba >> 32); @@ -450,6 +455,60 @@ nvme_io_readwrite(struct nvme_namespace *ns, u64 lba, = char *buf, u16 count, return DISK_RET_SUCCESS; } =20 +static void nvme_reset_prpl(struct nvme_namespace *ns) +{ + ns->prpl_len =3D 0; +} + +static int nvme_add_prpl(struct nvme_namespace *ns, u64 base) +{ + if (ns->prpl_len >=3D NVME_MAX_PRPL_ENTRIES) + return -1; + + ns->prpl[ns->prpl_len++] =3D base; + + return 0; +} + +int nvme_build_prpl(struct nvme_namespace *ns, struct disk_op_s *op) +{ + int first_page =3D 1; + u32 base =3D (long)op->buf_fl; + s32 size =3D op->count * ns->block_size; + + if (op->count > ns->max_req_size) + return -1; + + nvme_reset_prpl(ns); + + /* Special case for transfers that fit into PRP1, but are unaligned */ + if (((size + (base & ~NVME_PAGE_MASK)) <=3D NVME_PAGE_SIZE)) { + ns->prp1 =3D op->buf_fl; + return 0; + } + + /* Every request has to be page aligned */ + if (base & ~NVME_PAGE_MASK) + return -1; + + /* Make sure a full block fits into the last chunk */ + if (size & (ns->block_size - 1ULL)) + return -1; + + for (; size > 0; base +=3D NVME_PAGE_SIZE, size -=3D NVME_PAGE_SIZE) { + if (first_page) { + /* First page is special */ + ns->prp1 =3D (void*)base; + first_page =3D 0; + continue; + } + if (nvme_add_prpl(ns, base)) + return -1; + } + + return 0; +} + static int nvme_create_io_queues(struct nvme_ctrl *ctrl) { @@ -668,6 +727,11 @@ nvme_cmd_readwrite(struct nvme_namespace *ns, struct d= isk_op_s *op, int write) u16 const max_blocks =3D NVME_PAGE_SIZE / ns->block_size; u16 i; =20 + if (!nvme_build_prpl(ns, op)) { + /* Request goes via PRP List logic */ + return nvme_io_readwrite(ns, op->lba, ns->prp1, op->count, write); + } + for (i =3D 0; i < op->count && res =3D=3D DISK_RET_SUCCESS;) { u16 blocks_remaining =3D op->count - i; u16 blocks =3D blocks_remaining < max_blocks ? blocks_remaining --=20 2.16.4 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org