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