Skip to content

Commit 2fb038e

Browse files
hanxu-nxpmiquelraynal
authored andcommitted
mtd: rawnand: gpmi: Rename the variable ecc_chunk_size
There is only one variable ecc_chunk_size in bch_geometry data structure but two different field in BCH registers. The data0_size in BCH_FLASH0LAYOUT0 and datan_size in BCH_FLASH0LAYOUT1 should have dedicate variable since they might set to different values in some cases. For instance, if need dedicate ecc for meta area, the data0_size should be 0 rather than datan_size, but for all other cases, data0_size still equals to datan_size and it won't bring any function change. Signed-off-by: Han Xu <han.xu@nxp.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20220412025246.24269-5-han.xu@nxp.com
1 parent 1091585 commit 2fb038e

2 files changed

Lines changed: 34 additions & 27 deletions

File tree

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ static void gpmi_dump_info(struct gpmi_nand_data *this)
218218
"ECC Strength : %u\n"
219219
"Page Size in Bytes : %u\n"
220220
"Metadata Size in Bytes : %u\n"
221-
"ECC Chunk Size in Bytes: %u\n"
221+
"ECC0 Chunk Size in Bytes: %u\n"
222+
"ECCn Chunk Size in Bytes: %u\n"
222223
"ECC Chunk Count : %u\n"
223224
"Payload Size in Bytes : %u\n"
224225
"Auxiliary Size in Bytes: %u\n"
@@ -229,7 +230,8 @@ static void gpmi_dump_info(struct gpmi_nand_data *this)
229230
geo->ecc_strength,
230231
geo->page_size,
231232
geo->metadata_size,
232-
geo->ecc_chunk_size,
233+
geo->ecc0_chunk_size,
234+
geo->eccn_chunk_size,
233235
geo->ecc_chunk_count,
234236
geo->payload_size,
235237
geo->auxiliary_size,
@@ -293,13 +295,14 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this,
293295
nanddev_get_ecc_requirements(&chip->base)->step_size);
294296
return -EINVAL;
295297
}
296-
geo->ecc_chunk_size = ecc_step;
298+
geo->ecc0_chunk_size = ecc_step;
299+
geo->eccn_chunk_size = ecc_step;
297300
geo->ecc_strength = round_up(ecc_strength, 2);
298301
if (!gpmi_check_ecc(this))
299302
return -EINVAL;
300303

