From owner-freebsd-arm@freebsd.org Mon Sep 17 20:35:19 2018 Return-Path: Delivered-To: freebsd-arm@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8F9FB10A6CC3 for ; Mon, 17 Sep 2018 20:35:19 +0000 (UTC) (envelope-from marklmi@yahoo.com) Received: from sonic309-21.consmr.mail.ne1.yahoo.com (sonic309-21.consmr.mail.ne1.yahoo.com [66.163.184.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 300738C2AB for ; Mon, 17 Sep 2018 20:35:18 +0000 (UTC) (envelope-from marklmi@yahoo.com) X-YMail-OSG: zsDuwxwVM1kbVPBRKhdnz_aX_b43Bv_givosqtwWjT3Rt9UrQXRalwgyUeWnpHK jQmDJQvRyZMhClRMi_fRv2RzIGqEHmDMP5Rk8yM.LbBeVImMsyKw8jQEZEQCdFq.5ir5oofclwPP 16H.ZRqzGpxhKoke_5mN1I_wDZ.un9KW.lbk2uwSYUP8QahYXU8_nuOPhmtKqJQx4mLtU54pmY3P kDskhLUbpgJDcX4Vic1Q8BMfNpPil__YshJUaQnNL9H3Wh9K4cFlhY_ER_e_hEuIqZRWxsrpjEke nt8S3ko7TuNgSGid82ZEwIUPEUkUcy_HsN7JD.AkiPhKxErX27hesXxOCHNVPvKc2q0NRAM.oOLC B.eJnpX3RGwugCHFO3Kfx2ebsYmUJKPfDiKMEnVN5p6qCjLwW5oYcw8xMmL99H9q_byRk_nZ4icn TQmK6cCXPI8wNVEYcwiPW2BGZ1EP36dGBxn_QHS0SUW0jWifV6ysPhrD7714AiDh0RhEVVf.LMmH C2TwFxJQyDDXL8w5QKSo.3av.Um0wlmhpmw1Jgf4AD6u5bIeGN1Xou1pXh1yU_fE_ExIVUtNYiWE rLD7e0ZZ8LlYQeduAubaj9hqctgJIp4VI93fyMNOfOPOjGmrB6_X_UeBQSfy29E4Q9KLoYbEJIHB wv.aWhUn1ool_Mbj3mFvOhZwn6iX9PfF7xAoKmH3w1lkjWFZ_JWj1MEw7iD4qrtJiI5aNVp9VDH6 SPGJMftgYYMVgq9CKJUFqpClgqRniiQv13e3twcOx3oJLTJIt_EDoRS8an1IQ.K_FbmCFqC1GTGl QiJ6NnpV5m2PFC898x4hiNk1njdM5lGy_yAHw7vTF6C1wnm6Gq4h4foUSSqTKAfuoh_Sw5VY8YW9 smYtNJWJTANZw2XxnMb0BnrLm4U5s2JZVOPyLT9xuv4o3wHKguGtGodAKID_0c.VINygKq32l7XU Se1ilGDCYg0hZG0YooBCzCpe6u..d9CZZoIhbIFnzQxUNlaTz.Mv4CW_D9WXIn1_4Fuh9qPKgXQW XHmVPl4wHEtuE Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ne1.yahoo.com with HTTP; Mon, 17 Sep 2018 20:35:17 +0000 Received: from ip70-189-131-151.lv.lv.cox.net (EHLO [192.168.0.105]) ([70.189.131.151]) by smtp406.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 25a4b4b42780b2c31cc8ffe067ddea17; Mon, 17 Sep 2018 20:35:15 +0000 (UTC) From: Mark Millard Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: An experiment in enabling discard with e.MMC trim on a Pine64+ 2GB (based on head -r338675) Message-Id: <670AF48A-77BF-4246-BD80-9D067CB05DE3@yahoo.com> Date: Mon, 17 Sep 2018 13:35:14 -0700 To: freebsd-hackers@freebsd.org, freebsd-arm X-Mailer: Apple Mail (2.3445.9.1) X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "Porting FreeBSD to ARM processors." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Sep 2018 20:35:19 -0000 As stands this is just investigatory material. Also, I first had to enable using an e.MMC on a microsd card adapter on the Pine64+ 2GB, so those changes are listed too. The goal was for e.MMC 4.5+ to enable the discard bit with the trim bit to allow an e.MMC to not necessarily force the trim'ed data to become all zeros or all ones: the performance command trim variant that does not require data removal (but allows it). (I did nothing about discard from the modern sd card material. I doubt that I have any test context for that.) Unfortunately I have a very narrow range as far as test environments go currently: just Pine64+ 2GB and just one type of e.MMC in use. But for the context that I have it seems to be working. The discard-enabling related changes are in: /usr/src/sys/dev/mmc/mmcreg.h (an additional #define) /usr/src/sys/dev/mmc/mmcsd.c As stands I have nothing for overriding e.MMC 4.5+ using discard with trim (when trim is enabled via the historical criteria). If trim without discard worked but with discard did not for some device this could be a problem. Also: if trim without discard is desired for security reasons it would be a problem. But what I have here is sufficient for my basic testing. The Pine64+ 2GB e.MMC-on-adapter enabling changes are in: /usr/src/sys/dev/mmc/mmcreg.h (a renamed #define as a form of = commentary) /usr/src/sys/dev/mmc/mmc.c (not really Pine64+ 2GB or A64 specific) /usr/src/sys/arm/allwinner/aw_mmc.c (MMC_CAP_SIGNALING_180 part: Pine64+ = 2GB or A64 specific) (So mmcreg.h has something for each part.) I expect the mmc.c change is a generic correction to more accurately follow the e.MMC DDR52 definition as far as voltage requirements go. But it was driven by the Pine64+ 2GB properties leading to wanting the change. The changes for discard ( and mmcreg.h ) are: Index: /usr/src/sys/dev/mmc/mmcreg.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- /usr/src/sys/dev/mmc/mmcreg.h (revision 338675) +++ /usr/src/sys/dev/mmc/mmcreg.h (working copy) @@ -463,7 +463,7 @@ =20 #define EXT_CSD_CARD_TYPE_HS_26 0x0001 #define EXT_CSD_CARD_TYPE_HS_52 0x0002 -#define EXT_CSD_CARD_TYPE_DDR_52_1_8V 0x0004 +#define EXT_CSD_CARD_TYPE_DDR_52_3V_OR_1_8V 0x0004 #define EXT_CSD_CARD_TYPE_DDR_52_1_2V 0x0008 #define EXT_CSD_CARD_TYPE_HS200_1_8V 0x0010 #define EXT_CSD_CARD_TYPE_HS200_1_2V 0x0020 @@ -493,6 +493,7 @@ #define EXT_CSD_INAND_CMD38 113 #define EXT_CSD_INAND_CMD38_ERASE 0x00 #define EXT_CSD_INAND_CMD38_TRIM 0x01 +#define EXT_CSD_INAND_CMD38_DISCARD_WITH_MMC_TRIM = 0x03 #define EXT_CSD_INAND_CMD38_SECURE_ERASE 0x80 #define EXT_CSD_INAND_CMD38_SECURE_TRIM1 0x81 #define EXT_CSD_INAND_CMD38_SECURE_TRIM2 0x82 Index: /usr/src/sys/dev/mmc/mmcsd.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- /usr/src/sys/dev/mmc/mmcsd.c (revision 338675) +++ /usr/src/sys/dev/mmc/mmcsd.c (working copy) @@ -136,6 +136,7 @@ #define MMCSD_USE_TRIM 0x0002 #define MMCSD_FLUSH_CACHE 0x0004 #define MMCSD_DIRTY 0x0008 +#define MMCSD_USE_DISCARD_WITH_MMC_TRIM 0x0010 uint32_t cmd6_time; /* Generic switch timeout [us] */ uint32_t part_time; /* Partition switch timeout [us] */ off_t enh_base; /* Enhanced user data area slice base = ... */ @@ -297,6 +298,8 @@ device_printf(dev, "taking advantage of = TRIM\n"); sc->flags |=3D MMCSD_USE_TRIM; sc->erase_sector =3D 1; + if (6 <=3D ext_csd[EXT_CSD_REV]) // e.MMC 4.5 or later + sc->flags |=3D MMCSD_USE_DISCARD_WITH_MMC_TRIM; } else sc->erase_sector =3D mmc_get_erase_sector(dev); =20 @@ -1251,7 +1254,7 @@ device_t dev, mmcbus; u_int erase_sector, sz; int err; - bool use_trim; + bool use_trim, use_discard_with_mmc_trim; =20 sc =3D part->sc; dev =3D sc->dev; @@ -1261,6 +1264,7 @@ sz =3D part->disk->d_sectorsize; end =3D bp->bio_pblkno + (bp->bio_bcount / sz); use_trim =3D sc->flags & MMCSD_USE_TRIM; + use_discard_with_mmc_trim =3D sc->flags & = MMCSD_USE_DISCARD_WITH_MMC_TRIM; if (use_trim =3D=3D true) { start =3D block; stop =3D end; @@ -1289,8 +1293,10 @@ =20 if ((sc->flags & MMCSD_INAND_CMD38) !=3D 0) { err =3D mmc_switch(mmcbus, dev, sc->rca, = EXT_CSD_CMD_SET_NORMAL, - EXT_CSD_INAND_CMD38, use_trim =3D=3D true ? - EXT_CSD_INAND_CMD38_TRIM : = EXT_CSD_INAND_CMD38_ERASE, + EXT_CSD_INAND_CMD38, + use_discard_with_mmc_trim ? = EXT_CSD_INAND_CMD38_DISCARD_WITH_MMC_TRIM + : use_trim ? EXT_CSD_INAND_CMD38_TRIM + : EXT_CSD_INAND_CMD38_ERASE, sc->cmd6_time, true); if (err !=3D MMC_ERR_NONE) { device_printf(dev, As for enabling the Pine64+ 2GB e.MMC use (parts of which may be more general): Index: /usr/src/sys/dev/mmc/mmc.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- /usr/src/sys/dev/mmc/mmc.c (revision 338675) +++ /usr/src/sys/dev/mmc/mmc.c (working copy) @@ -1814,10 +1814,10 @@ setbit(&ivar->timings, = bus_timing_mmc_ddr52); setbit(&ivar->vccq_120, = bus_timing_mmc_ddr52); } - if ((card_type & EXT_CSD_CARD_TYPE_DDR_52_1_8V) = !=3D 0 && - (host_caps & MMC_CAP_SIGNALING_180) !=3D 0) = { + if ((card_type & = EXT_CSD_CARD_TYPE_DDR_52_3V_OR_1_8V) !=3D 0) { setbit(&ivar->timings, = bus_timing_mmc_ddr52); - setbit(&ivar->vccq_180, = bus_timing_mmc_ddr52); + if ((host_caps & MMC_CAP_SIGNALING_180) = !=3D 0) + setbit(&ivar->vccq_180, = bus_timing_mmc_ddr52); } if ((card_type & EXT_CSD_CARD_TYPE_HS200_1_2V) = !=3D 0 && (host_caps & MMC_CAP_SIGNALING_120) !=3D 0) = { Index: /usr/src/sys/arm/allwinner/aw_mmc.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- /usr/src/sys/arm/allwinner/aw_mmc.c (revision 338675) +++ /usr/src/sys/arm/allwinner/aw_mmc.c (working copy) @@ -509,7 +509,7 @@ MMC_CAP_UHS_SDR25 | MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_DDR50 | MMC_CAP_MMC_DDR52; =20 - sc->aw_host.caps |=3D MMC_CAP_SIGNALING_330 | = MMC_CAP_SIGNALING_180; + sc->aw_host.caps |=3D MMC_CAP_SIGNALING_330; // | = MMC_CAP_SIGNALING_180; not used on Pine64+ 2GB =20 if (bus_width >=3D 4) sc->aw_host.caps |=3D MMC_CAP_4_BIT_DATA; @@ -1308,17 +1308,20 @@ =20 sc =3D device_get_softc(bus); =20 - if (sc->aw_reg_vqmmc =3D=3D NULL) - return EOPNOTSUPP; - switch (sc->aw_host.ios.vccq) { case vccq_180: + if (sc->aw_reg_vqmmc =3D=3D NULL) + return EOPNOTSUPP; uvolt =3D 1800000; break; case vccq_330: + if (sc->aw_reg_vqmmc =3D=3D NULL) // implicitly already = stuck at vccq_330 + return 0; // avoid calling code treating the = assignment attempt as an error uvolt =3D 3300000; break; default: + if (sc->aw_reg_vqmmc =3D=3D NULL) + return EOPNOTSUPP; return EINVAL; } =20 I wonder if the sc->aw_reg_vqmmc =3D=3D NULL handling change may be more general than the Pine64+ 2GB (A64) context. Anyway that is what I have so far. See any problems? Would FreeBSD even want to support e.MMC 4.5+'s discard with trim (probably with more control over if it was used)? If yes, I'd presume not until 13.0 . =3D=3D=3D Mark Millard marklmi at yahoo.com ( dsl-only.net went away in early 2018-Mar)