Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2743337rdb; Fri, 22 Sep 2023 07:19:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxRy1OFsKlpgdufglo3vZYHNEk08uI9sYZWl2MTpPIBSljISABQuaNo5Hb8I40U16lbAAx X-Received: by 2002:a92:c7d0:0:b0:34f:ae17:c23b with SMTP id g16-20020a92c7d0000000b0034fae17c23bmr7773933ilk.11.1695392352473; Fri, 22 Sep 2023 07:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695392352; cv=none; d=google.com; s=arc-20160816; b=uWsB3E+l53rdU4dK43HNteRcWBGrh302H5MNdBA4Z4qyv72SnBCS0Cjx14Bub8hlmA AwZknaN4w/fPh0e1XwpAvGvNR7yuiPpGCDUO3xUIxWZ9480qQWSM0QxW5HaPc4lORtwu QRHCAWLX/XVR5/5ouMDyg2FmL2zYqKDaL11mqsb0/H9stzdwBnxFrMq2ZOo5OK3dBlnP BQZgi4o7hG6d+S5E7yGIFvuKXq/o7iXoHgLs90ADTs+QG141UoGVoET1B0s/2eB+CgkK HryvRq4lE03e/ctT69bB1drx8pCR48zR3mnwRxXUWn7RuOy9xGS230xucBz8L+27bSLO yrsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=zboP2VMAI7u3VH37MPd+XIKX/frI9REjuLpovita+dI=; fh=fveVa0H2HC/7jE4L9cWfqfikCG/TNQPI+8ql5w4zJXo=; b=vsSey/Tdg3/GOxlL1UNN0nOXu7ly8TO8zkIjNo2sHkjz7GYGL0kGz4w0QkXVqpce1q jpGwODt24epR7K6qlyQ1YMU8Xm+EDSXxPfBK+/NR/ZXoUqv/WJuigK1X3dTQAqsEf+FP qovJuSG6kg2oeKUff7Ee5xFGAPxRTJDvpOQVoqVSgCE5LnfpuWKYWQPyxpXOLpmT8+lT MT9UQC5vtjEvvvGCAvqfqZgDsWKUh8QOQOxq5dEKEXqp6xrdZP7arzJudrq45Xj4l0zr U15XMtkM+ui8bSyi0VFVQd13D3tzW7PATNh0EswgINqtPHSR6MoewkYgarNab7hFvYN0 guog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id v15-20020a65460f000000b005704979833csi3694293pgq.855.2023.09.22.07.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 07:19:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 9615083BBC1A; Fri, 22 Sep 2023 07:18:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234237AbjIVOSI (ORCPT + 99 others); Fri, 22 Sep 2023 10:18:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234186AbjIVOSH (ORCPT ); Fri, 22 Sep 2023 10:18:07 -0400 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3B78AB for ; Fri, 22 Sep 2023 07:18:01 -0700 (PDT) Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=localhost) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qjgyP-0007bx-Fs; Fri, 22 Sep 2023 16:17:52 +0200 From: Rouven Czerwinski To: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= , =?UTF-8?q?M=C3=A5ns=20Rullg=C3=A5rd?= , Alexander Shiyan , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , JaimeLiao Cc: kernel@pengutronix.de, Rouven Czerwinski , stable@vger.kernel.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] mtd: rawnand: Ensure the nand chip supports cached reads Date: Fri, 22 Sep 2023 16:17:16 +0200 Message-ID: <20230922141717.35977-1-r.czerwinski@pengutronix.de> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: r.czerwinski@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 22 Sep 2023 07:18:07 -0700 (PDT) Both the JEDEC and ONFI specification say that read cache sequential support is an optional command. This means that we not only need to check whether the individual controller supports the command, we also need to check the parameter pages for both ONFI and JEDEC NAND flashes before enabling sequential cache reads. This fixes support for NAND flashes which don't support enabling cache reads, i.e. Samsung K9F4G08U0F or Toshiba TC58NVG0S3HTA00. Sequential cache reads are now only available for ONFI and JEDEC devices, if individual vendors implement this, it needs to be enabled per vendor. Tested on i.MX6Q with a Samsung NAND flash chip that doesn't support sequential reads. Fixes: 003fe4b9545b ("mtd: rawnand: Support for sequential cache reads") Cc: stable@vger.kernel.org Signed-off-by: Rouven Czerwinski --- v2: - change title as suggested by Miquel - adjust controller sentence from implement to support - fix missing true assignement for flashes - add CC stable instead of empty line - add documentation comment for new supports_read_cache bool inside nand parameter struct drivers/mtd/nand/raw/nand_base.c | 3 +++ drivers/mtd/nand/raw/nand_jedec.c | 3 +++ drivers/mtd/nand/raw/nand_onfi.c | 3 +++ include/linux/mtd/jedec.h | 3 +++ include/linux/mtd/onfi.h | 1 + include/linux/mtd/rawnand.h | 2 ++ 6 files changed, 15 insertions(+) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index d4b55155aeae..1fcac403cee6 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -5110,6 +5110,9 @@ static void rawnand_check_cont_read_support(struct nand_chip *chip) { struct mtd_info *mtd = nand_to_mtd(chip); + if (!chip->parameters.supports_read_cache) + return; + if (chip->read_retries) return; diff --git a/drivers/mtd/nand/raw/nand_jedec.c b/drivers/mtd/nand/raw/nand_jedec.c index 836757717660..b3cc8f360529 100644 --- a/drivers/mtd/nand/raw/nand_jedec.c +++ b/drivers/mtd/nand/raw/nand_jedec.c @@ -94,6 +94,9 @@ int nand_jedec_detect(struct nand_chip *chip) goto free_jedec_param_page; } + if (p->opt_cmd[0] & JEDEC_OPT_CMD_READ_CACHE) + chip->parameters.supports_read_cache = true; + memorg->pagesize = le32_to_cpu(p->byte_per_page); mtd->writesize = memorg->pagesize; diff --git a/drivers/mtd/nand/raw/nand_onfi.c b/drivers/mtd/nand/raw/nand_onfi.c index f15ef90aec8c..861975e44b55 100644 --- a/drivers/mtd/nand/raw/nand_onfi.c +++ b/drivers/mtd/nand/raw/nand_onfi.c @@ -303,6 +303,9 @@ int nand_onfi_detect(struct nand_chip *chip) ONFI_FEATURE_ADDR_TIMING_MODE, 1); } + if (le16_to_cpu(p->opt_cmd) & ONFI_OPT_CMD_READ_CACHE) + chip->parameters.supports_read_cache = true; + onfi = kzalloc(sizeof(*onfi), GFP_KERNEL); if (!onfi) { ret = -ENOMEM; diff --git a/include/linux/mtd/jedec.h b/include/linux/mtd/jedec.h index 0b6b59f7cfbd..56047a4e54c9 100644 --- a/include/linux/mtd/jedec.h +++ b/include/linux/mtd/jedec.h @@ -21,6 +21,9 @@ struct jedec_ecc_info { /* JEDEC features */ #define JEDEC_FEATURE_16_BIT_BUS (1 << 0) +/* JEDEC Optional Commands */ +#define JEDEC_OPT_CMD_READ_CACHE BIT(1) + struct nand_jedec_params { /* rev info and features block */ /* 'J' 'E' 'S' 'D' */ diff --git a/include/linux/mtd/onfi.h b/include/linux/mtd/onfi.h index a7376f9beddf..55ab2e4d62f9 100644 --- a/include/linux/mtd/onfi.h +++ b/include/linux/mtd/onfi.h @@ -55,6 +55,7 @@ #define ONFI_SUBFEATURE_PARAM_LEN 4 /* ONFI optional commands SET/GET FEATURES supported? */ +#define ONFI_OPT_CMD_READ_CACHE BIT(1) #define ONFI_OPT_CMD_SET_GET_FEATURES BIT(2) struct nand_onfi_params { diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 90a141ba2a5a..c29ace15a053 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -225,6 +225,7 @@ struct gpio_desc; * struct nand_parameters - NAND generic parameters from the parameter page * @model: Model name * @supports_set_get_features: The NAND chip supports setting/getting features + * @supports_read_cache: The NAND chip supports read cache operations * @set_feature_list: Bitmap of features that can be set * @get_feature_list: Bitmap of features that can be get * @onfi: ONFI specific parameters @@ -233,6 +234,7 @@ struct nand_parameters { /* Generic parameters */ const char *model; bool supports_set_get_features; + bool supports_read_cache; DECLARE_BITMAP(set_feature_list, ONFI_FEATURE_NUMBER); DECLARE_BITMAP(get_feature_list, ONFI_FEATURE_NUMBER); base-commit: 42dc814987c1feb6410904e58cfd4c36c4146150 -- 2.42.0