From nobody Fri Oct 18 06:17:46 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