From patchwork Tue Jan 19 15:01:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: adamsomerville@gmail.com X-Patchwork-Id: 570006 X-Patchwork-Delegate: cyrille.pitchen@atmel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3BEEC140BAE for ; Wed, 20 Jan 2016 02:04:39 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=JlP2AwKt; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aLXnm-0000S7-Fh; Tue, 19 Jan 2016 15:02:34 +0000 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aLXnf-0000JO-Gb for linux-mtd@lists.infradead.org; Tue, 19 Jan 2016 15:02:28 +0000 Received: by mail-wm0-x233.google.com with SMTP id 123so95112278wmz.0 for ; Tue, 19 Jan 2016 07:02:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=2R+O4z3idLqN7qKrt85tx7nwXRp2n4YLdV8ZzTEZ6sw=; b=JlP2AwKtEumZ6eXLX6iTkbUHbEWw74vaEERSbcWP8OTMWoiUv3gdRBilyCvhbAebNz jU5aZmjGxsjBI18ksyUHw9n76KZBW97ljO94j6I3S2wod6C/a7+fJdyIaG3GLmu0gfGS qkBbY8xbtNO3PK8EbtI7m0B/Us/KwLPsBSh+mK546AXrx3ILiVAz6UdHCySS5TNOIBr4 thpQLidAACT9c8vqRxNB87tp9ZhFEhGwx4tHuOkBN8wmpVNuMjZPseNOBNZuwPYKLfez gaVm24tm0XaZKRXBR8ZFTsWazHKcnYXZteeO+Nfl7KaDu0gfCrCjU7+BjHGaSVuGUqCs jOng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=2R+O4z3idLqN7qKrt85tx7nwXRp2n4YLdV8ZzTEZ6sw=; b=XzusBxWilqbFAO22/SkRjLTvN+KVdYcaojt8NOznTimugr8RUYtxzbhOSjV0ZoKaIv tFlzG6LVJnJPMnHGl2YMx0i9XTruBBIgNLnuhwceM+bzd4+oyN94JctFaPv+qcNKc7N4 ZOk6p+96MhYhOkN1boVXw18/Vn2R4pZigYbT3JUW/BVq0k6xTDtMSxuOc1Q+y4ocqTos rPLmIFi3NJbeRmPJ9hz4yqDvRErit9Bp1Uw/8wxt/aV8/cyhzARYG8ClqJdUJxhjQaul 0PZLYulWXJXZ0Sos1QyG1aB3xPGwgakf4IMF8HygkmRxbMReWnvFsUQ9hPcUL5aedDVL JBuw== X-Gm-Message-State: ALoCoQkYdR8yh0gJI/whROYScKOGBj60D/GfbESKv05j15pgSwr44IKUtWR0b4ArAWUF0CjmSlrLZSuh2Pjawc4fnnqC/l/JSQ== X-Received: by 10.194.175.104 with SMTP id bz8mr28903473wjc.8.1453215725512; Tue, 19 Jan 2016 07:02:05 -0800 (PST) Received: from adams-ubuntu.BCFT.local ([31.216.13.178]) by smtp.gmail.com with ESMTPSA id g187sm20830814wmf.8.2016.01.19.07.02.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jan 2016 07:02:04 -0800 (PST) From: adamsomerville@gmail.com To: David Woodhouse , Brian Norris Subject: [RFC] spi-nor: fix cross die reads on Micron multi-die devices Date: Tue, 19 Jan 2016 15:01:50 +0000 Message-Id: <1453215710-10803-1-git-send-email-adamsomerville@gmail.com> X-Mailer: git-send-email 1.7.9.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160119_070227_894779_B7A7BF0E X-CRM114-Status: GOOD ( 15.26 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:233 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (adamsomerville[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Boris Brezillon , Furquan Shaikh , Adam Somerville , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , linux-kernel@vger.kernel.org, Gabor Juhos , linux-mtd@lists.infradead.org, Jagan Teki , Mika Westerberg MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Adam Somerville So as far as I can see there is a bug in the spi-nor driver when issuing die boundary crossing reads on Micron multi-die devices. Micron N25Q512A, N25Q00AA and probably any other Micron multi-die devices do not support a single read request that crosses a die boundary. The current behaviour is that the address on the device wraps back to the start of the first die, with any data returned beyond the boundary being from the start of the first die. To reproduce run: (assuming mtd0 is at offset 0 and spans across die boundary) mtd_debug read /dev/mtd0 0x1FFFFF0 32 bad and compare to: mtd_debug read /dev/mtd0 0x1FFFFF0 16 good1 mtd_debug read /dev/mtd0 0x2000000 16 good2 Instead we should split the read request in to 1 read per die. Tested on Cyclone 5 SOC with cadence-qspi connected to Micron n25q512ax3 Signed-off-by: Adam Somerville --- drivers/mtd/spi-nor/spi-nor.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index ed0c19c..68dc20e 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -903,10 +903,19 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor) return ERR_PTR(-ENODEV); } +/* + * Micron multi-die devices do not support cross die boundary + * reads. Split the read request in to 1 read per die + */ +#define MIN_READ_BOUNDARY 0x2000000 +#define DIST_TO_BOUNDARY(x) \ + (MIN_READ_BOUNDARY - ((u32)x & (MIN_READ_BOUNDARY - 1))) + static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { struct spi_nor *nor = mtd_to_spi_nor(mtd); + size_t read_len; int ret; dev_dbg(nor->dev, "from 0x%08x, len %zd\n", (u32)from, len); @@ -915,7 +924,17 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, if (ret) return ret; - ret = nor->read(nor, from, len, retlen, buf); + do { + read_len = min(len, DIST_TO_BOUNDARY(from)); + + ret = nor->read(nor, from, read_len, retlen, buf); + if (ret) + break; + + from += read_len; + buf += read_len; + len -= read_len; + } while (len > 0); spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_READ); return ret;