2 * Block driver for media (i.e., flash cards)
4 * Copyright 2002 Hewlett-Packard Company
5 * Copyright 2005-2008 Pierre Ossman
7 * Use consistent with the GNU GPL is permitted,
8 * provided that this copyright notice is
9 * preserved in its entirety in all copies and derived works.
11 * HEWLETT-PACKARD COMPANY MAKES NO WARRANTIES, EXPRESSED OR IMPLIED,
12 * AS TO THE USEFULNESS OR CORRECTNESS OF THIS CODE OR ITS
13 * FITNESS FOR ANY PARTICULAR PURPOSE.
15 * Many thanks to Alessandro Rubini and Jonathan Corbet!
17 * Author: Andrew Christian
20 #include <linux/moduleparam.h>
21 #include <linux/module.h>
22 #include <linux/init.h>
24 #include <linux/kernel.h>
26 #include <linux/slab.h>
27 #include <linux/errno.h>
28 #include <linux/hdreg.h>
29 #include <linux/kdev_t.h>
30 #include <linux/blkdev.h>
31 #include <linux/mutex.h>
32 #include <linux/scatterlist.h>
33 #include <linux/string_helpers.h>
34 #include <linux/delay.h>
35 #include <linux/capability.h>
36 #include <linux/compat.h>
38 #define CREATE_TRACE_POINTS
39 #include <trace/events/mmc.h>
41 #include <linux/mmc/ioctl.h>
42 #include <linux/mmc/card.h>
43 #include <linux/mmc/host.h>
44 #include <linux/mmc/mmc.h>
45 #include <linux/mmc/sd.h>
47 #include <asm/uaccess.h>
51 MODULE_ALIAS("mmc:block");
52 #ifdef MODULE_PARAM_PREFIX
53 #undef MODULE_PARAM_PREFIX
55 #define MODULE_PARAM_PREFIX "mmcblk."
57 #define INAND_CMD38_ARG_EXT_CSD 113
58 #define INAND_CMD38_ARG_ERASE 0x00
59 #define INAND_CMD38_ARG_TRIM 0x01
60 #define INAND_CMD38_ARG_SECERASE 0x80
61 #define INAND_CMD38_ARG_SECTRIM1 0x81
62 #define INAND_CMD38_ARG_SECTRIM2 0x88
63 #define MMC_BLK_TIMEOUT_MS (10 * 60 * 1000) /* 10 minute timeout */
65 #define mmc_req_rel_wr(req) (((req->cmd_flags & REQ_FUA) || \
66 (req->cmd_flags & REQ_META)) && \
67 (rq_data_dir(req) == WRITE))
68 #define PACKED_CMD_VER 0x01
69 #define PACKED_CMD_WR 0x02
71 static DEFINE_MUTEX(block_mutex);
74 * The defaults come from config options but can be overriden by module
77 static int perdev_minors = CONFIG_MMC_BLOCK_MINORS;
80 * We've only got one major, so number of mmcblk devices is
81 * limited to 256 / number of minors per device.
83 static int max_devices;
85 /* 256 minors, so at most 256 separate devices */
86 static DECLARE_BITMAP(dev_use, 256);
87 static DECLARE_BITMAP(name_use, 256);
90 * There is one mmc_blk_data per slot.
95 struct mmc_queue queue;
96 struct list_head part;
99 #define MMC_BLK_CMD23 (1 << 0) /* Can do SET_BLOCK_COUNT for multiblock */
100 #define MMC_BLK_REL_WR (1 << 1) /* MMC Reliable write support */
101 #define MMC_BLK_PACKED_CMD (1 << 2) /* MMC packed command support */
104 unsigned int read_only;
105 unsigned int part_type;
106 unsigned int name_idx;
107 unsigned int reset_done;
108 #define MMC_BLK_READ BIT(0)
109 #define MMC_BLK_WRITE BIT(1)
110 #define MMC_BLK_DISCARD BIT(2)
111 #define MMC_BLK_SECDISCARD BIT(3)
114 * Only set in main mmc_blk_data associated
115 * with mmc_card with mmc_set_drvdata, and keeps
116 * track of the current selected device partition.
118 unsigned int part_curr;
119 struct device_attribute force_ro;
120 struct device_attribute power_ro_lock;
124 static DEFINE_MUTEX(open_lock);
127 MMC_PACKED_NR_IDX = -1,
129 MMC_PACKED_NR_SINGLE,
132 module_param(perdev_minors, int, 0444);
133 MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device");
135 static inline int mmc_blk_part_switch(struct mmc_card *card,
136 struct mmc_blk_data *md);
137 static int get_card_status(struct mmc_card *card, u32 *status, int retries);
139 static inline void mmc_blk_clear_packed(struct mmc_queue_req *mqrq)
141 struct mmc_packed *packed = mqrq->packed;
145 mqrq->cmd_type = MMC_PACKED_NONE;
146 packed->nr_entries = MMC_PACKED_NR_ZERO;
147 packed->idx_failure = MMC_PACKED_NR_IDX;
152 static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk)
154 struct mmc_blk_data *md;
156 mutex_lock(&open_lock);
157 md = disk->private_data;
158 if (md && md->usage == 0)
162 mutex_unlock(&open_lock);
167 static inline int mmc_get_devidx(struct gendisk *disk)
169 int devidx = disk->first_minor / perdev_minors;
173 static void mmc_blk_put(struct mmc_blk_data *md)
175 mutex_lock(&open_lock);
177 if (md->usage == 0) {
178 int devidx = mmc_get_devidx(md->disk);
179 blk_cleanup_queue(md->queue.queue);
181 __clear_bit(devidx, dev_use);
186 mutex_unlock(&open_lock);
189 static ssize_t power_ro_lock_show(struct device *dev,
190 struct device_attribute *attr, char *buf)
193 struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
194 struct mmc_card *card = md->queue.card;
197 if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PERM_WP_EN)
199 else if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PWR_WP_EN)
202 ret = snprintf(buf, PAGE_SIZE, "%d\n", locked);
209 static ssize_t power_ro_lock_store(struct device *dev,
210 struct device_attribute *attr, const char *buf, size_t count)
213 struct mmc_blk_data *md, *part_md;
214 struct mmc_card *card;
217 if (kstrtoul(buf, 0, &set))
223 md = mmc_blk_get(dev_to_disk(dev));
224 card = md->queue.card;
226 mmc_claim_host(card->host);
228 ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_WP,
229 card->ext_csd.boot_ro_lock |
230 EXT_CSD_BOOT_WP_B_PWR_WP_EN,
231 card->ext_csd.part_time);
233 pr_err("%s: Locking boot partition ro until next power on failed: %d\n", md->disk->disk_name, ret);
235 card->ext_csd.boot_ro_lock |= EXT_CSD_BOOT_WP_B_PWR_WP_EN;
237 mmc_release_host(card->host);
240 pr_info("%s: Locking boot partition ro until next power on\n",
241 md->disk->disk_name);
242 set_disk_ro(md->disk, 1);
244 list_for_each_entry(part_md, &md->part, part)
245 if (part_md->area_type == MMC_BLK_DATA_AREA_BOOT) {
246 pr_info("%s: Locking boot partition ro until next power on\n", part_md->disk->disk_name);
247 set_disk_ro(part_md->disk, 1);
255 static ssize_t force_ro_show(struct device *dev, struct device_attribute *attr,
259 struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
261 ret = snprintf(buf, PAGE_SIZE, "%d\n",
262 get_disk_ro(dev_to_disk(dev)) ^
268 static ssize_t force_ro_store(struct device *dev, struct device_attribute *attr,
269 const char *buf, size_t count)
273 struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
274 unsigned long set = simple_strtoul(buf, &end, 0);
280 set_disk_ro(dev_to_disk(dev), set || md->read_only);
287 static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
289 struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk);
292 mutex_lock(&block_mutex);
295 check_disk_change(bdev);
298 if ((mode & FMODE_WRITE) && md->read_only) {
303 mutex_unlock(&block_mutex);
308 static void mmc_blk_release(struct gendisk *disk, fmode_t mode)
310 struct mmc_blk_data *md = disk->private_data;
312 mutex_lock(&block_mutex);
314 mutex_unlock(&block_mutex);
318 mmc_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
320 geo->cylinders = get_capacity(bdev->bd_disk) / (4 * 16);
326 struct mmc_blk_ioc_data {
327 struct mmc_ioc_cmd ic;
332 static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user(
333 struct mmc_ioc_cmd __user *user)
335 struct mmc_blk_ioc_data *idata;
338 idata = kzalloc(sizeof(*idata), GFP_KERNEL);
344 if (copy_from_user(&idata->ic, user, sizeof(idata->ic))) {
349 idata->buf_bytes = (u64) idata->ic.blksz * idata->ic.blocks;
350 if (idata->buf_bytes > MMC_IOC_MAX_BYTES) {
355 if (!idata->buf_bytes)
358 idata->buf = kzalloc(idata->buf_bytes, GFP_KERNEL);
364 if (copy_from_user(idata->buf, (void __user *)(unsigned long)
365 idata->ic.data_ptr, idata->buf_bytes)) {
380 static int ioctl_rpmb_card_status_poll(struct mmc_card *card, u32 *status,
386 if (!status || !retries_max)
390 err = get_card_status(card, status, 5);
394 if (!R1_STATUS(*status) &&
395 (R1_CURRENT_STATE(*status) != R1_STATE_PRG))
396 break; /* RPMB programming operation complete */
399 * Rechedule to give the MMC device a chance to continue
400 * processing the previous command without being polled too
403 usleep_range(1000, 5000);
404 } while (++retry_count < retries_max);
406 if (retry_count == retries_max)
412 static int mmc_blk_ioctl_cmd(struct block_device *bdev,
413 struct mmc_ioc_cmd __user *ic_ptr)
415 struct mmc_blk_ioc_data *idata;
416 struct mmc_blk_data *md;
417 struct mmc_card *card;
418 struct mmc_command cmd = {0};
419 struct mmc_data data = {0};
420 struct mmc_request mrq = {NULL};
421 struct scatterlist sg;
427 * The caller must have CAP_SYS_RAWIO, and must be calling this on the
428 * whole block device, not on a partition. This prevents overspray
429 * between sibling partitions.
431 if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains))
434 idata = mmc_blk_ioctl_copy_from_user(ic_ptr);
436 return PTR_ERR(idata);
438 md = mmc_blk_get(bdev->bd_disk);
444 if (md->area_type & MMC_BLK_DATA_AREA_RPMB)
447 card = md->queue.card;
453 cmd.opcode = idata->ic.opcode;
454 cmd.arg = idata->ic.arg;
455 cmd.flags = idata->ic.flags;
457 if (idata->buf_bytes) {
460 data.blksz = idata->ic.blksz;
461 data.blocks = idata->ic.blocks;
463 sg_init_one(data.sg, idata->buf, idata->buf_bytes);
465 if (idata->ic.write_flag)
466 data.flags = MMC_DATA_WRITE;
468 data.flags = MMC_DATA_READ;
470 /* data.flags must already be set before doing this. */
471 mmc_set_data_timeout(&data, card);
473 /* Allow overriding the timeout_ns for empirical tuning. */
474 if (idata->ic.data_timeout_ns)
475 data.timeout_ns = idata->ic.data_timeout_ns;
477 if ((cmd.flags & MMC_RSP_R1B) == MMC_RSP_R1B) {
479 * Pretend this is a data transfer and rely on the
480 * host driver to compute timeout. When all host
481 * drivers support cmd.cmd_timeout for R1B, this
485 * cmd.cmd_timeout = idata->ic.cmd_timeout_ms;
487 data.timeout_ns = idata->ic.cmd_timeout_ms * 1000000;
495 mmc_claim_host(card->host);
497 err = mmc_blk_part_switch(card, md);
501 if (idata->ic.is_acmd) {
502 err = mmc_app_cmd(card->host, card);
508 err = mmc_set_blockcount(card, data.blocks,
509 idata->ic.write_flag & (1 << 31));
514 mmc_wait_for_req(card->host, &mrq);
517 dev_err(mmc_dev(card->host), "%s: cmd error %d\n",
518 __func__, cmd.error);
523 dev_err(mmc_dev(card->host), "%s: data error %d\n",
524 __func__, data.error);
530 * According to the SD specs, some commands require a delay after
531 * issuing the command.
533 if (idata->ic.postsleep_min_us)
534 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
536 if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
541 if (!idata->ic.write_flag) {
542 if (copy_to_user((void __user *)(unsigned long) idata->ic.data_ptr,
543 idata->buf, idata->buf_bytes)) {
551 * Ensure RPMB command has completed by polling CMD13
554 err = ioctl_rpmb_card_status_poll(card, &status, 5);
556 dev_err(mmc_dev(card->host),
557 "%s: Card Status=0x%08X, error %d\n",
558 __func__, status, err);
562 mmc_release_host(card->host);
572 static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode,
573 unsigned int cmd, unsigned long arg)
576 if (cmd == MMC_IOC_CMD)
577 ret = mmc_blk_ioctl_cmd(bdev, (struct mmc_ioc_cmd __user *)arg);
582 static int mmc_blk_compat_ioctl(struct block_device *bdev, fmode_t mode,
583 unsigned int cmd, unsigned long arg)
585 return mmc_blk_ioctl(bdev, mode, cmd, (unsigned long) compat_ptr(arg));
589 static const struct block_device_operations mmc_bdops = {
590 .open = mmc_blk_open,
591 .release = mmc_blk_release,
592 .getgeo = mmc_blk_getgeo,
593 .owner = THIS_MODULE,
594 .ioctl = mmc_blk_ioctl,
596 .compat_ioctl = mmc_blk_compat_ioctl,
600 static inline int mmc_blk_part_switch(struct mmc_card *card,
601 struct mmc_blk_data *md)
604 struct mmc_blk_data *main_md = mmc_get_drvdata(card);
606 if (main_md->part_curr == md->part_type)
609 if (mmc_card_mmc(card)) {
610 u8 part_config = card->ext_csd.part_config;
612 part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK;
613 part_config |= md->part_type;
615 ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
616 EXT_CSD_PART_CONFIG, part_config,
617 card->ext_csd.part_time);
621 card->ext_csd.part_config = part_config;
624 main_md->part_curr = md->part_type;
628 static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
634 struct mmc_request mrq = {NULL};
635 struct mmc_command cmd = {0};
636 struct mmc_data data = {0};
638 struct scatterlist sg;
640 cmd.opcode = MMC_APP_CMD;
641 cmd.arg = card->rca << 16;
642 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
644 err = mmc_wait_for_cmd(card->host, &cmd, 0);
647 if (!mmc_host_is_spi(card->host) && !(cmd.resp[0] & R1_APP_CMD))
650 memset(&cmd, 0, sizeof(struct mmc_command));
652 cmd.opcode = SD_APP_SEND_NUM_WR_BLKS;
654 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
658 data.flags = MMC_DATA_READ;
661 mmc_set_data_timeout(&data, card);
666 blocks = kmalloc(4, GFP_KERNEL);
670 sg_init_one(&sg, blocks, 4);
672 mmc_wait_for_req(card->host, &mrq);
674 result = ntohl(*blocks);
677 if (cmd.error || data.error)
683 static int send_stop(struct mmc_card *card, u32 *status)
685 struct mmc_command cmd = {0};
688 cmd.opcode = MMC_STOP_TRANSMISSION;
689 cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
690 err = mmc_wait_for_cmd(card->host, &cmd, 5);
692 *status = cmd.resp[0];
696 static int get_card_status(struct mmc_card *card, u32 *status, int retries)
698 struct mmc_command cmd = {0};
701 cmd.opcode = MMC_SEND_STATUS;
702 if (!mmc_host_is_spi(card->host))
703 cmd.arg = card->rca << 16;
704 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
705 err = mmc_wait_for_cmd(card->host, &cmd, retries);
707 *status = cmd.resp[0];
711 #define ERR_NOMEDIUM 3
714 #define ERR_CONTINUE 0
716 static int mmc_blk_cmd_error(struct request *req, const char *name, int error,
717 bool status_valid, u32 status)
721 /* response crc error, retry the r/w cmd */
722 pr_err("%s: %s sending %s command, card status %#x\n",
723 req->rq_disk->disk_name, "response CRC error",
728 pr_err("%s: %s sending %s command, card status %#x\n",
729 req->rq_disk->disk_name, "timed out", name, status);
731 /* If the status cmd initially failed, retry the r/w cmd */
733 pr_err("%s: status not valid, retrying timeout\n", req->rq_disk->disk_name);
737 * If it was a r/w cmd crc error, or illegal command
738 * (eg, issued in wrong state) then retry - we should
739 * have corrected the state problem above.
741 if (status & (R1_COM_CRC_ERROR | R1_ILLEGAL_COMMAND)) {
742 pr_err("%s: command error, retrying timeout\n", req->rq_disk->disk_name);
746 /* Otherwise abort the command */
747 pr_err("%s: not retrying timeout\n", req->rq_disk->disk_name);
751 /* We don't understand the error code the driver gave us */
752 pr_err("%s: unknown error %d sending read/write command, card status %#x\n",
753 req->rq_disk->disk_name, error, status);
759 * Initial r/w and stop cmd error recovery.
760 * We don't know whether the card received the r/w cmd or not, so try to
761 * restore things back to a sane state. Essentially, we do this as follows:
762 * - Obtain card status. If the first attempt to obtain card status fails,
763 * the status word will reflect the failed status cmd, not the failed
764 * r/w cmd. If we fail to obtain card status, it suggests we can no
765 * longer communicate with the card.
766 * - Check the card state. If the card received the cmd but there was a
767 * transient problem with the response, it might still be in a data transfer
768 * mode. Try to send it a stop command. If this fails, we can't recover.
769 * - If the r/w cmd failed due to a response CRC error, it was probably
770 * transient, so retry the cmd.
771 * - If the r/w cmd timed out, but we didn't get the r/w cmd status, retry.
772 * - If the r/w cmd timed out, and the r/w cmd failed due to CRC error or
773 * illegal cmd, retry.
774 * Otherwise we don't understand what happened, so abort.
776 static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
777 struct mmc_blk_request *brq, int *ecc_err, int *gen_err)
779 bool prev_cmd_status_valid = true;
780 u32 status, stop_status = 0;
783 if (mmc_card_removed(card))
787 * Try to get card status which indicates both the card state
788 * and why there was no response. If the first attempt fails,
789 * we can't be sure the returned status is for the r/w command.
791 for (retry = 2; retry >= 0; retry--) {
792 err = get_card_status(card, &status, 0);
796 prev_cmd_status_valid = false;
797 pr_err("%s: error %d sending status command, %sing\n",
798 req->rq_disk->disk_name, err, retry ? "retry" : "abort");
801 /* We couldn't get a response from the card. Give up. */
803 /* Check if the card is removed */
804 if (mmc_detect_card_removed(card->host))
809 /* Flag ECC errors */
810 if ((status & R1_CARD_ECC_FAILED) ||
811 (brq->stop.resp[0] & R1_CARD_ECC_FAILED) ||
812 (brq->cmd.resp[0] & R1_CARD_ECC_FAILED))
815 /* Flag General errors */
816 if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ)
817 if ((status & R1_ERROR) ||
818 (brq->stop.resp[0] & R1_ERROR)) {
819 pr_err("%s: %s: general error sending stop or status command, stop cmd response %#x, card status %#x\n",
820 req->rq_disk->disk_name, __func__,
821 brq->stop.resp[0], status);
826 * Check the current card state. If it is in some data transfer
827 * mode, tell it to stop (and hopefully transition back to TRAN.)
829 if (R1_CURRENT_STATE(status) == R1_STATE_DATA ||
830 R1_CURRENT_STATE(status) == R1_STATE_RCV) {
831 err = send_stop(card, &stop_status);
833 pr_err("%s: error %d sending stop command\n",
834 req->rq_disk->disk_name, err);
837 * If the stop cmd also timed out, the card is probably
838 * not present, so abort. Other errors are bad news too.
842 if (stop_status & R1_CARD_ECC_FAILED)
844 if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ)
845 if (stop_status & R1_ERROR) {
846 pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n",
847 req->rq_disk->disk_name, __func__,
853 /* Check for set block count errors */
855 return mmc_blk_cmd_error(req, "SET_BLOCK_COUNT", brq->sbc.error,
856 prev_cmd_status_valid, status);
858 /* Check for r/w command errors */
860 return mmc_blk_cmd_error(req, "r/w cmd", brq->cmd.error,
861 prev_cmd_status_valid, status);
864 if (!brq->stop.error)
867 /* Now for stop errors. These aren't fatal to the transfer. */
868 pr_err("%s: error %d sending stop command, original cmd response %#x, card status %#x\n",
869 req->rq_disk->disk_name, brq->stop.error,
870 brq->cmd.resp[0], status);
873 * Subsitute in our own stop status as this will give the error
874 * state which happened during the execution of the r/w command.
877 brq->stop.resp[0] = stop_status;
883 static int mmc_blk_reset(struct mmc_blk_data *md, struct mmc_host *host,
888 if (md->reset_done & type)
891 md->reset_done |= type;
892 err = mmc_hw_reset(host);
893 /* Ensure we switch back to the correct partition */
894 if (err != -EOPNOTSUPP) {
895 struct mmc_blk_data *main_md = mmc_get_drvdata(host->card);
898 main_md->part_curr = main_md->part_type;
899 part_err = mmc_blk_part_switch(host->card, md);
902 * We have failed to get back into the correct
903 * partition, so we need to abort the whole request.
911 static inline void mmc_blk_reset_success(struct mmc_blk_data *md, int type)
913 md->reset_done &= ~type;
916 int mmc_access_rpmb(struct mmc_queue *mq)
918 struct mmc_blk_data *md = mq->data;
920 * If this is a RPMB partition access, return ture
922 if (md && md->part_type == EXT_CSD_PART_CONFIG_ACC_RPMB)
928 static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
930 struct mmc_blk_data *md = mq->data;
931 struct mmc_card *card = md->queue.card;
932 unsigned int from, nr, arg;
933 int err = 0, type = MMC_BLK_DISCARD;
935 if (!mmc_can_erase(card)) {
940 from = blk_rq_pos(req);
941 nr = blk_rq_sectors(req);
943 if (mmc_can_discard(card))
944 arg = MMC_DISCARD_ARG;
945 else if (mmc_can_trim(card))
950 if (card->quirks & MMC_QUIRK_INAND_CMD38) {
951 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
952 INAND_CMD38_ARG_EXT_CSD,
953 arg == MMC_TRIM_ARG ?
954 INAND_CMD38_ARG_TRIM :
955 INAND_CMD38_ARG_ERASE,
960 err = mmc_erase(card, from, nr, arg);
962 if (err == -EIO && !mmc_blk_reset(md, card->host, type))
965 mmc_blk_reset_success(md, type);
966 blk_end_request(req, err, blk_rq_bytes(req));
971 static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
974 struct mmc_blk_data *md = mq->data;
975 struct mmc_card *card = md->queue.card;
976 unsigned int from, nr, arg, trim_arg, erase_arg;
977 int err = 0, type = MMC_BLK_SECDISCARD;
979 if (!(mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))) {
984 from = blk_rq_pos(req);
985 nr = blk_rq_sectors(req);
987 /* The sanitize operation is supported at v4.5 only */
988 if (mmc_can_sanitize(card)) {
989 erase_arg = MMC_ERASE_ARG;
990 trim_arg = MMC_TRIM_ARG;
992 erase_arg = MMC_SECURE_ERASE_ARG;
993 trim_arg = MMC_SECURE_TRIM1_ARG;
996 if (mmc_erase_group_aligned(card, from, nr))
998 else if (mmc_can_trim(card))
1005 if (card->quirks & MMC_QUIRK_INAND_CMD38) {
1006 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1007 INAND_CMD38_ARG_EXT_CSD,
1008 arg == MMC_SECURE_TRIM1_ARG ?
1009 INAND_CMD38_ARG_SECTRIM1 :
1010 INAND_CMD38_ARG_SECERASE,
1016 err = mmc_erase(card, from, nr, arg);
1022 if (arg == MMC_SECURE_TRIM1_ARG) {
1023 if (card->quirks & MMC_QUIRK_INAND_CMD38) {
1024 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1025 INAND_CMD38_ARG_EXT_CSD,
1026 INAND_CMD38_ARG_SECTRIM2,
1032 err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG);
1039 if (mmc_can_sanitize(card)) {
1040 trace_mmc_blk_erase_start(EXT_CSD_SANITIZE_START, 0, 0);
1041 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1042 EXT_CSD_SANITIZE_START, 1, 0);
1043 trace_mmc_blk_erase_end(EXT_CSD_SANITIZE_START, 0, 0);
1046 if (err && !mmc_blk_reset(md, card->host, type))
1049 mmc_blk_reset_success(md, type);
1051 blk_end_request(req, err, blk_rq_bytes(req));
1056 static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req)
1058 struct mmc_blk_data *md = mq->data;
1059 struct mmc_card *card = md->queue.card;
1062 ret = mmc_flush_cache(card);
1066 blk_end_request_all(req, ret);
1072 * Reformat current write as a reliable write, supporting
1073 * both legacy and the enhanced reliable write MMC cards.
1074 * In each transfer we'll handle only as much as a single
1075 * reliable write can handle, thus finish the request in
1076 * partial completions.
1078 static inline void mmc_apply_rel_rw(struct mmc_blk_request *brq,
1079 struct mmc_card *card,
1080 struct request *req)
1082 if (!(card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN)) {
1083 /* Legacy mode imposes restrictions on transfers. */
1084 if (!IS_ALIGNED(brq->cmd.arg, card->ext_csd.rel_sectors))
1085 brq->data.blocks = 1;
1087 if (brq->data.blocks > card->ext_csd.rel_sectors)
1088 brq->data.blocks = card->ext_csd.rel_sectors;
1089 else if (brq->data.blocks < card->ext_csd.rel_sectors)
1090 brq->data.blocks = 1;
1094 #define CMD_ERRORS \
1095 (R1_OUT_OF_RANGE | /* Command argument out of range */ \
1096 R1_ADDRESS_ERROR | /* Misaligned address */ \
1097 R1_BLOCK_LEN_ERROR | /* Transferred block length incorrect */\
1098 R1_WP_VIOLATION | /* Tried to write to protected block */ \
1099 R1_CC_ERROR | /* Card controller error */ \
1100 R1_ERROR) /* General/unknown error */
1102 static int mmc_blk_err_check(struct mmc_card *card,
1103 struct mmc_async_req *areq)
1105 struct mmc_queue_req *mq_mrq = container_of(areq, struct mmc_queue_req,
1107 struct mmc_blk_request *brq = &mq_mrq->brq;
1108 struct request *req = mq_mrq->req;
1109 int ecc_err = 0, gen_err = 0;
1112 * sbc.error indicates a problem with the set block count
1113 * command. No data will have been transferred.
1115 * cmd.error indicates a problem with the r/w command. No
1116 * data will have been transferred.
1118 * stop.error indicates a problem with the stop command. Data
1119 * may have been transferred, or may still be transferring.
1121 if (brq->sbc.error || brq->cmd.error || brq->stop.error ||
1123 switch (mmc_blk_cmd_recovery(card, req, brq, &ecc_err, &gen_err)) {
1125 return MMC_BLK_RETRY;
1127 return MMC_BLK_ABORT;
1129 return MMC_BLK_NOMEDIUM;
1136 * Check for errors relating to the execution of the
1137 * initial command - such as address errors. No data
1138 * has been transferred.
1140 if (brq->cmd.resp[0] & CMD_ERRORS) {
1141 pr_err("%s: r/w command failed, status = %#x\n",
1142 req->rq_disk->disk_name, brq->cmd.resp[0]);
1143 return MMC_BLK_ABORT;
1147 * Everything else is either success, or a data error of some
1148 * kind. If it was a write, we may have transitioned to
1149 * program mode, which we have to wait for it to complete.
1151 if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) {
1153 unsigned long timeout;
1155 /* Check stop command response */
1156 if (brq->stop.resp[0] & R1_ERROR) {
1157 pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n",
1158 req->rq_disk->disk_name, __func__,
1163 timeout = jiffies + msecs_to_jiffies(MMC_BLK_TIMEOUT_MS);
1165 int err = get_card_status(card, &status, 5);
1167 pr_err("%s: error %d requesting status\n",
1168 req->rq_disk->disk_name, err);
1169 return MMC_BLK_CMD_ERR;
1172 if (status & R1_ERROR) {
1173 pr_err("%s: %s: general error sending status command, card status %#x\n",
1174 req->rq_disk->disk_name, __func__,
1179 /* Timeout if the device never becomes ready for data
1180 * and never leaves the program state.
1182 if (time_after(jiffies, timeout)) {
1183 pr_err("%s: Card stuck in programming state!"\
1184 " %s %s\n", mmc_hostname(card->host),
1185 req->rq_disk->disk_name, __func__);
1187 return MMC_BLK_CMD_ERR;
1190 * Some cards mishandle the status bits,
1191 * so make sure to check both the busy
1192 * indication and the card state.
1194 } while (!(status & R1_READY_FOR_DATA) ||
1195 (R1_CURRENT_STATE(status) == R1_STATE_PRG));
1198 /* if general error occurs, retry the write operation. */
1200 pr_warn("%s: retrying write for general error\n",
1201 req->rq_disk->disk_name);
1202 return MMC_BLK_RETRY;
1205 if (brq->data.error) {
1206 pr_err("%s: error %d transferring data, sector %u, nr %u, cmd response %#x, card status %#x\n",
1207 req->rq_disk->disk_name, brq->data.error,
1208 (unsigned)blk_rq_pos(req),
1209 (unsigned)blk_rq_sectors(req),
1210 brq->cmd.resp[0], brq->stop.resp[0]);
1212 if (rq_data_dir(req) == READ) {
1214 return MMC_BLK_ECC_ERR;
1215 return MMC_BLK_DATA_ERR;
1217 return MMC_BLK_CMD_ERR;
1221 if (!brq->data.bytes_xfered)
1222 return MMC_BLK_RETRY;
1224 if (mmc_packed_cmd(mq_mrq->cmd_type)) {
1225 if (unlikely(brq->data.blocks << 9 != brq->data.bytes_xfered))
1226 return MMC_BLK_PARTIAL;
1228 return MMC_BLK_SUCCESS;
1231 if (blk_rq_bytes(req) != brq->data.bytes_xfered)
1232 return MMC_BLK_PARTIAL;
1234 return MMC_BLK_SUCCESS;
1237 static int mmc_blk_packed_err_check(struct mmc_card *card,
1238 struct mmc_async_req *areq)
1240 struct mmc_queue_req *mq_rq = container_of(areq, struct mmc_queue_req,
1242 struct request *req = mq_rq->req;
1243 struct mmc_packed *packed = mq_rq->packed;
1244 int err, check, status;
1250 check = mmc_blk_err_check(card, areq);
1251 err = get_card_status(card, &status, 0);
1253 pr_err("%s: error %d sending status command\n",
1254 req->rq_disk->disk_name, err);
1255 return MMC_BLK_ABORT;
1258 if (status & R1_EXCEPTION_EVENT) {
1259 ext_csd = kzalloc(512, GFP_KERNEL);
1261 pr_err("%s: unable to allocate buffer for ext_csd\n",
1262 req->rq_disk->disk_name);
1266 err = mmc_send_ext_csd(card, ext_csd);
1268 pr_err("%s: error %d sending ext_csd\n",
1269 req->rq_disk->disk_name, err);
1270 check = MMC_BLK_ABORT;
1274 if ((ext_csd[EXT_CSD_EXP_EVENTS_STATUS] &
1275 EXT_CSD_PACKED_FAILURE) &&
1276 (ext_csd[EXT_CSD_PACKED_CMD_STATUS] &
1277 EXT_CSD_PACKED_GENERIC_ERROR)) {
1278 if (ext_csd[EXT_CSD_PACKED_CMD_STATUS] &
1279 EXT_CSD_PACKED_INDEXED_ERROR) {
1280 packed->idx_failure =
1281 ext_csd[EXT_CSD_PACKED_FAILURE_INDEX] - 1;
1282 check = MMC_BLK_PARTIAL;
1284 pr_err("%s: packed cmd failed, nr %u, sectors %u, "
1285 "failure index: %d\n",
1286 req->rq_disk->disk_name, packed->nr_entries,
1287 packed->blocks, packed->idx_failure);
1296 static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
1297 struct mmc_card *card,
1299 struct mmc_queue *mq)
1301 u32 readcmd, writecmd;
1302 struct mmc_blk_request *brq = &mqrq->brq;
1303 struct request *req = mqrq->req;
1304 struct mmc_blk_data *md = mq->data;
1308 * Reliable writes are used to implement Forced Unit Access and
1309 * REQ_META accesses, and are supported only on MMCs.
1311 * XXX: this really needs a good explanation of why REQ_META
1312 * is treated special.
1314 bool do_rel_wr = ((req->cmd_flags & REQ_FUA) ||
1315 (req->cmd_flags & REQ_META)) &&
1316 (rq_data_dir(req) == WRITE) &&
1317 (md->flags & MMC_BLK_REL_WR);
1319 memset(brq, 0, sizeof(struct mmc_blk_request));
1320 brq->mrq.cmd = &brq->cmd;
1321 brq->mrq.data = &brq->data;
1323 brq->cmd.arg = blk_rq_pos(req);
1324 if (!mmc_card_blockaddr(card))
1326 brq->cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
1327 brq->data.blksz = 512;
1328 brq->stop.opcode = MMC_STOP_TRANSMISSION;
1330 brq->stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
1331 brq->data.blocks = blk_rq_sectors(req);
1334 * The block layer doesn't support all sector count
1335 * restrictions, so we need to be prepared for too big
1338 if (brq->data.blocks > card->host->max_blk_count)
1339 brq->data.blocks = card->host->max_blk_count;
1341 if (brq->data.blocks > 1) {
1343 * After a read error, we redo the request one sector
1344 * at a time in order to accurately determine which
1345 * sectors can be read successfully.
1348 brq->data.blocks = 1;
1350 /* Some controllers can't do multiblock reads due to hw bugs */
1351 if (card->host->caps2 & MMC_CAP2_NO_MULTI_READ &&
1352 rq_data_dir(req) == READ)
1353 brq->data.blocks = 1;
1356 if (brq->data.blocks > 1 || do_rel_wr) {
1357 /* SPI multiblock writes terminate using a special
1358 * token, not a STOP_TRANSMISSION request.
1360 if (!mmc_host_is_spi(card->host) ||
1361 rq_data_dir(req) == READ)
1362 brq->mrq.stop = &brq->stop;
1363 readcmd = MMC_READ_MULTIPLE_BLOCK;
1364 writecmd = MMC_WRITE_MULTIPLE_BLOCK;
1366 brq->mrq.stop = NULL;
1367 readcmd = MMC_READ_SINGLE_BLOCK;
1368 writecmd = MMC_WRITE_BLOCK;
1370 if (rq_data_dir(req) == READ) {
1371 brq->cmd.opcode = readcmd;
1372 brq->data.flags |= MMC_DATA_READ;
1374 brq->cmd.opcode = writecmd;
1375 brq->data.flags |= MMC_DATA_WRITE;
1379 mmc_apply_rel_rw(brq, card, req);
1382 * Data tag is used only during writing meta data to speed
1383 * up write and any subsequent read of this meta data
1385 do_data_tag = (card->ext_csd.data_tag_unit_size) &&
1386 (req->cmd_flags & REQ_META) &&
1387 (rq_data_dir(req) == WRITE) &&
1388 ((brq->data.blocks * brq->data.blksz) >=
1389 card->ext_csd.data_tag_unit_size);
1392 * Pre-defined multi-block transfers are preferable to
1393 * open ended-ones (and necessary for reliable writes).
1394 * However, it is not sufficient to just send CMD23,
1395 * and avoid the final CMD12, as on an error condition
1396 * CMD12 (stop) needs to be sent anyway. This, coupled
1397 * with Auto-CMD23 enhancements provided by some
1398 * hosts, means that the complexity of dealing
1399 * with this is best left to the host. If CMD23 is
1400 * supported by card and host, we'll fill sbc in and let
1401 * the host deal with handling it correctly. This means
1402 * that for hosts that don't expose MMC_CAP_CMD23, no
1403 * change of behavior will be observed.
1405 * N.B: Some MMC cards experience perf degradation.
1406 * We'll avoid using CMD23-bounded multiblock writes for
1407 * these, while retaining features like reliable writes.
1409 if ((md->flags & MMC_BLK_CMD23) && mmc_op_multi(brq->cmd.opcode) &&
1410 (do_rel_wr || !(card->quirks & MMC_QUIRK_BLK_NO_CMD23) ||
1412 brq->sbc.opcode = MMC_SET_BLOCK_COUNT;
1413 brq->sbc.arg = brq->data.blocks |
1414 (do_rel_wr ? (1 << 31) : 0) |
1415 (do_data_tag ? (1 << 29) : 0);
1416 brq->sbc.flags = MMC_RSP_R1 | MMC_CMD_AC;
1417 brq->mrq.sbc = &brq->sbc;
1420 mmc_set_data_timeout(&brq->data, card);
1422 brq->data.sg = mqrq->sg;
1423 brq->data.sg_len = mmc_queue_map_sg(mq, mqrq);
1426 * Adjust the sg list so it is the same size as the
1429 if (brq->data.blocks != blk_rq_sectors(req)) {
1430 int i, data_size = brq->data.blocks << 9;
1431 struct scatterlist *sg;
1433 for_each_sg(brq->data.sg, sg, brq->data.sg_len, i) {
1434 data_size -= sg->length;
1435 if (data_size <= 0) {
1436 sg->length += data_size;
1441 brq->data.sg_len = i;
1444 mqrq->mmc_active.mrq = &brq->mrq;
1445 mqrq->mmc_active.err_check = mmc_blk_err_check;
1447 mmc_queue_bounce_pre(mqrq);
1450 static inline u8 mmc_calc_packed_hdr_segs(struct request_queue *q,
1451 struct mmc_card *card)
1453 unsigned int hdr_sz = mmc_large_sector(card) ? 4096 : 512;
1454 unsigned int max_seg_sz = queue_max_segment_size(q);
1455 unsigned int len, nr_segs = 0;
1458 len = min(hdr_sz, max_seg_sz);
1466 static u8 mmc_blk_prep_packed_list(struct mmc_queue *mq, struct request *req)
1468 struct request_queue *q = mq->queue;
1469 struct mmc_card *card = mq->card;
1470 struct request *cur = req, *next = NULL;
1471 struct mmc_blk_data *md = mq->data;
1472 struct mmc_queue_req *mqrq = mq->mqrq_cur;
1473 bool en_rel_wr = card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN;
1474 unsigned int req_sectors = 0, phys_segments = 0;
1475 unsigned int max_blk_count, max_phys_segs;
1476 bool put_back = true;
1477 u8 max_packed_rw = 0;
1480 if (!(md->flags & MMC_BLK_PACKED_CMD))
1483 if ((rq_data_dir(cur) == WRITE) &&
1484 mmc_host_packed_wr(card->host))
1485 max_packed_rw = card->ext_csd.max_packed_writes;
1487 if (max_packed_rw == 0)
1490 if (mmc_req_rel_wr(cur) &&
1491 (md->flags & MMC_BLK_REL_WR) && !en_rel_wr)
1494 if (mmc_large_sector(card) &&
1495 !IS_ALIGNED(blk_rq_sectors(cur), 8))
1498 mmc_blk_clear_packed(mqrq);
1500 max_blk_count = min(card->host->max_blk_count,
1501 card->host->max_req_size >> 9);
1502 if (unlikely(max_blk_count > 0xffff))
1503 max_blk_count = 0xffff;
1505 max_phys_segs = queue_max_segments(q);
1506 req_sectors += blk_rq_sectors(cur);
1507 phys_segments += cur->nr_phys_segments;
1509 if (rq_data_dir(cur) == WRITE) {
1510 req_sectors += mmc_large_sector(card) ? 8 : 1;
1511 phys_segments += mmc_calc_packed_hdr_segs(q, card);
1515 if (reqs >= max_packed_rw - 1) {
1520 spin_lock_irq(q->queue_lock);
1521 next = blk_fetch_request(q);
1522 spin_unlock_irq(q->queue_lock);
1528 if (mmc_large_sector(card) &&
1529 !IS_ALIGNED(blk_rq_sectors(next), 8))
1532 if (next->cmd_flags & REQ_DISCARD ||
1533 next->cmd_flags & REQ_FLUSH)
1536 if (rq_data_dir(cur) != rq_data_dir(next))
1539 if (mmc_req_rel_wr(next) &&
1540 (md->flags & MMC_BLK_REL_WR) && !en_rel_wr)
1543 req_sectors += blk_rq_sectors(next);
1544 if (req_sectors > max_blk_count)
1547 phys_segments += next->nr_phys_segments;
1548 if (phys_segments > max_phys_segs)
1551 list_add_tail(&next->queuelist, &mqrq->packed->list);
1557 spin_lock_irq(q->queue_lock);
1558 blk_requeue_request(q, next);
1559 spin_unlock_irq(q->queue_lock);
1563 list_add(&req->queuelist, &mqrq->packed->list);
1564 mqrq->packed->nr_entries = ++reqs;
1565 mqrq->packed->retries = reqs;
1570 mqrq->cmd_type = MMC_PACKED_NONE;
1574 static void mmc_blk_packed_hdr_wrq_prep(struct mmc_queue_req *mqrq,
1575 struct mmc_card *card,
1576 struct mmc_queue *mq)
1578 struct mmc_blk_request *brq = &mqrq->brq;
1579 struct request *req = mqrq->req;
1580 struct request *prq;
1581 struct mmc_blk_data *md = mq->data;
1582 struct mmc_packed *packed = mqrq->packed;
1583 bool do_rel_wr, do_data_tag;
1584 u32 *packed_cmd_hdr;
1590 mqrq->cmd_type = MMC_PACKED_WRITE;
1592 packed->idx_failure = MMC_PACKED_NR_IDX;
1594 packed_cmd_hdr = packed->cmd_hdr;
1595 memset(packed_cmd_hdr, 0, sizeof(packed->cmd_hdr));
1596 packed_cmd_hdr[0] = (packed->nr_entries << 16) |
1597 (PACKED_CMD_WR << 8) | PACKED_CMD_VER;
1598 hdr_blocks = mmc_large_sector(card) ? 8 : 1;
1601 * Argument for each entry of packed group
1603 list_for_each_entry(prq, &packed->list, queuelist) {
1604 do_rel_wr = mmc_req_rel_wr(prq) && (md->flags & MMC_BLK_REL_WR);
1605 do_data_tag = (card->ext_csd.data_tag_unit_size) &&
1606 (prq->cmd_flags & REQ_META) &&
1607 (rq_data_dir(prq) == WRITE) &&
1608 ((brq->data.blocks * brq->data.blksz) >=
1609 card->ext_csd.data_tag_unit_size);
1610 /* Argument of CMD23 */
1611 packed_cmd_hdr[(i * 2)] =
1612 (do_rel_wr ? MMC_CMD23_ARG_REL_WR : 0) |
1613 (do_data_tag ? MMC_CMD23_ARG_TAG_REQ : 0) |
1614 blk_rq_sectors(prq);
1615 /* Argument of CMD18 or CMD25 */
1616 packed_cmd_hdr[((i * 2)) + 1] =
1617 mmc_card_blockaddr(card) ?
1618 blk_rq_pos(prq) : blk_rq_pos(prq) << 9;
1619 packed->blocks += blk_rq_sectors(prq);
1623 memset(brq, 0, sizeof(struct mmc_blk_request));
1624 brq->mrq.cmd = &brq->cmd;
1625 brq->mrq.data = &brq->data;
1626 brq->mrq.sbc = &brq->sbc;
1627 brq->mrq.stop = &brq->stop;
1629 brq->sbc.opcode = MMC_SET_BLOCK_COUNT;
1630 brq->sbc.arg = MMC_CMD23_ARG_PACKED | (packed->blocks + hdr_blocks);
1631 brq->sbc.flags = MMC_RSP_R1 | MMC_CMD_AC;
1633 brq->cmd.opcode = MMC_WRITE_MULTIPLE_BLOCK;
1634 brq->cmd.arg = blk_rq_pos(req);
1635 if (!mmc_card_blockaddr(card))
1637 brq->cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
1639 brq->data.blksz = 512;
1640 brq->data.blocks = packed->blocks + hdr_blocks;
1641 brq->data.flags |= MMC_DATA_WRITE;
1643 brq->stop.opcode = MMC_STOP_TRANSMISSION;
1645 brq->stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
1647 mmc_set_data_timeout(&brq->data, card);
1649 brq->data.sg = mqrq->sg;
1650 brq->data.sg_len = mmc_queue_map_sg(mq, mqrq);
1652 mqrq->mmc_active.mrq = &brq->mrq;
1653 mqrq->mmc_active.err_check = mmc_blk_packed_err_check;
1655 mmc_queue_bounce_pre(mqrq);
1658 static int mmc_blk_cmd_err(struct mmc_blk_data *md, struct mmc_card *card,
1659 struct mmc_blk_request *brq, struct request *req,
1662 struct mmc_queue_req *mq_rq;
1663 mq_rq = container_of(brq, struct mmc_queue_req, brq);
1666 * If this is an SD card and we're writing, we can first
1667 * mark the known good sectors as ok.
1669 * If the card is not SD, we can still ok written sectors
1670 * as reported by the controller (which might be less than
1671 * the real number of written sectors, but never more).
1673 if (mmc_card_sd(card)) {
1676 blocks = mmc_sd_num_wr_blocks(card);
1677 if (blocks != (u32)-1) {
1678 ret = blk_end_request(req, 0, blocks << 9);
1681 if (!mmc_packed_cmd(mq_rq->cmd_type))
1682 ret = blk_end_request(req, 0, brq->data.bytes_xfered);
1687 static int mmc_blk_end_packed_req(struct mmc_queue_req *mq_rq)
1689 struct request *prq;
1690 struct mmc_packed *packed = mq_rq->packed;
1691 int idx = packed->idx_failure, i = 0;
1696 while (!list_empty(&packed->list)) {
1697 prq = list_entry_rq(packed->list.next);
1699 /* retry from error index */
1700 packed->nr_entries -= idx;
1704 if (packed->nr_entries == MMC_PACKED_NR_SINGLE) {
1705 list_del_init(&prq->queuelist);
1706 mmc_blk_clear_packed(mq_rq);
1710 list_del_init(&prq->queuelist);
1711 blk_end_request(prq, 0, blk_rq_bytes(prq));
1715 mmc_blk_clear_packed(mq_rq);
1719 static void mmc_blk_abort_packed_req(struct mmc_queue_req *mq_rq)
1721 struct request *prq;
1722 struct mmc_packed *packed = mq_rq->packed;
1726 while (!list_empty(&packed->list)) {
1727 prq = list_entry_rq(packed->list.next);
1728 list_del_init(&prq->queuelist);
1729 blk_end_request(prq, -EIO, blk_rq_bytes(prq));
1732 mmc_blk_clear_packed(mq_rq);
1735 static void mmc_blk_revert_packed_req(struct mmc_queue *mq,
1736 struct mmc_queue_req *mq_rq)
1738 struct request *prq;
1739 struct request_queue *q = mq->queue;
1740 struct mmc_packed *packed = mq_rq->packed;
1744 while (!list_empty(&packed->list)) {
1745 prq = list_entry_rq(packed->list.prev);
1746 if (prq->queuelist.prev != &packed->list) {
1747 list_del_init(&prq->queuelist);
1748 spin_lock_irq(q->queue_lock);
1749 blk_requeue_request(mq->queue, prq);
1750 spin_unlock_irq(q->queue_lock);
1752 list_del_init(&prq->queuelist);
1756 mmc_blk_clear_packed(mq_rq);
1759 static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
1761 struct mmc_blk_data *md = mq->data;
1762 struct mmc_card *card = md->queue.card;
1763 struct mmc_blk_request *brq = &mq->mqrq_cur->brq;
1764 int ret = 1, disable_multi = 0, retry = 0, type;
1765 enum mmc_blk_status status;
1766 struct mmc_queue_req *mq_rq;
1767 struct request *req = rqc;
1768 struct mmc_async_req *areq;
1769 const u8 packed_nr = 2;
1772 if (!rqc && !mq->mqrq_prev->req)
1776 reqs = mmc_blk_prep_packed_list(mq, rqc);
1781 * When 4KB native sector is enabled, only 8 blocks
1782 * multiple read or write is allowed
1784 if ((brq->data.blocks & 0x07) &&
1785 (card->ext_csd.data_sector_size == 4096)) {
1786 pr_err("%s: Transfer size is not 4KB sector size aligned\n",
1787 req->rq_disk->disk_name);
1788 mq_rq = mq->mqrq_cur;
1792 if (reqs >= packed_nr)
1793 mmc_blk_packed_hdr_wrq_prep(mq->mqrq_cur,
1796 mmc_blk_rw_rq_prep(mq->mqrq_cur, card, 0, mq);
1797 areq = &mq->mqrq_cur->mmc_active;
1800 areq = mmc_start_req(card->host, areq, (int *) &status);
1802 if (status == MMC_BLK_NEW_REQUEST)
1803 mq->flags |= MMC_QUEUE_NEW_REQUEST;
1807 mq_rq = container_of(areq, struct mmc_queue_req, mmc_active);
1810 type = rq_data_dir(req) == READ ? MMC_BLK_READ : MMC_BLK_WRITE;
1811 mmc_queue_bounce_post(mq_rq);
1814 case MMC_BLK_SUCCESS:
1815 case MMC_BLK_PARTIAL:
1817 * A block was successfully transferred.
1819 mmc_blk_reset_success(md, type);
1821 if (mmc_packed_cmd(mq_rq->cmd_type)) {
1822 ret = mmc_blk_end_packed_req(mq_rq);
1825 ret = blk_end_request(req, 0,
1826 brq->data.bytes_xfered);
1830 * If the blk_end_request function returns non-zero even
1831 * though all data has been transferred and no errors
1832 * were returned by the host controller, it's a bug.
1834 if (status == MMC_BLK_SUCCESS && ret) {
1835 pr_err("%s BUG rq_tot %d d_xfer %d\n",
1836 __func__, blk_rq_bytes(req),
1837 brq->data.bytes_xfered);
1842 case MMC_BLK_CMD_ERR:
1843 ret = mmc_blk_cmd_err(md, card, brq, req, ret);
1844 if (mmc_blk_reset(md, card->host, type))
1854 if (!mmc_blk_reset(md, card->host, type))
1857 case MMC_BLK_DATA_ERR: {
1860 err = mmc_blk_reset(md, card->host, type);
1863 if (err == -ENODEV ||
1864 mmc_packed_cmd(mq_rq->cmd_type))
1868 case MMC_BLK_ECC_ERR:
1869 if (brq->data.blocks > 1) {
1870 /* Redo read one sector at a time */
1871 pr_warning("%s: retrying using single block read\n",
1872 req->rq_disk->disk_name);
1877 * After an error, we redo I/O one sector at a
1878 * time, so we only reach here after trying to
1879 * read a single sector.
1881 ret = blk_end_request(req, -EIO,
1886 case MMC_BLK_NOMEDIUM:
1889 pr_err("%s: Unhandled return value (%d)",
1890 req->rq_disk->disk_name, status);
1895 if (mmc_packed_cmd(mq_rq->cmd_type)) {
1896 if (!mq_rq->packed->retries)
1898 mmc_blk_packed_hdr_wrq_prep(mq_rq, card, mq);
1899 mmc_start_req(card->host,
1900 &mq_rq->mmc_active, NULL);
1904 * In case of a incomplete request
1905 * prepare it again and resend.
1907 mmc_blk_rw_rq_prep(mq_rq, card,
1909 mmc_start_req(card->host,
1910 &mq_rq->mmc_active, NULL);
1918 if (mmc_packed_cmd(mq_rq->cmd_type)) {
1919 mmc_blk_abort_packed_req(mq_rq);
1921 if (mmc_card_removed(card))
1922 req->cmd_flags |= REQ_QUIET;
1924 ret = blk_end_request(req, -EIO,
1925 blk_rq_cur_bytes(req));
1930 if (mmc_card_removed(card)) {
1931 rqc->cmd_flags |= REQ_QUIET;
1932 blk_end_request_all(rqc, -EIO);
1935 * If current request is packed, it needs to put back.
1937 if (mmc_packed_cmd(mq->mqrq_cur->cmd_type))
1938 mmc_blk_revert_packed_req(mq, mq->mqrq_cur);
1940 mmc_blk_rw_rq_prep(mq->mqrq_cur, card, 0, mq);
1941 mmc_start_req(card->host,
1942 &mq->mqrq_cur->mmc_active, NULL);
1949 static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
1952 struct mmc_blk_data *md = mq->data;
1953 struct mmc_card *card = md->queue.card;
1954 struct mmc_host *host = card->host;
1955 unsigned long flags;
1956 unsigned int cmd_flags = req ? req->cmd_flags : 0;
1958 #ifdef CONFIG_MMC_BLOCK_DEFERRED_RESUME
1959 if (mmc_bus_needs_resume(card->host))
1960 mmc_resume_bus(card->host);
1963 if (req && !mq->mqrq_prev->req)
1964 /* claim host only for the first request */
1965 mmc_claim_host(card->host);
1967 ret = mmc_blk_part_switch(card, md);
1970 blk_end_request_all(req, -EIO);
1976 mq->flags &= ~MMC_QUEUE_NEW_REQUEST;
1977 if (cmd_flags & REQ_DISCARD) {
1978 /* complete ongoing async transfer before issuing discard */
1979 if (card->host->areq)
1980 mmc_blk_issue_rw_rq(mq, NULL);
1981 if (req->cmd_flags & REQ_SECURE &&
1982 !(card->quirks & MMC_QUIRK_SEC_ERASE_TRIM_BROKEN))
1983 ret = mmc_blk_issue_secdiscard_rq(mq, req);
1985 ret = mmc_blk_issue_discard_rq(mq, req);
1986 } else if (cmd_flags & REQ_FLUSH) {
1987 /* complete ongoing async transfer before issuing flush */
1988 if (card->host->areq)
1989 mmc_blk_issue_rw_rq(mq, NULL);
1990 ret = mmc_blk_issue_flush(mq, req);
1992 if (!req && host->areq) {
1993 spin_lock_irqsave(&host->context_info.lock, flags);
1994 host->context_info.is_waiting_last_req = true;
1995 spin_unlock_irqrestore(&host->context_info.lock, flags);
1997 ret = mmc_blk_issue_rw_rq(mq, req);
2001 if ((!req && !(mq->flags & MMC_QUEUE_NEW_REQUEST)) ||
2002 (cmd_flags & MMC_REQ_SPECIAL_MASK))
2004 * Release host when there are no more requests
2005 * and after special request(discard, flush) is done.
2006 * In case sepecial request, there is no reentry to
2007 * the 'mmc_blk_issue_rq' with 'mqrq_prev->req'.
2009 mmc_release_host(card->host);
2013 static inline int mmc_blk_readonly(struct mmc_card *card)
2015 return mmc_card_readonly(card) ||
2016 !(card->csd.cmdclass & CCC_BLOCK_WRITE);
2019 static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
2020 struct device *parent,
2023 const char *subname,
2026 struct mmc_blk_data *md;
2029 devidx = find_first_zero_bit(dev_use, max_devices);
2030 if (devidx >= max_devices)
2031 return ERR_PTR(-ENOSPC);
2032 __set_bit(devidx, dev_use);
2034 md = kzalloc(sizeof(struct mmc_blk_data), GFP_KERNEL);
2041 * !subname implies we are creating main mmc_blk_data that will be
2042 * associated with mmc_card with mmc_set_drvdata. Due to device
2043 * partitions, devidx will not coincide with a per-physical card
2044 * index anymore so we keep track of a name index.
2047 md->name_idx = find_first_zero_bit(name_use, max_devices);
2048 __set_bit(md->name_idx, name_use);
2050 md->name_idx = ((struct mmc_blk_data *)
2051 dev_to_disk(parent)->private_data)->name_idx;
2053 md->area_type = area_type;
2056 * Set the read-only status based on the supported commands
2057 * and the write protect switch.
2059 md->read_only = mmc_blk_readonly(card);
2061 md->disk = alloc_disk(perdev_minors);
2062 if (md->disk == NULL) {
2067 spin_lock_init(&md->lock);
2068 INIT_LIST_HEAD(&md->part);
2071 ret = mmc_init_queue(&md->queue, card, &md->lock, subname);
2075 md->queue.issue_fn = mmc_blk_issue_rq;
2076 md->queue.data = md;
2078 md->disk->major = MMC_BLOCK_MAJOR;
2079 md->disk->first_minor = devidx * perdev_minors;
2080 md->disk->fops = &mmc_bdops;
2081 md->disk->private_data = md;
2082 md->disk->queue = md->queue.queue;
2083 md->disk->driverfs_dev = parent;
2084 set_disk_ro(md->disk, md->read_only || default_ro);
2085 md->disk->flags = GENHD_FL_EXT_DEVT;
2086 if (area_type & MMC_BLK_DATA_AREA_RPMB)
2087 md->disk->flags |= GENHD_FL_NO_PART_SCAN;
2090 * As discussed on lkml, GENHD_FL_REMOVABLE should:
2092 * - be set for removable media with permanent block devices
2093 * - be unset for removable block devices with permanent media
2095 * Since MMC block devices clearly fall under the second
2096 * case, we do not set GENHD_FL_REMOVABLE. Userspace
2097 * should use the block device creation/destruction hotplug
2098 * messages to tell when the card is present.
2101 snprintf(md->disk->disk_name, sizeof(md->disk->disk_name),
2102 "mmcblk%d%s", md->name_idx, subname ? subname : "");
2104 if (mmc_card_mmc(card))
2105 blk_queue_logical_block_size(md->queue.queue,
2106 card->ext_csd.data_sector_size);
2108 blk_queue_logical_block_size(md->queue.queue, 512);
2110 set_capacity(md->disk, size);
2112 if (mmc_host_cmd23(card->host)) {
2113 if (mmc_card_mmc(card) ||
2114 (mmc_card_sd(card) &&
2115 card->scr.cmds & SD_SCR_CMD23_SUPPORT))
2116 md->flags |= MMC_BLK_CMD23;
2119 if (mmc_card_mmc(card) &&
2120 md->flags & MMC_BLK_CMD23 &&
2121 ((card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN) ||
2122 card->ext_csd.rel_sectors)) {
2123 md->flags |= MMC_BLK_REL_WR;
2124 blk_queue_flush(md->queue.queue, REQ_FLUSH | REQ_FUA);
2127 if (mmc_card_mmc(card) &&
2128 (area_type == MMC_BLK_DATA_AREA_MAIN) &&
2129 (md->flags & MMC_BLK_CMD23) &&
2130 card->ext_csd.packed_event_en) {
2131 if (!mmc_packed_init(&md->queue, card))
2132 md->flags |= MMC_BLK_PACKED_CMD;
2142 return ERR_PTR(ret);
2145 static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
2148 struct mmc_blk_data *md;
2150 if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) {
2152 * The EXT_CSD sector count is in number or 512 byte
2155 size = card->ext_csd.sectors;
2158 * The CSD capacity field is in units of read_blkbits.
2159 * set_capacity takes units of 512 bytes.
2161 size = card->csd.capacity << (card->csd.read_blkbits - 9);
2164 md = mmc_blk_alloc_req(card, &card->dev, size, false, NULL,
2165 MMC_BLK_DATA_AREA_MAIN);
2169 static int mmc_blk_alloc_part(struct mmc_card *card,
2170 struct mmc_blk_data *md,
2171 unsigned int part_type,
2174 const char *subname,
2178 struct mmc_blk_data *part_md;
2180 part_md = mmc_blk_alloc_req(card, disk_to_dev(md->disk), size, default_ro,
2181 subname, area_type);
2182 if (IS_ERR(part_md))
2183 return PTR_ERR(part_md);
2184 part_md->part_type = part_type;
2185 list_add(&part_md->part, &md->part);
2187 string_get_size((u64)get_capacity(part_md->disk) << 9, STRING_UNITS_2,
2188 cap_str, sizeof(cap_str));
2189 pr_info("%s: %s %s partition %u %s\n",
2190 part_md->disk->disk_name, mmc_card_id(card),
2191 mmc_card_name(card), part_md->part_type, cap_str);
2195 /* MMC Physical partitions consist of two boot partitions and
2196 * up to four general purpose partitions.
2197 * For each partition enabled in EXT_CSD a block device will be allocatedi
2198 * to provide access to the partition.
2201 static int mmc_blk_alloc_parts(struct mmc_card *card, struct mmc_blk_data *md)
2205 if (!mmc_card_mmc(card))
2208 for (idx = 0; idx < card->nr_parts; idx++) {
2209 if (card->part[idx].size) {
2210 ret = mmc_blk_alloc_part(card, md,
2211 card->part[idx].part_cfg,
2212 card->part[idx].size >> 9,
2213 card->part[idx].force_ro,
2214 card->part[idx].name,
2215 card->part[idx].area_type);
2224 static void mmc_blk_remove_req(struct mmc_blk_data *md)
2226 struct mmc_card *card;
2229 card = md->queue.card;
2230 if (md->disk->flags & GENHD_FL_UP) {
2231 device_remove_file(disk_to_dev(md->disk), &md->force_ro);
2232 if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
2233 card->ext_csd.boot_ro_lockable)
2234 device_remove_file(disk_to_dev(md->disk),
2235 &md->power_ro_lock);
2237 /* Stop new requests from getting into the queue */
2238 del_gendisk(md->disk);
2241 /* Then flush out any already in there */
2242 mmc_cleanup_queue(&md->queue);
2243 if (md->flags & MMC_BLK_PACKED_CMD)
2244 mmc_packed_clean(&md->queue);
2249 static void mmc_blk_remove_parts(struct mmc_card *card,
2250 struct mmc_blk_data *md)
2252 struct list_head *pos, *q;
2253 struct mmc_blk_data *part_md;
2255 __clear_bit(md->name_idx, name_use);
2256 list_for_each_safe(pos, q, &md->part) {
2257 part_md = list_entry(pos, struct mmc_blk_data, part);
2259 mmc_blk_remove_req(part_md);
2263 static int mmc_add_disk(struct mmc_blk_data *md)
2266 struct mmc_card *card = md->queue.card;
2269 md->force_ro.show = force_ro_show;
2270 md->force_ro.store = force_ro_store;
2271 sysfs_attr_init(&md->force_ro.attr);
2272 md->force_ro.attr.name = "force_ro";
2273 md->force_ro.attr.mode = S_IRUGO | S_IWUSR;
2274 ret = device_create_file(disk_to_dev(md->disk), &md->force_ro);
2278 if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
2279 card->ext_csd.boot_ro_lockable) {
2282 if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PWR_WP_DIS)
2285 mode = S_IRUGO | S_IWUSR;
2287 md->power_ro_lock.show = power_ro_lock_show;
2288 md->power_ro_lock.store = power_ro_lock_store;
2289 sysfs_attr_init(&md->power_ro_lock.attr);
2290 md->power_ro_lock.attr.mode = mode;
2291 md->power_ro_lock.attr.name =
2292 "ro_lock_until_next_power_on";
2293 ret = device_create_file(disk_to_dev(md->disk),
2294 &md->power_ro_lock);
2296 goto power_ro_lock_fail;
2301 device_remove_file(disk_to_dev(md->disk), &md->force_ro);
2303 del_gendisk(md->disk);
2308 #define CID_MANFID_SANDISK 0x2
2309 #define CID_MANFID_TOSHIBA 0x11
2310 #define CID_MANFID_MICRON 0x13
2311 #define CID_MANFID_SAMSUNG 0x15
2313 static const struct mmc_fixup blk_fixups[] =
2315 MMC_FIXUP("SEM02G", CID_MANFID_SANDISK, 0x100, add_quirk,
2316 MMC_QUIRK_INAND_CMD38),
2317 MMC_FIXUP("SEM04G", CID_MANFID_SANDISK, 0x100, add_quirk,
2318 MMC_QUIRK_INAND_CMD38),
2319 MMC_FIXUP("SEM08G", CID_MANFID_SANDISK, 0x100, add_quirk,
2320 MMC_QUIRK_INAND_CMD38),
2321 MMC_FIXUP("SEM16G", CID_MANFID_SANDISK, 0x100, add_quirk,
2322 MMC_QUIRK_INAND_CMD38),
2323 MMC_FIXUP("SEM32G", CID_MANFID_SANDISK, 0x100, add_quirk,
2324 MMC_QUIRK_INAND_CMD38),
2327 * Some MMC cards experience performance degradation with CMD23
2328 * instead of CMD12-bounded multiblock transfers. For now we'll
2329 * black list what's bad...
2330 * - Certain Toshiba cards.
2332 * N.B. This doesn't affect SD cards.
2334 MMC_FIXUP("MMC08G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
2335 MMC_QUIRK_BLK_NO_CMD23),
2336 MMC_FIXUP("MMC16G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
2337 MMC_QUIRK_BLK_NO_CMD23),
2338 MMC_FIXUP("MMC32G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
2339 MMC_QUIRK_BLK_NO_CMD23),
2342 * Some Micron MMC cards needs longer data read timeout than
2345 MMC_FIXUP(CID_NAME_ANY, CID_MANFID_MICRON, 0x200, add_quirk_mmc,
2346 MMC_QUIRK_LONG_READ_TIME),
2349 * On these Samsung MoviNAND parts, performing secure erase or
2350 * secure trim can result in unrecoverable corruption due to a
2353 MMC_FIXUP("M8G2FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2354 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2355 MMC_FIXUP("MAG4FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2356 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2357 MMC_FIXUP("MBG8FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2358 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2359 MMC_FIXUP("MCGAFA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2360 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2361 MMC_FIXUP("VAL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2362 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2363 MMC_FIXUP("VYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2364 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2365 MMC_FIXUP("KYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2366 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2367 MMC_FIXUP("VZL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2368 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2373 static int mmc_blk_probe(struct mmc_card *card)
2375 struct mmc_blk_data *md, *part_md;
2379 * Check that the card supports the command class(es) we need.
2381 if (!(card->csd.cmdclass & CCC_BLOCK_READ))
2384 md = mmc_blk_alloc(card);
2388 string_get_size((u64)get_capacity(md->disk) << 9, STRING_UNITS_2,
2389 cap_str, sizeof(cap_str));
2390 pr_info("%s: %s %s %s %s\n",
2391 md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
2392 cap_str, md->read_only ? "(ro)" : "");
2394 if (mmc_blk_alloc_parts(card, md))
2397 mmc_set_drvdata(card, md);
2398 mmc_fixup_device(card, blk_fixups);
2400 #ifdef CONFIG_MMC_BLOCK_DEFERRED_RESUME
2401 mmc_set_bus_resume_policy(card->host, 1);
2403 if (mmc_add_disk(md))
2406 list_for_each_entry(part_md, &md->part, part) {
2407 if (mmc_add_disk(part_md))
2413 mmc_blk_remove_parts(card, md);
2414 mmc_blk_remove_req(md);
2418 static void mmc_blk_remove(struct mmc_card *card)
2420 struct mmc_blk_data *md = mmc_get_drvdata(card);
2422 mmc_blk_remove_parts(card, md);
2423 mmc_claim_host(card->host);
2424 mmc_blk_part_switch(card, md);
2425 mmc_release_host(card->host);
2426 mmc_blk_remove_req(md);
2427 mmc_set_drvdata(card, NULL);
2428 #ifdef CONFIG_MMC_BLOCK_DEFERRED_RESUME
2429 mmc_set_bus_resume_policy(card->host, 0);
2434 static int mmc_blk_suspend(struct mmc_card *card)
2436 struct mmc_blk_data *part_md;
2437 struct mmc_blk_data *md = mmc_get_drvdata(card);
2440 mmc_queue_suspend(&md->queue);
2441 list_for_each_entry(part_md, &md->part, part) {
2442 mmc_queue_suspend(&part_md->queue);
2448 static int mmc_blk_resume(struct mmc_card *card)
2450 struct mmc_blk_data *part_md;
2451 struct mmc_blk_data *md = mmc_get_drvdata(card);
2455 * Resume involves the card going into idle state,
2456 * so current partition is always the main one.
2458 md->part_curr = md->part_type;
2459 mmc_queue_resume(&md->queue);
2460 list_for_each_entry(part_md, &md->part, part) {
2461 mmc_queue_resume(&part_md->queue);
2467 #define mmc_blk_suspend NULL
2468 #define mmc_blk_resume NULL
2471 static struct mmc_driver mmc_driver = {
2475 .probe = mmc_blk_probe,
2476 .remove = mmc_blk_remove,
2477 .suspend = mmc_blk_suspend,
2478 .resume = mmc_blk_resume,
2481 static int __init mmc_blk_init(void)
2485 if (perdev_minors != CONFIG_MMC_BLOCK_MINORS)
2486 pr_info("mmcblk: using %d minors per device\n", perdev_minors);
2488 max_devices = 256 / perdev_minors;
2490 res = register_blkdev(MMC_BLOCK_MAJOR, "mmc");
2494 res = mmc_register_driver(&mmc_driver);
2500 unregister_blkdev(MMC_BLOCK_MAJOR, "mmc");
2505 static void __exit mmc_blk_exit(void)
2507 mmc_unregister_driver(&mmc_driver);
2508 unregister_blkdev(MMC_BLOCK_MAJOR, "mmc");
2511 module_init(mmc_blk_init);
2512 module_exit(mmc_blk_exit);
2514 MODULE_LICENSE("GPL");
2515 MODULE_DESCRIPTION("Multimedia Card (MMC) block device driver");