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