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);
207 static ssize_t power_ro_lock_store(struct device *dev,
208 struct device_attribute *attr, const char *buf, size_t count)
211 struct mmc_blk_data *md, *part_md;
212 struct mmc_card *card;
215 if (kstrtoul(buf, 0, &set))
221 md = mmc_blk_get(dev_to_disk(dev));
222 card = md->queue.card;
224 mmc_claim_host(card->host);
226 ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_WP,
227 card->ext_csd.boot_ro_lock |
228 EXT_CSD_BOOT_WP_B_PWR_WP_EN,
229 card->ext_csd.part_time);
231 pr_err("%s: Locking boot partition ro until next power on failed: %d\n", md->disk->disk_name, ret);
233 card->ext_csd.boot_ro_lock |= EXT_CSD_BOOT_WP_B_PWR_WP_EN;
235 mmc_release_host(card->host);
238 pr_info("%s: Locking boot partition ro until next power on\n",
239 md->disk->disk_name);
240 set_disk_ro(md->disk, 1);
242 list_for_each_entry(part_md, &md->part, part)
243 if (part_md->area_type == MMC_BLK_DATA_AREA_BOOT) {
244 pr_info("%s: Locking boot partition ro until next power on\n", part_md->disk->disk_name);
245 set_disk_ro(part_md->disk, 1);
253 static ssize_t force_ro_show(struct device *dev, struct device_attribute *attr,
257 struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
259 ret = snprintf(buf, PAGE_SIZE, "%d",
260 get_disk_ro(dev_to_disk(dev)) ^
266 static ssize_t force_ro_store(struct device *dev, struct device_attribute *attr,
267 const char *buf, size_t count)
271 struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
272 unsigned long set = simple_strtoul(buf, &end, 0);
278 set_disk_ro(dev_to_disk(dev), set || md->read_only);
285 static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
287 struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk);
290 mutex_lock(&block_mutex);
293 check_disk_change(bdev);
296 if ((mode & FMODE_WRITE) && md->read_only) {
301 mutex_unlock(&block_mutex);
306 static void mmc_blk_release(struct gendisk *disk, fmode_t mode)
308 struct mmc_blk_data *md = disk->private_data;
310 mutex_lock(&block_mutex);
312 mutex_unlock(&block_mutex);
316 mmc_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
318 geo->cylinders = get_capacity(bdev->bd_disk) / (4 * 16);
324 struct mmc_blk_ioc_data {
325 struct mmc_ioc_cmd ic;
330 static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user(
331 struct mmc_ioc_cmd __user *user)
333 struct mmc_blk_ioc_data *idata;
336 idata = kzalloc(sizeof(*idata), GFP_KERNEL);
342 if (copy_from_user(&idata->ic, user, sizeof(idata->ic))) {
347 idata->buf_bytes = (u64) idata->ic.blksz * idata->ic.blocks;
348 if (idata->buf_bytes > MMC_IOC_MAX_BYTES) {
353 if (!idata->buf_bytes)
356 idata->buf = kzalloc(idata->buf_bytes, GFP_KERNEL);
362 if (copy_from_user(idata->buf, (void __user *)(unsigned long)
363 idata->ic.data_ptr, idata->buf_bytes)) {
378 static int ioctl_rpmb_card_status_poll(struct mmc_card *card, u32 *status,
384 if (!status || !retries_max)
388 err = get_card_status(card, status, 5);
392 if (!R1_STATUS(*status) &&
393 (R1_CURRENT_STATE(*status) != R1_STATE_PRG))
394 break; /* RPMB programming operation complete */
397 * Rechedule to give the MMC device a chance to continue
398 * processing the previous command without being polled too
401 usleep_range(1000, 5000);
402 } while (++retry_count < retries_max);
404 if (retry_count == retries_max)
410 static int mmc_blk_ioctl_cmd(struct block_device *bdev,
411 struct mmc_ioc_cmd __user *ic_ptr)
413 struct mmc_blk_ioc_data *idata;
414 struct mmc_blk_data *md;
415 struct mmc_card *card;
416 struct mmc_command cmd = {0};
417 struct mmc_data data = {0};
418 struct mmc_request mrq = {NULL};
419 struct scatterlist sg;
425 * The caller must have CAP_SYS_RAWIO, and must be calling this on the
426 * whole block device, not on a partition. This prevents overspray
427 * between sibling partitions.
429 if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains))
432 idata = mmc_blk_ioctl_copy_from_user(ic_ptr);
434 return PTR_ERR(idata);
436 md = mmc_blk_get(bdev->bd_disk);
442 if (md->area_type & MMC_BLK_DATA_AREA_RPMB)
445 card = md->queue.card;
451 cmd.opcode = idata->ic.opcode;
452 cmd.arg = idata->ic.arg;
453 cmd.flags = idata->ic.flags;
455 if (idata->buf_bytes) {
458 data.blksz = idata->ic.blksz;
459 data.blocks = idata->ic.blocks;
461 sg_init_one(data.sg, idata->buf, idata->buf_bytes);
463 if (idata->ic.write_flag)
464 data.flags = MMC_DATA_WRITE;
466 data.flags = MMC_DATA_READ;
468 /* data.flags must already be set before doing this. */
469 mmc_set_data_timeout(&data, card);
471 /* Allow overriding the timeout_ns for empirical tuning. */
472 if (idata->ic.data_timeout_ns)
473 data.timeout_ns = idata->ic.data_timeout_ns;
475 if ((cmd.flags & MMC_RSP_R1B) == MMC_RSP_R1B) {
477 * Pretend this is a data transfer and rely on the
478 * host driver to compute timeout. When all host
479 * drivers support cmd.cmd_timeout for R1B, this
483 * cmd.cmd_timeout = idata->ic.cmd_timeout_ms;
485 data.timeout_ns = idata->ic.cmd_timeout_ms * 1000000;
493 mmc_claim_host(card->host);
495 err = mmc_blk_part_switch(card, md);
499 if (idata->ic.is_acmd) {
500 err = mmc_app_cmd(card->host, card);
506 err = mmc_set_blockcount(card, data.blocks,
507 idata->ic.write_flag & (1 << 31));
512 mmc_wait_for_req(card->host, &mrq);
515 dev_err(mmc_dev(card->host), "%s: cmd error %d\n",
516 __func__, cmd.error);
521 dev_err(mmc_dev(card->host), "%s: data error %d\n",
522 __func__, data.error);
528 * According to the SD specs, some commands require a delay after
529 * issuing the command.
531 if (idata->ic.postsleep_min_us)
532 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
534 if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
539 if (!idata->ic.write_flag) {
540 if (copy_to_user((void __user *)(unsigned long) idata->ic.data_ptr,
541 idata->buf, idata->buf_bytes)) {
549 * Ensure RPMB command has completed by polling CMD13
552 err = ioctl_rpmb_card_status_poll(card, &status, 5);
554 dev_err(mmc_dev(card->host),
555 "%s: Card Status=0x%08X, error %d\n",
556 __func__, status, err);
560 mmc_release_host(card->host);
570 static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode,
571 unsigned int cmd, unsigned long arg)
574 if (cmd == MMC_IOC_CMD)
575 ret = mmc_blk_ioctl_cmd(bdev, (struct mmc_ioc_cmd __user *)arg);
580 static int mmc_blk_compat_ioctl(struct block_device *bdev, fmode_t mode,
581 unsigned int cmd, unsigned long arg)
583 return mmc_blk_ioctl(bdev, mode, cmd, (unsigned long) compat_ptr(arg));
587 static const struct block_device_operations mmc_bdops = {
588 .open = mmc_blk_open,
589 .release = mmc_blk_release,
590 .getgeo = mmc_blk_getgeo,
591 .owner = THIS_MODULE,
592 .ioctl = mmc_blk_ioctl,
594 .compat_ioctl = mmc_blk_compat_ioctl,
598 static inline int mmc_blk_part_switch(struct mmc_card *card,
599 struct mmc_blk_data *md)
602 struct mmc_blk_data *main_md = mmc_get_drvdata(card);
604 if (main_md->part_curr == md->part_type)
607 if (mmc_card_mmc(card)) {
608 u8 part_config = card->ext_csd.part_config;
610 part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK;
611 part_config |= md->part_type;
613 ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
614 EXT_CSD_PART_CONFIG, part_config,
615 card->ext_csd.part_time);
619 card->ext_csd.part_config = part_config;
622 main_md->part_curr = md->part_type;
626 static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
632 struct mmc_request mrq = {NULL};
633 struct mmc_command cmd = {0};
634 struct mmc_data data = {0};
636 struct scatterlist sg;
638 cmd.opcode = MMC_APP_CMD;
639 cmd.arg = card->rca << 16;
640 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
642 err = mmc_wait_for_cmd(card->host, &cmd, 0);
645 if (!mmc_host_is_spi(card->host) && !(cmd.resp[0] & R1_APP_CMD))
648 memset(&cmd, 0, sizeof(struct mmc_command));
650 cmd.opcode = SD_APP_SEND_NUM_WR_BLKS;
652 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
656 data.flags = MMC_DATA_READ;
659 mmc_set_data_timeout(&data, card);
664 blocks = kmalloc(4, GFP_KERNEL);
668 sg_init_one(&sg, blocks, 4);
670 mmc_wait_for_req(card->host, &mrq);
672 result = ntohl(*blocks);
675 if (cmd.error || data.error)
681 static int send_stop(struct mmc_card *card, u32 *status)
683 struct mmc_command cmd = {0};
686 cmd.opcode = MMC_STOP_TRANSMISSION;
687 cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
688 err = mmc_wait_for_cmd(card->host, &cmd, 5);
690 *status = cmd.resp[0];
694 static int get_card_status(struct mmc_card *card, u32 *status, int retries)
696 struct mmc_command cmd = {0};
699 cmd.opcode = MMC_SEND_STATUS;
700 if (!mmc_host_is_spi(card->host))
701 cmd.arg = card->rca << 16;
702 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
703 err = mmc_wait_for_cmd(card->host, &cmd, retries);
705 *status = cmd.resp[0];
709 #define ERR_NOMEDIUM 3
712 #define ERR_CONTINUE 0
714 static int mmc_blk_cmd_error(struct request *req, const char *name, int error,
715 bool status_valid, u32 status)
719 /* response crc error, retry the r/w cmd */
720 pr_err("%s: %s sending %s command, card status %#x\n",
721 req->rq_disk->disk_name, "response CRC error",
726 pr_err("%s: %s sending %s command, card status %#x\n",
727 req->rq_disk->disk_name, "timed out", name, status);
729 /* If the status cmd initially failed, retry the r/w cmd */
731 pr_err("%s: status not valid, retrying timeout\n", req->rq_disk->disk_name);
735 * If it was a r/w cmd crc error, or illegal command
736 * (eg, issued in wrong state) then retry - we should
737 * have corrected the state problem above.
739 if (status & (R1_COM_CRC_ERROR | R1_ILLEGAL_COMMAND)) {
740 pr_err("%s: command error, retrying timeout\n", req->rq_disk->disk_name);
744 /* Otherwise abort the command */
745 pr_err("%s: not retrying timeout\n", req->rq_disk->disk_name);
749 /* We don't understand the error code the driver gave us */
750 pr_err("%s: unknown error %d sending read/write command, card status %#x\n",
751 req->rq_disk->disk_name, error, status);
757 * Initial r/w and stop cmd error recovery.
758 * We don't know whether the card received the r/w cmd or not, so try to
759 * restore things back to a sane state. Essentially, we do this as follows:
760 * - Obtain card status. If the first attempt to obtain card status fails,
761 * the status word will reflect the failed status cmd, not the failed
762 * r/w cmd. If we fail to obtain card status, it suggests we can no
763 * longer communicate with the card.
764 * - Check the card state. If the card received the cmd but there was a
765 * transient problem with the response, it might still be in a data transfer
766 * mode. Try to send it a stop command. If this fails, we can't recover.
767 * - If the r/w cmd failed due to a response CRC error, it was probably
768 * transient, so retry the cmd.
769 * - If the r/w cmd timed out, but we didn't get the r/w cmd status, retry.
770 * - If the r/w cmd timed out, and the r/w cmd failed due to CRC error or
771 * illegal cmd, retry.
772 * Otherwise we don't understand what happened, so abort.
774 static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
775 struct mmc_blk_request *brq, int *ecc_err, int *gen_err)
777 bool prev_cmd_status_valid = true;
778 u32 status, stop_status = 0;
781 if (mmc_card_removed(card))
785 * Try to get card status which indicates both the card state
786 * and why there was no response. If the first attempt fails,
787 * we can't be sure the returned status is for the r/w command.
789 for (retry = 2; retry >= 0; retry--) {
790 err = get_card_status(card, &status, 0);
794 prev_cmd_status_valid = false;
795 pr_err("%s: error %d sending status command, %sing\n",
796 req->rq_disk->disk_name, err, retry ? "retry" : "abort");
799 /* We couldn't get a response from the card. Give up. */
801 /* Check if the card is removed */
802 if (mmc_detect_card_removed(card->host))
807 /* Flag ECC errors */
808 if ((status & R1_CARD_ECC_FAILED) ||
809 (brq->stop.resp[0] & R1_CARD_ECC_FAILED) ||
810 (brq->cmd.resp[0] & R1_CARD_ECC_FAILED))
813 /* Flag General errors */
814 if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ)
815 if ((status & R1_ERROR) ||
816 (brq->stop.resp[0] & R1_ERROR)) {
817 pr_err("%s: %s: general error sending stop or status command, stop cmd response %#x, card status %#x\n",
818 req->rq_disk->disk_name, __func__,
819 brq->stop.resp[0], status);
824 * Check the current card state. If it is in some data transfer
825 * mode, tell it to stop (and hopefully transition back to TRAN.)
827 if (R1_CURRENT_STATE(status) == R1_STATE_DATA ||
828 R1_CURRENT_STATE(status) == R1_STATE_RCV) {
829 err = send_stop(card, &stop_status);
831 pr_err("%s: error %d sending stop command\n",
832 req->rq_disk->disk_name, err);
835 * If the stop cmd also timed out, the card is probably
836 * not present, so abort. Other errors are bad news too.
840 if (stop_status & R1_CARD_ECC_FAILED)
842 if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ)
843 if (stop_status & R1_ERROR) {
844 pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n",
845 req->rq_disk->disk_name, __func__,
851 /* Check for set block count errors */
853 return mmc_blk_cmd_error(req, "SET_BLOCK_COUNT", brq->sbc.error,
854 prev_cmd_status_valid, status);
856 /* Check for r/w command errors */
858 return mmc_blk_cmd_error(req, "r/w cmd", brq->cmd.error,
859 prev_cmd_status_valid, status);
862 if (!brq->stop.error)
865 /* Now for stop errors. These aren't fatal to the transfer. */
866 pr_err("%s: error %d sending stop command, original cmd response %#x, card status %#x\n",
867 req->rq_disk->disk_name, brq->stop.error,
868 brq->cmd.resp[0], status);
871 * Subsitute in our own stop status as this will give the error
872 * state which happened during the execution of the r/w command.
875 brq->stop.resp[0] = stop_status;
881 static int mmc_blk_reset(struct mmc_blk_data *md, struct mmc_host *host,
886 if (md->reset_done & type)
889 md->reset_done |= type;
890 err = mmc_hw_reset(host);
891 /* Ensure we switch back to the correct partition */
892 if (err != -EOPNOTSUPP) {
893 struct mmc_blk_data *main_md = mmc_get_drvdata(host->card);
896 main_md->part_curr = main_md->part_type;
897 part_err = mmc_blk_part_switch(host->card, md);
900 * We have failed to get back into the correct
901 * partition, so we need to abort the whole request.
909 static inline void mmc_blk_reset_success(struct mmc_blk_data *md, int type)
911 md->reset_done &= ~type;
914 static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
916 struct mmc_blk_data *md = mq->data;
917 struct mmc_card *card = md->queue.card;
918 unsigned int from, nr, arg;
919 int err = 0, type = MMC_BLK_DISCARD;
921 if (!mmc_can_erase(card)) {
926 from = blk_rq_pos(req);
927 nr = blk_rq_sectors(req);
929 if (mmc_can_discard(card))
930 arg = MMC_DISCARD_ARG;
931 else if (mmc_can_trim(card))
936 if (card->quirks & MMC_QUIRK_INAND_CMD38) {
937 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
938 INAND_CMD38_ARG_EXT_CSD,
939 arg == MMC_TRIM_ARG ?
940 INAND_CMD38_ARG_TRIM :
941 INAND_CMD38_ARG_ERASE,
946 err = mmc_erase(card, from, nr, arg);
948 if (err == -EIO && !mmc_blk_reset(md, card->host, type))
951 mmc_blk_reset_success(md, type);
952 blk_end_request(req, err, blk_rq_bytes(req));
957 static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
960 struct mmc_blk_data *md = mq->data;
961 struct mmc_card *card = md->queue.card;
962 unsigned int from, nr, arg, trim_arg, erase_arg;
963 int err = 0, type = MMC_BLK_SECDISCARD;
965 if (!(mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))) {
970 from = blk_rq_pos(req);
971 nr = blk_rq_sectors(req);
973 /* The sanitize operation is supported at v4.5 only */
974 if (mmc_can_sanitize(card)) {
975 erase_arg = MMC_ERASE_ARG;
976 trim_arg = MMC_TRIM_ARG;
978 erase_arg = MMC_SECURE_ERASE_ARG;
979 trim_arg = MMC_SECURE_TRIM1_ARG;
982 if (mmc_erase_group_aligned(card, from, nr))
984 else if (mmc_can_trim(card))
991 if (card->quirks & MMC_QUIRK_INAND_CMD38) {
992 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
993 INAND_CMD38_ARG_EXT_CSD,
994 arg == MMC_SECURE_TRIM1_ARG ?
995 INAND_CMD38_ARG_SECTRIM1 :
996 INAND_CMD38_ARG_SECERASE,
1002 err = mmc_erase(card, from, nr, arg);
1008 if (arg == MMC_SECURE_TRIM1_ARG) {
1009 if (card->quirks & MMC_QUIRK_INAND_CMD38) {
1010 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1011 INAND_CMD38_ARG_EXT_CSD,
1012 INAND_CMD38_ARG_SECTRIM2,
1018 err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG);
1025 if (mmc_can_sanitize(card)) {
1026 trace_mmc_blk_erase_start(EXT_CSD_SANITIZE_START, 0, 0);
1027 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1028 EXT_CSD_SANITIZE_START, 1, 0);
1029 trace_mmc_blk_erase_end(EXT_CSD_SANITIZE_START, 0, 0);
1032 if (err && !mmc_blk_reset(md, card->host, type))
1035 mmc_blk_reset_success(md, type);
1037 blk_end_request(req, err, blk_rq_bytes(req));
1042 static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req)
1044 struct mmc_blk_data *md = mq->data;
1045 struct mmc_card *card = md->queue.card;
1048 ret = mmc_flush_cache(card);
1052 blk_end_request_all(req, ret);
1058 * Reformat current write as a reliable write, supporting
1059 * both legacy and the enhanced reliable write MMC cards.
1060 * In each transfer we'll handle only as much as a single
1061 * reliable write can handle, thus finish the request in
1062 * partial completions.
1064 static inline void mmc_apply_rel_rw(struct mmc_blk_request *brq,
1065 struct mmc_card *card,
1066 struct request *req)
1068 if (!(card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN)) {
1069 /* Legacy mode imposes restrictions on transfers. */
1070 if (!IS_ALIGNED(brq->cmd.arg, card->ext_csd.rel_sectors))
1071 brq->data.blocks = 1;
1073 if (brq->data.blocks > card->ext_csd.rel_sectors)
1074 brq->data.blocks = card->ext_csd.rel_sectors;
1075 else if (brq->data.blocks < card->ext_csd.rel_sectors)
1076 brq->data.blocks = 1;
1080 #define CMD_ERRORS \
1081 (R1_OUT_OF_RANGE | /* Command argument out of range */ \
1082 R1_ADDRESS_ERROR | /* Misaligned address */ \
1083 R1_BLOCK_LEN_ERROR | /* Transferred block length incorrect */\
1084 R1_WP_VIOLATION | /* Tried to write to protected block */ \
1085 R1_CC_ERROR | /* Card controller error */ \
1086 R1_ERROR) /* General/unknown error */
1088 static int mmc_blk_err_check(struct mmc_card *card,
1089 struct mmc_async_req *areq)
1091 struct mmc_queue_req *mq_mrq = container_of(areq, struct mmc_queue_req,
1093 struct mmc_blk_request *brq = &mq_mrq->brq;
1094 struct request *req = mq_mrq->req;
1095 int ecc_err = 0, gen_err = 0;
1098 * sbc.error indicates a problem with the set block count
1099 * command. No data will have been transferred.
1101 * cmd.error indicates a problem with the r/w command. No
1102 * data will have been transferred.
1104 * stop.error indicates a problem with the stop command. Data
1105 * may have been transferred, or may still be transferring.
1107 if (brq->sbc.error || brq->cmd.error || brq->stop.error ||
1109 switch (mmc_blk_cmd_recovery(card, req, brq, &ecc_err, &gen_err)) {
1111 return MMC_BLK_RETRY;
1113 return MMC_BLK_ABORT;
1115 return MMC_BLK_NOMEDIUM;
1122 * Check for errors relating to the execution of the
1123 * initial command - such as address errors. No data
1124 * has been transferred.
1126 if (brq->cmd.resp[0] & CMD_ERRORS) {
1127 pr_err("%s: r/w command failed, status = %#x\n",
1128 req->rq_disk->disk_name, brq->cmd.resp[0]);
1129 return MMC_BLK_ABORT;
1133 * Everything else is either success, or a data error of some
1134 * kind. If it was a write, we may have transitioned to
1135 * program mode, which we have to wait for it to complete.
1137 if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) {
1139 unsigned long timeout;
1141 /* Check stop command response */
1142 if (brq->stop.resp[0] & R1_ERROR) {
1143 pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n",
1144 req->rq_disk->disk_name, __func__,
1149 timeout = jiffies + msecs_to_jiffies(MMC_BLK_TIMEOUT_MS);
1151 int err = get_card_status(card, &status, 5);
1153 pr_err("%s: error %d requesting status\n",
1154 req->rq_disk->disk_name, err);
1155 return MMC_BLK_CMD_ERR;
1158 if (status & R1_ERROR) {
1159 pr_err("%s: %s: general error sending status command, card status %#x\n",
1160 req->rq_disk->disk_name, __func__,
1165 /* Timeout if the device never becomes ready for data
1166 * and never leaves the program state.
1168 if (time_after(jiffies, timeout)) {
1169 pr_err("%s: Card stuck in programming state!"\
1170 " %s %s\n", mmc_hostname(card->host),
1171 req->rq_disk->disk_name, __func__);
1173 return MMC_BLK_CMD_ERR;
1176 * Some cards mishandle the status bits,
1177 * so make sure to check both the busy
1178 * indication and the card state.
1180 } while (!(status & R1_READY_FOR_DATA) ||
1181 (R1_CURRENT_STATE(status) == R1_STATE_PRG));
1184 /* if general error occurs, retry the write operation. */
1186 pr_warn("%s: retrying write for general error\n",
1187 req->rq_disk->disk_name);
1188 return MMC_BLK_RETRY;
1191 if (brq->data.error) {
1192 pr_err("%s: error %d transferring data, sector %u, nr %u, cmd response %#x, card status %#x\n",
1193 req->rq_disk->disk_name, brq->data.error,
1194 (unsigned)blk_rq_pos(req),
1195 (unsigned)blk_rq_sectors(req),
1196 brq->cmd.resp[0], brq->stop.resp[0]);
1198 if (rq_data_dir(req) == READ) {
1200 return MMC_BLK_ECC_ERR;
1201 return MMC_BLK_DATA_ERR;
1203 return MMC_BLK_CMD_ERR;
1207 if (!brq->data.bytes_xfered)
1208 return MMC_BLK_RETRY;
1210 if (mmc_packed_cmd(mq_mrq->cmd_type)) {
1211 if (unlikely(brq->data.blocks << 9 != brq->data.bytes_xfered))
1212 return MMC_BLK_PARTIAL;
1214 return MMC_BLK_SUCCESS;
1217 if (blk_rq_bytes(req) != brq->data.bytes_xfered)
1218 return MMC_BLK_PARTIAL;
1220 return MMC_BLK_SUCCESS;
1223 static int mmc_blk_packed_err_check(struct mmc_card *card,
1224 struct mmc_async_req *areq)
1226 struct mmc_queue_req *mq_rq = container_of(areq, struct mmc_queue_req,
1228 struct request *req = mq_rq->req;
1229 struct mmc_packed *packed = mq_rq->packed;
1230 int err, check, status;
1236 check = mmc_blk_err_check(card, areq);
1237 err = get_card_status(card, &status, 0);
1239 pr_err("%s: error %d sending status command\n",
1240 req->rq_disk->disk_name, err);
1241 return MMC_BLK_ABORT;
1244 if (status & R1_EXCEPTION_EVENT) {
1245 ext_csd = kzalloc(512, GFP_KERNEL);
1247 pr_err("%s: unable to allocate buffer for ext_csd\n",
1248 req->rq_disk->disk_name);
1252 err = mmc_send_ext_csd(card, ext_csd);
1254 pr_err("%s: error %d sending ext_csd\n",
1255 req->rq_disk->disk_name, err);
1256 check = MMC_BLK_ABORT;
1260 if ((ext_csd[EXT_CSD_EXP_EVENTS_STATUS] &
1261 EXT_CSD_PACKED_FAILURE) &&
1262 (ext_csd[EXT_CSD_PACKED_CMD_STATUS] &
1263 EXT_CSD_PACKED_GENERIC_ERROR)) {
1264 if (ext_csd[EXT_CSD_PACKED_CMD_STATUS] &
1265 EXT_CSD_PACKED_INDEXED_ERROR) {
1266 packed->idx_failure =
1267 ext_csd[EXT_CSD_PACKED_FAILURE_INDEX] - 1;
1268 check = MMC_BLK_PARTIAL;
1270 pr_err("%s: packed cmd failed, nr %u, sectors %u, "
1271 "failure index: %d\n",
1272 req->rq_disk->disk_name, packed->nr_entries,
1273 packed->blocks, packed->idx_failure);
1282 static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
1283 struct mmc_card *card,
1285 struct mmc_queue *mq)
1287 u32 readcmd, writecmd;
1288 struct mmc_blk_request *brq = &mqrq->brq;
1289 struct request *req = mqrq->req;
1290 struct mmc_blk_data *md = mq->data;
1294 * Reliable writes are used to implement Forced Unit Access and
1295 * REQ_META accesses, and are supported only on MMCs.
1297 * XXX: this really needs a good explanation of why REQ_META
1298 * is treated special.
1300 bool do_rel_wr = ((req->cmd_flags & REQ_FUA) ||
1301 (req->cmd_flags & REQ_META)) &&
1302 (rq_data_dir(req) == WRITE) &&
1303 (md->flags & MMC_BLK_REL_WR);
1305 memset(brq, 0, sizeof(struct mmc_blk_request));
1306 brq->mrq.cmd = &brq->cmd;
1307 brq->mrq.data = &brq->data;
1309 brq->cmd.arg = blk_rq_pos(req);
1310 if (!mmc_card_blockaddr(card))
1312 brq->cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
1313 brq->data.blksz = 512;
1314 brq->stop.opcode = MMC_STOP_TRANSMISSION;
1316 brq->stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
1317 brq->data.blocks = blk_rq_sectors(req);
1320 * The block layer doesn't support all sector count
1321 * restrictions, so we need to be prepared for too big
1324 if (brq->data.blocks > card->host->max_blk_count)
1325 brq->data.blocks = card->host->max_blk_count;
1327 if (brq->data.blocks > 1) {
1329 * After a read error, we redo the request one sector
1330 * at a time in order to accurately determine which
1331 * sectors can be read successfully.
1334 brq->data.blocks = 1;
1336 /* Some controllers can't do multiblock reads due to hw bugs */
1337 if (card->host->caps2 & MMC_CAP2_NO_MULTI_READ &&
1338 rq_data_dir(req) == READ)
1339 brq->data.blocks = 1;
1342 if (brq->data.blocks > 1 || do_rel_wr) {
1343 /* SPI multiblock writes terminate using a special
1344 * token, not a STOP_TRANSMISSION request.
1346 if (!mmc_host_is_spi(card->host) ||
1347 rq_data_dir(req) == READ)
1348 brq->mrq.stop = &brq->stop;
1349 readcmd = MMC_READ_MULTIPLE_BLOCK;
1350 writecmd = MMC_WRITE_MULTIPLE_BLOCK;
1352 brq->mrq.stop = NULL;
1353 readcmd = MMC_READ_SINGLE_BLOCK;
1354 writecmd = MMC_WRITE_BLOCK;
1356 if (rq_data_dir(req) == READ) {
1357 brq->cmd.opcode = readcmd;
1358 brq->data.flags |= MMC_DATA_READ;
1360 brq->cmd.opcode = writecmd;
1361 brq->data.flags |= MMC_DATA_WRITE;
1365 mmc_apply_rel_rw(brq, card, req);
1368 * Data tag is used only during writing meta data to speed
1369 * up write and any subsequent read of this meta data
1371 do_data_tag = (card->ext_csd.data_tag_unit_size) &&
1372 (req->cmd_flags & REQ_META) &&
1373 (rq_data_dir(req) == WRITE) &&
1374 ((brq->data.blocks * brq->data.blksz) >=
1375 card->ext_csd.data_tag_unit_size);
1378 * Pre-defined multi-block transfers are preferable to
1379 * open ended-ones (and necessary for reliable writes).
1380 * However, it is not sufficient to just send CMD23,
1381 * and avoid the final CMD12, as on an error condition
1382 * CMD12 (stop) needs to be sent anyway. This, coupled
1383 * with Auto-CMD23 enhancements provided by some
1384 * hosts, means that the complexity of dealing
1385 * with this is best left to the host. If CMD23 is
1386 * supported by card and host, we'll fill sbc in and let
1387 * the host deal with handling it correctly. This means
1388 * that for hosts that don't expose MMC_CAP_CMD23, no
1389 * change of behavior will be observed.
1391 * N.B: Some MMC cards experience perf degradation.
1392 * We'll avoid using CMD23-bounded multiblock writes for
1393 * these, while retaining features like reliable writes.
1395 if ((md->flags & MMC_BLK_CMD23) && mmc_op_multi(brq->cmd.opcode) &&
1396 (do_rel_wr || !(card->quirks & MMC_QUIRK_BLK_NO_CMD23) ||
1398 brq->sbc.opcode = MMC_SET_BLOCK_COUNT;
1399 brq->sbc.arg = brq->data.blocks |
1400 (do_rel_wr ? (1 << 31) : 0) |
1401 (do_data_tag ? (1 << 29) : 0);
1402 brq->sbc.flags = MMC_RSP_R1 | MMC_CMD_AC;
1403 brq->mrq.sbc = &brq->sbc;
1406 mmc_set_data_timeout(&brq->data, card);
1408 brq->data.sg = mqrq->sg;
1409 brq->data.sg_len = mmc_queue_map_sg(mq, mqrq);
1412 * Adjust the sg list so it is the same size as the
1415 if (brq->data.blocks != blk_rq_sectors(req)) {
1416 int i, data_size = brq->data.blocks << 9;
1417 struct scatterlist *sg;
1419 for_each_sg(brq->data.sg, sg, brq->data.sg_len, i) {
1420 data_size -= sg->length;
1421 if (data_size <= 0) {
1422 sg->length += data_size;
1427 brq->data.sg_len = i;
1430 mqrq->mmc_active.mrq = &brq->mrq;
1431 mqrq->mmc_active.err_check = mmc_blk_err_check;
1433 mmc_queue_bounce_pre(mqrq);
1436 static inline u8 mmc_calc_packed_hdr_segs(struct request_queue *q,
1437 struct mmc_card *card)
1439 unsigned int hdr_sz = mmc_large_sector(card) ? 4096 : 512;
1440 unsigned int max_seg_sz = queue_max_segment_size(q);
1441 unsigned int len, nr_segs = 0;
1444 len = min(hdr_sz, max_seg_sz);
1452 static u8 mmc_blk_prep_packed_list(struct mmc_queue *mq, struct request *req)
1454 struct request_queue *q = mq->queue;
1455 struct mmc_card *card = mq->card;
1456 struct request *cur = req, *next = NULL;
1457 struct mmc_blk_data *md = mq->data;
1458 struct mmc_queue_req *mqrq = mq->mqrq_cur;
1459 bool en_rel_wr = card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN;
1460 unsigned int req_sectors = 0, phys_segments = 0;
1461 unsigned int max_blk_count, max_phys_segs;
1462 bool put_back = true;
1463 u8 max_packed_rw = 0;
1466 if (!(md->flags & MMC_BLK_PACKED_CMD))
1469 if ((rq_data_dir(cur) == WRITE) &&
1470 mmc_host_packed_wr(card->host))
1471 max_packed_rw = card->ext_csd.max_packed_writes;
1473 if (max_packed_rw == 0)
1476 if (mmc_req_rel_wr(cur) &&
1477 (md->flags & MMC_BLK_REL_WR) && !en_rel_wr)
1480 if (mmc_large_sector(card) &&
1481 !IS_ALIGNED(blk_rq_sectors(cur), 8))
1484 mmc_blk_clear_packed(mqrq);
1486 max_blk_count = min(card->host->max_blk_count,
1487 card->host->max_req_size >> 9);
1488 if (unlikely(max_blk_count > 0xffff))
1489 max_blk_count = 0xffff;
1491 max_phys_segs = queue_max_segments(q);
1492 req_sectors += blk_rq_sectors(cur);
1493 phys_segments += cur->nr_phys_segments;
1495 if (rq_data_dir(cur) == WRITE) {
1496 req_sectors += mmc_large_sector(card) ? 8 : 1;
1497 phys_segments += mmc_calc_packed_hdr_segs(q, card);
1501 if (reqs >= max_packed_rw - 1) {
1506 spin_lock_irq(q->queue_lock);
1507 next = blk_fetch_request(q);
1508 spin_unlock_irq(q->queue_lock);
1514 if (mmc_large_sector(card) &&
1515 !IS_ALIGNED(blk_rq_sectors(next), 8))
1518 if (next->cmd_flags & REQ_DISCARD ||
1519 next->cmd_flags & REQ_FLUSH)
1522 if (rq_data_dir(cur) != rq_data_dir(next))
1525 if (mmc_req_rel_wr(next) &&
1526 (md->flags & MMC_BLK_REL_WR) && !en_rel_wr)
1529 req_sectors += blk_rq_sectors(next);
1530 if (req_sectors > max_blk_count)
1533 phys_segments += next->nr_phys_segments;
1534 if (phys_segments > max_phys_segs)
1537 list_add_tail(&next->queuelist, &mqrq->packed->list);
1543 spin_lock_irq(q->queue_lock);
1544 blk_requeue_request(q, next);
1545 spin_unlock_irq(q->queue_lock);
1549 list_add(&req->queuelist, &mqrq->packed->list);
1550 mqrq->packed->nr_entries = ++reqs;
1551 mqrq->packed->retries = reqs;
1556 mqrq->cmd_type = MMC_PACKED_NONE;
1560 static void mmc_blk_packed_hdr_wrq_prep(struct mmc_queue_req *mqrq,
1561 struct mmc_card *card,
1562 struct mmc_queue *mq)
1564 struct mmc_blk_request *brq = &mqrq->brq;
1565 struct request *req = mqrq->req;
1566 struct request *prq;
1567 struct mmc_blk_data *md = mq->data;
1568 struct mmc_packed *packed = mqrq->packed;
1569 bool do_rel_wr, do_data_tag;
1570 u32 *packed_cmd_hdr;
1576 mqrq->cmd_type = MMC_PACKED_WRITE;
1578 packed->idx_failure = MMC_PACKED_NR_IDX;
1580 packed_cmd_hdr = packed->cmd_hdr;
1581 memset(packed_cmd_hdr, 0, sizeof(packed->cmd_hdr));
1582 packed_cmd_hdr[0] = (packed->nr_entries << 16) |
1583 (PACKED_CMD_WR << 8) | PACKED_CMD_VER;
1584 hdr_blocks = mmc_large_sector(card) ? 8 : 1;
1587 * Argument for each entry of packed group
1589 list_for_each_entry(prq, &packed->list, queuelist) {
1590 do_rel_wr = mmc_req_rel_wr(prq) && (md->flags & MMC_BLK_REL_WR);
1591 do_data_tag = (card->ext_csd.data_tag_unit_size) &&
1592 (prq->cmd_flags & REQ_META) &&
1593 (rq_data_dir(prq) == WRITE) &&
1594 ((brq->data.blocks * brq->data.blksz) >=
1595 card->ext_csd.data_tag_unit_size);
1596 /* Argument of CMD23 */
1597 packed_cmd_hdr[(i * 2)] =
1598 (do_rel_wr ? MMC_CMD23_ARG_REL_WR : 0) |
1599 (do_data_tag ? MMC_CMD23_ARG_TAG_REQ : 0) |
1600 blk_rq_sectors(prq);
1601 /* Argument of CMD18 or CMD25 */
1602 packed_cmd_hdr[((i * 2)) + 1] =
1603 mmc_card_blockaddr(card) ?
1604 blk_rq_pos(prq) : blk_rq_pos(prq) << 9;
1605 packed->blocks += blk_rq_sectors(prq);
1609 memset(brq, 0, sizeof(struct mmc_blk_request));
1610 brq->mrq.cmd = &brq->cmd;
1611 brq->mrq.data = &brq->data;
1612 brq->mrq.sbc = &brq->sbc;
1613 brq->mrq.stop = &brq->stop;
1615 brq->sbc.opcode = MMC_SET_BLOCK_COUNT;
1616 brq->sbc.arg = MMC_CMD23_ARG_PACKED | (packed->blocks + hdr_blocks);
1617 brq->sbc.flags = MMC_RSP_R1 | MMC_CMD_AC;
1619 brq->cmd.opcode = MMC_WRITE_MULTIPLE_BLOCK;
1620 brq->cmd.arg = blk_rq_pos(req);
1621 if (!mmc_card_blockaddr(card))
1623 brq->cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
1625 brq->data.blksz = 512;
1626 brq->data.blocks = packed->blocks + hdr_blocks;
1627 brq->data.flags |= MMC_DATA_WRITE;
1629 brq->stop.opcode = MMC_STOP_TRANSMISSION;
1631 brq->stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
1633 mmc_set_data_timeout(&brq->data, card);
1635 brq->data.sg = mqrq->sg;
1636 brq->data.sg_len = mmc_queue_map_sg(mq, mqrq);
1638 mqrq->mmc_active.mrq = &brq->mrq;
1639 mqrq->mmc_active.err_check = mmc_blk_packed_err_check;
1641 mmc_queue_bounce_pre(mqrq);
1644 static int mmc_blk_cmd_err(struct mmc_blk_data *md, struct mmc_card *card,
1645 struct mmc_blk_request *brq, struct request *req,
1648 struct mmc_queue_req *mq_rq;
1649 mq_rq = container_of(brq, struct mmc_queue_req, brq);
1652 * If this is an SD card and we're writing, we can first
1653 * mark the known good sectors as ok.
1655 * If the card is not SD, we can still ok written sectors
1656 * as reported by the controller (which might be less than
1657 * the real number of written sectors, but never more).
1659 if (mmc_card_sd(card)) {
1662 blocks = mmc_sd_num_wr_blocks(card);
1663 if (blocks != (u32)-1) {
1664 ret = blk_end_request(req, 0, blocks << 9);
1667 if (!mmc_packed_cmd(mq_rq->cmd_type))
1668 ret = blk_end_request(req, 0, brq->data.bytes_xfered);
1673 static int mmc_blk_end_packed_req(struct mmc_queue_req *mq_rq)
1675 struct request *prq;
1676 struct mmc_packed *packed = mq_rq->packed;
1677 int idx = packed->idx_failure, i = 0;
1682 while (!list_empty(&packed->list)) {
1683 prq = list_entry_rq(packed->list.next);
1685 /* retry from error index */
1686 packed->nr_entries -= idx;
1690 if (packed->nr_entries == MMC_PACKED_NR_SINGLE) {
1691 list_del_init(&prq->queuelist);
1692 mmc_blk_clear_packed(mq_rq);
1696 list_del_init(&prq->queuelist);
1697 blk_end_request(prq, 0, blk_rq_bytes(prq));
1701 mmc_blk_clear_packed(mq_rq);
1705 static void mmc_blk_abort_packed_req(struct mmc_queue_req *mq_rq)
1707 struct request *prq;
1708 struct mmc_packed *packed = mq_rq->packed;
1712 while (!list_empty(&packed->list)) {
1713 prq = list_entry_rq(packed->list.next);
1714 list_del_init(&prq->queuelist);
1715 blk_end_request(prq, -EIO, blk_rq_bytes(prq));
1718 mmc_blk_clear_packed(mq_rq);
1721 static void mmc_blk_revert_packed_req(struct mmc_queue *mq,
1722 struct mmc_queue_req *mq_rq)
1724 struct request *prq;
1725 struct request_queue *q = mq->queue;
1726 struct mmc_packed *packed = mq_rq->packed;
1730 while (!list_empty(&packed->list)) {
1731 prq = list_entry_rq(packed->list.prev);
1732 if (prq->queuelist.prev != &packed->list) {
1733 list_del_init(&prq->queuelist);
1734 spin_lock_irq(q->queue_lock);
1735 blk_requeue_request(mq->queue, prq);
1736 spin_unlock_irq(q->queue_lock);
1738 list_del_init(&prq->queuelist);
1742 mmc_blk_clear_packed(mq_rq);
1745 static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
1747 struct mmc_blk_data *md = mq->data;
1748 struct mmc_card *card = md->queue.card;
1749 struct mmc_blk_request *brq = &mq->mqrq_cur->brq;
1750 int ret = 1, disable_multi = 0, retry = 0, type;
1751 enum mmc_blk_status status;
1752 struct mmc_queue_req *mq_rq;
1753 struct request *req = rqc;
1754 struct mmc_async_req *areq;
1755 const u8 packed_nr = 2;
1758 if (!rqc && !mq->mqrq_prev->req)
1762 reqs = mmc_blk_prep_packed_list(mq, rqc);
1767 * When 4KB native sector is enabled, only 8 blocks
1768 * multiple read or write is allowed
1770 if ((brq->data.blocks & 0x07) &&
1771 (card->ext_csd.data_sector_size == 4096)) {
1772 pr_err("%s: Transfer size is not 4KB sector size aligned\n",
1773 req->rq_disk->disk_name);
1774 mq_rq = mq->mqrq_cur;
1778 if (reqs >= packed_nr)
1779 mmc_blk_packed_hdr_wrq_prep(mq->mqrq_cur,
1782 mmc_blk_rw_rq_prep(mq->mqrq_cur, card, 0, mq);
1783 areq = &mq->mqrq_cur->mmc_active;
1786 areq = mmc_start_req(card->host, areq, (int *) &status);
1788 if (status == MMC_BLK_NEW_REQUEST)
1789 mq->flags |= MMC_QUEUE_NEW_REQUEST;
1793 mq_rq = container_of(areq, struct mmc_queue_req, mmc_active);
1796 type = rq_data_dir(req) == READ ? MMC_BLK_READ : MMC_BLK_WRITE;
1797 mmc_queue_bounce_post(mq_rq);
1800 case MMC_BLK_SUCCESS:
1801 case MMC_BLK_PARTIAL:
1803 * A block was successfully transferred.
1805 mmc_blk_reset_success(md, type);
1807 if (mmc_packed_cmd(mq_rq->cmd_type)) {
1808 ret = mmc_blk_end_packed_req(mq_rq);
1811 ret = blk_end_request(req, 0,
1812 brq->data.bytes_xfered);
1816 * If the blk_end_request function returns non-zero even
1817 * though all data has been transferred and no errors
1818 * were returned by the host controller, it's a bug.
1820 if (status == MMC_BLK_SUCCESS && ret) {
1821 pr_err("%s BUG rq_tot %d d_xfer %d\n",
1822 __func__, blk_rq_bytes(req),
1823 brq->data.bytes_xfered);
1828 case MMC_BLK_CMD_ERR:
1829 ret = mmc_blk_cmd_err(md, card, brq, req, ret);
1830 if (!mmc_blk_reset(md, card->host, type))
1838 if (!mmc_blk_reset(md, card->host, type))
1841 case MMC_BLK_DATA_ERR: {
1844 err = mmc_blk_reset(md, card->host, type);
1847 if (err == -ENODEV ||
1848 mmc_packed_cmd(mq_rq->cmd_type))
1852 case MMC_BLK_ECC_ERR:
1853 if (brq->data.blocks > 1) {
1854 /* Redo read one sector at a time */
1855 pr_warning("%s: retrying using single block read\n",
1856 req->rq_disk->disk_name);
1861 * After an error, we redo I/O one sector at a
1862 * time, so we only reach here after trying to
1863 * read a single sector.
1865 ret = blk_end_request(req, -EIO,
1870 case MMC_BLK_NOMEDIUM:
1873 pr_err("%s: Unhandled return value (%d)",
1874 req->rq_disk->disk_name, status);
1879 if (mmc_packed_cmd(mq_rq->cmd_type)) {
1880 if (!mq_rq->packed->retries)
1882 mmc_blk_packed_hdr_wrq_prep(mq_rq, card, mq);
1883 mmc_start_req(card->host,
1884 &mq_rq->mmc_active, NULL);
1888 * In case of a incomplete request
1889 * prepare it again and resend.
1891 mmc_blk_rw_rq_prep(mq_rq, card,
1893 mmc_start_req(card->host,
1894 &mq_rq->mmc_active, NULL);
1902 if (mmc_packed_cmd(mq_rq->cmd_type)) {
1903 mmc_blk_abort_packed_req(mq_rq);
1905 if (mmc_card_removed(card))
1906 req->cmd_flags |= REQ_QUIET;
1908 ret = blk_end_request(req, -EIO,
1909 blk_rq_cur_bytes(req));
1914 if (mmc_card_removed(card)) {
1915 rqc->cmd_flags |= REQ_QUIET;
1916 blk_end_request_all(rqc, -EIO);
1919 * If current request is packed, it needs to put back.
1921 if (mmc_packed_cmd(mq->mqrq_cur->cmd_type))
1922 mmc_blk_revert_packed_req(mq, mq->mqrq_cur);
1924 mmc_blk_rw_rq_prep(mq->mqrq_cur, card, 0, mq);
1925 mmc_start_req(card->host,
1926 &mq->mqrq_cur->mmc_active, NULL);
1933 static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
1936 struct mmc_blk_data *md = mq->data;
1937 struct mmc_card *card = md->queue.card;
1938 struct mmc_host *host = card->host;
1939 unsigned long flags;
1940 unsigned int cmd_flags = req ? req->cmd_flags : 0;
1942 #ifdef CONFIG_MMC_BLOCK_DEFERRED_RESUME
1943 if (mmc_bus_needs_resume(card->host))
1944 mmc_resume_bus(card->host);
1947 if (req && !mq->mqrq_prev->req)
1948 /* claim host only for the first request */
1949 mmc_claim_host(card->host);
1951 ret = mmc_blk_part_switch(card, md);
1954 blk_end_request_all(req, -EIO);
1960 mq->flags &= ~MMC_QUEUE_NEW_REQUEST;
1961 if (cmd_flags & REQ_DISCARD) {
1962 /* complete ongoing async transfer before issuing discard */
1963 if (card->host->areq)
1964 mmc_blk_issue_rw_rq(mq, NULL);
1965 if (req->cmd_flags & REQ_SECURE &&
1966 !(card->quirks & MMC_QUIRK_SEC_ERASE_TRIM_BROKEN))
1967 ret = mmc_blk_issue_secdiscard_rq(mq, req);
1969 ret = mmc_blk_issue_discard_rq(mq, req);
1970 } else if (cmd_flags & REQ_FLUSH) {
1971 /* complete ongoing async transfer before issuing flush */
1972 if (card->host->areq)
1973 mmc_blk_issue_rw_rq(mq, NULL);
1974 ret = mmc_blk_issue_flush(mq, req);
1976 if (!req && host->areq) {
1977 spin_lock_irqsave(&host->context_info.lock, flags);
1978 host->context_info.is_waiting_last_req = true;
1979 spin_unlock_irqrestore(&host->context_info.lock, flags);
1981 ret = mmc_blk_issue_rw_rq(mq, req);
1985 if ((!req && !(mq->flags & MMC_QUEUE_NEW_REQUEST)) ||
1986 (cmd_flags & MMC_REQ_SPECIAL_MASK))
1988 * Release host when there are no more requests
1989 * and after special request(discard, flush) is done.
1990 * In case sepecial request, there is no reentry to
1991 * the 'mmc_blk_issue_rq' with 'mqrq_prev->req'.
1993 mmc_release_host(card->host);
1997 static inline int mmc_blk_readonly(struct mmc_card *card)
1999 return mmc_card_readonly(card) ||
2000 !(card->csd.cmdclass & CCC_BLOCK_WRITE);
2003 static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
2004 struct device *parent,
2007 const char *subname,
2010 struct mmc_blk_data *md;
2013 devidx = find_first_zero_bit(dev_use, max_devices);
2014 if (devidx >= max_devices)
2015 return ERR_PTR(-ENOSPC);
2016 __set_bit(devidx, dev_use);
2018 md = kzalloc(sizeof(struct mmc_blk_data), GFP_KERNEL);
2025 * !subname implies we are creating main mmc_blk_data that will be
2026 * associated with mmc_card with mmc_set_drvdata. Due to device
2027 * partitions, devidx will not coincide with a per-physical card
2028 * index anymore so we keep track of a name index.
2031 md->name_idx = find_first_zero_bit(name_use, max_devices);
2032 __set_bit(md->name_idx, name_use);
2034 md->name_idx = ((struct mmc_blk_data *)
2035 dev_to_disk(parent)->private_data)->name_idx;
2037 md->area_type = area_type;
2040 * Set the read-only status based on the supported commands
2041 * and the write protect switch.
2043 md->read_only = mmc_blk_readonly(card);
2045 md->disk = alloc_disk(perdev_minors);
2046 if (md->disk == NULL) {
2051 spin_lock_init(&md->lock);
2052 INIT_LIST_HEAD(&md->part);
2055 ret = mmc_init_queue(&md->queue, card, &md->lock, subname);
2059 md->queue.issue_fn = mmc_blk_issue_rq;
2060 md->queue.data = md;
2062 md->disk->major = MMC_BLOCK_MAJOR;
2063 md->disk->first_minor = devidx * perdev_minors;
2064 md->disk->fops = &mmc_bdops;
2065 md->disk->private_data = md;
2066 md->disk->queue = md->queue.queue;
2067 md->disk->driverfs_dev = parent;
2068 set_disk_ro(md->disk, md->read_only || default_ro);
2069 md->disk->flags = GENHD_FL_EXT_DEVT;
2070 if (area_type & MMC_BLK_DATA_AREA_RPMB)
2071 md->disk->flags |= GENHD_FL_NO_PART_SCAN;
2074 * As discussed on lkml, GENHD_FL_REMOVABLE should:
2076 * - be set for removable media with permanent block devices
2077 * - be unset for removable block devices with permanent media
2079 * Since MMC block devices clearly fall under the second
2080 * case, we do not set GENHD_FL_REMOVABLE. Userspace
2081 * should use the block device creation/destruction hotplug
2082 * messages to tell when the card is present.
2085 snprintf(md->disk->disk_name, sizeof(md->disk->disk_name),
2086 "mmcblk%d%s", md->name_idx, subname ? subname : "");
2088 if (mmc_card_mmc(card))
2089 blk_queue_logical_block_size(md->queue.queue,
2090 card->ext_csd.data_sector_size);
2092 blk_queue_logical_block_size(md->queue.queue, 512);
2094 set_capacity(md->disk, size);
2096 if (mmc_host_cmd23(card->host)) {
2097 if (mmc_card_mmc(card) ||
2098 (mmc_card_sd(card) &&
2099 card->scr.cmds & SD_SCR_CMD23_SUPPORT))
2100 md->flags |= MMC_BLK_CMD23;
2103 if (mmc_card_mmc(card) &&
2104 md->flags & MMC_BLK_CMD23 &&
2105 ((card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN) ||
2106 card->ext_csd.rel_sectors)) {
2107 md->flags |= MMC_BLK_REL_WR;
2108 blk_queue_flush(md->queue.queue, REQ_FLUSH | REQ_FUA);
2111 if (mmc_card_mmc(card) &&
2112 (area_type == MMC_BLK_DATA_AREA_MAIN) &&
2113 (md->flags & MMC_BLK_CMD23) &&
2114 card->ext_csd.packed_event_en) {
2115 if (!mmc_packed_init(&md->queue, card))
2116 md->flags |= MMC_BLK_PACKED_CMD;
2126 return ERR_PTR(ret);
2129 static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
2132 struct mmc_blk_data *md;
2134 if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) {
2136 * The EXT_CSD sector count is in number or 512 byte
2139 size = card->ext_csd.sectors;
2142 * The CSD capacity field is in units of read_blkbits.
2143 * set_capacity takes units of 512 bytes.
2145 size = card->csd.capacity << (card->csd.read_blkbits - 9);
2148 md = mmc_blk_alloc_req(card, &card->dev, size, false, NULL,
2149 MMC_BLK_DATA_AREA_MAIN);
2153 static int mmc_blk_alloc_part(struct mmc_card *card,
2154 struct mmc_blk_data *md,
2155 unsigned int part_type,
2158 const char *subname,
2162 struct mmc_blk_data *part_md;
2164 part_md = mmc_blk_alloc_req(card, disk_to_dev(md->disk), size, default_ro,
2165 subname, area_type);
2166 if (IS_ERR(part_md))
2167 return PTR_ERR(part_md);
2168 part_md->part_type = part_type;
2169 list_add(&part_md->part, &md->part);
2171 string_get_size((u64)get_capacity(part_md->disk) << 9, STRING_UNITS_2,
2172 cap_str, sizeof(cap_str));
2173 pr_info("%s: %s %s partition %u %s\n",
2174 part_md->disk->disk_name, mmc_card_id(card),
2175 mmc_card_name(card), part_md->part_type, cap_str);
2179 /* MMC Physical partitions consist of two boot partitions and
2180 * up to four general purpose partitions.
2181 * For each partition enabled in EXT_CSD a block device will be allocatedi
2182 * to provide access to the partition.
2185 static int mmc_blk_alloc_parts(struct mmc_card *card, struct mmc_blk_data *md)
2189 if (!mmc_card_mmc(card))
2192 for (idx = 0; idx < card->nr_parts; idx++) {
2193 if (card->part[idx].size) {
2194 ret = mmc_blk_alloc_part(card, md,
2195 card->part[idx].part_cfg,
2196 card->part[idx].size >> 9,
2197 card->part[idx].force_ro,
2198 card->part[idx].name,
2199 card->part[idx].area_type);
2208 static void mmc_blk_remove_req(struct mmc_blk_data *md)
2210 struct mmc_card *card;
2213 card = md->queue.card;
2214 if (md->disk->flags & GENHD_FL_UP) {
2215 device_remove_file(disk_to_dev(md->disk), &md->force_ro);
2216 if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
2217 card->ext_csd.boot_ro_lockable)
2218 device_remove_file(disk_to_dev(md->disk),
2219 &md->power_ro_lock);
2221 /* Stop new requests from getting into the queue */
2222 del_gendisk(md->disk);
2225 /* Then flush out any already in there */
2226 mmc_cleanup_queue(&md->queue);
2227 if (md->flags & MMC_BLK_PACKED_CMD)
2228 mmc_packed_clean(&md->queue);
2233 static void mmc_blk_remove_parts(struct mmc_card *card,
2234 struct mmc_blk_data *md)
2236 struct list_head *pos, *q;
2237 struct mmc_blk_data *part_md;
2239 __clear_bit(md->name_idx, name_use);
2240 list_for_each_safe(pos, q, &md->part) {
2241 part_md = list_entry(pos, struct mmc_blk_data, part);
2243 mmc_blk_remove_req(part_md);
2247 static int mmc_add_disk(struct mmc_blk_data *md)
2250 struct mmc_card *card = md->queue.card;
2253 md->force_ro.show = force_ro_show;
2254 md->force_ro.store = force_ro_store;
2255 sysfs_attr_init(&md->force_ro.attr);
2256 md->force_ro.attr.name = "force_ro";
2257 md->force_ro.attr.mode = S_IRUGO | S_IWUSR;
2258 ret = device_create_file(disk_to_dev(md->disk), &md->force_ro);
2262 if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
2263 card->ext_csd.boot_ro_lockable) {
2266 if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PWR_WP_DIS)
2269 mode = S_IRUGO | S_IWUSR;
2271 md->power_ro_lock.show = power_ro_lock_show;
2272 md->power_ro_lock.store = power_ro_lock_store;
2273 sysfs_attr_init(&md->power_ro_lock.attr);
2274 md->power_ro_lock.attr.mode = mode;
2275 md->power_ro_lock.attr.name =
2276 "ro_lock_until_next_power_on";
2277 ret = device_create_file(disk_to_dev(md->disk),
2278 &md->power_ro_lock);
2280 goto power_ro_lock_fail;
2285 device_remove_file(disk_to_dev(md->disk), &md->force_ro);
2287 del_gendisk(md->disk);
2292 #define CID_MANFID_SANDISK 0x2
2293 #define CID_MANFID_TOSHIBA 0x11
2294 #define CID_MANFID_MICRON 0x13
2295 #define CID_MANFID_SAMSUNG 0x15
2297 static const struct mmc_fixup blk_fixups[] =
2299 MMC_FIXUP("SEM02G", CID_MANFID_SANDISK, 0x100, add_quirk,
2300 MMC_QUIRK_INAND_CMD38),
2301 MMC_FIXUP("SEM04G", CID_MANFID_SANDISK, 0x100, add_quirk,
2302 MMC_QUIRK_INAND_CMD38),
2303 MMC_FIXUP("SEM08G", CID_MANFID_SANDISK, 0x100, add_quirk,
2304 MMC_QUIRK_INAND_CMD38),
2305 MMC_FIXUP("SEM16G", CID_MANFID_SANDISK, 0x100, add_quirk,
2306 MMC_QUIRK_INAND_CMD38),
2307 MMC_FIXUP("SEM32G", CID_MANFID_SANDISK, 0x100, add_quirk,
2308 MMC_QUIRK_INAND_CMD38),
2311 * Some MMC cards experience performance degradation with CMD23
2312 * instead of CMD12-bounded multiblock transfers. For now we'll
2313 * black list what's bad...
2314 * - Certain Toshiba cards.
2316 * N.B. This doesn't affect SD cards.
2318 MMC_FIXUP("MMC08G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
2319 MMC_QUIRK_BLK_NO_CMD23),
2320 MMC_FIXUP("MMC16G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
2321 MMC_QUIRK_BLK_NO_CMD23),
2322 MMC_FIXUP("MMC32G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
2323 MMC_QUIRK_BLK_NO_CMD23),
2326 * Some Micron MMC cards needs longer data read timeout than
2329 MMC_FIXUP(CID_NAME_ANY, CID_MANFID_MICRON, 0x200, add_quirk_mmc,
2330 MMC_QUIRK_LONG_READ_TIME),
2333 * On these Samsung MoviNAND parts, performing secure erase or
2334 * secure trim can result in unrecoverable corruption due to a
2337 MMC_FIXUP("M8G2FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2338 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2339 MMC_FIXUP("MAG4FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2340 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2341 MMC_FIXUP("MBG8FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2342 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2343 MMC_FIXUP("MCGAFA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2344 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2345 MMC_FIXUP("VAL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2346 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2347 MMC_FIXUP("VYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2348 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2349 MMC_FIXUP("KYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2350 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2351 MMC_FIXUP("VZL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
2352 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
2357 static int mmc_blk_probe(struct mmc_card *card)
2359 struct mmc_blk_data *md, *part_md;
2363 * Check that the card supports the command class(es) we need.
2365 if (!(card->csd.cmdclass & CCC_BLOCK_READ))
2368 md = mmc_blk_alloc(card);
2372 string_get_size((u64)get_capacity(md->disk) << 9, STRING_UNITS_2,
2373 cap_str, sizeof(cap_str));
2374 pr_info("%s: %s %s %s %s\n",
2375 md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
2376 cap_str, md->read_only ? "(ro)" : "");
2378 if (mmc_blk_alloc_parts(card, md))
2381 mmc_set_drvdata(card, md);
2382 mmc_fixup_device(card, blk_fixups);
2384 #ifdef CONFIG_MMC_BLOCK_DEFERRED_RESUME
2385 mmc_set_bus_resume_policy(card->host, 1);
2387 if (mmc_add_disk(md))
2390 list_for_each_entry(part_md, &md->part, part) {
2391 if (mmc_add_disk(part_md))
2397 mmc_blk_remove_parts(card, md);
2398 mmc_blk_remove_req(md);
2402 static void mmc_blk_remove(struct mmc_card *card)
2404 struct mmc_blk_data *md = mmc_get_drvdata(card);
2406 mmc_blk_remove_parts(card, md);
2407 mmc_claim_host(card->host);
2408 mmc_blk_part_switch(card, md);
2409 mmc_release_host(card->host);
2410 mmc_blk_remove_req(md);
2411 mmc_set_drvdata(card, NULL);
2412 #ifdef CONFIG_MMC_BLOCK_DEFERRED_RESUME
2413 mmc_set_bus_resume_policy(card->host, 0);
2418 static int mmc_blk_suspend(struct mmc_card *card)
2420 struct mmc_blk_data *part_md;
2421 struct mmc_blk_data *md = mmc_get_drvdata(card);
2424 mmc_queue_suspend(&md->queue);
2425 list_for_each_entry(part_md, &md->part, part) {
2426 mmc_queue_suspend(&part_md->queue);
2432 static int mmc_blk_resume(struct mmc_card *card)
2434 struct mmc_blk_data *part_md;
2435 struct mmc_blk_data *md = mmc_get_drvdata(card);
2439 * Resume involves the card going into idle state,
2440 * so current partition is always the main one.
2442 md->part_curr = md->part_type;
2443 mmc_queue_resume(&md->queue);
2444 list_for_each_entry(part_md, &md->part, part) {
2445 mmc_queue_resume(&part_md->queue);
2451 #define mmc_blk_suspend NULL
2452 #define mmc_blk_resume NULL
2455 static struct mmc_driver mmc_driver = {
2459 .probe = mmc_blk_probe,
2460 .remove = mmc_blk_remove,
2461 .suspend = mmc_blk_suspend,
2462 .resume = mmc_blk_resume,
2465 static int __init mmc_blk_init(void)
2469 if (perdev_minors != CONFIG_MMC_BLOCK_MINORS)
2470 pr_info("mmcblk: using %d minors per device\n", perdev_minors);
2472 max_devices = 256 / perdev_minors;
2474 res = register_blkdev(MMC_BLOCK_MAJOR, "mmc");
2478 res = mmc_register_driver(&mmc_driver);
2484 unregister_blkdev(MMC_BLOCK_MAJOR, "mmc");
2489 static void __exit mmc_blk_exit(void)
2491 mmc_unregister_driver(&mmc_driver);
2492 unregister_blkdev(MMC_BLOCK_MAJOR, "mmc");
2495 module_init(mmc_blk_init);
2496 module_exit(mmc_blk_exit);
2498 MODULE_LICENSE("GPL");
2499 MODULE_DESCRIPTION("Multimedia Card (MMC) block device driver");