@@ -59,10 +59,6 @@ MODULE_ALIAS("mmc:block");
5959#define INAND_CMD38_ARG_SECTRIM1 0x81
6060#define INAND_CMD38_ARG_SECTRIM2 0x88
6161
62- #define REL_WRITES_SUPPORTED (card ) (mmc_card_mmc((card)) && \
63- (((card)->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN) || \
64- ((card)->ext_csd.rel_sectors)))
65-
6662static DEFINE_MUTEX (block_mutex );
6763
6864/*
@@ -90,6 +86,10 @@ struct mmc_blk_data {
9086 struct mmc_queue queue ;
9187 struct list_head part ;
9288
89+ unsigned int flags ;
90+ #define MMC_BLK_CMD23 (1 << 0) /* Can do SET_BLOCK_COUNT for multiblock */
91+ #define MMC_BLK_REL_WR (1 << 1) /* MMC Reliable write support */
92+
9393 unsigned int usage ;
9494 unsigned int read_only ;
9595 unsigned int part_type ;
@@ -429,6 +429,7 @@ static const struct block_device_operations mmc_bdops = {
429429
430430struct mmc_blk_request {
431431 struct mmc_request mrq ;
432+ struct mmc_command sbc ;
432433 struct mmc_command cmd ;
433434 struct mmc_command stop ;
434435 struct mmc_data data ;
@@ -652,13 +653,10 @@ static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req)
652653 * reliable write can handle, thus finish the request in
653654 * partial completions.
654655 */
655- static inline int mmc_apply_rel_rw (struct mmc_blk_request * brq ,
656- struct mmc_card * card ,
657- struct request * req )
656+ static inline void mmc_apply_rel_rw (struct mmc_blk_request * brq ,
657+ struct mmc_card * card ,
658+ struct request * req )
658659{
659- int err ;
660- struct mmc_command set_count = {0 };
661-
662660 if (!(card -> ext_csd .rel_param & EXT_CSD_WR_REL_PARAM_EN )) {
663661 /* Legacy mode imposes restrictions on transfers. */
664662 if (!IS_ALIGNED (brq -> cmd .arg , card -> ext_csd .rel_sectors ))
@@ -669,15 +667,6 @@ static inline int mmc_apply_rel_rw(struct mmc_blk_request *brq,
669667 else if (brq -> data .blocks < card -> ext_csd .rel_sectors )
670668 brq -> data .blocks = 1 ;
671669 }
672-
673- set_count .opcode = MMC_SET_BLOCK_COUNT ;
674- set_count .arg = brq -> data .blocks | (1 << 31 );
675- set_count .flags = MMC_RSP_R1 | MMC_CMD_AC ;
676- err = mmc_wait_for_cmd (card -> host , & set_count , 0 );
677- if (err )
678- printk (KERN_ERR "%s: error %d SET_BLOCK_COUNT\n" ,
679- req -> rq_disk -> disk_name , err );
680- return err ;
681670}
682671
683672static int mmc_blk_issue_rw_rq (struct mmc_queue * mq , struct request * req )
@@ -694,7 +683,7 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
694683 bool do_rel_wr = ((req -> cmd_flags & REQ_FUA ) ||
695684 (req -> cmd_flags & REQ_META )) &&
696685 (rq_data_dir (req ) == WRITE ) &&
697- REL_WRITES_SUPPORTED ( card );
686+ ( md -> flags & MMC_BLK_REL_WR );
698687
699688 do {
700689 struct mmc_command cmd = {0 };
@@ -732,11 +721,9 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
732721
733722 if (brq .data .blocks > 1 || do_rel_wr ) {
734723 /* SPI multiblock writes terminate using a special
735- * token, not a STOP_TRANSMISSION request. Reliable
736- * writes use SET_BLOCK_COUNT and do not use a
737- * STOP_TRANSMISSION request either.
724+ * token, not a STOP_TRANSMISSION request.
738725 */
739- if (( !mmc_host_is_spi (card -> host ) && ! do_rel_wr ) ||
726+ if (!mmc_host_is_spi (card -> host ) ||
740727 rq_data_dir (req ) == READ )
741728 brq .mrq .stop = & brq .stop ;
742729 readcmd = MMC_READ_MULTIPLE_BLOCK ;
@@ -754,8 +741,37 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
754741 brq .data .flags |= MMC_DATA_WRITE ;
755742 }
756743
757- if (do_rel_wr && mmc_apply_rel_rw (& brq , card , req ))
758- goto cmd_err ;
744+ if (do_rel_wr )
745+ mmc_apply_rel_rw (& brq , card , req );
746+
747+ /*
748+ * Pre-defined multi-block transfers are preferable to
749+ * open ended-ones (and necessary for reliable writes).
750+ * However, it is not sufficient to just send CMD23,
751+ * and avoid the final CMD12, as on an error condition
752+ * CMD12 (stop) needs to be sent anyway. This, coupled
753+ * with Auto-CMD23 enhancements provided by some
754+ * hosts, means that the complexity of dealing
755+ * with this is best left to the host. If CMD23 is
756+ * supported by card and host, we'll fill sbc in and let
757+ * the host deal with handling it correctly. This means
758+ * that for hosts that don't expose MMC_CAP_CMD23, no
759+ * change of behavior will be observed.
760+ *
761+ * N.B: Some MMC cards experience perf degradation.
762+ * We'll avoid using CMD23-bounded multiblock writes for
763+ * these, while retaining features like reliable writes.
764+ */
765+
766+ if ((md -> flags & MMC_BLK_CMD23 ) &&
767+ mmc_op_multi (brq .cmd .opcode ) &&
768+ (do_rel_wr || !(card -> quirks & MMC_QUIRK_BLK_NO_CMD23 ))) {
769+ brq .sbc .opcode = MMC_SET_BLOCK_COUNT ;
770+ brq .sbc .arg = brq .data .blocks |
771+ (do_rel_wr ? (1 << 31 ) : 0 );
772+ brq .sbc .flags = MMC_RSP_R1 | MMC_CMD_AC ;
773+ brq .mrq .sbc = & brq .sbc ;
774+ }
759775
760776 mmc_set_data_timeout (& brq .data , card );
761777
@@ -792,7 +808,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
792808 * until later as we need to wait for the card to leave
793809 * programming mode even when things go wrong.
794810 */
795- if (brq .cmd .error || brq .data .error || brq .stop .error ) {
811+ if (brq .sbc .error || brq .cmd .error ||
812+ brq .data .error || brq .stop .error ) {
796813 if (brq .data .blocks > 1 && rq_data_dir (req ) == READ ) {
797814 /* Redo read one sector at a time */
798815 printk (KERN_WARNING "%s: retrying using single "
@@ -803,6 +820,13 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
803820 status = get_card_status (card , req );
804821 }
805822
823+ if (brq .sbc .error ) {
824+ printk (KERN_ERR "%s: error %d sending SET_BLOCK_COUNT "
825+ "command, response %#x, card status %#x\n" ,
826+ req -> rq_disk -> disk_name , brq .sbc .error ,
827+ brq .sbc .resp [0 ], status );
828+ }
829+
806830 if (brq .cmd .error ) {
807831 printk (KERN_ERR "%s: error %d sending read/write "
808832 "command, response %#x, card status %#x\n" ,
@@ -1014,8 +1038,6 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
10141038 md -> disk -> queue = md -> queue .queue ;
10151039 md -> disk -> driverfs_dev = parent ;
10161040 set_disk_ro (md -> disk , md -> read_only || default_ro );
1017- if (REL_WRITES_SUPPORTED (card ))
1018- blk_queue_flush (md -> queue .queue , REQ_FLUSH | REQ_FUA );
10191041
10201042 /*
10211043 * As discussed on lkml, GENHD_FL_REMOVABLE should:
@@ -1034,6 +1056,19 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
10341056
10351057 blk_queue_logical_block_size (md -> queue .queue , 512 );
10361058 set_capacity (md -> disk , size );
1059+
1060+ if (mmc_host_cmd23 (card -> host ) &&
1061+ mmc_card_mmc (card ))
1062+ md -> flags |= MMC_BLK_CMD23 ;
1063+
1064+ if (mmc_card_mmc (card ) &&
1065+ md -> flags & MMC_BLK_CMD23 &&
1066+ ((card -> ext_csd .rel_param & EXT_CSD_WR_REL_PARAM_EN ) ||
1067+ card -> ext_csd .rel_sectors )) {
1068+ md -> flags |= MMC_BLK_REL_WR ;
1069+ blk_queue_flush (md -> queue .queue , REQ_FLUSH | REQ_FUA );
1070+ }
1071+
10371072 return md ;
10381073
10391074 err_putdisk :
@@ -1189,6 +1224,21 @@ static const struct mmc_fixup blk_fixups[] =
11891224 MMC_FIXUP ("SEM08G" , 0x2 , 0x100 , add_quirk , MMC_QUIRK_INAND_CMD38 ),
11901225 MMC_FIXUP ("SEM16G" , 0x2 , 0x100 , add_quirk , MMC_QUIRK_INAND_CMD38 ),
11911226 MMC_FIXUP ("SEM32G" , 0x2 , 0x100 , add_quirk , MMC_QUIRK_INAND_CMD38 ),
1227+
1228+ /*
1229+ * Some MMC cards experience performance degradation with CMD23
1230+ * instead of CMD12-bounded multiblock transfers. For now we'll
1231+ * black list what's bad...
1232+ * - Certain Toshiba cards.
1233+ *
1234+ * N.B. This doesn't affect SD cards.
1235+ */
1236+ MMC_FIXUP ("MMC08G" , 0x11 , CID_OEMID_ANY , add_quirk_mmc ,
1237+ MMC_QUIRK_BLK_NO_CMD23 ),
1238+ MMC_FIXUP ("MMC16G" , 0x11 , CID_OEMID_ANY , add_quirk_mmc ,
1239+ MMC_QUIRK_BLK_NO_CMD23 ),
1240+ MMC_FIXUP ("MMC32G" , 0x11 , CID_OEMID_ANY , add_quirk_mmc ,
1241+ MMC_QUIRK_BLK_NO_CMD23 ),
11921242 END_FIXUP
11931243};
11941244
0 commit comments