Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * dcssblk.c -- the S/390 block driver for dcss memory |
| 3 | * |
| 4 | * Authors: Carsten Otte, Stefan Weinhuber, Gerald Schaefer |
| 5 | */ |
| 6 | |
Hongjie Yang | 93098bf | 2008-12-25 13:39:45 +0100 | [diff] [blame] | 7 | #define KMSG_COMPONENT "dcssblk" |
| 8 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/module.h> |
| 11 | #include <linux/moduleparam.h> |
| 12 | #include <linux/ctype.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/blkdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/completion.h> |
| 18 | #include <linux/interrupt.h> |
Gerald Schaefer | c369527 | 2009-06-16 10:30:51 +0200 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
| 20 | #include <asm/extmem.h> |
| 21 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #define DCSSBLK_NAME "dcssblk" |
| 24 | #define DCSSBLK_MINORS_PER_DISK 1 |
| 25 | #define DCSSBLK_PARM_LEN 400 |
Kay Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 26 | #define DCSS_BUS_ID_SIZE 20 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Al Viro | 46d7432 | 2008-03-02 10:37:41 -0500 | [diff] [blame] | 28 | static int dcssblk_open(struct block_device *bdev, fmode_t mode); |
Al Viro | db2a144 | 2013-05-05 21:52:57 -0400 | [diff] [blame] | 29 | static void dcssblk_release(struct gendisk *disk, fmode_t mode); |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 30 | static void dcssblk_make_request(struct request_queue *q, struct bio *bio); |
Matthew Wilcox | dd22f55 | 2015-01-07 18:05:34 +0200 | [diff] [blame] | 31 | static long dcssblk_direct_access(struct block_device *bdev, sector_t secnum, |
| 32 | void **kaddr, unsigned long *pfn, long size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | static char dcssblk_segments[DCSSBLK_PARM_LEN] = "\0"; |
| 35 | |
| 36 | static int dcssblk_major; |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 37 | static const struct block_device_operations dcssblk_devops = { |
Carsten Otte | 420edbc | 2005-06-23 22:05:23 -0700 | [diff] [blame] | 38 | .owner = THIS_MODULE, |
Al Viro | 46d7432 | 2008-03-02 10:37:41 -0500 | [diff] [blame] | 39 | .open = dcssblk_open, |
| 40 | .release = dcssblk_release, |
Carsten Otte | 420edbc | 2005-06-23 22:05:23 -0700 | [diff] [blame] | 41 | .direct_access = dcssblk_direct_access, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | struct dcssblk_dev_info { |
| 45 | struct list_head lh; |
| 46 | struct device dev; |
Kay Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 47 | char segment_name[DCSS_BUS_ID_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | atomic_t use_count; |
| 49 | struct gendisk *gd; |
| 50 | unsigned long start; |
| 51 | unsigned long end; |
| 52 | int segment_type; |
| 53 | unsigned char save_pending; |
| 54 | unsigned char is_shared; |
| 55 | struct request_queue *dcssblk_queue; |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 56 | int num_of_segments; |
| 57 | struct list_head seg_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 60 | struct segment_info { |
| 61 | struct list_head lh; |
Kay Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 62 | char segment_name[DCSS_BUS_ID_SIZE]; |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 63 | unsigned long start; |
| 64 | unsigned long end; |
| 65 | int segment_type; |
| 66 | }; |
| 67 | |
| 68 | static ssize_t dcssblk_add_store(struct device * dev, struct device_attribute *attr, const char * buf, |
| 69 | size_t count); |
| 70 | static ssize_t dcssblk_remove_store(struct device * dev, struct device_attribute *attr, const char * buf, |
| 71 | size_t count); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 72 | |
| 73 | static DEVICE_ATTR(add, S_IWUSR, NULL, dcssblk_add_store); |
| 74 | static DEVICE_ATTR(remove, S_IWUSR, NULL, dcssblk_remove_store); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 75 | |
| 76 | static struct device *dcssblk_root_dev; |
| 77 | |
Denis Cheng | c11ca97 | 2008-01-26 14:11:13 +0100 | [diff] [blame] | 78 | static LIST_HEAD(dcssblk_devices); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | static struct rw_semaphore dcssblk_devices_sem; |
| 80 | |
| 81 | /* |
| 82 | * release function for segment device. |
| 83 | */ |
| 84 | static void |
| 85 | dcssblk_release_segment(struct device *dev) |
| 86 | { |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 87 | struct dcssblk_dev_info *dev_info; |
| 88 | struct segment_info *entry, *temp; |
| 89 | |
| 90 | dev_info = container_of(dev, struct dcssblk_dev_info, dev); |
| 91 | list_for_each_entry_safe(entry, temp, &dev_info->seg_list, lh) { |
| 92 | list_del(&entry->lh); |
| 93 | kfree(entry); |
| 94 | } |
| 95 | kfree(dev_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | module_put(THIS_MODULE); |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * get a minor number. needs to be called with |
| 101 | * down_write(&dcssblk_devices_sem) and the |
| 102 | * device needs to be enqueued before the semaphore is |
| 103 | * freed. |
| 104 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 105 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | dcssblk_assign_free_minor(struct dcssblk_dev_info *dev_info) |
| 107 | { |
| 108 | int minor, found; |
| 109 | struct dcssblk_dev_info *entry; |
| 110 | |
| 111 | if (dev_info == NULL) |
| 112 | return -EINVAL; |
| 113 | for (minor = 0; minor < (1<<MINORBITS); minor++) { |
| 114 | found = 0; |
| 115 | // test if minor available |
| 116 | list_for_each_entry(entry, &dcssblk_devices, lh) |
Gerald Schaefer | d059148 | 2009-06-12 10:26:35 +0200 | [diff] [blame] | 117 | if (minor == entry->gd->first_minor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | found++; |
| 119 | if (!found) break; // got unused minor |
| 120 | } |
| 121 | if (found) |
| 122 | return -EBUSY; |
| 123 | dev_info->gd->first_minor = minor; |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * get the struct dcssblk_dev_info from dcssblk_devices |
| 129 | * for the given name. |
| 130 | * down_read(&dcssblk_devices_sem) must be held. |
| 131 | */ |
| 132 | static struct dcssblk_dev_info * |
| 133 | dcssblk_get_device_by_name(char *name) |
| 134 | { |
| 135 | struct dcssblk_dev_info *entry; |
| 136 | |
| 137 | list_for_each_entry(entry, &dcssblk_devices, lh) { |
| 138 | if (!strcmp(name, entry->segment_name)) { |
| 139 | return entry; |
| 140 | } |
| 141 | } |
| 142 | return NULL; |
| 143 | } |
| 144 | |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 145 | /* |
| 146 | * get the struct segment_info from seg_list |
| 147 | * for the given name. |
| 148 | * down_read(&dcssblk_devices_sem) must be held. |
| 149 | */ |
| 150 | static struct segment_info * |
| 151 | dcssblk_get_segment_by_name(char *name) |
| 152 | { |
| 153 | struct dcssblk_dev_info *dev_info; |
| 154 | struct segment_info *entry; |
| 155 | |
| 156 | list_for_each_entry(dev_info, &dcssblk_devices, lh) { |
| 157 | list_for_each_entry(entry, &dev_info->seg_list, lh) { |
| 158 | if (!strcmp(name, entry->segment_name)) |
| 159 | return entry; |
| 160 | } |
| 161 | } |
| 162 | return NULL; |
| 163 | } |
| 164 | |
| 165 | /* |
| 166 | * get the highest address of the multi-segment block. |
| 167 | */ |
| 168 | static unsigned long |
| 169 | dcssblk_find_highest_addr(struct dcssblk_dev_info *dev_info) |
| 170 | { |
| 171 | unsigned long highest_addr; |
| 172 | struct segment_info *entry; |
| 173 | |
| 174 | highest_addr = 0; |
| 175 | list_for_each_entry(entry, &dev_info->seg_list, lh) { |
| 176 | if (highest_addr < entry->end) |
| 177 | highest_addr = entry->end; |
| 178 | } |
| 179 | return highest_addr; |
| 180 | } |
| 181 | |
| 182 | /* |
| 183 | * get the lowest address of the multi-segment block. |
| 184 | */ |
| 185 | static unsigned long |
| 186 | dcssblk_find_lowest_addr(struct dcssblk_dev_info *dev_info) |
| 187 | { |
| 188 | int set_first; |
| 189 | unsigned long lowest_addr; |
| 190 | struct segment_info *entry; |
| 191 | |
| 192 | set_first = 0; |
| 193 | lowest_addr = 0; |
| 194 | list_for_each_entry(entry, &dev_info->seg_list, lh) { |
| 195 | if (set_first == 0) { |
| 196 | lowest_addr = entry->start; |
| 197 | set_first = 1; |
| 198 | } else { |
| 199 | if (lowest_addr > entry->start) |
| 200 | lowest_addr = entry->start; |
| 201 | } |
| 202 | } |
| 203 | return lowest_addr; |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * Check continuity of segments. |
| 208 | */ |
| 209 | static int |
| 210 | dcssblk_is_continuous(struct dcssblk_dev_info *dev_info) |
| 211 | { |
| 212 | int i, j, rc; |
| 213 | struct segment_info *sort_list, *entry, temp; |
| 214 | |
| 215 | if (dev_info->num_of_segments <= 1) |
| 216 | return 0; |
| 217 | |
| 218 | sort_list = kzalloc( |
| 219 | sizeof(struct segment_info) * dev_info->num_of_segments, |
| 220 | GFP_KERNEL); |
| 221 | if (sort_list == NULL) |
| 222 | return -ENOMEM; |
| 223 | i = 0; |
| 224 | list_for_each_entry(entry, &dev_info->seg_list, lh) { |
| 225 | memcpy(&sort_list[i], entry, sizeof(struct segment_info)); |
| 226 | i++; |
| 227 | } |
| 228 | |
| 229 | /* sort segments */ |
| 230 | for (i = 0; i < dev_info->num_of_segments; i++) |
| 231 | for (j = 0; j < dev_info->num_of_segments; j++) |
| 232 | if (sort_list[j].start > sort_list[i].start) { |
| 233 | memcpy(&temp, &sort_list[i], |
| 234 | sizeof(struct segment_info)); |
| 235 | memcpy(&sort_list[i], &sort_list[j], |
| 236 | sizeof(struct segment_info)); |
| 237 | memcpy(&sort_list[j], &temp, |
| 238 | sizeof(struct segment_info)); |
| 239 | } |
| 240 | |
| 241 | /* check continuity */ |
| 242 | for (i = 0; i < dev_info->num_of_segments - 1; i++) { |
| 243 | if ((sort_list[i].end + 1) != sort_list[i+1].start) { |
Hongjie Yang | 93098bf | 2008-12-25 13:39:45 +0100 | [diff] [blame] | 244 | pr_err("Adjacent DCSSs %s and %s are not " |
| 245 | "contiguous\n", sort_list[i].segment_name, |
| 246 | sort_list[i+1].segment_name); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 247 | rc = -EINVAL; |
| 248 | goto out; |
| 249 | } |
| 250 | /* EN and EW are allowed in a block device */ |
| 251 | if (sort_list[i].segment_type != sort_list[i+1].segment_type) { |
| 252 | if (!(sort_list[i].segment_type & SEGMENT_EXCLUSIVE) || |
| 253 | (sort_list[i].segment_type == SEG_TYPE_ER) || |
| 254 | !(sort_list[i+1].segment_type & |
| 255 | SEGMENT_EXCLUSIVE) || |
| 256 | (sort_list[i+1].segment_type == SEG_TYPE_ER)) { |
Hongjie Yang | 93098bf | 2008-12-25 13:39:45 +0100 | [diff] [blame] | 257 | pr_err("DCSS %s and DCSS %s have " |
| 258 | "incompatible types\n", |
| 259 | sort_list[i].segment_name, |
| 260 | sort_list[i+1].segment_name); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 261 | rc = -EINVAL; |
| 262 | goto out; |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | rc = 0; |
| 267 | out: |
| 268 | kfree(sort_list); |
| 269 | return rc; |
| 270 | } |
| 271 | |
| 272 | /* |
| 273 | * Load a segment |
| 274 | */ |
| 275 | static int |
| 276 | dcssblk_load_segment(char *name, struct segment_info **seg_info) |
| 277 | { |
| 278 | int rc; |
| 279 | |
| 280 | /* already loaded? */ |
| 281 | down_read(&dcssblk_devices_sem); |
| 282 | *seg_info = dcssblk_get_segment_by_name(name); |
| 283 | up_read(&dcssblk_devices_sem); |
| 284 | if (*seg_info != NULL) |
| 285 | return -EEXIST; |
| 286 | |
| 287 | /* get a struct segment_info */ |
| 288 | *seg_info = kzalloc(sizeof(struct segment_info), GFP_KERNEL); |
| 289 | if (*seg_info == NULL) |
| 290 | return -ENOMEM; |
| 291 | |
| 292 | strcpy((*seg_info)->segment_name, name); |
| 293 | |
| 294 | /* load the segment */ |
| 295 | rc = segment_load(name, SEGMENT_SHARED, |
| 296 | &(*seg_info)->start, &(*seg_info)->end); |
| 297 | if (rc < 0) { |
| 298 | segment_warning(rc, (*seg_info)->segment_name); |
| 299 | kfree(*seg_info); |
| 300 | } else { |
| 301 | INIT_LIST_HEAD(&(*seg_info)->lh); |
| 302 | (*seg_info)->segment_type = rc; |
| 303 | } |
| 304 | return rc; |
| 305 | } |
| 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | /* |
| 308 | * device attribute for switching shared/nonshared (exclusive) |
| 309 | * operation (show + store) |
| 310 | */ |
| 311 | static ssize_t |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 312 | dcssblk_shared_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
| 314 | struct dcssblk_dev_info *dev_info; |
| 315 | |
| 316 | dev_info = container_of(dev, struct dcssblk_dev_info, dev); |
| 317 | return sprintf(buf, dev_info->is_shared ? "1\n" : "0\n"); |
| 318 | } |
| 319 | |
| 320 | static ssize_t |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 321 | dcssblk_shared_store(struct device *dev, struct device_attribute *attr, const char *inbuf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
| 323 | struct dcssblk_dev_info *dev_info; |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 324 | struct segment_info *entry, *temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | int rc; |
| 326 | |
Hongjie Yang | ded77fb | 2008-07-14 09:59:39 +0200 | [diff] [blame] | 327 | if ((count > 1) && (inbuf[1] != '\n') && (inbuf[1] != '\0')) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | down_write(&dcssblk_devices_sem); |
| 330 | dev_info = container_of(dev, struct dcssblk_dev_info, dev); |
| 331 | if (atomic_read(&dev_info->use_count)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | rc = -EBUSY; |
| 333 | goto out; |
| 334 | } |
| 335 | if (inbuf[0] == '1') { |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 336 | /* reload segments in shared mode */ |
| 337 | list_for_each_entry(entry, &dev_info->seg_list, lh) { |
| 338 | rc = segment_modify_shared(entry->segment_name, |
| 339 | SEGMENT_SHARED); |
| 340 | if (rc < 0) { |
| 341 | BUG_ON(rc == -EINVAL); |
| 342 | if (rc != -EAGAIN) |
| 343 | goto removeseg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 346 | dev_info->is_shared = 1; |
| 347 | switch (dev_info->segment_type) { |
| 348 | case SEG_TYPE_SR: |
| 349 | case SEG_TYPE_ER: |
| 350 | case SEG_TYPE_SC: |
| 351 | set_disk_ro(dev_info->gd, 1); |
| 352 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } else if (inbuf[0] == '0') { |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 354 | /* reload segments in exclusive mode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | if (dev_info->segment_type == SEG_TYPE_SC) { |
Hongjie Yang | 93098bf | 2008-12-25 13:39:45 +0100 | [diff] [blame] | 356 | pr_err("DCSS %s is of type SC and cannot be " |
| 357 | "loaded as exclusive-writable\n", |
| 358 | dev_info->segment_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | rc = -EINVAL; |
| 360 | goto out; |
| 361 | } |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 362 | list_for_each_entry(entry, &dev_info->seg_list, lh) { |
| 363 | rc = segment_modify_shared(entry->segment_name, |
| 364 | SEGMENT_EXCLUSIVE); |
| 365 | if (rc < 0) { |
| 366 | BUG_ON(rc == -EINVAL); |
| 367 | if (rc != -EAGAIN) |
| 368 | goto removeseg; |
| 369 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 371 | dev_info->is_shared = 0; |
| 372 | set_disk_ro(dev_info->gd, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | rc = -EINVAL; |
| 375 | goto out; |
| 376 | } |
| 377 | rc = count; |
| 378 | goto out; |
| 379 | |
| 380 | removeseg: |
Hongjie Yang | 93098bf | 2008-12-25 13:39:45 +0100 | [diff] [blame] | 381 | pr_err("DCSS device %s is removed after a failed access mode " |
| 382 | "change\n", dev_info->segment_name); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 383 | temp = entry; |
| 384 | list_for_each_entry(entry, &dev_info->seg_list, lh) { |
| 385 | if (entry != temp) |
| 386 | segment_unload(entry->segment_name); |
| 387 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | list_del(&dev_info->lh); |
| 389 | |
| 390 | del_gendisk(dev_info->gd); |
Al Viro | 1312f40 | 2006-03-12 11:02:03 -0500 | [diff] [blame] | 391 | blk_cleanup_queue(dev_info->dcssblk_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | dev_info->gd->queue = NULL; |
| 393 | put_disk(dev_info->gd); |
Tejun Heo | 0b60f9e | 2014-02-03 14:03:04 -0500 | [diff] [blame] | 394 | up_write(&dcssblk_devices_sem); |
| 395 | |
| 396 | if (device_remove_file_self(dev, attr)) { |
| 397 | device_unregister(dev); |
| 398 | put_device(dev); |
| 399 | } |
| 400 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | out: |
| 402 | up_write(&dcssblk_devices_sem); |
| 403 | return rc; |
| 404 | } |
Sebastian Ott | 521b3d7 | 2012-10-01 09:12:01 +0200 | [diff] [blame] | 405 | static DEVICE_ATTR(shared, S_IWUSR | S_IRUSR, dcssblk_shared_show, |
| 406 | dcssblk_shared_store); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
| 408 | /* |
| 409 | * device attribute for save operation on current copy |
| 410 | * of the segment. If the segment is busy, saving will |
| 411 | * become pending until it gets released, which can be |
| 412 | * undone by storing a non-true value to this entry. |
| 413 | * (show + store) |
| 414 | */ |
| 415 | static ssize_t |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 416 | dcssblk_save_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | { |
| 418 | struct dcssblk_dev_info *dev_info; |
| 419 | |
| 420 | dev_info = container_of(dev, struct dcssblk_dev_info, dev); |
| 421 | return sprintf(buf, dev_info->save_pending ? "1\n" : "0\n"); |
| 422 | } |
| 423 | |
| 424 | static ssize_t |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 425 | dcssblk_save_store(struct device *dev, struct device_attribute *attr, const char *inbuf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | { |
| 427 | struct dcssblk_dev_info *dev_info; |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 428 | struct segment_info *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
Hongjie Yang | ded77fb | 2008-07-14 09:59:39 +0200 | [diff] [blame] | 430 | if ((count > 1) && (inbuf[1] != '\n') && (inbuf[1] != '\0')) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | dev_info = container_of(dev, struct dcssblk_dev_info, dev); |
| 433 | |
| 434 | down_write(&dcssblk_devices_sem); |
| 435 | if (inbuf[0] == '1') { |
| 436 | if (atomic_read(&dev_info->use_count) == 0) { |
| 437 | // device is idle => we save immediately |
Hongjie Yang | 93098bf | 2008-12-25 13:39:45 +0100 | [diff] [blame] | 438 | pr_info("All DCSSs that map to device %s are " |
| 439 | "saved\n", dev_info->segment_name); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 440 | list_for_each_entry(entry, &dev_info->seg_list, lh) { |
Gerald Schaefer | 5be6fdc | 2015-01-16 18:29:04 +0100 | [diff] [blame] | 441 | if (entry->segment_type == SEG_TYPE_EN || |
| 442 | entry->segment_type == SEG_TYPE_SN) |
| 443 | pr_warn("DCSS %s is of type SN or EN" |
| 444 | " and cannot be saved\n", |
| 445 | entry->segment_name); |
| 446 | else |
| 447 | segment_save(entry->segment_name); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 448 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | } else { |
| 450 | // device is busy => we save it when it becomes |
| 451 | // idle in dcssblk_release |
Hongjie Yang | 93098bf | 2008-12-25 13:39:45 +0100 | [diff] [blame] | 452 | pr_info("Device %s is in use, its DCSSs will be " |
| 453 | "saved when it becomes idle\n", |
| 454 | dev_info->segment_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | dev_info->save_pending = 1; |
| 456 | } |
| 457 | } else if (inbuf[0] == '0') { |
| 458 | if (dev_info->save_pending) { |
| 459 | // device is busy & the user wants to undo his save |
| 460 | // request |
| 461 | dev_info->save_pending = 0; |
Hongjie Yang | 93098bf | 2008-12-25 13:39:45 +0100 | [diff] [blame] | 462 | pr_info("A pending save request for device %s " |
| 463 | "has been canceled\n", |
| 464 | dev_info->segment_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | } |
| 466 | } else { |
| 467 | up_write(&dcssblk_devices_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | return -EINVAL; |
| 469 | } |
| 470 | up_write(&dcssblk_devices_sem); |
| 471 | return count; |
| 472 | } |
Sebastian Ott | 521b3d7 | 2012-10-01 09:12:01 +0200 | [diff] [blame] | 473 | static DEVICE_ATTR(save, S_IWUSR | S_IRUSR, dcssblk_save_show, |
| 474 | dcssblk_save_store); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
| 476 | /* |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 477 | * device attribute for showing all segments in a device |
| 478 | */ |
| 479 | static ssize_t |
| 480 | dcssblk_seglist_show(struct device *dev, struct device_attribute *attr, |
| 481 | char *buf) |
| 482 | { |
| 483 | int i; |
| 484 | |
| 485 | struct dcssblk_dev_info *dev_info; |
| 486 | struct segment_info *entry; |
| 487 | |
| 488 | down_read(&dcssblk_devices_sem); |
| 489 | dev_info = container_of(dev, struct dcssblk_dev_info, dev); |
| 490 | i = 0; |
| 491 | buf[0] = '\0'; |
| 492 | list_for_each_entry(entry, &dev_info->seg_list, lh) { |
| 493 | strcpy(&buf[i], entry->segment_name); |
| 494 | i += strlen(entry->segment_name); |
| 495 | buf[i] = '\n'; |
| 496 | i++; |
| 497 | } |
| 498 | up_read(&dcssblk_devices_sem); |
| 499 | return i; |
| 500 | } |
Sebastian Ott | 521b3d7 | 2012-10-01 09:12:01 +0200 | [diff] [blame] | 501 | static DEVICE_ATTR(seglist, S_IRUSR, dcssblk_seglist_show, NULL); |
| 502 | |
| 503 | static struct attribute *dcssblk_dev_attrs[] = { |
| 504 | &dev_attr_shared.attr, |
| 505 | &dev_attr_save.attr, |
| 506 | &dev_attr_seglist.attr, |
| 507 | NULL, |
| 508 | }; |
| 509 | static struct attribute_group dcssblk_dev_attr_group = { |
| 510 | .attrs = dcssblk_dev_attrs, |
| 511 | }; |
| 512 | static const struct attribute_group *dcssblk_dev_attr_groups[] = { |
| 513 | &dcssblk_dev_attr_group, |
| 514 | NULL, |
| 515 | }; |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 516 | |
| 517 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | * device attribute for adding devices |
| 519 | */ |
| 520 | static ssize_t |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 521 | dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | { |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 523 | int rc, i, j, num_of_segments; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | struct dcssblk_dev_info *dev_info; |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 525 | struct segment_info *seg_info, *temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | char *local_buf; |
| 527 | unsigned long seg_byte_size; |
| 528 | |
| 529 | dev_info = NULL; |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 530 | seg_info = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | if (dev != dcssblk_root_dev) { |
| 532 | rc = -EINVAL; |
| 533 | goto out_nobuf; |
| 534 | } |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 535 | if ((count < 1) || (buf[0] == '\0') || (buf[0] == '\n')) { |
| 536 | rc = -ENAMETOOLONG; |
| 537 | goto out_nobuf; |
| 538 | } |
| 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | local_buf = kmalloc(count + 1, GFP_KERNEL); |
| 541 | if (local_buf == NULL) { |
| 542 | rc = -ENOMEM; |
| 543 | goto out_nobuf; |
| 544 | } |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | /* |
| 547 | * parse input |
| 548 | */ |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 549 | num_of_segments = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | for (i = 0; ((buf[i] != '\0') && (buf[i] != '\n') && i < count); i++) { |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 551 | for (j = i; (buf[j] != ':') && |
| 552 | (buf[j] != '\0') && |
| 553 | (buf[j] != '\n') && |
| 554 | j < count; j++) { |
| 555 | local_buf[j-i] = toupper(buf[j]); |
| 556 | } |
| 557 | local_buf[j-i] = '\0'; |
| 558 | if (((j - i) == 0) || ((j - i) > 8)) { |
| 559 | rc = -ENAMETOOLONG; |
| 560 | goto seg_list_del; |
| 561 | } |
| 562 | |
| 563 | rc = dcssblk_load_segment(local_buf, &seg_info); |
| 564 | if (rc < 0) |
| 565 | goto seg_list_del; |
| 566 | /* |
| 567 | * get a struct dcssblk_dev_info |
| 568 | */ |
| 569 | if (num_of_segments == 0) { |
| 570 | dev_info = kzalloc(sizeof(struct dcssblk_dev_info), |
| 571 | GFP_KERNEL); |
| 572 | if (dev_info == NULL) { |
| 573 | rc = -ENOMEM; |
| 574 | goto out; |
| 575 | } |
| 576 | strcpy(dev_info->segment_name, local_buf); |
| 577 | dev_info->segment_type = seg_info->segment_type; |
| 578 | INIT_LIST_HEAD(&dev_info->seg_list); |
| 579 | } |
| 580 | list_add_tail(&seg_info->lh, &dev_info->seg_list); |
| 581 | num_of_segments++; |
| 582 | i = j; |
| 583 | |
| 584 | if ((buf[j] == '\0') || (buf[j] == '\n')) |
| 585 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 588 | /* no trailing colon at the end of the input */ |
| 589 | if ((i > 0) && (buf[i-1] == ':')) { |
| 590 | rc = -ENAMETOOLONG; |
| 591 | goto seg_list_del; |
| 592 | } |
| 593 | strlcpy(local_buf, buf, i + 1); |
| 594 | dev_info->num_of_segments = num_of_segments; |
| 595 | rc = dcssblk_is_continuous(dev_info); |
| 596 | if (rc < 0) |
| 597 | goto seg_list_del; |
| 598 | |
| 599 | dev_info->start = dcssblk_find_lowest_addr(dev_info); |
| 600 | dev_info->end = dcssblk_find_highest_addr(dev_info); |
| 601 | |
Kees Cook | ef283688f | 2014-06-10 10:46:20 -0700 | [diff] [blame] | 602 | dev_set_name(&dev_info->dev, "%s", dev_info->segment_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | dev_info->dev.release = dcssblk_release_segment; |
Sebastian Ott | 521b3d7 | 2012-10-01 09:12:01 +0200 | [diff] [blame] | 604 | dev_info->dev.groups = dcssblk_dev_attr_groups; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | INIT_LIST_HEAD(&dev_info->lh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | dev_info->gd = alloc_disk(DCSSBLK_MINORS_PER_DISK); |
| 607 | if (dev_info->gd == NULL) { |
| 608 | rc = -ENOMEM; |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 609 | goto seg_list_del; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } |
| 611 | dev_info->gd->major = dcssblk_major; |
| 612 | dev_info->gd->fops = &dcssblk_devops; |
| 613 | dev_info->dcssblk_queue = blk_alloc_queue(GFP_KERNEL); |
| 614 | dev_info->gd->queue = dev_info->dcssblk_queue; |
| 615 | dev_info->gd->private_data = dev_info; |
| 616 | dev_info->gd->driverfs_dev = &dev_info->dev; |
Heiko Carstens | c5411db | 2008-02-05 16:50:50 +0100 | [diff] [blame] | 617 | blk_queue_make_request(dev_info->dcssblk_queue, dcssblk_make_request); |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 618 | blk_queue_logical_block_size(dev_info->dcssblk_queue, 4096); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | seg_byte_size = (dev_info->end - dev_info->start + 1); |
| 621 | set_capacity(dev_info->gd, seg_byte_size >> 9); // size in sectors |
Hongjie Yang | 93098bf | 2008-12-25 13:39:45 +0100 | [diff] [blame] | 622 | pr_info("Loaded %s with total size %lu bytes and capacity %lu " |
| 623 | "sectors\n", local_buf, seg_byte_size, seg_byte_size >> 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | dev_info->save_pending = 0; |
| 626 | dev_info->is_shared = 1; |
| 627 | dev_info->dev.parent = dcssblk_root_dev; |
| 628 | |
| 629 | /* |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 630 | *get minor, add to list |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | */ |
| 632 | down_write(&dcssblk_devices_sem); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 633 | if (dcssblk_get_segment_by_name(local_buf)) { |
Gerald Schaefer | 04f64b5 | 2008-08-21 19:46:40 +0200 | [diff] [blame] | 634 | rc = -EEXIST; |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 635 | goto release_gd; |
Gerald Schaefer | 04f64b5 | 2008-08-21 19:46:40 +0200 | [diff] [blame] | 636 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | rc = dcssblk_assign_free_minor(dev_info); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 638 | if (rc) |
| 639 | goto release_gd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | sprintf(dev_info->gd->disk_name, "dcssblk%d", |
Gerald Schaefer | d059148 | 2009-06-12 10:26:35 +0200 | [diff] [blame] | 641 | dev_info->gd->first_minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | list_add_tail(&dev_info->lh, &dcssblk_devices); |
| 643 | |
| 644 | if (!try_module_get(THIS_MODULE)) { |
| 645 | rc = -ENODEV; |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 646 | goto dev_list_del; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | /* |
| 649 | * register the device |
| 650 | */ |
| 651 | rc = device_register(&dev_info->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | if (rc) |
Sebastian Ott | 521b3d7 | 2012-10-01 09:12:01 +0200 | [diff] [blame] | 653 | goto put_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
Sebastian Ott | 521b3d7 | 2012-10-01 09:12:01 +0200 | [diff] [blame] | 655 | get_device(&dev_info->dev); |
Christian Borntraeger | 436d1bc | 2007-12-04 16:09:03 +0100 | [diff] [blame] | 656 | add_disk(dev_info->gd); |
| 657 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | switch (dev_info->segment_type) { |
| 659 | case SEG_TYPE_SR: |
| 660 | case SEG_TYPE_ER: |
| 661 | case SEG_TYPE_SC: |
| 662 | set_disk_ro(dev_info->gd,1); |
| 663 | break; |
| 664 | default: |
| 665 | set_disk_ro(dev_info->gd,0); |
| 666 | break; |
| 667 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | up_write(&dcssblk_devices_sem); |
| 669 | rc = count; |
| 670 | goto out; |
| 671 | |
Sebastian Ott | 521b3d7 | 2012-10-01 09:12:01 +0200 | [diff] [blame] | 672 | put_dev: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | list_del(&dev_info->lh); |
Al Viro | 1312f40 | 2006-03-12 11:02:03 -0500 | [diff] [blame] | 674 | blk_cleanup_queue(dev_info->dcssblk_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | dev_info->gd->queue = NULL; |
| 676 | put_disk(dev_info->gd); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 677 | list_for_each_entry(seg_info, &dev_info->seg_list, lh) { |
| 678 | segment_unload(seg_info->segment_name); |
| 679 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | put_device(&dev_info->dev); |
| 681 | up_write(&dcssblk_devices_sem); |
| 682 | goto out; |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 683 | dev_list_del: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | list_del(&dev_info->lh); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 685 | release_gd: |
Al Viro | 1312f40 | 2006-03-12 11:02:03 -0500 | [diff] [blame] | 686 | blk_cleanup_queue(dev_info->dcssblk_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | dev_info->gd->queue = NULL; |
| 688 | put_disk(dev_info->gd); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 689 | up_write(&dcssblk_devices_sem); |
| 690 | seg_list_del: |
| 691 | if (dev_info == NULL) |
| 692 | goto out; |
| 693 | list_for_each_entry_safe(seg_info, temp, &dev_info->seg_list, lh) { |
| 694 | list_del(&seg_info->lh); |
| 695 | segment_unload(seg_info->segment_name); |
| 696 | kfree(seg_info); |
| 697 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | kfree(dev_info); |
| 699 | out: |
| 700 | kfree(local_buf); |
| 701 | out_nobuf: |
| 702 | return rc; |
| 703 | } |
| 704 | |
| 705 | /* |
| 706 | * device attribute for removing devices |
| 707 | */ |
| 708 | static ssize_t |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 709 | dcssblk_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | { |
| 711 | struct dcssblk_dev_info *dev_info; |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 712 | struct segment_info *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | int rc, i; |
| 714 | char *local_buf; |
| 715 | |
| 716 | if (dev != dcssblk_root_dev) { |
| 717 | return -EINVAL; |
| 718 | } |
| 719 | local_buf = kmalloc(count + 1, GFP_KERNEL); |
| 720 | if (local_buf == NULL) { |
| 721 | return -ENOMEM; |
| 722 | } |
| 723 | /* |
| 724 | * parse input |
| 725 | */ |
| 726 | for (i = 0; ((*(buf+i)!='\0') && (*(buf+i)!='\n') && i < count); i++) { |
| 727 | local_buf[i] = toupper(buf[i]); |
| 728 | } |
| 729 | local_buf[i] = '\0'; |
| 730 | if ((i == 0) || (i > 8)) { |
| 731 | rc = -ENAMETOOLONG; |
| 732 | goto out_buf; |
| 733 | } |
| 734 | |
| 735 | down_write(&dcssblk_devices_sem); |
| 736 | dev_info = dcssblk_get_device_by_name(local_buf); |
| 737 | if (dev_info == NULL) { |
| 738 | up_write(&dcssblk_devices_sem); |
Hongjie Yang | 93098bf | 2008-12-25 13:39:45 +0100 | [diff] [blame] | 739 | pr_warning("Device %s cannot be removed because it is not a " |
| 740 | "known device\n", local_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | rc = -ENODEV; |
| 742 | goto out_buf; |
| 743 | } |
| 744 | if (atomic_read(&dev_info->use_count) != 0) { |
| 745 | up_write(&dcssblk_devices_sem); |
Hongjie Yang | 93098bf | 2008-12-25 13:39:45 +0100 | [diff] [blame] | 746 | pr_warning("Device %s cannot be removed while it is in " |
| 747 | "use\n", local_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | rc = -EBUSY; |
| 749 | goto out_buf; |
| 750 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 752 | list_del(&dev_info->lh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | del_gendisk(dev_info->gd); |
Al Viro | 1312f40 | 2006-03-12 11:02:03 -0500 | [diff] [blame] | 754 | blk_cleanup_queue(dev_info->dcssblk_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | dev_info->gd->queue = NULL; |
| 756 | put_disk(dev_info->gd); |
| 757 | device_unregister(&dev_info->dev); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 758 | |
| 759 | /* unload all related segments */ |
| 760 | list_for_each_entry(entry, &dev_info->seg_list, lh) |
| 761 | segment_unload(entry->segment_name); |
| 762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | put_device(&dev_info->dev); |
| 764 | up_write(&dcssblk_devices_sem); |
| 765 | |
| 766 | rc = count; |
| 767 | out_buf: |
| 768 | kfree(local_buf); |
| 769 | return rc; |
| 770 | } |
| 771 | |
| 772 | static int |
Al Viro | 46d7432 | 2008-03-02 10:37:41 -0500 | [diff] [blame] | 773 | dcssblk_open(struct block_device *bdev, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | { |
| 775 | struct dcssblk_dev_info *dev_info; |
| 776 | int rc; |
| 777 | |
Al Viro | 46d7432 | 2008-03-02 10:37:41 -0500 | [diff] [blame] | 778 | dev_info = bdev->bd_disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | if (NULL == dev_info) { |
| 780 | rc = -ENODEV; |
| 781 | goto out; |
| 782 | } |
| 783 | atomic_inc(&dev_info->use_count); |
Al Viro | 46d7432 | 2008-03-02 10:37:41 -0500 | [diff] [blame] | 784 | bdev->bd_block_size = 4096; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | rc = 0; |
| 786 | out: |
| 787 | return rc; |
| 788 | } |
| 789 | |
Al Viro | db2a144 | 2013-05-05 21:52:57 -0400 | [diff] [blame] | 790 | static void |
Al Viro | 46d7432 | 2008-03-02 10:37:41 -0500 | [diff] [blame] | 791 | dcssblk_release(struct gendisk *disk, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | { |
Al Viro | 46d7432 | 2008-03-02 10:37:41 -0500 | [diff] [blame] | 793 | struct dcssblk_dev_info *dev_info = disk->private_data; |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 794 | struct segment_info *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
Al Viro | 46d7432 | 2008-03-02 10:37:41 -0500 | [diff] [blame] | 796 | if (!dev_info) { |
Al Viro | db2a144 | 2013-05-05 21:52:57 -0400 | [diff] [blame] | 797 | WARN_ON(1); |
| 798 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | } |
| 800 | down_write(&dcssblk_devices_sem); |
| 801 | if (atomic_dec_and_test(&dev_info->use_count) |
| 802 | && (dev_info->save_pending)) { |
Hongjie Yang | 93098bf | 2008-12-25 13:39:45 +0100 | [diff] [blame] | 803 | pr_info("Device %s has become idle and is being saved " |
| 804 | "now\n", dev_info->segment_name); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 805 | list_for_each_entry(entry, &dev_info->seg_list, lh) { |
Gerald Schaefer | 5be6fdc | 2015-01-16 18:29:04 +0100 | [diff] [blame] | 806 | if (entry->segment_type == SEG_TYPE_EN || |
| 807 | entry->segment_type == SEG_TYPE_SN) |
| 808 | pr_warn("DCSS %s is of type SN or EN and cannot" |
| 809 | " be saved\n", entry->segment_name); |
| 810 | else |
| 811 | segment_save(entry->segment_name); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 812 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | dev_info->save_pending = 0; |
| 814 | } |
| 815 | up_write(&dcssblk_devices_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 818 | static void |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 819 | dcssblk_make_request(struct request_queue *q, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | { |
| 821 | struct dcssblk_dev_info *dev_info; |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 822 | struct bio_vec bvec; |
| 823 | struct bvec_iter iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | unsigned long index; |
| 825 | unsigned long page_addr; |
| 826 | unsigned long source_addr; |
| 827 | unsigned long bytes_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | |
| 829 | bytes_done = 0; |
| 830 | dev_info = bio->bi_bdev->bd_disk->private_data; |
| 831 | if (dev_info == NULL) |
| 832 | goto fail; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 833 | if ((bio->bi_iter.bi_sector & 7) != 0 || |
| 834 | (bio->bi_iter.bi_size & 4095) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | /* Request is not page-aligned. */ |
| 836 | goto fail; |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 837 | if (bio_end_sector(bio) > get_capacity(bio->bi_bdev->bd_disk)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | /* Request beyond end of DCSS segment. */ |
| 839 | goto fail; |
| 840 | } |
Carsten Otte | 420edbc | 2005-06-23 22:05:23 -0700 | [diff] [blame] | 841 | /* verify data transfer direction */ |
| 842 | if (dev_info->is_shared) { |
| 843 | switch (dev_info->segment_type) { |
| 844 | case SEG_TYPE_SR: |
| 845 | case SEG_TYPE_ER: |
| 846 | case SEG_TYPE_SC: |
| 847 | /* cannot write to these segments */ |
| 848 | if (bio_data_dir(bio) == WRITE) { |
Hongjie Yang | 93098bf | 2008-12-25 13:39:45 +0100 | [diff] [blame] | 849 | pr_warning("Writing to %s failed because it " |
| 850 | "is a read-only device\n", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 851 | dev_name(&dev_info->dev)); |
Carsten Otte | 420edbc | 2005-06-23 22:05:23 -0700 | [diff] [blame] | 852 | goto fail; |
| 853 | } |
| 854 | } |
| 855 | } |
| 856 | |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 857 | index = (bio->bi_iter.bi_sector >> 3); |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 858 | bio_for_each_segment(bvec, bio, iter) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | page_addr = (unsigned long) |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 860 | page_address(bvec.bv_page) + bvec.bv_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | source_addr = dev_info->start + (index<<12) + bytes_done; |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 862 | if (unlikely((page_addr & 4095) != 0) || (bvec.bv_len & 4095) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | // More paranoia. |
| 864 | goto fail; |
| 865 | if (bio_data_dir(bio) == READ) { |
| 866 | memcpy((void*)page_addr, (void*)source_addr, |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 867 | bvec.bv_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | } else { |
| 869 | memcpy((void*)source_addr, (void*)page_addr, |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 870 | bvec.bv_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | } |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 872 | bytes_done += bvec.bv_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | } |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 874 | bio_endio(bio, 0); |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 875 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | fail: |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 877 | bio_io_error(bio); |
Carsten Otte | 420edbc | 2005-06-23 22:05:23 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Matthew Wilcox | dd22f55 | 2015-01-07 18:05:34 +0200 | [diff] [blame] | 880 | static long |
Carsten Otte | 420edbc | 2005-06-23 22:05:23 -0700 | [diff] [blame] | 881 | dcssblk_direct_access (struct block_device *bdev, sector_t secnum, |
Matthew Wilcox | dd22f55 | 2015-01-07 18:05:34 +0200 | [diff] [blame] | 882 | void **kaddr, unsigned long *pfn, long size) |
Carsten Otte | 420edbc | 2005-06-23 22:05:23 -0700 | [diff] [blame] | 883 | { |
| 884 | struct dcssblk_dev_info *dev_info; |
Matthew Wilcox | dd22f55 | 2015-01-07 18:05:34 +0200 | [diff] [blame] | 885 | unsigned long offset, dev_sz; |
Carsten Otte | 420edbc | 2005-06-23 22:05:23 -0700 | [diff] [blame] | 886 | |
| 887 | dev_info = bdev->bd_disk->private_data; |
| 888 | if (!dev_info) |
| 889 | return -ENODEV; |
Matthew Wilcox | dd22f55 | 2015-01-07 18:05:34 +0200 | [diff] [blame] | 890 | dev_sz = dev_info->end - dev_info->start; |
| 891 | offset = secnum * 512; |
| 892 | *kaddr = (void *) (dev_info->start + offset); |
Jared Hulbert | 30afcb4 | 2008-04-28 02:13:02 -0700 | [diff] [blame] | 893 | *pfn = virt_to_phys(*kaddr) >> PAGE_SHIFT; |
| 894 | |
Matthew Wilcox | dd22f55 | 2015-01-07 18:05:34 +0200 | [diff] [blame] | 895 | return dev_sz - offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | static void |
| 899 | dcssblk_check_params(void) |
| 900 | { |
| 901 | int rc, i, j, k; |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 902 | char buf[DCSSBLK_PARM_LEN + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | struct dcssblk_dev_info *dev_info; |
| 904 | |
| 905 | for (i = 0; (i < DCSSBLK_PARM_LEN) && (dcssblk_segments[i] != '\0'); |
| 906 | i++) { |
| 907 | for (j = i; (dcssblk_segments[j] != ',') && |
| 908 | (dcssblk_segments[j] != '\0') && |
| 909 | (dcssblk_segments[j] != '(') && |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 910 | (j < DCSSBLK_PARM_LEN); j++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | { |
| 912 | buf[j-i] = dcssblk_segments[j]; |
| 913 | } |
| 914 | buf[j-i] = '\0'; |
Cornelia Huck | f901e5d | 2005-06-25 14:55:29 -0700 | [diff] [blame] | 915 | rc = dcssblk_add_store(dcssblk_root_dev, NULL, buf, j-i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | if ((rc >= 0) && (dcssblk_segments[j] == '(')) { |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 917 | for (k = 0; (buf[k] != ':') && (buf[k] != '\0'); k++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | buf[k] = toupper(buf[k]); |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 919 | buf[k] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | if (!strncmp(&dcssblk_segments[j], "(local)", 7)) { |
| 921 | down_read(&dcssblk_devices_sem); |
| 922 | dev_info = dcssblk_get_device_by_name(buf); |
| 923 | up_read(&dcssblk_devices_sem); |
| 924 | if (dev_info) |
| 925 | dcssblk_shared_store(&dev_info->dev, |
Cornelia Huck | f901e5d | 2005-06-25 14:55:29 -0700 | [diff] [blame] | 926 | NULL, "0\n", 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | while ((dcssblk_segments[j] != ',') && |
| 930 | (dcssblk_segments[j] != '\0')) |
| 931 | { |
| 932 | j++; |
| 933 | } |
| 934 | if (dcssblk_segments[j] == '\0') |
| 935 | break; |
| 936 | i = j; |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | /* |
Gerald Schaefer | c369527 | 2009-06-16 10:30:51 +0200 | [diff] [blame] | 941 | * Suspend / Resume |
| 942 | */ |
| 943 | static int dcssblk_freeze(struct device *dev) |
| 944 | { |
| 945 | struct dcssblk_dev_info *dev_info; |
| 946 | int rc = 0; |
| 947 | |
| 948 | list_for_each_entry(dev_info, &dcssblk_devices, lh) { |
| 949 | switch (dev_info->segment_type) { |
| 950 | case SEG_TYPE_SR: |
| 951 | case SEG_TYPE_ER: |
| 952 | case SEG_TYPE_SC: |
| 953 | if (!dev_info->is_shared) |
| 954 | rc = -EINVAL; |
| 955 | break; |
| 956 | default: |
| 957 | rc = -EINVAL; |
| 958 | break; |
| 959 | } |
| 960 | if (rc) |
| 961 | break; |
| 962 | } |
| 963 | if (rc) |
Christian Borntraeger | 2c48c4d | 2009-07-07 16:37:11 +0200 | [diff] [blame] | 964 | pr_err("Suspending the system failed because DCSS device %s " |
| 965 | "is writable\n", |
Gerald Schaefer | c369527 | 2009-06-16 10:30:51 +0200 | [diff] [blame] | 966 | dev_info->segment_name); |
| 967 | return rc; |
| 968 | } |
| 969 | |
| 970 | static int dcssblk_restore(struct device *dev) |
| 971 | { |
| 972 | struct dcssblk_dev_info *dev_info; |
| 973 | struct segment_info *entry; |
| 974 | unsigned long start, end; |
| 975 | int rc = 0; |
| 976 | |
| 977 | list_for_each_entry(dev_info, &dcssblk_devices, lh) { |
| 978 | list_for_each_entry(entry, &dev_info->seg_list, lh) { |
| 979 | segment_unload(entry->segment_name); |
| 980 | rc = segment_load(entry->segment_name, SEGMENT_SHARED, |
| 981 | &start, &end); |
| 982 | if (rc < 0) { |
| 983 | // TODO in_use check ? |
| 984 | segment_warning(rc, entry->segment_name); |
| 985 | goto out_panic; |
| 986 | } |
| 987 | if (start != entry->start || end != entry->end) { |
Christian Borntraeger | 2c48c4d | 2009-07-07 16:37:11 +0200 | [diff] [blame] | 988 | pr_err("The address range of DCSS %s changed " |
| 989 | "while the system was suspended\n", |
Gerald Schaefer | c369527 | 2009-06-16 10:30:51 +0200 | [diff] [blame] | 990 | entry->segment_name); |
| 991 | goto out_panic; |
| 992 | } |
| 993 | } |
| 994 | } |
| 995 | return 0; |
| 996 | out_panic: |
| 997 | panic("fatal dcssblk resume error\n"); |
| 998 | } |
| 999 | |
| 1000 | static int dcssblk_thaw(struct device *dev) |
| 1001 | { |
| 1002 | return 0; |
| 1003 | } |
| 1004 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 1005 | static const struct dev_pm_ops dcssblk_pm_ops = { |
Gerald Schaefer | c369527 | 2009-06-16 10:30:51 +0200 | [diff] [blame] | 1006 | .freeze = dcssblk_freeze, |
| 1007 | .thaw = dcssblk_thaw, |
| 1008 | .restore = dcssblk_restore, |
| 1009 | }; |
| 1010 | |
| 1011 | static struct platform_driver dcssblk_pdrv = { |
| 1012 | .driver = { |
| 1013 | .name = "dcssblk", |
Gerald Schaefer | c369527 | 2009-06-16 10:30:51 +0200 | [diff] [blame] | 1014 | .pm = &dcssblk_pm_ops, |
| 1015 | }, |
| 1016 | }; |
| 1017 | |
| 1018 | static struct platform_device *dcssblk_pdev; |
| 1019 | |
| 1020 | |
| 1021 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | * The init/exit functions. |
| 1023 | */ |
| 1024 | static void __exit |
| 1025 | dcssblk_exit(void) |
| 1026 | { |
Gerald Schaefer | c369527 | 2009-06-16 10:30:51 +0200 | [diff] [blame] | 1027 | platform_device_unregister(dcssblk_pdev); |
| 1028 | platform_driver_unregister(&dcssblk_pdrv); |
Mark McLoughlin | 035da16 | 2008-12-15 12:58:29 +0000 | [diff] [blame] | 1029 | root_device_unregister(dcssblk_root_dev); |
Akinobu Mita | 00d5940 | 2007-07-17 04:03:46 -0700 | [diff] [blame] | 1030 | unregister_blkdev(dcssblk_major, DCSSBLK_NAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | static int __init |
| 1034 | dcssblk_init(void) |
| 1035 | { |
| 1036 | int rc; |
| 1037 | |
Gerald Schaefer | c369527 | 2009-06-16 10:30:51 +0200 | [diff] [blame] | 1038 | rc = platform_driver_register(&dcssblk_pdrv); |
| 1039 | if (rc) |
| 1040 | return rc; |
| 1041 | |
| 1042 | dcssblk_pdev = platform_device_register_simple("dcssblk", -1, NULL, |
| 1043 | 0); |
| 1044 | if (IS_ERR(dcssblk_pdev)) { |
| 1045 | rc = PTR_ERR(dcssblk_pdev); |
| 1046 | goto out_pdrv; |
| 1047 | } |
| 1048 | |
Mark McLoughlin | 035da16 | 2008-12-15 12:58:29 +0000 | [diff] [blame] | 1049 | dcssblk_root_dev = root_device_register("dcssblk"); |
Gerald Schaefer | c369527 | 2009-06-16 10:30:51 +0200 | [diff] [blame] | 1050 | if (IS_ERR(dcssblk_root_dev)) { |
| 1051 | rc = PTR_ERR(dcssblk_root_dev); |
| 1052 | goto out_pdev; |
| 1053 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | rc = device_create_file(dcssblk_root_dev, &dev_attr_add); |
Gerald Schaefer | c369527 | 2009-06-16 10:30:51 +0200 | [diff] [blame] | 1055 | if (rc) |
| 1056 | goto out_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | rc = device_create_file(dcssblk_root_dev, &dev_attr_remove); |
Gerald Schaefer | c369527 | 2009-06-16 10:30:51 +0200 | [diff] [blame] | 1058 | if (rc) |
| 1059 | goto out_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | rc = register_blkdev(0, DCSSBLK_NAME); |
Gerald Schaefer | c369527 | 2009-06-16 10:30:51 +0200 | [diff] [blame] | 1061 | if (rc < 0) |
| 1062 | goto out_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | dcssblk_major = rc; |
| 1064 | init_rwsem(&dcssblk_devices_sem); |
| 1065 | |
| 1066 | dcssblk_check_params(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | return 0; |
Gerald Schaefer | c369527 | 2009-06-16 10:30:51 +0200 | [diff] [blame] | 1068 | |
| 1069 | out_root: |
| 1070 | root_device_unregister(dcssblk_root_dev); |
| 1071 | out_pdev: |
| 1072 | platform_device_unregister(dcssblk_pdev); |
| 1073 | out_pdrv: |
| 1074 | platform_driver_unregister(&dcssblk_pdrv); |
| 1075 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | module_init(dcssblk_init); |
| 1079 | module_exit(dcssblk_exit); |
| 1080 | |
| 1081 | module_param_string(segments, dcssblk_segments, DCSSBLK_PARM_LEN, 0444); |
| 1082 | MODULE_PARM_DESC(segments, "Name of DCSS segment(s) to be loaded, " |
Hongjie Yang | b2300b9 | 2008-10-10 21:33:21 +0200 | [diff] [blame] | 1083 | "comma-separated list, names in each set separated " |
| 1084 | "by commas are separated by colons, each set contains " |
| 1085 | "names of contiguous segments and each name max. 8 chars.\n" |
| 1086 | "Adding \"(local)\" to the end of each set equals echoing 0 " |
| 1087 | "to /sys/devices/dcssblk/<device name>/shared after loading " |
| 1088 | "the contiguous segments - \n" |
| 1089 | "e.g. segments=\"mydcss1,mydcss2:mydcss3,mydcss4(local)\""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | |
| 1091 | MODULE_LICENSE("GPL"); |