301304
/* Keep the C >= O */
302-
if (geo->ecc_chunk_size < mtd->oobsize) {
305+
if (geo->eccn_chunk_size < mtd->oobsize) {
303306
dev_err(this->dev,
304307
"unsupported nand chip. ecc size: %d, oob size : %d\n",
305308
ecc_step, mtd->oobsize);
@@ -309,7 +312,7 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this,
309312
/* The default value, see comment in the legacy_set_geometry(). */
310313
geo->metadata_size = 10;
311314

312-
geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunk_size;
315+
geo->ecc_chunk_count = mtd->writesize / geo->eccn_chunk_size;
313316

314317
/*
315318
* Now, the NAND chip with 2K page(data chunk is 512byte) shows below:
@@ -431,13 +434,15 @@ static int legacy_set_geometry(struct gpmi_nand_data *this)
431434
geo->gf_len = 13;
432435

433436
/* The default for chunk size. */
434-
geo->ecc_chunk_size = 512;
435-
while (geo->ecc_chunk_size < mtd->oobsize) {
436-
geo->ecc_chunk_size *= 2; /* keep C >= O */
437+
geo->ecc0_chunk_size = 512;
438+
geo->eccn_chunk_size = 512;
439+
while (geo->eccn_chunk_size < mtd->oobsize) {
440+
geo->ecc0_chunk_size *= 2; /* keep C >= O */
441+
geo->eccn_chunk_size *= 2; /* keep C >= O */
437442
geo->gf_len = 14;
438443
}
439444

440-
geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunk_size;
445+
geo->ecc_chunk_count = mtd->writesize / geo->eccn_chunk_size;
441446

442447
/* We use the same ECC strength for all chunks. */
443448
geo->ecc_strength = get_ecc_strength(this);
@@ -864,7 +869,7 @@ static int gpmi_raw_len_to_len(struct gpmi_nand_data *this, int raw_len)
864869
* we are passed in exec_op. Calculate the data length from it.
865870
*/
866871
if (this->bch)
867-
return ALIGN_DOWN(raw_len, this->bch_geometry.ecc_chunk_size);
872+
return ALIGN_DOWN(raw_len, this->bch_geometry.eccn_chunk_size);
868873
else
869874
return raw_len;
870875
}
@@ -1256,7 +1261,7 @@ static int gpmi_count_bitflips(struct nand_chip *chip, void *buf, int first,
12561261

12571262
/* Read ECC bytes into our internal raw_buffer */
12581263
offset = nfc_geo->metadata_size * 8;
1259-
offset += ((8 * nfc_geo->ecc_chunk_size) + eccbits) * (i + 1);
1264+
offset += ((8 * nfc_geo->eccn_chunk_size) + eccbits) * (i + 1);
12601265
offset -= eccbits;
12611266
bitoffset = offset % 8;
12621267
eccbytes = DIV_ROUND_UP(offset + eccbits, 8);
@@ -1293,16 +1298,16 @@ static int gpmi_count_bitflips(struct nand_chip *chip, void *buf, int first,
12931298
if (i == 0) {
12941299
/* The first block includes metadata */
12951300
flips = nand_check_erased_ecc_chunk(
1296-
buf + i * nfc_geo->ecc_chunk_size,
1297-
nfc_geo->ecc_chunk_size,
1301+
buf + i * nfc_geo->eccn_chunk_size,
1302+
nfc_geo->eccn_chunk_size,
12981303
eccbuf, eccbytes,
12991304
this->auxiliary_virt,
13001305
nfc_geo->metadata_size,
13011306
nfc_geo->ecc_strength);
13021307
} else {
13031308
flips = nand_check_erased_ecc_chunk(
1304-
buf + i * nfc_geo->ecc_chunk_size,
1305-
nfc_geo->ecc_chunk_size,
1309+
buf + i * nfc_geo->eccn_chunk_size,
1310+
nfc_geo->eccn_chunk_size,
13061311
eccbuf, eccbytes,
13071312
NULL, 0,
13081313
nfc_geo->ecc_strength);
@@ -1331,20 +1336,21 @@ static void gpmi_bch_layout_std(struct gpmi_nand_data *this)
13311336
struct bch_geometry *geo = &this->bch_geometry;
13321337
unsigned int ecc_strength = geo->ecc_strength >> 1;
13331338
unsigned int gf_len = geo->gf_len;
1334-
unsigned int block_size = geo->ecc_chunk_size;
1339+
unsigned int block0_size = geo->ecc0_chunk_size;
1340+
unsigned int blockn_size = geo->eccn_chunk_size;
13351341

13361342
this->bch_flashlayout0 =
13371343
BF_BCH_FLASH0LAYOUT0_NBLOCKS(geo->ecc_chunk_count - 1) |
13381344
BF_BCH_FLASH0LAYOUT0_META_SIZE(geo->metadata_size) |
13391345
BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength, this) |
13401346
BF_BCH_FLASH0LAYOUT0_GF(gf_len, this) |
1341-
BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size, this);
1347+
BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block0_size, this);
13421348

13431349
this->bch_flashlayout1 =
13441350
BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(geo->page_size) |
13451351
BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this) |
13461352
BF_BCH_FLASH0LAYOUT1_GF(gf_len, this) |
1347-
BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size, this);
1353+
BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(blockn_size, this);
13481354
}
13491355

