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 | 385e322 | 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 | |
| 44 | #include <asm/system.h> |
| 45 | #include <asm/uaccess.h> |
| 46 | |
Pierre Ossman | 98ac216 | 2006-12-23 20:03:02 +0100 | [diff] [blame] | 47 | #include "queue.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Andy Whitcroft | 6b0b628 | 2009-02-23 12:38:41 +0000 | [diff] [blame] | 49 | MODULE_ALIAS("mmc:block"); |
Olof Johansson | 5e71b7a | 2010-09-17 21:19:57 -0400 | [diff] [blame] | 50 | #ifdef MODULE_PARAM_PREFIX |
| 51 | #undef MODULE_PARAM_PREFIX |
| 52 | #endif |
| 53 | #define MODULE_PARAM_PREFIX "mmcblk." |
David Woodhouse | 1dff314 | 2007-11-21 18:45:12 +0100 | [diff] [blame] | 54 | |
Andrei Warkentin | 6a7a6b4 | 2011-04-12 15:06:53 -0500 | [diff] [blame] | 55 | #define INAND_CMD38_ARG_EXT_CSD 113 |
| 56 | #define INAND_CMD38_ARG_ERASE 0x00 |
| 57 | #define INAND_CMD38_ARG_TRIM 0x01 |
| 58 | #define INAND_CMD38_ARG_SECERASE 0x80 |
| 59 | #define INAND_CMD38_ARG_SECTRIM1 0x81 |
| 60 | #define INAND_CMD38_ARG_SECTRIM2 0x88 |
| 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; |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | * Only set in main mmc_blk_data associated |
| 100 | * with mmc_card with mmc_set_drvdata, and keeps |
| 101 | * track of the current selected device partition. |
| 102 | */ |
| 103 | unsigned int part_curr; |
| 104 | struct device_attribute force_ro; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 107 | static DEFINE_MUTEX(open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Olof Johansson | 5e71b7a | 2010-09-17 21:19:57 -0400 | [diff] [blame] | 109 | module_param(perdev_minors, int, 0444); |
| 110 | MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device"); |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk) |
| 113 | { |
| 114 | struct mmc_blk_data *md; |
| 115 | |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 116 | mutex_lock(&open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | md = disk->private_data; |
| 118 | if (md && md->usage == 0) |
| 119 | md = NULL; |
| 120 | if (md) |
| 121 | md->usage++; |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 122 | mutex_unlock(&open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | return md; |
| 125 | } |
| 126 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 127 | static inline int mmc_get_devidx(struct gendisk *disk) |
| 128 | { |
| 129 | int devmaj = MAJOR(disk_devt(disk)); |
| 130 | int devidx = MINOR(disk_devt(disk)) / perdev_minors; |
| 131 | |
| 132 | if (!devmaj) |
| 133 | devidx = disk->first_minor / perdev_minors; |
| 134 | return devidx; |
| 135 | } |
| 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | static void mmc_blk_put(struct mmc_blk_data *md) |
| 138 | { |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 139 | mutex_lock(&open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | md->usage--; |
| 141 | if (md->usage == 0) { |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 142 | int devidx = mmc_get_devidx(md->disk); |
Adrian Hunter | 5fa83ce | 2010-01-08 14:43:00 -0800 | [diff] [blame] | 143 | blk_cleanup_queue(md->queue.queue); |
| 144 | |
David Woodhouse | 1dff314 | 2007-11-21 18:45:12 +0100 | [diff] [blame] | 145 | __clear_bit(devidx, dev_use); |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | put_disk(md->disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | kfree(md); |
| 149 | } |
Arjan van de Ven | a621aae | 2006-01-12 18:43:35 +0000 | [diff] [blame] | 150 | mutex_unlock(&open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 153 | static ssize_t force_ro_show(struct device *dev, struct device_attribute *attr, |
| 154 | char *buf) |
| 155 | { |
| 156 | int ret; |
| 157 | struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev)); |
| 158 | |
| 159 | ret = snprintf(buf, PAGE_SIZE, "%d", |
| 160 | get_disk_ro(dev_to_disk(dev)) ^ |
| 161 | md->read_only); |
| 162 | mmc_blk_put(md); |
| 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | static ssize_t force_ro_store(struct device *dev, struct device_attribute *attr, |
| 167 | const char *buf, size_t count) |
| 168 | { |
| 169 | int ret; |
| 170 | char *end; |
| 171 | struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev)); |
| 172 | unsigned long set = simple_strtoul(buf, &end, 0); |
| 173 | if (end == buf) { |
| 174 | ret = -EINVAL; |
| 175 | goto out; |
| 176 | } |
| 177 | |
| 178 | set_disk_ro(dev_to_disk(dev), set || md->read_only); |
| 179 | ret = count; |
| 180 | out: |
| 181 | mmc_blk_put(md); |
| 182 | return ret; |
| 183 | } |
| 184 | |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 185 | static int mmc_blk_open(struct block_device *bdev, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | { |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 187 | struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | int ret = -ENXIO; |
| 189 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 190 | mutex_lock(&block_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | if (md) { |
| 192 | if (md->usage == 2) |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 193 | check_disk_change(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | ret = 0; |
Pierre Ossman | a00fc09 | 2005-09-06 15:18:52 -0700 | [diff] [blame] | 195 | |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 196 | if ((mode & FMODE_WRITE) && md->read_only) { |
Andrew Morton | 70bb089 | 2008-09-05 14:00:24 -0700 | [diff] [blame] | 197 | mmc_blk_put(md); |
Pierre Ossman | a00fc09 | 2005-09-06 15:18:52 -0700 | [diff] [blame] | 198 | ret = -EROFS; |
Andrew Morton | 70bb089 | 2008-09-05 14:00:24 -0700 | [diff] [blame] | 199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 201 | mutex_unlock(&block_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | return ret; |
| 204 | } |
| 205 | |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 206 | static int mmc_blk_release(struct gendisk *disk, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | { |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 208 | struct mmc_blk_data *md = disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 210 | mutex_lock(&block_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | mmc_blk_put(md); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 212 | mutex_unlock(&block_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | static int |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 217 | mmc_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 219 | geo->cylinders = get_capacity(bdev->bd_disk) / (4 * 16); |
| 220 | geo->heads = 4; |
| 221 | geo->sectors = 16; |
| 222 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | } |
| 224 | |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 225 | struct mmc_blk_ioc_data { |
| 226 | struct mmc_ioc_cmd ic; |
| 227 | unsigned char *buf; |
| 228 | u64 buf_bytes; |
| 229 | }; |
| 230 | |
| 231 | static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user( |
| 232 | struct mmc_ioc_cmd __user *user) |
| 233 | { |
| 234 | struct mmc_blk_ioc_data *idata; |
| 235 | int err; |
| 236 | |
| 237 | idata = kzalloc(sizeof(*idata), GFP_KERNEL); |
| 238 | if (!idata) { |
| 239 | err = -ENOMEM; |
Vladimir Motyka | aea253e | 2011-05-11 00:00:43 -0400 | [diff] [blame] | 240 | goto out; |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | if (copy_from_user(&idata->ic, user, sizeof(idata->ic))) { |
| 244 | err = -EFAULT; |
Vladimir Motyka | aea253e | 2011-05-11 00:00:43 -0400 | [diff] [blame] | 245 | goto idata_err; |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | idata->buf_bytes = (u64) idata->ic.blksz * idata->ic.blocks; |
| 249 | if (idata->buf_bytes > MMC_IOC_MAX_BYTES) { |
| 250 | err = -EOVERFLOW; |
Vladimir Motyka | aea253e | 2011-05-11 00:00:43 -0400 | [diff] [blame] | 251 | goto idata_err; |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | idata->buf = kzalloc(idata->buf_bytes, GFP_KERNEL); |
| 255 | if (!idata->buf) { |
| 256 | err = -ENOMEM; |
Vladimir Motyka | aea253e | 2011-05-11 00:00:43 -0400 | [diff] [blame] | 257 | goto idata_err; |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | if (copy_from_user(idata->buf, (void __user *)(unsigned long) |
| 261 | idata->ic.data_ptr, idata->buf_bytes)) { |
| 262 | err = -EFAULT; |
| 263 | goto copy_err; |
| 264 | } |
| 265 | |
| 266 | return idata; |
| 267 | |
| 268 | copy_err: |
| 269 | kfree(idata->buf); |
Vladimir Motyka | aea253e | 2011-05-11 00:00:43 -0400 | [diff] [blame] | 270 | idata_err: |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 271 | kfree(idata); |
Vladimir Motyka | aea253e | 2011-05-11 00:00:43 -0400 | [diff] [blame] | 272 | out: |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 273 | return ERR_PTR(err); |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | static int mmc_blk_ioctl_cmd(struct block_device *bdev, |
| 277 | struct mmc_ioc_cmd __user *ic_ptr) |
| 278 | { |
| 279 | struct mmc_blk_ioc_data *idata; |
| 280 | struct mmc_blk_data *md; |
| 281 | struct mmc_card *card; |
| 282 | struct mmc_command cmd = {0}; |
| 283 | struct mmc_data data = {0}; |
| 284 | struct mmc_request mrq = {0}; |
| 285 | struct scatterlist sg; |
| 286 | int err; |
| 287 | |
| 288 | /* |
| 289 | * The caller must have CAP_SYS_RAWIO, and must be calling this on the |
| 290 | * whole block device, not on a partition. This prevents overspray |
| 291 | * between sibling partitions. |
| 292 | */ |
| 293 | if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains)) |
| 294 | return -EPERM; |
| 295 | |
| 296 | idata = mmc_blk_ioctl_copy_from_user(ic_ptr); |
| 297 | if (IS_ERR(idata)) |
| 298 | return PTR_ERR(idata); |
| 299 | |
| 300 | cmd.opcode = idata->ic.opcode; |
| 301 | cmd.arg = idata->ic.arg; |
| 302 | cmd.flags = idata->ic.flags; |
| 303 | |
| 304 | data.sg = &sg; |
| 305 | data.sg_len = 1; |
| 306 | data.blksz = idata->ic.blksz; |
| 307 | data.blocks = idata->ic.blocks; |
| 308 | |
| 309 | sg_init_one(data.sg, idata->buf, idata->buf_bytes); |
| 310 | |
| 311 | if (idata->ic.write_flag) |
| 312 | data.flags = MMC_DATA_WRITE; |
| 313 | else |
| 314 | data.flags = MMC_DATA_READ; |
| 315 | |
| 316 | mrq.cmd = &cmd; |
| 317 | mrq.data = &data; |
| 318 | |
| 319 | md = mmc_blk_get(bdev->bd_disk); |
| 320 | if (!md) { |
| 321 | err = -EINVAL; |
| 322 | goto cmd_done; |
| 323 | } |
| 324 | |
| 325 | card = md->queue.card; |
| 326 | if (IS_ERR(card)) { |
| 327 | err = PTR_ERR(card); |
| 328 | goto cmd_done; |
| 329 | } |
| 330 | |
| 331 | mmc_claim_host(card->host); |
| 332 | |
| 333 | if (idata->ic.is_acmd) { |
| 334 | err = mmc_app_cmd(card->host, card); |
| 335 | if (err) |
| 336 | goto cmd_rel_host; |
| 337 | } |
| 338 | |
| 339 | /* data.flags must already be set before doing this. */ |
| 340 | mmc_set_data_timeout(&data, card); |
| 341 | /* Allow overriding the timeout_ns for empirical tuning. */ |
| 342 | if (idata->ic.data_timeout_ns) |
| 343 | data.timeout_ns = idata->ic.data_timeout_ns; |
| 344 | |
| 345 | if ((cmd.flags & MMC_RSP_R1B) == MMC_RSP_R1B) { |
| 346 | /* |
| 347 | * Pretend this is a data transfer and rely on the host driver |
| 348 | * to compute timeout. When all host drivers support |
| 349 | * cmd.cmd_timeout for R1B, this can be changed to: |
| 350 | * |
| 351 | * mrq.data = NULL; |
| 352 | * cmd.cmd_timeout = idata->ic.cmd_timeout_ms; |
| 353 | */ |
| 354 | data.timeout_ns = idata->ic.cmd_timeout_ms * 1000000; |
| 355 | } |
| 356 | |
| 357 | mmc_wait_for_req(card->host, &mrq); |
| 358 | |
| 359 | if (cmd.error) { |
| 360 | dev_err(mmc_dev(card->host), "%s: cmd error %d\n", |
| 361 | __func__, cmd.error); |
| 362 | err = cmd.error; |
| 363 | goto cmd_rel_host; |
| 364 | } |
| 365 | if (data.error) { |
| 366 | dev_err(mmc_dev(card->host), "%s: data error %d\n", |
| 367 | __func__, data.error); |
| 368 | err = data.error; |
| 369 | goto cmd_rel_host; |
| 370 | } |
| 371 | |
| 372 | /* |
| 373 | * According to the SD specs, some commands require a delay after |
| 374 | * issuing the command. |
| 375 | */ |
| 376 | if (idata->ic.postsleep_min_us) |
| 377 | usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us); |
| 378 | |
| 379 | if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) { |
| 380 | err = -EFAULT; |
| 381 | goto cmd_rel_host; |
| 382 | } |
| 383 | |
| 384 | if (!idata->ic.write_flag) { |
| 385 | if (copy_to_user((void __user *)(unsigned long) idata->ic.data_ptr, |
| 386 | idata->buf, idata->buf_bytes)) { |
| 387 | err = -EFAULT; |
| 388 | goto cmd_rel_host; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | cmd_rel_host: |
| 393 | mmc_release_host(card->host); |
| 394 | |
| 395 | cmd_done: |
| 396 | mmc_blk_put(md); |
| 397 | kfree(idata->buf); |
| 398 | kfree(idata); |
| 399 | return err; |
| 400 | } |
| 401 | |
| 402 | static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode, |
| 403 | unsigned int cmd, unsigned long arg) |
| 404 | { |
| 405 | int ret = -EINVAL; |
| 406 | if (cmd == MMC_IOC_CMD) |
| 407 | ret = mmc_blk_ioctl_cmd(bdev, (struct mmc_ioc_cmd __user *)arg); |
| 408 | return ret; |
| 409 | } |
| 410 | |
| 411 | #ifdef CONFIG_COMPAT |
| 412 | static int mmc_blk_compat_ioctl(struct block_device *bdev, fmode_t mode, |
| 413 | unsigned int cmd, unsigned long arg) |
| 414 | { |
| 415 | return mmc_blk_ioctl(bdev, mode, cmd, (unsigned long) compat_ptr(arg)); |
| 416 | } |
| 417 | #endif |
| 418 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 419 | static const struct block_device_operations mmc_bdops = { |
Al Viro | a5a1561 | 2008-03-02 10:33:30 -0500 | [diff] [blame] | 420 | .open = mmc_blk_open, |
| 421 | .release = mmc_blk_release, |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 422 | .getgeo = mmc_blk_getgeo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | .owner = THIS_MODULE, |
John Calixto | cb87ea2 | 2011-04-26 18:56:29 -0400 | [diff] [blame] | 424 | .ioctl = mmc_blk_ioctl, |
| 425 | #ifdef CONFIG_COMPAT |
| 426 | .compat_ioctl = mmc_blk_compat_ioctl, |
| 427 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | }; |
| 429 | |
| 430 | struct mmc_blk_request { |
| 431 | struct mmc_request mrq; |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 432 | struct mmc_command sbc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | struct mmc_command cmd; |
| 434 | struct mmc_command stop; |
| 435 | struct mmc_data data; |
| 436 | }; |
| 437 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 438 | static inline int mmc_blk_part_switch(struct mmc_card *card, |
| 439 | struct mmc_blk_data *md) |
| 440 | { |
| 441 | int ret; |
| 442 | struct mmc_blk_data *main_md = mmc_get_drvdata(card); |
| 443 | if (main_md->part_curr == md->part_type) |
| 444 | return 0; |
| 445 | |
| 446 | if (mmc_card_mmc(card)) { |
| 447 | card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; |
| 448 | card->ext_csd.part_config |= md->part_type; |
| 449 | |
| 450 | ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
| 451 | EXT_CSD_PART_CONFIG, card->ext_csd.part_config, |
| 452 | card->ext_csd.part_time); |
| 453 | if (ret) |
| 454 | return ret; |
| 455 | } |
| 456 | |
| 457 | main_md->part_curr = md->part_type; |
| 458 | return 0; |
| 459 | } |
| 460 | |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 461 | static u32 mmc_sd_num_wr_blocks(struct mmc_card *card) |
| 462 | { |
| 463 | int err; |
Ben Dooks | 051913d | 2009-06-08 23:33:57 +0100 | [diff] [blame] | 464 | u32 result; |
| 465 | __be32 *blocks; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 466 | |
Chris Ball | 24f5b53 | 2011-04-13 23:49:45 -0400 | [diff] [blame] | 467 | struct mmc_request mrq = {0}; |
Chris Ball | 1278dba | 2011-04-13 23:40:30 -0400 | [diff] [blame] | 468 | struct mmc_command cmd = {0}; |
Chris Ball | a61ad2b | 2011-04-13 23:46:05 -0400 | [diff] [blame] | 469 | struct mmc_data data = {0}; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 470 | unsigned int timeout_us; |
| 471 | |
| 472 | struct scatterlist sg; |
| 473 | |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 474 | cmd.opcode = MMC_APP_CMD; |
| 475 | cmd.arg = card->rca << 16; |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 476 | cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 477 | |
| 478 | err = mmc_wait_for_cmd(card->host, &cmd, 0); |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 479 | if (err) |
| 480 | return (u32)-1; |
| 481 | 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] | 482 | return (u32)-1; |
| 483 | |
| 484 | memset(&cmd, 0, sizeof(struct mmc_command)); |
| 485 | |
| 486 | cmd.opcode = SD_APP_SEND_NUM_WR_BLKS; |
| 487 | cmd.arg = 0; |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 488 | cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 489 | |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 490 | data.timeout_ns = card->csd.tacc_ns * 100; |
| 491 | data.timeout_clks = card->csd.tacc_clks * 100; |
| 492 | |
| 493 | timeout_us = data.timeout_ns / 1000; |
| 494 | timeout_us += data.timeout_clks * 1000 / |
| 495 | (card->host->ios.clock / 1000); |
| 496 | |
| 497 | if (timeout_us > 100000) { |
| 498 | data.timeout_ns = 100000000; |
| 499 | data.timeout_clks = 0; |
| 500 | } |
| 501 | |
| 502 | data.blksz = 4; |
| 503 | data.blocks = 1; |
| 504 | data.flags = MMC_DATA_READ; |
| 505 | data.sg = &sg; |
| 506 | data.sg_len = 1; |
| 507 | |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 508 | mrq.cmd = &cmd; |
| 509 | mrq.data = &data; |
| 510 | |
Ben Dooks | 051913d | 2009-06-08 23:33:57 +0100 | [diff] [blame] | 511 | blocks = kmalloc(4, GFP_KERNEL); |
| 512 | if (!blocks) |
| 513 | return (u32)-1; |
| 514 | |
| 515 | sg_init_one(&sg, blocks, 4); |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 516 | |
| 517 | mmc_wait_for_req(card->host, &mrq); |
| 518 | |
Ben Dooks | 051913d | 2009-06-08 23:33:57 +0100 | [diff] [blame] | 519 | result = ntohl(*blocks); |
| 520 | kfree(blocks); |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 521 | |
Ben Dooks | 051913d | 2009-06-08 23:33:57 +0100 | [diff] [blame] | 522 | if (cmd.error || data.error) |
| 523 | result = (u32)-1; |
| 524 | |
| 525 | return result; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 526 | } |
| 527 | |
Russell King - ARM Linux | 0a2d404 | 2011-06-20 20:10:08 +0100 | [diff] [blame^] | 528 | 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] | 529 | { |
Chris Ball | 1278dba | 2011-04-13 23:40:30 -0400 | [diff] [blame] | 530 | struct mmc_command cmd = {0}; |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 531 | int err; |
| 532 | |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 533 | cmd.opcode = MMC_SEND_STATUS; |
| 534 | if (!mmc_host_is_spi(card->host)) |
| 535 | cmd.arg = card->rca << 16; |
| 536 | 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^] | 537 | err = mmc_wait_for_cmd(card->host, &cmd, retries); |
| 538 | if (err == 0) |
| 539 | *status = cmd.resp[0]; |
| 540 | return err; |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 541 | } |
| 542 | |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 543 | static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req) |
| 544 | { |
| 545 | struct mmc_blk_data *md = mq->data; |
| 546 | struct mmc_card *card = md->queue.card; |
| 547 | unsigned int from, nr, arg; |
| 548 | int err = 0; |
| 549 | |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 550 | if (!mmc_can_erase(card)) { |
| 551 | err = -EOPNOTSUPP; |
| 552 | goto out; |
| 553 | } |
| 554 | |
| 555 | from = blk_rq_pos(req); |
| 556 | nr = blk_rq_sectors(req); |
| 557 | |
| 558 | if (mmc_can_trim(card)) |
| 559 | arg = MMC_TRIM_ARG; |
| 560 | else |
| 561 | arg = MMC_ERASE_ARG; |
| 562 | |
Andrei Warkentin | 6a7a6b4 | 2011-04-12 15:06:53 -0500 | [diff] [blame] | 563 | if (card->quirks & MMC_QUIRK_INAND_CMD38) { |
| 564 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
| 565 | INAND_CMD38_ARG_EXT_CSD, |
| 566 | arg == MMC_TRIM_ARG ? |
| 567 | INAND_CMD38_ARG_TRIM : |
| 568 | INAND_CMD38_ARG_ERASE, |
| 569 | 0); |
| 570 | if (err) |
| 571 | goto out; |
| 572 | } |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 573 | err = mmc_erase(card, from, nr, arg); |
| 574 | out: |
| 575 | spin_lock_irq(&md->lock); |
| 576 | __blk_end_request(req, err, blk_rq_bytes(req)); |
| 577 | spin_unlock_irq(&md->lock); |
| 578 | |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 579 | return err ? 0 : 1; |
| 580 | } |
| 581 | |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 582 | static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq, |
| 583 | struct request *req) |
| 584 | { |
| 585 | struct mmc_blk_data *md = mq->data; |
| 586 | struct mmc_card *card = md->queue.card; |
| 587 | unsigned int from, nr, arg; |
| 588 | int err = 0; |
| 589 | |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 590 | if (!mmc_can_secure_erase_trim(card)) { |
| 591 | err = -EOPNOTSUPP; |
| 592 | goto out; |
| 593 | } |
| 594 | |
| 595 | from = blk_rq_pos(req); |
| 596 | nr = blk_rq_sectors(req); |
| 597 | |
| 598 | if (mmc_can_trim(card) && !mmc_erase_group_aligned(card, from, nr)) |
| 599 | arg = MMC_SECURE_TRIM1_ARG; |
| 600 | else |
| 601 | arg = MMC_SECURE_ERASE_ARG; |
| 602 | |
Andrei Warkentin | 6a7a6b4 | 2011-04-12 15:06:53 -0500 | [diff] [blame] | 603 | if (card->quirks & MMC_QUIRK_INAND_CMD38) { |
| 604 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
| 605 | INAND_CMD38_ARG_EXT_CSD, |
| 606 | arg == MMC_SECURE_TRIM1_ARG ? |
| 607 | INAND_CMD38_ARG_SECTRIM1 : |
| 608 | INAND_CMD38_ARG_SECERASE, |
| 609 | 0); |
| 610 | if (err) |
| 611 | goto out; |
| 612 | } |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 613 | err = mmc_erase(card, from, nr, arg); |
Andrei Warkentin | 6a7a6b4 | 2011-04-12 15:06:53 -0500 | [diff] [blame] | 614 | if (!err && arg == MMC_SECURE_TRIM1_ARG) { |
| 615 | if (card->quirks & MMC_QUIRK_INAND_CMD38) { |
| 616 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
| 617 | INAND_CMD38_ARG_EXT_CSD, |
| 618 | INAND_CMD38_ARG_SECTRIM2, |
| 619 | 0); |
| 620 | if (err) |
| 621 | goto out; |
| 622 | } |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 623 | err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG); |
Andrei Warkentin | 6a7a6b4 | 2011-04-12 15:06:53 -0500 | [diff] [blame] | 624 | } |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 625 | out: |
| 626 | spin_lock_irq(&md->lock); |
| 627 | __blk_end_request(req, err, blk_rq_bytes(req)); |
| 628 | spin_unlock_irq(&md->lock); |
| 629 | |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 630 | return err ? 0 : 1; |
| 631 | } |
| 632 | |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 633 | static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req) |
| 634 | { |
| 635 | struct mmc_blk_data *md = mq->data; |
| 636 | |
| 637 | /* |
| 638 | * No-op, only service this because we need REQ_FUA for reliable |
| 639 | * writes. |
| 640 | */ |
| 641 | spin_lock_irq(&md->lock); |
| 642 | __blk_end_request_all(req, 0); |
| 643 | spin_unlock_irq(&md->lock); |
| 644 | |
| 645 | return 1; |
| 646 | } |
| 647 | |
| 648 | /* |
| 649 | * Reformat current write as a reliable write, supporting |
| 650 | * both legacy and the enhanced reliable write MMC cards. |
| 651 | * In each transfer we'll handle only as much as a single |
| 652 | * reliable write can handle, thus finish the request in |
| 653 | * partial completions. |
| 654 | */ |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 655 | static inline void mmc_apply_rel_rw(struct mmc_blk_request *brq, |
| 656 | struct mmc_card *card, |
| 657 | struct request *req) |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 658 | { |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 659 | if (!(card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN)) { |
| 660 | /* Legacy mode imposes restrictions on transfers. */ |
| 661 | if (!IS_ALIGNED(brq->cmd.arg, card->ext_csd.rel_sectors)) |
| 662 | brq->data.blocks = 1; |
| 663 | |
| 664 | if (brq->data.blocks > card->ext_csd.rel_sectors) |
| 665 | brq->data.blocks = card->ext_csd.rel_sectors; |
| 666 | else if (brq->data.blocks < card->ext_csd.rel_sectors) |
| 667 | brq->data.blocks = 1; |
| 668 | } |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 669 | } |
| 670 | |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 671 | static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | { |
| 673 | struct mmc_blk_data *md = mq->data; |
| 674 | struct mmc_card *card = md->queue.card; |
Pierre Ossman | 176f00f | 2006-10-04 02:15:41 -0700 | [diff] [blame] | 675 | struct mmc_blk_request brq; |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 676 | int ret = 1, disable_multi = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 678 | /* |
| 679 | * Reliable writes are used to implement Forced Unit Access and |
| 680 | * REQ_META accesses, and are supported only on MMCs. |
| 681 | */ |
| 682 | bool do_rel_wr = ((req->cmd_flags & REQ_FUA) || |
| 683 | (req->cmd_flags & REQ_META)) && |
| 684 | (rq_data_dir(req) == WRITE) && |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 685 | (md->flags & MMC_BLK_REL_WR); |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | do { |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 688 | u32 readcmd, writecmd, status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
| 690 | memset(&brq, 0, sizeof(struct mmc_blk_request)); |
| 691 | brq.mrq.cmd = &brq.cmd; |
| 692 | brq.mrq.data = &brq.data; |
| 693 | |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 694 | brq.cmd.arg = blk_rq_pos(req); |
Philip Langdale | fba68bd | 2007-01-04 06:57:32 -0800 | [diff] [blame] | 695 | if (!mmc_card_blockaddr(card)) |
| 696 | brq.cmd.arg <<= 9; |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 697 | brq.cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; |
Pierre Ossman | 0884669 | 2008-08-31 14:10:08 +0200 | [diff] [blame] | 698 | brq.data.blksz = 512; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | brq.stop.opcode = MMC_STOP_TRANSMISSION; |
| 700 | brq.stop.arg = 0; |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 701 | brq.stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 702 | brq.data.blocks = blk_rq_sectors(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 704 | /* |
Pierre Ossman | 548d2de | 2009-04-10 17:52:57 +0200 | [diff] [blame] | 705 | * The block layer doesn't support all sector count |
| 706 | * restrictions, so we need to be prepared for too big |
| 707 | * requests. |
| 708 | */ |
| 709 | if (brq.data.blocks > card->host->max_blk_count) |
| 710 | brq.data.blocks = card->host->max_blk_count; |
| 711 | |
| 712 | /* |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 713 | * After a read error, we redo the request one sector at a time |
| 714 | * in order to accurately determine which sectors can be read |
| 715 | * successfully. |
| 716 | */ |
| 717 | if (disable_multi && brq.data.blocks > 1) |
| 718 | brq.data.blocks = 1; |
| 719 | |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 720 | if (brq.data.blocks > 1 || do_rel_wr) { |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 721 | /* SPI multiblock writes terminate using a special |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 722 | * token, not a STOP_TRANSMISSION request. |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 723 | */ |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 724 | if (!mmc_host_is_spi(card->host) || |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 725 | rq_data_dir(req) == READ) |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 726 | brq.mrq.stop = &brq.stop; |
Russell King | db53f28 | 2006-08-30 15:14:56 +0100 | [diff] [blame] | 727 | readcmd = MMC_READ_MULTIPLE_BLOCK; |
| 728 | writecmd = MMC_WRITE_MULTIPLE_BLOCK; |
Russell King | 788ee7b | 2006-01-09 21:12:17 +0000 | [diff] [blame] | 729 | } else { |
| 730 | brq.mrq.stop = NULL; |
Russell King | db53f28 | 2006-08-30 15:14:56 +0100 | [diff] [blame] | 731 | readcmd = MMC_READ_SINGLE_BLOCK; |
| 732 | writecmd = MMC_WRITE_BLOCK; |
| 733 | } |
Russell King | db53f28 | 2006-08-30 15:14:56 +0100 | [diff] [blame] | 734 | if (rq_data_dir(req) == READ) { |
| 735 | brq.cmd.opcode = readcmd; |
| 736 | brq.data.flags |= MMC_DATA_READ; |
| 737 | } else { |
| 738 | brq.cmd.opcode = writecmd; |
| 739 | brq.data.flags |= MMC_DATA_WRITE; |
Russell King | 788ee7b | 2006-01-09 21:12:17 +0000 | [diff] [blame] | 740 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 742 | if (do_rel_wr) |
| 743 | mmc_apply_rel_rw(&brq, card, req); |
| 744 | |
| 745 | /* |
| 746 | * Pre-defined multi-block transfers are preferable to |
| 747 | * open ended-ones (and necessary for reliable writes). |
| 748 | * However, it is not sufficient to just send CMD23, |
| 749 | * and avoid the final CMD12, as on an error condition |
| 750 | * CMD12 (stop) needs to be sent anyway. This, coupled |
| 751 | * with Auto-CMD23 enhancements provided by some |
| 752 | * hosts, means that the complexity of dealing |
| 753 | * with this is best left to the host. If CMD23 is |
| 754 | * supported by card and host, we'll fill sbc in and let |
| 755 | * the host deal with handling it correctly. This means |
| 756 | * that for hosts that don't expose MMC_CAP_CMD23, no |
| 757 | * change of behavior will be observed. |
| 758 | * |
| 759 | * N.B: Some MMC cards experience perf degradation. |
| 760 | * We'll avoid using CMD23-bounded multiblock writes for |
| 761 | * these, while retaining features like reliable writes. |
| 762 | */ |
| 763 | |
| 764 | if ((md->flags & MMC_BLK_CMD23) && |
| 765 | mmc_op_multi(brq.cmd.opcode) && |
| 766 | (do_rel_wr || !(card->quirks & MMC_QUIRK_BLK_NO_CMD23))) { |
| 767 | brq.sbc.opcode = MMC_SET_BLOCK_COUNT; |
| 768 | brq.sbc.arg = brq.data.blocks | |
| 769 | (do_rel_wr ? (1 << 31) : 0); |
| 770 | brq.sbc.flags = MMC_RSP_R1 | MMC_CMD_AC; |
| 771 | brq.mrq.sbc = &brq.sbc; |
| 772 | } |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 773 | |
Pierre Ossman | b146d26 | 2007-07-24 19:16:54 +0200 | [diff] [blame] | 774 | mmc_set_data_timeout(&brq.data, card); |
| 775 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | brq.data.sg = mq->sg; |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 777 | brq.data.sg_len = mmc_queue_map_sg(mq); |
| 778 | |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 779 | /* |
| 780 | * Adjust the sg list so it is the same size as the |
| 781 | * request. |
| 782 | */ |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 783 | if (brq.data.blocks != blk_rq_sectors(req)) { |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 784 | int i, data_size = brq.data.blocks << 9; |
| 785 | struct scatterlist *sg; |
| 786 | |
| 787 | for_each_sg(brq.data.sg, sg, brq.data.sg_len, i) { |
| 788 | data_size -= sg->length; |
| 789 | if (data_size <= 0) { |
| 790 | sg->length += data_size; |
| 791 | i++; |
| 792 | break; |
| 793 | } |
| 794 | } |
| 795 | brq.data.sg_len = i; |
| 796 | } |
| 797 | |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 798 | mmc_queue_bounce_pre(mq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | |
| 800 | mmc_wait_for_req(card->host, &brq.mrq); |
Pierre Ossman | 98ccf14 | 2007-05-12 00:26:16 +0200 | [diff] [blame] | 801 | |
| 802 | mmc_queue_bounce_post(mq); |
| 803 | |
Pierre Ossman | 979ce72 | 2008-06-29 12:19:47 +0200 | [diff] [blame] | 804 | /* |
| 805 | * Check for errors here, but don't jump to cmd_err |
| 806 | * until later as we need to wait for the card to leave |
| 807 | * programming mode even when things go wrong. |
| 808 | */ |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 809 | if (brq.sbc.error || brq.cmd.error || |
| 810 | brq.data.error || brq.stop.error) { |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 811 | if (brq.data.blocks > 1 && rq_data_dir(req) == READ) { |
| 812 | /* Redo read one sector at a time */ |
| 813 | printk(KERN_WARNING "%s: retrying using single " |
| 814 | "block read\n", req->rq_disk->disk_name); |
| 815 | disable_multi = 1; |
| 816 | continue; |
| 817 | } |
Russell King - ARM Linux | 0a2d404 | 2011-06-20 20:10:08 +0100 | [diff] [blame^] | 818 | get_card_status(card, &status, 0); |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 819 | } |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 820 | |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 821 | if (brq.sbc.error) { |
| 822 | printk(KERN_ERR "%s: error %d sending SET_BLOCK_COUNT " |
| 823 | "command, response %#x, card status %#x\n", |
| 824 | req->rq_disk->disk_name, brq.sbc.error, |
| 825 | brq.sbc.resp[0], status); |
| 826 | } |
| 827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | if (brq.cmd.error) { |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 829 | printk(KERN_ERR "%s: error %d sending read/write " |
| 830 | "command, response %#x, card status %#x\n", |
| 831 | req->rq_disk->disk_name, brq.cmd.error, |
| 832 | brq.cmd.resp[0], status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | if (brq.data.error) { |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 836 | if (brq.data.error == -ETIMEDOUT && brq.mrq.stop) |
| 837 | /* 'Stop' response contains card status */ |
| 838 | status = brq.mrq.stop->resp[0]; |
| 839 | printk(KERN_ERR "%s: error %d transferring data," |
| 840 | " sector %u, nr %u, card status %#x\n", |
| 841 | req->rq_disk->disk_name, brq.data.error, |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 842 | (unsigned)blk_rq_pos(req), |
| 843 | (unsigned)blk_rq_sectors(req), status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | if (brq.stop.error) { |
Adrian Hunter | 504f191 | 2008-10-16 12:55:25 +0300 | [diff] [blame] | 847 | printk(KERN_ERR "%s: error %d sending stop command, " |
| 848 | "response %#x, card status %#x\n", |
| 849 | req->rq_disk->disk_name, brq.stop.error, |
| 850 | brq.stop.resp[0], status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | } |
| 852 | |
David Brownell | 7213d17 | 2007-08-08 09:10:23 -0700 | [diff] [blame] | 853 | if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) { |
Russell King | 2ed6d22 | 2006-09-24 10:46:43 +0100 | [diff] [blame] | 854 | do { |
Russell King - ARM Linux | 0a2d404 | 2011-06-20 20:10:08 +0100 | [diff] [blame^] | 855 | int err = get_card_status(card, &status, 5); |
Russell King | 2ed6d22 | 2006-09-24 10:46:43 +0100 | [diff] [blame] | 856 | if (err) { |
| 857 | printk(KERN_ERR "%s: error %d requesting status\n", |
| 858 | req->rq_disk->disk_name, err); |
| 859 | goto cmd_err; |
| 860 | } |
Pierre Ossman | d198f10 | 2007-11-02 18:21:13 +0100 | [diff] [blame] | 861 | /* |
| 862 | * Some cards mishandle the status bits, |
| 863 | * so make sure to check both the busy |
| 864 | * indication and the card state. |
| 865 | */ |
Russell King - ARM Linux | 0a2d404 | 2011-06-20 20:10:08 +0100 | [diff] [blame^] | 866 | } while (!(status & R1_READY_FOR_DATA) || |
| 867 | (R1_CURRENT_STATE(status) == R1_STATE_PRG)); |
Russell King | 2ed6d22 | 2006-09-24 10:46:43 +0100 | [diff] [blame] | 868 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 870 | if (brq.cmd.error || brq.stop.error || brq.data.error) { |
| 871 | if (rq_data_dir(req) == READ) { |
| 872 | /* |
| 873 | * After an error, we redo I/O one sector at a |
| 874 | * time, so we only reach here after trying to |
| 875 | * read a single sector. |
| 876 | */ |
| 877 | spin_lock_irq(&md->lock); |
| 878 | ret = __blk_end_request(req, -EIO, brq.data.blksz); |
| 879 | spin_unlock_irq(&md->lock); |
| 880 | continue; |
| 881 | } |
Pierre Ossman | 979ce72 | 2008-06-29 12:19:47 +0200 | [diff] [blame] | 882 | goto cmd_err; |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 883 | } |
Pierre Ossman | 979ce72 | 2008-06-29 12:19:47 +0200 | [diff] [blame] | 884 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | /* |
| 886 | * A block was successfully transferred. |
| 887 | */ |
| 888 | spin_lock_irq(&md->lock); |
Kiyoshi Ueda | fd53983 | 2007-12-11 17:48:29 -0500 | [diff] [blame] | 889 | ret = __blk_end_request(req, 0, brq.data.bytes_xfered); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | spin_unlock_irq(&md->lock); |
| 891 | } while (ret); |
| 892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | return 1; |
| 894 | |
| 895 | cmd_err: |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 896 | /* |
| 897 | * If this is an SD card and we're writing, we can first |
| 898 | * mark the known good sectors as ok. |
| 899 | * |
| 900 | * If the card is not SD, we can still ok written sectors |
Pierre Ossman | 23af603 | 2008-07-06 01:10:27 +0200 | [diff] [blame] | 901 | * as reported by the controller (which might be less than |
| 902 | * the real number of written sectors, but never more). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | */ |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 904 | if (mmc_card_sd(card)) { |
| 905 | u32 blocks; |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 906 | |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 907 | blocks = mmc_sd_num_wr_blocks(card); |
| 908 | if (blocks != (u32)-1) { |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 909 | spin_lock_irq(&md->lock); |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 910 | ret = __blk_end_request(req, 0, blocks << 9); |
Pierre Ossman | ec5a19d | 2006-10-06 00:44:03 -0700 | [diff] [blame] | 911 | spin_unlock_irq(&md->lock); |
| 912 | } |
Adrian Hunter | 6a79e39 | 2008-12-31 18:21:17 +0100 | [diff] [blame] | 913 | } else { |
| 914 | spin_lock_irq(&md->lock); |
| 915 | ret = __blk_end_request(req, 0, brq.data.bytes_xfered); |
| 916 | spin_unlock_irq(&md->lock); |
Pierre Ossman | 176f00f | 2006-10-04 02:15:41 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | spin_lock_irq(&md->lock); |
Kiyoshi Ueda | fd53983 | 2007-12-11 17:48:29 -0500 | [diff] [blame] | 920 | while (ret) |
| 921 | ret = __blk_end_request(req, -EIO, blk_rq_cur_bytes(req)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | spin_unlock_irq(&md->lock); |
| 923 | |
| 924 | return 0; |
| 925 | } |
| 926 | |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 927 | static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) |
| 928 | { |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 929 | int ret; |
| 930 | struct mmc_blk_data *md = mq->data; |
| 931 | struct mmc_card *card = md->queue.card; |
| 932 | |
| 933 | mmc_claim_host(card->host); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 934 | ret = mmc_blk_part_switch(card, md); |
| 935 | if (ret) { |
| 936 | ret = 0; |
| 937 | goto out; |
| 938 | } |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 939 | |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 940 | if (req->cmd_flags & REQ_DISCARD) { |
| 941 | if (req->cmd_flags & REQ_SECURE) |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 942 | ret = mmc_blk_issue_secdiscard_rq(mq, req); |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 943 | else |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 944 | ret = mmc_blk_issue_discard_rq(mq, req); |
Andrei Warkentin | f4c5522 | 2011-03-31 18:40:00 -0500 | [diff] [blame] | 945 | } else if (req->cmd_flags & REQ_FLUSH) { |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 946 | ret = mmc_blk_issue_flush(mq, req); |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 947 | } else { |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 948 | ret = mmc_blk_issue_rw_rq(mq, req); |
Adrian Hunter | 4980454 | 2010-08-11 14:17:50 -0700 | [diff] [blame] | 949 | } |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 950 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 951 | out: |
Andrei Warkentin | 1a258db | 2011-04-11 18:10:24 -0500 | [diff] [blame] | 952 | mmc_release_host(card->host); |
| 953 | return ret; |
Adrian Hunter | bd788c9 | 2010-08-11 14:17:47 -0700 | [diff] [blame] | 954 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 956 | static inline int mmc_blk_readonly(struct mmc_card *card) |
| 957 | { |
| 958 | return mmc_card_readonly(card) || |
| 959 | !(card->csd.cmdclass & CCC_BLOCK_WRITE); |
| 960 | } |
| 961 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 962 | static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, |
| 963 | struct device *parent, |
| 964 | sector_t size, |
| 965 | bool default_ro, |
| 966 | const char *subname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | { |
| 968 | struct mmc_blk_data *md; |
| 969 | int devidx, ret; |
| 970 | |
Olof Johansson | 5e71b7a | 2010-09-17 21:19:57 -0400 | [diff] [blame] | 971 | devidx = find_first_zero_bit(dev_use, max_devices); |
| 972 | if (devidx >= max_devices) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | return ERR_PTR(-ENOSPC); |
| 974 | __set_bit(devidx, dev_use); |
| 975 | |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 976 | md = kzalloc(sizeof(struct mmc_blk_data), GFP_KERNEL); |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 977 | if (!md) { |
| 978 | ret = -ENOMEM; |
| 979 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | } |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 981 | |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 982 | /* |
Andrei Warkentin | f06c915 | 2011-04-21 22:46:13 -0500 | [diff] [blame] | 983 | * !subname implies we are creating main mmc_blk_data that will be |
| 984 | * associated with mmc_card with mmc_set_drvdata. Due to device |
| 985 | * partitions, devidx will not coincide with a per-physical card |
| 986 | * index anymore so we keep track of a name index. |
| 987 | */ |
| 988 | if (!subname) { |
| 989 | md->name_idx = find_first_zero_bit(name_use, max_devices); |
| 990 | __set_bit(md->name_idx, name_use); |
| 991 | } |
| 992 | else |
| 993 | md->name_idx = ((struct mmc_blk_data *) |
| 994 | dev_to_disk(parent)->private_data)->name_idx; |
| 995 | |
| 996 | /* |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 997 | * Set the read-only status based on the supported commands |
| 998 | * and the write protect switch. |
| 999 | */ |
| 1000 | md->read_only = mmc_blk_readonly(card); |
| 1001 | |
Olof Johansson | 5e71b7a | 2010-09-17 21:19:57 -0400 | [diff] [blame] | 1002 | md->disk = alloc_disk(perdev_minors); |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1003 | if (md->disk == NULL) { |
| 1004 | ret = -ENOMEM; |
| 1005 | goto err_kfree; |
| 1006 | } |
| 1007 | |
| 1008 | spin_lock_init(&md->lock); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1009 | INIT_LIST_HEAD(&md->part); |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1010 | md->usage = 1; |
| 1011 | |
Adrian Hunter | d09408a | 2011-06-23 13:40:28 +0300 | [diff] [blame] | 1012 | ret = mmc_init_queue(&md->queue, card, &md->lock, subname); |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1013 | if (ret) |
| 1014 | goto err_putdisk; |
| 1015 | |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1016 | md->queue.issue_fn = mmc_blk_issue_rq; |
| 1017 | md->queue.data = md; |
| 1018 | |
Pierre Ossman | fe6b4c8 | 2007-05-14 17:27:29 +0200 | [diff] [blame] | 1019 | md->disk->major = MMC_BLOCK_MAJOR; |
Olof Johansson | 5e71b7a | 2010-09-17 21:19:57 -0400 | [diff] [blame] | 1020 | md->disk->first_minor = devidx * perdev_minors; |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1021 | md->disk->fops = &mmc_bdops; |
| 1022 | md->disk->private_data = md; |
| 1023 | md->disk->queue = md->queue.queue; |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1024 | md->disk->driverfs_dev = parent; |
| 1025 | set_disk_ro(md->disk, md->read_only || default_ro); |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1026 | |
| 1027 | /* |
| 1028 | * As discussed on lkml, GENHD_FL_REMOVABLE should: |
| 1029 | * |
| 1030 | * - be set for removable media with permanent block devices |
| 1031 | * - be unset for removable block devices with permanent media |
| 1032 | * |
| 1033 | * Since MMC block devices clearly fall under the second |
| 1034 | * case, we do not set GENHD_FL_REMOVABLE. Userspace |
| 1035 | * should use the block device creation/destruction hotplug |
| 1036 | * messages to tell when the card is present. |
| 1037 | */ |
| 1038 | |
Andrei Warkentin | f06c915 | 2011-04-21 22:46:13 -0500 | [diff] [blame] | 1039 | snprintf(md->disk->disk_name, sizeof(md->disk->disk_name), |
| 1040 | "mmcblk%d%s", md->name_idx, subname ? subname : ""); |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1041 | |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 1042 | blk_queue_logical_block_size(md->queue.queue, 512); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1043 | set_capacity(md->disk, size); |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 1044 | |
Andrei Warkentin | f0d8997 | 2011-05-23 15:06:38 -0500 | [diff] [blame] | 1045 | if (mmc_host_cmd23(card->host)) { |
| 1046 | if (mmc_card_mmc(card) || |
| 1047 | (mmc_card_sd(card) && |
| 1048 | card->scr.cmds & SD_SCR_CMD23_SUPPORT)) |
| 1049 | md->flags |= MMC_BLK_CMD23; |
| 1050 | } |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 1051 | |
| 1052 | if (mmc_card_mmc(card) && |
| 1053 | md->flags & MMC_BLK_CMD23 && |
| 1054 | ((card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN) || |
| 1055 | card->ext_csd.rel_sectors)) { |
| 1056 | md->flags |= MMC_BLK_REL_WR; |
| 1057 | blk_queue_flush(md->queue.queue, REQ_FLUSH | REQ_FUA); |
| 1058 | } |
| 1059 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | return md; |
Russell King | a6f6c96 | 2006-01-03 22:38:44 +0000 | [diff] [blame] | 1061 | |
| 1062 | err_putdisk: |
| 1063 | put_disk(md->disk); |
| 1064 | err_kfree: |
| 1065 | kfree(md); |
| 1066 | out: |
| 1067 | return ERR_PTR(ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1070 | static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card) |
| 1071 | { |
| 1072 | sector_t size; |
| 1073 | struct mmc_blk_data *md; |
| 1074 | |
| 1075 | if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) { |
| 1076 | /* |
| 1077 | * The EXT_CSD sector count is in number or 512 byte |
| 1078 | * sectors. |
| 1079 | */ |
| 1080 | size = card->ext_csd.sectors; |
| 1081 | } else { |
| 1082 | /* |
| 1083 | * The CSD capacity field is in units of read_blkbits. |
| 1084 | * set_capacity takes units of 512 bytes. |
| 1085 | */ |
| 1086 | size = card->csd.capacity << (card->csd.read_blkbits - 9); |
| 1087 | } |
| 1088 | |
| 1089 | md = mmc_blk_alloc_req(card, &card->dev, size, false, NULL); |
| 1090 | return md; |
| 1091 | } |
| 1092 | |
| 1093 | static int mmc_blk_alloc_part(struct mmc_card *card, |
| 1094 | struct mmc_blk_data *md, |
| 1095 | unsigned int part_type, |
| 1096 | sector_t size, |
| 1097 | bool default_ro, |
| 1098 | const char *subname) |
| 1099 | { |
| 1100 | char cap_str[10]; |
| 1101 | struct mmc_blk_data *part_md; |
| 1102 | |
| 1103 | part_md = mmc_blk_alloc_req(card, disk_to_dev(md->disk), size, default_ro, |
| 1104 | subname); |
| 1105 | if (IS_ERR(part_md)) |
| 1106 | return PTR_ERR(part_md); |
| 1107 | part_md->part_type = part_type; |
| 1108 | list_add(&part_md->part, &md->part); |
| 1109 | |
| 1110 | string_get_size((u64)get_capacity(part_md->disk) << 9, STRING_UNITS_2, |
| 1111 | cap_str, sizeof(cap_str)); |
| 1112 | printk(KERN_INFO "%s: %s %s partition %u %s\n", |
| 1113 | part_md->disk->disk_name, mmc_card_id(card), |
| 1114 | mmc_card_name(card), part_md->part_type, cap_str); |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
| 1118 | static int mmc_blk_alloc_parts(struct mmc_card *card, struct mmc_blk_data *md) |
| 1119 | { |
| 1120 | int ret = 0; |
| 1121 | |
| 1122 | if (!mmc_card_mmc(card)) |
| 1123 | return 0; |
| 1124 | |
| 1125 | if (card->ext_csd.boot_size) { |
| 1126 | ret = mmc_blk_alloc_part(card, md, EXT_CSD_PART_CONFIG_ACC_BOOT0, |
| 1127 | card->ext_csd.boot_size >> 9, |
| 1128 | true, |
| 1129 | "boot0"); |
| 1130 | if (ret) |
| 1131 | return ret; |
| 1132 | ret = mmc_blk_alloc_part(card, md, EXT_CSD_PART_CONFIG_ACC_BOOT1, |
| 1133 | card->ext_csd.boot_size >> 9, |
| 1134 | true, |
| 1135 | "boot1"); |
| 1136 | if (ret) |
| 1137 | return ret; |
| 1138 | } |
| 1139 | |
| 1140 | return ret; |
| 1141 | } |
| 1142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | static int |
| 1144 | mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card) |
| 1145 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | int err; |
| 1147 | |
Pierre Ossman | b855885 | 2007-01-03 19:47:29 +0100 | [diff] [blame] | 1148 | mmc_claim_host(card->host); |
Adrian Hunter | 0f8d8ea | 2010-08-24 13:20:26 +0300 | [diff] [blame] | 1149 | err = mmc_set_blocklen(card, 512); |
Pierre Ossman | b855885 | 2007-01-03 19:47:29 +0100 | [diff] [blame] | 1150 | mmc_release_host(card->host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | |
| 1152 | if (err) { |
Adrian Hunter | 0f8d8ea | 2010-08-24 13:20:26 +0300 | [diff] [blame] | 1153 | printk(KERN_ERR "%s: unable to set block size to 512: %d\n", |
| 1154 | md->disk->disk_name, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | return -EINVAL; |
| 1156 | } |
| 1157 | |
| 1158 | return 0; |
| 1159 | } |
| 1160 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1161 | static void mmc_blk_remove_req(struct mmc_blk_data *md) |
| 1162 | { |
| 1163 | if (md) { |
| 1164 | if (md->disk->flags & GENHD_FL_UP) { |
| 1165 | device_remove_file(disk_to_dev(md->disk), &md->force_ro); |
| 1166 | |
| 1167 | /* Stop new requests from getting into the queue */ |
| 1168 | del_gendisk(md->disk); |
| 1169 | } |
| 1170 | |
| 1171 | /* Then flush out any already in there */ |
| 1172 | mmc_cleanup_queue(&md->queue); |
| 1173 | mmc_blk_put(md); |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | static void mmc_blk_remove_parts(struct mmc_card *card, |
| 1178 | struct mmc_blk_data *md) |
| 1179 | { |
| 1180 | struct list_head *pos, *q; |
| 1181 | struct mmc_blk_data *part_md; |
| 1182 | |
Andrei Warkentin | f06c915 | 2011-04-21 22:46:13 -0500 | [diff] [blame] | 1183 | __clear_bit(md->name_idx, name_use); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1184 | list_for_each_safe(pos, q, &md->part) { |
| 1185 | part_md = list_entry(pos, struct mmc_blk_data, part); |
| 1186 | list_del(pos); |
| 1187 | mmc_blk_remove_req(part_md); |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | static int mmc_add_disk(struct mmc_blk_data *md) |
| 1192 | { |
| 1193 | int ret; |
| 1194 | |
| 1195 | add_disk(md->disk); |
| 1196 | md->force_ro.show = force_ro_show; |
| 1197 | md->force_ro.store = force_ro_store; |
Rabin Vincent | 641c318 | 2011-04-23 20:52:58 +0530 | [diff] [blame] | 1198 | sysfs_attr_init(&md->force_ro.attr); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1199 | md->force_ro.attr.name = "force_ro"; |
| 1200 | md->force_ro.attr.mode = S_IRUGO | S_IWUSR; |
| 1201 | ret = device_create_file(disk_to_dev(md->disk), &md->force_ro); |
| 1202 | if (ret) |
| 1203 | del_gendisk(md->disk); |
| 1204 | |
| 1205 | return ret; |
| 1206 | } |
| 1207 | |
Andrei Warkentin | 6f60c22 | 2011-04-11 19:11:04 -0400 | [diff] [blame] | 1208 | static const struct mmc_fixup blk_fixups[] = |
| 1209 | { |
Andrei Warkentin | 6a7a6b4 | 2011-04-12 15:06:53 -0500 | [diff] [blame] | 1210 | MMC_FIXUP("SEM02G", 0x2, 0x100, add_quirk, MMC_QUIRK_INAND_CMD38), |
| 1211 | MMC_FIXUP("SEM04G", 0x2, 0x100, add_quirk, MMC_QUIRK_INAND_CMD38), |
| 1212 | MMC_FIXUP("SEM08G", 0x2, 0x100, add_quirk, MMC_QUIRK_INAND_CMD38), |
| 1213 | MMC_FIXUP("SEM16G", 0x2, 0x100, add_quirk, MMC_QUIRK_INAND_CMD38), |
| 1214 | MMC_FIXUP("SEM32G", 0x2, 0x100, add_quirk, MMC_QUIRK_INAND_CMD38), |
Andrei Warkentin | d0c97cf | 2011-05-23 15:06:36 -0500 | [diff] [blame] | 1215 | |
| 1216 | /* |
| 1217 | * Some MMC cards experience performance degradation with CMD23 |
| 1218 | * instead of CMD12-bounded multiblock transfers. For now we'll |
| 1219 | * black list what's bad... |
| 1220 | * - Certain Toshiba cards. |
| 1221 | * |
| 1222 | * N.B. This doesn't affect SD cards. |
| 1223 | */ |
| 1224 | MMC_FIXUP("MMC08G", 0x11, CID_OEMID_ANY, add_quirk_mmc, |
| 1225 | MMC_QUIRK_BLK_NO_CMD23), |
| 1226 | MMC_FIXUP("MMC16G", 0x11, CID_OEMID_ANY, add_quirk_mmc, |
| 1227 | MMC_QUIRK_BLK_NO_CMD23), |
| 1228 | MMC_FIXUP("MMC32G", 0x11, CID_OEMID_ANY, add_quirk_mmc, |
| 1229 | MMC_QUIRK_BLK_NO_CMD23), |
Andrei Warkentin | 6f60c22 | 2011-04-11 19:11:04 -0400 | [diff] [blame] | 1230 | END_FIXUP |
| 1231 | }; |
| 1232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | static int mmc_blk_probe(struct mmc_card *card) |
| 1234 | { |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1235 | struct mmc_blk_data *md, *part_md; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | int err; |
Pierre Ossman | a7bbb57 | 2008-09-06 10:57:57 +0200 | [diff] [blame] | 1237 | char cap_str[10]; |
| 1238 | |
Pierre Ossman | 912490d | 2005-05-21 10:27:02 +0100 | [diff] [blame] | 1239 | /* |
| 1240 | * Check that the card supports the command class(es) we need. |
| 1241 | */ |
| 1242 | if (!(card->csd.cmdclass & CCC_BLOCK_READ)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | return -ENODEV; |
| 1244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | md = mmc_blk_alloc(card); |
| 1246 | if (IS_ERR(md)) |
| 1247 | return PTR_ERR(md); |
| 1248 | |
| 1249 | err = mmc_blk_set_blksize(md, card); |
| 1250 | if (err) |
| 1251 | goto out; |
| 1252 | |
Yi Li | 444122f | 2009-02-05 15:31:57 +0800 | [diff] [blame] | 1253 | string_get_size((u64)get_capacity(md->disk) << 9, STRING_UNITS_2, |
Pierre Ossman | a7bbb57 | 2008-09-06 10:57:57 +0200 | [diff] [blame] | 1254 | cap_str, sizeof(cap_str)); |
| 1255 | printk(KERN_INFO "%s: %s %s %s %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | md->disk->disk_name, mmc_card_id(card), mmc_card_name(card), |
Pierre Ossman | a7bbb57 | 2008-09-06 10:57:57 +0200 | [diff] [blame] | 1257 | cap_str, md->read_only ? "(ro)" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1259 | if (mmc_blk_alloc_parts(card, md)) |
| 1260 | goto out; |
| 1261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | mmc_set_drvdata(card, md); |
Andrei Warkentin | 6f60c22 | 2011-04-11 19:11:04 -0400 | [diff] [blame] | 1263 | mmc_fixup_device(card, blk_fixups); |
| 1264 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1265 | if (mmc_add_disk(md)) |
| 1266 | goto out; |
| 1267 | |
| 1268 | list_for_each_entry(part_md, &md->part, part) { |
| 1269 | if (mmc_add_disk(part_md)) |
| 1270 | goto out; |
| 1271 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | return 0; |
| 1273 | |
| 1274 | out: |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1275 | mmc_blk_remove_parts(card, md); |
| 1276 | mmc_blk_remove_req(md); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | return err; |
| 1278 | } |
| 1279 | |
| 1280 | static void mmc_blk_remove(struct mmc_card *card) |
| 1281 | { |
| 1282 | struct mmc_blk_data *md = mmc_get_drvdata(card); |
| 1283 | |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1284 | mmc_blk_remove_parts(card, md); |
Adrian Hunter | ddd6fa7 | 2011-06-23 13:40:26 +0300 | [diff] [blame] | 1285 | mmc_claim_host(card->host); |
| 1286 | mmc_blk_part_switch(card, md); |
| 1287 | mmc_release_host(card->host); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1288 | mmc_blk_remove_req(md); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | mmc_set_drvdata(card, NULL); |
| 1290 | } |
| 1291 | |
| 1292 | #ifdef CONFIG_PM |
| 1293 | static int mmc_blk_suspend(struct mmc_card *card, pm_message_t state) |
| 1294 | { |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1295 | struct mmc_blk_data *part_md; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | struct mmc_blk_data *md = mmc_get_drvdata(card); |
| 1297 | |
| 1298 | if (md) { |
| 1299 | mmc_queue_suspend(&md->queue); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1300 | list_for_each_entry(part_md, &md->part, part) { |
| 1301 | mmc_queue_suspend(&part_md->queue); |
| 1302 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | } |
| 1304 | return 0; |
| 1305 | } |
| 1306 | |
| 1307 | static int mmc_blk_resume(struct mmc_card *card) |
| 1308 | { |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1309 | struct mmc_blk_data *part_md; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | struct mmc_blk_data *md = mmc_get_drvdata(card); |
| 1311 | |
| 1312 | if (md) { |
| 1313 | mmc_blk_set_blksize(md, card); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1314 | |
| 1315 | /* |
| 1316 | * Resume involves the card going into idle state, |
| 1317 | * so current partition is always the main one. |
| 1318 | */ |
| 1319 | md->part_curr = md->part_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | mmc_queue_resume(&md->queue); |
Andrei Warkentin | 371a689 | 2011-04-11 18:10:25 -0500 | [diff] [blame] | 1321 | list_for_each_entry(part_md, &md->part, part) { |
| 1322 | mmc_queue_resume(&part_md->queue); |
| 1323 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | } |
| 1325 | return 0; |
| 1326 | } |
| 1327 | #else |
| 1328 | #define mmc_blk_suspend NULL |
| 1329 | #define mmc_blk_resume NULL |
| 1330 | #endif |
| 1331 | |
| 1332 | static struct mmc_driver mmc_driver = { |
| 1333 | .drv = { |
| 1334 | .name = "mmcblk", |
| 1335 | }, |
| 1336 | .probe = mmc_blk_probe, |
| 1337 | .remove = mmc_blk_remove, |
| 1338 | .suspend = mmc_blk_suspend, |
| 1339 | .resume = mmc_blk_resume, |
| 1340 | }; |
| 1341 | |
| 1342 | static int __init mmc_blk_init(void) |
| 1343 | { |
Akinobu Mita | 9d4e98e | 2008-09-13 19:02:07 +0900 | [diff] [blame] | 1344 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | |
Olof Johansson | 5e71b7a | 2010-09-17 21:19:57 -0400 | [diff] [blame] | 1346 | if (perdev_minors != CONFIG_MMC_BLOCK_MINORS) |
| 1347 | pr_info("mmcblk: using %d minors per device\n", perdev_minors); |
| 1348 | |
| 1349 | max_devices = 256 / perdev_minors; |
| 1350 | |
Pierre Ossman | fe6b4c8 | 2007-05-14 17:27:29 +0200 | [diff] [blame] | 1351 | res = register_blkdev(MMC_BLOCK_MAJOR, "mmc"); |
| 1352 | if (res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | |
Akinobu Mita | 9d4e98e | 2008-09-13 19:02:07 +0900 | [diff] [blame] | 1355 | res = mmc_register_driver(&mmc_driver); |
| 1356 | if (res) |
| 1357 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | |
Akinobu Mita | 9d4e98e | 2008-09-13 19:02:07 +0900 | [diff] [blame] | 1359 | return 0; |
| 1360 | out2: |
| 1361 | unregister_blkdev(MMC_BLOCK_MAJOR, "mmc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | out: |
| 1363 | return res; |
| 1364 | } |
| 1365 | |
| 1366 | static void __exit mmc_blk_exit(void) |
| 1367 | { |
| 1368 | mmc_unregister_driver(&mmc_driver); |
Pierre Ossman | fe6b4c8 | 2007-05-14 17:27:29 +0200 | [diff] [blame] | 1369 | unregister_blkdev(MMC_BLOCK_MAJOR, "mmc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | module_init(mmc_blk_init); |
| 1373 | module_exit(mmc_blk_exit); |
| 1374 | |
| 1375 | MODULE_LICENSE("GPL"); |
| 1376 | MODULE_DESCRIPTION("Multimedia Card (MMC) block device driver"); |
| 1377 | |