Skip to content

Commit 4d0c8d0

Browse files
avri-altman-sndkstorulf
authored andcommitted
mmc: core: Use mrq.sbc in close-ended ffu
Field Firmware Update (ffu) may use close-ended or open ended sequence. Each such sequence is comprised of a write commands enclosed between 2 switch commands - to and from ffu mode. So for the close-ended case, it will be: cmd6->cmd23-cmd25-cmd6. Some host controllers however, get confused when multi-block rw is sent without sbc, and may generate auto-cmd12 which breaks the ffu sequence. I encountered this issue while testing fwupd (github.com/fwupd/fwupd) on HP Chromebook x2, a qualcomm based QC-7c, code name - strongbad. Instead of a quirk, or hooking the request function of the msm ops, it would be better to fix the ioctl handling and make it use mrq.sbc instead of issuing SET_BLOCK_COUNT separately. Signed-off-by: Avri Altman <avri.altman@wdc.com> Acked-by: Adrian Hunter <adrian.hunter@intel.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20231129092535.3278-1-avri.altman@wdc.com Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 5cb2f92 commit 4d0c8d0

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

drivers/mmc/core/block.c

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ struct mmc_blk_ioc_data {
400400
struct mmc_ioc_cmd ic;
401401
unsigned char *buf;
402402
u64 buf_bytes;
403+
unsigned int flags;
404+
#define MMC_BLK_IOC_DROP BIT(0) /* drop this mrq */
405+
#define MMC_BLK_IOC_SBC BIT(1) /* use mrq.sbc */
406+
403407
struct mmc_rpmb_data *rpmb;
404408
};
405409

@@ -465,7 +469,7 @@ static int mmc_blk_ioctl_copy_to_user(struct mmc_ioc_cmd __user *ic_ptr,
465469
}
466470

467471
static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
468-
struct mmc_blk_ioc_data *idata)
472+
struct mmc_blk_ioc_data **idatas, int i)
469473
{
470474
struct mmc_command cmd = {}, sbc = {};
471475
struct mmc_data data = {};
@@ -475,10 +479,18 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
475479
unsigned int busy_timeout_ms;
476480
int err;
477481
unsigned int target_part;
482+
struct mmc_blk_ioc_data *idata = idatas[i];
483+
struct mmc_blk_ioc_data *prev_idata = NULL;
478484

479485
if (!card || !md || !idata)
480486
return -EINVAL;
481487

488+
if (idata->flags & MMC_BLK_IOC_DROP)
489+
return 0;
490+
491+
if (idata->flags & MMC_BLK_IOC_SBC)
492+
prev_idata = idatas[i - 1];
493+
482494
/*
483495
* The RPMB accesses comes in from the character device, so we
484496
* need to target these explicitly. Else we just target the
@@ -532,14 +544,16 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
532544
return err;
533545
}
534546

535-
if (idata->rpmb) {
547+
if (idata->rpmb || prev_idata) {
536548
sbc.opcode = MMC_SET_BLOCK_COUNT;
537549
/*
538550
* We don't do any blockcount validation because the max size
539551
* may be increased by a future standard. We just copy the
540552
* 'Reliable Write' bit here.
541553
*/
542554
sbc.arg = data.blocks | (idata->ic.write_flag & BIT(31));
555+
if (prev_idata)
556+
sbc.arg = prev_idata->ic.arg;
543557
sbc.flags = MMC_RSP_R1 | MMC_CMD_AC;
544558
mrq.sbc = &sbc;
545559
}
@@ -557,6 +571,15 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
557571
mmc_wait_for_req(card->host, &mrq);
558572
memcpy(&idata->ic.response, cmd.resp, sizeof(cmd.resp));
559573

574+
if (prev_idata) {
575+
memcpy(&prev_idata->ic.response, sbc.resp, sizeof(sbc.resp));
576+
if (sbc.error) {
577+
dev_err(mmc_dev(card->host), "%s: sbc error %d\n",
578+
__func__, sbc.error);
579+
return sbc.error;
580+
}
581+
}
582+
560583
if (cmd.error) {
561584
dev_err(mmc_dev(card->host), "%s: cmd error %d\n",
562585
__func__, cmd.error);
@@ -1032,6 +1055,20 @@ static inline void mmc_blk_reset_success(struct mmc_blk_data *md, int type)
10321055
md->reset_done &= ~type;
10331056
}
10341057

1058+
static void mmc_blk_check_sbc(struct mmc_queue_req *mq_rq)
1059+
{
1060+
struct mmc_blk_ioc_data **idata = mq_rq->drv_op_data;
1061+
int i;
1062+
1063+
for (i = 1; i < mq_rq->ioc_count; i++) {
1064+
if (idata[i - 1]->ic.opcode == MMC_SET_BLOCK_COUNT &&
1065+
mmc_op_multi(idata[i]->ic.opcode)) {
1066+
idata[i - 1]->flags |= MMC_BLK_IOC_DROP;
1067+
idata[i]->flags |= MMC_BLK_IOC_SBC;
1068+
}
1069+
}
1070+
}
1071+
10351072
/*
10361073
* The non-block commands come back from the block layer after it queued it and
10371074
* processed it with all other requests and then they get issued in this
@@ -1059,11 +1096,14 @@ static void mmc_blk_issue_drv_op(struct mmc_queue *mq, struct request *req)
10591096
if (ret)
10601097
break;
10611098
}
1099+
1100+
mmc_blk_check_sbc(mq_rq);
1101+
10621102
fallthrough;
10631103
case MMC_DRV_OP_IOCTL_RPMB:
10641104
idata = mq_rq->drv_op_data;
10651105
for (i = 0, ret = 0; i < mq_rq->ioc_count; i++) {
1066-
ret = __mmc_blk_ioctl_cmd(card, md, idata[i]);
1106+
ret = __mmc_blk_ioctl_cmd(card, md, idata, i);
10671107
if (ret)
10681108
break;
10691109
}

0 commit comments

Comments
 (0)