Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04B05C433FE for ; Wed, 2 Nov 2022 02:34:58 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C86E585074; Wed, 2 Nov 2022 03:34:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fjpyWvkw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 70BA484EEF; Wed, 2 Nov 2022 02:06:12 +0100 (CET) Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6BDE381273 for ; Wed, 2 Nov 2022 02:06:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=liangyanyu13@gmail.com Received: by mail-pj1-x102b.google.com with SMTP id k5so7239189pjo.5 for ; Tue, 01 Nov 2022 18:06:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bMxkz3Y/ev9W3wKi/UG2B+dx9yCn2eWhiHBiqdhTFAU=; b=fjpyWvkwvHe2Vd1PJP6zybGdpQkT8+jhb0wj8KlNKgzx0j1mAxoAOFcVLUMaaTtKZX gl7rWe5IsQ5KTiNP5d6DfGnZhJ6wIIWrMJi3fTs1hPwhTfSoEwC8nt6IrxukTHN8Ckk5 WOWqexqruGh7n9L8V5RqLGFOx82Frm+heMFjXfD+AGcRw8GepjOFmiQPbS6C80f/E5NK Ujsa6hGnQVp0qILYiWNB5H0R7Mb9187QX26CFyQc+1xmxmmmN7sohFeZkx0t0K8glClA jWPpU7CLaMMriyQh1xjc9wdzeuYt9mtJNGh/vi8+BmxMQZx7UQZ4PCX2RvTFXc2mb1F0 tOYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bMxkz3Y/ev9W3wKi/UG2B+dx9yCn2eWhiHBiqdhTFAU=; b=ixXyhRkL6JqjqrXH2kVOCFE7x/0in21WXJk/eem/kB8/KVe5mMGEdUgFRIEKlWe46k ANFvE7HWMmA7URI/eRVJU09heX0C3AeEMqUvVf5LYXXAer07oam+lmAcfTgkr/gEbvDJ BckLG7Hu8VdlYgFlOLrx1R8CxrkctOCMc/B7c8AJhc/ZGrSeTiy7p29DegpiWk76tM// 3CaXBCnnSGeVYMZKgPdhOv30TN5dQFxMOtf59rSszbM4d/QAtlDgwJ70wK8AhVT8CZ5R NmbiNukwryJOpt7cijWp96RT3I5asfz3jBNbSKasNNbQ2y8EOkqwsN9jhM90jy2rbwOw 9yYA== X-Gm-Message-State: ACrzQf2BheJvmGnzC1sOcYEu9+xTNrnidBilp2SWN54S3MvER/uQmT0J KS0fx9UJOWWcYmiCvSMT1RE= X-Google-Smtp-Source: AMsMyM4lygLLjWtydx4mAK9l/psNfBmXEjOuYBBgMOp5DSjsP1eC9Sxsep/aTc96omsU1lC2fUzH/g== X-Received: by 2002:a17:903:264b:b0:186:af7a:391d with SMTP id je11-20020a170903264b00b00186af7a391dmr22258695plb.19.1667351167743; Tue, 01 Nov 2022 18:06:07 -0700 (PDT) Received: from localhost.localdomain ([123.51.145.88]) by smtp.gmail.com with ESMTPSA id w23-20020a1709026f1700b00186f81bb3f0sm6926300plk.122.2022.11.01.18.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Nov 2022 18:06:07 -0700 (PDT) From: Leo Yu To: dario.binacchi@amarulasolutions.com, michael@amarulasolutions.com, miquel.raynal@bootlin.com, u-boot@lists.denx.de Cc: jaimeliao.tw@gmail.com, Leo Yu Subject: [PATCH v1 4/5] mtd: spinand: Add continuous read operation Date: Wed, 2 Nov 2022 09:05:47 +0800 Message-Id: <20221102010547.32255-1-liangyanyu13@gmail.com> X-Mailer: git-send-email 2.17.1 X-Mailman-Approved-At: Wed, 02 Nov 2022 03:33:58 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean The flow of continuous read operation is: firstly, starting with the page read command and the 1st page data will be read into the cache after the read latency tRD. Secondly, issuing the Read From Cache commands (03h/0Bh/3Bh/6Bh/BBh/EBh) to read out the data from cache continuously. After all the data is read out, the host should pull CS# high to terminate this continuous read operation and wait tRST for the NAND device resets read operation. The continuous read usage is enabled by reading multiple pages (at least greater than 1 page size) and the column address is "don't care" in this operation, since the data output for each page will always start from byte 0 and a full page data should be read out for each page. On the other hand, since the continuous read mode can only read the entire page of data and cannot read the oob data, the dynamic mode switching is added to enable continuous read mode and disable continuous read mode in spinand_continuous_read to avoid abnormal writing and erasing operations. The performance of continuous read mode is as follows. Set the flash to QSPI mode and run 25MHz direct mapping mode on the SPI bus and use the MTD test module to show the performance of continuous reads. Signed-off-by: Leo Yu --- drivers/mtd/nand/spi/core.c | 120 +++++++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index 9d628f6f26..b28962f921 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -269,7 +269,10 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand, u16 column = 0; int ret; - if (req->datalen) { + if (spinand->use_continuous_read) { + buf = req->databuf.in; + nbytes = req->datalen; + } else if (req->datalen) { adjreq.datalen = nanddev_page_size(nand); adjreq.dataoffs = 0; adjreq.databuf.in = spinand->databuf; @@ -312,6 +315,9 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand, op.addr.val += op.data.nbytes; } + if (spinand->use_continuous_read) + return 0; + if (req->datalen) memcpy(req->databuf.in, spinand->databuf + req->dataoffs, req->datalen); @@ -577,6 +583,105 @@ static int spinand_write_page(struct spinand_device *spinand, return ret; } +static int spinand_continuous_read(struct mtd_info *mtd, loff_t from, + struct mtd_oob_ops *req, + struct nand_io_iter *iter) +{ + struct spinand_device *spinand = mtd_to_spinand(mtd); + struct nand_device *nand = mtd_to_nanddev(mtd); + int ret = 0; + + bool enable_cont_read = true; + bool enable_ecc = false; + + /* + * Since the continuous read mode can only read the entire page of data + * and cannot read the oob data, therefore, only ECC-Free SPI-NAND support + * continuous read mode now. + */ + iter->req.mode = MTD_OPS_RAW; + iter->req.ooblen = 0; + + req->retlen = 0; + + /* Read the first unaligned page with conventional read */ + if (from & (nanddev_page_size(nand) - 1)) { + pr_debug("address not aligned\n"); + + iter->req.databuf.in = req->datbuf; + iter->req.dataoffs = nanddev_offs_to_pos(nand, from, &iter->req.pos); + iter->req.datalen = nanddev_page_size(nand) - iter->req.dataoffs; + + schedule(); + ret = spinand_select_target(spinand, iter->req.pos.target); + if (ret) + return ret; + + spinand_read_page(spinand, &iter->req, enable_ecc); + if (ret) + return ret; + + req->retlen += iter->req.datalen; + } + + iter->req.dataoffs = nanddev_offs_to_pos(nand, from + req->retlen, &iter->req.pos); + iter->req.databuf.in = req->datbuf + req->retlen; + iter->req.datalen = req->totallen - req->retlen; + + schedule(); + ret = spinand_continuous_read_enable(spinand, enable_cont_read); + if (ret) + return ret; + + ret = spinand_select_target(spinand, iter->req.pos.target); + if (ret) { + req->retlen = 0; + goto continuous_read_error; + } + + /* + * The continuous read operation including: firstly, starting with the + * page read command and the 1 st page data will be read into the cache + * after the read latency tRD. Secondly, Issuing the Read From Cache + * commands (03h/0Bh/3Bh/6Bh/BBh/EBh) to read out the data from cache + * continuously. + * + * The cache is divided into two halves, while one half of the cache is + * outputting the data, the other half will be loaded for the new data; + * therefore, the host can read out the data continuously from page to + * page. Multiple of Read From Cache commands can be issued in one + * continuous read operation, each Read From Cache command is required + * to read multiple 4-byte data exactly; otherwise, the data output will + * be out of sequence from one Read From Cache command to another Read + * From Cache command. + * + * After all the data is read out, the host should pull CS# high to + * terminate this continuous read operation and wait a 6us of tRST for + * the NAND device resets read operation. The data output for each page + * will always start from byte 0 and a full page data should be read out + * for each page. + */ + ret = spinand_read_page(spinand, &iter->req, enable_ecc); + if (ret) { + req->retlen = 0; + goto continuous_read_error; + } + + ret = spinand_reset_op(spinand); + if (ret) { + req->retlen = 0; + goto continuous_read_error; + } + + req->retlen += iter->req.datalen; + +continuous_read_error: + enable_cont_read = false; + ret = spinand_continuous_read_enable(spinand, enable_cont_read); + + return ret; +} + static int spinand_mtd_read(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) { @@ -594,6 +699,18 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from, #ifndef __UBOOT__ mutex_lock(&spinand->lock); #endif + /* + * If the device supports continuous read mode and the read length is greater + * than one page size, the device will enter the continuous read mode. This mode + * helps avoiding issuing a page read command and read from cache command + * again, and improves the performance of reading continuous pages. + */ + if ((spinand->flags & SPINAND_HAS_CONT_READ_BIT) && + (ops->totallen > nanddev_page_size(nand))) { + ret = spinand_continuous_read(mtd, from, ops, &iter); + + goto continuous_read_finish; + } nanddev_io_for_each_page(nand, from, ops, &iter) { schedule(); @@ -622,6 +739,7 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from, ops->oobretlen += iter.req.ooblen; } +continuous_read_finish: #ifndef __UBOOT__ mutex_unlock(&spinand->lock); #endif -- 2.17.1