13501356
static int gpmi_ecc_read_page(struct nand_chip *chip, uint8_t *buf,
@@ -1444,12 +1450,12 @@ static int gpmi_ecc_read_subpage(struct nand_chip *chip, uint32_t offs,
14441450
BF_BCH_FLASH0LAYOUT0_META_SIZE(meta) |
14451451
BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength, this) |
14461452
BF_BCH_FLASH0LAYOUT0_GF(geo->gf_len, this) |
1447-
BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(geo->ecc_chunk_size, this);
1453+
BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(geo->eccn_chunk_size, this);
14481454

14491455
this->bch_flashlayout1 = BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(page_size) |
14501456
BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this) |
14511457
BF_BCH_FLASH0LAYOUT1_GF(geo->gf_len, this) |
1452-
BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(geo->ecc_chunk_size, this);
1458+
BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(geo->eccn_chunk_size, this);
14531459

14541460
this->bch = true;
14551461

@@ -1618,7 +1624,7 @@ static int gpmi_ecc_read_page_raw(struct nand_chip *chip, uint8_t *buf,
16181624
struct mtd_info *mtd = nand_to_mtd(chip);
16191625
struct gpmi_nand_data *this = nand_get_controller_data(chip);
16201626
struct bch_geometry *nfc_geo = &this->bch_geometry;
1621-
int eccsize = nfc_geo->ecc_chunk_size;
1627+
int eccsize = nfc_geo->eccn_chunk_size;
16221628
int eccbits = nfc_geo->ecc_strength * nfc_geo->gf_len;
16231629
u8 *tmp_buf = this->raw_buffer;
16241630
size_t src_bit_off;
@@ -1703,7 +1709,7 @@ static int gpmi_ecc_write_page_raw(struct nand_chip *chip, const uint8_t *buf,
17031709
struct mtd_info *mtd = nand_to_mtd(chip);
17041710
struct gpmi_nand_data *this = nand_get_controller_data(chip);
17051711
struct bch_geometry *nfc_geo = &this->bch_geometry;
1706-
int eccsize = nfc_geo->ecc_chunk_size;
1712+
int eccsize = nfc_geo->eccn_chunk_size;
17071713
int eccbits = nfc_geo->ecc_strength * nfc_geo->gf_len;
17081714
u8 *tmp_buf = this->raw_buffer;
17091715
uint8_t *oob = chip->oob_poi;
@@ -2077,7 +2083,7 @@ static int gpmi_init_last(struct gpmi_nand_data *this)
20772083
ecc->read_oob_raw = gpmi_ecc_read_oob_raw;
20782084
ecc->write_oob_raw = gpmi_ecc_write_oob_raw;
20792085
ecc->engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
2080-
ecc->size = bch_geo->ecc_chunk_size;
2086+
ecc->size = bch_geo->eccn_chunk_size;
20812087
ecc->strength = bch_geo->ecc_strength;
20822088
mtd_set_ooblayout(mtd, &gpmi_ooblayout_ops);
20832089

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ struct resources {
3030
* @page_size: The size, in bytes, of a physical page, including
3131
* both data and OOB.
3232
* @metadata_size: The size, in bytes, of the metadata.
33-
* @ecc_chunk_size: The size, in bytes, of a single ECC chunk. Note
34-
* the first chunk in the page includes both data and
35-
* metadata, so it's a bit larger than this value.
33+
* @ecc0_chunk_size: The size, in bytes, of a first ECC chunk.
34+
* @eccn_chunk_size: The size, in bytes, of a single ECC chunk after
35+
* the first chunk in the page.
3636
* @ecc_chunk_count: The number of ECC chunks in the page,
3737
* @payload_size: The size, in bytes, of the payload buffer.
3838
* @auxiliary_size: The size, in bytes, of the auxiliary buffer.
@@ -48,7 +48,8 @@ struct bch_geometry {
4848
unsigned int ecc_strength;
4949
unsigned int page_size;
5050
unsigned int metadata_size;
51-
unsigned int ecc_chunk_size;
51+
unsigned int ecc0_chunk_size;
52+
unsigned int eccn_chunk_size;
5253
unsigned int ecc_chunk_count;
5354
unsigned int payload_size;
5455
unsigned int auxiliary_size;

0 commit comments

Comments
 (0)