Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Block driver for media (i.e., flash cards) |
| 3 | * |
| 4 | * Copyright 2002 Hewlett-Packard Company |
Pierre Ossman | 979ce72 | 2008-06-29 12:19:47 +0200 | [diff] [blame] | 5 | * Copyright 2005-2008 Pierre Ossman |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 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. |
| 10 | * |
| 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. |
| 14 | * |
| 15 | * Many thanks to Alessandro Rubini and Jonathan Corbet! |
| 16 | * |
| 17 | * Author: Andrew Christian |
| 18 | * 28 May 2002 |
| 19 | */ |
| 20 | #include <linux/moduleparam.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/init.h> |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/kernel.h> |
| 25 | #include <linux/fs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/errno.h> |
| 28 | #include <linux/hdreg.h> |
| 29 | #include <linux/kdev_t.h> |
| 30 | #include <linux/blkdev.h> |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 31 | #include <linux/mutex.h> |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 32 | #include <linux/scatterlist.h> |
Pierre Ossman | a7bbb57 | 2008-09-06 10:57:57 +0200 | [diff] [blame] | 33 | #include <linux/string_helpers.h> |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 34 | #include <linux/delay.h> |
| 35 | #include <linux/capability.h> |
| 36 | #include <linux/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 38 | #include <linux/mmc/ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/mmc/card.h> |
Pierre Ossman | 385e3227 | 2006-06-18 14:34:37 +0200 | [diff] [blame] | 40 | #include <linux/mmc/host.h> |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 41 | #include <linux/mmc/mmc.h> |
| 42 | #include <linux/mmc/sd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <asm/uaccess.h> |
| 45 | |
Pierre Ossman | 98ac216 | 2006-12-23 20:03:02 +0100 | [diff] [blame] | 46 | #include "queue.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Andy Whitcroft | 6b0b628 | 2009-02-23 12:38:41 +0000 | [diff] [blame] | 48 | MODULE_ALIAS("mmc:block"); |
Olof Johansson | 5e71b7a | 2010-09-17 21:19:57 -0400 | [diff] [blame] | 49 | #ifdef MODULE_PARAM_PREFIX |
| 50 | #undef MODULE_PARAM_PREFIX |
| 51 | #endif |
| 52 | #define MODULE_PARAM_PREFIX "mmcblk." |
David Woodhouse | 1dff314 | 2007-11-21 18:45:12 +0100 | [diff] [blame] | 53 | |
Andrei Warkentin | 6a7a6b4 | 2011-04-12 15:06:53 -0500 | [diff] [blame] | 54 | #define INAND_CMD38_ARG_EXT_CSD 113 |
| 55 | #define INAND_CMD38_ARG_ERASE 0x00 |
| 56 | #define INAND_CMD38_ARG_TRIM 0x01 |
| 57 | #define INAND_CMD38_ARG_SECERASE 0x80 |
| 58 | #define INAND_CMD38_ARG_SECTRIM1 0x81 |
| 59 | #define INAND_CMD38_ARG_SECTRIM2 0x88 |
Trey Ramsay | 8fee476 | 2012-11-16 09:31:41 -0600 | [diff] [blame] | 60 | #define MMC_BLK_TIMEOUT_MS (10 * 60 * 1000) /* 10 minute timeout */ |
Andrei Warkentin | 6a7a6b4 | 2011-04-12 15:06:53 -0500 | [diff] [blame] | 61 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 62 | static DEFINE_MUTEX(block_mutex); |
Olof Johansson | 5e71b7a | 2010-09-17 21:19:57 -0400 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * The defaults come from config options but can be overriden by module |
| 66 | * or bootarg options. |
| 67 | */ |
| 68 | static int perdev_minors = CONFIG_MMC_BLOCK_MINORS; |
| 69 | |
| 70 | /* |
| 71 | * We've only got one major, so number of mmcblk devices is |
| 72 | * limited to 256 / number of minors per device. |
| 73 | */ |
| 74 | static int max_devices; |
| 75 | |
| 76 | /* 256 minors, so at most 256 separate devices */ |
| 77 | static DECLARE_BITMAP(dev_use, 256); |
Andrei Warkentin | f06c915 | 2011-04-21 22:46:13 -0500 | [diff] [blame] | 78 | static DECLARE_BITMAP(name_use, 256); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* |
| 81 | * There is one mmc_blk_data per slot. |
| 82 | */ |
| 83 | struct mmc_blk_data { |
| 84 | spinlock_t lock; |
| 85 | struct gendisk *disk; |
| 86 | struct mmc_queue queue; |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 87 | struct list_head part; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 89 | unsigned int flags; |
| 90 | #define MMC_BLK_CMD23 (1 << 0) /* Can do SET_BLOCK_COUNT for multiblock */ |
| 91 | #define MMC_BLK_REL_WR (1 << 1) /* MMC Reliable write support */ |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | unsigned int usage; |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 94 | unsigned int read_only; |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 95 | unsigned int part_type; |
Andrei Warkentin | f06c915 | 2011-04-21 22:46:13 -0500 | [diff] [blame] | 96 | unsigned int name_idx; |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 97 | unsigned int reset_done; |
| 98 | #define MMC_BLK_READ BIT(0) |
| 99 | #define MMC_BLK_WRITE BIT(1) |
| 100 | #define MMC_BLK_DISCARD BIT(2) |
| 101 | #define MMC_BLK_SECDISCARD BIT(3) |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 102 | |
| 103 | /* |
| 104 | * Only set in main mmc_blk_data associated |
| 105 | * with mmc_card with mmc_set_drvdata, and keeps |
| 106 | * track of the current selected device partition. |
| 107 | */ |
| 108 | unsigned int part_curr; |
| 109 | struct device_attribute force_ro; |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 110 | struct device_attribute power_ro_lock; |
| 111 | int area_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 114 | static DEFINE_MUTEX(open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 116 | enum mmc_blk_status { |
| 117 | MMC_BLK_SUCCESS = 0, |
| 118 | MMC_BLK_PARTIAL, |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 119 | MMC_BLK_CMD_ERR, |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 120 | MMC_BLK_RETRY, |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 121 | MMC_BLK_ABORT, |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 122 | MMC_BLK_DATA_ERR, |
| 123 | MMC_BLK_ECC_ERR, |
Sujit Reddy Thumma | a8ad82cc | 2011-12-08 14:05:50 +0530 | [diff] [blame] | 124 | MMC_BLK_NOMEDIUM, |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 125 | }; |
| 126 | |
Olof Johansson | 5e71b7a | 2010-09-17 21:19:57 -0400 | [diff] [blame] | 127 | module_param(perdev_minors, int, 0444); |
| 128 | MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device"); |
| 129 | |
Loic Pallardy | 8d1e977 | 2012-08-06 17:12:31 +0200 | [diff] [blame^] | 130 | static inline int mmc_blk_part_switch(struct mmc_card *card, |
| 131 | struct mmc_blk_data *md); |
| 132 | static int get_card_status(struct mmc_card *card, u32 *status, int retries); |
| 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk) |
| 135 | { |
| 136 | struct mmc_blk_data *md; |
| 137 | |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 138 | mutex_lock(&open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | md = disk->private_data; |
| 140 | if (md && md->usage == 0) |
| 141 | md = NULL; |
| 142 | if (md) |
| 143 | md->usage++; |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 144 | mutex_unlock(&open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | return md; |
| 147 | } |
| 148 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 149 | static inline int mmc_get_devidx(struct gendisk *disk) |
| 150 | { |
| 151 | int devmaj = MAJOR(disk_devt(disk)); |
| 152 | int devidx = MINOR(disk_devt(disk)) / perdev_minors; |
| 153 | |
| 154 | if (!devmaj) |
| 155 | devidx = disk->first_minor / perdev_minors; |
| 156 | return devidx; |
| 157 | } |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | static void mmc_blk_put(struct mmc_blk_data *md) |
| 160 | { |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 161 | mutex_lock(&open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | md->usage--; |
| 163 | if (md->usage == 0) { |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 164 | int devidx = mmc_get_devidx(md->disk); |
Adrian Hunter | 5fa83ce | 2010-01-08 14:43:00 -0800 | [diff] [blame] | 165 | blk_cleanup_queue(md->queue.queue); |
| 166 | |
David Woodhouse | 1dff314 | 2007-11-21 18:45:12 +0100 | [diff] [blame] | 167 | __clear_bit(devidx, dev_use); |
| 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | put_disk(md->disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | kfree(md); |
| 171 | } |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 172 | mutex_unlock(&open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 175 | static ssize_t power_ro_lock_show(struct device *dev, |
| 176 | struct device_attribute *attr, char *buf) |
| 177 | { |
| 178 | int ret; |
| 179 | struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev)); |
| 180 | struct mmc_card *card = md->queue.card; |
| 181 | int locked = 0; |
| 182 | |
| 183 | if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PERM_WP_EN) |
| 184 | locked = 2; |
| 185 | else if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PWR_WP_EN) |
| 186 | locked = 1; |
| 187 | |
| 188 | ret = snprintf(buf, PAGE_SIZE, "%d\n", locked); |
| 189 | |
| 190 | return ret; |
| 191 | } |
| 192 | |
| 193 | static ssize_t power_ro_lock_store(struct device *dev, |
| 194 | struct device_attribute *attr, const char *buf, size_t count) |
| 195 | { |
| 196 | int ret; |
| 197 | struct mmc_blk_data *md, *part_md; |
| 198 | struct mmc_card *card; |
| 199 | unsigned long set; |
| 200 | |
| 201 | if (kstrtoul(buf, 0, &set)) |
| 202 | return -EINVAL; |
| 203 | |
| 204 | if (set != 1) |
| 205 | return count; |
| 206 | |
| 207 | md = mmc_blk_get(dev_to_disk(dev)); |
| 208 | card = md->queue.card; |
| 209 | |
| 210 | mmc_claim_host(card->host); |
| 211 | |
| 212 | ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_WP, |
| 213 | card->ext_csd.boot_ro_lock | |
| 214 | EXT_CSD_BOOT_WP_B_PWR_WP_EN, |
| 215 | card->ext_csd.part_time); |
| 216 | if (ret) |
| 217 | pr_err("%s: Locking boot partition ro until next power on failed: %d\n", md->disk->disk_name, ret); |
| 218 | else |
| 219 | card->ext_csd.boot_ro_lock |= EXT_CSD_BOOT_WP_B_PWR_WP_EN; |
| 220 | |
| 221 | mmc_release_host(card->host); |
| 222 | |
| 223 | if (!ret) { |
| 224 | pr_info("%s: Locking boot partition ro until next power on\n", |
| 225 | md->disk->disk_name); |
| 226 | set_disk_ro(md->disk, 1); |
| 227 | |
| 228 | list_for_each_entry(part_md, &md->part, part) |
| 229 | if (part_md->area_type == MMC_BLK_DATA_AREA_BOOT) { |
| 230 | pr_info("%s: Locking boot partition ro until next power on\n", part_md->disk->disk_name); |
| 231 | set_disk_ro(part_md->disk, 1); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | mmc_blk_put(md); |
| 236 | return count; |
| 237 | } |
| 238 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 239 | static ssize_t force_ro_show(struct device *dev, struct device_attribute *attr, |
| 240 | char *buf) |
| 241 | { |
| 242 | int ret; |
| 243 | struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev)); |
| 244 | |
| 245 | ret = snprintf(buf, PAGE_SIZE, "%d", |
| 246 | get_disk_ro(dev_to_disk(dev)) ^ |
| 247 | md->read_only); |
| 248 | mmc_blk_put(md); |
| 249 | return ret; |
| 250 | } |
| 251 | |
| 252 | static ssize_t force_ro_store(struct device *dev, struct device_attribute *attr, |
| 253 | const char *buf, size_t count) |
| 254 | { |
| 255 | int ret; |
| 256 | char *end; |
| 257 | struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev)); |
| 258 | unsigned long set = simple_strtoul(buf, &end, 0); |
| 259 | if (end == buf) { |
| 260 | ret = -EINVAL; |
| 261 | goto out; |
| 262 | } |
| 263 | |
| 264 | set_disk_ro(dev_to_disk(dev), set || md->read_only); |
| 265 | ret = count; |
| 266 | out: |
| 267 | mmc_blk_put(md); |
| 268 | return ret; |
| 269 | } |
| 270 | |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 271 | static int mmc_blk_open(struct block_device *bdev, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | { |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 273 | struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | int ret = -ENXIO; |
| 275 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 276 | mutex_lock(&block_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | if (md) { |
| 278 | if (md->usage == 2) |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 279 | check_disk_change(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | ret = 0; |
Pierre Ossman | a00fc09 | 2005-09-06 15:18:52 -0700 | [diff] [blame] | 281 | |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 282 | if ((mode & FMODE_WRITE) && md->read_only) { |
Andrew Morton | 70bb089 | 2008-09-05 14:00:24 -0700 | [diff] [blame] | 283 | mmc_blk_put(md); |
Pierre Ossman | a00fc09 | 2005-09-06 15:18:52 -0700 | [diff] [blame] | 284 | ret = -EROFS; |
Andrew Morton | 70bb089 | 2008-09-05 14:00:24 -0700 | [diff] [blame] | 285 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 287 | mutex_unlock(&block_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
| 289 | return ret; |
| 290 | } |
| 291 | |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 292 | static int mmc_blk_release(struct gendisk *disk, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | { |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 294 | struct mmc_blk_data *md = disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 296 | mutex_lock(&block_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | mmc_blk_put(md); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 298 | mutex_unlock(&block_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | static int |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 303 | mmc_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 305 | geo->cylinders = get_capacity(bdev->bd_disk) / (4 * 16); |
| 306 | geo->heads = 4; |
| 307 | geo->sectors = 16; |
| 308 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
| 310 | |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 311 | struct mmc_blk_ioc_data { |
| 312 | struct mmc_ioc_cmd ic; |
| 313 | unsigned char *buf; |
| 314 | u64 buf_bytes; |
| 315 | }; |
| 316 | |
| 317 | static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user( |
| 318 | struct mmc_ioc_cmd __user *user) |
| 319 | { |
| 320 | struct mmc_blk_ioc_data *idata; |
| 321 | int err; |
| 322 | |
| 323 | idata = kzalloc(sizeof(*idata), GFP_KERNEL); |
| 324 | if (!idata) { |
| 325 | err = -ENOMEM; |
Vladimir Motyka | aea253e | 2011-05-11 00:00:43 -0400 | [diff] [blame] | 326 | goto out; |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | if (copy_from_user(&idata->ic, user, sizeof(idata->ic))) { |
| 330 | err = -EFAULT; |
Vladimir Motyka | aea253e | 2011-05-11 00:00:43 -0400 | [diff] [blame] | 331 | goto idata_err; |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | idata->buf_bytes = (u64) idata->ic.blksz * idata->ic.blocks; |
| 335 | if (idata->buf_bytes > MMC_IOC_MAX_BYTES) { |
| 336 | err = -EOVERFLOW; |
Vladimir Motyka | aea253e | 2011-05-11 00:00:43 -0400 | [diff] [blame] | 337 | goto idata_err; |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 338 | } |
| 339 | |
Johan Rudholm | 4d6144d | 2011-11-23 09:05:58 +0100 | [diff] [blame] | 340 | if (!idata->buf_bytes) |
| 341 | return idata; |
| 342 | |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 343 | idata->buf = kzalloc(idata->buf_bytes, GFP_KERNEL); |
| 344 | if (!idata->buf) { |
| 345 | err = -ENOMEM; |
Vladimir Motyka | aea253e | 2011-05-11 00:00:43 -0400 | [diff] [blame] | 346 | goto idata_err; |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | if (copy_from_user(idata->buf, (void __user *)(unsigned long) |
| 350 | idata->ic.data_ptr, idata->buf_bytes)) { |
| 351 | err = -EFAULT; |
| 352 | goto copy_err; |
| 353 | } |
| 354 | |
| 355 | return idata; |
| 356 | |
| 357 | copy_err: |
| 358 | kfree(idata->buf); |
Vladimir Motyka | aea253e | 2011-05-11 00:00:43 -0400 | [diff] [blame] | 359 | idata_err: |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 360 | kfree(idata); |
Vladimir Motyka | aea253e | 2011-05-11 00:00:43 -0400 | [diff] [blame] | 361 | out: |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 362 | return ERR_PTR(err); |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 363 | } |
| 364 | |
Loic Pallardy | 8d1e977 | 2012-08-06 17:12:31 +0200 | [diff] [blame^] | 365 | static int ioctl_rpmb_card_status_poll(struct mmc_card *card, u32 *status, |
| 366 | u32 retries_max) |
| 367 | { |
| 368 | int err; |
| 369 | u32 retry_count = 0; |
| 370 | |
| 371 | if (!status || !retries_max) |
| 372 | return -EINVAL; |
| 373 | |
| 374 | do { |
| 375 | err = get_card_status(card, status, 5); |
| 376 | if (err) |
| 377 | break; |
| 378 | |
| 379 | if (!R1_STATUS(*status) && |
| 380 | (R1_CURRENT_STATE(*status) != R1_STATE_PRG)) |
| 381 | break; /* RPMB programming operation complete */ |
| 382 | |
| 383 | /* |
| 384 | * Rechedule to give the MMC device a chance to continue |
| 385 | * processing the previous command without being polled too |
| 386 | * frequently. |
| 387 | */ |
| 388 | usleep_range(1000, 5000); |
| 389 | } while (++retry_count < retries_max); |
| 390 | |
| 391 | if (retry_count == retries_max) |
| 392 | err = -EPERM; |
| 393 | |
| 394 | return err; |
| 395 | } |
| 396 | |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 397 | static int mmc_blk_ioctl_cmd(struct block_device *bdev, |
| 398 | struct mmc_ioc_cmd __user *ic_ptr) |
| 399 | { |
| 400 | struct mmc_blk_ioc_data *idata; |
| 401 | struct mmc_blk_data *md; |
| 402 | struct mmc_card *card; |
| 403 | struct mmc_command cmd = {0}; |
| 404 | struct mmc_data data = {0}; |
Venkatraman S | ad5fd97 | 2011-08-25 00:30:50 +0530 | [diff] [blame] | 405 | struct mmc_request mrq = {NULL}; |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 406 | struct scatterlist sg; |
| 407 | int err; |
Loic Pallardy | 8d1e977 | 2012-08-06 17:12:31 +0200 | [diff] [blame^] | 408 | int is_rpmb = false; |
| 409 | u32 status = 0; |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 410 | |
| 411 | /* |
| 412 | * The caller must have CAP_SYS_RAWIO, and must be calling this on the |
| 413 | * whole block device, not on a partition. This prevents overspray |
| 414 | * between sibling partitions. |
| 415 | */ |
| 416 | if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains)) |
| 417 | return -EPERM; |
| 418 | |
| 419 | idata = mmc_blk_ioctl_copy_from_user(ic_ptr); |
| 420 | if (IS_ERR(idata)) |
| 421 | return PTR_ERR(idata); |
| 422 | |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 423 | md = mmc_blk_get(bdev->bd_disk); |
| 424 | if (!md) { |
| 425 | err = -EINVAL; |
Philippe De Swert | 1c02f00 | 2012-04-11 23:31:45 +0300 | [diff] [blame] | 426 | goto cmd_err; |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 427 | } |
| 428 | |
Loic Pallardy | 8d1e977 | 2012-08-06 17:12:31 +0200 | [diff] [blame^] | 429 | if (md->area_type & MMC_BLK_DATA_AREA_RPMB) |
| 430 | is_rpmb = true; |
| 431 | |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 432 | card = md->queue.card; |
| 433 | if (IS_ERR(card)) { |
| 434 | err = PTR_ERR(card); |
| 435 | goto cmd_done; |
| 436 | } |
| 437 | |
Johan Rudholm | 4d6144d | 2011-11-23 09:05:58 +0100 | [diff] [blame] | 438 | cmd.opcode = idata->ic.opcode; |
| 439 | cmd.arg = idata->ic.arg; |
| 440 | cmd.flags = idata->ic.flags; |
| 441 | |
| 442 | if (idata->buf_bytes) { |
| 443 | data.sg = &sg; |
| 444 | data.sg_len = 1; |
| 445 | data.blksz = idata->ic.blksz; |
| 446 | data.blocks = idata->ic.blocks; |
| 447 | |
| 448 | sg_init_one(data.sg, idata->buf, idata->buf_bytes); |
| 449 | |
| 450 | if (idata->ic.write_flag) |
| 451 | data.flags = MMC_DATA_WRITE; |
| 452 | else |
| 453 | data.flags = MMC_DATA_READ; |
| 454 | |
| 455 | /* data.flags must already be set before doing this. */ |
| 456 | mmc_set_data_timeout(&data, card); |
| 457 | |
| 458 | /* Allow overriding the timeout_ns for empirical tuning. */ |
| 459 | if (idata->ic.data_timeout_ns) |
| 460 | data.timeout_ns = idata->ic.data_timeout_ns; |
| 461 | |
| 462 | if ((cmd.flags & MMC_RSP_R1B) == MMC_RSP_R1B) { |
| 463 | /* |
| 464 | * Pretend this is a data transfer and rely on the |
| 465 | * host driver to compute timeout. When all host |
| 466 | * drivers support cmd.cmd_timeout for R1B, this |
| 467 | * can be changed to: |
| 468 | * |
| 469 | * mrq.data = NULL; |
| 470 | * cmd.cmd_timeout = idata->ic.cmd_timeout_ms; |
| 471 | */ |
| 472 | data.timeout_ns = idata->ic.cmd_timeout_ms * 1000000; |
| 473 | } |
| 474 | |
| 475 | mrq.data = &data; |
| 476 | } |
| 477 | |
| 478 | mrq.cmd = &cmd; |
| 479 | |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 480 | mmc_claim_host(card->host); |
| 481 | |
Loic Pallardy | 8d1e977 | 2012-08-06 17:12:31 +0200 | [diff] [blame^] | 482 | err = mmc_blk_part_switch(card, md); |
| 483 | if (err) |
| 484 | goto cmd_rel_host; |
| 485 | |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 486 | if (idata->ic.is_acmd) { |
| 487 | err = mmc_app_cmd(card->host, card); |
| 488 | if (err) |
| 489 | goto cmd_rel_host; |
| 490 | } |
| 491 | |
Loic Pallardy | 8d1e977 | 2012-08-06 17:12:31 +0200 | [diff] [blame^] | 492 | if (is_rpmb) { |
| 493 | err = mmc_set_blockcount(card, data.blocks, |
| 494 | idata->ic.write_flag & (1 << 31)); |
| 495 | if (err) |
| 496 | goto cmd_rel_host; |
| 497 | } |
| 498 | |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 499 | mmc_wait_for_req(card->host, &mrq); |
| 500 | |
| 501 | if (cmd.error) { |
| 502 | dev_err(mmc_dev(card->host), "%s: cmd error %d\n", |
| 503 | __func__, cmd.error); |
| 504 | err = cmd.error; |
| 505 | goto cmd_rel_host; |
| 506 | } |
| 507 | if (data.error) { |
| 508 | dev_err(mmc_dev(card->host), "%s: data error %d\n", |
| 509 | __func__, data.error); |
| 510 | err = data.error; |
| 511 | goto cmd_rel_host; |
| 512 | } |
| 513 | |
| 514 | /* |
| 515 | * According to the SD specs, some commands require a delay after |
| 516 | * issuing the command. |
| 517 | */ |
| 518 | if (idata->ic.postsleep_min_us) |
| 519 | usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us); |
| 520 | |
| 521 | if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) { |
| 522 | err = -EFAULT; |
| 523 | goto cmd_rel_host; |
| 524 | } |
| 525 | |
| 526 | if (!idata->ic.write_flag) { |
| 527 | if (copy_to_user((void __user *)(unsigned long) idata->ic.data_ptr, |
| 528 | idata->buf, idata->buf_bytes)) { |
| 529 | err = -EFAULT; |
| 530 | goto cmd_rel_host; |
| 531 | } |
| 532 | } |
| 533 | |
Loic Pallardy | 8d1e977 | 2012-08-06 17:12:31 +0200 | [diff] [blame^] | 534 | if (is_rpmb) { |
| 535 | /* |
| 536 | * Ensure RPMB command has completed by polling CMD13 |
| 537 | * "Send Status". |
| 538 | */ |
| 539 | err = ioctl_rpmb_card_status_poll(card, &status, 5); |
| 540 | if (err) |
| 541 | dev_err(mmc_dev(card->host), |
| 542 | "%s: Card Status=0x%08X, error %d\n", |
| 543 | __func__, status, err); |
| 544 | } |
| 545 | |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 546 | cmd_rel_host: |
| 547 | mmc_release_host(card->host); |
| 548 | |
| 549 | cmd_done: |
| 550 | mmc_blk_put(md); |
Philippe De Swert | 1c02f00 | 2012-04-11 23:31:45 +0300 | [diff] [blame] | 551 | cmd_err: |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 552 | kfree(idata->buf); |
| 553 | kfree(idata); |
| 554 | return err; |
| 555 | } |
| 556 | |
| 557 | static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode, |
| 558 | unsigned int cmd, unsigned long arg) |
| 559 | { |
| 560 | int ret = -EINVAL; |
| 561 | if (cmd == MMC_IOC_CMD) |
| 562 | ret = mmc_blk_ioctl_cmd(bdev, (struct mmc_ioc_cmd __user *)arg); |
| 563 | return ret; |
| 564 | } |
| 565 | |
| 566 | #ifdef CONFIG_COMPAT |
| 567 | static int mmc_blk_compat_ioctl(struct block_device *bdev, fmode_t mode, |
| 568 | unsigned int cmd, unsigned long arg) |
| 569 | { |
| 570 | return mmc_blk_ioctl(bdev, mode, cmd, (unsigned long) compat_ptr(arg)); |
| 571 | } |
| 572 | #endif |
| 573 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 574 | static const struct block_device_operations mmc_bdops = { |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 575 | .open = mmc_blk_open, |
| 576 | .release = mmc_blk_release, |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 577 | .getgeo = mmc_blk_getgeo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | .owner = THIS_MODULE, |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 579 | .ioctl = mmc_blk_ioctl, |
| 580 | #ifdef CONFIG_COMPAT |
| 581 | .compat_ioctl = mmc_blk_compat_ioctl, |
| 582 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | }; |
| 584 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 585 | static inline int mmc_blk_part_switch(struct mmc_card *card, |
| 586 | struct mmc_blk_data *md) |
| 587 | { |
| 588 | int ret; |
| 589 | struct mmc_blk_data *main_md = mmc_get_drvdata(card); |
Adrian Hunter | 0d7d85c | 2011-09-23 12:48:20 +0300 | [diff] [blame] | 590 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 591 | if (main_md->part_curr == md->part_type) |
| 592 | return 0; |
| 593 | |
| 594 | if (mmc_card_mmc(card)) { |
Adrian Hunter | 0d7d85c | 2011-09-23 12:48:20 +0300 | [diff] [blame] | 595 | u8 part_config = card->ext_csd.part_config; |
| 596 | |
| 597 | part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; |
| 598 | part_config |= md->part_type; |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 599 | |
| 600 | ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
Adrian Hunter | 0d7d85c | 2011-09-23 12:48:20 +0300 | [diff] [blame] | 601 | EXT_CSD_PART_CONFIG, part_config, |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 602 | card->ext_csd.part_time); |
| 603 | if (ret) |
| 604 | return ret; |
Adrian Hunter | 0d7d85c | 2011-09-23 12:48:20 +0300 | [diff] [blame] | 605 | |
| 606 | card->ext_csd.part_config = part_config; |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 607 | } |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 608 | |
| 609 | main_md->part_curr = md->part_type; |
| 610 | return 0; |
| 611 | } |
| 612 | |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 613 | static u32 mmc_sd_num_wr_blocks(struct mmc_card *card) |
| 614 | { |
| 615 | int err; |
Ben Dooks | 051913d | 2009-06-08 23:33:57 +0100 | [diff] [blame] | 616 | u32 result; |
| 617 | __be32 *blocks; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 618 | |
Venkatraman S | ad5fd97 | 2011-08-25 00:30:50 +0530 | [diff] [blame] | 619 | struct mmc_request mrq = {NULL}; |
Chris Ball | 1278dba | 2011-04-13 23:40:30 -0400 | [diff] [blame] | 620 | struct mmc_command cmd = {0}; |
Chris Ball | a61ad2b | 2011-04-13 23:46:05 -0400 | [diff] [blame] | 621 | struct mmc_data data = {0}; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 622 | |
| 623 | struct scatterlist sg; |
| 624 | |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 625 | cmd.opcode = MMC_APP_CMD; |
| 626 | cmd.arg = card->rca << 16; |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 627 | cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 628 | |
| 629 | err = mmc_wait_for_cmd(card->host, &cmd, 0); |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 630 | if (err) |
| 631 | return (u32)-1; |
| 632 | if (!mmc_host_is_spi(card->host) && !(cmd.resp[0] & R1_APP_CMD)) |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 633 | return (u32)-1; |
| 634 | |
| 635 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 636 | |
| 637 | cmd.opcode = SD_APP_SEND_NUM_WR_BLKS; |
| 638 | cmd.arg = 0; |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 639 | cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 640 | |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 641 | data.blksz = 4; |
| 642 | data.blocks = 1; |
| 643 | data.flags = MMC_DATA_READ; |
| 644 | data.sg = &sg; |
| 645 | data.sg_len = 1; |
Subhash Jadavani | d380443 | 2012-06-13 17:10:43 +0530 | [diff] [blame] | 646 | mmc_set_data_timeout(&data, card); |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 647 | |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 648 | mrq.cmd = &cmd; |
| 649 | mrq.data = &data; |
| 650 | |
Ben Dooks | 051913d | 2009-06-08 23:33:57 +0100 | [diff] [blame] | 651 | blocks = kmalloc(4, GFP_KERNEL); |
| 652 | if (!blocks) |
| 653 | return (u32)-1; |
| 654 | |
| 655 | sg_init_one(&sg, blocks, 4); |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 656 | |
| 657 | mmc_wait_for_req(card->host, &mrq); |
| 658 | |
Ben Dooks | 051913d | 2009-06-08 23:33:57 +0100 | [diff] [blame] | 659 | result = ntohl(*blocks); |
| 660 | kfree(blocks); |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 661 | |
Ben Dooks | 051913d | 2009-06-08 23:33:57 +0100 | [diff] [blame] | 662 | if (cmd.error || data.error) |
| 663 | result = (u32)-1; |
| 664 | |
| 665 | return result; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Russell King - ARM Linux | a01f3cc | 2011-06-20 20:10:28 +0100 | [diff] [blame] | 668 | static int send_stop(struct mmc_card *card, u32 *status) |
| 669 | { |
| 670 | struct mmc_command cmd = {0}; |
| 671 | int err; |
| 672 | |
| 673 | cmd.opcode = MMC_STOP_TRANSMISSION; |
| 674 | cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; |
| 675 | err = mmc_wait_for_cmd(card->host, &cmd, 5); |
| 676 | if (err == 0) |
| 677 | *status = cmd.resp[0]; |
| 678 | return err; |
| 679 | } |
| 680 | |
Russell King - ARM Linux | 0a2d404 | 2011-06-20 20:10:08 +0100 | [diff] [blame] | 681 | static int get_card_status(struct mmc_card *card, u32 *status, int retries) |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 682 | { |
Chris Ball | 1278dba | 2011-04-13 23:40:30 -0400 | [diff] [blame] | 683 | struct mmc_command cmd = {0}; |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 684 | int err; |
| 685 | |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 686 | cmd.opcode = MMC_SEND_STATUS; |
| 687 | if (!mmc_host_is_spi(card->host)) |
| 688 | cmd.arg = card->rca << 16; |
| 689 | cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC; |
Russell King - ARM Linux | 0a2d404 | 2011-06-20 20:10:08 +0100 | [diff] [blame] | 690 | err = mmc_wait_for_cmd(card->host, &cmd, retries); |
| 691 | if (err == 0) |
| 692 | *status = cmd.resp[0]; |
| 693 | return err; |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 694 | } |
| 695 | |
Sujit Reddy Thumma | a8ad82cc | 2011-12-08 14:05:50 +0530 | [diff] [blame] | 696 | #define ERR_NOMEDIUM 3 |
Russell King - ARM Linux | a01f3cc | 2011-06-20 20:10:28 +0100 | [diff] [blame] | 697 | #define ERR_RETRY 2 |
| 698 | #define ERR_ABORT 1 |
| 699 | #define ERR_CONTINUE 0 |
| 700 | |
| 701 | static int mmc_blk_cmd_error(struct request *req, const char *name, int error, |
| 702 | bool status_valid, u32 status) |
| 703 | { |
| 704 | switch (error) { |
| 705 | case -EILSEQ: |
| 706 | /* response crc error, retry the r/w cmd */ |
| 707 | pr_err("%s: %s sending %s command, card status %#x\n", |
| 708 | req->rq_disk->disk_name, "response CRC error", |
| 709 | name, status); |
| 710 | return ERR_RETRY; |
| 711 | |
| 712 | case -ETIMEDOUT: |
| 713 | pr_err("%s: %s sending %s command, card status %#x\n", |
| 714 | req->rq_disk->disk_name, "timed out", name, status); |
| 715 | |
| 716 | /* If the status cmd initially failed, retry the r/w cmd */ |
| 717 | if (!status_valid) |
| 718 | return ERR_RETRY; |
| 719 | |
| 720 | /* |
| 721 | * If it was a r/w cmd crc error, or illegal command |
| 722 | * (eg, issued in wrong state) then retry - we should |
| 723 | * have corrected the state problem above. |
| 724 | */ |
| 725 | if (status & (R1_COM_CRC_ERROR | R1_ILLEGAL_COMMAND)) |
| 726 | return ERR_RETRY; |
| 727 | |
| 728 | /* Otherwise abort the command */ |
| 729 | return ERR_ABORT; |
| 730 | |
| 731 | default: |
| 732 | /* We don't understand the error code the driver gave us */ |
| 733 | pr_err("%s: unknown error %d sending read/write command, card status %#x\n", |
| 734 | req->rq_disk->disk_name, error, status); |
| 735 | return ERR_ABORT; |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | /* |
| 740 | * Initial r/w and stop cmd error recovery. |
| 741 | * We don't know whether the card received the r/w cmd or not, so try to |
| 742 | * restore things back to a sane state. Essentially, we do this as follows: |
| 743 | * - Obtain card status. If the first attempt to obtain card status fails, |
| 744 | * the status word will reflect the failed status cmd, not the failed |
| 745 | * r/w cmd. If we fail to obtain card status, it suggests we can no |
| 746 | * longer communicate with the card. |
| 747 | * - Check the card state. If the card received the cmd but there was a |
| 748 | * transient problem with the response, it might still be in a data transfer |
| 749 | * mode. Try to send it a stop command. If this fails, we can't recover. |
| 750 | * - If the r/w cmd failed due to a response CRC error, it was probably |
| 751 | * transient, so retry the cmd. |
| 752 | * - If the r/w cmd timed out, but we didn't get the r/w cmd status, retry. |
| 753 | * - If the r/w cmd timed out, and the r/w cmd failed due to CRC error or |
| 754 | * illegal cmd, retry. |
| 755 | * Otherwise we don't understand what happened, so abort. |
| 756 | */ |
| 757 | static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req, |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 758 | struct mmc_blk_request *brq, int *ecc_err) |
Russell King - ARM Linux | a01f3cc | 2011-06-20 20:10:28 +0100 | [diff] [blame] | 759 | { |
| 760 | bool prev_cmd_status_valid = true; |
| 761 | u32 status, stop_status = 0; |
| 762 | int err, retry; |
| 763 | |
Sujit Reddy Thumma | a8ad82cc | 2011-12-08 14:05:50 +0530 | [diff] [blame] | 764 | if (mmc_card_removed(card)) |
| 765 | return ERR_NOMEDIUM; |
| 766 | |
Russell King - ARM Linux | a01f3cc | 2011-06-20 20:10:28 +0100 | [diff] [blame] | 767 | /* |
| 768 | * Try to get card status which indicates both the card state |
| 769 | * and why there was no response. If the first attempt fails, |
| 770 | * we can't be sure the returned status is for the r/w command. |
| 771 | */ |
| 772 | for (retry = 2; retry >= 0; retry--) { |
| 773 | err = get_card_status(card, &status, 0); |
| 774 | if (!err) |
| 775 | break; |
| 776 | |
| 777 | prev_cmd_status_valid = false; |
| 778 | pr_err("%s: error %d sending status command, %sing\n", |
| 779 | req->rq_disk->disk_name, err, retry ? "retry" : "abort"); |
| 780 | } |
| 781 | |
| 782 | /* We couldn't get a response from the card. Give up. */ |
Sujit Reddy Thumma | a8ad82cc | 2011-12-08 14:05:50 +0530 | [diff] [blame] | 783 | if (err) { |
| 784 | /* Check if the card is removed */ |
| 785 | if (mmc_detect_card_removed(card->host)) |
| 786 | return ERR_NOMEDIUM; |
Russell King - ARM Linux | a01f3cc | 2011-06-20 20:10:28 +0100 | [diff] [blame] | 787 | return ERR_ABORT; |
Sujit Reddy Thumma | a8ad82cc | 2011-12-08 14:05:50 +0530 | [diff] [blame] | 788 | } |
Russell King - ARM Linux | a01f3cc | 2011-06-20 20:10:28 +0100 | [diff] [blame] | 789 | |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 790 | /* Flag ECC errors */ |
| 791 | if ((status & R1_CARD_ECC_FAILED) || |
| 792 | (brq->stop.resp[0] & R1_CARD_ECC_FAILED) || |
| 793 | (brq->cmd.resp[0] & R1_CARD_ECC_FAILED)) |
| 794 | *ecc_err = 1; |
| 795 | |
Russell King - ARM Linux | a01f3cc | 2011-06-20 20:10:28 +0100 | [diff] [blame] | 796 | /* |
| 797 | * Check the current card state. If it is in some data transfer |
| 798 | * mode, tell it to stop (and hopefully transition back to TRAN.) |
| 799 | */ |
| 800 | if (R1_CURRENT_STATE(status) == R1_STATE_DATA || |
| 801 | R1_CURRENT_STATE(status) == R1_STATE_RCV) { |
| 802 | err = send_stop(card, &stop_status); |
| 803 | if (err) |
| 804 | pr_err("%s: error %d sending stop command\n", |
| 805 | req->rq_disk->disk_name, err); |
| 806 | |
| 807 | /* |
| 808 | * If the stop cmd also timed out, the card is probably |
| 809 | * not present, so abort. Other errors are bad news too. |
| 810 | */ |
| 811 | if (err) |
| 812 | return ERR_ABORT; |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 813 | if (stop_status & R1_CARD_ECC_FAILED) |
| 814 | *ecc_err = 1; |
Russell King - ARM Linux | a01f3cc | 2011-06-20 20:10:28 +0100 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /* Check for set block count errors */ |
| 818 | if (brq->sbc.error) |
| 819 | return mmc_blk_cmd_error(req, "SET_BLOCK_COUNT", brq->sbc.error, |
| 820 | prev_cmd_status_valid, status); |
| 821 | |
| 822 | /* Check for r/w command errors */ |
| 823 | if (brq->cmd.error) |
| 824 | return mmc_blk_cmd_error(req, "r/w cmd", brq->cmd.error, |
| 825 | prev_cmd_status_valid, status); |
| 826 | |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 827 | /* Data errors */ |
| 828 | if (!brq->stop.error) |
| 829 | return ERR_CONTINUE; |
| 830 | |
Russell King - ARM Linux | a01f3cc | 2011-06-20 20:10:28 +0100 | [diff] [blame] | 831 | /* Now for stop errors. These aren't fatal to the transfer. */ |
| 832 | pr_err("%s: error %d sending stop command, original cmd response %#x, card status %#x\n", |
| 833 | req->rq_disk->disk_name, brq->stop.error, |
| 834 | brq->cmd.resp[0], status); |
| 835 | |
| 836 | /* |
| 837 | * Subsitute in our own stop status as this will give the error |
| 838 | * state which happened during the execution of the r/w command. |
| 839 | */ |
| 840 | if (stop_status) { |
| 841 | brq->stop.resp[0] = stop_status; |
| 842 | brq->stop.error = 0; |
| 843 | } |
| 844 | return ERR_CONTINUE; |
| 845 | } |
| 846 | |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 847 | static int mmc_blk_reset(struct mmc_blk_data *md, struct mmc_host *host, |
| 848 | int type) |
| 849 | { |
| 850 | int err; |
| 851 | |
| 852 | if (md->reset_done & type) |
| 853 | return -EEXIST; |
| 854 | |
| 855 | md->reset_done |= type; |
| 856 | err = mmc_hw_reset(host); |
| 857 | /* Ensure we switch back to the correct partition */ |
| 858 | if (err != -EOPNOTSUPP) { |
| 859 | struct mmc_blk_data *main_md = mmc_get_drvdata(host->card); |
| 860 | int part_err; |
| 861 | |
| 862 | main_md->part_curr = main_md->part_type; |
| 863 | part_err = mmc_blk_part_switch(host->card, md); |
| 864 | if (part_err) { |
| 865 | /* |
| 866 | * We have failed to get back into the correct |
| 867 | * partition, so we need to abort the whole request. |
| 868 | */ |
| 869 | return -ENODEV; |
| 870 | } |
| 871 | } |
| 872 | return err; |
| 873 | } |
| 874 | |
| 875 | static inline void mmc_blk_reset_success(struct mmc_blk_data *md, int type) |
| 876 | { |
| 877 | md->reset_done &= ~type; |
| 878 | } |
| 879 | |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 880 | static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req) |
| 881 | { |
| 882 | struct mmc_blk_data *md = mq->data; |
| 883 | struct mmc_card *card = md->queue.card; |
| 884 | unsigned int from, nr, arg; |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 885 | int err = 0, type = MMC_BLK_DISCARD; |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 886 | |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 887 | if (!mmc_can_erase(card)) { |
| 888 | err = -EOPNOTSUPP; |
| 889 | goto out; |
| 890 | } |
| 891 | |
| 892 | from = blk_rq_pos(req); |
| 893 | nr = blk_rq_sectors(req); |
| 894 | |
Kyungmin Park | b3bf915 | 2011-10-18 09:34:04 +0900 | [diff] [blame] | 895 | if (mmc_can_discard(card)) |
| 896 | arg = MMC_DISCARD_ARG; |
| 897 | else if (mmc_can_trim(card)) |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 898 | arg = MMC_TRIM_ARG; |
| 899 | else |
| 900 | arg = MMC_ERASE_ARG; |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 901 | retry: |
Andrei Warkentin | 6a7a6b4 | 2011-04-12 15:06:53 -0500 | [diff] [blame] | 902 | if (card->quirks & MMC_QUIRK_INAND_CMD38) { |
| 903 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
| 904 | INAND_CMD38_ARG_EXT_CSD, |
| 905 | arg == MMC_TRIM_ARG ? |
| 906 | INAND_CMD38_ARG_TRIM : |
| 907 | INAND_CMD38_ARG_ERASE, |
| 908 | 0); |
| 909 | if (err) |
| 910 | goto out; |
| 911 | } |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 912 | err = mmc_erase(card, from, nr, arg); |
| 913 | out: |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 914 | if (err == -EIO && !mmc_blk_reset(md, card->host, type)) |
| 915 | goto retry; |
| 916 | if (!err) |
| 917 | mmc_blk_reset_success(md, type); |
Subhash Jadavani | ecf8b5d | 2012-06-07 15:46:58 +0530 | [diff] [blame] | 918 | blk_end_request(req, err, blk_rq_bytes(req)); |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 919 | |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 920 | return err ? 0 : 1; |
| 921 | } |
| 922 | |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 923 | static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq, |
| 924 | struct request *req) |
| 925 | { |
| 926 | struct mmc_blk_data *md = mq->data; |
| 927 | struct mmc_card *card = md->queue.card; |
Adrian Hunter | 2830281 | 2012-04-05 14:45:48 +0300 | [diff] [blame] | 928 | unsigned int from, nr, arg, trim_arg, erase_arg; |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 929 | int err = 0, type = MMC_BLK_SECDISCARD; |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 930 | |
Kyungmin Park | d9ddd62 | 2011-10-14 14:15:48 +0900 | [diff] [blame] | 931 | if (!(mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))) { |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 932 | err = -EOPNOTSUPP; |
| 933 | goto out; |
| 934 | } |
| 935 | |
| 936 | from = blk_rq_pos(req); |
| 937 | nr = blk_rq_sectors(req); |
| 938 | |
Adrian Hunter | 2830281 | 2012-04-05 14:45:48 +0300 | [diff] [blame] | 939 | /* The sanitize operation is supported at v4.5 only */ |
| 940 | if (mmc_can_sanitize(card)) { |
| 941 | erase_arg = MMC_ERASE_ARG; |
| 942 | trim_arg = MMC_TRIM_ARG; |
| 943 | } else { |
| 944 | erase_arg = MMC_SECURE_ERASE_ARG; |
| 945 | trim_arg = MMC_SECURE_TRIM1_ARG; |
| 946 | } |
| 947 | |
| 948 | if (mmc_erase_group_aligned(card, from, nr)) |
| 949 | arg = erase_arg; |
| 950 | else if (mmc_can_trim(card)) |
| 951 | arg = trim_arg; |
| 952 | else { |
| 953 | err = -EINVAL; |
| 954 | goto out; |
| 955 | } |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 956 | retry: |
Andrei Warkentin | 6a7a6b4 | 2011-04-12 15:06:53 -0500 | [diff] [blame] | 957 | if (card->quirks & MMC_QUIRK_INAND_CMD38) { |
| 958 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
| 959 | INAND_CMD38_ARG_EXT_CSD, |
| 960 | arg == MMC_SECURE_TRIM1_ARG ? |
| 961 | INAND_CMD38_ARG_SECTRIM1 : |
| 962 | INAND_CMD38_ARG_SECERASE, |
| 963 | 0); |
| 964 | if (err) |
Adrian Hunter | 2830281 | 2012-04-05 14:45:48 +0300 | [diff] [blame] | 965 | goto out_retry; |
Andrei Warkentin | 6a7a6b4 | 2011-04-12 15:06:53 -0500 | [diff] [blame] | 966 | } |
Adrian Hunter | 2830281 | 2012-04-05 14:45:48 +0300 | [diff] [blame] | 967 | |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 968 | err = mmc_erase(card, from, nr, arg); |
Adrian Hunter | 2830281 | 2012-04-05 14:45:48 +0300 | [diff] [blame] | 969 | if (err == -EIO) |
| 970 | goto out_retry; |
| 971 | if (err) |
| 972 | goto out; |
| 973 | |
| 974 | if (arg == MMC_SECURE_TRIM1_ARG) { |
Andrei Warkentin | 6a7a6b4 | 2011-04-12 15:06:53 -0500 | [diff] [blame] | 975 | if (card->quirks & MMC_QUIRK_INAND_CMD38) { |
| 976 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
| 977 | INAND_CMD38_ARG_EXT_CSD, |
| 978 | INAND_CMD38_ARG_SECTRIM2, |
| 979 | 0); |
| 980 | if (err) |
Adrian Hunter | 2830281 | 2012-04-05 14:45:48 +0300 | [diff] [blame] | 981 | goto out_retry; |
Andrei Warkentin | 6a7a6b4 | 2011-04-12 15:06:53 -0500 | [diff] [blame] | 982 | } |
Adrian Hunter | 2830281 | 2012-04-05 14:45:48 +0300 | [diff] [blame] | 983 | |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 984 | err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG); |
Adrian Hunter | 2830281 | 2012-04-05 14:45:48 +0300 | [diff] [blame] | 985 | if (err == -EIO) |
| 986 | goto out_retry; |
| 987 | if (err) |
| 988 | goto out; |
Andrei Warkentin | 6a7a6b4 | 2011-04-12 15:06:53 -0500 | [diff] [blame] | 989 | } |
Adrian Hunter | 2830281 | 2012-04-05 14:45:48 +0300 | [diff] [blame] | 990 | |
| 991 | if (mmc_can_sanitize(card)) |
| 992 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
| 993 | EXT_CSD_SANITIZE_START, 1, 0); |
| 994 | out_retry: |
| 995 | if (err && !mmc_blk_reset(md, card->host, type)) |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 996 | goto retry; |
| 997 | if (!err) |
| 998 | mmc_blk_reset_success(md, type); |
Adrian Hunter | 2830281 | 2012-04-05 14:45:48 +0300 | [diff] [blame] | 999 | out: |
Subhash Jadavani | ecf8b5d | 2012-06-07 15:46:58 +0530 | [diff] [blame] | 1000 | blk_end_request(req, err, blk_rq_bytes(req)); |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 1001 | |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 1002 | return err ? 0 : 1; |
| 1003 | } |
| 1004 | |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 1005 | static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req) |
| 1006 | { |
| 1007 | struct mmc_blk_data *md = mq->data; |
Seungwon Jeon | 881d1c2 | 2011-10-14 14:03:21 +0900 | [diff] [blame] | 1008 | struct mmc_card *card = md->queue.card; |
| 1009 | int ret = 0; |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 1010 | |
Seungwon Jeon | 881d1c2 | 2011-10-14 14:03:21 +0900 | [diff] [blame] | 1011 | ret = mmc_flush_cache(card); |
| 1012 | if (ret) |
| 1013 | ret = -EIO; |
| 1014 | |
Subhash Jadavani | ecf8b5d | 2012-06-07 15:46:58 +0530 | [diff] [blame] | 1015 | blk_end_request_all(req, ret); |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 1016 | |
Seungwon Jeon | 881d1c2 | 2011-10-14 14:03:21 +0900 | [diff] [blame] | 1017 | return ret ? 0 : 1; |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | /* |
| 1021 | * Reformat current write as a reliable write, supporting |
| 1022 | * both legacy and the enhanced reliable write MMC cards. |
| 1023 | * In each transfer we'll handle only as much as a single |
| 1024 | * reliable write can handle, thus finish the request in |
| 1025 | * partial completions. |
| 1026 | */ |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 1027 | static inline void mmc_apply_rel_rw(struct mmc_blk_request *brq, |
| 1028 | struct mmc_card *card, |
| 1029 | struct request *req) |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 1030 | { |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 1031 | if (!(card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN)) { |
| 1032 | /* Legacy mode imposes restrictions on transfers. */ |
| 1033 | if (!IS_ALIGNED(brq->cmd.arg, card->ext_csd.rel_sectors)) |
| 1034 | brq->data.blocks = 1; |
| 1035 | |
| 1036 | if (brq->data.blocks > card->ext_csd.rel_sectors) |
| 1037 | brq->data.blocks = card->ext_csd.rel_sectors; |
| 1038 | else if (brq->data.blocks < card->ext_csd.rel_sectors) |
| 1039 | brq->data.blocks = 1; |
| 1040 | } |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 1041 | } |
| 1042 | |
Russell King - ARM Linux | 4c2b8f2 | 2011-06-20 20:10:49 +0100 | [diff] [blame] | 1043 | #define CMD_ERRORS \ |
| 1044 | (R1_OUT_OF_RANGE | /* Command argument out of range */ \ |
| 1045 | R1_ADDRESS_ERROR | /* Misaligned address */ \ |
| 1046 | R1_BLOCK_LEN_ERROR | /* Transferred block length incorrect */\ |
| 1047 | R1_WP_VIOLATION | /* Tried to write to protected block */ \ |
| 1048 | R1_CC_ERROR | /* Card controller error */ \ |
| 1049 | R1_ERROR) /* General/unknown error */ |
| 1050 | |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1051 | static int mmc_blk_err_check(struct mmc_card *card, |
| 1052 | struct mmc_async_req *areq) |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1053 | { |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1054 | struct mmc_queue_req *mq_mrq = container_of(areq, struct mmc_queue_req, |
| 1055 | mmc_active); |
| 1056 | struct mmc_blk_request *brq = &mq_mrq->brq; |
| 1057 | struct request *req = mq_mrq->req; |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1058 | int ecc_err = 0; |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1059 | |
| 1060 | /* |
| 1061 | * sbc.error indicates a problem with the set block count |
| 1062 | * command. No data will have been transferred. |
| 1063 | * |
| 1064 | * cmd.error indicates a problem with the r/w command. No |
| 1065 | * data will have been transferred. |
| 1066 | * |
| 1067 | * stop.error indicates a problem with the stop command. Data |
| 1068 | * may have been transferred, or may still be transferring. |
| 1069 | */ |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1070 | if (brq->sbc.error || brq->cmd.error || brq->stop.error || |
| 1071 | brq->data.error) { |
| 1072 | switch (mmc_blk_cmd_recovery(card, req, brq, &ecc_err)) { |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1073 | case ERR_RETRY: |
| 1074 | return MMC_BLK_RETRY; |
| 1075 | case ERR_ABORT: |
| 1076 | return MMC_BLK_ABORT; |
Sujit Reddy Thumma | a8ad82cc | 2011-12-08 14:05:50 +0530 | [diff] [blame] | 1077 | case ERR_NOMEDIUM: |
| 1078 | return MMC_BLK_NOMEDIUM; |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1079 | case ERR_CONTINUE: |
| 1080 | break; |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | /* |
| 1085 | * Check for errors relating to the execution of the |
| 1086 | * initial command - such as address errors. No data |
| 1087 | * has been transferred. |
| 1088 | */ |
| 1089 | if (brq->cmd.resp[0] & CMD_ERRORS) { |
| 1090 | pr_err("%s: r/w command failed, status = %#x\n", |
| 1091 | req->rq_disk->disk_name, brq->cmd.resp[0]); |
| 1092 | return MMC_BLK_ABORT; |
| 1093 | } |
| 1094 | |
| 1095 | /* |
| 1096 | * Everything else is either success, or a data error of some |
| 1097 | * kind. If it was a write, we may have transitioned to |
| 1098 | * program mode, which we have to wait for it to complete. |
| 1099 | */ |
| 1100 | if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) { |
| 1101 | u32 status; |
Trey Ramsay | 8fee476 | 2012-11-16 09:31:41 -0600 | [diff] [blame] | 1102 | unsigned long timeout; |
| 1103 | |
| 1104 | timeout = jiffies + msecs_to_jiffies(MMC_BLK_TIMEOUT_MS); |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1105 | do { |
| 1106 | int err = get_card_status(card, &status, 5); |
| 1107 | if (err) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 1108 | pr_err("%s: error %d requesting status\n", |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1109 | req->rq_disk->disk_name, err); |
| 1110 | return MMC_BLK_CMD_ERR; |
| 1111 | } |
Trey Ramsay | 8fee476 | 2012-11-16 09:31:41 -0600 | [diff] [blame] | 1112 | |
| 1113 | /* Timeout if the device never becomes ready for data |
| 1114 | * and never leaves the program state. |
| 1115 | */ |
| 1116 | if (time_after(jiffies, timeout)) { |
| 1117 | pr_err("%s: Card stuck in programming state!"\ |
| 1118 | " %s %s\n", mmc_hostname(card->host), |
| 1119 | req->rq_disk->disk_name, __func__); |
| 1120 | |
| 1121 | return MMC_BLK_CMD_ERR; |
| 1122 | } |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1123 | /* |
| 1124 | * Some cards mishandle the status bits, |
| 1125 | * so make sure to check both the busy |
| 1126 | * indication and the card state. |
| 1127 | */ |
| 1128 | } while (!(status & R1_READY_FOR_DATA) || |
| 1129 | (R1_CURRENT_STATE(status) == R1_STATE_PRG)); |
| 1130 | } |
| 1131 | |
| 1132 | if (brq->data.error) { |
| 1133 | pr_err("%s: error %d transferring data, sector %u, nr %u, cmd response %#x, card status %#x\n", |
| 1134 | req->rq_disk->disk_name, brq->data.error, |
| 1135 | (unsigned)blk_rq_pos(req), |
| 1136 | (unsigned)blk_rq_sectors(req), |
| 1137 | brq->cmd.resp[0], brq->stop.resp[0]); |
| 1138 | |
| 1139 | if (rq_data_dir(req) == READ) { |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1140 | if (ecc_err) |
| 1141 | return MMC_BLK_ECC_ERR; |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1142 | return MMC_BLK_DATA_ERR; |
| 1143 | } else { |
| 1144 | return MMC_BLK_CMD_ERR; |
| 1145 | } |
| 1146 | } |
| 1147 | |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1148 | if (!brq->data.bytes_xfered) |
| 1149 | return MMC_BLK_RETRY; |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1150 | |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1151 | if (blk_rq_bytes(req) != brq->data.bytes_xfered) |
| 1152 | return MMC_BLK_PARTIAL; |
| 1153 | |
| 1154 | return MMC_BLK_SUCCESS; |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1155 | } |
| 1156 | |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1157 | static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq, |
| 1158 | struct mmc_card *card, |
| 1159 | int disable_multi, |
| 1160 | struct mmc_queue *mq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | { |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1162 | u32 readcmd, writecmd; |
| 1163 | struct mmc_blk_request *brq = &mqrq->brq; |
| 1164 | struct request *req = mqrq->req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | struct mmc_blk_data *md = mq->data; |
Saugata Das | 4265900 | 2011-12-21 13:09:17 +0530 | [diff] [blame] | 1166 | bool do_data_tag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 1168 | /* |
| 1169 | * Reliable writes are used to implement Forced Unit Access and |
| 1170 | * REQ_META accesses, and are supported only on MMCs. |
Christoph Hellwig | 65299a3 | 2011-08-23 14:50:29 +0200 | [diff] [blame] | 1171 | * |
| 1172 | * XXX: this really needs a good explanation of why REQ_META |
| 1173 | * is treated special. |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 1174 | */ |
| 1175 | bool do_rel_wr = ((req->cmd_flags & REQ_FUA) || |
| 1176 | (req->cmd_flags & REQ_META)) && |
| 1177 | (rq_data_dir(req) == WRITE) && |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 1178 | (md->flags & MMC_BLK_REL_WR); |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 1179 | |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1180 | memset(brq, 0, sizeof(struct mmc_blk_request)); |
| 1181 | brq->mrq.cmd = &brq->cmd; |
| 1182 | brq->mrq.data = &brq->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1184 | brq->cmd.arg = blk_rq_pos(req); |
| 1185 | if (!mmc_card_blockaddr(card)) |
| 1186 | brq->cmd.arg <<= 9; |
| 1187 | brq->cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; |
| 1188 | brq->data.blksz = 512; |
| 1189 | brq->stop.opcode = MMC_STOP_TRANSMISSION; |
| 1190 | brq->stop.arg = 0; |
| 1191 | brq->stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; |
| 1192 | brq->data.blocks = blk_rq_sectors(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1194 | /* |
| 1195 | * The block layer doesn't support all sector count |
| 1196 | * restrictions, so we need to be prepared for too big |
| 1197 | * requests. |
| 1198 | */ |
| 1199 | if (brq->data.blocks > card->host->max_blk_count) |
| 1200 | brq->data.blocks = card->host->max_blk_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | |
Paul Walmsley | 2bf22b3 | 2011-10-06 14:50:33 -0600 | [diff] [blame] | 1202 | if (brq->data.blocks > 1) { |
| 1203 | /* |
| 1204 | * After a read error, we redo the request one sector |
| 1205 | * at a time in order to accurately determine which |
| 1206 | * sectors can be read successfully. |
| 1207 | */ |
| 1208 | if (disable_multi) |
| 1209 | brq->data.blocks = 1; |
| 1210 | |
| 1211 | /* Some controllers can't do multiblock reads due to hw bugs */ |
| 1212 | if (card->host->caps2 & MMC_CAP2_NO_MULTI_READ && |
| 1213 | rq_data_dir(req) == READ) |
| 1214 | brq->data.blocks = 1; |
| 1215 | } |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1216 | |
| 1217 | if (brq->data.blocks > 1 || do_rel_wr) { |
| 1218 | /* SPI multiblock writes terminate using a special |
| 1219 | * token, not a STOP_TRANSMISSION request. |
Pierre Ossman | 548d2de | 2009-04-10 17:52:57 +0200 | [diff] [blame] | 1220 | */ |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1221 | if (!mmc_host_is_spi(card->host) || |
| 1222 | rq_data_dir(req) == READ) |
| 1223 | brq->mrq.stop = &brq->stop; |
| 1224 | readcmd = MMC_READ_MULTIPLE_BLOCK; |
| 1225 | writecmd = MMC_WRITE_MULTIPLE_BLOCK; |
| 1226 | } else { |
| 1227 | brq->mrq.stop = NULL; |
| 1228 | readcmd = MMC_READ_SINGLE_BLOCK; |
| 1229 | writecmd = MMC_WRITE_BLOCK; |
| 1230 | } |
| 1231 | if (rq_data_dir(req) == READ) { |
| 1232 | brq->cmd.opcode = readcmd; |
| 1233 | brq->data.flags |= MMC_DATA_READ; |
| 1234 | } else { |
| 1235 | brq->cmd.opcode = writecmd; |
| 1236 | brq->data.flags |= MMC_DATA_WRITE; |
| 1237 | } |
Pierre Ossman | 548d2de | 2009-04-10 17:52:57 +0200 | [diff] [blame] | 1238 | |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1239 | if (do_rel_wr) |
| 1240 | mmc_apply_rel_rw(brq, card, req); |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 1241 | |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1242 | /* |
Saugata Das | 4265900 | 2011-12-21 13:09:17 +0530 | [diff] [blame] | 1243 | * Data tag is used only during writing meta data to speed |
| 1244 | * up write and any subsequent read of this meta data |
| 1245 | */ |
| 1246 | do_data_tag = (card->ext_csd.data_tag_unit_size) && |
| 1247 | (req->cmd_flags & REQ_META) && |
| 1248 | (rq_data_dir(req) == WRITE) && |
| 1249 | ((brq->data.blocks * brq->data.blksz) >= |
| 1250 | card->ext_csd.data_tag_unit_size); |
| 1251 | |
| 1252 | /* |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1253 | * Pre-defined multi-block transfers are preferable to |
| 1254 | * open ended-ones (and necessary for reliable writes). |
| 1255 | * However, it is not sufficient to just send CMD23, |
| 1256 | * and avoid the final CMD12, as on an error condition |
| 1257 | * CMD12 (stop) needs to be sent anyway. This, coupled |
| 1258 | * with Auto-CMD23 enhancements provided by some |
| 1259 | * hosts, means that the complexity of dealing |
| 1260 | * with this is best left to the host. If CMD23 is |
| 1261 | * supported by card and host, we'll fill sbc in and let |
| 1262 | * the host deal with handling it correctly. This means |
| 1263 | * that for hosts that don't expose MMC_CAP_CMD23, no |
| 1264 | * change of behavior will be observed. |
| 1265 | * |
| 1266 | * N.B: Some MMC cards experience perf degradation. |
| 1267 | * We'll avoid using CMD23-bounded multiblock writes for |
| 1268 | * these, while retaining features like reliable writes. |
| 1269 | */ |
Saugata Das | 4265900 | 2011-12-21 13:09:17 +0530 | [diff] [blame] | 1270 | if ((md->flags & MMC_BLK_CMD23) && mmc_op_multi(brq->cmd.opcode) && |
| 1271 | (do_rel_wr || !(card->quirks & MMC_QUIRK_BLK_NO_CMD23) || |
| 1272 | do_data_tag)) { |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1273 | brq->sbc.opcode = MMC_SET_BLOCK_COUNT; |
| 1274 | brq->sbc.arg = brq->data.blocks | |
Saugata Das | 4265900 | 2011-12-21 13:09:17 +0530 | [diff] [blame] | 1275 | (do_rel_wr ? (1 << 31) : 0) | |
| 1276 | (do_data_tag ? (1 << 29) : 0); |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1277 | brq->sbc.flags = MMC_RSP_R1 | MMC_CMD_AC; |
| 1278 | brq->mrq.sbc = &brq->sbc; |
| 1279 | } |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 1280 | |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1281 | mmc_set_data_timeout(&brq->data, card); |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 1282 | |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1283 | brq->data.sg = mqrq->sg; |
| 1284 | brq->data.sg_len = mmc_queue_map_sg(mq, mqrq); |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 1285 | |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1286 | /* |
| 1287 | * Adjust the sg list so it is the same size as the |
| 1288 | * request. |
| 1289 | */ |
| 1290 | if (brq->data.blocks != blk_rq_sectors(req)) { |
| 1291 | int i, data_size = brq->data.blocks << 9; |
| 1292 | struct scatterlist *sg; |
Pierre Ossman | b146d26 | 2007-07-24 19:16:54 +0200 | [diff] [blame] | 1293 | |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1294 | for_each_sg(brq->data.sg, sg, brq->data.sg_len, i) { |
| 1295 | data_size -= sg->length; |
| 1296 | if (data_size <= 0) { |
| 1297 | sg->length += data_size; |
| 1298 | i++; |
| 1299 | break; |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 1300 | } |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 1301 | } |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1302 | brq->data.sg_len = i; |
| 1303 | } |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 1304 | |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1305 | mqrq->mmc_active.mrq = &brq->mrq; |
| 1306 | mqrq->mmc_active.err_check = mmc_blk_err_check; |
| 1307 | |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1308 | mmc_queue_bounce_pre(mqrq); |
| 1309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1311 | static int mmc_blk_cmd_err(struct mmc_blk_data *md, struct mmc_card *card, |
| 1312 | struct mmc_blk_request *brq, struct request *req, |
| 1313 | int ret) |
| 1314 | { |
| 1315 | /* |
| 1316 | * If this is an SD card and we're writing, we can first |
| 1317 | * mark the known good sectors as ok. |
| 1318 | * |
| 1319 | * If the card is not SD, we can still ok written sectors |
| 1320 | * as reported by the controller (which might be less than |
| 1321 | * the real number of written sectors, but never more). |
| 1322 | */ |
| 1323 | if (mmc_card_sd(card)) { |
| 1324 | u32 blocks; |
| 1325 | |
| 1326 | blocks = mmc_sd_num_wr_blocks(card); |
| 1327 | if (blocks != (u32)-1) { |
Subhash Jadavani | ecf8b5d | 2012-06-07 15:46:58 +0530 | [diff] [blame] | 1328 | ret = blk_end_request(req, 0, blocks << 9); |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1329 | } |
| 1330 | } else { |
Subhash Jadavani | ecf8b5d | 2012-06-07 15:46:58 +0530 | [diff] [blame] | 1331 | ret = blk_end_request(req, 0, brq->data.bytes_xfered); |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1332 | } |
| 1333 | return ret; |
| 1334 | } |
| 1335 | |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1336 | static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc) |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1337 | { |
| 1338 | struct mmc_blk_data *md = mq->data; |
| 1339 | struct mmc_card *card = md->queue.card; |
| 1340 | struct mmc_blk_request *brq = &mq->mqrq_cur->brq; |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1341 | int ret = 1, disable_multi = 0, retry = 0, type; |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1342 | enum mmc_blk_status status; |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1343 | struct mmc_queue_req *mq_rq; |
Saugata Das | a5075eb | 2012-05-17 16:32:21 +0530 | [diff] [blame] | 1344 | struct request *req = rqc; |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1345 | struct mmc_async_req *areq; |
| 1346 | |
| 1347 | if (!rqc && !mq->mqrq_prev->req) |
| 1348 | return 0; |
Per Forlin | 54d49d7 | 2011-07-01 18:55:29 +0200 | [diff] [blame] | 1349 | |
| 1350 | do { |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1351 | if (rqc) { |
Saugata Das | a5075eb | 2012-05-17 16:32:21 +0530 | [diff] [blame] | 1352 | /* |
| 1353 | * When 4KB native sector is enabled, only 8 blocks |
| 1354 | * multiple read or write is allowed |
| 1355 | */ |
| 1356 | if ((brq->data.blocks & 0x07) && |
| 1357 | (card->ext_csd.data_sector_size == 4096)) { |
| 1358 | pr_err("%s: Transfer size is not 4KB sector size aligned\n", |
| 1359 | req->rq_disk->disk_name); |
| 1360 | goto cmd_abort; |
| 1361 | } |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1362 | mmc_blk_rw_rq_prep(mq->mqrq_cur, card, 0, mq); |
| 1363 | areq = &mq->mqrq_cur->mmc_active; |
| 1364 | } else |
| 1365 | areq = NULL; |
| 1366 | areq = mmc_start_req(card->host, areq, (int *) &status); |
| 1367 | if (!areq) |
| 1368 | return 0; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 1369 | |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1370 | mq_rq = container_of(areq, struct mmc_queue_req, mmc_active); |
| 1371 | brq = &mq_rq->brq; |
| 1372 | req = mq_rq->req; |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1373 | type = rq_data_dir(req) == READ ? MMC_BLK_READ : MMC_BLK_WRITE; |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1374 | mmc_queue_bounce_post(mq_rq); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 1375 | |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1376 | switch (status) { |
| 1377 | case MMC_BLK_SUCCESS: |
| 1378 | case MMC_BLK_PARTIAL: |
| 1379 | /* |
| 1380 | * A block was successfully transferred. |
| 1381 | */ |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1382 | mmc_blk_reset_success(md, type); |
Subhash Jadavani | ecf8b5d | 2012-06-07 15:46:58 +0530 | [diff] [blame] | 1383 | ret = blk_end_request(req, 0, |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1384 | brq->data.bytes_xfered); |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1385 | /* |
| 1386 | * If the blk_end_request function returns non-zero even |
| 1387 | * though all data has been transferred and no errors |
| 1388 | * were returned by the host controller, it's a bug. |
| 1389 | */ |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1390 | if (status == MMC_BLK_SUCCESS && ret) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 1391 | pr_err("%s BUG rq_tot %d d_xfer %d\n", |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1392 | __func__, blk_rq_bytes(req), |
| 1393 | brq->data.bytes_xfered); |
| 1394 | rqc = NULL; |
| 1395 | goto cmd_abort; |
| 1396 | } |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1397 | break; |
| 1398 | case MMC_BLK_CMD_ERR: |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1399 | ret = mmc_blk_cmd_err(md, card, brq, req, ret); |
| 1400 | if (!mmc_blk_reset(md, card->host, type)) |
| 1401 | break; |
| 1402 | goto cmd_abort; |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1403 | case MMC_BLK_RETRY: |
| 1404 | if (retry++ < 5) |
Russell King - ARM Linux | a01f3cc | 2011-06-20 20:10:28 +0100 | [diff] [blame] | 1405 | break; |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1406 | /* Fall through */ |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1407 | case MMC_BLK_ABORT: |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1408 | if (!mmc_blk_reset(md, card->host, type)) |
| 1409 | break; |
Russell King - ARM Linux | 4c2b8f2 | 2011-06-20 20:10:49 +0100 | [diff] [blame] | 1410 | goto cmd_abort; |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1411 | case MMC_BLK_DATA_ERR: { |
| 1412 | int err; |
| 1413 | |
| 1414 | err = mmc_blk_reset(md, card->host, type); |
| 1415 | if (!err) |
| 1416 | break; |
| 1417 | if (err == -ENODEV) |
| 1418 | goto cmd_abort; |
| 1419 | /* Fall through */ |
| 1420 | } |
| 1421 | case MMC_BLK_ECC_ERR: |
| 1422 | if (brq->data.blocks > 1) { |
| 1423 | /* Redo read one sector at a time */ |
| 1424 | pr_warning("%s: retrying using single block read\n", |
| 1425 | req->rq_disk->disk_name); |
| 1426 | disable_multi = 1; |
| 1427 | break; |
| 1428 | } |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1429 | /* |
| 1430 | * After an error, we redo I/O one sector at a |
| 1431 | * time, so we only reach here after trying to |
| 1432 | * read a single sector. |
| 1433 | */ |
Subhash Jadavani | ecf8b5d | 2012-06-07 15:46:58 +0530 | [diff] [blame] | 1434 | ret = blk_end_request(req, -EIO, |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1435 | brq->data.blksz); |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1436 | if (!ret) |
| 1437 | goto start_new_req; |
Per Forlin | d78d4a8 | 2011-07-01 18:55:30 +0200 | [diff] [blame] | 1438 | break; |
Sujit Reddy Thumma | a8ad82cc | 2011-12-08 14:05:50 +0530 | [diff] [blame] | 1439 | case MMC_BLK_NOMEDIUM: |
| 1440 | goto cmd_abort; |
Russell King - ARM Linux | 4c2b8f2 | 2011-06-20 20:10:49 +0100 | [diff] [blame] | 1441 | } |
| 1442 | |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1443 | if (ret) { |
| 1444 | /* |
Adrian Hunter | 6771632 | 2011-08-29 16:42:15 +0300 | [diff] [blame] | 1445 | * In case of a incomplete request |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1446 | * prepare it again and resend. |
| 1447 | */ |
| 1448 | mmc_blk_rw_rq_prep(mq_rq, card, disable_multi, mq); |
| 1449 | mmc_start_req(card->host, &mq_rq->mmc_active, NULL); |
| 1450 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | } while (ret); |
| 1452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | return 1; |
| 1454 | |
Russell King - ARM Linux | a01f3cc | 2011-06-20 20:10:28 +0100 | [diff] [blame] | 1455 | cmd_abort: |
Sujit Reddy Thumma | a8ad82cc | 2011-12-08 14:05:50 +0530 | [diff] [blame] | 1456 | if (mmc_card_removed(card)) |
| 1457 | req->cmd_flags |= REQ_QUIET; |
Kiyoshi Ueda | fd53983 | 2007-12-11 17:48:29 -0500 | [diff] [blame] | 1458 | while (ret) |
Subhash Jadavani | ecf8b5d | 2012-06-07 15:46:58 +0530 | [diff] [blame] | 1459 | ret = blk_end_request(req, -EIO, blk_rq_cur_bytes(req)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1461 | start_new_req: |
| 1462 | if (rqc) { |
| 1463 | mmc_blk_rw_rq_prep(mq->mqrq_cur, card, 0, mq); |
| 1464 | mmc_start_req(card->host, &mq->mqrq_cur->mmc_active, NULL); |
| 1465 | } |
| 1466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | return 0; |
| 1468 | } |
| 1469 | |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 1470 | static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) |
| 1471 | { |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 1472 | int ret; |
| 1473 | struct mmc_blk_data *md = mq->data; |
| 1474 | struct mmc_card *card = md->queue.card; |
| 1475 | |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1476 | if (req && !mq->mqrq_prev->req) |
| 1477 | /* claim host only for the first request */ |
| 1478 | mmc_claim_host(card->host); |
| 1479 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1480 | ret = mmc_blk_part_switch(card, md); |
| 1481 | if (ret) { |
Adrian Hunter | 0d7d85c | 2011-09-23 12:48:20 +0300 | [diff] [blame] | 1482 | if (req) { |
Subhash Jadavani | ecf8b5d | 2012-06-07 15:46:58 +0530 | [diff] [blame] | 1483 | blk_end_request_all(req, -EIO); |
Adrian Hunter | 0d7d85c | 2011-09-23 12:48:20 +0300 | [diff] [blame] | 1484 | } |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1485 | ret = 0; |
| 1486 | goto out; |
| 1487 | } |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 1488 | |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1489 | if (req && req->cmd_flags & REQ_DISCARD) { |
| 1490 | /* complete ongoing async transfer before issuing discard */ |
| 1491 | if (card->host->areq) |
| 1492 | mmc_blk_issue_rw_rq(mq, NULL); |
Ian Chen | 3550ccd | 2012-08-29 15:05:36 +0900 | [diff] [blame] | 1493 | if (req->cmd_flags & REQ_SECURE && |
| 1494 | !(card->quirks & MMC_QUIRK_SEC_ERASE_TRIM_BROKEN)) |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 1495 | ret = mmc_blk_issue_secdiscard_rq(mq, req); |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 1496 | else |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 1497 | ret = mmc_blk_issue_discard_rq(mq, req); |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1498 | } else if (req && req->cmd_flags & REQ_FLUSH) { |
Jaehoon Chung | 393f9a0 | 2011-07-13 17:02:16 +0900 | [diff] [blame] | 1499 | /* complete ongoing async transfer before issuing flush */ |
| 1500 | if (card->host->areq) |
| 1501 | mmc_blk_issue_rw_rq(mq, NULL); |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 1502 | ret = mmc_blk_issue_flush(mq, req); |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 1503 | } else { |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 1504 | ret = mmc_blk_issue_rw_rq(mq, req); |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 1505 | } |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 1506 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1507 | out: |
Per Forlin | ee8a43a | 2011-07-01 18:55:33 +0200 | [diff] [blame] | 1508 | if (!req) |
| 1509 | /* release host only when there are no more requests */ |
| 1510 | mmc_release_host(card->host); |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 1511 | return ret; |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 1512 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1514 | static inline int mmc_blk_readonly(struct mmc_card *card) |
| 1515 | { |
| 1516 | return mmc_card_readonly(card) || |
| 1517 | !(card->csd.cmdclass & CCC_BLOCK_WRITE); |
| 1518 | } |
| 1519 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1520 | static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, |
| 1521 | struct device *parent, |
| 1522 | sector_t size, |
| 1523 | bool default_ro, |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 1524 | const char *subname, |
| 1525 | int area_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | { |
| 1527 | struct mmc_blk_data *md; |
| 1528 | int devidx, ret; |
| 1529 | |
Olof Johansson | 5e71b7a | 2010-09-17 21:19:57 -0400 | [diff] [blame] | 1530 | devidx = find_first_zero_bit(dev_use, max_devices); |
| 1531 | if (devidx >= max_devices) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | return ERR_PTR(-ENOSPC); |
| 1533 | __set_bit(devidx, dev_use); |
| 1534 | |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 1535 | md = kzalloc(sizeof(struct mmc_blk_data), GFP_KERNEL); |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1536 | if (!md) { |
| 1537 | ret = -ENOMEM; |
| 1538 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | } |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1540 | |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1541 | /* |
Andrei Warkentin | f06c915 | 2011-04-21 22:46:13 -0500 | [diff] [blame] | 1542 | * !subname implies we are creating main mmc_blk_data that will be |
| 1543 | * associated with mmc_card with mmc_set_drvdata. Due to device |
| 1544 | * partitions, devidx will not coincide with a per-physical card |
| 1545 | * index anymore so we keep track of a name index. |
| 1546 | */ |
| 1547 | if (!subname) { |
| 1548 | md->name_idx = find_first_zero_bit(name_use, max_devices); |
| 1549 | __set_bit(md->name_idx, name_use); |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 1550 | } else |
Andrei Warkentin | f06c915 | 2011-04-21 22:46:13 -0500 | [diff] [blame] | 1551 | md->name_idx = ((struct mmc_blk_data *) |
| 1552 | dev_to_disk(parent)->private_data)->name_idx; |
| 1553 | |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 1554 | md->area_type = area_type; |
| 1555 | |
Andrei Warkentin | f06c915 | 2011-04-21 22:46:13 -0500 | [diff] [blame] | 1556 | /* |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1557 | * Set the read-only status based on the supported commands |
| 1558 | * and the write protect switch. |
| 1559 | */ |
| 1560 | md->read_only = mmc_blk_readonly(card); |
| 1561 | |
Olof Johansson | 5e71b7a | 2010-09-17 21:19:57 -0400 | [diff] [blame] | 1562 | md->disk = alloc_disk(perdev_minors); |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1563 | if (md->disk == NULL) { |
| 1564 | ret = -ENOMEM; |
| 1565 | goto err_kfree; |
| 1566 | } |
| 1567 | |
| 1568 | spin_lock_init(&md->lock); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1569 | INIT_LIST_HEAD(&md->part); |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1570 | md->usage = 1; |
| 1571 | |
Adrian Hunter | d09408a | 2011-06-23 13:40:28 +0300 | [diff] [blame] | 1572 | ret = mmc_init_queue(&md->queue, card, &md->lock, subname); |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1573 | if (ret) |
| 1574 | goto err_putdisk; |
| 1575 | |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1576 | md->queue.issue_fn = mmc_blk_issue_rq; |
| 1577 | md->queue.data = md; |
| 1578 | |
Pierre Ossman | fe6b4c8 | 2007-05-14 17:27:29 +0200 | [diff] [blame] | 1579 | md->disk->major = MMC_BLOCK_MAJOR; |
Olof Johansson | 5e71b7a | 2010-09-17 21:19:57 -0400 | [diff] [blame] | 1580 | md->disk->first_minor = devidx * perdev_minors; |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1581 | md->disk->fops = &mmc_bdops; |
| 1582 | md->disk->private_data = md; |
| 1583 | md->disk->queue = md->queue.queue; |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1584 | md->disk->driverfs_dev = parent; |
| 1585 | set_disk_ro(md->disk, md->read_only || default_ro); |
Loic Pallardy | 53d8f97 | 2012-08-06 17:12:28 +0200 | [diff] [blame] | 1586 | if (area_type & MMC_BLK_DATA_AREA_RPMB) |
| 1587 | md->disk->flags |= GENHD_FL_NO_PART_SCAN; |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1588 | |
| 1589 | /* |
| 1590 | * As discussed on lkml, GENHD_FL_REMOVABLE should: |
| 1591 | * |
| 1592 | * - be set for removable media with permanent block devices |
| 1593 | * - be unset for removable block devices with permanent media |
| 1594 | * |
| 1595 | * Since MMC block devices clearly fall under the second |
| 1596 | * case, we do not set GENHD_FL_REMOVABLE. Userspace |
| 1597 | * should use the block device creation/destruction hotplug |
| 1598 | * messages to tell when the card is present. |
| 1599 | */ |
| 1600 | |
Andrei Warkentin | f06c915 | 2011-04-21 22:46:13 -0500 | [diff] [blame] | 1601 | snprintf(md->disk->disk_name, sizeof(md->disk->disk_name), |
| 1602 | "mmcblk%d%s", md->name_idx, subname ? subname : ""); |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1603 | |
Saugata Das | a5075eb | 2012-05-17 16:32:21 +0530 | [diff] [blame] | 1604 | if (mmc_card_mmc(card)) |
| 1605 | blk_queue_logical_block_size(md->queue.queue, |
| 1606 | card->ext_csd.data_sector_size); |
| 1607 | else |
| 1608 | blk_queue_logical_block_size(md->queue.queue, 512); |
| 1609 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1610 | set_capacity(md->disk, size); |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 1611 | |
Andrei Warkentin | f0d8997 | 2011-05-23 15:06:38 -0500 | [diff] [blame] | 1612 | if (mmc_host_cmd23(card->host)) { |
| 1613 | if (mmc_card_mmc(card) || |
| 1614 | (mmc_card_sd(card) && |
| 1615 | card->scr.cmds & SD_SCR_CMD23_SUPPORT)) |
| 1616 | md->flags |= MMC_BLK_CMD23; |
| 1617 | } |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 1618 | |
| 1619 | if (mmc_card_mmc(card) && |
| 1620 | md->flags & MMC_BLK_CMD23 && |
| 1621 | ((card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN) || |
| 1622 | card->ext_csd.rel_sectors)) { |
| 1623 | md->flags |= MMC_BLK_REL_WR; |
| 1624 | blk_queue_flush(md->queue.queue, REQ_FLUSH | REQ_FUA); |
| 1625 | } |
| 1626 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | return md; |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1628 | |
| 1629 | err_putdisk: |
| 1630 | put_disk(md->disk); |
| 1631 | err_kfree: |
| 1632 | kfree(md); |
| 1633 | out: |
| 1634 | return ERR_PTR(ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | } |
| 1636 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1637 | static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card) |
| 1638 | { |
| 1639 | sector_t size; |
| 1640 | struct mmc_blk_data *md; |
| 1641 | |
| 1642 | if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) { |
| 1643 | /* |
| 1644 | * The EXT_CSD sector count is in number or 512 byte |
| 1645 | * sectors. |
| 1646 | */ |
| 1647 | size = card->ext_csd.sectors; |
| 1648 | } else { |
| 1649 | /* |
| 1650 | * The CSD capacity field is in units of read_blkbits. |
| 1651 | * set_capacity takes units of 512 bytes. |
| 1652 | */ |
| 1653 | size = card->csd.capacity << (card->csd.read_blkbits - 9); |
| 1654 | } |
| 1655 | |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 1656 | md = mmc_blk_alloc_req(card, &card->dev, size, false, NULL, |
| 1657 | MMC_BLK_DATA_AREA_MAIN); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1658 | return md; |
| 1659 | } |
| 1660 | |
| 1661 | static int mmc_blk_alloc_part(struct mmc_card *card, |
| 1662 | struct mmc_blk_data *md, |
| 1663 | unsigned int part_type, |
| 1664 | sector_t size, |
| 1665 | bool default_ro, |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 1666 | const char *subname, |
| 1667 | int area_type) |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1668 | { |
| 1669 | char cap_str[10]; |
| 1670 | struct mmc_blk_data *part_md; |
| 1671 | |
| 1672 | part_md = mmc_blk_alloc_req(card, disk_to_dev(md->disk), size, default_ro, |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 1673 | subname, area_type); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1674 | if (IS_ERR(part_md)) |
| 1675 | return PTR_ERR(part_md); |
| 1676 | part_md->part_type = part_type; |
| 1677 | list_add(&part_md->part, &md->part); |
| 1678 | |
| 1679 | string_get_size((u64)get_capacity(part_md->disk) << 9, STRING_UNITS_2, |
| 1680 | cap_str, sizeof(cap_str)); |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 1681 | pr_info("%s: %s %s partition %u %s\n", |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1682 | part_md->disk->disk_name, mmc_card_id(card), |
| 1683 | mmc_card_name(card), part_md->part_type, cap_str); |
| 1684 | return 0; |
| 1685 | } |
| 1686 | |
Namjae Jeon | e0c368d | 2011-10-06 23:41:38 +0900 | [diff] [blame] | 1687 | /* MMC Physical partitions consist of two boot partitions and |
| 1688 | * up to four general purpose partitions. |
| 1689 | * For each partition enabled in EXT_CSD a block device will be allocatedi |
| 1690 | * to provide access to the partition. |
| 1691 | */ |
| 1692 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1693 | static int mmc_blk_alloc_parts(struct mmc_card *card, struct mmc_blk_data *md) |
| 1694 | { |
Namjae Jeon | e0c368d | 2011-10-06 23:41:38 +0900 | [diff] [blame] | 1695 | int idx, ret = 0; |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1696 | |
| 1697 | if (!mmc_card_mmc(card)) |
| 1698 | return 0; |
| 1699 | |
Namjae Jeon | e0c368d | 2011-10-06 23:41:38 +0900 | [diff] [blame] | 1700 | for (idx = 0; idx < card->nr_parts; idx++) { |
| 1701 | if (card->part[idx].size) { |
| 1702 | ret = mmc_blk_alloc_part(card, md, |
| 1703 | card->part[idx].part_cfg, |
| 1704 | card->part[idx].size >> 9, |
| 1705 | card->part[idx].force_ro, |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 1706 | card->part[idx].name, |
| 1707 | card->part[idx].area_type); |
Namjae Jeon | e0c368d | 2011-10-06 23:41:38 +0900 | [diff] [blame] | 1708 | if (ret) |
| 1709 | return ret; |
| 1710 | } |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | return ret; |
| 1714 | } |
| 1715 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1716 | static void mmc_blk_remove_req(struct mmc_blk_data *md) |
| 1717 | { |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 1718 | struct mmc_card *card; |
| 1719 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1720 | if (md) { |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 1721 | card = md->queue.card; |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1722 | if (md->disk->flags & GENHD_FL_UP) { |
| 1723 | device_remove_file(disk_to_dev(md->disk), &md->force_ro); |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 1724 | if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) && |
| 1725 | card->ext_csd.boot_ro_lockable) |
| 1726 | device_remove_file(disk_to_dev(md->disk), |
| 1727 | &md->power_ro_lock); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1728 | |
| 1729 | /* Stop new requests from getting into the queue */ |
| 1730 | del_gendisk(md->disk); |
| 1731 | } |
| 1732 | |
| 1733 | /* Then flush out any already in there */ |
| 1734 | mmc_cleanup_queue(&md->queue); |
| 1735 | mmc_blk_put(md); |
| 1736 | } |
| 1737 | } |
| 1738 | |
| 1739 | static void mmc_blk_remove_parts(struct mmc_card *card, |
| 1740 | struct mmc_blk_data *md) |
| 1741 | { |
| 1742 | struct list_head *pos, *q; |
| 1743 | struct mmc_blk_data *part_md; |
| 1744 | |
Andrei Warkentin | f06c915 | 2011-04-21 22:46:13 -0500 | [diff] [blame] | 1745 | __clear_bit(md->name_idx, name_use); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1746 | list_for_each_safe(pos, q, &md->part) { |
| 1747 | part_md = list_entry(pos, struct mmc_blk_data, part); |
| 1748 | list_del(pos); |
| 1749 | mmc_blk_remove_req(part_md); |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | static int mmc_add_disk(struct mmc_blk_data *md) |
| 1754 | { |
| 1755 | int ret; |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 1756 | struct mmc_card *card = md->queue.card; |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1757 | |
| 1758 | add_disk(md->disk); |
| 1759 | md->force_ro.show = force_ro_show; |
| 1760 | md->force_ro.store = force_ro_store; |
Rabin Vincent | 641c318 | 2011-04-23 20:52:58 +0530 | [diff] [blame] | 1761 | sysfs_attr_init(&md->force_ro.attr); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1762 | md->force_ro.attr.name = "force_ro"; |
| 1763 | md->force_ro.attr.mode = S_IRUGO | S_IWUSR; |
| 1764 | ret = device_create_file(disk_to_dev(md->disk), &md->force_ro); |
| 1765 | if (ret) |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 1766 | goto force_ro_fail; |
| 1767 | |
| 1768 | if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) && |
| 1769 | card->ext_csd.boot_ro_lockable) { |
Al Viro | 8818739 | 2012-03-20 06:00:24 -0400 | [diff] [blame] | 1770 | umode_t mode; |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 1771 | |
| 1772 | if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PWR_WP_DIS) |
| 1773 | mode = S_IRUGO; |
| 1774 | else |
| 1775 | mode = S_IRUGO | S_IWUSR; |
| 1776 | |
| 1777 | md->power_ro_lock.show = power_ro_lock_show; |
| 1778 | md->power_ro_lock.store = power_ro_lock_store; |
Rabin Vincent | 00d9ac0 | 2012-02-01 16:31:56 +0100 | [diff] [blame] | 1779 | sysfs_attr_init(&md->power_ro_lock.attr); |
Johan Rudholm | add710e | 2011-12-02 08:51:06 +0100 | [diff] [blame] | 1780 | md->power_ro_lock.attr.mode = mode; |
| 1781 | md->power_ro_lock.attr.name = |
| 1782 | "ro_lock_until_next_power_on"; |
| 1783 | ret = device_create_file(disk_to_dev(md->disk), |
| 1784 | &md->power_ro_lock); |
| 1785 | if (ret) |
| 1786 | goto power_ro_lock_fail; |
| 1787 | } |
| 1788 | return ret; |
| 1789 | |
| 1790 | power_ro_lock_fail: |
| 1791 | device_remove_file(disk_to_dev(md->disk), &md->force_ro); |
| 1792 | force_ro_fail: |
| 1793 | del_gendisk(md->disk); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1794 | |
| 1795 | return ret; |
| 1796 | } |
| 1797 | |
Chris Ball | c59d447 | 2011-11-11 22:01:43 -0500 | [diff] [blame] | 1798 | #define CID_MANFID_SANDISK 0x2 |
| 1799 | #define CID_MANFID_TOSHIBA 0x11 |
| 1800 | #define CID_MANFID_MICRON 0x13 |
Ian Chen | 3550ccd | 2012-08-29 15:05:36 +0900 | [diff] [blame] | 1801 | #define CID_MANFID_SAMSUNG 0x15 |
Chris Ball | c59d447 | 2011-11-11 22:01:43 -0500 | [diff] [blame] | 1802 | |
Andrei Warkentin | 6f60c22 | 2011-04-11 19:11:04 -0400 | [diff] [blame] | 1803 | static const struct mmc_fixup blk_fixups[] = |
| 1804 | { |
Chris Ball | c59d447 | 2011-11-11 22:01:43 -0500 | [diff] [blame] | 1805 | MMC_FIXUP("SEM02G", CID_MANFID_SANDISK, 0x100, add_quirk, |
| 1806 | MMC_QUIRK_INAND_CMD38), |
| 1807 | MMC_FIXUP("SEM04G", CID_MANFID_SANDISK, 0x100, add_quirk, |
| 1808 | MMC_QUIRK_INAND_CMD38), |
| 1809 | MMC_FIXUP("SEM08G", CID_MANFID_SANDISK, 0x100, add_quirk, |
| 1810 | MMC_QUIRK_INAND_CMD38), |
| 1811 | MMC_FIXUP("SEM16G", CID_MANFID_SANDISK, 0x100, add_quirk, |
| 1812 | MMC_QUIRK_INAND_CMD38), |
| 1813 | MMC_FIXUP("SEM32G", CID_MANFID_SANDISK, 0x100, add_quirk, |
| 1814 | MMC_QUIRK_INAND_CMD38), |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 1815 | |
| 1816 | /* |
| 1817 | * Some MMC cards experience performance degradation with CMD23 |
| 1818 | * instead of CMD12-bounded multiblock transfers. For now we'll |
| 1819 | * black list what's bad... |
| 1820 | * - Certain Toshiba cards. |
| 1821 | * |
| 1822 | * N.B. This doesn't affect SD cards. |
| 1823 | */ |
Chris Ball | c59d447 | 2011-11-11 22:01:43 -0500 | [diff] [blame] | 1824 | MMC_FIXUP("MMC08G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc, |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 1825 | MMC_QUIRK_BLK_NO_CMD23), |
Chris Ball | c59d447 | 2011-11-11 22:01:43 -0500 | [diff] [blame] | 1826 | MMC_FIXUP("MMC16G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc, |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 1827 | MMC_QUIRK_BLK_NO_CMD23), |
Chris Ball | c59d447 | 2011-11-11 22:01:43 -0500 | [diff] [blame] | 1828 | MMC_FIXUP("MMC32G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc, |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 1829 | MMC_QUIRK_BLK_NO_CMD23), |
Stefan Nilsson XK | 6de5fc9 | 2011-11-03 09:44:12 +0100 | [diff] [blame] | 1830 | |
| 1831 | /* |
| 1832 | * Some Micron MMC cards needs longer data read timeout than |
| 1833 | * indicated in CSD. |
| 1834 | */ |
Chris Ball | c59d447 | 2011-11-11 22:01:43 -0500 | [diff] [blame] | 1835 | MMC_FIXUP(CID_NAME_ANY, CID_MANFID_MICRON, 0x200, add_quirk_mmc, |
Stefan Nilsson XK | 6de5fc9 | 2011-11-03 09:44:12 +0100 | [diff] [blame] | 1836 | MMC_QUIRK_LONG_READ_TIME), |
| 1837 | |
Ian Chen | 3550ccd | 2012-08-29 15:05:36 +0900 | [diff] [blame] | 1838 | /* |
| 1839 | * On these Samsung MoviNAND parts, performing secure erase or |
| 1840 | * secure trim can result in unrecoverable corruption due to a |
| 1841 | * firmware bug. |
| 1842 | */ |
| 1843 | MMC_FIXUP("M8G2FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, |
| 1844 | MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), |
| 1845 | MMC_FIXUP("MAG4FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, |
| 1846 | MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), |
| 1847 | MMC_FIXUP("MBG8FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, |
| 1848 | MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), |
| 1849 | MMC_FIXUP("MCGAFA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, |
| 1850 | MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), |
| 1851 | MMC_FIXUP("VAL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, |
| 1852 | MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), |
| 1853 | MMC_FIXUP("VYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, |
| 1854 | MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), |
| 1855 | MMC_FIXUP("KYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, |
| 1856 | MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), |
| 1857 | MMC_FIXUP("VZL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, |
| 1858 | MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), |
| 1859 | |
Andrei Warkentin | 6f60c22 | 2011-04-11 19:11:04 -0400 | [diff] [blame] | 1860 | END_FIXUP |
| 1861 | }; |
| 1862 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | static int mmc_blk_probe(struct mmc_card *card) |
| 1864 | { |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1865 | struct mmc_blk_data *md, *part_md; |
Pierre Ossman | a7bbb57 | 2008-09-06 10:57:57 +0200 | [diff] [blame] | 1866 | char cap_str[10]; |
| 1867 | |
Pierre Ossman | 912490d | 2005-05-21 10:27:02 +0100 | [diff] [blame] | 1868 | /* |
| 1869 | * Check that the card supports the command class(es) we need. |
| 1870 | */ |
| 1871 | if (!(card->csd.cmdclass & CCC_BLOCK_READ)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | return -ENODEV; |
| 1873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | md = mmc_blk_alloc(card); |
| 1875 | if (IS_ERR(md)) |
| 1876 | return PTR_ERR(md); |
| 1877 | |
Yi Li | 444122f | 2009-02-05 15:31:57 +0800 | [diff] [blame] | 1878 | string_get_size((u64)get_capacity(md->disk) << 9, STRING_UNITS_2, |
Pierre Ossman | a7bbb57 | 2008-09-06 10:57:57 +0200 | [diff] [blame] | 1879 | cap_str, sizeof(cap_str)); |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 1880 | pr_info("%s: %s %s %s %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | md->disk->disk_name, mmc_card_id(card), mmc_card_name(card), |
Pierre Ossman | a7bbb57 | 2008-09-06 10:57:57 +0200 | [diff] [blame] | 1882 | cap_str, md->read_only ? "(ro)" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1884 | if (mmc_blk_alloc_parts(card, md)) |
| 1885 | goto out; |
| 1886 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | mmc_set_drvdata(card, md); |
Andrei Warkentin | 6f60c22 | 2011-04-11 19:11:04 -0400 | [diff] [blame] | 1888 | mmc_fixup_device(card, blk_fixups); |
| 1889 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1890 | if (mmc_add_disk(md)) |
| 1891 | goto out; |
| 1892 | |
| 1893 | list_for_each_entry(part_md, &md->part, part) { |
| 1894 | if (mmc_add_disk(part_md)) |
| 1895 | goto out; |
| 1896 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | return 0; |
| 1898 | |
| 1899 | out: |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1900 | mmc_blk_remove_parts(card, md); |
| 1901 | mmc_blk_remove_req(md); |
Ulf Hansson | 5865f28 | 2012-03-22 11:47:26 +0100 | [diff] [blame] | 1902 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | static void mmc_blk_remove(struct mmc_card *card) |
| 1906 | { |
| 1907 | struct mmc_blk_data *md = mmc_get_drvdata(card); |
| 1908 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1909 | mmc_blk_remove_parts(card, md); |
Adrian Hunter | ddd6fa7 | 2011-06-23 13:40:26 +0300 | [diff] [blame] | 1910 | mmc_claim_host(card->host); |
| 1911 | mmc_blk_part_switch(card, md); |
| 1912 | mmc_release_host(card->host); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1913 | mmc_blk_remove_req(md); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | mmc_set_drvdata(card, NULL); |
| 1915 | } |
| 1916 | |
| 1917 | #ifdef CONFIG_PM |
Chuanxiao Dong | 32d317c | 2012-04-11 19:54:38 +0800 | [diff] [blame] | 1918 | static int mmc_blk_suspend(struct mmc_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | { |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1920 | struct mmc_blk_data *part_md; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | struct mmc_blk_data *md = mmc_get_drvdata(card); |
| 1922 | |
| 1923 | if (md) { |
| 1924 | mmc_queue_suspend(&md->queue); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1925 | list_for_each_entry(part_md, &md->part, part) { |
| 1926 | mmc_queue_suspend(&part_md->queue); |
| 1927 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | } |
| 1929 | return 0; |
| 1930 | } |
| 1931 | |
| 1932 | static int mmc_blk_resume(struct mmc_card *card) |
| 1933 | { |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1934 | struct mmc_blk_data *part_md; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | struct mmc_blk_data *md = mmc_get_drvdata(card); |
| 1936 | |
| 1937 | if (md) { |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1938 | /* |
| 1939 | * Resume involves the card going into idle state, |
| 1940 | * so current partition is always the main one. |
| 1941 | */ |
| 1942 | md->part_curr = md->part_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | mmc_queue_resume(&md->queue); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1944 | list_for_each_entry(part_md, &md->part, part) { |
| 1945 | mmc_queue_resume(&part_md->queue); |
| 1946 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | } |
| 1948 | return 0; |
| 1949 | } |
| 1950 | #else |
| 1951 | #define mmc_blk_suspend NULL |
| 1952 | #define mmc_blk_resume NULL |
| 1953 | #endif |
| 1954 | |
| 1955 | static struct mmc_driver mmc_driver = { |
| 1956 | .drv = { |
| 1957 | .name = "mmcblk", |
| 1958 | }, |
| 1959 | .probe = mmc_blk_probe, |
| 1960 | .remove = mmc_blk_remove, |
| 1961 | .suspend = mmc_blk_suspend, |
| 1962 | .resume = mmc_blk_resume, |
| 1963 | }; |
| 1964 | |
| 1965 | static int __init mmc_blk_init(void) |
| 1966 | { |
Akinobu Mita | 9d4e98e | 2008-09-13 19:02:07 +0900 | [diff] [blame] | 1967 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | |
Olof Johansson | 5e71b7a | 2010-09-17 21:19:57 -0400 | [diff] [blame] | 1969 | if (perdev_minors != CONFIG_MMC_BLOCK_MINORS) |
| 1970 | pr_info("mmcblk: using %d minors per device\n", perdev_minors); |
| 1971 | |
| 1972 | max_devices = 256 / perdev_minors; |
| 1973 | |
Pierre Ossman | fe6b4c8 | 2007-05-14 17:27:29 +0200 | [diff] [blame] | 1974 | res = register_blkdev(MMC_BLOCK_MAJOR, "mmc"); |
| 1975 | if (res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | |
Akinobu Mita | 9d4e98e | 2008-09-13 19:02:07 +0900 | [diff] [blame] | 1978 | res = mmc_register_driver(&mmc_driver); |
| 1979 | if (res) |
| 1980 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | |
Akinobu Mita | 9d4e98e | 2008-09-13 19:02:07 +0900 | [diff] [blame] | 1982 | return 0; |
| 1983 | out2: |
| 1984 | unregister_blkdev(MMC_BLOCK_MAJOR, "mmc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | out: |
| 1986 | return res; |
| 1987 | } |
| 1988 | |
| 1989 | static void __exit mmc_blk_exit(void) |
| 1990 | { |
| 1991 | mmc_unregister_driver(&mmc_driver); |
Pierre Ossman | fe6b4c8 | 2007-05-14 17:27:29 +0200 | [diff] [blame] | 1992 | unregister_blkdev(MMC_BLOCK_MAJOR, "mmc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | module_init(mmc_blk_init); |
| 1996 | module_exit(mmc_blk_exit); |
| 1997 | |
| 1998 | MODULE_LICENSE("GPL"); |
| 1999 | MODULE_DESCRIPTION("Multimedia Card (MMC) block device driver"); |
| 2000 | |