vserver 1.9.5.x5
[linux-2.6.git] / drivers / s390 / block / dasd.c
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  *
10  * $Revision: 1.156 $
11  */
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>
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");
46 MODULE_PARM(dasd, "1-" __MODULE_STRING(256) "s");
47 MODULE_LICENSE("GPL");
48
49 /*
50  * SECTION: prototypes for static functions of dasd.c
51  */
52 static int  dasd_alloc_queue(struct dasd_device * device);
53 static void dasd_setup_queue(struct dasd_device * device);
54 static void dasd_free_queue(struct dasd_device * device);
55 static void dasd_flush_request_queue(struct dasd_device *);
56 static void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
57 static void dasd_flush_ccw_queue(struct dasd_device *, int);
58 static void dasd_tasklet(struct dasd_device *);
59 static void do_kick_device(void *data);
60
61 /*
62  * SECTION: Operations on the device structure.
63  */
64 static wait_queue_head_t dasd_init_waitq;
65
66 /*
67  * Allocate memory for a new device structure.
68  */
69 struct dasd_device *
70 dasd_alloc_device(void)
71 {
72         struct dasd_device *device;
73
74         device = kmalloc(sizeof (struct dasd_device), GFP_ATOMIC);
75         if (device == NULL)
76                 return ERR_PTR(-ENOMEM);
77         memset(device, 0, sizeof (struct dasd_device));
78         /* open_count = 0 means device online but not in use */
79         atomic_set(&device->open_count, -1);
80
81         /* Get two pages for normal block device operations. */
82         device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
83         if (device->ccw_mem == NULL) {
84                 kfree(device);
85                 return ERR_PTR(-ENOMEM);
86         }
87         /* Get one page for error recovery. */
88         device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
89         if (device->erp_mem == NULL) {
90                 free_pages((unsigned long) device->ccw_mem, 1);
91                 kfree(device);
92                 return ERR_PTR(-ENOMEM);
93         }
94
95         dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
96         dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
97         spin_lock_init(&device->mem_lock);
98         spin_lock_init(&device->request_queue_lock);
99         atomic_set (&device->tasklet_scheduled, 0);
100         tasklet_init(&device->tasklet, 
101                      (void (*)(unsigned long)) dasd_tasklet,
102                      (unsigned long) device);
103         INIT_LIST_HEAD(&device->ccw_queue);
104         init_timer(&device->timer);
105         INIT_WORK(&device->kick_work, do_kick_device, device);
106         device->state = DASD_STATE_NEW;
107         device->target = DASD_STATE_NEW;
108
109         return device;
110 }
111
112 /*
113  * Free memory of a device structure.
114  */
115 void
116 dasd_free_device(struct dasd_device *device)
117 {
118         if (device->private)
119                 kfree(device->private);
120         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  */
128 static inline int
129 dasd_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  */
152 static inline void
153 dasd_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  */
168 static inline int
169 dasd_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 */
179         device->debug_area = debug_register(device->cdev->dev.bus_id, 0, 2,
180                                             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  */
192 static inline void
193 dasd_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  */
218 static inline int
219 dasd_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  */
240 static inline void
241 dasd_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  */
257 static inline int
258 dasd_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  */
268 static inline void
269 dasd_state_online_to_ready(struct dasd_device * device)
270 {
271         device->state = DASD_STATE_READY;
272 }
273
274 /*
275  * Device startup state changes.
276  */
277 static inline int
278 dasd_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  */
308 static inline int
309 dasd_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  */
333 static void
334 dasd_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  */
358 static void
359 do_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
369 void
370 dasd_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  */
380 void
381 dasd_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  */
398 static inline int
399 _wait_for_device(struct dasd_device *device)
400 {
401         return (device->state == device->target);
402 }
403
404 void
405 dasd_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
420 struct dasd_profile_info_t dasd_global_profile;
421 unsigned 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  */
437 static inline void
438 dasd_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  */
459 static inline void
460 dasd_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  */
513 struct dasd_ccw_req *
514 dasd_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) {
542                         if (cqr->cpaddr != NULL)
543                                 kfree(cqr->cpaddr);
544                         kfree(cqr);
545                         return ERR_PTR(-ENOMEM);
546                 }
547                 memset(cqr->data, 0, datasize);
548         }
549         strncpy((char *) &cqr->magic, magic, 4);
550         ASCEBC((char *) &cqr->magic, 4);
551         set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
552         dasd_get_device(device);
553         return cqr;
554 }
555
556 struct dasd_ccw_req *
557 dasd_smalloc_request(char *magic, int cplength, int datasize,
558                    struct dasd_device * device)
559 {
560         unsigned long flags;
561         struct dasd_ccw_req *cqr;
562         char *data;
563         int size;
564
565         /* Sanity checks */
566         if ( magic == NULL || datasize > PAGE_SIZE ||
567              (cplength*sizeof(struct ccw1)) > PAGE_SIZE)
568                 BUG();
569
570         size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
571         if (cplength > 0)
572                 size += cplength * sizeof(struct ccw1);
573         if (datasize > 0)
574                 size += datasize;
575         spin_lock_irqsave(&device->mem_lock, flags);
576         cqr = (struct dasd_ccw_req *)
577                 dasd_alloc_chunk(&device->ccw_chunks, size);
578         spin_unlock_irqrestore(&device->mem_lock, flags);
579         if (cqr == NULL)
580                 return ERR_PTR(-ENOMEM);
581         memset(cqr, 0, sizeof(struct dasd_ccw_req));
582         data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
583         cqr->cpaddr = NULL;
584         if (cplength > 0) {
585                 cqr->cpaddr = (struct ccw1 *) data;
586                 data += cplength*sizeof(struct ccw1);
587                 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
588         }
589         cqr->data = NULL;
590         if (datasize > 0) {
591                 cqr->data = data;
592                 memset(cqr->data, 0, datasize);
593         }
594         strncpy((char *) &cqr->magic, magic, 4);
595         ASCEBC((char *) &cqr->magic, 4);
596         set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
597         dasd_get_device(device);
598         return cqr;
599 }
600
601 /*
602  * Free memory of a channel program. This function needs to free all the
603  * idal lists that might have been created by dasd_set_cda and the
604  * struct dasd_ccw_req itself.
605  */
606 void
607 dasd_kfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
608 {
609 #ifdef CONFIG_ARCH_S390X
610         struct ccw1 *ccw;
611
612         /* Clear any idals used for the request. */
613         ccw = cqr->cpaddr;
614         do {
615                 clear_normalized_cda(ccw);
616         } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
617 #endif
618         if (cqr->cpaddr != NULL)
619                 kfree(cqr->cpaddr);
620         if (cqr->data != NULL)
621                 kfree(cqr->data);
622         kfree(cqr);
623         dasd_put_device(device);
624 }
625
626 void
627 dasd_sfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
628 {
629         unsigned long flags;
630
631         spin_lock_irqsave(&device->mem_lock, flags);
632         dasd_free_chunk(&device->ccw_chunks, cqr);
633         spin_unlock_irqrestore(&device->mem_lock, flags);
634         dasd_put_device(device);
635 }
636
637 /*
638  * Check discipline magic in cqr.
639  */
640 static inline int
641 dasd_check_cqr(struct dasd_ccw_req *cqr)
642 {
643         struct dasd_device *device;
644
645         if (cqr == NULL)
646                 return -EINVAL;
647         device = cqr->device;
648         if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
649                 DEV_MESSAGE(KERN_WARNING, device,
650                             " dasd_ccw_req 0x%08x magic doesn't match"
651                             " discipline 0x%08x",
652                             cqr->magic,
653                             *(unsigned int *) device->discipline->name);
654                 return -EINVAL;
655         }
656         return 0;
657 }
658
659 /*
660  * Terminate the current i/o and set the request to clear_pending.
661  * Timer keeps device runnig.
662  * ccw_device_clear can fail if the i/o subsystem
663  * is in a bad mood.
664  */
665 int
666 dasd_term_IO(struct dasd_ccw_req * cqr)
667 {
668         struct dasd_device *device;
669         int retries, rc;
670
671         /* Check the cqr */
672         rc = dasd_check_cqr(cqr);
673         if (rc)
674                 return rc;
675         retries = 0;
676         device = (struct dasd_device *) cqr->device;
677         while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
678                 rc = ccw_device_clear(device->cdev, (long) cqr);
679                 switch (rc) {
680                 case 0: /* termination successful */
681                         if (cqr->retries > 0) {
682                                 cqr->retries--;
683                                 cqr->status = DASD_CQR_CLEAR;
684                         } else
685                                 cqr->status = DASD_CQR_FAILED;
686                         cqr->stopclk = get_clock();
687                         DBF_DEV_EVENT(DBF_DEBUG, device,
688                                       "terminate cqr %p successful",
689                                       cqr);
690                         break;
691                 case -ENODEV:
692                         DBF_DEV_EVENT(DBF_ERR, device, "%s",
693                                       "device gone, retry");
694                         break;
695                 case -EIO:
696                         DBF_DEV_EVENT(DBF_ERR, device, "%s",
697                                       "I/O error, retry");
698                         break;
699                 case -EINVAL:
700                 case -EBUSY:
701                         DBF_DEV_EVENT(DBF_ERR, device, "%s",
702                                       "device busy, retry later");
703                         break;
704                 default:
705                         DEV_MESSAGE(KERN_ERR, device,
706                                     "line %d unknown RC=%d, please "
707                                     "report to linux390@de.ibm.com",
708                                     __LINE__, rc);
709                         BUG();
710                         break;
711                 }
712                 retries++;
713         }
714         dasd_schedule_bh(device);
715         return rc;
716 }
717
718 /*
719  * Start the i/o. This start_IO can fail if the channel is really busy.
720  * In that case set up a timer to start the request later.
721  */
722 int
723 dasd_start_IO(struct dasd_ccw_req * cqr)
724 {
725         struct dasd_device *device;
726         int rc;
727
728         /* Check the cqr */
729         rc = dasd_check_cqr(cqr);
730         if (rc)
731                 return rc;
732         device = (struct dasd_device *) cqr->device;
733         if (cqr->retries < 0) {
734                 DEV_MESSAGE(KERN_DEBUG, device,
735                             "start_IO: request %p (%02x/%i) - no retry left.",
736                             cqr, cqr->status, cqr->retries);
737                 cqr->status = DASD_CQR_FAILED;
738                 return -EIO;
739         }
740         cqr->startclk = get_clock();
741         cqr->starttime = jiffies;
742         cqr->retries--;
743         rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr,
744                               cqr->lpm, 0);
745         switch (rc) {
746         case 0:
747                 cqr->status = DASD_CQR_IN_IO;
748                 DBF_DEV_EVENT(DBF_DEBUG, device,
749                               "start_IO: request %p started successful",
750                               cqr);
751                 break;
752         case -EBUSY:
753                 DBF_DEV_EVENT(DBF_ERR, device, "%s",
754                               "start_IO: device busy, retry later");
755                 break;
756         case -ETIMEDOUT:
757                 DBF_DEV_EVENT(DBF_ERR, device, "%s",
758                               "start_IO: request timeout, retry later");
759                 break;
760         case -ENODEV:
761         case -EIO:
762                 DBF_DEV_EVENT(DBF_ERR, device, "%s",
763                               "start_IO: device gone, retry");
764                 break;
765         default:
766                 DEV_MESSAGE(KERN_ERR, device,
767                             "line %d unknown RC=%d, please report"
768                             " to linux390@de.ibm.com", __LINE__, rc);
769                 BUG();
770                 break;
771         }
772         return rc;
773 }
774
775 /*
776  * Timeout function for dasd devices. This is used for different purposes
777  *  1) missing interrupt handler for normal operation
778  *  2) delayed start of request where start_IO failed with -EBUSY
779  *  3) timeout for missing state change interrupts
780  * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
781  * DASD_CQR_QUEUED for 2) and 3).
782  */
783 static void
784 dasd_timeout_device(unsigned long ptr)
785 {
786         unsigned long flags;
787         struct dasd_device *device;
788
789         device = (struct dasd_device *) ptr;
790         spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
791         /* re-activate request queue */
792         device->stopped &= ~DASD_STOPPED_PENDING;
793         spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
794         dasd_schedule_bh(device);
795 }
796
797 /*
798  * Setup timeout for a device in jiffies.
799  */
800 void
801 dasd_set_timer(struct dasd_device *device, int expires)
802 {
803         if (expires == 0) {
804                 if (timer_pending(&device->timer))
805                         del_timer(&device->timer);
806                 return;
807         }
808         if (timer_pending(&device->timer)) {
809                 if (mod_timer(&device->timer, jiffies + expires))
810                         return;
811         }
812         device->timer.function = dasd_timeout_device;
813         device->timer.data = (unsigned long) device;
814         device->timer.expires = jiffies + expires;
815         add_timer(&device->timer);
816 }
817
818 /*
819  * Clear timeout for a device.
820  */
821 void
822 dasd_clear_timer(struct dasd_device *device)
823 {
824         if (timer_pending(&device->timer))
825                 del_timer(&device->timer);
826 }
827
828 static void
829 dasd_handle_killed_request(struct ccw_device *cdev, unsigned long intparm)
830 {
831         struct dasd_ccw_req *cqr;
832         struct dasd_device *device;
833
834         cqr = (struct dasd_ccw_req *) intparm;
835         if (cqr->status != DASD_CQR_IN_IO) {
836                 MESSAGE(KERN_DEBUG,
837                         "invalid status in handle_killed_request: "
838                         "bus_id %s, status %02x",
839                         cdev->dev.bus_id, cqr->status);
840                 return;
841         }
842
843         device = (struct dasd_device *) cqr->device;
844         if (device == NULL ||
845             device != dasd_device_from_cdev(cdev) ||
846             strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
847                 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
848                         cdev->dev.bus_id);
849                 return;
850         }
851
852         /* Schedule request to be retried. */
853         cqr->status = DASD_CQR_QUEUED;
854
855         dasd_clear_timer(device);
856         dasd_schedule_bh(device);
857         dasd_put_device(device);
858 }
859
860 static void
861 dasd_handle_state_change_pending(struct dasd_device *device)
862 {
863         struct dasd_ccw_req *cqr;
864         struct list_head *l, *n;
865
866         device->stopped &= ~DASD_STOPPED_PENDING;
867
868         /* restart all 'running' IO on queue */
869         list_for_each_safe(l, n, &device->ccw_queue) {
870                 cqr = list_entry(l, struct dasd_ccw_req, list);
871                 if (cqr->status == DASD_CQR_IN_IO) {
872                         cqr->status = DASD_CQR_QUEUED;
873                 }
874         }
875         dasd_clear_timer(device);
876         dasd_schedule_bh(device);
877 }
878
879 /*
880  * Interrupt handler for "normal" ssch-io based dasd devices.
881  */
882 void
883 dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
884                  struct irb *irb)
885 {
886         struct dasd_ccw_req *cqr, *next;
887         struct dasd_device *device;
888         unsigned long long now;
889         int expires;
890         dasd_era_t era;
891         char mask;
892
893         if (IS_ERR(irb)) {
894                 switch (PTR_ERR(irb)) {
895                 case -EIO:
896                         dasd_handle_killed_request(cdev, intparm);
897                         break;
898                 case -ETIMEDOUT:
899                         printk(KERN_WARNING"%s(%s): request timed out\n",
900                                __FUNCTION__, cdev->dev.bus_id);
901                         //FIXME - dasd uses own timeout interface...
902                         break;
903                 default:
904                         printk(KERN_WARNING"%s(%s): unknown error %ld\n",
905                                __FUNCTION__, cdev->dev.bus_id, PTR_ERR(irb));
906                 }
907                 return;
908         }
909
910         now = get_clock();
911
912         DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
913                   cdev->dev.bus_id, ((irb->scsw.cstat<<8)|irb->scsw.dstat),
914                   (unsigned int) intparm);
915
916         /* first of all check for state change pending interrupt */
917         mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
918         if ((irb->scsw.dstat & mask) == mask) {
919                 device = dasd_device_from_cdev(cdev);
920                 if (!IS_ERR(device)) {
921                         dasd_handle_state_change_pending(device);
922                         dasd_put_device(device);
923                 }
924                 return;
925         }
926
927         cqr = (struct dasd_ccw_req *) intparm;
928
929         /* check for unsolicited interrupts */
930         if (cqr == NULL) {
931                 MESSAGE(KERN_DEBUG,
932                         "unsolicited interrupt received: bus_id %s",
933                         cdev->dev.bus_id);
934                 return;
935         }
936
937         device = (struct dasd_device *) cqr->device;
938         if (device == NULL ||
939             strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
940                 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
941                         cdev->dev.bus_id);
942                 return;
943         }
944
945         /* Check for clear pending */
946         if (cqr->status == DASD_CQR_CLEAR &&
947             irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
948                 cqr->status = DASD_CQR_QUEUED;
949                 dasd_clear_timer(device);
950                 dasd_schedule_bh(device);
951                 return;
952         }
953
954         /* check status - the request might have been killed by dyn detach */
955         if (cqr->status != DASD_CQR_IN_IO) {
956                 MESSAGE(KERN_DEBUG,
957                         "invalid status: bus_id %s, status %02x",
958                         cdev->dev.bus_id, cqr->status);
959                 return;
960         }
961         DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p",
962                       ((irb->scsw.cstat << 8) | irb->scsw.dstat), cqr);
963
964         /* Find out the appropriate era_action. */
965         if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC) 
966                 era = dasd_era_fatal;
967         else if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
968                  irb->scsw.cstat == 0 &&
969                  !irb->esw.esw0.erw.cons)
970                 era = dasd_era_none;
971         else if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags))
972                 era = dasd_era_fatal; /* don't recover this request */
973         else if (irb->esw.esw0.erw.cons)
974                 era = device->discipline->examine_error(cqr, irb);
975         else 
976                 era = dasd_era_recover;
977
978         DBF_DEV_EVENT(DBF_DEBUG, device, "era_code %d", era);
979         expires = 0;
980         if (era == dasd_era_none) {
981                 cqr->status = DASD_CQR_DONE;
982                 cqr->stopclk = now;
983                 /* Start first request on queue if possible -> fast_io. */
984                 if (cqr->list.next != &device->ccw_queue) {
985                         next = list_entry(cqr->list.next,
986                                           struct dasd_ccw_req, list);
987                         if ((next->status == DASD_CQR_QUEUED) &&
988                             (!device->stopped)) {
989                                 if (device->discipline->start_IO(next) == 0)
990                                         expires = next->expires;
991                                 else
992                                         DEV_MESSAGE(KERN_DEBUG, device, "%s",
993                                                     "Interrupt fastpath "
994                                                     "failed!");
995                         }
996                 }
997         } else {                /* error */
998                 memcpy(&cqr->irb, irb, sizeof (struct irb));
999 #ifdef ERP_DEBUG
1000                 /* dump sense data */
1001                 dasd_log_sense(cqr, irb);
1002 #endif
1003                 switch (era) {
1004                 case dasd_era_fatal:
1005                         cqr->status = DASD_CQR_FAILED;
1006                         cqr->stopclk = now;
1007                         break;
1008                 case dasd_era_recover:
1009                         cqr->status = DASD_CQR_ERROR;
1010                         break;
1011                 default:
1012                         BUG();
1013                 }
1014         }
1015         if (expires != 0)
1016                 dasd_set_timer(device, expires);
1017         else
1018                 dasd_clear_timer(device);
1019         dasd_schedule_bh(device);
1020 }
1021
1022 /*
1023  * posts the buffer_cache about a finalized request
1024  */
1025 static inline void
1026 dasd_end_request(struct request *req, int uptodate)
1027 {
1028         if (end_that_request_first(req, uptodate, req->hard_nr_sectors))
1029                 BUG();
1030         add_disk_randomness(req->rq_disk);
1031         end_that_request_last(req);
1032 }
1033
1034 /*
1035  * Process finished error recovery ccw.
1036  */
1037 static inline void
1038 __dasd_process_erp(struct dasd_device *device, struct dasd_ccw_req *cqr)
1039 {
1040         dasd_erp_fn_t erp_fn;
1041
1042         if (cqr->status == DASD_CQR_DONE)
1043                 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
1044         else
1045                 DEV_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful");
1046         erp_fn = device->discipline->erp_postaction(cqr);
1047         erp_fn(cqr);
1048 }
1049
1050 /*
1051  * Process ccw request queue.
1052  */
1053 static inline void
1054 __dasd_process_ccw_queue(struct dasd_device * device,
1055                          struct list_head *final_queue)
1056 {
1057         struct list_head *l, *n;
1058         struct dasd_ccw_req *cqr;
1059         dasd_erp_fn_t erp_fn;
1060
1061 restart:
1062         /* Process request with final status. */
1063         list_for_each_safe(l, n, &device->ccw_queue) {
1064                 cqr = list_entry(l, struct dasd_ccw_req, list);
1065                 /* Stop list processing at the first non-final request. */
1066                 if (cqr->status != DASD_CQR_DONE &&
1067                     cqr->status != DASD_CQR_FAILED &&
1068                     cqr->status != DASD_CQR_ERROR)
1069                         break;
1070                 /*  Process requests with DASD_CQR_ERROR */
1071                 if (cqr->status == DASD_CQR_ERROR) {
1072                         if (cqr->irb.scsw.fctl & SCSW_FCTL_HALT_FUNC) {
1073                                 cqr->status = DASD_CQR_FAILED;
1074                                 cqr->stopclk = get_clock();
1075                         } else {
1076                                 if (cqr->irb.esw.esw0.erw.cons) {
1077                                         erp_fn = device->discipline->
1078                                                 erp_action(cqr);
1079                                         erp_fn(cqr);
1080                                 } else
1081                                         dasd_default_erp_action(cqr);
1082                         }
1083                         goto restart;
1084                 }
1085                 /* Process finished ERP request. */
1086                 if (cqr->refers) {
1087                         __dasd_process_erp(device, cqr);
1088                         goto restart;
1089                 }
1090
1091                 /* Rechain finished requests to final queue */
1092                 cqr->endclk = get_clock();
1093                 list_move_tail(&cqr->list, final_queue);
1094         }
1095 }
1096
1097 static void
1098 dasd_end_request_cb(struct dasd_ccw_req * cqr, void *data)
1099 {
1100         struct request *req;
1101         struct dasd_device *device;
1102         int status;
1103
1104         req = (struct request *) data;
1105         device = cqr->device;
1106         dasd_profile_end(device, cqr, req);
1107         status = cqr->device->discipline->free_cp(cqr,req);
1108         spin_lock_irq(&device->request_queue_lock);
1109         dasd_end_request(req, status);
1110         spin_unlock_irq(&device->request_queue_lock);
1111 }
1112
1113
1114 /*
1115  * Fetch requests from the block device queue.
1116  */
1117 static inline void
1118 __dasd_process_blk_queue(struct dasd_device * device)
1119 {
1120         request_queue_t *queue;
1121         struct request *req;
1122         struct dasd_ccw_req *cqr;
1123         int nr_queued;
1124
1125         queue = device->request_queue;
1126         /* No queue ? Then there is nothing to do. */
1127         if (queue == NULL)
1128                 return;
1129
1130         /*
1131          * We requeue request from the block device queue to the ccw
1132          * queue only in two states. In state DASD_STATE_READY the
1133          * partition detection is done and we need to requeue requests
1134          * for that. State DASD_STATE_ONLINE is normal block device
1135          * operation.
1136          */
1137         if (device->state != DASD_STATE_READY &&
1138             device->state != DASD_STATE_ONLINE)
1139                 return;
1140         nr_queued = 0;
1141         /* Now we try to fetch requests from the request queue */
1142         list_for_each_entry(cqr, &device->ccw_queue, list)
1143                 if (cqr->status == DASD_CQR_QUEUED)
1144                         nr_queued++;
1145         while (!blk_queue_plugged(queue) &&
1146                elv_next_request(queue) &&
1147                 nr_queued < DASD_CHANQ_MAX_SIZE) {
1148                 req = elv_next_request(queue);
1149                 if (test_bit(DASD_FLAG_RO, &device->flags) &&
1150                     rq_data_dir(req) == WRITE) {
1151                         DBF_DEV_EVENT(DBF_ERR, device,
1152                                       "Rejecting write request %p",
1153                                       req);
1154                         blkdev_dequeue_request(req);
1155                         dasd_end_request(req, 0);
1156                         continue;
1157                 }
1158                 if (device->stopped & DASD_STOPPED_DC_EIO) {
1159                         blkdev_dequeue_request(req);
1160                         dasd_end_request(req, 0);
1161                         continue;
1162                 }
1163                 cqr = device->discipline->build_cp(device, req);
1164                 if (IS_ERR(cqr)) {
1165                         if (PTR_ERR(cqr) == -ENOMEM)
1166                                 break;  /* terminate request queue loop */
1167                         DBF_DEV_EVENT(DBF_ERR, device,
1168                                       "CCW creation failed (rc=%ld) "
1169                                       "on request %p",
1170                                       PTR_ERR(cqr), req);
1171                         blkdev_dequeue_request(req);
1172                         dasd_end_request(req, 0);
1173                         continue;
1174                 }
1175                 cqr->callback = dasd_end_request_cb;
1176                 cqr->callback_data = (void *) req;
1177                 cqr->status = DASD_CQR_QUEUED;
1178                 blkdev_dequeue_request(req);
1179                 list_add_tail(&cqr->list, &device->ccw_queue);
1180                 dasd_profile_start(device, cqr, req);
1181                 nr_queued++;
1182         }
1183 }
1184
1185 /*
1186  * Take a look at the first request on the ccw queue and check
1187  * if it reached its expire time. If so, terminate the IO.
1188  */
1189 static inline void
1190 __dasd_check_expire(struct dasd_device * device)
1191 {
1192         struct dasd_ccw_req *cqr;
1193
1194         if (list_empty(&device->ccw_queue))
1195                 return;
1196         cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1197         if (cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) {
1198                 if (time_after_eq(jiffies, cqr->expires + cqr->starttime)) {
1199                         if (device->discipline->term_IO(cqr) != 0)
1200                                 /* Hmpf, try again in 1/10 sec */
1201                                 dasd_set_timer(device, 10);
1202                 }
1203         }
1204 }
1205
1206 /*
1207  * Take a look at the first request on the ccw queue and check
1208  * if it needs to be started.
1209  */
1210 static inline void
1211 __dasd_start_head(struct dasd_device * device)
1212 {
1213         struct dasd_ccw_req *cqr;
1214         int rc;
1215
1216         if (list_empty(&device->ccw_queue))
1217                 return;
1218         cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1219         if ((cqr->status == DASD_CQR_QUEUED) &&
1220             (!device->stopped)) {
1221                 /* try to start the first I/O that can be started */
1222                 rc = device->discipline->start_IO(cqr);
1223                 if (rc == 0)
1224                         dasd_set_timer(device, cqr->expires);
1225                 else
1226                         /* Hmpf, try again in 1/2 sec */
1227                         dasd_set_timer(device, 50);
1228         }
1229 }
1230
1231 /*
1232  * Remove requests from the ccw queue. 
1233  */
1234 static void
1235 dasd_flush_ccw_queue(struct dasd_device * device, int all)
1236 {
1237         struct list_head flush_queue;
1238         struct list_head *l, *n;
1239         struct dasd_ccw_req *cqr;
1240
1241         INIT_LIST_HEAD(&flush_queue);
1242         spin_lock_irq(get_ccwdev_lock(device->cdev));
1243         list_for_each_safe(l, n, &device->ccw_queue) {
1244                 cqr = list_entry(l, struct dasd_ccw_req, list);
1245                 /* Flush all request or only block device requests? */
1246                 if (all == 0 && cqr->callback == dasd_end_request_cb)
1247                         continue;
1248                 if (cqr->status == DASD_CQR_IN_IO)
1249                         device->discipline->term_IO(cqr);
1250                 if (cqr->status != DASD_CQR_DONE ||
1251                     cqr->status != DASD_CQR_FAILED) {
1252                         cqr->status = DASD_CQR_FAILED;
1253                         cqr->stopclk = get_clock();
1254                 }
1255                 /* Process finished ERP request. */
1256                 if (cqr->refers) {
1257                         __dasd_process_erp(device, cqr);
1258                         continue;
1259                 }
1260                 /* Rechain request on device request queue */
1261                 cqr->endclk = get_clock();
1262                 list_move_tail(&cqr->list, &flush_queue);
1263         }
1264         spin_unlock_irq(get_ccwdev_lock(device->cdev));
1265         /* Now call the callback function of flushed requests */
1266         list_for_each_safe(l, n, &flush_queue) {
1267                 cqr = list_entry(l, struct dasd_ccw_req, list);
1268                 if (cqr->callback != NULL)
1269                         (cqr->callback)(cqr, cqr->callback_data);
1270         }
1271 }
1272
1273 /*
1274  * Acquire the device lock and process queues for the device.
1275  */
1276 static void
1277 dasd_tasklet(struct dasd_device * device)
1278 {
1279         struct list_head final_queue;
1280         struct list_head *l, *n;
1281         struct dasd_ccw_req *cqr;
1282
1283         atomic_set (&device->tasklet_scheduled, 0);
1284         INIT_LIST_HEAD(&final_queue);
1285         spin_lock_irq(get_ccwdev_lock(device->cdev));
1286         /* Check expire time of first request on the ccw queue. */
1287         __dasd_check_expire(device);
1288         /* Finish off requests on ccw queue */
1289         __dasd_process_ccw_queue(device, &final_queue);
1290         spin_unlock_irq(get_ccwdev_lock(device->cdev));
1291         /* Now call the callback function of requests with final status */
1292         list_for_each_safe(l, n, &final_queue) {
1293                 cqr = list_entry(l, struct dasd_ccw_req, list);
1294                 list_del(&cqr->list);
1295                 if (cqr->callback != NULL)
1296                         (cqr->callback)(cqr, cqr->callback_data);
1297         }
1298         spin_lock_irq(&device->request_queue_lock);
1299         spin_lock(get_ccwdev_lock(device->cdev));
1300         /* Get new request from the block device request queue */
1301         __dasd_process_blk_queue(device);
1302         /* Now check if the head of the ccw queue needs to be started. */
1303         __dasd_start_head(device);
1304         spin_unlock(get_ccwdev_lock(device->cdev));
1305         spin_unlock_irq(&device->request_queue_lock);
1306         dasd_put_device(device);
1307 }
1308
1309 /*
1310  * Schedules a call to dasd_tasklet over the device tasklet.
1311  */
1312 void
1313 dasd_schedule_bh(struct dasd_device * device)
1314 {
1315         /* Protect against rescheduling. */
1316         if (atomic_compare_and_swap (0, 1, &device->tasklet_scheduled))
1317                 return;
1318         dasd_get_device(device);
1319         tasklet_hi_schedule(&device->tasklet);
1320 }
1321
1322 /*
1323  * Queue a request to the head of the ccw_queue. Start the I/O if
1324  * possible.
1325  */
1326 void
1327 dasd_add_request_head(struct dasd_ccw_req *req)
1328 {
1329         struct dasd_device *device;
1330         unsigned long flags;
1331
1332         device = req->device;
1333         spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1334         req->status = DASD_CQR_QUEUED;
1335         req->device = device;
1336         list_add(&req->list, &device->ccw_queue);
1337         /* let the bh start the request to keep them in order */
1338         dasd_schedule_bh(device);
1339         spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1340 }
1341
1342 /*
1343  * Queue a request to the tail of the ccw_queue. Start the I/O if
1344  * possible.
1345  */
1346 void
1347 dasd_add_request_tail(struct dasd_ccw_req *req)
1348 {
1349         struct dasd_device *device;
1350         unsigned long flags;
1351
1352         device = req->device;
1353         spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1354         req->status = DASD_CQR_QUEUED;
1355         req->device = device;
1356         list_add_tail(&req->list, &device->ccw_queue);
1357         /* let the bh start the request to keep them in order */
1358         dasd_schedule_bh(device);
1359         spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1360 }
1361
1362 /*
1363  * Wakeup callback.
1364  */
1365 static void
1366 dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
1367 {
1368         wake_up((wait_queue_head_t *) data);
1369 }
1370
1371 static inline int
1372 _wait_for_wakeup(struct dasd_ccw_req *cqr)
1373 {
1374         struct dasd_device *device;
1375         int rc;
1376
1377         device = cqr->device;
1378         spin_lock_irq(get_ccwdev_lock(device->cdev));
1379         rc = cqr->status == DASD_CQR_DONE || cqr->status == DASD_CQR_FAILED;
1380         spin_unlock_irq(get_ccwdev_lock(device->cdev));
1381         return rc;
1382 }
1383
1384 /*
1385  * Attempts to start a special ccw queue and waits for its completion.
1386  */
1387 int
1388 dasd_sleep_on(struct dasd_ccw_req * cqr)
1389 {
1390         wait_queue_head_t wait_q;
1391         struct dasd_device *device;
1392         int rc;
1393         
1394         device = cqr->device;
1395         spin_lock_irq(get_ccwdev_lock(device->cdev));
1396         
1397         init_waitqueue_head (&wait_q);
1398         cqr->callback = dasd_wakeup_cb;
1399         cqr->callback_data = (void *) &wait_q;
1400         cqr->status = DASD_CQR_QUEUED;
1401         list_add_tail(&cqr->list, &device->ccw_queue);
1402         
1403         /* let the bh start the request to keep them in order */
1404         dasd_schedule_bh(device);
1405         
1406         spin_unlock_irq(get_ccwdev_lock(device->cdev));
1407
1408         wait_event(wait_q, _wait_for_wakeup(cqr));
1409         
1410         /* Request status is either done or failed. */
1411         rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1412         return rc;
1413 }
1414
1415 /*
1416  * Attempts to start a special ccw queue and wait interruptible
1417  * for its completion.
1418  */
1419 int
1420 dasd_sleep_on_interruptible(struct dasd_ccw_req * cqr)
1421 {
1422         wait_queue_head_t wait_q;
1423         struct dasd_device *device;
1424         int rc, finished;
1425
1426         device = cqr->device;
1427         spin_lock_irq(get_ccwdev_lock(device->cdev));
1428
1429         init_waitqueue_head (&wait_q);
1430         cqr->callback = dasd_wakeup_cb;
1431         cqr->callback_data = (void *) &wait_q;
1432         cqr->status = DASD_CQR_QUEUED;
1433         list_add_tail(&cqr->list, &device->ccw_queue);
1434
1435         /* let the bh start the request to keep them in order */
1436         dasd_schedule_bh(device);
1437         spin_unlock_irq(get_ccwdev_lock(device->cdev));
1438
1439         finished = 0;
1440         while (!finished) {
1441                 rc = wait_event_interruptible(wait_q, _wait_for_wakeup(cqr));
1442                 if (rc != -ERESTARTSYS) {
1443                         /* Request status is either done or failed. */
1444                         rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1445                         break;
1446                 }
1447                 spin_lock_irq(get_ccwdev_lock(device->cdev));
1448                 if (cqr->status == DASD_CQR_IN_IO &&
1449                     device->discipline->term_IO(cqr) == 0) {
1450                         list_del(&cqr->list);
1451                         finished = 1;
1452                 }
1453                 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1454         }
1455         return rc;
1456 }
1457
1458 /*
1459  * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
1460  * for eckd devices) the currently running request has to be terminated
1461  * and be put back to status queued, before the special request is added
1462  * to the head of the queue. Then the special request is waited on normally.
1463  */
1464 static inline int
1465 _dasd_term_running_cqr(struct dasd_device *device)
1466 {
1467         struct dasd_ccw_req *cqr;
1468         int rc;
1469
1470         if (list_empty(&device->ccw_queue))
1471                 return 0;
1472         cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1473         rc = device->discipline->term_IO(cqr);
1474         if (rc == 0) {
1475                 /* termination successful */
1476                 cqr->status = DASD_CQR_QUEUED;
1477                 cqr->startclk = cqr->stopclk = 0;
1478                 cqr->starttime = 0;
1479         }
1480         return rc;
1481 }
1482
1483 int
1484 dasd_sleep_on_immediatly(struct dasd_ccw_req * cqr)
1485 {
1486         wait_queue_head_t wait_q;
1487         struct dasd_device *device;
1488         int rc;
1489         
1490         device = cqr->device;
1491         spin_lock_irq(get_ccwdev_lock(device->cdev));
1492         rc = _dasd_term_running_cqr(device);
1493         if (rc) {
1494                 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1495                 return rc;
1496         }
1497         
1498         init_waitqueue_head (&wait_q);
1499         cqr->callback = dasd_wakeup_cb;
1500         cqr->callback_data = (void *) &wait_q;
1501         cqr->status = DASD_CQR_QUEUED;
1502         list_add(&cqr->list, &device->ccw_queue);
1503         
1504         /* let the bh start the request to keep them in order */
1505         dasd_schedule_bh(device);
1506         
1507         spin_unlock_irq(get_ccwdev_lock(device->cdev));
1508
1509         wait_event(wait_q, _wait_for_wakeup(cqr));
1510         
1511         /* Request status is either done or failed. */
1512         rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1513         return rc;
1514 }
1515
1516 /*
1517  * Cancels a request that was started with dasd_sleep_on_req.
1518  * This is useful to timeout requests. The request will be
1519  * terminated if it is currently in i/o.
1520  * Returns 1 if the request has been terminated.
1521  */
1522 int
1523 dasd_cancel_req(struct dasd_ccw_req *cqr)
1524 {
1525         struct dasd_device *device = cqr->device;
1526         unsigned long flags;
1527         int rc;
1528
1529         rc = 0;
1530         spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1531         switch (cqr->status) {
1532         case DASD_CQR_QUEUED:
1533                 /* request was not started - just set to failed */
1534                 cqr->status = DASD_CQR_FAILED;
1535                 break;
1536         case DASD_CQR_IN_IO:
1537                 /* request in IO - terminate IO and release again */
1538                 if (device->discipline->term_IO(cqr) != 0)
1539                         /* what to do if unable to terminate ??????
1540                            e.g. not _IN_IO */
1541                         cqr->status = DASD_CQR_FAILED;
1542                 cqr->stopclk = get_clock();
1543                 rc = 1;
1544                 break;
1545         case DASD_CQR_DONE:
1546         case DASD_CQR_FAILED:
1547                 /* already finished - do nothing */
1548                 break;
1549         default:
1550                 DEV_MESSAGE(KERN_ALERT, device,
1551                             "invalid status %02x in request",
1552                             cqr->status);
1553                 BUG();
1554
1555         }
1556         spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1557         dasd_schedule_bh(device);
1558         return rc;
1559 }
1560
1561 /*
1562  * SECTION: Block device operations (request queue, partitions, open, release).
1563  */
1564
1565 /*
1566  * Dasd request queue function. Called from ll_rw_blk.c
1567  */
1568 static void
1569 do_dasd_request(request_queue_t * queue)
1570 {
1571         struct dasd_device *device;
1572
1573         device = (struct dasd_device *) queue->queuedata;
1574         spin_lock(get_ccwdev_lock(device->cdev));
1575         /* Get new request from the block device request queue */
1576         __dasd_process_blk_queue(device);
1577         /* Now check if the head of the ccw queue needs to be started. */
1578         __dasd_start_head(device);
1579         spin_unlock(get_ccwdev_lock(device->cdev));
1580 }
1581
1582 /*
1583  * Allocate and initialize request queue and default I/O scheduler.
1584  */
1585 static int
1586 dasd_alloc_queue(struct dasd_device * device)
1587 {
1588         int rc;
1589
1590         device->request_queue = blk_init_queue(do_dasd_request,
1591                                                &device->request_queue_lock);
1592         if (device->request_queue == NULL)
1593                 return -ENOMEM;
1594
1595         device->request_queue->queuedata = device;
1596
1597         elevator_exit(device->request_queue->elevator);
1598         rc = elevator_init(device->request_queue, "deadline");
1599         if (rc) {
1600                 blk_cleanup_queue(device->request_queue);
1601                 return rc;
1602         }
1603         return 0;
1604 }
1605
1606 /*
1607  * Allocate and initialize request queue.
1608  */
1609 static void
1610 dasd_setup_queue(struct dasd_device * device)
1611 {
1612         int max;
1613
1614         blk_queue_hardsect_size(device->request_queue, device->bp_block);
1615         max = device->discipline->max_blocks << device->s2b_shift;
1616         blk_queue_max_sectors(device->request_queue, max);
1617         blk_queue_max_phys_segments(device->request_queue, -1L);
1618         blk_queue_max_hw_segments(device->request_queue, -1L);
1619         blk_queue_max_segment_size(device->request_queue, -1L);
1620         blk_queue_segment_boundary(device->request_queue, -1L);
1621 }
1622
1623 /*
1624  * Deactivate and free request queue.
1625  */
1626 static void
1627 dasd_free_queue(struct dasd_device * device)
1628 {
1629         if (device->request_queue) {
1630                 blk_cleanup_queue(device->request_queue);
1631                 device->request_queue = NULL;
1632         }
1633 }
1634
1635 /*
1636  * Flush request on the request queue.
1637  */
1638 static void
1639 dasd_flush_request_queue(struct dasd_device * device)
1640 {
1641         struct request *req;
1642
1643         if (!device->request_queue)
1644                 return;
1645         
1646         spin_lock_irq(&device->request_queue_lock);
1647         while (!list_empty(&device->request_queue->queue_head)) {
1648                 req = elv_next_request(device->request_queue);
1649                 if (req == NULL)
1650                         break;
1651                 dasd_end_request(req, 0);
1652                 blkdev_dequeue_request(req);
1653         }
1654         spin_unlock_irq(&device->request_queue_lock);
1655 }
1656
1657 static int
1658 dasd_open(struct inode *inp, struct file *filp)
1659 {
1660         struct gendisk *disk = inp->i_bdev->bd_disk;
1661         struct dasd_device *device = disk->private_data;
1662         int rc;
1663
1664         atomic_inc(&device->open_count);
1665         if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1666                 rc = -ENODEV;
1667                 goto unlock;
1668         }
1669
1670         if (!try_module_get(device->discipline->owner)) {
1671                 rc = -EINVAL;
1672                 goto unlock;
1673         }
1674
1675         if (dasd_probeonly) {
1676                 DEV_MESSAGE(KERN_INFO, device, "%s",
1677                             "No access to device due to probeonly mode");
1678                 rc = -EPERM;
1679                 goto out;
1680         }
1681
1682         if (device->state < DASD_STATE_BASIC) {
1683                 DBF_DEV_EVENT(DBF_ERR, device, " %s",
1684                               " Cannot open unrecognized device");
1685                 rc = -ENODEV;
1686                 goto out;
1687         }
1688
1689         return 0;
1690
1691 out:
1692         module_put(device->discipline->owner);
1693 unlock:
1694         atomic_dec(&device->open_count);
1695         return rc;
1696 }
1697
1698 static int
1699 dasd_release(struct inode *inp, struct file *filp)
1700 {
1701         struct gendisk *disk = inp->i_bdev->bd_disk;
1702         struct dasd_device *device = disk->private_data;
1703
1704         atomic_dec(&device->open_count);
1705         module_put(device->discipline->owner);
1706         return 0;
1707 }
1708
1709 struct block_device_operations
1710 dasd_device_operations = {
1711         .owner          = THIS_MODULE,
1712         .open           = dasd_open,
1713         .release        = dasd_release,
1714         .ioctl          = dasd_ioctl,
1715 };
1716
1717
1718 static void
1719 dasd_exit(void)
1720 {
1721 #ifdef CONFIG_PROC_FS
1722         dasd_proc_exit();
1723 #endif
1724         dasd_ioctl_exit();
1725         dasd_gendisk_exit();
1726         dasd_devmap_exit();
1727         devfs_remove("dasd");
1728         if (dasd_debug_area != NULL) {
1729                 debug_unregister(dasd_debug_area);
1730                 dasd_debug_area = NULL;
1731         }
1732 }
1733
1734 /*
1735  * SECTION: common functions for ccw_driver use
1736  */
1737
1738 /* initial attempt at a probe function. this can be simplified once
1739  * the other detection code is gone */
1740 int
1741 dasd_generic_probe (struct ccw_device *cdev,
1742                     struct dasd_discipline *discipline)
1743 {
1744         int ret;
1745
1746         ret = dasd_add_sysfs_files(cdev);
1747         if (ret) {
1748                 printk(KERN_WARNING
1749                        "dasd_generic_probe: could not add sysfs entries "
1750                        "for %s\n", cdev->dev.bus_id);
1751         }
1752
1753         cdev->handler = &dasd_int_handler;
1754
1755         return ret;
1756 }
1757
1758 /* this will one day be called from a global not_oper handler.
1759  * It is also used by driver_unregister during module unload */
1760 void
1761 dasd_generic_remove (struct ccw_device *cdev)
1762 {
1763         struct dasd_device *device;
1764
1765         dasd_remove_sysfs_files(cdev);
1766         device = dasd_device_from_cdev(cdev);
1767         if (IS_ERR(device))
1768                 return;
1769         if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1770                 /* Already doing offline processing */
1771                 dasd_put_device(device);
1772                 return;
1773         }
1774         /*
1775          * This device is removed unconditionally. Set offline
1776          * flag to prevent dasd_open from opening it while it is
1777          * no quite down yet.
1778          */
1779         dasd_set_target_state(device, DASD_STATE_NEW);
1780         /* dasd_delete_device destroys the device reference. */
1781         dasd_delete_device(device);
1782 }
1783
1784 /* activate a device. This is called from dasd_{eckd,fba}_probe() when either
1785  * the device is detected for the first time and is supposed to be used
1786  * or the user has started activation through sysfs */
1787 int
1788 dasd_generic_set_online (struct ccw_device *cdev,
1789                          struct dasd_discipline *discipline)
1790
1791 {
1792         struct dasd_device *device;
1793         int rc;
1794
1795         device = dasd_create_device(cdev);
1796         if (IS_ERR(device))
1797                 return PTR_ERR(device);
1798
1799         if (test_bit(DASD_FLAG_USE_DIAG, &device->flags)) {
1800                 if (!dasd_diag_discipline_pointer) {
1801                         printk (KERN_WARNING
1802                                 "dasd_generic couldn't online device %s "
1803                                 "- discipline DIAG not available\n",
1804                                 cdev->dev.bus_id);
1805                         dasd_delete_device(device);
1806                         return -ENODEV;
1807                 }
1808                 discipline = dasd_diag_discipline_pointer;
1809         }
1810         device->discipline = discipline;
1811
1812         rc = discipline->check_device(device);
1813         if (rc) {
1814                 printk (KERN_WARNING
1815                         "dasd_generic couldn't online device %s "
1816                         "with discipline %s\n", 
1817                         cdev->dev.bus_id, discipline->name);
1818                 dasd_delete_device(device);
1819                 return rc;
1820         }
1821
1822         dasd_set_target_state(device, DASD_STATE_ONLINE);
1823         if (device->state <= DASD_STATE_KNOWN) {
1824                 printk (KERN_WARNING
1825                         "dasd_generic discipline not found for %s\n",
1826                         cdev->dev.bus_id);
1827                 rc = -ENODEV;
1828                 dasd_set_target_state(device, DASD_STATE_NEW);
1829                 dasd_delete_device(device);
1830         } else
1831                 pr_debug("dasd_generic device %s found\n",
1832                                 cdev->dev.bus_id);
1833
1834         /* FIXME: we have to wait for the root device but we don't want
1835          * to wait for each single device but for all at once. */
1836         wait_event(dasd_init_waitq, _wait_for_device(device));
1837
1838         dasd_put_device(device);
1839
1840         return rc;
1841 }
1842
1843 int
1844 dasd_generic_set_offline (struct ccw_device *cdev)
1845 {
1846         struct dasd_device *device;
1847         int max_count;
1848
1849         device = dasd_device_from_cdev(cdev);
1850         if (IS_ERR(device))
1851                 return PTR_ERR(device);
1852         if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1853                 /* Already doing offline processing */
1854                 dasd_put_device(device);
1855                 return 0;
1856         }
1857         /*
1858          * We must make sure that this device is currently not in use.
1859          * The open_count is increased for every opener, that includes
1860          * the blkdev_get in dasd_scan_partitions. We are only interested
1861          * in the other openers.
1862          */
1863         max_count = device->bdev ? 0 : -1;
1864         if (atomic_read(&device->open_count) > max_count) {
1865                 printk (KERN_WARNING "Can't offline dasd device with open"
1866                         " count = %i.\n",
1867                         atomic_read(&device->open_count));
1868                 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
1869                 dasd_put_device(device);
1870                 return -EBUSY;
1871         }
1872         dasd_set_target_state(device, DASD_STATE_NEW);
1873         /* dasd_delete_device destroys the device reference. */
1874         dasd_delete_device(device);
1875
1876         return 0;
1877 }
1878
1879 int
1880 dasd_generic_notify(struct ccw_device *cdev, int event)
1881 {
1882         struct dasd_device *device;
1883         struct dasd_ccw_req *cqr;
1884         unsigned long flags;
1885         int ret;
1886
1887         device = dasd_device_from_cdev(cdev);
1888         if (IS_ERR(device))
1889                 return 0;
1890         spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1891         ret = 0;
1892         switch (event) {
1893         case CIO_GONE:
1894         case CIO_NO_PATH:
1895                 if (device->state < DASD_STATE_BASIC)
1896                         break;
1897                 /* Device is active. We want to keep it. */
1898                 if (test_bit(DASD_FLAG_DSC_ERROR, &device->flags)) {
1899                         list_for_each_entry(cqr, &device->ccw_queue, list)
1900                                 if (cqr->status == DASD_CQR_IN_IO)
1901                                         cqr->status = DASD_CQR_FAILED;
1902                         device->stopped |= DASD_STOPPED_DC_EIO;
1903                         dasd_schedule_bh(device);
1904                 } else {
1905                         list_for_each_entry(cqr, &device->ccw_queue, list)
1906                                 if (cqr->status == DASD_CQR_IN_IO) {
1907                                         cqr->status = DASD_CQR_QUEUED;
1908                                         cqr->retries++;
1909                                 }
1910                         device->stopped |= DASD_STOPPED_DC_WAIT;
1911                         dasd_set_timer(device, 0);
1912                 }
1913                 ret = 1;
1914                 break;
1915         case CIO_OPER:
1916                 /* FIXME: add a sanity check. */
1917                 device->stopped &= ~(DASD_STOPPED_DC_WAIT|DASD_STOPPED_DC_EIO);
1918                 dasd_schedule_bh(device);
1919                 ret = 1;
1920                 break;
1921         }
1922         spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1923         dasd_put_device(device);
1924         return ret;
1925 }
1926
1927 /*
1928  * Automatically online either all dasd devices (dasd_autodetect) or
1929  * all devices specified with dasd= parameters.
1930  */
1931 void
1932 dasd_generic_auto_online (struct ccw_driver *dasd_discipline_driver)
1933 {
1934         struct device_driver *drv;
1935         struct device *d, *dev;
1936         struct ccw_device *cdev;
1937
1938         drv = get_driver(&dasd_discipline_driver->driver);
1939         down_read(&drv->bus->subsys.rwsem);
1940         dev = NULL;
1941         list_for_each_entry(d, &drv->devices, driver_list) {
1942                 dev = get_device(d);
1943                 if (!dev)
1944                         continue;
1945                 cdev = to_ccwdev(dev);
1946                 if (dasd_autodetect || dasd_busid_known(cdev->dev.bus_id) == 0)
1947                         ccw_device_set_online(cdev);
1948                 put_device(dev);
1949         }
1950         up_read(&drv->bus->subsys.rwsem);
1951         put_driver(drv);
1952 }
1953
1954 static int __init
1955 dasd_init(void)
1956 {
1957         int rc;
1958
1959         init_waitqueue_head(&dasd_init_waitq);
1960
1961         /* register 'common' DASD debug area, used for all DBF_XXX calls */
1962         dasd_debug_area = debug_register("dasd", 0, 2, 8 * sizeof (long));
1963         if (dasd_debug_area == NULL) {
1964                 rc = -ENOMEM;
1965                 goto failed;
1966         }
1967         debug_register_view(dasd_debug_area, &debug_sprintf_view);
1968         debug_set_level(dasd_debug_area, DBF_EMERG);
1969
1970         DBF_EVENT(DBF_EMERG, "%s", "debug area created");
1971
1972         dasd_diag_discipline_pointer = NULL;
1973
1974         rc = devfs_mk_dir("dasd");
1975         if (rc)
1976                 goto failed;
1977         rc = dasd_devmap_init();
1978         if (rc)
1979                 goto failed;
1980         rc = dasd_gendisk_init();
1981         if (rc)
1982                 goto failed;
1983         rc = dasd_parse();
1984         if (rc)
1985                 goto failed;
1986         rc = dasd_ioctl_init();
1987         if (rc)
1988                 goto failed;
1989 #ifdef CONFIG_PROC_FS
1990         rc = dasd_proc_init();
1991         if (rc)
1992                 goto failed;
1993 #endif
1994
1995         return 0;
1996 failed:
1997         MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
1998         dasd_exit();
1999         return rc;
2000 }
2001
2002 module_init(dasd_init);
2003 module_exit(dasd_exit);
2004
2005 EXPORT_SYMBOL(dasd_debug_area);
2006 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
2007
2008 EXPORT_SYMBOL(dasd_add_request_head);
2009 EXPORT_SYMBOL(dasd_add_request_tail);
2010 EXPORT_SYMBOL(dasd_cancel_req);
2011 EXPORT_SYMBOL(dasd_clear_timer);
2012 EXPORT_SYMBOL(dasd_enable_device);
2013 EXPORT_SYMBOL(dasd_int_handler);
2014 EXPORT_SYMBOL(dasd_kfree_request);
2015 EXPORT_SYMBOL(dasd_kick_device);
2016 EXPORT_SYMBOL(dasd_kmalloc_request);
2017 EXPORT_SYMBOL(dasd_schedule_bh);
2018 EXPORT_SYMBOL(dasd_set_target_state);
2019 EXPORT_SYMBOL(dasd_set_timer);
2020 EXPORT_SYMBOL(dasd_sfree_request);
2021 EXPORT_SYMBOL(dasd_sleep_on);
2022 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2023 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2024 EXPORT_SYMBOL(dasd_smalloc_request);
2025 EXPORT_SYMBOL(dasd_start_IO);
2026 EXPORT_SYMBOL(dasd_term_IO);
2027
2028 EXPORT_SYMBOL_GPL(dasd_generic_probe);
2029 EXPORT_SYMBOL_GPL(dasd_generic_remove);
2030 EXPORT_SYMBOL_GPL(dasd_generic_notify);
2031 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
2032 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
2033 EXPORT_SYMBOL_GPL(dasd_generic_auto_online);
2034
2035 /*
2036  * Overrides for Emacs so that we follow Linus's tabbing style.
2037  * Emacs will notice this stuff at the end of the file and automatically
2038  * adjust the settings for this buffer only.  This must remain at the end
2039  * of the file.
2040  * ---------------------------------------------------------------------------
2041  * Local variables:
2042  * c-indent-level: 4
2043  * c-brace-imaginary-offset: 0
2044  * c-brace-offset: -4
2045  * c-argdecl-indent: 4
2046  * c-label-offset: -4
2047  * c-continued-statement-offset: 4
2048  * c-continued-brace-offset: 0
2049  * indent-tabs-mode: 1
2050  * tab-width: 8
2051  * End:
2052  */