Skip to content

Commit c468721

Browse files
committed
mtd: spi-nor: Move erase_map to 'struct spi_nor_flash_parameter'
All flash parameters and settings should reside inside 'struct spi_nor_flash_parameter'. Move the SMPT parsed erase map from 'struct spi_nor' to 'struct spi_nor_flash_parameter'. Please note that there is a roll-back mechanism for the flash parameter and settings, for cases when SFDP parser fails. The SFDP parser receives a Stack allocated copy of nor->params, called sfdp_params, and uses it to retrieve the serial flash discoverable parameters. JESD216 SFDP is a standard and has a higher priority than the default initialized flash parameters, so will overwrite the sfdp_params data when needed. All SFDP code uses the local copy of nor->params, that will overwrite it in the end, if the parser succeds. Saving and restoring the nor->params.erase_map is no longer needed, since the SFDP code does not touch it. Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Reviewed-by: Vignesh Raghavendra <vigneshr@ti.com>
1 parent 42f5994 commit c468721

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

drivers/mtd/spi-nor/spi-nor.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)
600600
nor->erase_opcode = spi_nor_convert_3to4_erase(nor->erase_opcode);
601601

602602
if (!spi_nor_has_uniform_erase(nor)) {
603-
struct spi_nor_erase_map *map = &nor->erase_map;
603+
struct spi_nor_erase_map *map = &nor->params.erase_map;
604604
struct spi_nor_erase_type *erase;
605605
int i;
606606

@@ -1133,7 +1133,7 @@ static int spi_nor_init_erase_cmd_list(struct spi_nor *nor,
11331133
struct list_head *erase_list,
11341134
u64 addr, u32 len)
11351135
{
1136-
const struct spi_nor_erase_map *map = &nor->erase_map;
1136+
const struct spi_nor_erase_map *map = &nor->params.erase_map;
11371137
const struct spi_nor_erase_type *erase, *prev_erase = NULL;
11381138
struct spi_nor_erase_region *region;
11391139
struct spi_nor_erase_command *cmd = NULL;
@@ -3328,7 +3328,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
33283328
const struct sfdp_parameter_header *bfpt_header,
33293329
struct spi_nor_flash_parameter *params)
33303330
{
3331-
struct spi_nor_erase_map *map = &nor->erase_map;
3331+
struct spi_nor_erase_map *map = &params->erase_map;
33323332
struct spi_nor_erase_type *erase_type = map->erase_type;
33333333
struct sfdp_bfpt bfpt;
33343334
size_t len;
@@ -3409,7 +3409,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
34093409
* Erase Types defined in the bfpt table.
34103410
*/
34113411
erase_mask = 0;
3412-
memset(&nor->erase_map, 0, sizeof(nor->erase_map));
3412+
memset(&params->erase_map, 0, sizeof(params->erase_map));
34133413
for (i = 0; i < ARRAY_SIZE(sfdp_bfpt_erases); i++) {
34143414
const struct sfdp_bfpt_erase *er = &sfdp_bfpt_erases[i];
34153415
u32 erasesize;
@@ -3684,14 +3684,18 @@ spi_nor_region_check_overlay(struct spi_nor_erase_region *region,
36843684
/**
36853685
* spi_nor_init_non_uniform_erase_map() - initialize the non-uniform erase map
36863686
* @nor: pointer to a 'struct spi_nor'
3687+
* @params: pointer to a duplicate 'struct spi_nor_flash_parameter' that is
3688+
* used for storing SFDP parsed data
36873689
* @smpt: pointer to the sector map parameter table
36883690
*
36893691
* Return: 0 on success, -errno otherwise.
36903692
*/
3691-
static int spi_nor_init_non_uniform_erase_map(struct spi_nor *nor,
3692-
const u32 *smpt)
3693+
static int
3694+
spi_nor_init_non_uniform_erase_map(struct spi_nor *nor,
3695+
struct spi_nor_flash_parameter *params,
3696+
const u32 *smpt)
36933697
{
3694-
struct spi_nor_erase_map *map = &nor->erase_map;
3698+
struct spi_nor_erase_map *map = &params->erase_map;
36953699
struct spi_nor_erase_type *erase = map->erase_type;
36963700
struct spi_nor_erase_region *region;
36973701
u64 offset;
@@ -3770,6 +3774,8 @@ static int spi_nor_init_non_uniform_erase_map(struct spi_nor *nor,
37703774
* spi_nor_parse_smpt() - parse Sector Map Parameter Table
37713775
* @nor: pointer to a 'struct spi_nor'
37723776
* @smpt_header: sector map parameter table header
3777+
* @params: pointer to a duplicate 'struct spi_nor_flash_parameter'
3778+
* that is used for storing SFDP parsed data
37733779
*
37743780
* This table is optional, but when available, we parse it to identify the
37753781
* location and size of sectors within the main data array of the flash memory
@@ -3778,7 +3784,8 @@ static int spi_nor_init_non_uniform_erase_map(struct spi_nor *nor,
37783784
* Return: 0 on success, -errno otherwise.
37793785
*/
37803786
static int spi_nor_parse_smpt(struct spi_nor *nor,
3781-
const struct sfdp_parameter_header *smpt_header)
3787+
const struct sfdp_parameter_header *smpt_header,
3788+
struct spi_nor_flash_parameter *params)
37823789
{
37833790
const u32 *sector_map;
37843791
u32 *smpt;
@@ -3807,11 +3814,11 @@ static int spi_nor_parse_smpt(struct spi_nor *nor,
38073814
goto out;
38083815
}
38093816

3810-
ret = spi_nor_init_non_uniform_erase_map(nor, sector_map);
3817+
ret = spi_nor_init_non_uniform_erase_map(nor, params, sector_map);
38113818
if (ret)
38123819
goto out;
38133820

3814-
spi_nor_regions_sort_erase_types(&nor->erase_map);
3821+
spi_nor_regions_sort_erase_types(&params->erase_map);
38153822
/* fall through */
38163823
out:
38173824
kfree(smpt);
@@ -3867,7 +3874,7 @@ static int spi_nor_parse_4bait(struct spi_nor *nor,
38673874
{ 0u /* not used */, BIT(12) },
38683875
};
38693876
struct spi_nor_pp_command *params_pp = params->page_programs;
3870-
struct spi_nor_erase_map *map = &nor->erase_map;
3877+
struct spi_nor_erase_map *map = &params->erase_map;
38713878
struct spi_nor_erase_type *erase_type = map->erase_type;
38723879
u32 *dwords;
38733880
size_t len;
@@ -4097,7 +4104,7 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor,
40974104

40984105
switch (SFDP_PARAM_HEADER_ID(param_header)) {
40994106
case SFDP_SECTOR_MAP_ID:
4100-
err = spi_nor_parse_smpt(nor, param_header);
4107+
err = spi_nor_parse_smpt(nor, param_header, params);
41014108
break;
41024109

41034110
case SFDP_4BAIT_ID:
@@ -4129,7 +4136,7 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor,
41294136
static int spi_nor_init_params(struct spi_nor *nor)
41304137
{
41314138
struct spi_nor_flash_parameter *params = &nor->params;
4132-
struct spi_nor_erase_map *map = &nor->erase_map;
4139+
struct spi_nor_erase_map *map = &params->erase_map;
41334140
const struct flash_info *info = nor->info;
41344141
u8 i, erase_mask;
41354142

@@ -4229,17 +4236,12 @@ static int spi_nor_init_params(struct spi_nor *nor)
42294236
if ((info->flags & (SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)) &&
42304237
!(info->flags & SPI_NOR_SKIP_SFDP)) {
42314238
struct spi_nor_flash_parameter sfdp_params;
4232-
struct spi_nor_erase_map prev_map;
42334239

42344240
memcpy(&sfdp_params, params, sizeof(sfdp_params));
4235-
memcpy(&prev_map, &nor->erase_map, sizeof(prev_map));
42364241

42374242
if (spi_nor_parse_sfdp(nor, &sfdp_params)) {
42384243
nor->addr_width = 0;
42394244
nor->flags &= ~SNOR_F_4B_OPCODES;
4240-
/* restore previous erase map */
4241-
memcpy(&nor->erase_map, &prev_map,
4242-
sizeof(nor->erase_map));
42434245
} else {
42444246
memcpy(params, &sfdp_params, sizeof(*params));
42454247
}
@@ -4353,7 +4355,7 @@ spi_nor_select_uniform_erase(struct spi_nor_erase_map *map,
43534355

43544356
static int spi_nor_select_erase(struct spi_nor *nor, u32 wanted_size)
43554357
{
4356-
struct spi_nor_erase_map *map = &nor->erase_map;
4358+
struct spi_nor_erase_map *map = &nor->params.erase_map;
43574359
const struct spi_nor_erase_type *erase = NULL;
43584360
struct mtd_info *mtd = &nor->mtd;
43594361
int i;

include/linux/mtd/spi-nor.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ struct spi_nor;
479479
* in the array, the higher priority.
480480
* @page_programs: page program capabilities ordered by priority: the
481481
* higher index in the array, the higher priority.
482+
* @erase_map: the erase map parsed from the SFDP Sector Map Parameter
483+
* Table.
482484
* @quad_enable: enables SPI NOR quad mode.
483485
*/
484486
struct spi_nor_flash_parameter {
@@ -489,6 +491,8 @@ struct spi_nor_flash_parameter {
489491
struct spi_nor_read_command reads[SNOR_CMD_READ_MAX];
490492
struct spi_nor_pp_command page_programs[SNOR_CMD_PP_MAX];
491493

494+
struct spi_nor_erase_map erase_map;
495+
492496
int (*quad_enable)(struct spi_nor *nor);
493497
};
494498

@@ -519,7 +523,6 @@ struct flash_info;
519523
* @read_proto: the SPI protocol for read operations
520524
* @write_proto: the SPI protocol for write operations
521525
* @reg_proto the SPI protocol for read_reg/write_reg/erase operations
522-
* @erase_map: the erase map of the SPI NOR
523526
* @prepare: [OPTIONAL] do some preparations for the
524527
* read/write/erase/lock/unlock operations
525528
* @unprepare: [OPTIONAL] do some post work after the
@@ -562,7 +565,6 @@ struct spi_nor {
562565
enum spi_nor_protocol reg_proto;
563566
bool sst_write_second;
564567
u32 flags;
565-
struct spi_nor_erase_map erase_map;
566568

567569
int (*prepare)(struct spi_nor *nor, enum spi_nor_ops ops);
568570
void (*unprepare)(struct spi_nor *nor, enum spi_nor_ops ops);
@@ -610,7 +612,7 @@ spi_nor_region_mark_overlay(struct spi_nor_erase_region *region)
610612

611613
static bool __maybe_unused spi_nor_has_uniform_erase(const struct spi_nor *nor)
612614
{
613-
return !!nor->erase_map.uniform_erase_type;
615+
return !!nor->params.erase_map.uniform_erase_type;
614616
}
615617

616618
static inline void spi_nor_set_flash_node(struct spi_nor *nor,

0 commit comments

Comments
 (0)