Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: rawnand: Ensure the nand chip supports cached reads

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 <r.czerwinski@pengutronix.de>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20230922141717.35977-1-r.czerwinski@pengutronix.de

authored by

Rouven Czerwinski and committed by
Miquel Raynal
f6ca3fb6 5279f4a9

+15
+3
drivers/mtd/nand/raw/nand_base.c
··· 5110 5110 { 5111 5111 struct mtd_info *mtd = nand_to_mtd(chip); 5112 5112 5113 + if (!chip->parameters.supports_read_cache) 5114 + return; 5115 + 5113 5116 if (chip->read_retries) 5114 5117 return; 5115 5118
+3
drivers/mtd/nand/raw/nand_jedec.c
··· 94 94 goto free_jedec_param_page; 95 95 } 96 96 97 + if (p->opt_cmd[0] & JEDEC_OPT_CMD_READ_CACHE) 98 + chip->parameters.supports_read_cache = true; 99 + 97 100 memorg->pagesize = le32_to_cpu(p->byte_per_page); 98 101 mtd->writesize = memorg->pagesize; 99 102
+3
drivers/mtd/nand/raw/nand_onfi.c
··· 303 303 ONFI_FEATURE_ADDR_TIMING_MODE, 1); 304 304 } 305 305 306 + if (le16_to_cpu(p->opt_cmd) & ONFI_OPT_CMD_READ_CACHE) 307 + chip->parameters.supports_read_cache = true; 308 + 306 309 onfi = kzalloc(sizeof(*onfi), GFP_KERNEL); 307 310 if (!onfi) { 308 311 ret = -ENOMEM;
+3
include/linux/mtd/jedec.h
··· 21 21 /* JEDEC features */ 22 22 #define JEDEC_FEATURE_16_BIT_BUS (1 << 0) 23 23 24 + /* JEDEC Optional Commands */ 25 + #define JEDEC_OPT_CMD_READ_CACHE BIT(1) 26 + 24 27 struct nand_jedec_params { 25 28 /* rev info and features block */ 26 29 /* 'J' 'E' 'S' 'D' */
+1
include/linux/mtd/onfi.h
··· 55 55 #define ONFI_SUBFEATURE_PARAM_LEN 4 56 56 57 57 /* ONFI optional commands SET/GET FEATURES supported? */ 58 + #define ONFI_OPT_CMD_READ_CACHE BIT(1) 58 59 #define ONFI_OPT_CMD_SET_GET_FEATURES BIT(2) 59 60 60 61 struct nand_onfi_params {
+2
include/linux/mtd/rawnand.h
··· 225 225 * struct nand_parameters - NAND generic parameters from the parameter page 226 226 * @model: Model name 227 227 * @supports_set_get_features: The NAND chip supports setting/getting features 228 + * @supports_read_cache: The NAND chip supports read cache operations 228 229 * @set_feature_list: Bitmap of features that can be set 229 230 * @get_feature_list: Bitmap of features that can be get 230 231 * @onfi: ONFI specific parameters ··· 234 233 /* Generic parameters */ 235 234 const char *model; 236 235 bool supports_set_get_features; 236 + bool supports_read_cache; 237 237 DECLARE_BITMAP(set_feature_list, ONFI_FEATURE_NUMBER); 238 238 DECLARE_BITMAP(get_feature_list, ONFI_FEATURE_NUMBER); 239 239