Skip to content

Commit bd0b643

Browse files
miquelraynalBoris Brezillon
authored andcommitted
mtd: rawnand: get rid of the ONFI parameter page in nand_chip
The NAND chip parameter page is statically allocated within the nand_chip structure, which reserves a lot of space. Even not ONFI nor JEDEC chips have it embedded. Also, only a few parameters are actually read from the parameter page after the detection. Now that there is a small nand_parameters structure that hold all needed ONFI parameters, remove the ONFI page from the nand_chip structure by just allocating it during the identification phase and removing it right after. Signed-off-by: Miquel Raynal <[email protected]> Signed-off-by: Boris Brezillon <[email protected]>
1 parent 480139d commit bd0b643

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

drivers/mtd/nand/raw/nand_base.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5101,7 +5101,7 @@ static int nand_flash_detect_ext_param_page(struct nand_chip *chip,
51015101
static int nand_flash_detect_onfi(struct nand_chip *chip)
51025102
{
51035103
struct mtd_info *mtd = nand_to_mtd(chip);
5104-
struct nand_onfi_params *p = &chip->onfi_params;
5104+
struct nand_onfi_params *p;
51055105
char id[4];
51065106
int i, ret, val;
51075107

@@ -5110,14 +5110,23 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
51105110
if (ret || strncmp(id, "ONFI", 4))
51115111
return 0;
51125112

5113+
/* ONFI chip: allocate a buffer to hold its parameter page */
5114+
p = kzalloc(sizeof(*p), GFP_KERNEL);
5115+
if (!p)
5116+
return -ENOMEM;
5117+
51135118
ret = nand_read_param_page_op(chip, 0, NULL, 0);
5114-
if (ret)
5115-
return 0;
5119+
if (ret) {
5120+
ret = 0;
5121+
goto free_onfi_param_page;
5122+
}
51165123

51175124
for (i = 0; i < 3; i++) {
51185125
ret = nand_read_data_op(chip, p, sizeof(*p), true);
5119-
if (ret)
5120-
return 0;
5126+
if (ret) {
5127+
ret = 0;
5128+
goto free_onfi_param_page;
5129+
}
51215130

51225131
if (onfi_crc16(ONFI_CRC_BASE, (uint8_t *)p, 254) ==
51235132
le16_to_cpu(p->crc)) {
@@ -5127,7 +5136,7 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
51275136

51285137
if (i == 3) {
51295138
pr_err("Could not find valid ONFI parameter page; aborting\n");
5130-
return 0;
5139+
goto free_onfi_param_page;
51315140
}
51325141

51335142
/* Check version */
@@ -5145,7 +5154,9 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
51455154

51465155
if (!chip->parameters.onfi.version) {
51475156
pr_info("unsupported ONFI version: %d\n", val);
5148-
return 0;
5157+
goto free_onfi_param_page;
5158+
} else {
5159+
ret = 1;
51495160
}
51505161

51515162
sanitize_string(p->manufacturer, sizeof(p->manufacturer));
@@ -5217,7 +5228,9 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
52175228
memcpy(chip->parameters.onfi.vendor, p->vendor,
52185229
sizeof(p->vendor));
52195230

5220-
return 1;
5231+
free_onfi_param_page:
5232+
kfree(p);
5233+
return ret;
52215234
}
52225235

52235236
/*
@@ -5612,7 +5625,10 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
56125625
chip->parameters.onfi.version = 0;
56135626
if (!type->name || !type->pagesize) {
56145627
/* Check if the chip is ONFI compliant */
5615-
if (nand_flash_detect_onfi(chip))
5628+
ret = nand_flash_detect_onfi(chip);
5629+
if (ret < 0)
5630+
return ret;
5631+
else if (ret)
56165632
goto ident_done;
56175633

56185634
/* Check if the chip is JEDEC compliant */

include/linux/mtd/rawnand.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,6 @@ int nand_op_parser_exec_op(struct nand_chip *chip,
12001200
* currently in data_buf.
12011201
* @subpagesize: [INTERN] holds the subpagesize
12021202
* @id: [INTERN] holds NAND ID
1203-
* @onfi_params: [INTERN] holds the ONFI page parameter when ONFI is
1204-
* supported, 0 otherwise.
12051203
* @parameters: [INTERN] holds generic parameters under an easily
12061204
* readable form.
12071205
* @max_bb_per_die: [INTERN] the max number of bad blocks each die of a
@@ -1282,7 +1280,6 @@ struct nand_chip {
12821280
int badblockbits;
12831281

12841282
struct nand_id id;
1285-
struct nand_onfi_params onfi_params;
12861283
struct nand_parameters parameters;
12871284
u16 max_bb_per_die;
12881285
u32 blocks_per_die;

0 commit comments

Comments
 (0)