Re: [PATCHv3 1/2] mmc-utils: Refactor switch to allow custom timeout

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 13 Oct 2022 at 11:10, Christian Löhle <CLoehle@xxxxxxxxxxxxxx> wrote:
>
> Certain commands require a longer switch timeout.
> Refactor accordingly to allow e.g. for future sanitize change.
>
> Signed-off-by: Christian Loehle <cloehle@xxxxxxxxxxxxxx>

Applied to git.kernel.org/pub/scm//utils/mmc/mmc-utils.git master, thanks!

Kind regards
Uffe


> ---
>  mmc_cmds.c | 60 ++++++++++++++++++++++++++++--------------------------
>  1 file changed, 31 insertions(+), 29 deletions(-)
>
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index 2957aa9..3337ded 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -76,7 +76,7 @@ int read_extcsd(int fd, __u8 *ext_csd)
>         return ret;
>  }
>
> -int write_extcsd_value(int fd, __u8 index, __u8 value)
> +int write_extcsd_value(int fd, __u8 index, __u8 value, unsigned int timeout_ms)
>  {
>         int ret = 0;
>         struct mmc_ioc_cmd idata;
> @@ -89,6 +89,8 @@ int write_extcsd_value(int fd, __u8 index, __u8 value)
>                         (value << 8) |
>                         EXT_CSD_CMD_SET_NORMAL;
>         idata.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
> +       /* Kernel will set cmd_timeout_ms if 0 is set */
> +       idata.cmd_timeout_ms = timeout_ms;
>
>         ret = ioctl(fd, MMC_IOC_CMD, &idata);
>         if (ret)
> @@ -341,7 +343,7 @@ int do_writeprotect_boot_set(int nargs, char **argv)
>         value |= permanent ? EXT_CSD_BOOT_WP_B_PERM_WP_EN
>                            : EXT_CSD_BOOT_WP_B_PWR_WP_EN;
>
> -       ret = write_extcsd_value(fd, EXT_CSD_BOOT_WP, value);
> +       ret = write_extcsd_value(fd, EXT_CSD_BOOT_WP, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%02x to "
>                         "EXT_CSD[%d] in %s\n",
> @@ -508,7 +510,7 @@ int do_writeprotect_user_set(int nargs, char **argv)
>                         break;
>                 }
>                 if (user_wp != ext_csd[EXT_CSD_USER_WP]) {
> -                       ret = write_extcsd_value(fd, EXT_CSD_USER_WP, user_wp);
> +                       ret = write_extcsd_value(fd, EXT_CSD_USER_WP, user_wp, 0);
>                         if (ret) {
>                                 fprintf(stderr, "Error setting EXT_CSD\n");
>                                 exit(1);
> @@ -526,7 +528,7 @@ int do_writeprotect_user_set(int nargs, char **argv)
>         }
>         if (wptype != WPTYPE_NONE) {
>                 ret = write_extcsd_value(fd, EXT_CSD_USER_WP,
> -                                       ext_csd[EXT_CSD_USER_WP]);
> +                               ext_csd[EXT_CSD_USER_WP], 0);
>                 if (ret) {
>                         fprintf(stderr, "Error restoring EXT_CSD\n");
>                         exit(1);
> @@ -571,7 +573,7 @@ int do_disable_512B_emulation(int nargs, char **argv)
>
>         if (native_sector_size && !data_sector_size &&
>            (wr_rel_param & EN_REL_WR)) {
> -               ret = write_extcsd_value(fd, EXT_CSD_USE_NATIVE_SECTOR, 1);
> +               ret = write_extcsd_value(fd, EXT_CSD_USE_NATIVE_SECTOR, 1, 0);
>
>                 if (ret) {
>                         fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
> @@ -650,7 +652,7 @@ int do_write_boot_en(int nargs, char **argv)
>         else
>                 value &= ~EXT_CSD_PART_CONFIG_ACC_ACK;
>
> -       ret = write_extcsd_value(fd, EXT_CSD_PART_CONFIG, value);
> +       ret = write_extcsd_value(fd, EXT_CSD_PART_CONFIG, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%02x to "
>                         "EXT_CSD[%d] in %s\n",
> @@ -720,7 +722,7 @@ int do_boot_bus_conditions_set(int nargs, char **argv)
>         printf("Changing ext_csd[BOOT_BUS_CONDITIONS] from 0x%02x to 0x%02x\n",
>                 ext_csd[EXT_CSD_BOOT_BUS_CONDITIONS], value);
>
> -       ret = write_extcsd_value(fd, EXT_CSD_BOOT_BUS_CONDITIONS, value);
> +       ret = write_extcsd_value(fd, EXT_CSD_BOOT_BUS_CONDITIONS, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%02x to "
>                         "EXT_CSD[%d] in %s\n",
> @@ -771,7 +773,7 @@ int do_hwreset(int value, int nargs, char **argv)
>                 exit(1);
>         }
>
> -       ret = write_extcsd_value(fd, EXT_CSD_RST_N_FUNCTION, value);
> +       ret = write_extcsd_value(fd, EXT_CSD_RST_N_FUNCTION, value, 0);
>         if (ret) {
>                 fprintf(stderr,
>                         "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
> @@ -825,9 +827,9 @@ int do_write_bkops_en(int nargs, char **argv)
>                         fprintf(stderr, "%s doesn't support AUTO_EN in the BKOPS_EN register\n", device);
>                         exit(1);
>                 }
> -               ret = write_extcsd_value(fd, EXT_CSD_BKOPS_EN, BKOPS_AUTO_ENABLE);
> +               ret = write_extcsd_value(fd, EXT_CSD_BKOPS_EN, BKOPS_AUTO_ENABLE, 0);
>         } else if (strcmp(en_type, "manual") == 0) {
> -               ret = write_extcsd_value(fd, EXT_CSD_BKOPS_EN, BKOPS_MAN_ENABLE);
> +               ret = write_extcsd_value(fd, EXT_CSD_BKOPS_EN, BKOPS_MAN_ENABLE, 0);
>         } else {
>                 fprintf(stderr, "%s invalid mode for BKOPS_EN requested: %s. Valid options: auto or manual\n", en_type, device);
>                 exit(1);
> @@ -1002,7 +1004,7 @@ int set_partitioning_setting_completed(int dry_run, const char * const device,
>         }
>
>         fprintf(stderr, "setting OTP PARTITION_SETTING_COMPLETED!\n");
> -       ret = write_extcsd_value(fd, EXT_CSD_PARTITION_SETTING_COMPLETED, 0x1);
> +       ret = write_extcsd_value(fd, EXT_CSD_PARTITION_SETTING_COMPLETED, 0x1, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x1 to "
>                         "EXT_CSD[%d] in %s\n",
> @@ -1188,7 +1190,7 @@ int do_create_gp_partition(int nargs, char **argv)
>         gp_size_mult = (length_kib + align/2l) / align;
>
>         /* set EXT_CSD_ERASE_GROUP_DEF bit 0 */
> -       ret = write_extcsd_value(fd, EXT_CSD_ERASE_GROUP_DEF, 0x1);
> +       ret = write_extcsd_value(fd, EXT_CSD_ERASE_GROUP_DEF, 0x1, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x1 to EXT_CSD[%d] in %s\n",
>                         EXT_CSD_ERASE_GROUP_DEF, device);
> @@ -1197,7 +1199,7 @@ int do_create_gp_partition(int nargs, char **argv)
>
>         value = (gp_size_mult >> 16) & 0xff;
>         address = EXT_CSD_GP_SIZE_MULT_1_2 + (partition - 1) * 3;
> -       ret = write_extcsd_value(fd, address, value);
> +       ret = write_extcsd_value(fd, address, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
>                         value, address, device);
> @@ -1205,7 +1207,7 @@ int do_create_gp_partition(int nargs, char **argv)
>         }
>         value = (gp_size_mult >> 8) & 0xff;
>         address = EXT_CSD_GP_SIZE_MULT_1_1 + (partition - 1) * 3;
> -       ret = write_extcsd_value(fd, address, value);
> +       ret = write_extcsd_value(fd, address, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
>                         value, address, device);
> @@ -1213,7 +1215,7 @@ int do_create_gp_partition(int nargs, char **argv)
>         }
>         value = gp_size_mult & 0xff;
>         address = EXT_CSD_GP_SIZE_MULT_1_0 + (partition - 1) * 3;
> -       ret = write_extcsd_value(fd, address, value);
> +       ret = write_extcsd_value(fd, address, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
>                         value, address, device);
> @@ -1226,7 +1228,7 @@ int do_create_gp_partition(int nargs, char **argv)
>         else
>                 value &= ~(1 << partition);
>
> -       ret = write_extcsd_value(fd, EXT_CSD_PARTITIONS_ATTRIBUTE, value);
> +       ret = write_extcsd_value(fd, EXT_CSD_PARTITIONS_ATTRIBUTE, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write EXT_CSD_ENH_%x to EXT_CSD[%d] in %s\n",
>                         partition, EXT_CSD_PARTITIONS_ATTRIBUTE, device);
> @@ -1240,7 +1242,7 @@ int do_create_gp_partition(int nargs, char **argv)
>         else
>                 value &= (0xF << (4 * ((partition % 2))));
>
> -       ret = write_extcsd_value(fd, address, value);
> +       ret = write_extcsd_value(fd, address, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%x to EXT_CSD[%d] in %s\n",
>                         value, address, device);
> @@ -1317,7 +1319,7 @@ int do_enh_area_set(int nargs, char **argv)
>         enh_start_addr *= align;
>
>         /* set EXT_CSD_ERASE_GROUP_DEF bit 0 */
> -       ret = write_extcsd_value(fd, EXT_CSD_ERASE_GROUP_DEF, 0x1);
> +       ret = write_extcsd_value(fd, EXT_CSD_ERASE_GROUP_DEF, 0x1, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x1 to "
>                         "EXT_CSD[%d] in %s\n",
> @@ -1327,7 +1329,7 @@ int do_enh_area_set(int nargs, char **argv)
>
>         /* write to ENH_START_ADDR and ENH_SIZE_MULT and PARTITIONS_ATTRIBUTE's ENH_USR bit */
>         value = (enh_start_addr >> 24) & 0xff;
> -       ret = write_extcsd_value(fd, EXT_CSD_ENH_START_ADDR_3, value);
> +       ret = write_extcsd_value(fd, EXT_CSD_ENH_START_ADDR_3, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%02x to "
>                         "EXT_CSD[%d] in %s\n", value,
> @@ -1335,7 +1337,7 @@ int do_enh_area_set(int nargs, char **argv)
>                 exit(1);
>         }
>         value = (enh_start_addr >> 16) & 0xff;
> -       ret = write_extcsd_value(fd, EXT_CSD_ENH_START_ADDR_2, value);
> +       ret = write_extcsd_value(fd, EXT_CSD_ENH_START_ADDR_2, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%02x to "
>                         "EXT_CSD[%d] in %s\n", value,
> @@ -1343,7 +1345,7 @@ int do_enh_area_set(int nargs, char **argv)
>                 exit(1);
>         }
>         value = (enh_start_addr >> 8) & 0xff;
> -       ret = write_extcsd_value(fd, EXT_CSD_ENH_START_ADDR_1, value);
> +       ret = write_extcsd_value(fd, EXT_CSD_ENH_START_ADDR_1, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%02x to "
>                         "EXT_CSD[%d] in %s\n", value,
> @@ -1351,7 +1353,7 @@ int do_enh_area_set(int nargs, char **argv)
>                 exit(1);
>         }
>         value = enh_start_addr & 0xff;
> -       ret = write_extcsd_value(fd, EXT_CSD_ENH_START_ADDR_0, value);
> +       ret = write_extcsd_value(fd, EXT_CSD_ENH_START_ADDR_0, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%02x to "
>                         "EXT_CSD[%d] in %s\n", value,
> @@ -1360,7 +1362,7 @@ int do_enh_area_set(int nargs, char **argv)
>         }
>
>         value = (enh_size_mult >> 16) & 0xff;
> -       ret = write_extcsd_value(fd, EXT_CSD_ENH_SIZE_MULT_2, value);
> +       ret = write_extcsd_value(fd, EXT_CSD_ENH_SIZE_MULT_2, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%02x to "
>                         "EXT_CSD[%d] in %s\n", value,
> @@ -1368,7 +1370,7 @@ int do_enh_area_set(int nargs, char **argv)
>                 exit(1);
>         }
>         value = (enh_size_mult >> 8) & 0xff;
> -       ret = write_extcsd_value(fd, EXT_CSD_ENH_SIZE_MULT_1, value);
> +       ret = write_extcsd_value(fd, EXT_CSD_ENH_SIZE_MULT_1, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%02x to "
>                         "EXT_CSD[%d] in %s\n", value,
> @@ -1376,7 +1378,7 @@ int do_enh_area_set(int nargs, char **argv)
>                 exit(1);
>         }
>         value = enh_size_mult & 0xff;
> -       ret = write_extcsd_value(fd, EXT_CSD_ENH_SIZE_MULT_0, value);
> +       ret = write_extcsd_value(fd, EXT_CSD_ENH_SIZE_MULT_0, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%02x to "
>                         "EXT_CSD[%d] in %s\n", value,
> @@ -1384,7 +1386,7 @@ int do_enh_area_set(int nargs, char **argv)
>                 exit(1);
>         }
>         value = ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE] | EXT_CSD_ENH_USR;
> -       ret = write_extcsd_value(fd, EXT_CSD_PARTITIONS_ATTRIBUTE, value);
> +       ret = write_extcsd_value(fd, EXT_CSD_PARTITIONS_ATTRIBUTE, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write EXT_CSD_ENH_USR to "
>                         "EXT_CSD[%d] in %s\n",
> @@ -1455,7 +1457,7 @@ int do_write_reliability_set(int nargs, char **argv)
>         }
>
>         value = ext_csd[EXT_CSD_WR_REL_SET] | (1<<partition);
> -       ret = write_extcsd_value(fd, EXT_CSD_WR_REL_SET, value);
> +       ret = write_extcsd_value(fd, EXT_CSD_WR_REL_SET, value, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
>                                 value, EXT_CSD_WR_REL_SET, device);
> @@ -1998,7 +2000,7 @@ int do_sanitize(int nargs, char **argv)
>                 exit(1);
>         }
>
> -       ret = write_extcsd_value(fd, EXT_CSD_SANITIZE_START, 1);
> +       ret = write_extcsd_value(fd, EXT_CSD_SANITIZE_START, 1, 0);
>         if (ret) {
>                 fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
>                         1, EXT_CSD_SANITIZE_START, device);
> @@ -2587,7 +2589,7 @@ int do_cache_ctrl(int value, int nargs, char **argv)
>                         device);
>                 exit(1);
>         }
> -       ret = write_extcsd_value(fd, EXT_CSD_CACHE_CTRL, value);
> +       ret = write_extcsd_value(fd, EXT_CSD_CACHE_CTRL, value, 0);
>         if (ret) {
>                 fprintf(stderr,
>                         "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
> --
> 2.37.3
>
> Hyperstone GmbH | Reichenaustr. 39a  | 78467 Konstanz
> Managing Director: Dr. Jan Peter Berns.
> Commercial register of local courts: Freiburg HRB381782
>




[Index of Archives]     [Linux Memonry Technology]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux