Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * File...........: linux/drivers/s390/block/dasd.c |
| 3 | * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> |
| 4 | * Horst Hummel <Horst.Hummel@de.ibm.com> |
| 5 | * Carsten Otte <Cotte@de.ibm.com> |
| 6 | * Martin Schwidefsky <schwidefsky@de.ibm.com> |
| 7 | * Bugreports.to..: <Linux390@de.ibm.com> |
| 8 | * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001 |
| 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/config.h> |
| 13 | #include <linux/kmod.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/ctype.h> |
| 17 | #include <linux/major.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/buffer_head.h> |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 20 | #include <linux/hdreg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | #include <asm/ccwdev.h> |
| 23 | #include <asm/ebcdic.h> |
| 24 | #include <asm/idals.h> |
| 25 | #include <asm/todclk.h> |
| 26 | |
| 27 | /* This is ugly... */ |
| 28 | #define PRINTK_HEADER "dasd:" |
| 29 | |
| 30 | #include "dasd_int.h" |
| 31 | /* |
| 32 | * SECTION: Constant definitions to be used within this file |
| 33 | */ |
| 34 | #define DASD_CHANQ_MAX_SIZE 4 |
| 35 | |
| 36 | /* |
| 37 | * SECTION: exported variables of dasd.c |
| 38 | */ |
| 39 | debug_info_t *dasd_debug_area; |
| 40 | struct dasd_discipline *dasd_diag_discipline_pointer; |
| 41 | |
| 42 | MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>"); |
| 43 | MODULE_DESCRIPTION("Linux on S/390 DASD device driver," |
| 44 | " Copyright 2000 IBM Corporation"); |
| 45 | MODULE_SUPPORTED_DEVICE("dasd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | MODULE_LICENSE("GPL"); |
| 47 | |
| 48 | /* |
| 49 | * SECTION: prototypes for static functions of dasd.c |
| 50 | */ |
| 51 | static int dasd_alloc_queue(struct dasd_device * device); |
| 52 | static void dasd_setup_queue(struct dasd_device * device); |
| 53 | static void dasd_free_queue(struct dasd_device * device); |
| 54 | static void dasd_flush_request_queue(struct dasd_device *); |
| 55 | static void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *); |
| 56 | static void dasd_flush_ccw_queue(struct dasd_device *, int); |
| 57 | static void dasd_tasklet(struct dasd_device *); |
| 58 | static void do_kick_device(void *data); |
| 59 | |
| 60 | /* |
| 61 | * SECTION: Operations on the device structure. |
| 62 | */ |
| 63 | static wait_queue_head_t dasd_init_waitq; |
| 64 | |
| 65 | /* |
| 66 | * Allocate memory for a new device structure. |
| 67 | */ |
| 68 | struct dasd_device * |
| 69 | dasd_alloc_device(void) |
| 70 | { |
| 71 | struct dasd_device *device; |
| 72 | |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 73 | device = kzalloc(sizeof (struct dasd_device), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | if (device == NULL) |
| 75 | return ERR_PTR(-ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /* open_count = 0 means device online but not in use */ |
| 77 | atomic_set(&device->open_count, -1); |
| 78 | |
| 79 | /* Get two pages for normal block device operations. */ |
| 80 | device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1); |
| 81 | if (device->ccw_mem == NULL) { |
| 82 | kfree(device); |
| 83 | return ERR_PTR(-ENOMEM); |
| 84 | } |
| 85 | /* Get one page for error recovery. */ |
| 86 | device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA); |
| 87 | if (device->erp_mem == NULL) { |
| 88 | free_pages((unsigned long) device->ccw_mem, 1); |
| 89 | kfree(device); |
| 90 | return ERR_PTR(-ENOMEM); |
| 91 | } |
| 92 | |
| 93 | dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2); |
| 94 | dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE); |
| 95 | spin_lock_init(&device->mem_lock); |
| 96 | spin_lock_init(&device->request_queue_lock); |
| 97 | atomic_set (&device->tasklet_scheduled, 0); |
| 98 | tasklet_init(&device->tasklet, |
| 99 | (void (*)(unsigned long)) dasd_tasklet, |
| 100 | (unsigned long) device); |
| 101 | INIT_LIST_HEAD(&device->ccw_queue); |
| 102 | init_timer(&device->timer); |
| 103 | INIT_WORK(&device->kick_work, do_kick_device, device); |
| 104 | device->state = DASD_STATE_NEW; |
| 105 | device->target = DASD_STATE_NEW; |
| 106 | |
| 107 | return device; |
| 108 | } |
| 109 | |
| 110 | /* |
| 111 | * Free memory of a device structure. |
| 112 | */ |
| 113 | void |
| 114 | dasd_free_device(struct dasd_device *device) |
| 115 | { |
Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 116 | kfree(device->private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | free_page((unsigned long) device->erp_mem); |
| 118 | free_pages((unsigned long) device->ccw_mem, 1); |
| 119 | kfree(device); |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * Make a new device known to the system. |
| 124 | */ |
| 125 | static inline int |
| 126 | dasd_state_new_to_known(struct dasd_device *device) |
| 127 | { |
| 128 | int rc; |
| 129 | |
| 130 | /* |
| 131 | * As long as the device is not in state DASD_STATE_NEW we want to |
| 132 | * keep the reference count > 0. |
| 133 | */ |
| 134 | dasd_get_device(device); |
| 135 | |
| 136 | rc = dasd_alloc_queue(device); |
| 137 | if (rc) { |
| 138 | dasd_put_device(device); |
| 139 | return rc; |
| 140 | } |
| 141 | |
| 142 | device->state = DASD_STATE_KNOWN; |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | * Let the system forget about a device. |
| 148 | */ |
| 149 | static inline void |
| 150 | dasd_state_known_to_new(struct dasd_device * device) |
| 151 | { |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 152 | /* Disable extended error reporting for this device. */ |
| 153 | dasd_eer_disable(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | /* Forget the discipline information. */ |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 155 | if (device->discipline) |
| 156 | module_put(device->discipline->owner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | device->discipline = NULL; |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 158 | if (device->base_discipline) |
| 159 | module_put(device->base_discipline->owner); |
| 160 | device->base_discipline = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | device->state = DASD_STATE_NEW; |
| 162 | |
| 163 | dasd_free_queue(device); |
| 164 | |
| 165 | /* Give up reference we took in dasd_state_new_to_known. */ |
| 166 | dasd_put_device(device); |
| 167 | } |
| 168 | |
| 169 | /* |
| 170 | * Request the irq line for the device. |
| 171 | */ |
| 172 | static inline int |
| 173 | dasd_state_known_to_basic(struct dasd_device * device) |
| 174 | { |
| 175 | int rc; |
| 176 | |
| 177 | /* Allocate and register gendisk structure. */ |
| 178 | rc = dasd_gendisk_alloc(device); |
| 179 | if (rc) |
| 180 | return rc; |
| 181 | |
| 182 | /* register 'device' debug area, used for all DBF_DEV_XXX calls */ |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 183 | device->debug_area = debug_register(device->cdev->dev.bus_id, 1, 2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | 8 * sizeof (long)); |
| 185 | debug_register_view(device->debug_area, &debug_sprintf_view); |
| 186 | debug_set_level(device->debug_area, DBF_EMERG); |
| 187 | DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created"); |
| 188 | |
| 189 | device->state = DASD_STATE_BASIC; |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | * Release the irq line for the device. Terminate any running i/o. |
| 195 | */ |
| 196 | static inline void |
| 197 | dasd_state_basic_to_known(struct dasd_device * device) |
| 198 | { |
| 199 | dasd_gendisk_free(device); |
| 200 | dasd_flush_ccw_queue(device, 1); |
| 201 | DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device); |
| 202 | if (device->debug_area != NULL) { |
| 203 | debug_unregister(device->debug_area); |
| 204 | device->debug_area = NULL; |
| 205 | } |
| 206 | device->state = DASD_STATE_KNOWN; |
| 207 | } |
| 208 | |
| 209 | /* |
| 210 | * Do the initial analysis. The do_analysis function may return |
| 211 | * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC |
| 212 | * until the discipline decides to continue the startup sequence |
| 213 | * by calling the function dasd_change_state. The eckd disciplines |
| 214 | * uses this to start a ccw that detects the format. The completion |
| 215 | * interrupt for this detection ccw uses the kernel event daemon to |
| 216 | * trigger the call to dasd_change_state. All this is done in the |
| 217 | * discipline code, see dasd_eckd.c. |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 218 | * After the analysis ccw is done (do_analysis returned 0) the block |
| 219 | * device is setup. |
| 220 | * In case the analysis returns an error, the device setup is stopped |
| 221 | * (a fake disk was already added to allow formatting). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | */ |
| 223 | static inline int |
| 224 | dasd_state_basic_to_ready(struct dasd_device * device) |
| 225 | { |
| 226 | int rc; |
| 227 | |
| 228 | rc = 0; |
| 229 | if (device->discipline->do_analysis != NULL) |
| 230 | rc = device->discipline->do_analysis(device); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 231 | if (rc) { |
| 232 | if (rc != -EAGAIN) |
| 233 | device->state = DASD_STATE_UNFMT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | return rc; |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 235 | } |
| 236 | /* make disk known with correct capacity */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | dasd_setup_queue(device); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 238 | set_capacity(device->gdp, device->blocks << device->s2b_shift); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | device->state = DASD_STATE_READY; |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 240 | rc = dasd_scan_partitions(device); |
| 241 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | device->state = DASD_STATE_BASIC; |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 243 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /* |
| 247 | * Remove device from block device layer. Destroy dirty buffers. |
| 248 | * Forget format information. Check if the target level is basic |
| 249 | * and if it is create fake disk for formatting. |
| 250 | */ |
| 251 | static inline void |
| 252 | dasd_state_ready_to_basic(struct dasd_device * device) |
| 253 | { |
| 254 | dasd_flush_ccw_queue(device, 0); |
| 255 | dasd_destroy_partitions(device); |
| 256 | dasd_flush_request_queue(device); |
| 257 | device->blocks = 0; |
| 258 | device->bp_block = 0; |
| 259 | device->s2b_shift = 0; |
| 260 | device->state = DASD_STATE_BASIC; |
| 261 | } |
| 262 | |
| 263 | /* |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 264 | * Back to basic. |
| 265 | */ |
| 266 | static inline void |
| 267 | dasd_state_unfmt_to_basic(struct dasd_device * device) |
| 268 | { |
| 269 | device->state = DASD_STATE_BASIC; |
| 270 | } |
| 271 | |
| 272 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | * Make the device online and schedule the bottom half to start |
| 274 | * the requeueing of requests from the linux request queue to the |
| 275 | * ccw queue. |
| 276 | */ |
| 277 | static inline int |
| 278 | dasd_state_ready_to_online(struct dasd_device * device) |
| 279 | { |
| 280 | device->state = DASD_STATE_ONLINE; |
| 281 | dasd_schedule_bh(device); |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | * Stop the requeueing of requests again. |
| 287 | */ |
| 288 | static inline void |
| 289 | dasd_state_online_to_ready(struct dasd_device * device) |
| 290 | { |
| 291 | device->state = DASD_STATE_READY; |
| 292 | } |
| 293 | |
| 294 | /* |
| 295 | * Device startup state changes. |
| 296 | */ |
| 297 | static inline int |
| 298 | dasd_increase_state(struct dasd_device *device) |
| 299 | { |
| 300 | int rc; |
| 301 | |
| 302 | rc = 0; |
| 303 | if (device->state == DASD_STATE_NEW && |
| 304 | device->target >= DASD_STATE_KNOWN) |
| 305 | rc = dasd_state_new_to_known(device); |
| 306 | |
| 307 | if (!rc && |
| 308 | device->state == DASD_STATE_KNOWN && |
| 309 | device->target >= DASD_STATE_BASIC) |
| 310 | rc = dasd_state_known_to_basic(device); |
| 311 | |
| 312 | if (!rc && |
| 313 | device->state == DASD_STATE_BASIC && |
| 314 | device->target >= DASD_STATE_READY) |
| 315 | rc = dasd_state_basic_to_ready(device); |
| 316 | |
| 317 | if (!rc && |
| 318 | device->state == DASD_STATE_READY && |
| 319 | device->target >= DASD_STATE_ONLINE) |
| 320 | rc = dasd_state_ready_to_online(device); |
| 321 | |
| 322 | return rc; |
| 323 | } |
| 324 | |
| 325 | /* |
| 326 | * Device shutdown state changes. |
| 327 | */ |
| 328 | static inline int |
| 329 | dasd_decrease_state(struct dasd_device *device) |
| 330 | { |
| 331 | if (device->state == DASD_STATE_ONLINE && |
| 332 | device->target <= DASD_STATE_READY) |
| 333 | dasd_state_online_to_ready(device); |
| 334 | |
| 335 | if (device->state == DASD_STATE_READY && |
| 336 | device->target <= DASD_STATE_BASIC) |
| 337 | dasd_state_ready_to_basic(device); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 338 | |
| 339 | if (device->state == DASD_STATE_UNFMT && |
| 340 | device->target <= DASD_STATE_BASIC) |
| 341 | dasd_state_unfmt_to_basic(device); |
| 342 | |
| 343 | if (device->state == DASD_STATE_BASIC && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | device->target <= DASD_STATE_KNOWN) |
| 345 | dasd_state_basic_to_known(device); |
| 346 | |
| 347 | if (device->state == DASD_STATE_KNOWN && |
| 348 | device->target <= DASD_STATE_NEW) |
| 349 | dasd_state_known_to_new(device); |
| 350 | |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | /* |
| 355 | * This is the main startup/shutdown routine. |
| 356 | */ |
| 357 | static void |
| 358 | dasd_change_state(struct dasd_device *device) |
| 359 | { |
| 360 | int rc; |
| 361 | |
| 362 | if (device->state == device->target) |
| 363 | /* Already where we want to go today... */ |
| 364 | return; |
| 365 | if (device->state < device->target) |
| 366 | rc = dasd_increase_state(device); |
| 367 | else |
| 368 | rc = dasd_decrease_state(device); |
| 369 | if (rc && rc != -EAGAIN) |
| 370 | device->target = device->state; |
| 371 | |
| 372 | if (device->state == device->target) |
| 373 | wake_up(&dasd_init_waitq); |
| 374 | } |
| 375 | |
| 376 | /* |
| 377 | * Kick starter for devices that did not complete the startup/shutdown |
| 378 | * procedure or were sleeping because of a pending state. |
| 379 | * dasd_kick_device will schedule a call do do_kick_device to the kernel |
| 380 | * event daemon. |
| 381 | */ |
| 382 | static void |
| 383 | do_kick_device(void *data) |
| 384 | { |
| 385 | struct dasd_device *device; |
| 386 | |
| 387 | device = (struct dasd_device *) data; |
| 388 | dasd_change_state(device); |
| 389 | dasd_schedule_bh(device); |
| 390 | dasd_put_device(device); |
| 391 | } |
| 392 | |
| 393 | void |
| 394 | dasd_kick_device(struct dasd_device *device) |
| 395 | { |
| 396 | dasd_get_device(device); |
| 397 | /* queue call to dasd_kick_device to the kernel event daemon. */ |
| 398 | schedule_work(&device->kick_work); |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * Set the target state for a device and starts the state change. |
| 403 | */ |
| 404 | void |
| 405 | dasd_set_target_state(struct dasd_device *device, int target) |
| 406 | { |
| 407 | /* If we are in probeonly mode stop at DASD_STATE_READY. */ |
| 408 | if (dasd_probeonly && target > DASD_STATE_READY) |
| 409 | target = DASD_STATE_READY; |
| 410 | if (device->target != target) { |
| 411 | if (device->state == target) |
| 412 | wake_up(&dasd_init_waitq); |
| 413 | device->target = target; |
| 414 | } |
| 415 | if (device->state != device->target) |
| 416 | dasd_change_state(device); |
| 417 | } |
| 418 | |
| 419 | /* |
| 420 | * Enable devices with device numbers in [from..to]. |
| 421 | */ |
| 422 | static inline int |
| 423 | _wait_for_device(struct dasd_device *device) |
| 424 | { |
| 425 | return (device->state == device->target); |
| 426 | } |
| 427 | |
| 428 | void |
| 429 | dasd_enable_device(struct dasd_device *device) |
| 430 | { |
| 431 | dasd_set_target_state(device, DASD_STATE_ONLINE); |
| 432 | if (device->state <= DASD_STATE_KNOWN) |
| 433 | /* No discipline for device found. */ |
| 434 | dasd_set_target_state(device, DASD_STATE_NEW); |
| 435 | /* Now wait for the devices to come up. */ |
| 436 | wait_event(dasd_init_waitq, _wait_for_device(device)); |
| 437 | } |
| 438 | |
| 439 | /* |
| 440 | * SECTION: device operation (interrupt handler, start i/o, term i/o ...) |
| 441 | */ |
| 442 | #ifdef CONFIG_DASD_PROFILE |
| 443 | |
| 444 | struct dasd_profile_info_t dasd_global_profile; |
| 445 | unsigned int dasd_profile_level = DASD_PROFILE_OFF; |
| 446 | |
| 447 | /* |
| 448 | * Increments counter in global and local profiling structures. |
| 449 | */ |
| 450 | #define dasd_profile_counter(value, counter, device) \ |
| 451 | { \ |
| 452 | int index; \ |
| 453 | for (index = 0; index < 31 && value >> (2+index); index++); \ |
| 454 | dasd_global_profile.counter[index]++; \ |
| 455 | device->profile.counter[index]++; \ |
| 456 | } |
| 457 | |
| 458 | /* |
| 459 | * Add profiling information for cqr before execution. |
| 460 | */ |
| 461 | static inline void |
| 462 | dasd_profile_start(struct dasd_device *device, struct dasd_ccw_req * cqr, |
| 463 | struct request *req) |
| 464 | { |
| 465 | struct list_head *l; |
| 466 | unsigned int counter; |
| 467 | |
| 468 | if (dasd_profile_level != DASD_PROFILE_ON) |
| 469 | return; |
| 470 | |
| 471 | /* count the length of the chanq for statistics */ |
| 472 | counter = 0; |
| 473 | list_for_each(l, &device->ccw_queue) |
| 474 | if (++counter >= 31) |
| 475 | break; |
| 476 | dasd_global_profile.dasd_io_nr_req[counter]++; |
| 477 | device->profile.dasd_io_nr_req[counter]++; |
| 478 | } |
| 479 | |
| 480 | /* |
| 481 | * Add profiling information for cqr after execution. |
| 482 | */ |
| 483 | static inline void |
| 484 | dasd_profile_end(struct dasd_device *device, struct dasd_ccw_req * cqr, |
| 485 | struct request *req) |
| 486 | { |
| 487 | long strtime, irqtime, endtime, tottime; /* in microseconds */ |
| 488 | long tottimeps, sectors; |
| 489 | |
| 490 | if (dasd_profile_level != DASD_PROFILE_ON) |
| 491 | return; |
| 492 | |
| 493 | sectors = req->nr_sectors; |
| 494 | if (!cqr->buildclk || !cqr->startclk || |
| 495 | !cqr->stopclk || !cqr->endclk || |
| 496 | !sectors) |
| 497 | return; |
| 498 | |
| 499 | strtime = ((cqr->startclk - cqr->buildclk) >> 12); |
| 500 | irqtime = ((cqr->stopclk - cqr->startclk) >> 12); |
| 501 | endtime = ((cqr->endclk - cqr->stopclk) >> 12); |
| 502 | tottime = ((cqr->endclk - cqr->buildclk) >> 12); |
| 503 | tottimeps = tottime / sectors; |
| 504 | |
| 505 | if (!dasd_global_profile.dasd_io_reqs) |
| 506 | memset(&dasd_global_profile, 0, |
| 507 | sizeof (struct dasd_profile_info_t)); |
| 508 | dasd_global_profile.dasd_io_reqs++; |
| 509 | dasd_global_profile.dasd_io_sects += sectors; |
| 510 | |
| 511 | if (!device->profile.dasd_io_reqs) |
| 512 | memset(&device->profile, 0, |
| 513 | sizeof (struct dasd_profile_info_t)); |
| 514 | device->profile.dasd_io_reqs++; |
| 515 | device->profile.dasd_io_sects += sectors; |
| 516 | |
| 517 | dasd_profile_counter(sectors, dasd_io_secs, device); |
| 518 | dasd_profile_counter(tottime, dasd_io_times, device); |
| 519 | dasd_profile_counter(tottimeps, dasd_io_timps, device); |
| 520 | dasd_profile_counter(strtime, dasd_io_time1, device); |
| 521 | dasd_profile_counter(irqtime, dasd_io_time2, device); |
| 522 | dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, device); |
| 523 | dasd_profile_counter(endtime, dasd_io_time3, device); |
| 524 | } |
| 525 | #else |
| 526 | #define dasd_profile_start(device, cqr, req) do {} while (0) |
| 527 | #define dasd_profile_end(device, cqr, req) do {} while (0) |
| 528 | #endif /* CONFIG_DASD_PROFILE */ |
| 529 | |
| 530 | /* |
| 531 | * Allocate memory for a channel program with 'cplength' channel |
| 532 | * command words and 'datasize' additional space. There are two |
| 533 | * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed |
| 534 | * memory and 2) dasd_smalloc_request uses the static ccw memory |
| 535 | * that gets allocated for each device. |
| 536 | */ |
| 537 | struct dasd_ccw_req * |
| 538 | dasd_kmalloc_request(char *magic, int cplength, int datasize, |
| 539 | struct dasd_device * device) |
| 540 | { |
| 541 | struct dasd_ccw_req *cqr; |
| 542 | |
| 543 | /* Sanity checks */ |
Eric Sesterhenn | 7ac1e87 | 2006-03-24 18:48:13 +0100 | [diff] [blame] | 544 | BUG_ON( magic == NULL || datasize > PAGE_SIZE || |
| 545 | (cplength*sizeof(struct ccw1)) > PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 547 | cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | if (cqr == NULL) |
| 549 | return ERR_PTR(-ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | cqr->cpaddr = NULL; |
| 551 | if (cplength > 0) { |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 552 | cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | GFP_ATOMIC | GFP_DMA); |
| 554 | if (cqr->cpaddr == NULL) { |
| 555 | kfree(cqr); |
| 556 | return ERR_PTR(-ENOMEM); |
| 557 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
| 559 | cqr->data = NULL; |
| 560 | if (datasize > 0) { |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 561 | cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | if (cqr->data == NULL) { |
Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 563 | kfree(cqr->cpaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | kfree(cqr); |
| 565 | return ERR_PTR(-ENOMEM); |
| 566 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | } |
| 568 | strncpy((char *) &cqr->magic, magic, 4); |
| 569 | ASCEBC((char *) &cqr->magic, 4); |
| 570 | set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 571 | dasd_get_device(device); |
| 572 | return cqr; |
| 573 | } |
| 574 | |
| 575 | struct dasd_ccw_req * |
| 576 | dasd_smalloc_request(char *magic, int cplength, int datasize, |
| 577 | struct dasd_device * device) |
| 578 | { |
| 579 | unsigned long flags; |
| 580 | struct dasd_ccw_req *cqr; |
| 581 | char *data; |
| 582 | int size; |
| 583 | |
| 584 | /* Sanity checks */ |
Eric Sesterhenn | 7ac1e87 | 2006-03-24 18:48:13 +0100 | [diff] [blame] | 585 | BUG_ON( magic == NULL || datasize > PAGE_SIZE || |
| 586 | (cplength*sizeof(struct ccw1)) > PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
| 588 | size = (sizeof(struct dasd_ccw_req) + 7L) & -8L; |
| 589 | if (cplength > 0) |
| 590 | size += cplength * sizeof(struct ccw1); |
| 591 | if (datasize > 0) |
| 592 | size += datasize; |
| 593 | spin_lock_irqsave(&device->mem_lock, flags); |
| 594 | cqr = (struct dasd_ccw_req *) |
| 595 | dasd_alloc_chunk(&device->ccw_chunks, size); |
| 596 | spin_unlock_irqrestore(&device->mem_lock, flags); |
| 597 | if (cqr == NULL) |
| 598 | return ERR_PTR(-ENOMEM); |
| 599 | memset(cqr, 0, sizeof(struct dasd_ccw_req)); |
| 600 | data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L); |
| 601 | cqr->cpaddr = NULL; |
| 602 | if (cplength > 0) { |
| 603 | cqr->cpaddr = (struct ccw1 *) data; |
| 604 | data += cplength*sizeof(struct ccw1); |
| 605 | memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1)); |
| 606 | } |
| 607 | cqr->data = NULL; |
| 608 | if (datasize > 0) { |
| 609 | cqr->data = data; |
| 610 | memset(cqr->data, 0, datasize); |
| 611 | } |
| 612 | strncpy((char *) &cqr->magic, magic, 4); |
| 613 | ASCEBC((char *) &cqr->magic, 4); |
| 614 | set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 615 | dasd_get_device(device); |
| 616 | return cqr; |
| 617 | } |
| 618 | |
| 619 | /* |
| 620 | * Free memory of a channel program. This function needs to free all the |
| 621 | * idal lists that might have been created by dasd_set_cda and the |
| 622 | * struct dasd_ccw_req itself. |
| 623 | */ |
| 624 | void |
| 625 | dasd_kfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device) |
| 626 | { |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 627 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | struct ccw1 *ccw; |
| 629 | |
| 630 | /* Clear any idals used for the request. */ |
| 631 | ccw = cqr->cpaddr; |
| 632 | do { |
| 633 | clear_normalized_cda(ccw); |
| 634 | } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC)); |
| 635 | #endif |
Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 636 | kfree(cqr->cpaddr); |
| 637 | kfree(cqr->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | kfree(cqr); |
| 639 | dasd_put_device(device); |
| 640 | } |
| 641 | |
| 642 | void |
| 643 | dasd_sfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device) |
| 644 | { |
| 645 | unsigned long flags; |
| 646 | |
| 647 | spin_lock_irqsave(&device->mem_lock, flags); |
| 648 | dasd_free_chunk(&device->ccw_chunks, cqr); |
| 649 | spin_unlock_irqrestore(&device->mem_lock, flags); |
| 650 | dasd_put_device(device); |
| 651 | } |
| 652 | |
| 653 | /* |
| 654 | * Check discipline magic in cqr. |
| 655 | */ |
| 656 | static inline int |
| 657 | dasd_check_cqr(struct dasd_ccw_req *cqr) |
| 658 | { |
| 659 | struct dasd_device *device; |
| 660 | |
| 661 | if (cqr == NULL) |
| 662 | return -EINVAL; |
| 663 | device = cqr->device; |
| 664 | if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) { |
| 665 | DEV_MESSAGE(KERN_WARNING, device, |
| 666 | " dasd_ccw_req 0x%08x magic doesn't match" |
| 667 | " discipline 0x%08x", |
| 668 | cqr->magic, |
| 669 | *(unsigned int *) device->discipline->name); |
| 670 | return -EINVAL; |
| 671 | } |
| 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | /* |
| 676 | * Terminate the current i/o and set the request to clear_pending. |
| 677 | * Timer keeps device runnig. |
| 678 | * ccw_device_clear can fail if the i/o subsystem |
| 679 | * is in a bad mood. |
| 680 | */ |
| 681 | int |
| 682 | dasd_term_IO(struct dasd_ccw_req * cqr) |
| 683 | { |
| 684 | struct dasd_device *device; |
| 685 | int retries, rc; |
| 686 | |
| 687 | /* Check the cqr */ |
| 688 | rc = dasd_check_cqr(cqr); |
| 689 | if (rc) |
| 690 | return rc; |
| 691 | retries = 0; |
| 692 | device = (struct dasd_device *) cqr->device; |
| 693 | while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) { |
| 694 | rc = ccw_device_clear(device->cdev, (long) cqr); |
| 695 | switch (rc) { |
| 696 | case 0: /* termination successful */ |
Horst Hummel | c2ba444 | 2006-02-01 03:06:37 -0800 | [diff] [blame] | 697 | cqr->retries--; |
| 698 | cqr->status = DASD_CQR_CLEAR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | cqr->stopclk = get_clock(); |
| 700 | DBF_DEV_EVENT(DBF_DEBUG, device, |
| 701 | "terminate cqr %p successful", |
| 702 | cqr); |
| 703 | break; |
| 704 | case -ENODEV: |
| 705 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
| 706 | "device gone, retry"); |
| 707 | break; |
| 708 | case -EIO: |
| 709 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
| 710 | "I/O error, retry"); |
| 711 | break; |
| 712 | case -EINVAL: |
| 713 | case -EBUSY: |
| 714 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
| 715 | "device busy, retry later"); |
| 716 | break; |
| 717 | default: |
| 718 | DEV_MESSAGE(KERN_ERR, device, |
| 719 | "line %d unknown RC=%d, please " |
| 720 | "report to linux390@de.ibm.com", |
| 721 | __LINE__, rc); |
| 722 | BUG(); |
| 723 | break; |
| 724 | } |
| 725 | retries++; |
| 726 | } |
| 727 | dasd_schedule_bh(device); |
| 728 | return rc; |
| 729 | } |
| 730 | |
| 731 | /* |
| 732 | * Start the i/o. This start_IO can fail if the channel is really busy. |
| 733 | * In that case set up a timer to start the request later. |
| 734 | */ |
| 735 | int |
| 736 | dasd_start_IO(struct dasd_ccw_req * cqr) |
| 737 | { |
| 738 | struct dasd_device *device; |
| 739 | int rc; |
| 740 | |
| 741 | /* Check the cqr */ |
| 742 | rc = dasd_check_cqr(cqr); |
| 743 | if (rc) |
| 744 | return rc; |
| 745 | device = (struct dasd_device *) cqr->device; |
| 746 | if (cqr->retries < 0) { |
| 747 | DEV_MESSAGE(KERN_DEBUG, device, |
| 748 | "start_IO: request %p (%02x/%i) - no retry left.", |
| 749 | cqr, cqr->status, cqr->retries); |
| 750 | cqr->status = DASD_CQR_FAILED; |
| 751 | return -EIO; |
| 752 | } |
| 753 | cqr->startclk = get_clock(); |
| 754 | cqr->starttime = jiffies; |
| 755 | cqr->retries--; |
| 756 | rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr, |
| 757 | cqr->lpm, 0); |
| 758 | switch (rc) { |
| 759 | case 0: |
| 760 | cqr->status = DASD_CQR_IN_IO; |
| 761 | DBF_DEV_EVENT(DBF_DEBUG, device, |
| 762 | "start_IO: request %p started successful", |
| 763 | cqr); |
| 764 | break; |
| 765 | case -EBUSY: |
| 766 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
| 767 | "start_IO: device busy, retry later"); |
| 768 | break; |
| 769 | case -ETIMEDOUT: |
| 770 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
| 771 | "start_IO: request timeout, retry later"); |
| 772 | break; |
| 773 | case -EACCES: |
| 774 | /* -EACCES indicates that the request used only a |
| 775 | * subset of the available pathes and all these |
| 776 | * pathes are gone. |
| 777 | * Do a retry with all available pathes. |
| 778 | */ |
| 779 | cqr->lpm = LPM_ANYPATH; |
| 780 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
| 781 | "start_IO: selected pathes gone," |
| 782 | " retry on all pathes"); |
| 783 | break; |
| 784 | case -ENODEV: |
| 785 | case -EIO: |
| 786 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
| 787 | "start_IO: device gone, retry"); |
| 788 | break; |
| 789 | default: |
| 790 | DEV_MESSAGE(KERN_ERR, device, |
| 791 | "line %d unknown RC=%d, please report" |
| 792 | " to linux390@de.ibm.com", __LINE__, rc); |
| 793 | BUG(); |
| 794 | break; |
| 795 | } |
| 796 | return rc; |
| 797 | } |
| 798 | |
| 799 | /* |
| 800 | * Timeout function for dasd devices. This is used for different purposes |
| 801 | * 1) missing interrupt handler for normal operation |
| 802 | * 2) delayed start of request where start_IO failed with -EBUSY |
| 803 | * 3) timeout for missing state change interrupts |
| 804 | * The head of the ccw queue will have status DASD_CQR_IN_IO for 1), |
| 805 | * DASD_CQR_QUEUED for 2) and 3). |
| 806 | */ |
| 807 | static void |
| 808 | dasd_timeout_device(unsigned long ptr) |
| 809 | { |
| 810 | unsigned long flags; |
| 811 | struct dasd_device *device; |
| 812 | |
| 813 | device = (struct dasd_device *) ptr; |
| 814 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 815 | /* re-activate request queue */ |
| 816 | device->stopped &= ~DASD_STOPPED_PENDING; |
| 817 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 818 | dasd_schedule_bh(device); |
| 819 | } |
| 820 | |
| 821 | /* |
| 822 | * Setup timeout for a device in jiffies. |
| 823 | */ |
| 824 | void |
| 825 | dasd_set_timer(struct dasd_device *device, int expires) |
| 826 | { |
| 827 | if (expires == 0) { |
| 828 | if (timer_pending(&device->timer)) |
| 829 | del_timer(&device->timer); |
| 830 | return; |
| 831 | } |
| 832 | if (timer_pending(&device->timer)) { |
| 833 | if (mod_timer(&device->timer, jiffies + expires)) |
| 834 | return; |
| 835 | } |
| 836 | device->timer.function = dasd_timeout_device; |
| 837 | device->timer.data = (unsigned long) device; |
| 838 | device->timer.expires = jiffies + expires; |
| 839 | add_timer(&device->timer); |
| 840 | } |
| 841 | |
| 842 | /* |
| 843 | * Clear timeout for a device. |
| 844 | */ |
| 845 | void |
| 846 | dasd_clear_timer(struct dasd_device *device) |
| 847 | { |
| 848 | if (timer_pending(&device->timer)) |
| 849 | del_timer(&device->timer); |
| 850 | } |
| 851 | |
| 852 | static void |
| 853 | dasd_handle_killed_request(struct ccw_device *cdev, unsigned long intparm) |
| 854 | { |
| 855 | struct dasd_ccw_req *cqr; |
| 856 | struct dasd_device *device; |
| 857 | |
| 858 | cqr = (struct dasd_ccw_req *) intparm; |
| 859 | if (cqr->status != DASD_CQR_IN_IO) { |
| 860 | MESSAGE(KERN_DEBUG, |
| 861 | "invalid status in handle_killed_request: " |
| 862 | "bus_id %s, status %02x", |
| 863 | cdev->dev.bus_id, cqr->status); |
| 864 | return; |
| 865 | } |
| 866 | |
| 867 | device = (struct dasd_device *) cqr->device; |
| 868 | if (device == NULL || |
| 869 | device != dasd_device_from_cdev(cdev) || |
| 870 | strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) { |
| 871 | MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s", |
| 872 | cdev->dev.bus_id); |
| 873 | return; |
| 874 | } |
| 875 | |
| 876 | /* Schedule request to be retried. */ |
| 877 | cqr->status = DASD_CQR_QUEUED; |
| 878 | |
| 879 | dasd_clear_timer(device); |
| 880 | dasd_schedule_bh(device); |
| 881 | dasd_put_device(device); |
| 882 | } |
| 883 | |
| 884 | static void |
| 885 | dasd_handle_state_change_pending(struct dasd_device *device) |
| 886 | { |
| 887 | struct dasd_ccw_req *cqr; |
| 888 | struct list_head *l, *n; |
| 889 | |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 890 | /* First of all start sense subsystem status request. */ |
| 891 | dasd_eer_snss(device); |
| 892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | device->stopped &= ~DASD_STOPPED_PENDING; |
| 894 | |
| 895 | /* restart all 'running' IO on queue */ |
| 896 | list_for_each_safe(l, n, &device->ccw_queue) { |
| 897 | cqr = list_entry(l, struct dasd_ccw_req, list); |
| 898 | if (cqr->status == DASD_CQR_IN_IO) { |
| 899 | cqr->status = DASD_CQR_QUEUED; |
| 900 | } |
| 901 | } |
| 902 | dasd_clear_timer(device); |
| 903 | dasd_schedule_bh(device); |
| 904 | } |
| 905 | |
| 906 | /* |
| 907 | * Interrupt handler for "normal" ssch-io based dasd devices. |
| 908 | */ |
| 909 | void |
| 910 | dasd_int_handler(struct ccw_device *cdev, unsigned long intparm, |
| 911 | struct irb *irb) |
| 912 | { |
| 913 | struct dasd_ccw_req *cqr, *next; |
| 914 | struct dasd_device *device; |
| 915 | unsigned long long now; |
| 916 | int expires; |
| 917 | dasd_era_t era; |
| 918 | char mask; |
| 919 | |
| 920 | if (IS_ERR(irb)) { |
| 921 | switch (PTR_ERR(irb)) { |
| 922 | case -EIO: |
| 923 | dasd_handle_killed_request(cdev, intparm); |
| 924 | break; |
| 925 | case -ETIMEDOUT: |
| 926 | printk(KERN_WARNING"%s(%s): request timed out\n", |
| 927 | __FUNCTION__, cdev->dev.bus_id); |
| 928 | //FIXME - dasd uses own timeout interface... |
| 929 | break; |
| 930 | default: |
| 931 | printk(KERN_WARNING"%s(%s): unknown error %ld\n", |
| 932 | __FUNCTION__, cdev->dev.bus_id, PTR_ERR(irb)); |
| 933 | } |
| 934 | return; |
| 935 | } |
| 936 | |
| 937 | now = get_clock(); |
| 938 | |
| 939 | DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x", |
| 940 | cdev->dev.bus_id, ((irb->scsw.cstat<<8)|irb->scsw.dstat), |
| 941 | (unsigned int) intparm); |
| 942 | |
| 943 | /* first of all check for state change pending interrupt */ |
| 944 | mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP; |
| 945 | if ((irb->scsw.dstat & mask) == mask) { |
| 946 | device = dasd_device_from_cdev(cdev); |
| 947 | if (!IS_ERR(device)) { |
| 948 | dasd_handle_state_change_pending(device); |
| 949 | dasd_put_device(device); |
| 950 | } |
| 951 | return; |
| 952 | } |
| 953 | |
| 954 | cqr = (struct dasd_ccw_req *) intparm; |
| 955 | |
| 956 | /* check for unsolicited interrupts */ |
| 957 | if (cqr == NULL) { |
| 958 | MESSAGE(KERN_DEBUG, |
| 959 | "unsolicited interrupt received: bus_id %s", |
| 960 | cdev->dev.bus_id); |
| 961 | return; |
| 962 | } |
| 963 | |
| 964 | device = (struct dasd_device *) cqr->device; |
| 965 | if (device == NULL || |
| 966 | strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) { |
| 967 | MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s", |
| 968 | cdev->dev.bus_id); |
| 969 | return; |
| 970 | } |
| 971 | |
| 972 | /* Check for clear pending */ |
| 973 | if (cqr->status == DASD_CQR_CLEAR && |
| 974 | irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) { |
| 975 | cqr->status = DASD_CQR_QUEUED; |
| 976 | dasd_clear_timer(device); |
| 977 | dasd_schedule_bh(device); |
| 978 | return; |
| 979 | } |
| 980 | |
| 981 | /* check status - the request might have been killed by dyn detach */ |
| 982 | if (cqr->status != DASD_CQR_IN_IO) { |
| 983 | MESSAGE(KERN_DEBUG, |
| 984 | "invalid status: bus_id %s, status %02x", |
| 985 | cdev->dev.bus_id, cqr->status); |
| 986 | return; |
| 987 | } |
| 988 | DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p", |
| 989 | ((irb->scsw.cstat << 8) | irb->scsw.dstat), cqr); |
| 990 | |
| 991 | /* Find out the appropriate era_action. */ |
| 992 | if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC) |
| 993 | era = dasd_era_fatal; |
| 994 | else if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) && |
| 995 | irb->scsw.cstat == 0 && |
| 996 | !irb->esw.esw0.erw.cons) |
| 997 | era = dasd_era_none; |
| 998 | else if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) |
| 999 | era = dasd_era_fatal; /* don't recover this request */ |
| 1000 | else if (irb->esw.esw0.erw.cons) |
| 1001 | era = device->discipline->examine_error(cqr, irb); |
| 1002 | else |
| 1003 | era = dasd_era_recover; |
| 1004 | |
| 1005 | DBF_DEV_EVENT(DBF_DEBUG, device, "era_code %d", era); |
| 1006 | expires = 0; |
| 1007 | if (era == dasd_era_none) { |
| 1008 | cqr->status = DASD_CQR_DONE; |
| 1009 | cqr->stopclk = now; |
| 1010 | /* Start first request on queue if possible -> fast_io. */ |
| 1011 | if (cqr->list.next != &device->ccw_queue) { |
| 1012 | next = list_entry(cqr->list.next, |
| 1013 | struct dasd_ccw_req, list); |
| 1014 | if ((next->status == DASD_CQR_QUEUED) && |
| 1015 | (!device->stopped)) { |
| 1016 | if (device->discipline->start_IO(next) == 0) |
| 1017 | expires = next->expires; |
| 1018 | else |
| 1019 | DEV_MESSAGE(KERN_DEBUG, device, "%s", |
| 1020 | "Interrupt fastpath " |
| 1021 | "failed!"); |
| 1022 | } |
| 1023 | } |
| 1024 | } else { /* error */ |
| 1025 | memcpy(&cqr->irb, irb, sizeof (struct irb)); |
| 1026 | #ifdef ERP_DEBUG |
| 1027 | /* dump sense data */ |
| 1028 | dasd_log_sense(cqr, irb); |
| 1029 | #endif |
| 1030 | switch (era) { |
| 1031 | case dasd_era_fatal: |
| 1032 | cqr->status = DASD_CQR_FAILED; |
| 1033 | cqr->stopclk = now; |
| 1034 | break; |
| 1035 | case dasd_era_recover: |
| 1036 | cqr->status = DASD_CQR_ERROR; |
| 1037 | break; |
| 1038 | default: |
| 1039 | BUG(); |
| 1040 | } |
| 1041 | } |
| 1042 | if (expires != 0) |
| 1043 | dasd_set_timer(device, expires); |
| 1044 | else |
| 1045 | dasd_clear_timer(device); |
| 1046 | dasd_schedule_bh(device); |
| 1047 | } |
| 1048 | |
| 1049 | /* |
| 1050 | * posts the buffer_cache about a finalized request |
| 1051 | */ |
| 1052 | static inline void |
| 1053 | dasd_end_request(struct request *req, int uptodate) |
| 1054 | { |
| 1055 | if (end_that_request_first(req, uptodate, req->hard_nr_sectors)) |
| 1056 | BUG(); |
| 1057 | add_disk_randomness(req->rq_disk); |
Tejun Heo | 8ffdc65 | 2006-01-06 09:49:03 +0100 | [diff] [blame] | 1058 | end_that_request_last(req, uptodate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | /* |
| 1062 | * Process finished error recovery ccw. |
| 1063 | */ |
| 1064 | static inline void |
| 1065 | __dasd_process_erp(struct dasd_device *device, struct dasd_ccw_req *cqr) |
| 1066 | { |
| 1067 | dasd_erp_fn_t erp_fn; |
| 1068 | |
| 1069 | if (cqr->status == DASD_CQR_DONE) |
| 1070 | DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful"); |
| 1071 | else |
| 1072 | DEV_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful"); |
| 1073 | erp_fn = device->discipline->erp_postaction(cqr); |
| 1074 | erp_fn(cqr); |
| 1075 | } |
| 1076 | |
| 1077 | /* |
| 1078 | * Process ccw request queue. |
| 1079 | */ |
| 1080 | static inline void |
| 1081 | __dasd_process_ccw_queue(struct dasd_device * device, |
| 1082 | struct list_head *final_queue) |
| 1083 | { |
| 1084 | struct list_head *l, *n; |
| 1085 | struct dasd_ccw_req *cqr; |
| 1086 | dasd_erp_fn_t erp_fn; |
| 1087 | |
| 1088 | restart: |
| 1089 | /* Process request with final status. */ |
| 1090 | list_for_each_safe(l, n, &device->ccw_queue) { |
| 1091 | cqr = list_entry(l, struct dasd_ccw_req, list); |
| 1092 | /* Stop list processing at the first non-final request. */ |
| 1093 | if (cqr->status != DASD_CQR_DONE && |
| 1094 | cqr->status != DASD_CQR_FAILED && |
| 1095 | cqr->status != DASD_CQR_ERROR) |
| 1096 | break; |
| 1097 | /* Process requests with DASD_CQR_ERROR */ |
| 1098 | if (cqr->status == DASD_CQR_ERROR) { |
| 1099 | if (cqr->irb.scsw.fctl & SCSW_FCTL_HALT_FUNC) { |
| 1100 | cqr->status = DASD_CQR_FAILED; |
| 1101 | cqr->stopclk = get_clock(); |
| 1102 | } else { |
| 1103 | if (cqr->irb.esw.esw0.erw.cons) { |
| 1104 | erp_fn = device->discipline-> |
| 1105 | erp_action(cqr); |
| 1106 | erp_fn(cqr); |
| 1107 | } else |
| 1108 | dasd_default_erp_action(cqr); |
| 1109 | } |
| 1110 | goto restart; |
| 1111 | } |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1112 | |
| 1113 | /* First of all call extended error reporting. */ |
| 1114 | if (dasd_eer_enabled(device) && |
| 1115 | cqr->status == DASD_CQR_FAILED) { |
| 1116 | dasd_eer_write(device, cqr, DASD_EER_FATALERROR); |
| 1117 | |
| 1118 | /* restart request */ |
| 1119 | cqr->status = DASD_CQR_QUEUED; |
| 1120 | cqr->retries = 255; |
| 1121 | device->stopped |= DASD_STOPPED_QUIESCE; |
| 1122 | goto restart; |
| 1123 | } |
| 1124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | /* Process finished ERP request. */ |
| 1126 | if (cqr->refers) { |
| 1127 | __dasd_process_erp(device, cqr); |
| 1128 | goto restart; |
| 1129 | } |
| 1130 | |
| 1131 | /* Rechain finished requests to final queue */ |
| 1132 | cqr->endclk = get_clock(); |
| 1133 | list_move_tail(&cqr->list, final_queue); |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | static void |
| 1138 | dasd_end_request_cb(struct dasd_ccw_req * cqr, void *data) |
| 1139 | { |
| 1140 | struct request *req; |
| 1141 | struct dasd_device *device; |
| 1142 | int status; |
| 1143 | |
| 1144 | req = (struct request *) data; |
| 1145 | device = cqr->device; |
| 1146 | dasd_profile_end(device, cqr, req); |
| 1147 | status = cqr->device->discipline->free_cp(cqr,req); |
| 1148 | spin_lock_irq(&device->request_queue_lock); |
| 1149 | dasd_end_request(req, status); |
| 1150 | spin_unlock_irq(&device->request_queue_lock); |
| 1151 | } |
| 1152 | |
| 1153 | |
| 1154 | /* |
| 1155 | * Fetch requests from the block device queue. |
| 1156 | */ |
| 1157 | static inline void |
| 1158 | __dasd_process_blk_queue(struct dasd_device * device) |
| 1159 | { |
| 1160 | request_queue_t *queue; |
| 1161 | struct request *req; |
| 1162 | struct dasd_ccw_req *cqr; |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 1163 | int nr_queued; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | |
| 1165 | queue = device->request_queue; |
| 1166 | /* No queue ? Then there is nothing to do. */ |
| 1167 | if (queue == NULL) |
| 1168 | return; |
| 1169 | |
| 1170 | /* |
| 1171 | * We requeue request from the block device queue to the ccw |
| 1172 | * queue only in two states. In state DASD_STATE_READY the |
| 1173 | * partition detection is done and we need to requeue requests |
| 1174 | * for that. State DASD_STATE_ONLINE is normal block device |
| 1175 | * operation. |
| 1176 | */ |
| 1177 | if (device->state != DASD_STATE_READY && |
| 1178 | device->state != DASD_STATE_ONLINE) |
| 1179 | return; |
| 1180 | nr_queued = 0; |
| 1181 | /* Now we try to fetch requests from the request queue */ |
| 1182 | list_for_each_entry(cqr, &device->ccw_queue, list) |
| 1183 | if (cqr->status == DASD_CQR_QUEUED) |
| 1184 | nr_queued++; |
| 1185 | while (!blk_queue_plugged(queue) && |
| 1186 | elv_next_request(queue) && |
| 1187 | nr_queued < DASD_CHANQ_MAX_SIZE) { |
| 1188 | req = elv_next_request(queue); |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1189 | |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 1190 | if (device->features & DASD_FEATURE_READONLY && |
| 1191 | rq_data_dir(req) == WRITE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | DBF_DEV_EVENT(DBF_ERR, device, |
| 1193 | "Rejecting write request %p", |
| 1194 | req); |
| 1195 | blkdev_dequeue_request(req); |
| 1196 | dasd_end_request(req, 0); |
| 1197 | continue; |
| 1198 | } |
| 1199 | if (device->stopped & DASD_STOPPED_DC_EIO) { |
| 1200 | blkdev_dequeue_request(req); |
| 1201 | dasd_end_request(req, 0); |
| 1202 | continue; |
| 1203 | } |
| 1204 | cqr = device->discipline->build_cp(device, req); |
| 1205 | if (IS_ERR(cqr)) { |
| 1206 | if (PTR_ERR(cqr) == -ENOMEM) |
| 1207 | break; /* terminate request queue loop */ |
| 1208 | DBF_DEV_EVENT(DBF_ERR, device, |
| 1209 | "CCW creation failed (rc=%ld) " |
| 1210 | "on request %p", |
| 1211 | PTR_ERR(cqr), req); |
| 1212 | blkdev_dequeue_request(req); |
| 1213 | dasd_end_request(req, 0); |
| 1214 | continue; |
| 1215 | } |
| 1216 | cqr->callback = dasd_end_request_cb; |
| 1217 | cqr->callback_data = (void *) req; |
| 1218 | cqr->status = DASD_CQR_QUEUED; |
| 1219 | blkdev_dequeue_request(req); |
| 1220 | list_add_tail(&cqr->list, &device->ccw_queue); |
| 1221 | dasd_profile_start(device, cqr, req); |
| 1222 | nr_queued++; |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | /* |
| 1227 | * Take a look at the first request on the ccw queue and check |
| 1228 | * if it reached its expire time. If so, terminate the IO. |
| 1229 | */ |
| 1230 | static inline void |
| 1231 | __dasd_check_expire(struct dasd_device * device) |
| 1232 | { |
| 1233 | struct dasd_ccw_req *cqr; |
| 1234 | |
| 1235 | if (list_empty(&device->ccw_queue)) |
| 1236 | return; |
| 1237 | cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list); |
| 1238 | if (cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) { |
| 1239 | if (time_after_eq(jiffies, cqr->expires + cqr->starttime)) { |
| 1240 | if (device->discipline->term_IO(cqr) != 0) |
| 1241 | /* Hmpf, try again in 1/10 sec */ |
| 1242 | dasd_set_timer(device, 10); |
| 1243 | } |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | /* |
| 1248 | * Take a look at the first request on the ccw queue and check |
| 1249 | * if it needs to be started. |
| 1250 | */ |
| 1251 | static inline void |
| 1252 | __dasd_start_head(struct dasd_device * device) |
| 1253 | { |
| 1254 | struct dasd_ccw_req *cqr; |
| 1255 | int rc; |
| 1256 | |
| 1257 | if (list_empty(&device->ccw_queue)) |
| 1258 | return; |
| 1259 | cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list); |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 1260 | /* check FAILFAST */ |
| 1261 | if (device->stopped & ~DASD_STOPPED_PENDING && |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1262 | test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) && |
| 1263 | (!dasd_eer_enabled(device))) { |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 1264 | cqr->status = DASD_CQR_FAILED; |
| 1265 | dasd_schedule_bh(device); |
| 1266 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | if ((cqr->status == DASD_CQR_QUEUED) && |
| 1268 | (!device->stopped)) { |
| 1269 | /* try to start the first I/O that can be started */ |
| 1270 | rc = device->discipline->start_IO(cqr); |
| 1271 | if (rc == 0) |
| 1272 | dasd_set_timer(device, cqr->expires); |
| 1273 | else if (rc == -EACCES) { |
| 1274 | dasd_schedule_bh(device); |
| 1275 | } else |
| 1276 | /* Hmpf, try again in 1/2 sec */ |
| 1277 | dasd_set_timer(device, 50); |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | /* |
| 1282 | * Remove requests from the ccw queue. |
| 1283 | */ |
| 1284 | static void |
| 1285 | dasd_flush_ccw_queue(struct dasd_device * device, int all) |
| 1286 | { |
| 1287 | struct list_head flush_queue; |
| 1288 | struct list_head *l, *n; |
| 1289 | struct dasd_ccw_req *cqr; |
| 1290 | |
| 1291 | INIT_LIST_HEAD(&flush_queue); |
| 1292 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
| 1293 | list_for_each_safe(l, n, &device->ccw_queue) { |
| 1294 | cqr = list_entry(l, struct dasd_ccw_req, list); |
| 1295 | /* Flush all request or only block device requests? */ |
| 1296 | if (all == 0 && cqr->callback == dasd_end_request_cb) |
| 1297 | continue; |
| 1298 | if (cqr->status == DASD_CQR_IN_IO) |
| 1299 | device->discipline->term_IO(cqr); |
| 1300 | if (cqr->status != DASD_CQR_DONE || |
| 1301 | cqr->status != DASD_CQR_FAILED) { |
| 1302 | cqr->status = DASD_CQR_FAILED; |
| 1303 | cqr->stopclk = get_clock(); |
| 1304 | } |
| 1305 | /* Process finished ERP request. */ |
| 1306 | if (cqr->refers) { |
| 1307 | __dasd_process_erp(device, cqr); |
| 1308 | continue; |
| 1309 | } |
| 1310 | /* Rechain request on device request queue */ |
| 1311 | cqr->endclk = get_clock(); |
| 1312 | list_move_tail(&cqr->list, &flush_queue); |
| 1313 | } |
| 1314 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 1315 | /* Now call the callback function of flushed requests */ |
| 1316 | list_for_each_safe(l, n, &flush_queue) { |
| 1317 | cqr = list_entry(l, struct dasd_ccw_req, list); |
| 1318 | if (cqr->callback != NULL) |
| 1319 | (cqr->callback)(cqr, cqr->callback_data); |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | /* |
| 1324 | * Acquire the device lock and process queues for the device. |
| 1325 | */ |
| 1326 | static void |
| 1327 | dasd_tasklet(struct dasd_device * device) |
| 1328 | { |
| 1329 | struct list_head final_queue; |
| 1330 | struct list_head *l, *n; |
| 1331 | struct dasd_ccw_req *cqr; |
| 1332 | |
| 1333 | atomic_set (&device->tasklet_scheduled, 0); |
| 1334 | INIT_LIST_HEAD(&final_queue); |
| 1335 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
| 1336 | /* Check expire time of first request on the ccw queue. */ |
| 1337 | __dasd_check_expire(device); |
| 1338 | /* Finish off requests on ccw queue */ |
| 1339 | __dasd_process_ccw_queue(device, &final_queue); |
| 1340 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 1341 | /* Now call the callback function of requests with final status */ |
| 1342 | list_for_each_safe(l, n, &final_queue) { |
| 1343 | cqr = list_entry(l, struct dasd_ccw_req, list); |
Horst Hummel | c2ba444 | 2006-02-01 03:06:37 -0800 | [diff] [blame] | 1344 | list_del_init(&cqr->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | if (cqr->callback != NULL) |
| 1346 | (cqr->callback)(cqr, cqr->callback_data); |
| 1347 | } |
| 1348 | spin_lock_irq(&device->request_queue_lock); |
| 1349 | spin_lock(get_ccwdev_lock(device->cdev)); |
| 1350 | /* Get new request from the block device request queue */ |
| 1351 | __dasd_process_blk_queue(device); |
| 1352 | /* Now check if the head of the ccw queue needs to be started. */ |
| 1353 | __dasd_start_head(device); |
| 1354 | spin_unlock(get_ccwdev_lock(device->cdev)); |
| 1355 | spin_unlock_irq(&device->request_queue_lock); |
| 1356 | dasd_put_device(device); |
| 1357 | } |
| 1358 | |
| 1359 | /* |
| 1360 | * Schedules a call to dasd_tasklet over the device tasklet. |
| 1361 | */ |
| 1362 | void |
| 1363 | dasd_schedule_bh(struct dasd_device * device) |
| 1364 | { |
| 1365 | /* Protect against rescheduling. */ |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 1366 | if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | return; |
| 1368 | dasd_get_device(device); |
| 1369 | tasklet_hi_schedule(&device->tasklet); |
| 1370 | } |
| 1371 | |
| 1372 | /* |
| 1373 | * Queue a request to the head of the ccw_queue. Start the I/O if |
| 1374 | * possible. |
| 1375 | */ |
| 1376 | void |
| 1377 | dasd_add_request_head(struct dasd_ccw_req *req) |
| 1378 | { |
| 1379 | struct dasd_device *device; |
| 1380 | unsigned long flags; |
| 1381 | |
| 1382 | device = req->device; |
| 1383 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 1384 | req->status = DASD_CQR_QUEUED; |
| 1385 | req->device = device; |
| 1386 | list_add(&req->list, &device->ccw_queue); |
| 1387 | /* let the bh start the request to keep them in order */ |
| 1388 | dasd_schedule_bh(device); |
| 1389 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 1390 | } |
| 1391 | |
| 1392 | /* |
| 1393 | * Queue a request to the tail of the ccw_queue. Start the I/O if |
| 1394 | * possible. |
| 1395 | */ |
| 1396 | void |
| 1397 | dasd_add_request_tail(struct dasd_ccw_req *req) |
| 1398 | { |
| 1399 | struct dasd_device *device; |
| 1400 | unsigned long flags; |
| 1401 | |
| 1402 | device = req->device; |
| 1403 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 1404 | req->status = DASD_CQR_QUEUED; |
| 1405 | req->device = device; |
| 1406 | list_add_tail(&req->list, &device->ccw_queue); |
| 1407 | /* let the bh start the request to keep them in order */ |
| 1408 | dasd_schedule_bh(device); |
| 1409 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 1410 | } |
| 1411 | |
| 1412 | /* |
| 1413 | * Wakeup callback. |
| 1414 | */ |
| 1415 | static void |
| 1416 | dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data) |
| 1417 | { |
| 1418 | wake_up((wait_queue_head_t *) data); |
| 1419 | } |
| 1420 | |
| 1421 | static inline int |
| 1422 | _wait_for_wakeup(struct dasd_ccw_req *cqr) |
| 1423 | { |
| 1424 | struct dasd_device *device; |
| 1425 | int rc; |
| 1426 | |
| 1427 | device = cqr->device; |
| 1428 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
Horst Hummel | c2ba444 | 2006-02-01 03:06:37 -0800 | [diff] [blame] | 1429 | rc = ((cqr->status == DASD_CQR_DONE || |
| 1430 | cqr->status == DASD_CQR_FAILED) && |
| 1431 | list_empty(&cqr->list)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 1433 | return rc; |
| 1434 | } |
| 1435 | |
| 1436 | /* |
| 1437 | * Attempts to start a special ccw queue and waits for its completion. |
| 1438 | */ |
| 1439 | int |
| 1440 | dasd_sleep_on(struct dasd_ccw_req * cqr) |
| 1441 | { |
| 1442 | wait_queue_head_t wait_q; |
| 1443 | struct dasd_device *device; |
| 1444 | int rc; |
| 1445 | |
| 1446 | device = cqr->device; |
| 1447 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
| 1448 | |
| 1449 | init_waitqueue_head (&wait_q); |
| 1450 | cqr->callback = dasd_wakeup_cb; |
| 1451 | cqr->callback_data = (void *) &wait_q; |
| 1452 | cqr->status = DASD_CQR_QUEUED; |
| 1453 | list_add_tail(&cqr->list, &device->ccw_queue); |
| 1454 | |
| 1455 | /* let the bh start the request to keep them in order */ |
| 1456 | dasd_schedule_bh(device); |
| 1457 | |
| 1458 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 1459 | |
| 1460 | wait_event(wait_q, _wait_for_wakeup(cqr)); |
| 1461 | |
| 1462 | /* Request status is either done or failed. */ |
| 1463 | rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0; |
| 1464 | return rc; |
| 1465 | } |
| 1466 | |
| 1467 | /* |
| 1468 | * Attempts to start a special ccw queue and wait interruptible |
| 1469 | * for its completion. |
| 1470 | */ |
| 1471 | int |
| 1472 | dasd_sleep_on_interruptible(struct dasd_ccw_req * cqr) |
| 1473 | { |
| 1474 | wait_queue_head_t wait_q; |
| 1475 | struct dasd_device *device; |
| 1476 | int rc, finished; |
| 1477 | |
| 1478 | device = cqr->device; |
| 1479 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
| 1480 | |
| 1481 | init_waitqueue_head (&wait_q); |
| 1482 | cqr->callback = dasd_wakeup_cb; |
| 1483 | cqr->callback_data = (void *) &wait_q; |
| 1484 | cqr->status = DASD_CQR_QUEUED; |
| 1485 | list_add_tail(&cqr->list, &device->ccw_queue); |
| 1486 | |
| 1487 | /* let the bh start the request to keep them in order */ |
| 1488 | dasd_schedule_bh(device); |
| 1489 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 1490 | |
| 1491 | finished = 0; |
| 1492 | while (!finished) { |
| 1493 | rc = wait_event_interruptible(wait_q, _wait_for_wakeup(cqr)); |
| 1494 | if (rc != -ERESTARTSYS) { |
Horst Hummel | c2ba444 | 2006-02-01 03:06:37 -0800 | [diff] [blame] | 1495 | /* Request is final (done or failed) */ |
| 1496 | rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | break; |
| 1498 | } |
| 1499 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
Horst Hummel | c2ba444 | 2006-02-01 03:06:37 -0800 | [diff] [blame] | 1500 | switch (cqr->status) { |
| 1501 | case DASD_CQR_IN_IO: |
| 1502 | /* terminate runnig cqr */ |
| 1503 | if (device->discipline->term_IO) { |
| 1504 | cqr->retries = -1; |
| 1505 | device->discipline->term_IO(cqr); |
| 1506 | /*nished = |
| 1507 | * wait (non-interruptible) for final status |
| 1508 | * because signal ist still pending |
| 1509 | */ |
| 1510 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 1511 | wait_event(wait_q, _wait_for_wakeup(cqr)); |
| 1512 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
| 1513 | rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO; |
| 1514 | finished = 1; |
| 1515 | } |
| 1516 | break; |
| 1517 | case DASD_CQR_QUEUED: |
| 1518 | /* request */ |
| 1519 | list_del_init(&cqr->list); |
| 1520 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | finished = 1; |
Horst Hummel | c2ba444 | 2006-02-01 03:06:37 -0800 | [diff] [blame] | 1522 | break; |
| 1523 | default: |
| 1524 | /* cqr with 'non-interruptable' status - just wait */ |
| 1525 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | } |
| 1527 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 1528 | } |
| 1529 | return rc; |
| 1530 | } |
| 1531 | |
| 1532 | /* |
| 1533 | * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock |
| 1534 | * for eckd devices) the currently running request has to be terminated |
| 1535 | * and be put back to status queued, before the special request is added |
| 1536 | * to the head of the queue. Then the special request is waited on normally. |
| 1537 | */ |
| 1538 | static inline int |
| 1539 | _dasd_term_running_cqr(struct dasd_device *device) |
| 1540 | { |
| 1541 | struct dasd_ccw_req *cqr; |
| 1542 | int rc; |
| 1543 | |
| 1544 | if (list_empty(&device->ccw_queue)) |
| 1545 | return 0; |
| 1546 | cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list); |
| 1547 | rc = device->discipline->term_IO(cqr); |
| 1548 | if (rc == 0) { |
| 1549 | /* termination successful */ |
| 1550 | cqr->status = DASD_CQR_QUEUED; |
| 1551 | cqr->startclk = cqr->stopclk = 0; |
| 1552 | cqr->starttime = 0; |
| 1553 | } |
| 1554 | return rc; |
| 1555 | } |
| 1556 | |
| 1557 | int |
| 1558 | dasd_sleep_on_immediatly(struct dasd_ccw_req * cqr) |
| 1559 | { |
| 1560 | wait_queue_head_t wait_q; |
| 1561 | struct dasd_device *device; |
| 1562 | int rc; |
| 1563 | |
| 1564 | device = cqr->device; |
| 1565 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
| 1566 | rc = _dasd_term_running_cqr(device); |
| 1567 | if (rc) { |
| 1568 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 1569 | return rc; |
| 1570 | } |
| 1571 | |
| 1572 | init_waitqueue_head (&wait_q); |
| 1573 | cqr->callback = dasd_wakeup_cb; |
| 1574 | cqr->callback_data = (void *) &wait_q; |
| 1575 | cqr->status = DASD_CQR_QUEUED; |
| 1576 | list_add(&cqr->list, &device->ccw_queue); |
| 1577 | |
| 1578 | /* let the bh start the request to keep them in order */ |
| 1579 | dasd_schedule_bh(device); |
| 1580 | |
| 1581 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 1582 | |
| 1583 | wait_event(wait_q, _wait_for_wakeup(cqr)); |
| 1584 | |
| 1585 | /* Request status is either done or failed. */ |
| 1586 | rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0; |
| 1587 | return rc; |
| 1588 | } |
| 1589 | |
| 1590 | /* |
| 1591 | * Cancels a request that was started with dasd_sleep_on_req. |
| 1592 | * This is useful to timeout requests. The request will be |
| 1593 | * terminated if it is currently in i/o. |
| 1594 | * Returns 1 if the request has been terminated. |
| 1595 | */ |
| 1596 | int |
| 1597 | dasd_cancel_req(struct dasd_ccw_req *cqr) |
| 1598 | { |
| 1599 | struct dasd_device *device = cqr->device; |
| 1600 | unsigned long flags; |
| 1601 | int rc; |
| 1602 | |
| 1603 | rc = 0; |
| 1604 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 1605 | switch (cqr->status) { |
| 1606 | case DASD_CQR_QUEUED: |
| 1607 | /* request was not started - just set to failed */ |
| 1608 | cqr->status = DASD_CQR_FAILED; |
| 1609 | break; |
| 1610 | case DASD_CQR_IN_IO: |
| 1611 | /* request in IO - terminate IO and release again */ |
| 1612 | if (device->discipline->term_IO(cqr) != 0) |
| 1613 | /* what to do if unable to terminate ?????? |
| 1614 | e.g. not _IN_IO */ |
| 1615 | cqr->status = DASD_CQR_FAILED; |
| 1616 | cqr->stopclk = get_clock(); |
| 1617 | rc = 1; |
| 1618 | break; |
| 1619 | case DASD_CQR_DONE: |
| 1620 | case DASD_CQR_FAILED: |
| 1621 | /* already finished - do nothing */ |
| 1622 | break; |
| 1623 | default: |
| 1624 | DEV_MESSAGE(KERN_ALERT, device, |
| 1625 | "invalid status %02x in request", |
| 1626 | cqr->status); |
| 1627 | BUG(); |
| 1628 | |
| 1629 | } |
| 1630 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 1631 | dasd_schedule_bh(device); |
| 1632 | return rc; |
| 1633 | } |
| 1634 | |
| 1635 | /* |
| 1636 | * SECTION: Block device operations (request queue, partitions, open, release). |
| 1637 | */ |
| 1638 | |
| 1639 | /* |
| 1640 | * Dasd request queue function. Called from ll_rw_blk.c |
| 1641 | */ |
| 1642 | static void |
| 1643 | do_dasd_request(request_queue_t * queue) |
| 1644 | { |
| 1645 | struct dasd_device *device; |
| 1646 | |
| 1647 | device = (struct dasd_device *) queue->queuedata; |
| 1648 | spin_lock(get_ccwdev_lock(device->cdev)); |
| 1649 | /* Get new request from the block device request queue */ |
| 1650 | __dasd_process_blk_queue(device); |
| 1651 | /* Now check if the head of the ccw queue needs to be started. */ |
| 1652 | __dasd_start_head(device); |
| 1653 | spin_unlock(get_ccwdev_lock(device->cdev)); |
| 1654 | } |
| 1655 | |
| 1656 | /* |
| 1657 | * Allocate and initialize request queue and default I/O scheduler. |
| 1658 | */ |
| 1659 | static int |
| 1660 | dasd_alloc_queue(struct dasd_device * device) |
| 1661 | { |
| 1662 | int rc; |
| 1663 | |
| 1664 | device->request_queue = blk_init_queue(do_dasd_request, |
| 1665 | &device->request_queue_lock); |
| 1666 | if (device->request_queue == NULL) |
| 1667 | return -ENOMEM; |
| 1668 | |
| 1669 | device->request_queue->queuedata = device; |
| 1670 | |
| 1671 | elevator_exit(device->request_queue->elevator); |
| 1672 | rc = elevator_init(device->request_queue, "deadline"); |
| 1673 | if (rc) { |
| 1674 | blk_cleanup_queue(device->request_queue); |
| 1675 | return rc; |
| 1676 | } |
| 1677 | return 0; |
| 1678 | } |
| 1679 | |
| 1680 | /* |
| 1681 | * Allocate and initialize request queue. |
| 1682 | */ |
| 1683 | static void |
| 1684 | dasd_setup_queue(struct dasd_device * device) |
| 1685 | { |
| 1686 | int max; |
| 1687 | |
| 1688 | blk_queue_hardsect_size(device->request_queue, device->bp_block); |
| 1689 | max = device->discipline->max_blocks << device->s2b_shift; |
| 1690 | blk_queue_max_sectors(device->request_queue, max); |
| 1691 | blk_queue_max_phys_segments(device->request_queue, -1L); |
| 1692 | blk_queue_max_hw_segments(device->request_queue, -1L); |
| 1693 | blk_queue_max_segment_size(device->request_queue, -1L); |
| 1694 | blk_queue_segment_boundary(device->request_queue, -1L); |
Heiko Carstens | ed68cb3 | 2006-01-14 13:21:05 -0800 | [diff] [blame] | 1695 | blk_queue_ordered(device->request_queue, QUEUE_ORDERED_TAG, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | /* |
| 1699 | * Deactivate and free request queue. |
| 1700 | */ |
| 1701 | static void |
| 1702 | dasd_free_queue(struct dasd_device * device) |
| 1703 | { |
| 1704 | if (device->request_queue) { |
| 1705 | blk_cleanup_queue(device->request_queue); |
| 1706 | device->request_queue = NULL; |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | /* |
| 1711 | * Flush request on the request queue. |
| 1712 | */ |
| 1713 | static void |
| 1714 | dasd_flush_request_queue(struct dasd_device * device) |
| 1715 | { |
| 1716 | struct request *req; |
| 1717 | |
| 1718 | if (!device->request_queue) |
| 1719 | return; |
| 1720 | |
| 1721 | spin_lock_irq(&device->request_queue_lock); |
| 1722 | while (!list_empty(&device->request_queue->queue_head)) { |
| 1723 | req = elv_next_request(device->request_queue); |
| 1724 | if (req == NULL) |
| 1725 | break; |
| 1726 | dasd_end_request(req, 0); |
| 1727 | blkdev_dequeue_request(req); |
| 1728 | } |
| 1729 | spin_unlock_irq(&device->request_queue_lock); |
| 1730 | } |
| 1731 | |
| 1732 | static int |
| 1733 | dasd_open(struct inode *inp, struct file *filp) |
| 1734 | { |
| 1735 | struct gendisk *disk = inp->i_bdev->bd_disk; |
| 1736 | struct dasd_device *device = disk->private_data; |
| 1737 | int rc; |
| 1738 | |
| 1739 | atomic_inc(&device->open_count); |
| 1740 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) { |
| 1741 | rc = -ENODEV; |
| 1742 | goto unlock; |
| 1743 | } |
| 1744 | |
| 1745 | if (!try_module_get(device->discipline->owner)) { |
| 1746 | rc = -EINVAL; |
| 1747 | goto unlock; |
| 1748 | } |
| 1749 | |
| 1750 | if (dasd_probeonly) { |
| 1751 | DEV_MESSAGE(KERN_INFO, device, "%s", |
| 1752 | "No access to device due to probeonly mode"); |
| 1753 | rc = -EPERM; |
| 1754 | goto out; |
| 1755 | } |
| 1756 | |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 1757 | if (device->state <= DASD_STATE_BASIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | DBF_DEV_EVENT(DBF_ERR, device, " %s", |
| 1759 | " Cannot open unrecognized device"); |
| 1760 | rc = -ENODEV; |
| 1761 | goto out; |
| 1762 | } |
| 1763 | |
| 1764 | return 0; |
| 1765 | |
| 1766 | out: |
| 1767 | module_put(device->discipline->owner); |
| 1768 | unlock: |
| 1769 | atomic_dec(&device->open_count); |
| 1770 | return rc; |
| 1771 | } |
| 1772 | |
| 1773 | static int |
| 1774 | dasd_release(struct inode *inp, struct file *filp) |
| 1775 | { |
| 1776 | struct gendisk *disk = inp->i_bdev->bd_disk; |
| 1777 | struct dasd_device *device = disk->private_data; |
| 1778 | |
| 1779 | atomic_dec(&device->open_count); |
| 1780 | module_put(device->discipline->owner); |
| 1781 | return 0; |
| 1782 | } |
| 1783 | |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 1784 | /* |
| 1785 | * Return disk geometry. |
| 1786 | */ |
| 1787 | static int |
| 1788 | dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
| 1789 | { |
| 1790 | struct dasd_device *device; |
| 1791 | |
| 1792 | device = bdev->bd_disk->private_data; |
| 1793 | if (!device) |
| 1794 | return -ENODEV; |
| 1795 | |
| 1796 | if (!device->discipline || |
| 1797 | !device->discipline->fill_geometry) |
| 1798 | return -EINVAL; |
| 1799 | |
| 1800 | device->discipline->fill_geometry(device, geo); |
| 1801 | geo->start = get_start_sect(bdev) >> device->s2b_shift; |
| 1802 | return 0; |
| 1803 | } |
| 1804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | struct block_device_operations |
| 1806 | dasd_device_operations = { |
| 1807 | .owner = THIS_MODULE, |
| 1808 | .open = dasd_open, |
| 1809 | .release = dasd_release, |
| 1810 | .ioctl = dasd_ioctl, |
Christoph Hellwig | 8262037 | 2006-01-09 20:52:12 -0800 | [diff] [blame] | 1811 | .compat_ioctl = dasd_compat_ioctl, |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 1812 | .getgeo = dasd_getgeo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | }; |
| 1814 | |
| 1815 | |
| 1816 | static void |
| 1817 | dasd_exit(void) |
| 1818 | { |
| 1819 | #ifdef CONFIG_PROC_FS |
| 1820 | dasd_proc_exit(); |
| 1821 | #endif |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1822 | dasd_eer_exit(); |
Horst Hummel | 6bb0e01 | 2005-07-27 11:45:03 -0700 | [diff] [blame] | 1823 | if (dasd_page_cache != NULL) { |
| 1824 | kmem_cache_destroy(dasd_page_cache); |
| 1825 | dasd_page_cache = NULL; |
| 1826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | dasd_gendisk_exit(); |
| 1828 | dasd_devmap_exit(); |
| 1829 | devfs_remove("dasd"); |
| 1830 | if (dasd_debug_area != NULL) { |
| 1831 | debug_unregister(dasd_debug_area); |
| 1832 | dasd_debug_area = NULL; |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | /* |
| 1837 | * SECTION: common functions for ccw_driver use |
| 1838 | */ |
| 1839 | |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 1840 | /* |
| 1841 | * Initial attempt at a probe function. this can be simplified once |
| 1842 | * the other detection code is gone. |
| 1843 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | int |
| 1845 | dasd_generic_probe (struct ccw_device *cdev, |
| 1846 | struct dasd_discipline *discipline) |
| 1847 | { |
| 1848 | int ret; |
| 1849 | |
| 1850 | ret = dasd_add_sysfs_files(cdev); |
| 1851 | if (ret) { |
| 1852 | printk(KERN_WARNING |
| 1853 | "dasd_generic_probe: could not add sysfs entries " |
| 1854 | "for %s\n", cdev->dev.bus_id); |
Horst Hummel | 59afda7 | 2005-05-16 21:53:39 -0700 | [diff] [blame] | 1855 | } else { |
| 1856 | cdev->handler = &dasd_int_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | } |
| 1858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | return ret; |
| 1860 | } |
| 1861 | |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 1862 | /* |
| 1863 | * This will one day be called from a global not_oper handler. |
| 1864 | * It is also used by driver_unregister during module unload. |
| 1865 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | void |
| 1867 | dasd_generic_remove (struct ccw_device *cdev) |
| 1868 | { |
| 1869 | struct dasd_device *device; |
| 1870 | |
Horst Hummel | 59afda7 | 2005-05-16 21:53:39 -0700 | [diff] [blame] | 1871 | cdev->handler = NULL; |
| 1872 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | dasd_remove_sysfs_files(cdev); |
| 1874 | device = dasd_device_from_cdev(cdev); |
| 1875 | if (IS_ERR(device)) |
| 1876 | return; |
| 1877 | if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) { |
| 1878 | /* Already doing offline processing */ |
| 1879 | dasd_put_device(device); |
| 1880 | return; |
| 1881 | } |
| 1882 | /* |
| 1883 | * This device is removed unconditionally. Set offline |
| 1884 | * flag to prevent dasd_open from opening it while it is |
| 1885 | * no quite down yet. |
| 1886 | */ |
| 1887 | dasd_set_target_state(device, DASD_STATE_NEW); |
| 1888 | /* dasd_delete_device destroys the device reference. */ |
| 1889 | dasd_delete_device(device); |
| 1890 | } |
| 1891 | |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 1892 | /* |
| 1893 | * Activate a device. This is called from dasd_{eckd,fba}_probe() when either |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | * the device is detected for the first time and is supposed to be used |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 1895 | * or the user has started activation through sysfs. |
| 1896 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | int |
| 1898 | dasd_generic_set_online (struct ccw_device *cdev, |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 1899 | struct dasd_discipline *base_discipline) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | |
| 1901 | { |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 1902 | struct dasd_discipline *discipline; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | struct dasd_device *device; |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 1904 | int rc; |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1905 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | device = dasd_create_device(cdev); |
| 1907 | if (IS_ERR(device)) |
| 1908 | return PTR_ERR(device); |
| 1909 | |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 1910 | discipline = base_discipline; |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 1911 | if (device->features & DASD_FEATURE_USEDIAG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | if (!dasd_diag_discipline_pointer) { |
| 1913 | printk (KERN_WARNING |
| 1914 | "dasd_generic couldn't online device %s " |
| 1915 | "- discipline DIAG not available\n", |
| 1916 | cdev->dev.bus_id); |
| 1917 | dasd_delete_device(device); |
| 1918 | return -ENODEV; |
| 1919 | } |
| 1920 | discipline = dasd_diag_discipline_pointer; |
| 1921 | } |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 1922 | if (!try_module_get(base_discipline->owner)) { |
| 1923 | dasd_delete_device(device); |
| 1924 | return -EINVAL; |
| 1925 | } |
| 1926 | if (!try_module_get(discipline->owner)) { |
| 1927 | module_put(base_discipline->owner); |
| 1928 | dasd_delete_device(device); |
| 1929 | return -EINVAL; |
| 1930 | } |
| 1931 | device->base_discipline = base_discipline; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | device->discipline = discipline; |
| 1933 | |
| 1934 | rc = discipline->check_device(device); |
| 1935 | if (rc) { |
| 1936 | printk (KERN_WARNING |
| 1937 | "dasd_generic couldn't online device %s " |
| 1938 | "with discipline %s rc=%i\n", |
| 1939 | cdev->dev.bus_id, discipline->name, rc); |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 1940 | module_put(discipline->owner); |
| 1941 | module_put(base_discipline->owner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | dasd_delete_device(device); |
| 1943 | return rc; |
| 1944 | } |
| 1945 | |
| 1946 | dasd_set_target_state(device, DASD_STATE_ONLINE); |
| 1947 | if (device->state <= DASD_STATE_KNOWN) { |
| 1948 | printk (KERN_WARNING |
| 1949 | "dasd_generic discipline not found for %s\n", |
| 1950 | cdev->dev.bus_id); |
| 1951 | rc = -ENODEV; |
| 1952 | dasd_set_target_state(device, DASD_STATE_NEW); |
| 1953 | dasd_delete_device(device); |
| 1954 | } else |
| 1955 | pr_debug("dasd_generic device %s found\n", |
| 1956 | cdev->dev.bus_id); |
| 1957 | |
| 1958 | /* FIXME: we have to wait for the root device but we don't want |
| 1959 | * to wait for each single device but for all at once. */ |
| 1960 | wait_event(dasd_init_waitq, _wait_for_device(device)); |
| 1961 | |
| 1962 | dasd_put_device(device); |
| 1963 | |
| 1964 | return rc; |
| 1965 | } |
| 1966 | |
| 1967 | int |
| 1968 | dasd_generic_set_offline (struct ccw_device *cdev) |
| 1969 | { |
| 1970 | struct dasd_device *device; |
Horst Hummel | dafd87a | 2006-04-10 22:53:47 -0700 | [diff] [blame^] | 1971 | int max_count, open_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | |
| 1973 | device = dasd_device_from_cdev(cdev); |
| 1974 | if (IS_ERR(device)) |
| 1975 | return PTR_ERR(device); |
| 1976 | if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) { |
| 1977 | /* Already doing offline processing */ |
| 1978 | dasd_put_device(device); |
| 1979 | return 0; |
| 1980 | } |
| 1981 | /* |
| 1982 | * We must make sure that this device is currently not in use. |
| 1983 | * The open_count is increased for every opener, that includes |
| 1984 | * the blkdev_get in dasd_scan_partitions. We are only interested |
| 1985 | * in the other openers. |
| 1986 | */ |
| 1987 | max_count = device->bdev ? 0 : -1; |
Horst Hummel | dafd87a | 2006-04-10 22:53:47 -0700 | [diff] [blame^] | 1988 | open_count = (int) atomic_read(&device->open_count); |
| 1989 | if (open_count > max_count) { |
| 1990 | if (open_count > 0) |
| 1991 | printk (KERN_WARNING "Can't offline dasd device with " |
| 1992 | "open count = %i.\n", |
| 1993 | open_count); |
| 1994 | else |
| 1995 | printk (KERN_WARNING "%s", |
| 1996 | "Can't offline dasd device due to internal " |
| 1997 | "use\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | clear_bit(DASD_FLAG_OFFLINE, &device->flags); |
| 1999 | dasd_put_device(device); |
| 2000 | return -EBUSY; |
| 2001 | } |
| 2002 | dasd_set_target_state(device, DASD_STATE_NEW); |
| 2003 | /* dasd_delete_device destroys the device reference. */ |
| 2004 | dasd_delete_device(device); |
| 2005 | |
| 2006 | return 0; |
| 2007 | } |
| 2008 | |
| 2009 | int |
| 2010 | dasd_generic_notify(struct ccw_device *cdev, int event) |
| 2011 | { |
| 2012 | struct dasd_device *device; |
| 2013 | struct dasd_ccw_req *cqr; |
| 2014 | unsigned long flags; |
| 2015 | int ret; |
| 2016 | |
| 2017 | device = dasd_device_from_cdev(cdev); |
| 2018 | if (IS_ERR(device)) |
| 2019 | return 0; |
| 2020 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
| 2021 | ret = 0; |
| 2022 | switch (event) { |
| 2023 | case CIO_GONE: |
| 2024 | case CIO_NO_PATH: |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 2025 | /* First of all call extended error reporting. */ |
| 2026 | dasd_eer_write(device, NULL, DASD_EER_NOPATH); |
| 2027 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | if (device->state < DASD_STATE_BASIC) |
| 2029 | break; |
| 2030 | /* Device is active. We want to keep it. */ |
| 2031 | if (test_bit(DASD_FLAG_DSC_ERROR, &device->flags)) { |
| 2032 | list_for_each_entry(cqr, &device->ccw_queue, list) |
| 2033 | if (cqr->status == DASD_CQR_IN_IO) |
| 2034 | cqr->status = DASD_CQR_FAILED; |
| 2035 | device->stopped |= DASD_STOPPED_DC_EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | } else { |
| 2037 | list_for_each_entry(cqr, &device->ccw_queue, list) |
| 2038 | if (cqr->status == DASD_CQR_IN_IO) { |
| 2039 | cqr->status = DASD_CQR_QUEUED; |
| 2040 | cqr->retries++; |
| 2041 | } |
| 2042 | device->stopped |= DASD_STOPPED_DC_WAIT; |
| 2043 | dasd_set_timer(device, 0); |
| 2044 | } |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 2045 | dasd_schedule_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | ret = 1; |
| 2047 | break; |
| 2048 | case CIO_OPER: |
| 2049 | /* FIXME: add a sanity check. */ |
| 2050 | device->stopped &= ~(DASD_STOPPED_DC_WAIT|DASD_STOPPED_DC_EIO); |
| 2051 | dasd_schedule_bh(device); |
| 2052 | ret = 1; |
| 2053 | break; |
| 2054 | } |
| 2055 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
| 2056 | dasd_put_device(device); |
| 2057 | return ret; |
| 2058 | } |
| 2059 | |
| 2060 | /* |
| 2061 | * Automatically online either all dasd devices (dasd_autodetect) or |
| 2062 | * all devices specified with dasd= parameters. |
| 2063 | */ |
Cornelia Huck | c551288 | 2005-06-25 14:55:28 -0700 | [diff] [blame] | 2064 | static int |
| 2065 | __dasd_auto_online(struct device *dev, void *data) |
| 2066 | { |
| 2067 | struct ccw_device *cdev; |
| 2068 | |
| 2069 | cdev = to_ccwdev(dev); |
| 2070 | if (dasd_autodetect || dasd_busid_known(cdev->dev.bus_id) == 0) |
| 2071 | ccw_device_set_online(cdev); |
| 2072 | return 0; |
| 2073 | } |
| 2074 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | void |
| 2076 | dasd_generic_auto_online (struct ccw_driver *dasd_discipline_driver) |
| 2077 | { |
| 2078 | struct device_driver *drv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | |
| 2080 | drv = get_driver(&dasd_discipline_driver->driver); |
Cornelia Huck | c551288 | 2005-06-25 14:55:28 -0700 | [diff] [blame] | 2081 | driver_for_each_device(drv, NULL, NULL, __dasd_auto_online); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | put_driver(drv); |
| 2083 | } |
| 2084 | |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 2085 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | static int __init |
| 2087 | dasd_init(void) |
| 2088 | { |
| 2089 | int rc; |
| 2090 | |
| 2091 | init_waitqueue_head(&dasd_init_waitq); |
| 2092 | |
| 2093 | /* register 'common' DASD debug area, used for all DBF_XXX calls */ |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 2094 | dasd_debug_area = debug_register("dasd", 1, 2, 8 * sizeof (long)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | if (dasd_debug_area == NULL) { |
| 2096 | rc = -ENOMEM; |
| 2097 | goto failed; |
| 2098 | } |
| 2099 | debug_register_view(dasd_debug_area, &debug_sprintf_view); |
| 2100 | debug_set_level(dasd_debug_area, DBF_EMERG); |
| 2101 | |
| 2102 | DBF_EVENT(DBF_EMERG, "%s", "debug area created"); |
| 2103 | |
| 2104 | dasd_diag_discipline_pointer = NULL; |
| 2105 | |
| 2106 | rc = devfs_mk_dir("dasd"); |
| 2107 | if (rc) |
| 2108 | goto failed; |
| 2109 | rc = dasd_devmap_init(); |
| 2110 | if (rc) |
| 2111 | goto failed; |
| 2112 | rc = dasd_gendisk_init(); |
| 2113 | if (rc) |
| 2114 | goto failed; |
| 2115 | rc = dasd_parse(); |
| 2116 | if (rc) |
| 2117 | goto failed; |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 2118 | rc = dasd_eer_init(); |
| 2119 | if (rc) |
| 2120 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | #ifdef CONFIG_PROC_FS |
| 2122 | rc = dasd_proc_init(); |
| 2123 | if (rc) |
| 2124 | goto failed; |
| 2125 | #endif |
| 2126 | |
| 2127 | return 0; |
| 2128 | failed: |
| 2129 | MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors"); |
| 2130 | dasd_exit(); |
| 2131 | return rc; |
| 2132 | } |
| 2133 | |
| 2134 | module_init(dasd_init); |
| 2135 | module_exit(dasd_exit); |
| 2136 | |
| 2137 | EXPORT_SYMBOL(dasd_debug_area); |
| 2138 | EXPORT_SYMBOL(dasd_diag_discipline_pointer); |
| 2139 | |
| 2140 | EXPORT_SYMBOL(dasd_add_request_head); |
| 2141 | EXPORT_SYMBOL(dasd_add_request_tail); |
| 2142 | EXPORT_SYMBOL(dasd_cancel_req); |
| 2143 | EXPORT_SYMBOL(dasd_clear_timer); |
| 2144 | EXPORT_SYMBOL(dasd_enable_device); |
| 2145 | EXPORT_SYMBOL(dasd_int_handler); |
| 2146 | EXPORT_SYMBOL(dasd_kfree_request); |
| 2147 | EXPORT_SYMBOL(dasd_kick_device); |
| 2148 | EXPORT_SYMBOL(dasd_kmalloc_request); |
| 2149 | EXPORT_SYMBOL(dasd_schedule_bh); |
| 2150 | EXPORT_SYMBOL(dasd_set_target_state); |
| 2151 | EXPORT_SYMBOL(dasd_set_timer); |
| 2152 | EXPORT_SYMBOL(dasd_sfree_request); |
| 2153 | EXPORT_SYMBOL(dasd_sleep_on); |
| 2154 | EXPORT_SYMBOL(dasd_sleep_on_immediatly); |
| 2155 | EXPORT_SYMBOL(dasd_sleep_on_interruptible); |
| 2156 | EXPORT_SYMBOL(dasd_smalloc_request); |
| 2157 | EXPORT_SYMBOL(dasd_start_IO); |
| 2158 | EXPORT_SYMBOL(dasd_term_IO); |
| 2159 | |
| 2160 | EXPORT_SYMBOL_GPL(dasd_generic_probe); |
| 2161 | EXPORT_SYMBOL_GPL(dasd_generic_remove); |
| 2162 | EXPORT_SYMBOL_GPL(dasd_generic_notify); |
| 2163 | EXPORT_SYMBOL_GPL(dasd_generic_set_online); |
| 2164 | EXPORT_SYMBOL_GPL(dasd_generic_set_offline); |
| 2165 | EXPORT_SYMBOL_GPL(dasd_generic_auto_online); |
| 2166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | /* |
| 2168 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 2169 | * Emacs will notice this stuff at the end of the file and automatically |
| 2170 | * adjust the settings for this buffer only. This must remain at the end |
| 2171 | * of the file. |
| 2172 | * --------------------------------------------------------------------------- |
| 2173 | * Local variables: |
| 2174 | * c-indent-level: 4 |
| 2175 | * c-brace-imaginary-offset: 0 |
| 2176 | * c-brace-offset: -4 |
| 2177 | * c-argdecl-indent: 4 |
| 2178 | * c-label-offset: -4 |
| 2179 | * c-continued-statement-offset: 4 |
| 2180 | * c-continued-brace-offset: 0 |
| 2181 | * indent-tabs-mode: 1 |
| 2182 | * tab-width: 8 |
| 2183 | * End: |
| 2184 | */ |