From patchwork Tue Aug 20 08:36:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Williams X-Patchwork-Id: 1149923 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=marvell.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=marvell.com header.i=@marvell.com header.b="Io02WPFR"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46CPLY6Xw5z9s3Z for ; Tue, 20 Aug 2019 18:37:41 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 7EB50C21EE8; Tue, 20 Aug 2019 08:37:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id C4D0AC21F75; Tue, 20 Aug 2019 08:37:18 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CA9E4C21F8C; Tue, 20 Aug 2019 08:37:03 +0000 (UTC) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by lists.denx.de (Postfix) with ESMTPS id 6E3A4C21F38 for ; Tue, 20 Aug 2019 08:37:01 +0000 (UTC) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x7K8XhOd002994 for ; Tue, 20 Aug 2019 01:36:59 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0818; bh=i3KC+fIItPjzQDeD/4NNDBe3otqwQqaXO1F8asYRzqg=; b=Io02WPFRpGb8ubplhUsiVsH18RAaS7qrLpPKuflmjuH/OC3qCTyFk4T8KTSaZ1841J9n e8/k9Zb0eUgqX2pB0nsvLhK+GOCNfIV3VGWdNqbIn5duCAVK/rBJGNyLSQ3Rm1U6wB/L PrsyNXqoa+9SkUHD7Nca5FEaqX/G5NrDoOzh+DC5Z2SgVdGaLrpuExf/g+2DpjwVpGN1 lxD4u1GcuVsbEjnYtet3cplz9Qk6RDKCzLMGCGtIZ2oKNaOpfsF/HBE/lnBGFSWcSIP1 bu42kiJEpbwxFCdiQ8JhG27Bg1ptgcHDV/dwylzeEaB1yiug3PmocdEhAdwzdJWC+ON1 eA== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0b-0016f401.pphosted.com with ESMTP id 2ug8d7909b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 20 Aug 2019 01:36:59 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 20 Aug 2019 01:36:58 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 20 Aug 2019 01:36:58 -0700 Received: from marvell.com (unknown [10.85.93.181]) by maili.marvell.com (Postfix) with ESMTP id C4B3B3F703F; Tue, 20 Aug 2019 01:36:57 -0700 (PDT) From: Aaron Williams To: Date: Tue, 20 Aug 2019 01:36:33 -0700 Message-ID: <20190820083633.9826-2-awilliams@marvell.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190820083633.9826-1-awilliams@marvell.com> References: <20190820083633.9826-1-awilliams@marvell.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:5.22.84,1.0.8 definitions=2019-08-20_03:2019-08-19,2019-08-20 signatures=0 Subject: [U-Boot] [PATCH 1/1] nvme: Fix PRP Offset Invalid X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" When large writes take place I saw a Samsung EVO 970+ return a status value of 0x13, PRP Offset Invalid. I tracked this down to the improper handling of PRP entries. The blocks the PRP entries are placed in cannot cross a page boundary and thus should be allocated on page boundaries. This is how the Linux kernel driver works. With this patch, the PRP pool is allocated on a page boundary and other than the very first allocation, the pool size is a multiple of the page size. Each page can hold (4096 / 8) - 1 entries since the last entry must point to the next page in the pool. Signed-off-by: Aaron Williams --- drivers/nvme/nvme.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) -- 2.16.4 diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c index 7008a54a6d..ae64459edf 100644 --- a/drivers/nvme/nvme.c +++ b/drivers/nvme/nvme.c @@ -75,6 +75,8 @@ static int nvme_setup_prps(struct nvme_dev *dev, u64 *prp2, int length = total_len; int i, nprps; length -= (page_size - offset); + u32 prps_per_page = (page_size >> 3) - 1; + u32 num_pages; if (length <= 0) { *prp2 = 0; @@ -90,15 +92,16 @@ static int nvme_setup_prps(struct nvme_dev *dev, u64 *prp2, } nprps = DIV_ROUND_UP(length, page_size); + num_pages = (nprps + prps_per_page - 1) / prps_per_page; if (nprps > dev->prp_entry_num) { free(dev->prp_pool); - dev->prp_pool = malloc(nprps << 3); + dev->prp_pool = memalign(page_size, num_pages * page_size); if (!dev->prp_pool) { printf("Error: malloc prp_pool fail\n"); return -ENOMEM; } - dev->prp_entry_num = nprps; + dev->prp_entry_num = ((page_size >> 3) - 1) * num_pages; } prp_pool = dev->prp_pool; @@ -791,7 +794,7 @@ static int nvme_probe(struct udevice *udev) } memset(ndev->queues, 0, NVME_Q_NUM * sizeof(struct nvme_queue *)); - ndev->prp_pool = malloc(MAX_PRP_POOL); + ndev->prp_pool = memalign(1 << 12, MAX_PRP_POOL); if (!ndev->prp_pool) { ret = -ENOMEM; printf("Error: %s: Out of memory!\n", udev->name);