Re: [PATCH] mmc: core: add MMC_QUIRK_BROKEN_WRITE_ZEROES for ESMT eMMC

Ulf Hansson <[email protected]> Mon, 27 Jul 2026 18:19:32 +0200
Newsgroups org.kernel.vger.linux-mmc,org.kernel.vger.linux-kernel
Message-ID <CAPx+jO9rFKorZ9DYQ7uNjRJK9r1+Kx6Qxza7GQChAWtzZeK63w@mail.gmail.com>
On Sat, Jul 25, 2026 at 8:51=E2=80=AFPM Mayur Kumar <[email protected]> w=
rote:
>
> ESMT eMMC (SM0000) supports normal TRIM discard, but fails when TRIM
> is used to offload WRITE_ZEROES operations.

Out of curiosity, how does it fail?

>
> Add a new card quirk, MMC_QUIRK_BROKEN_WRITE_ZEROES, to prevent setting
> max_write_zeroes_sectors during queue setup when this quirk is present.
> Apply this fixup to ESMT eMMC devices (CID_MANFID_ESM_MMC 0xEC,
> CID 'SM0000').
>
> Signed-off-by: Mayur Kumar <[email protected]>
> ---
>  drivers/mmc/core/card.h   | 1 +
>  drivers/mmc/core/queue.c  | 3 ++-
>  drivers/mmc/core/quirks.h | 6 ++++++
>  include/linux/mmc/card.h  | 1 +
>  4 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/core/card.h b/drivers/mmc/core/card.h
> index a7c364d0030..144a8f5e7d2 100644
> --- a/drivers/mmc/core/card.h
> +++ b/drivers/mmc/core/card.h
> @@ -94,6 +94,7 @@ struct mmc_fixup {
>  #define CID_MANFID_KINGSTON     0x70
>  #define CID_MANFID_HYNIX       0x90
>  #define CID_MANFID_KINGSTON_SD 0x9F
> +#define CID_MANFID_ESMT_MMC    0xEC
>  #define CID_MANFID_NUMONYX     0xFE
>
>  #define END_FIXUP { NULL }
> diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c
> index 5d187e063da..3ee640056a5 100644
> --- a/drivers/mmc/core/queue.c
> +++ b/drivers/mmc/core/queue.c
> @@ -191,7 +191,8 @@ static void mmc_queue_setup_discard(struct mmc_card *=
card,
>                         lim->max_secure_erase_sectors =3D max_discard;
>         }
>
> -       if (mmc_card_can_trim(card) && card->erased_byte =3D=3D 0)
> +       if (mmc_card_can_trim(card) && card->erased_byte =3D=3D 0 &&
> +           !(card->quirks & MMC_QUIRK_BROKEN_WRITE_ZEROS))

Please add a helper in card.h, similar to the others "mmc_card_broken_*".

>                 lim->max_write_zeroes_sectors =3D max_discard;
>
>         /* granularity must not be greater than max. discard */
> diff --git a/drivers/mmc/core/quirks.h b/drivers/mmc/core/quirks.h
> index ae3ece89d0a..91758fd7fc2 100644
> --- a/drivers/mmc/core/quirks.h
> +++ b/drivers/mmc/core/quirks.h
> @@ -91,6 +91,12 @@ static const struct mmc_fixup __maybe_unused mmc_blk_f=
ixups[] =3D {
>         MMC_FIXUP("MMC32G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_=
mmc,
>                   MMC_QUIRK_BLK_NO_CMD23),
>
> +       /* SM0000 supports normal TRIM discard but fails when TRIM is
> +        * used to offload WRITE_ZEROES, so we disable it.
> +        */
> +       MMC_FIXUP("SM0000", CID_MANFID_ESMT_MMC, 0x0100, add_quirk_mmc,
> +                 MMC_QUIRK_BROKEN_WRITE_ZEROES),
> +
>         /*
>          * Some SD cards lockup while using CMD23 multiblock transfers.
>          */
> diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
> index 9dc4750296a..938a4296b55 100644
> --- a/include/linux/mmc/card.h
> +++ b/include/linux/mmc/card.h
> @@ -331,6 +331,7 @@ struct mmc_card {
>  #define MMC_QUIRK_NO_UHS_DDR50_TUNING  (1<<18) /* Disable DDR50 tuning *=
/
>  #define MMC_QUIRK_BROKEN_MDT    (1<<19) /* Wrong manufacturing year */
>  #define MMC_QUIRK_FIXED_SECURE_ERASE_TRIM_TIME (1<<20) /* Secure erase/t=
rim time is fixed regardless of size */
> +#define MMC_QUIRK_BROKEN_WRITE_ZEROES  (1<<21) /* Broken write zeroes vi=
a trim */
>
>         bool                    written_flag;   /* Indicates eMMC has bee=
n written since power on */
>         bool                    reenable_cmdq;  /* Re-enable Command Queu=
e */
> --
> 2.34.1
>

Kind regards
Uffe