From nobody Sat May 18 05:53:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=koconnor.net Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1642783764348687.6947838138422; Fri, 21 Jan 2022 08:49:24 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id AD9D716E418E; Fri, 21 Jan 2022 16:49:20 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 73EE316E3D81 for ; Fri, 21 Jan 2022 16:48:52 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) for ; Fri, 21 Jan 2022 08:48:52 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.gmail.com with ESMTPSA id bm23sm3449898qkb.25.2022.01.21.08.48.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 08:48:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=koconnor.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=igSHZxt3ASSo8G/QjrDsmbT72hNVMb6je9WpGtT1nus=; b=CR6xwYTEzNSLIY6SNmtUaMM004+9wjYyHwVHyIUlzHoLx22ew/lr84Tp9UeYMgKfUk Z3nIEdKcV/d9YvEmrXUobKhsUFwQn5ux8DMuglq02DjhNsct9gdb8iVqacyyCJsWddHE GS745fIAWulWC/zPQ9VlM9RiN+9iZvoTOZY4Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=igSHZxt3ASSo8G/QjrDsmbT72hNVMb6je9WpGtT1nus=; b=dTyRuTy8TBlzWCyCSJgywJXqAcVHcLbkFgKm0YBBMXkX+PfEdwM1H+ql46KpZ47sf+ DtlHCq6rG9AEFtiYBt4bVYqwlp+WQ/MAGJdztHOyVTmrtLevlqeL1hwcseevUVyhdsDk 5DcvSWeR/b13DXWgfOPplnRDmSEsnFRnsiLaw9qkLTsR9d4W5/L6yAYuVWVtRhHhxzxH xxecVbQOIAFiT9WC0xM1BoNwd0YVl7Gn5zZZlXx4LpYpxcX7tdq5btS7nY9fDsfUJKzk GOx/IBuBi7uj24dTOdeOs14gtHht8v5yzIi4X1zt+VBkChmCYe+c+5xNbTdUOX/7YpCU AUFA== X-Gm-Message-State: AOAM530BHknVcuWX6Cm8DfgxWCBrTQSWEECKX5fwt+3sy/qD0IX7aYrV NqGWHrO3kzcYO8n2EnkRx17SjSWIiE40zA== X-Google-Smtp-Source: ABdhPJznBBiK8TO+DMs6PGQr5LfIUK3+5e7bzBiChZJgGVVYqpd3A28VKtZa9k8LoIeatgF9iyP8Ww== X-Received: by 2002:ad4:576e:: with SMTP id r14mr4428833qvx.99.1642783731201; Fri, 21 Jan 2022 08:48:51 -0800 (PST) From: Kevin O'Connor To: seabios@seabios.org Date: Fri, 21 Jan 2022 11:48:43 -0500 Message-Id: <20220121164848.2000294-2-kevin@koconnor.net> In-Reply-To: <20220121164848.2000294-1-kevin@koconnor.net> References: <20220121164848.2000294-1-kevin@koconnor.net> MIME-Version: 1.0 X-Spam-Level: ** Message-ID-Hash: U3ZL6ST32LTLGPBH5NYJVAROO3TFYHLZ X-Message-ID-Hash: U3ZL6ST32LTLGPBH5NYJVAROO3TFYHLZ X-MailFrom: kevin@koconnor.net 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; digests; suspicious-header CC: Alexander Graf X-Mailman-Version: 3.3.5rc1 Precedence: list Subject: [SeaBIOS] [PATCHv2 1/6] nvme: Rework nvme_io_readwrite() to return -1 on error List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: 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) X-ZM-MESSAGEID: 1642783766616100001 Content-Type: text/plain; charset="utf-8" Rename nvme_io_readwrite() to nvme_io_xfer() and change it so it implements the debugging dprintf() and it returns -1 on an error. Signed-off-by: Kevin O'Connor Reviewed-by: Alexander Graf --- src/hw/nvme.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/hw/nvme.c b/src/hw/nvme.c index f035fa2..608651a 100644 --- a/src/hw/nvme.c +++ b/src/hw/nvme.c @@ -414,11 +414,10 @@ err: return -1; } =20 -/* Reads count sectors into buf. Returns DISK_RET_*. The buffer cannot cro= ss - page boundaries. */ +/* Reads count sectors into buf. The buffer cannot cross page boundaries. = */ static int -nvme_io_readwrite(struct nvme_namespace *ns, u64 lba, char *buf, u16 count, - int write) +nvme_io_xfer(struct nvme_namespace *ns, u64 lba, void *buf, u16 count, + int write) { u32 buf_addr =3D (u32)buf; void *prp2; @@ -426,7 +425,7 @@ nvme_io_readwrite(struct nvme_namespace *ns, u64 lba, c= har *buf, u16 count, if (buf_addr & 0x3) { /* Buffer is misaligned */ warn_internalerror(); - return DISK_RET_EBADTRACK; + return -1; } =20 if ((ns->block_size * count) > (NVME_PAGE_SIZE * 2)) { @@ -457,10 +456,12 @@ nvme_io_readwrite(struct nvme_namespace *ns, u64 lba,= char *buf, u16 count, dprintf(2, "read io: %08x %08x %08x %08x\n", cqe.dword[0], cqe.dword[1], cqe.dword[2], cqe.dword[3]); =20 - return DISK_RET_EBADTRACK; + return -1; } =20 - return DISK_RET_SUCCESS; + dprintf(5, "ns %u %s lba %llu+%u\n", ns->ns_id, write ? "write" : "rea= d", + lba, count); + return count; } =20 static void nvme_reset_prpl(struct nvme_namespace *ns) @@ -716,20 +717,18 @@ nvme_scan(void) static int nvme_cmd_readwrite(struct nvme_namespace *ns, struct disk_op_s *op, int wr= ite) { - int res =3D DISK_RET_SUCCESS; u16 const max_blocks =3D NVME_PAGE_SIZE / ns->block_size; u16 i, blocks; =20 - for (i =3D 0; i < op->count && res =3D=3D DISK_RET_SUCCESS;) { + for (i =3D 0; i < op->count;) { u16 blocks_remaining =3D op->count - i; char *op_buf =3D op->buf_fl + i * ns->block_size; =20 blocks =3D nvme_build_prpl(ns, op_buf, blocks_remaining); if (blocks) { - res =3D nvme_io_readwrite(ns, op->lba + i, ns->prp1, blocks, w= rite); - dprintf(5, "ns %u %s lba %llu+%u: %d\n", ns->ns_id, write ? "w= rite" - : "r= ead", - op->lba, blocks, res); + int res =3D nvme_io_xfer(ns, op->lba + i, ns->prp1, blocks, wr= ite); + if (res < 0) + return DISK_RET_EBADTRACK; } else { blocks =3D blocks_remaining < max_blocks ? blocks_remaining : max_blocks; @@ -738,12 +737,12 @@ nvme_cmd_readwrite(struct nvme_namespace *ns, struct = disk_op_s *op, int write) memcpy(ns->dma_buffer, op_buf, blocks * ns->block_size); } =20 - res =3D nvme_io_readwrite(ns, op->lba + i, ns->dma_buffer, blo= cks, write); - dprintf(5, "ns %u %s lba %llu+%u: %d\n", ns->ns_id, write ? "w= rite" - : "r= ead", - op->lba + i, blocks, res); + int res =3D nvme_io_xfer(ns, op->lba + i, ns->dma_buffer, + blocks, write); + if (res < 0) + return DISK_RET_EBADTRACK; =20 - if (!write && res =3D=3D DISK_RET_SUCCESS) { + if (!write) { memcpy(op_buf, ns->dma_buffer, blocks * ns->block_size); } } @@ -751,7 +750,7 @@ nvme_cmd_readwrite(struct nvme_namespace *ns, struct di= sk_op_s *op, int write) i +=3D blocks; } =20 - return res; + return DISK_RET_SUCCESS; } =20 int --=20 2.31.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org From nobody Sat May 18 05:53:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=koconnor.net Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 16427837777166.761083707746025; Fri, 21 Jan 2022 08:49:37 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id E046616E4191; Fri, 21 Jan 2022 16:49:33 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 35D3816E3D81 for ; Fri, 21 Jan 2022 16:48:53 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) for ; Fri, 21 Jan 2022 08:48:53 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.gmail.com with ESMTPSA id d8sm3480466qtd.70.2022.01.21.08.48.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 08:48:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=koconnor.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LOKd+qQzuaC1bfJvJ4wRj7PQ2Gg8BD4v/mdBvCmQ4uA=; b=eJhuqPIODKKRhkEyguWuvqzjPXevuyXuL6V2DIpONKy3uLvqeF9naZYN4DuD26TEFk 1bsyNacUlN1LOQSmlvo2K7p54KK2WxnA2hGK9hXlq5LDXE8XF3pOZZaIxtZzVXhllRIN fM/KQYv5GVk+ZglFYOJkCzc9p4XL7iNSY+Glc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LOKd+qQzuaC1bfJvJ4wRj7PQ2Gg8BD4v/mdBvCmQ4uA=; b=S+OPdPGS2UgtIZRCbg/PZjS87JZKFpUR9mYKelqGU57GFh1UP6SajDScldTG/uzVtn 5cgKYwHCGs+uyt0nMmPBghV81MTT5MU6YQGHyBP6GVtJEea4XDi9/3wukMpgEzSKJhVk aPSPK5XLDTt5Nk5m5aMGkJKxi7HgeYCT7BubIFytHS+X5gN1E2RDfjHC5wFLlVOi2616 +ytSJ0Dw6XjCYx8YzbyTanXJmtDE6K76pcFYq68leyRJU6W38DLvcpmuO/2s5TEc0sJN XHEaiH+o1V8yzkVjbc+unedxgieYZKxw2A5eX0ieSB+0iVATKEOGbn4p2PILb4s7gfy3 KCGA== X-Gm-Message-State: AOAM531uCinNCdxnMiODiorDKsCggIDUBCZilyW4mr2xnHcYUQ/qTiBM zOvt72xWC0sibf88O3A3qLNP2WHWvvm9oA== X-Google-Smtp-Source: ABdhPJyDZDf/LQxNpOQJ/hdnO1vYzH5RhEJctGVAh49ZbyjPm4RPhUNbuQdsOPwuomTJDGcSEAbp5g== X-Received: by 2002:ad4:4589:: with SMTP id x9mr4556814qvu.27.1642783732013; Fri, 21 Jan 2022 08:48:52 -0800 (PST) From: Kevin O'Connor To: seabios@seabios.org Date: Fri, 21 Jan 2022 11:48:44 -0500 Message-Id: <20220121164848.2000294-3-kevin@koconnor.net> In-Reply-To: <20220121164848.2000294-1-kevin@koconnor.net> References: <20220121164848.2000294-1-kevin@koconnor.net> MIME-Version: 1.0 X-Spam-Level: ** Message-ID-Hash: AJCGQ5V47LPTOZDUTCV24QM7QDNXWA4V X-Message-ID-Hash: AJCGQ5V47LPTOZDUTCV24QM7QDNXWA4V X-MailFrom: kevin@koconnor.net 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; digests; suspicious-header CC: Alexander Graf X-Mailman-Version: 3.3.5rc1 Precedence: list Subject: [SeaBIOS] [PATCHv2 2/6] nvme: Add nvme_bounce_xfer() helper function List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: 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) X-ZM-MESSAGEID: 1642783779432100001 Content-Type: text/plain; charset="utf-8" Move bounce buffer processing to a new helper function. Signed-off-by: Kevin O'Connor Reviewed-by: Alexander Graf --- src/hw/nvme.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/hw/nvme.c b/src/hw/nvme.c index 608651a..d656e9b 100644 --- a/src/hw/nvme.c +++ b/src/hw/nvme.c @@ -464,6 +464,25 @@ nvme_io_xfer(struct nvme_namespace *ns, u64 lba, void = *buf, u16 count, return count; } =20 +// Transfer up to one page of data using the internal dma bounce buffer +static int +nvme_bounce_xfer(struct nvme_namespace *ns, u64 lba, void *buf, u16 count, + int write) +{ + u16 const max_blocks =3D NVME_PAGE_SIZE / ns->block_size; + u16 blocks =3D count < max_blocks ? count : max_blocks; + + if (write) + memcpy(ns->dma_buffer, buf, blocks * ns->block_size); + + int res =3D nvme_io_xfer(ns, lba, ns->dma_buffer, blocks, write); + + if (!write && res >=3D 0) + memcpy(buf, ns->dma_buffer, res * ns->block_size); + + return res; +} + static void nvme_reset_prpl(struct nvme_namespace *ns) { ns->prpl_len =3D 0; @@ -717,7 +736,6 @@ nvme_scan(void) static int nvme_cmd_readwrite(struct nvme_namespace *ns, struct disk_op_s *op, int wr= ite) { - u16 const max_blocks =3D NVME_PAGE_SIZE / ns->block_size; u16 i, blocks; =20 for (i =3D 0; i < op->count;) { @@ -730,21 +748,10 @@ nvme_cmd_readwrite(struct nvme_namespace *ns, struct = disk_op_s *op, int write) if (res < 0) return DISK_RET_EBADTRACK; } else { - blocks =3D blocks_remaining < max_blocks ? blocks_remaining - : max_blocks; - - if (write) { - memcpy(ns->dma_buffer, op_buf, blocks * ns->block_size); - } - - int res =3D nvme_io_xfer(ns, op->lba + i, ns->dma_buffer, - blocks, write); + int res =3D nvme_bounce_xfer(ns, op->lba + i, op_buf, blocks, = write); if (res < 0) return DISK_RET_EBADTRACK; - - if (!write) { - memcpy(op_buf, ns->dma_buffer, blocks * ns->block_size); - } + blocks =3D res; } =20 i +=3D blocks; --=20 2.31.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org From nobody Sat May 18 05:53:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=koconnor.net Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1642783792118767.370692451092; Fri, 21 Jan 2022 08:49:52 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 29D0016E4194; Fri, 21 Jan 2022 16:49:48 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 1F53E16E3D81 for ; Fri, 21 Jan 2022 16:48:54 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) for ; Fri, 21 Jan 2022 08:48:53 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.gmail.com with ESMTPSA id m144sm3198706qke.37.2022.01.21.08.48.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 08:48:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=koconnor.net; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=I+UV7q/4V6C2AYowtgm3Rcxp3O18CcAHf5gUk3KTblk=; b=VKKaNRZw7usHQ1etqVMDaZ1eVjRXvFJNV/kTg74Ound61Ar8Gk6loMoZj+bfLQ1L5h /p/bWC4yQmVZTtllE3HifM4ar4kY964z9XXbUPnHzsLpLD5P4/k6yICW7Pw4P5WUhgN1 7SLpmH4OshFjkL14igeZFK/ZCJPPc9N2UXHHs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I+UV7q/4V6C2AYowtgm3Rcxp3O18CcAHf5gUk3KTblk=; b=o27238S4zOIlhXUqJygm23WSBlDkEX7lIJscaFmO1ovzym0VMoSioqzMtYGEnnooSO Gffua/h8Q1Iv6x+k1ZUSB7s/2TerQTSISdBpN7i2AhGQ9MgNasffgA/yn83K9VKQIVJz nmZ0Xh2UUYIQBeewXPuWpBuiOmCEjUSybMllGAFdDWqH5mnqq29XDcUswM6TiBWEiKtI FgMkmczPpPOeqSfWfTXGEVKGsGGljB/j2/VH0rryswksFq9/GughZmRpLPvna1mPVtpY nVDDWe/EJxvAWg1uURuwet0CXQz1qHh+TxCKghvBC+AYUg0L+kQAMNdocxsKmhe5cY+5 riQg== X-Gm-Message-State: AOAM5321/aAL3WHeNIoBjD1hXrFmS8WLlL7MOxdY9LF/0LT9zfjfpO6P t3sCc9GTEbpiMW3YDtXivk5hCaVDdggP6Q== X-Google-Smtp-Source: ABdhPJwbTroy4ULtRl3cRPFD1/q5jwnBcxE2J+kt2RfKq5YmzdwWwdygCw+J8/5P7CqcFWS0iFE62g== X-Received: by 2002:a05:622a:1981:: with SMTP id u1mr3907592qtc.491.1642783732922; Fri, 21 Jan 2022 08:48:52 -0800 (PST) From: Kevin O'Connor To: seabios@seabios.org Date: Fri, 21 Jan 2022 11:48:45 -0500 Message-Id: <20220121164848.2000294-4-kevin@koconnor.net> In-Reply-To: <20220121164848.2000294-1-kevin@koconnor.net> References: <20220121164848.2000294-1-kevin@koconnor.net> MIME-Version: 1.0 X-Spam-Level: ** Message-ID-Hash: FSP3C3TC7MRBUMMQJOWYRCQRAKRCCQBH X-Message-ID-Hash: FSP3C3TC7MRBUMMQJOWYRCQRAKRCCQBH X-MailFrom: kevin@koconnor.net 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; digests; suspicious-header X-Mailman-Version: 3.3.5rc1 Precedence: list Subject: [SeaBIOS] [PATCHv2 3/6] nvme: Convert nvme_build_prpl() to nvme_prpl_xfer() List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: 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) X-ZM-MESSAGEID: 1642783794330100001 Content-Type: text/plain; charset="utf-8" Rename nvme_build_prpl() to nvme_prpl_xfer() and directly invoke nvme_io_xfer() or nvme_bounce_xfer() from that function. Signed-off-by: Kevin O'Connor Reviewed-by: Alexander Graf --- src/hw/nvme-int.h | 1 - src/hw/nvme.c | 46 ++++++++++++++++++++-------------------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/hw/nvme-int.h b/src/hw/nvme-int.h index a4c1555..9564c17 100644 --- a/src/hw/nvme-int.h +++ b/src/hw/nvme-int.h @@ -125,7 +125,6 @@ struct nvme_namespace { =20 /* Page List */ u32 prpl_len; - void *prp1; u64 prpl[NVME_MAX_PRPL_ENTRIES]; }; =20 diff --git a/src/hw/nvme.c b/src/hw/nvme.c index d656e9b..eee7d17 100644 --- a/src/hw/nvme.c +++ b/src/hw/nvme.c @@ -498,10 +498,13 @@ static int nvme_add_prpl(struct nvme_namespace *ns, u= 64 base) return 0; } =20 -static int nvme_build_prpl(struct nvme_namespace *ns, void *op_buf, u16 co= unt) +// Transfer data using page list (if applicable) +static int +nvme_prpl_xfer(struct nvme_namespace *ns, u64 lba, void *buf, u16 count, + int write) { int first_page =3D 1; - u32 base =3D (long)op_buf; + u32 base =3D (long)buf; s32 size; =20 if (count > ns->max_req_size) @@ -511,31 +514,32 @@ static int nvme_build_prpl(struct nvme_namespace *ns,= void *op_buf, u16 count) =20 size =3D count * ns->block_size; /* 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; - return count; - } + if (((size + (base & ~NVME_PAGE_MASK)) <=3D NVME_PAGE_SIZE)) + return nvme_io_xfer(ns, lba, buf, count, write); =20 /* Every request has to be page aligned */ if (base & ~NVME_PAGE_MASK) - return 0; + goto bounce; =20 /* Make sure a full block fits into the last chunk */ if (size & (ns->block_size - 1ULL)) - return 0; + goto bounce; =20 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 0; + goto bounce; } =20 - return count; + return nvme_io_xfer(ns, lba, buf, count, write); + +bounce: + /* Use bounce buffer to make transfer */ + return nvme_bounce_xfer(ns, lba, buf, count, write); } =20 static int @@ -736,24 +740,14 @@ nvme_scan(void) static int nvme_cmd_readwrite(struct nvme_namespace *ns, struct disk_op_s *op, int wr= ite) { - u16 i, blocks; - + int i; for (i =3D 0; i < op->count;) { u16 blocks_remaining =3D op->count - i; char *op_buf =3D op->buf_fl + i * ns->block_size; - - blocks =3D nvme_build_prpl(ns, op_buf, blocks_remaining); - if (blocks) { - int res =3D nvme_io_xfer(ns, op->lba + i, ns->prp1, blocks, wr= ite); - if (res < 0) - return DISK_RET_EBADTRACK; - } else { - int res =3D nvme_bounce_xfer(ns, op->lba + i, op_buf, blocks, = write); - if (res < 0) - return DISK_RET_EBADTRACK; - blocks =3D res; - } - + int blocks =3D nvme_prpl_xfer(ns, op->lba + i, op_buf, + blocks_remaining, write); + if (blocks < 0) + return DISK_RET_EBADTRACK; i +=3D blocks; } =20 --=20 2.31.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org From nobody Sat May 18 05:53:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=koconnor.net Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 16427838049681004.3205968993769; Fri, 21 Jan 2022 08:50:04 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 145F716E4196; Fri, 21 Jan 2022 16:50:00 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id D7C5516E3D81 for ; Fri, 21 Jan 2022 16:48:54 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) for ; Fri, 21 Jan 2022 08:48:54 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.gmail.com with ESMTPSA id de15sm3278112qkb.4.2022.01.21.08.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 08:48:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=koconnor.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8K2XFJDza5yFFi0J5mpeJJRR4n4W6t719sA2FYfGxQE=; b=b5SrFXUcsTJWqcwr8h69jesYY6Rnry8iZuAh4ErqrUD5B99n5zFxjPfPRazE8EEkA6 OXqLqiGPkrD9jBHEs62xVgiALrYohxf8ZroatKLiD/wPuT8Kqha4+WzmvWbxQHsCeeSc NWGhWyPTm9I6IP4+VmUrzJZ1a0yJfSMMSArMo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8K2XFJDza5yFFi0J5mpeJJRR4n4W6t719sA2FYfGxQE=; b=MlnQv7mrwFo/E9NVrsmJGFn8C4lGUrVNWpelG+NfgfhPSV3HaTZKY1bV6K0849TxZl x0D4HEmZbk0enhWlck+vtoEdW22lPQBeWmiLF8C8vArm52NfqzxqL65YDrJZvMzt3rvg KwtzRVhCQElZycgdsDfzjphEIvdlAcEuVwZhKINfT7BfA6785F3vQUa6xrKY3jlCceyt q43MCErniehE+GYRM0bLRxuZmMHMCvuHHmoAUt9hpuvRS6uvCOT86/DxEhLsUfi4Bo3x Z8citnbiK9iKSGPwTCnjQgIwViyvkki84p1gpgjGiohkTlL3oGesFqdh/489+2iK99H/ x6Ew== X-Gm-Message-State: AOAM532XtWKi1dyQKaYRF3kDtEL7KlY66mbYTDf1Xs2MUqpkcpwAZPLs 0u6zLivcU/GzcYHoC5cCbgXAkHuf28eJjg== X-Google-Smtp-Source: ABdhPJzmV0s/6Up+251viZFrXSFI7k46B1xO+5CgnG7ggzqyDDE/0uP9GX0hNkb1TIhjFcJX61pXUg== X-Received: by 2002:a05:6214:20aa:: with SMTP id 10mr4567763qvd.40.1642783733788; Fri, 21 Jan 2022 08:48:53 -0800 (PST) From: Kevin O'Connor To: seabios@seabios.org Date: Fri, 21 Jan 2022 11:48:46 -0500 Message-Id: <20220121164848.2000294-5-kevin@koconnor.net> In-Reply-To: <20220121164848.2000294-1-kevin@koconnor.net> References: <20220121164848.2000294-1-kevin@koconnor.net> MIME-Version: 1.0 X-Spam-Level: *** Message-ID-Hash: MHJYOAVTLMMHAIOFYUWTLSV27HVYXTTM X-Message-ID-Hash: MHJYOAVTLMMHAIOFYUWTLSV27HVYXTTM X-MailFrom: kevin@koconnor.net 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; digests; suspicious-header CC: Alexander Graf X-Mailman-Version: 3.3.5rc1 Precedence: list Subject: [SeaBIOS] [PATCHv2 4/6] nvme: Pass prp1 and prp2 directly to nvme_io_xfer() List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: 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) X-ZM-MESSAGEID: 1642783806658100001 Content-Type: text/plain; charset="utf-8" When using a prp2 parameter, build it in nvme_prpl_xfer() and pass it directly to nvme_io_xfer(). Signed-off-by: Kevin O'Connor Reviewed-by: Alexander Graf --- src/hw/nvme.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/hw/nvme.c b/src/hw/nvme.c index eee7d17..20976fc 100644 --- a/src/hw/nvme.c +++ b/src/hw/nvme.c @@ -416,33 +416,19 @@ err: =20 /* Reads count sectors into buf. The buffer cannot cross page boundaries. = */ static int -nvme_io_xfer(struct nvme_namespace *ns, u64 lba, void *buf, u16 count, - int write) +nvme_io_xfer(struct nvme_namespace *ns, u64 lba, void *prp1, void *prp2, + u16 count, int write) { - u32 buf_addr =3D (u32)buf; - void *prp2; - - if (buf_addr & 0x3) { + if (((u32)prp1 & 0x3) || ((u32)prp2 & 0x3)) { /* Buffer is misaligned */ warn_internalerror(); return -1; } =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, prp2); + NULL, prp1, prp2); io_read->nsid =3D ns->ns_id; io_read->dword[10] =3D (u32)lba; io_read->dword[11] =3D (u32)(lba >> 32); @@ -475,7 +461,7 @@ nvme_bounce_xfer(struct nvme_namespace *ns, u64 lba, vo= id *buf, u16 count, if (write) memcpy(ns->dma_buffer, buf, blocks * ns->block_size); =20 - int res =3D nvme_io_xfer(ns, lba, ns->dma_buffer, blocks, write); + int res =3D nvme_io_xfer(ns, lba, ns->dma_buffer, NULL, blocks, write); =20 if (!write && res >=3D 0) memcpy(buf, ns->dma_buffer, res * ns->block_size); @@ -515,7 +501,7 @@ nvme_prpl_xfer(struct nvme_namespace *ns, u64 lba, void= *buf, u16 count, size =3D count * ns->block_size; /* Special case for transfers that fit into PRP1, but are unaligned */ if (((size + (base & ~NVME_PAGE_MASK)) <=3D NVME_PAGE_SIZE)) - return nvme_io_xfer(ns, lba, buf, count, write); + return nvme_io_xfer(ns, lba, buf, NULL, count, write); =20 /* Every request has to be page aligned */ if (base & ~NVME_PAGE_MASK) @@ -535,7 +521,18 @@ nvme_prpl_xfer(struct nvme_namespace *ns, u64 lba, voi= d *buf, u16 count, goto bounce; } =20 - return nvme_io_xfer(ns, lba, buf, count, write); + void *prp2; + 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; + } + return nvme_io_xfer(ns, lba, buf, prp2, count, write); =20 bounce: /* Use bounce buffer to make transfer */ --=20 2.31.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org From nobody Sat May 18 05:53:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=koconnor.net Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1642783818336351.5927425072118; Fri, 21 Jan 2022 08:50:18 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id A28B616E4179; Fri, 21 Jan 2022 16:50:14 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id B14C116E3D81 for ; Fri, 21 Jan 2022 16:48:55 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) for ; Fri, 21 Jan 2022 08:48:55 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.gmail.com with ESMTPSA id de15sm3278127qkb.4.2022.01.21.08.48.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 08:48:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=koconnor.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j/3SIoXnlni8QvPrfYbqLSpWmklZq4IJ/Ifv7avAi5c=; b=DpYhdWOeayavXCsQ6xfcgQg4DHPZXlQlFmcTKnHqAvL7E30uGZc65+Ky+EeznQokc7 nT9KIk5xVd+Hkj9ZhQJ02lDesI8l+QvRVVUvt96oWzR6slWQBW3g3UwM+Kt9AHNQpx8O 2cGN12fnxcMoJxgYBIyu/kN2nH1qEW6qqv8x8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j/3SIoXnlni8QvPrfYbqLSpWmklZq4IJ/Ifv7avAi5c=; b=bhfBc80re0rnsmUpLHDHbc14gFrBWhisAyPPzQ/wR24xJGfwwei8epBtrnIw5NSBzB wtVEkSvHNaBt//x6jg1s2+GiKYQ1cOO1b/JXZSEasgkF+ItxHCe2qmbVM7kpTWxmjLOv 0ExLSNs1r9v5buBzdG9+ER/+lPrHKaPIi216R0Eur1Zje+GlZ6pEDuwiK3lPa94qwicV NsxV2j6yT2oH57EwtnqTJBtLsdxT/a2RUGEVuKxvaS6BugpX5q2sNkv3eRPtxHbwqrmf HzKivUpM3dMyjPdP5TMU/vg+Vr6CWi158W3SukKj52IcHJNv9pQumgyP3/sfLkokCH3G CuzQ== X-Gm-Message-State: AOAM533yKLroPfGqod3mkMSXhMBAzp4HOFqO8SOTZoIVoviRxoP6Kns3 MYxrYw5YJKkwDSwa3K96C3nq6L5mEOYryg== X-Google-Smtp-Source: ABdhPJyhvJAL5/QtNNzsXVOt4JNft0TNBgGaKGBOdEMidBGbTUroRydiK4OyIrZcEcGTwUecXyMG/Q== X-Received: by 2002:a05:6214:1c09:: with SMTP id u9mr4600994qvc.4.1642783734588; Fri, 21 Jan 2022 08:48:54 -0800 (PST) From: Kevin O'Connor To: seabios@seabios.org Date: Fri, 21 Jan 2022 11:48:47 -0500 Message-Id: <20220121164848.2000294-6-kevin@koconnor.net> In-Reply-To: <20220121164848.2000294-1-kevin@koconnor.net> References: <20220121164848.2000294-1-kevin@koconnor.net> MIME-Version: 1.0 X-Spam-Level: * Message-ID-Hash: T4PHZPJLWPHTVWE7EYQ5YGFAEENXBKYY X-Message-ID-Hash: T4PHZPJLWPHTVWE7EYQ5YGFAEENXBKYY X-MailFrom: kevin@koconnor.net 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; digests; suspicious-header CC: Alexander Graf X-Mailman-Version: 3.3.5rc1 Precedence: list Subject: [SeaBIOS] [PATCHv2 5/6] nvme: Build the page list in the existing dma buffer List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: 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) X-ZM-MESSAGEID: 1642783819066100001 Content-Type: text/plain; charset="utf-8" Commit 01f2736cc905d ("nvme: Pass large I/O requests as PRP lists") introduced multi-page requests using the NVMe PRP mechanism. To store the list and "first page to write to" hints, it added fields to the NVMe namespace struct. Unfortunately, that struct resides in fseg which is read-only at runtime. While KVM ignores the read-only part and allows writes, real hardware and TCG adhere to the semantics and ignore writes to the fseg region. The net effect of that is that reads and writes were always happening on address 0, unless they went through the bounce buffer logic. This patch builds the PRP maintenance data in the existing "dma bounce buffer" and only builds it when needed. Fixes: 01f2736cc905d ("nvme: Pass large I/O requests as PRP lists") Reported-by: Matt DeVillier Signed-off-by: Alexander Graf Signed-off-by: Kevin O'Connor Reviewed-by: Alexander Graf --- src/hw/nvme-int.h | 6 ----- src/hw/nvme.c | 61 +++++++++++++++++++---------------------------- 2 files changed, 24 insertions(+), 43 deletions(-) diff --git a/src/hw/nvme-int.h b/src/hw/nvme-int.h index 9564c17..f0d717d 100644 --- a/src/hw/nvme-int.h +++ b/src/hw/nvme-int.h @@ -10,8 +10,6 @@ #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 @@ -122,10 +120,6 @@ struct nvme_namespace { =20 /* Page aligned buffer of size NVME_PAGE_SIZE. */ char *dma_buffer; - - /* Page List */ - u32 prpl_len; - u64 prpl[NVME_MAX_PRPL_ENTRIES]; }; =20 /* Data structures for NVMe admin identify commands */ diff --git a/src/hw/nvme.c b/src/hw/nvme.c index 20976fc..e9c449d 100644 --- a/src/hw/nvme.c +++ b/src/hw/nvme.c @@ -469,39 +469,23 @@ nvme_bounce_xfer(struct nvme_namespace *ns, u64 lba, = void *buf, u16 count, return res; } =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; -} +#define NVME_MAX_PRPL_ENTRIES 15 /* Allows requests up to 64kb */ =20 // Transfer data using page list (if applicable) static int nvme_prpl_xfer(struct nvme_namespace *ns, u64 lba, void *buf, u16 count, int write) { - int first_page =3D 1; u32 base =3D (long)buf; s32 size; =20 if (count > ns->max_req_size) count =3D ns->max_req_size; =20 - nvme_reset_prpl(ns); - size =3D count * ns->block_size; /* Special case for transfers that fit into PRP1, but are unaligned */ if (((size + (base & ~NVME_PAGE_MASK)) <=3D NVME_PAGE_SIZE)) - return nvme_io_xfer(ns, lba, buf, NULL, count, write); + goto single; =20 /* Every request has to be page aligned */ if (base & ~NVME_PAGE_MASK) @@ -511,28 +495,31 @@ nvme_prpl_xfer(struct nvme_namespace *ns, u64 lba, vo= id *buf, u16 count, if (size & (ns->block_size - 1ULL)) goto bounce; =20 - for (; size > 0; base +=3D NVME_PAGE_SIZE, size -=3D NVME_PAGE_SIZE) { - if (first_page) { - /* First page is special */ - first_page =3D 0; - continue; + /* Build PRP list if we need to describe more than 2 pages */ + if ((ns->block_size * count) > (NVME_PAGE_SIZE * 2)) { + u32 prpl_len =3D 0; + u64 *prpl =3D (void*)ns->dma_buffer; + int first_page =3D 1; + for (; size > 0; base +=3D NVME_PAGE_SIZE, size -=3D NVME_PAGE_SIZ= E) { + if (first_page) { + /* First page is special */ + first_page =3D 0; + continue; + } + if (prpl_len >=3D NVME_MAX_PRPL_ENTRIES) + goto bounce; + prpl[prpl_len++] =3D base; } - if (nvme_add_prpl(ns, base)) - goto bounce; + return nvme_io_xfer(ns, lba, buf, prpl, count, write); } =20 - void *prp2; - 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; - } - return nvme_io_xfer(ns, lba, buf, prp2, count, write); + /* Directly embed the 2nd page if we only need 2 pages */ + if ((ns->block_size * count) > NVME_PAGE_SIZE) + return nvme_io_xfer(ns, lba, buf, buf + NVME_PAGE_SIZE, count, wri= te); + +single: + /* One page is enough, don't expose anything else */ + return nvme_io_xfer(ns, lba, buf, NULL, count, write); =20 bounce: /* Use bounce buffer to make transfer */ --=20 2.31.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org From nobody Sat May 18 05:53:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=koconnor.net Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1642783831890984.7702897801429; Fri, 21 Jan 2022 08:50:31 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 162EF16E419D; Fri, 21 Jan 2022 16:50:27 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 7BC9116E3D81 for ; Fri, 21 Jan 2022 16:48:56 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) for ; Fri, 21 Jan 2022 08:48:56 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.gmail.com with ESMTPSA id p6sm3627180qtx.18.2022.01.21.08.48.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 08:48:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=koconnor.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q9OeCqGWbJcrFbFvXcyGUxfOzdbCz53k1ku2h+yjmIQ=; b=OflhOjl3t52UQcNDuaW30h2D1HoktvXba6zFXoCKpaRkykLVFvt6taodHBFc+lOfYT 3pK0lcFYO940666Ud8KN8WbrrnhVV6jOKXBcmyXuKN5ScSxccZXG0G2B0p4FXq4l12Ch YQVggmhhf12cTzFmkJXQr1cW0Sac6u/Lyr7dI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q9OeCqGWbJcrFbFvXcyGUxfOzdbCz53k1ku2h+yjmIQ=; b=SL+u7GVeTRc6gW9n1hLrL8pM/3cDWbYvgaO4wReYKZZiPpjM9KF0Yl6Tg7XQcAsfzC RiASeRJS1OZQpAccms2gQuK5SW4iCE9KVu+a4wcCBvbPzzhbYuoxBQYmAeWyhBMtB5IB yFN7kqaHK611xEyjrNaQi7hWOCAmF4PX+l/H2AW3aiTJuGK/89FAc0/xsvuaTvXkmcIC nbeYRxuHVo+Wc7D88TN7veN2PKfOGPEtM5caWLHszPiAK6s+ajPtBIaU1FmgzfSm4Zlo oB7o/mkipSwjml74PCCtre++hjGVAVvhDjt3kGQrVRNcH4RoWpnqmW0bQs5uVvvcggwQ sVig== X-Gm-Message-State: AOAM531Lpabn3VHbsRD3O7A6dYLyRK8fIqiqXw0rbBz9VbsB/iSC4Ged YxKe8ttP3bToRn93Cb6oArcvW1xsOkNzAQ== X-Google-Smtp-Source: ABdhPJzwFEtz9DAyxbnoYUL48D1cvvrg6uH25g6g2wnAd7fm/5CnI8dWWBpwsymFn3UkqsHjVt6cpQ== X-Received: by 2002:a05:622a:4d1:: with SMTP id q17mr3855853qtx.593.1642783735409; Fri, 21 Jan 2022 08:48:55 -0800 (PST) From: Kevin O'Connor To: seabios@seabios.org Date: Fri, 21 Jan 2022 11:48:48 -0500 Message-Id: <20220121164848.2000294-7-kevin@koconnor.net> In-Reply-To: <20220121164848.2000294-1-kevin@koconnor.net> References: <20220121164848.2000294-1-kevin@koconnor.net> MIME-Version: 1.0 X-Spam-Level: * Message-ID-Hash: KR4XCBQEZ5UMSC7I4M5AAKTXBZHYYKH5 X-Message-ID-Hash: KR4XCBQEZ5UMSC7I4M5AAKTXBZHYYKH5 X-MailFrom: kevin@koconnor.net 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; digests; suspicious-header CC: Alexander Graf X-Mailman-Version: 3.3.5rc1 Precedence: list Subject: [SeaBIOS] [PATCHv2 6/6] nvme: Only allocate one dma bounce buffer for all nvme drives List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: 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) X-ZM-MESSAGEID: 1642783833679100001 Content-Type: text/plain; charset="utf-8" There is no need to create multiple dma bounce buffers as the BIOS disk code isn't reentrant capable. Also, verify that the allocation succeeds. Signed-off-by: Kevin O'Connor Reviewed-by: Alexander Graf --- src/hw/nvme-int.h | 3 --- src/hw/nvme.c | 21 +++++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/hw/nvme-int.h b/src/hw/nvme-int.h index f0d717d..f9c807e 100644 --- a/src/hw/nvme-int.h +++ b/src/hw/nvme-int.h @@ -117,9 +117,6 @@ struct nvme_namespace { u32 block_size; u32 metadata_size; u32 max_req_size; - - /* Page aligned buffer of size NVME_PAGE_SIZE. */ - char *dma_buffer; }; =20 /* Data structures for NVMe admin identify commands */ diff --git a/src/hw/nvme.c b/src/hw/nvme.c index e9c449d..3dfa0ce 100644 --- a/src/hw/nvme.c +++ b/src/hw/nvme.c @@ -20,6 +20,9 @@ #include "nvme.h" #include "nvme-int.h" =20 +// Page aligned "dma bounce buffer" of size NVME_PAGE_SIZE in high memory +static void *nvme_dma_buffer; + static void * zalloc_page_aligned(struct zone_s *zone, u32 size) { @@ -257,6 +260,14 @@ nvme_probe_ns(struct nvme_ctrl *ctrl, u32 ns_idx, u8 m= dts) goto free_buffer; } =20 + if (!nvme_dma_buffer) { + nvme_dma_buffer =3D zalloc_page_aligned(&ZoneHigh, NVME_PAGE_SIZE); + if (!nvme_dma_buffer) { + warn_noalloc(); + goto free_buffer; + } + } + struct nvme_namespace *ns =3D malloc_fseg(sizeof(*ns)); if (!ns) { warn_noalloc(); @@ -294,8 +305,6 @@ nvme_probe_ns(struct nvme_ctrl *ctrl, u32 ns_idx, u8 md= ts) ns->max_req_size =3D -1U; } =20 - ns->dma_buffer =3D zalloc_page_aligned(&ZoneHigh, NVME_PAGE_SIZE); - char *desc =3D znprintf(MAXDESCSIZE, "NVMe NS %u: %llu MiB (%llu %u-by= te " "blocks + %u-byte metadata)", ns_id, (ns->lba_count * ns->block_size) >> 20, @@ -459,12 +468,12 @@ nvme_bounce_xfer(struct nvme_namespace *ns, u64 lba, = void *buf, u16 count, u16 blocks =3D count < max_blocks ? count : max_blocks; =20 if (write) - memcpy(ns->dma_buffer, buf, blocks * ns->block_size); + memcpy(nvme_dma_buffer, buf, blocks * ns->block_size); =20 - int res =3D nvme_io_xfer(ns, lba, ns->dma_buffer, NULL, blocks, write); + int res =3D nvme_io_xfer(ns, lba, nvme_dma_buffer, NULL, blocks, write= ); =20 if (!write && res >=3D 0) - memcpy(buf, ns->dma_buffer, res * ns->block_size); + memcpy(buf, nvme_dma_buffer, res * ns->block_size); =20 return res; } @@ -498,7 +507,7 @@ nvme_prpl_xfer(struct nvme_namespace *ns, u64 lba, void= *buf, u16 count, /* Build PRP list if we need to describe more than 2 pages */ if ((ns->block_size * count) > (NVME_PAGE_SIZE * 2)) { u32 prpl_len =3D 0; - u64 *prpl =3D (void*)ns->dma_buffer; + u64 *prpl =3D nvme_dma_buffer; int first_page =3D 1; for (; size > 0; base +=3D NVME_PAGE_SIZE, size -=3D NVME_PAGE_SIZ= E) { if (first_page) { --=20 2.31.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org