blob: e64f62d5e0fc503f2fe7533c741778be1a5092d1 [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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
11
Stefan Haberlandfc19f382009-03-26 15:23:49 +010012#define KMSG_COMPONENT "dasd"
13#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/kmod.h>
16#include <linux/init.h>
17#include <linux/interrupt.h>
18#include <linux/ctype.h>
19#include <linux/major.h>
20#include <linux/slab.h>
21#include <linux/buffer_head.h>
Christoph Hellwiga885c8c2006-01-08 01:02:50 -080022#include <linux/hdreg.h>
Cornelia Huckf3445a12009-04-14 15:36:23 +020023#include <linux/async.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include <asm/ccwdev.h>
26#include <asm/ebcdic.h>
27#include <asm/idals.h>
28#include <asm/todclk.h>
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +010029#include <asm/itcw.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31/* This is ugly... */
32#define PRINTK_HEADER "dasd:"
33
34#include "dasd_int.h"
35/*
36 * SECTION: Constant definitions to be used within this file
37 */
38#define DASD_CHANQ_MAX_SIZE 4
39
40/*
41 * SECTION: exported variables of dasd.c
42 */
43debug_info_t *dasd_debug_area;
44struct dasd_discipline *dasd_diag_discipline_pointer;
Heiko Carstens2b67fc42007-02-05 21:16:47 +010045void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
48MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
49 " Copyright 2000 IBM Corporation");
50MODULE_SUPPORTED_DEVICE("dasd");
Linus Torvalds1da177e2005-04-16 15:20:36 -070051MODULE_LICENSE("GPL");
52
53/*
54 * SECTION: prototypes for static functions of dasd.c
55 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010056static int dasd_alloc_queue(struct dasd_block *);
57static void dasd_setup_queue(struct dasd_block *);
58static void dasd_free_queue(struct dasd_block *);
59static void dasd_flush_request_queue(struct dasd_block *);
60static int dasd_flush_block_queue(struct dasd_block *);
61static void dasd_device_tasklet(struct dasd_device *);
62static void dasd_block_tasklet(struct dasd_block *);
Al Viro4927b3f2006-12-06 19:18:20 +000063static void do_kick_device(struct work_struct *);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010064static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
Stefan Weinhuber48cae882009-02-11 10:37:31 +010065static void dasd_device_timeout(unsigned long);
66static void dasd_block_timeout(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68/*
69 * SECTION: Operations on the device structure.
70 */
71static wait_queue_head_t dasd_init_waitq;
Horst Hummel8f617012006-08-30 14:33:33 +020072static wait_queue_head_t dasd_flush_wq;
Stefan Haberlandc80ee722008-05-30 10:03:31 +020073static wait_queue_head_t generic_waitq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75/*
76 * Allocate memory for a new device structure.
77 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010078struct dasd_device *dasd_alloc_device(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
80 struct dasd_device *device;
81
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010082 device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
83 if (!device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 /* Get two pages for normal block device operations. */
87 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010088 if (!device->ccw_mem) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 kfree(device);
90 return ERR_PTR(-ENOMEM);
91 }
92 /* Get one page for error recovery. */
93 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010094 if (!device->erp_mem) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 free_pages((unsigned long) device->ccw_mem, 1);
96 kfree(device);
97 return ERR_PTR(-ENOMEM);
98 }
99
100 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
101 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
102 spin_lock_init(&device->mem_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100103 atomic_set(&device->tasklet_scheduled, 0);
Horst Hummel138c0142006-06-29 14:58:12 +0200104 tasklet_init(&device->tasklet,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100105 (void (*)(unsigned long)) dasd_device_tasklet,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 (unsigned long) device);
107 INIT_LIST_HEAD(&device->ccw_queue);
108 init_timer(&device->timer);
Stefan Weinhuber48cae882009-02-11 10:37:31 +0100109 device->timer.function = dasd_device_timeout;
110 device->timer.data = (unsigned long) device;
Al Viro4927b3f2006-12-06 19:18:20 +0000111 INIT_WORK(&device->kick_work, do_kick_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 device->state = DASD_STATE_NEW;
113 device->target = DASD_STATE_NEW;
114
115 return device;
116}
117
118/*
119 * Free memory of a device structure.
120 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100121void dasd_free_device(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
Jesper Juhl17fd6822005-11-07 01:01:30 -0800123 kfree(device->private);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 free_page((unsigned long) device->erp_mem);
125 free_pages((unsigned long) device->ccw_mem, 1);
126 kfree(device);
127}
128
129/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100130 * Allocate memory for a new device structure.
131 */
132struct dasd_block *dasd_alloc_block(void)
133{
134 struct dasd_block *block;
135
136 block = kzalloc(sizeof(*block), GFP_ATOMIC);
137 if (!block)
138 return ERR_PTR(-ENOMEM);
139 /* open_count = 0 means device online but not in use */
140 atomic_set(&block->open_count, -1);
141
142 spin_lock_init(&block->request_queue_lock);
143 atomic_set(&block->tasklet_scheduled, 0);
144 tasklet_init(&block->tasklet,
145 (void (*)(unsigned long)) dasd_block_tasklet,
146 (unsigned long) block);
147 INIT_LIST_HEAD(&block->ccw_queue);
148 spin_lock_init(&block->queue_lock);
149 init_timer(&block->timer);
Stefan Weinhuber48cae882009-02-11 10:37:31 +0100150 block->timer.function = dasd_block_timeout;
151 block->timer.data = (unsigned long) block;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100152
153 return block;
154}
155
156/*
157 * Free memory of a device structure.
158 */
159void dasd_free_block(struct dasd_block *block)
160{
161 kfree(block);
162}
163
164/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 * Make a new device known to the system.
166 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100167static int dasd_state_new_to_known(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
169 int rc;
170
171 /*
Horst Hummel138c0142006-06-29 14:58:12 +0200172 * As long as the device is not in state DASD_STATE_NEW we want to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 * keep the reference count > 0.
174 */
175 dasd_get_device(device);
176
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100177 if (device->block) {
178 rc = dasd_alloc_queue(device->block);
179 if (rc) {
180 dasd_put_device(device);
181 return rc;
182 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 device->state = DASD_STATE_KNOWN;
185 return 0;
186}
187
188/*
189 * Let the system forget about a device.
190 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100191static int dasd_state_known_to_new(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Stefan Weinhuber20c64462006-03-24 03:15:25 -0800193 /* Disable extended error reporting for this device. */
194 dasd_eer_disable(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 /* Forget the discipline information. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100196 if (device->discipline) {
197 if (device->discipline->uncheck_device)
198 device->discipline->uncheck_device(device);
Peter Oberparleiteraa888612006-02-20 18:28:13 -0800199 module_put(device->discipline->owner);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100200 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 device->discipline = NULL;
Peter Oberparleiteraa888612006-02-20 18:28:13 -0800202 if (device->base_discipline)
203 module_put(device->base_discipline->owner);
204 device->base_discipline = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 device->state = DASD_STATE_NEW;
206
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100207 if (device->block)
208 dasd_free_queue(device->block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 /* Give up reference we took in dasd_state_new_to_known. */
211 dasd_put_device(device);
Horst Hummel8f617012006-08-30 14:33:33 +0200212 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213}
214
215/*
216 * Request the irq line for the device.
217 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100218static int dasd_state_known_to_basic(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
220 int rc;
221
222 /* Allocate and register gendisk structure. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100223 if (device->block) {
224 rc = dasd_gendisk_alloc(device->block);
225 if (rc)
226 return rc;
227 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100229 device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100230 8 * sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 debug_register_view(device->debug_area, &debug_sprintf_view);
Horst Hummelb0035f12006-09-20 15:59:07 +0200232 debug_set_level(device->debug_area, DBF_WARNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
234
235 device->state = DASD_STATE_BASIC;
236 return 0;
237}
238
239/*
240 * Release the irq line for the device. Terminate any running i/o.
241 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100242static int dasd_state_basic_to_known(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
Horst Hummel8f617012006-08-30 14:33:33 +0200244 int rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100245 if (device->block) {
246 dasd_gendisk_free(device->block);
247 dasd_block_clear_timer(device->block);
248 }
249 rc = dasd_flush_device_queue(device);
Horst Hummel8f617012006-08-30 14:33:33 +0200250 if (rc)
251 return rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100252 dasd_device_clear_timer(device);
Horst Hummel8f617012006-08-30 14:33:33 +0200253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
255 if (device->debug_area != NULL) {
256 debug_unregister(device->debug_area);
257 device->debug_area = NULL;
258 }
259 device->state = DASD_STATE_KNOWN;
Horst Hummel8f617012006-08-30 14:33:33 +0200260 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261}
262
263/*
264 * Do the initial analysis. The do_analysis function may return
265 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
266 * until the discipline decides to continue the startup sequence
267 * by calling the function dasd_change_state. The eckd disciplines
268 * uses this to start a ccw that detects the format. The completion
269 * interrupt for this detection ccw uses the kernel event daemon to
270 * trigger the call to dasd_change_state. All this is done in the
271 * discipline code, see dasd_eckd.c.
Horst Hummel90f00942006-03-07 21:55:39 -0800272 * After the analysis ccw is done (do_analysis returned 0) the block
273 * device is setup.
274 * In case the analysis returns an error, the device setup is stopped
275 * (a fake disk was already added to allow formatting).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100277static int dasd_state_basic_to_ready(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
279 int rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100280 struct dasd_block *block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
282 rc = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100283 block = device->block;
Horst Hummel90f00942006-03-07 21:55:39 -0800284 /* make disk known with correct capacity */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100285 if (block) {
286 if (block->base->discipline->do_analysis != NULL)
287 rc = block->base->discipline->do_analysis(block);
288 if (rc) {
289 if (rc != -EAGAIN)
290 device->state = DASD_STATE_UNFMT;
291 return rc;
292 }
293 dasd_setup_queue(block);
294 set_capacity(block->gdp,
295 block->blocks << block->s2b_shift);
296 device->state = DASD_STATE_READY;
297 rc = dasd_scan_partitions(block);
298 if (rc)
299 device->state = DASD_STATE_BASIC;
300 } else {
301 device->state = DASD_STATE_READY;
302 }
Horst Hummel90f00942006-03-07 21:55:39 -0800303 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304}
305
306/*
307 * Remove device from block device layer. Destroy dirty buffers.
308 * Forget format information. Check if the target level is basic
309 * and if it is create fake disk for formatting.
310 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100311static int dasd_state_ready_to_basic(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
Horst Hummel8f617012006-08-30 14:33:33 +0200313 int rc;
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 device->state = DASD_STATE_BASIC;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100316 if (device->block) {
317 struct dasd_block *block = device->block;
318 rc = dasd_flush_block_queue(block);
319 if (rc) {
320 device->state = DASD_STATE_READY;
321 return rc;
322 }
323 dasd_destroy_partitions(block);
324 dasd_flush_request_queue(block);
325 block->blocks = 0;
326 block->bp_block = 0;
327 block->s2b_shift = 0;
328 }
Horst Hummel8f617012006-08-30 14:33:33 +0200329 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330}
331
332/*
Horst Hummel90f00942006-03-07 21:55:39 -0800333 * Back to basic.
334 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100335static int dasd_state_unfmt_to_basic(struct dasd_device *device)
Horst Hummel90f00942006-03-07 21:55:39 -0800336{
337 device->state = DASD_STATE_BASIC;
Horst Hummel8f617012006-08-30 14:33:33 +0200338 return 0;
Horst Hummel90f00942006-03-07 21:55:39 -0800339}
340
341/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 * Make the device online and schedule the bottom half to start
343 * the requeueing of requests from the linux request queue to the
344 * ccw queue.
345 */
Horst Hummel8f617012006-08-30 14:33:33 +0200346static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347dasd_state_ready_to_online(struct dasd_device * device)
348{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100349 int rc;
Stefan Weinhuber13018092009-01-09 12:14:50 +0100350 struct gendisk *disk;
351 struct disk_part_iter piter;
352 struct hd_struct *part;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100353
354 if (device->discipline->ready_to_online) {
355 rc = device->discipline->ready_to_online(device);
356 if (rc)
357 return rc;
358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 device->state = DASD_STATE_ONLINE;
Stefan Weinhuber13018092009-01-09 12:14:50 +0100360 if (device->block) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100361 dasd_schedule_block_bh(device->block);
Stefan Weinhuber13018092009-01-09 12:14:50 +0100362 disk = device->block->bdev->bd_disk;
363 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
364 while ((part = disk_part_iter_next(&piter)))
365 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
366 disk_part_iter_exit(&piter);
367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 return 0;
369}
370
371/*
372 * Stop the requeueing of requests again.
373 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100374static int dasd_state_online_to_ready(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100376 int rc;
Stefan Weinhuber13018092009-01-09 12:14:50 +0100377 struct gendisk *disk;
378 struct disk_part_iter piter;
379 struct hd_struct *part;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100380
381 if (device->discipline->online_to_ready) {
382 rc = device->discipline->online_to_ready(device);
383 if (rc)
384 return rc;
385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 device->state = DASD_STATE_READY;
Stefan Weinhuber13018092009-01-09 12:14:50 +0100387 if (device->block) {
388 disk = device->block->bdev->bd_disk;
389 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
390 while ((part = disk_part_iter_next(&piter)))
391 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
392 disk_part_iter_exit(&piter);
393 }
Horst Hummel8f617012006-08-30 14:33:33 +0200394 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395}
396
397/*
398 * Device startup state changes.
399 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100400static int dasd_increase_state(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
402 int rc;
403
404 rc = 0;
405 if (device->state == DASD_STATE_NEW &&
406 device->target >= DASD_STATE_KNOWN)
407 rc = dasd_state_new_to_known(device);
408
409 if (!rc &&
410 device->state == DASD_STATE_KNOWN &&
411 device->target >= DASD_STATE_BASIC)
412 rc = dasd_state_known_to_basic(device);
413
414 if (!rc &&
415 device->state == DASD_STATE_BASIC &&
416 device->target >= DASD_STATE_READY)
417 rc = dasd_state_basic_to_ready(device);
418
419 if (!rc &&
Horst Hummel39ccf952006-04-27 18:40:10 -0700420 device->state == DASD_STATE_UNFMT &&
421 device->target > DASD_STATE_UNFMT)
422 rc = -EPERM;
423
424 if (!rc &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 device->state == DASD_STATE_READY &&
426 device->target >= DASD_STATE_ONLINE)
427 rc = dasd_state_ready_to_online(device);
428
429 return rc;
430}
431
432/*
433 * Device shutdown state changes.
434 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100435static int dasd_decrease_state(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
Horst Hummel8f617012006-08-30 14:33:33 +0200437 int rc;
438
439 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 if (device->state == DASD_STATE_ONLINE &&
441 device->target <= DASD_STATE_READY)
Horst Hummel8f617012006-08-30 14:33:33 +0200442 rc = dasd_state_online_to_ready(device);
Horst Hummel138c0142006-06-29 14:58:12 +0200443
Horst Hummel8f617012006-08-30 14:33:33 +0200444 if (!rc &&
445 device->state == DASD_STATE_READY &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 device->target <= DASD_STATE_BASIC)
Horst Hummel8f617012006-08-30 14:33:33 +0200447 rc = dasd_state_ready_to_basic(device);
Horst Hummel90f00942006-03-07 21:55:39 -0800448
Horst Hummel8f617012006-08-30 14:33:33 +0200449 if (!rc &&
450 device->state == DASD_STATE_UNFMT &&
Horst Hummel90f00942006-03-07 21:55:39 -0800451 device->target <= DASD_STATE_BASIC)
Horst Hummel8f617012006-08-30 14:33:33 +0200452 rc = dasd_state_unfmt_to_basic(device);
Horst Hummel90f00942006-03-07 21:55:39 -0800453
Horst Hummel8f617012006-08-30 14:33:33 +0200454 if (!rc &&
455 device->state == DASD_STATE_BASIC &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 device->target <= DASD_STATE_KNOWN)
Horst Hummel8f617012006-08-30 14:33:33 +0200457 rc = dasd_state_basic_to_known(device);
Horst Hummel138c0142006-06-29 14:58:12 +0200458
Horst Hummel8f617012006-08-30 14:33:33 +0200459 if (!rc &&
460 device->state == DASD_STATE_KNOWN &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 device->target <= DASD_STATE_NEW)
Horst Hummel8f617012006-08-30 14:33:33 +0200462 rc = dasd_state_known_to_new(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Horst Hummel8f617012006-08-30 14:33:33 +0200464 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465}
466
467/*
468 * This is the main startup/shutdown routine.
469 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100470static void dasd_change_state(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
472 int rc;
473
474 if (device->state == device->target)
475 /* Already where we want to go today... */
476 return;
477 if (device->state < device->target)
478 rc = dasd_increase_state(device);
479 else
480 rc = dasd_decrease_state(device);
481 if (rc && rc != -EAGAIN)
482 device->target = device->state;
483
Cornelia Huckf3445a12009-04-14 15:36:23 +0200484 if (device->state == device->target) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 wake_up(&dasd_init_waitq);
Cornelia Huckf3445a12009-04-14 15:36:23 +0200486 dasd_put_device(device);
487 }
Horst Hummel4dfd5c42007-04-27 16:01:47 +0200488
489 /* let user-space know that the device status changed */
490 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491}
492
493/*
494 * Kick starter for devices that did not complete the startup/shutdown
495 * procedure or were sleeping because of a pending state.
496 * dasd_kick_device will schedule a call do do_kick_device to the kernel
497 * event daemon.
498 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100499static void do_kick_device(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
Al Viro4927b3f2006-12-06 19:18:20 +0000501 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 dasd_change_state(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100503 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 dasd_put_device(device);
505}
506
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100507void dasd_kick_device(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508{
509 dasd_get_device(device);
510 /* queue call to dasd_kick_device to the kernel event daemon. */
511 schedule_work(&device->kick_work);
512}
513
514/*
515 * Set the target state for a device and starts the state change.
516 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100517void dasd_set_target_state(struct dasd_device *device, int target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
Cornelia Huckf3445a12009-04-14 15:36:23 +0200519 dasd_get_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 /* If we are in probeonly mode stop at DASD_STATE_READY. */
521 if (dasd_probeonly && target > DASD_STATE_READY)
522 target = DASD_STATE_READY;
523 if (device->target != target) {
Cornelia Huckf3445a12009-04-14 15:36:23 +0200524 if (device->state == target) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 wake_up(&dasd_init_waitq);
Cornelia Huckf3445a12009-04-14 15:36:23 +0200526 dasd_put_device(device);
527 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 device->target = target;
529 }
530 if (device->state != device->target)
531 dasd_change_state(device);
532}
533
534/*
535 * Enable devices with device numbers in [from..to].
536 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100537static inline int _wait_for_device(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
539 return (device->state == device->target);
540}
541
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100542void dasd_enable_device(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
544 dasd_set_target_state(device, DASD_STATE_ONLINE);
545 if (device->state <= DASD_STATE_KNOWN)
546 /* No discipline for device found. */
547 dasd_set_target_state(device, DASD_STATE_NEW);
548 /* Now wait for the devices to come up. */
549 wait_event(dasd_init_waitq, _wait_for_device(device));
550}
551
552/*
553 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
554 */
555#ifdef CONFIG_DASD_PROFILE
556
557struct dasd_profile_info_t dasd_global_profile;
558unsigned int dasd_profile_level = DASD_PROFILE_OFF;
559
560/*
561 * Increments counter in global and local profiling structures.
562 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100563#define dasd_profile_counter(value, counter, block) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{ \
565 int index; \
566 for (index = 0; index < 31 && value >> (2+index); index++); \
567 dasd_global_profile.counter[index]++; \
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100568 block->profile.counter[index]++; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569}
570
571/*
572 * Add profiling information for cqr before execution.
573 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100574static void dasd_profile_start(struct dasd_block *block,
575 struct dasd_ccw_req *cqr,
576 struct request *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577{
578 struct list_head *l;
579 unsigned int counter;
580
581 if (dasd_profile_level != DASD_PROFILE_ON)
582 return;
583
584 /* count the length of the chanq for statistics */
585 counter = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100586 list_for_each(l, &block->ccw_queue)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 if (++counter >= 31)
588 break;
589 dasd_global_profile.dasd_io_nr_req[counter]++;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100590 block->profile.dasd_io_nr_req[counter]++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591}
592
593/*
594 * Add profiling information for cqr after execution.
595 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100596static void dasd_profile_end(struct dasd_block *block,
597 struct dasd_ccw_req *cqr,
598 struct request *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
600 long strtime, irqtime, endtime, tottime; /* in microseconds */
601 long tottimeps, sectors;
602
603 if (dasd_profile_level != DASD_PROFILE_ON)
604 return;
605
Tejun Heo83096eb2009-05-07 22:24:39 +0900606 sectors = blk_rq_sectors(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 if (!cqr->buildclk || !cqr->startclk ||
608 !cqr->stopclk || !cqr->endclk ||
609 !sectors)
610 return;
611
612 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
613 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
614 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
615 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
616 tottimeps = tottime / sectors;
617
618 if (!dasd_global_profile.dasd_io_reqs)
619 memset(&dasd_global_profile, 0,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100620 sizeof(struct dasd_profile_info_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 dasd_global_profile.dasd_io_reqs++;
622 dasd_global_profile.dasd_io_sects += sectors;
623
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100624 if (!block->profile.dasd_io_reqs)
625 memset(&block->profile, 0,
626 sizeof(struct dasd_profile_info_t));
627 block->profile.dasd_io_reqs++;
628 block->profile.dasd_io_sects += sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100630 dasd_profile_counter(sectors, dasd_io_secs, block);
631 dasd_profile_counter(tottime, dasd_io_times, block);
632 dasd_profile_counter(tottimeps, dasd_io_timps, block);
633 dasd_profile_counter(strtime, dasd_io_time1, block);
634 dasd_profile_counter(irqtime, dasd_io_time2, block);
635 dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, block);
636 dasd_profile_counter(endtime, dasd_io_time3, block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637}
638#else
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100639#define dasd_profile_start(block, cqr, req) do {} while (0)
640#define dasd_profile_end(block, cqr, req) do {} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#endif /* CONFIG_DASD_PROFILE */
642
643/*
644 * Allocate memory for a channel program with 'cplength' channel
645 * command words and 'datasize' additional space. There are two
646 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
647 * memory and 2) dasd_smalloc_request uses the static ccw memory
648 * that gets allocated for each device.
649 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100650struct dasd_ccw_req *dasd_kmalloc_request(char *magic, int cplength,
651 int datasize,
652 struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
654 struct dasd_ccw_req *cqr;
655
656 /* Sanity checks */
Eric Sesterhenn7ac1e872006-03-24 18:48:13 +0100657 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
658 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800660 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 if (cqr == NULL)
662 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 cqr->cpaddr = NULL;
664 if (cplength > 0) {
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800665 cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 GFP_ATOMIC | GFP_DMA);
667 if (cqr->cpaddr == NULL) {
668 kfree(cqr);
669 return ERR_PTR(-ENOMEM);
670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 }
672 cqr->data = NULL;
673 if (datasize > 0) {
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800674 cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 if (cqr->data == NULL) {
Jesper Juhl17fd6822005-11-07 01:01:30 -0800676 kfree(cqr->cpaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 kfree(cqr);
678 return ERR_PTR(-ENOMEM);
679 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 }
681 strncpy((char *) &cqr->magic, magic, 4);
682 ASCEBC((char *) &cqr->magic, 4);
683 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
684 dasd_get_device(device);
685 return cqr;
686}
687
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100688struct dasd_ccw_req *dasd_smalloc_request(char *magic, int cplength,
689 int datasize,
690 struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
692 unsigned long flags;
693 struct dasd_ccw_req *cqr;
694 char *data;
695 int size;
696
697 /* Sanity checks */
Eric Sesterhenn7ac1e872006-03-24 18:48:13 +0100698 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
699 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
701 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
702 if (cplength > 0)
703 size += cplength * sizeof(struct ccw1);
704 if (datasize > 0)
705 size += datasize;
706 spin_lock_irqsave(&device->mem_lock, flags);
707 cqr = (struct dasd_ccw_req *)
708 dasd_alloc_chunk(&device->ccw_chunks, size);
709 spin_unlock_irqrestore(&device->mem_lock, flags);
710 if (cqr == NULL)
711 return ERR_PTR(-ENOMEM);
712 memset(cqr, 0, sizeof(struct dasd_ccw_req));
713 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
714 cqr->cpaddr = NULL;
715 if (cplength > 0) {
716 cqr->cpaddr = (struct ccw1 *) data;
717 data += cplength*sizeof(struct ccw1);
718 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
719 }
720 cqr->data = NULL;
721 if (datasize > 0) {
722 cqr->data = data;
723 memset(cqr->data, 0, datasize);
724 }
725 strncpy((char *) &cqr->magic, magic, 4);
726 ASCEBC((char *) &cqr->magic, 4);
727 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
728 dasd_get_device(device);
729 return cqr;
730}
731
732/*
733 * Free memory of a channel program. This function needs to free all the
734 * idal lists that might have been created by dasd_set_cda and the
735 * struct dasd_ccw_req itself.
736 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100737void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738{
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800739#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 struct ccw1 *ccw;
741
742 /* Clear any idals used for the request. */
743 ccw = cqr->cpaddr;
744 do {
745 clear_normalized_cda(ccw);
746 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
747#endif
Jesper Juhl17fd6822005-11-07 01:01:30 -0800748 kfree(cqr->cpaddr);
749 kfree(cqr->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 kfree(cqr);
751 dasd_put_device(device);
752}
753
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100754void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755{
756 unsigned long flags;
757
758 spin_lock_irqsave(&device->mem_lock, flags);
759 dasd_free_chunk(&device->ccw_chunks, cqr);
760 spin_unlock_irqrestore(&device->mem_lock, flags);
761 dasd_put_device(device);
762}
763
764/*
765 * Check discipline magic in cqr.
766 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100767static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
769 struct dasd_device *device;
770
771 if (cqr == NULL)
772 return -EINVAL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100773 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100775 DBF_DEV_EVENT(DBF_WARNING, device,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 " dasd_ccw_req 0x%08x magic doesn't match"
777 " discipline 0x%08x",
778 cqr->magic,
779 *(unsigned int *) device->discipline->name);
780 return -EINVAL;
781 }
782 return 0;
783}
784
785/*
786 * Terminate the current i/o and set the request to clear_pending.
787 * Timer keeps device runnig.
788 * ccw_device_clear can fail if the i/o subsystem
789 * is in a bad mood.
790 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100791int dasd_term_IO(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792{
793 struct dasd_device *device;
794 int retries, rc;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100795 char errorstring[ERRORLENGTH];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 /* Check the cqr */
798 rc = dasd_check_cqr(cqr);
799 if (rc)
800 return rc;
801 retries = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100802 device = (struct dasd_device *) cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
804 rc = ccw_device_clear(device->cdev, (long) cqr);
805 switch (rc) {
806 case 0: /* termination successful */
Horst Hummelc2ba4442006-02-01 03:06:37 -0800807 cqr->retries--;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100808 cqr->status = DASD_CQR_CLEAR_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 cqr->stopclk = get_clock();
Horst Hummel8f617012006-08-30 14:33:33 +0200810 cqr->starttime = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 DBF_DEV_EVENT(DBF_DEBUG, device,
812 "terminate cqr %p successful",
813 cqr);
814 break;
815 case -ENODEV:
816 DBF_DEV_EVENT(DBF_ERR, device, "%s",
817 "device gone, retry");
818 break;
819 case -EIO:
820 DBF_DEV_EVENT(DBF_ERR, device, "%s",
821 "I/O error, retry");
822 break;
823 case -EINVAL:
824 case -EBUSY:
825 DBF_DEV_EVENT(DBF_ERR, device, "%s",
826 "device busy, retry later");
827 break;
828 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100829 /* internal error 10 - unknown rc*/
830 snprintf(errorstring, ERRORLENGTH, "10 %d", rc);
831 dev_err(&device->cdev->dev, "An error occurred in the "
832 "DASD device driver, reason=%s\n", errorstring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 BUG();
834 break;
835 }
836 retries++;
837 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100838 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 return rc;
840}
841
842/*
843 * Start the i/o. This start_IO can fail if the channel is really busy.
844 * In that case set up a timer to start the request later.
845 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100846int dasd_start_IO(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847{
848 struct dasd_device *device;
849 int rc;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100850 char errorstring[ERRORLENGTH];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
852 /* Check the cqr */
853 rc = dasd_check_cqr(cqr);
854 if (rc)
855 return rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100856 device = (struct dasd_device *) cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 if (cqr->retries < 0) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100858 /* internal error 14 - start_IO run out of retries */
859 sprintf(errorstring, "14 %p", cqr);
860 dev_err(&device->cdev->dev, "An error occurred in the DASD "
861 "device driver, reason=%s\n", errorstring);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100862 cqr->status = DASD_CQR_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 return -EIO;
864 }
865 cqr->startclk = get_clock();
866 cqr->starttime = jiffies;
867 cqr->retries--;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100868 if (cqr->cpmode == 1) {
869 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
870 (long) cqr, cqr->lpm);
871 } else {
872 rc = ccw_device_start(device->cdev, cqr->cpaddr,
873 (long) cqr, cqr->lpm, 0);
874 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 switch (rc) {
876 case 0:
877 cqr->status = DASD_CQR_IN_IO;
878 DBF_DEV_EVENT(DBF_DEBUG, device,
879 "start_IO: request %p started successful",
880 cqr);
881 break;
882 case -EBUSY:
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100883 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 "start_IO: device busy, retry later");
885 break;
886 case -ETIMEDOUT:
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100887 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 "start_IO: request timeout, retry later");
889 break;
890 case -EACCES:
891 /* -EACCES indicates that the request used only a
892 * subset of the available pathes and all these
893 * pathes are gone.
894 * Do a retry with all available pathes.
895 */
896 cqr->lpm = LPM_ANYPATH;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100897 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 "start_IO: selected pathes gone,"
899 " retry on all pathes");
900 break;
901 case -ENODEV:
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100902 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
903 "start_IO: -ENODEV device gone, retry");
904 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 case -EIO:
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100906 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100907 "start_IO: -EIO device gone, retry");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 break;
909 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100910 /* internal error 11 - unknown rc */
911 snprintf(errorstring, ERRORLENGTH, "11 %d", rc);
912 dev_err(&device->cdev->dev,
913 "An error occurred in the DASD device driver, "
914 "reason=%s\n", errorstring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 BUG();
916 break;
917 }
918 return rc;
919}
920
921/*
922 * Timeout function for dasd devices. This is used for different purposes
923 * 1) missing interrupt handler for normal operation
924 * 2) delayed start of request where start_IO failed with -EBUSY
925 * 3) timeout for missing state change interrupts
926 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
927 * DASD_CQR_QUEUED for 2) and 3).
928 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100929static void dasd_device_timeout(unsigned long ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930{
931 unsigned long flags;
932 struct dasd_device *device;
933
934 device = (struct dasd_device *) ptr;
935 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
936 /* re-activate request queue */
937 device->stopped &= ~DASD_STOPPED_PENDING;
938 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100939 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940}
941
942/*
943 * Setup timeout for a device in jiffies.
944 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100945void dasd_device_set_timer(struct dasd_device *device, int expires)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946{
Stefan Weinhuber48cae882009-02-11 10:37:31 +0100947 if (expires == 0)
948 del_timer(&device->timer);
949 else
950 mod_timer(&device->timer, jiffies + expires);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951}
952
953/*
954 * Clear timeout for a device.
955 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100956void dasd_device_clear_timer(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957{
Stefan Weinhuber48cae882009-02-11 10:37:31 +0100958 del_timer(&device->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959}
960
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100961static void dasd_handle_killed_request(struct ccw_device *cdev,
962 unsigned long intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963{
964 struct dasd_ccw_req *cqr;
965 struct dasd_device *device;
966
Stefan Weinhuberf16f5842008-05-15 16:52:36 +0200967 if (!intparm)
968 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 cqr = (struct dasd_ccw_req *) intparm;
970 if (cqr->status != DASD_CQR_IN_IO) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100971 DBF_EVENT(DBF_DEBUG,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 "invalid status in handle_killed_request: "
973 "bus_id %s, status %02x",
Kay Sievers2a0217d2008-10-10 21:33:09 +0200974 dev_name(&cdev->dev), cqr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 return;
976 }
977
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100978 device = (struct dasd_device *) cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 if (device == NULL ||
Martin Schwidefskya00bfd72006-09-20 15:59:05 +0200980 device != dasd_device_from_cdev_locked(cdev) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100982 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid device in request: "
983 "bus_id %s", dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 return;
985 }
986
987 /* Schedule request to be retried. */
988 cqr->status = DASD_CQR_QUEUED;
989
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100990 dasd_device_clear_timer(device);
991 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 dasd_put_device(device);
993}
994
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100995void dasd_generic_handle_state_change(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996{
Stefan Weinhuber20c64462006-03-24 03:15:25 -0800997 /* First of all start sense subsystem status request. */
998 dasd_eer_snss(device);
999
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 device->stopped &= ~DASD_STOPPED_PENDING;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001001 dasd_schedule_device_bh(device);
1002 if (device->block)
1003 dasd_schedule_block_bh(device->block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004}
1005
1006/*
1007 * Interrupt handler for "normal" ssch-io based dasd devices.
1008 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001009void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1010 struct irb *irb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011{
1012 struct dasd_ccw_req *cqr, *next;
1013 struct dasd_device *device;
1014 unsigned long long now;
1015 int expires;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
1017 if (IS_ERR(irb)) {
1018 switch (PTR_ERR(irb)) {
1019 case -EIO:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 break;
1021 case -ETIMEDOUT:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001022 DBF_EVENT(DBF_WARNING, "%s(%s): request timed out\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +02001023 __func__, dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 break;
1025 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001026 DBF_EVENT(DBF_WARNING, "%s(%s): unknown error %ld\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +02001027 __func__, dev_name(&cdev->dev), PTR_ERR(irb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 }
Stefan Weinhuberf16f5842008-05-15 16:52:36 +02001029 dasd_handle_killed_request(cdev, intparm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 return;
1031 }
1032
1033 now = get_clock();
1034
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001035 /* check for unsolicited interrupts */
1036 cqr = (struct dasd_ccw_req *) intparm;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001037 if (!cqr || ((scsw_cc(&irb->scsw) == 1) &&
1038 (scsw_fctl(&irb->scsw) & SCSW_FCTL_START_FUNC) &&
1039 (scsw_stctl(&irb->scsw) & SCSW_STCTL_STATUS_PEND))) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001040 if (cqr && cqr->status == DASD_CQR_IN_IO)
1041 cqr->status = DASD_CQR_QUEUED;
Martin Schwidefskya00bfd72006-09-20 15:59:05 +02001042 device = dasd_device_from_cdev_locked(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 if (!IS_ERR(device)) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001044 dasd_device_clear_timer(device);
1045 device->discipline->handle_unsolicited_interrupt(device,
1046 irb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 dasd_put_device(device);
1048 }
1049 return;
1050 }
1051
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001052 device = (struct dasd_device *) cqr->startdev;
1053 if (!device ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001055 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid device in request: "
1056 "bus_id %s", dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 return;
1058 }
1059
1060 /* Check for clear pending */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001061 if (cqr->status == DASD_CQR_CLEAR_PENDING &&
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001062 scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001063 cqr->status = DASD_CQR_CLEARED;
1064 dasd_device_clear_timer(device);
Horst Hummel8f617012006-08-30 14:33:33 +02001065 wake_up(&dasd_flush_wq);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001066 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 return;
1068 }
1069
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001070 /* check status - the request might have been killed by dyn detach */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 if (cqr->status != DASD_CQR_IN_IO) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001072 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1073 "status %02x", dev_name(&cdev->dev), cqr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 return;
1075 }
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001076
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001077 next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 expires = 0;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001079 if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1080 scsw_cstat(&irb->scsw) == 0) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001081 /* request was completed successfully */
1082 cqr->status = DASD_CQR_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 cqr->stopclk = now;
1084 /* Start first request on queue if possible -> fast_io. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001085 if (cqr->devlist.next != &device->ccw_queue) {
1086 next = list_entry(cqr->devlist.next,
1087 struct dasd_ccw_req, devlist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001089 } else { /* error */
1090 memcpy(&cqr->irb, irb, sizeof(struct irb));
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001091 /* log sense for every failed I/O to s390 debugfeature */
1092 dasd_log_sense_dbf(cqr, irb);
Horst Hummel9575bf22006-12-08 15:54:15 +01001093 if (device->features & DASD_FEATURE_ERPLOG) {
Horst Hummel9575bf22006-12-08 15:54:15 +01001094 dasd_log_sense(cqr, irb);
1095 }
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001096
Stefan Haberland6c5f57c2008-02-05 16:50:46 +01001097 /*
1098 * If we don't want complex ERP for this request, then just
1099 * reset this and retry it in the fastpath
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001100 */
Stefan Haberland6c5f57c2008-02-05 16:50:46 +01001101 if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001102 cqr->retries > 0) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001103 if (cqr->lpm == LPM_ANYPATH)
1104 DBF_DEV_EVENT(DBF_DEBUG, device,
1105 "default ERP in fastpath "
1106 "(%i retries left)",
1107 cqr->retries);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001108 cqr->lpm = LPM_ANYPATH;
1109 cqr->status = DASD_CQR_QUEUED;
1110 next = cqr;
1111 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 cqr->status = DASD_CQR_ERROR;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001113 }
1114 if (next && (next->status == DASD_CQR_QUEUED) &&
1115 (!device->stopped)) {
1116 if (device->discipline->start_IO(next) == 0)
1117 expires = next->expires;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 }
1119 if (expires != 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001120 dasd_device_set_timer(device, expires);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 else
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001122 dasd_device_clear_timer(device);
1123 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124}
1125
1126/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001127 * If we have an error on a dasd_block layer request then we cancel
1128 * and return all further requests from the same dasd_block as well.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001130static void __dasd_device_recovery(struct dasd_device *device,
1131 struct dasd_ccw_req *ref_cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132{
1133 struct list_head *l, *n;
1134 struct dasd_ccw_req *cqr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
1136 /*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001137 * only requeue request that came from the dasd_block layer
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001139 if (!ref_cqr->block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 return;
Horst Hummelf24acd42005-05-01 08:58:59 -07001141
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001142 list_for_each_safe(l, n, &device->ccw_queue) {
1143 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1144 if (cqr->status == DASD_CQR_QUEUED &&
1145 ref_cqr->block == cqr->block) {
1146 cqr->status = DASD_CQR_CLEARED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001148 }
1149};
1150
1151/*
1152 * Remove those ccw requests from the queue that need to be returned
1153 * to the upper layer.
1154 */
1155static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1156 struct list_head *final_queue)
1157{
1158 struct list_head *l, *n;
1159 struct dasd_ccw_req *cqr;
1160
1161 /* Process request with final status. */
1162 list_for_each_safe(l, n, &device->ccw_queue) {
1163 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1164
1165 /* Stop list processing at the first non-final request. */
1166 if (cqr->status == DASD_CQR_QUEUED ||
1167 cqr->status == DASD_CQR_IN_IO ||
1168 cqr->status == DASD_CQR_CLEAR_PENDING)
1169 break;
1170 if (cqr->status == DASD_CQR_ERROR) {
1171 __dasd_device_recovery(device, cqr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001173 /* Rechain finished requests to final queue */
1174 list_move_tail(&cqr->devlist, final_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 }
1176}
1177
1178/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001179 * the cqrs from the final queue are returned to the upper layer
1180 * by setting a dasd_block state and calling the callback function
1181 */
1182static void __dasd_device_process_final_queue(struct dasd_device *device,
1183 struct list_head *final_queue)
1184{
1185 struct list_head *l, *n;
1186 struct dasd_ccw_req *cqr;
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001187 struct dasd_block *block;
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001188 void (*callback)(struct dasd_ccw_req *, void *data);
1189 void *callback_data;
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001190 char errorstring[ERRORLENGTH];
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001191
1192 list_for_each_safe(l, n, final_queue) {
1193 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1194 list_del_init(&cqr->devlist);
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001195 block = cqr->block;
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001196 callback = cqr->callback;
1197 callback_data = cqr->callback_data;
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001198 if (block)
1199 spin_lock_bh(&block->queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001200 switch (cqr->status) {
1201 case DASD_CQR_SUCCESS:
1202 cqr->status = DASD_CQR_DONE;
1203 break;
1204 case DASD_CQR_ERROR:
1205 cqr->status = DASD_CQR_NEED_ERP;
1206 break;
1207 case DASD_CQR_CLEARED:
1208 cqr->status = DASD_CQR_TERMINATED;
1209 break;
1210 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001211 /* internal error 12 - wrong cqr status*/
1212 snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status);
1213 dev_err(&device->cdev->dev,
1214 "An error occurred in the DASD device driver, "
1215 "reason=%s\n", errorstring);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001216 BUG();
1217 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001218 if (cqr->callback != NULL)
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001219 (callback)(cqr, callback_data);
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001220 if (block)
1221 spin_unlock_bh(&block->queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001222 }
1223}
1224
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001225/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 * Take a look at the first request on the ccw queue and check
1227 * if it reached its expire time. If so, terminate the IO.
1228 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001229static void __dasd_device_check_expire(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230{
1231 struct dasd_ccw_req *cqr;
1232
1233 if (list_empty(&device->ccw_queue))
1234 return;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001235 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
Horst Hummel29145a62006-12-04 15:40:15 +01001236 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1237 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
1238 if (device->discipline->term_IO(cqr) != 0) {
1239 /* Hmpf, try again in 5 sec */
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001240 dev_err(&device->cdev->dev,
1241 "cqr %p timed out (%is) but cannot be "
1242 "ended, retrying in 5 s\n",
1243 cqr, (cqr->expires/HZ));
Stefan Haberland7dc1da92008-01-26 14:11:26 +01001244 cqr->expires += 5*HZ;
1245 dasd_device_set_timer(device, 5*HZ);
Horst Hummel29145a62006-12-04 15:40:15 +01001246 } else {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001247 dev_err(&device->cdev->dev,
1248 "cqr %p timed out (%is), %i retries "
1249 "remaining\n", cqr, (cqr->expires/HZ),
1250 cqr->retries);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 }
1252 }
1253}
1254
1255/*
1256 * Take a look at the first request on the ccw queue and check
1257 * if it needs to be started.
1258 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001259static void __dasd_device_start_head(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260{
1261 struct dasd_ccw_req *cqr;
1262 int rc;
1263
1264 if (list_empty(&device->ccw_queue))
1265 return;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001266 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07001267 if (cqr->status != DASD_CQR_QUEUED)
1268 return;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001269 /* when device is stopped, return request to previous layer */
1270 if (device->stopped) {
1271 cqr->status = DASD_CQR_CLEARED;
1272 dasd_schedule_device_bh(device);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07001273 return;
Horst Hummel1c01b8a2006-01-06 00:19:15 -08001274 }
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07001275
1276 rc = device->discipline->start_IO(cqr);
1277 if (rc == 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001278 dasd_device_set_timer(device, cqr->expires);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07001279 else if (rc == -EACCES) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001280 dasd_schedule_device_bh(device);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07001281 } else
1282 /* Hmpf, try again in 1/2 sec */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001283 dasd_device_set_timer(device, 50);
Horst Hummel8f617012006-08-30 14:33:33 +02001284}
1285
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001287 * Go through all request on the dasd_device request queue,
1288 * terminate them on the cdev if necessary, and return them to the
1289 * submitting layer via callback.
1290 * Note:
1291 * Make sure that all 'submitting layers' still exist when
1292 * this function is called!. In other words, when 'device' is a base
1293 * device then all block layer requests must have been removed before
1294 * via dasd_flush_block_queue.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001296int dasd_flush_device_queue(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001298 struct dasd_ccw_req *cqr, *n;
1299 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 struct list_head flush_queue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
1302 INIT_LIST_HEAD(&flush_queue);
1303 spin_lock_irq(get_ccwdev_lock(device->cdev));
Horst Hummel8f617012006-08-30 14:33:33 +02001304 rc = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001305 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
Horst Hummel8f617012006-08-30 14:33:33 +02001306 /* Check status and move request to flush_queue */
1307 switch (cqr->status) {
1308 case DASD_CQR_IN_IO:
1309 rc = device->discipline->term_IO(cqr);
1310 if (rc) {
1311 /* unable to terminate requeust */
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001312 dev_err(&device->cdev->dev,
1313 "Flushing the DASD request queue "
1314 "failed for request %p\n", cqr);
Horst Hummel8f617012006-08-30 14:33:33 +02001315 /* stop flush processing */
1316 goto finished;
1317 }
1318 break;
1319 case DASD_CQR_QUEUED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 cqr->stopclk = get_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001321 cqr->status = DASD_CQR_CLEARED;
Horst Hummel8f617012006-08-30 14:33:33 +02001322 break;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001323 default: /* no need to modify the others */
Horst Hummel8f617012006-08-30 14:33:33 +02001324 break;
1325 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001326 list_move_tail(&cqr->devlist, &flush_queue);
Horst Hummel8f617012006-08-30 14:33:33 +02001327 }
Horst Hummel8f617012006-08-30 14:33:33 +02001328finished:
1329 spin_unlock_irq(get_ccwdev_lock(device->cdev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001330 /*
1331 * After this point all requests must be in state CLEAR_PENDING,
1332 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
1333 * one of the others.
1334 */
1335 list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
1336 wait_event(dasd_flush_wq,
1337 (cqr->status != DASD_CQR_CLEAR_PENDING));
1338 /*
1339 * Now set each request back to TERMINATED, DONE or NEED_ERP
1340 * and call the callback function of flushed requests
1341 */
1342 __dasd_device_process_final_queue(device, &flush_queue);
Horst Hummel8f617012006-08-30 14:33:33 +02001343 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344}
1345
1346/*
1347 * Acquire the device lock and process queues for the device.
1348 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001349static void dasd_device_tasklet(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350{
1351 struct list_head final_queue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
1353 atomic_set (&device->tasklet_scheduled, 0);
1354 INIT_LIST_HEAD(&final_queue);
1355 spin_lock_irq(get_ccwdev_lock(device->cdev));
1356 /* Check expire time of first request on the ccw queue. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001357 __dasd_device_check_expire(device);
1358 /* find final requests on ccw queue */
1359 __dasd_device_process_ccw_queue(device, &final_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1361 /* Now call the callback function of requests with final status */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001362 __dasd_device_process_final_queue(device, &final_queue);
1363 spin_lock_irq(get_ccwdev_lock(device->cdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 /* Now check if the head of the ccw queue needs to be started. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001365 __dasd_device_start_head(device);
1366 spin_unlock_irq(get_ccwdev_lock(device->cdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 dasd_put_device(device);
1368}
1369
1370/*
1371 * Schedules a call to dasd_tasklet over the device tasklet.
1372 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001373void dasd_schedule_device_bh(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374{
1375 /* Protect against rescheduling. */
Martin Schwidefsky973bd992006-01-06 00:19:07 -08001376 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 return;
1378 dasd_get_device(device);
1379 tasklet_hi_schedule(&device->tasklet);
1380}
1381
1382/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001383 * Queue a request to the head of the device ccw_queue.
1384 * Start the I/O if possible.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001386void dasd_add_request_head(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387{
1388 struct dasd_device *device;
1389 unsigned long flags;
1390
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001391 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001393 cqr->status = DASD_CQR_QUEUED;
1394 list_add(&cqr->devlist, &device->ccw_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 /* let the bh start the request to keep them in order */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001396 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1398}
1399
1400/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001401 * Queue a request to the tail of the device ccw_queue.
1402 * Start the I/O if possible.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001404void dasd_add_request_tail(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405{
1406 struct dasd_device *device;
1407 unsigned long flags;
1408
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001409 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001411 cqr->status = DASD_CQR_QUEUED;
1412 list_add_tail(&cqr->devlist, &device->ccw_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 /* let the bh start the request to keep them in order */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001414 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1416}
1417
1418/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001419 * Wakeup helper for the 'sleep_on' functions.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001421static void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422{
1423 wake_up((wait_queue_head_t *) data);
1424}
1425
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001426static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427{
1428 struct dasd_device *device;
1429 int rc;
1430
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001431 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 spin_lock_irq(get_ccwdev_lock(device->cdev));
Horst Hummelc2ba4442006-02-01 03:06:37 -08001433 rc = ((cqr->status == DASD_CQR_DONE ||
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001434 cqr->status == DASD_CQR_NEED_ERP ||
1435 cqr->status == DASD_CQR_TERMINATED) &&
1436 list_empty(&cqr->devlist));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1438 return rc;
1439}
1440
1441/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001442 * Queue a request to the tail of the device ccw_queue and wait for
1443 * it's completion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001445int dasd_sleep_on(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 struct dasd_device *device;
1448 int rc;
Horst Hummel138c0142006-06-29 14:58:12 +02001449
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001450 device = cqr->startdev;
Horst Hummel138c0142006-06-29 14:58:12 +02001451
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 cqr->callback = dasd_wakeup_cb;
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001453 cqr->callback_data = (void *) &generic_waitq;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001454 dasd_add_request_tail(cqr);
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001455 wait_event(generic_waitq, _wait_for_wakeup(cqr));
Horst Hummel138c0142006-06-29 14:58:12 +02001456
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 /* Request status is either done or failed. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001458 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 return rc;
1460}
1461
1462/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001463 * Queue a request to the tail of the device ccw_queue and wait
1464 * interruptible for it's completion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001466int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 struct dasd_device *device;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001469 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001471 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 cqr->callback = dasd_wakeup_cb;
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001473 cqr->callback_data = (void *) &generic_waitq;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001474 dasd_add_request_tail(cqr);
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001475 rc = wait_event_interruptible(generic_waitq, _wait_for_wakeup(cqr));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001476 if (rc == -ERESTARTSYS) {
1477 dasd_cancel_req(cqr);
1478 /* wait (non-interruptible) for final status */
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001479 wait_event(generic_waitq, _wait_for_wakeup(cqr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001481 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 return rc;
1483}
1484
1485/*
1486 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
1487 * for eckd devices) the currently running request has to be terminated
1488 * and be put back to status queued, before the special request is added
1489 * to the head of the queue. Then the special request is waited on normally.
1490 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001491static inline int _dasd_term_running_cqr(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492{
1493 struct dasd_ccw_req *cqr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
1495 if (list_empty(&device->ccw_queue))
1496 return 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001497 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
Horst Hummel8f617012006-08-30 14:33:33 +02001498 return device->discipline->term_IO(cqr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499}
1500
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001501int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 struct dasd_device *device;
1504 int rc;
Horst Hummel138c0142006-06-29 14:58:12 +02001505
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001506 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 spin_lock_irq(get_ccwdev_lock(device->cdev));
1508 rc = _dasd_term_running_cqr(device);
1509 if (rc) {
1510 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1511 return rc;
1512 }
Horst Hummel138c0142006-06-29 14:58:12 +02001513
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 cqr->callback = dasd_wakeup_cb;
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001515 cqr->callback_data = (void *) &generic_waitq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 cqr->status = DASD_CQR_QUEUED;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001517 list_add(&cqr->devlist, &device->ccw_queue);
Horst Hummel138c0142006-06-29 14:58:12 +02001518
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 /* let the bh start the request to keep them in order */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001520 dasd_schedule_device_bh(device);
Horst Hummel138c0142006-06-29 14:58:12 +02001521
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1523
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001524 wait_event(generic_waitq, _wait_for_wakeup(cqr));
Horst Hummel138c0142006-06-29 14:58:12 +02001525
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 /* Request status is either done or failed. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001527 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 return rc;
1529}
1530
1531/*
1532 * Cancels a request that was started with dasd_sleep_on_req.
1533 * This is useful to timeout requests. The request will be
1534 * terminated if it is currently in i/o.
1535 * Returns 1 if the request has been terminated.
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001536 * 0 if there was no need to terminate the request (not started yet)
1537 * negative error code if termination failed
1538 * Cancellation of a request is an asynchronous operation! The calling
1539 * function has to wait until the request is properly returned via callback.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001541int dasd_cancel_req(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001543 struct dasd_device *device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 unsigned long flags;
1545 int rc;
1546
1547 rc = 0;
1548 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1549 switch (cqr->status) {
1550 case DASD_CQR_QUEUED:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001551 /* request was not started - just set to cleared */
1552 cqr->status = DASD_CQR_CLEARED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 break;
1554 case DASD_CQR_IN_IO:
1555 /* request in IO - terminate IO and release again */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001556 rc = device->discipline->term_IO(cqr);
1557 if (rc) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001558 dev_err(&device->cdev->dev,
1559 "Cancelling request %p failed with rc=%d\n",
1560 cqr, rc);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001561 } else {
1562 cqr->stopclk = get_clock();
1563 rc = 1;
1564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 break;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001566 default: /* already finished or clear pending - do nothing */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 }
1569 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001570 dasd_schedule_device_bh(device);
1571 return rc;
1572}
1573
1574
1575/*
1576 * SECTION: Operations of the dasd_block layer.
1577 */
1578
1579/*
1580 * Timeout function for dasd_block. This is used when the block layer
1581 * is waiting for something that may not come reliably, (e.g. a state
1582 * change interrupt)
1583 */
1584static void dasd_block_timeout(unsigned long ptr)
1585{
1586 unsigned long flags;
1587 struct dasd_block *block;
1588
1589 block = (struct dasd_block *) ptr;
1590 spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
1591 /* re-activate request queue */
1592 block->base->stopped &= ~DASD_STOPPED_PENDING;
1593 spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
1594 dasd_schedule_block_bh(block);
1595}
1596
1597/*
1598 * Setup timeout for a dasd_block in jiffies.
1599 */
1600void dasd_block_set_timer(struct dasd_block *block, int expires)
1601{
Stefan Weinhuber48cae882009-02-11 10:37:31 +01001602 if (expires == 0)
1603 del_timer(&block->timer);
1604 else
1605 mod_timer(&block->timer, jiffies + expires);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001606}
1607
1608/*
1609 * Clear timeout for a dasd_block.
1610 */
1611void dasd_block_clear_timer(struct dasd_block *block)
1612{
Stefan Weinhuber48cae882009-02-11 10:37:31 +01001613 del_timer(&block->timer);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001614}
1615
1616/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001617 * Process finished error recovery ccw.
1618 */
1619static inline void __dasd_block_process_erp(struct dasd_block *block,
1620 struct dasd_ccw_req *cqr)
1621{
1622 dasd_erp_fn_t erp_fn;
1623 struct dasd_device *device = block->base;
1624
1625 if (cqr->status == DASD_CQR_DONE)
1626 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
1627 else
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001628 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001629 erp_fn = device->discipline->erp_postaction(cqr);
1630 erp_fn(cqr);
1631}
1632
1633/*
1634 * Fetch requests from the block device queue.
1635 */
1636static void __dasd_process_request_queue(struct dasd_block *block)
1637{
1638 struct request_queue *queue;
1639 struct request *req;
1640 struct dasd_ccw_req *cqr;
1641 struct dasd_device *basedev;
1642 unsigned long flags;
1643 queue = block->request_queue;
1644 basedev = block->base;
1645 /* No queue ? Then there is nothing to do. */
1646 if (queue == NULL)
1647 return;
1648
1649 /*
1650 * We requeue request from the block device queue to the ccw
1651 * queue only in two states. In state DASD_STATE_READY the
1652 * partition detection is done and we need to requeue requests
1653 * for that. State DASD_STATE_ONLINE is normal block device
1654 * operation.
1655 */
1656 if (basedev->state < DASD_STATE_READY)
1657 return;
1658 /* Now we try to fetch requests from the request queue */
Tejun Heo9934c8c2009-05-08 11:54:16 +09001659 while (!blk_queue_plugged(queue) && (req = blk_peek_request(queue))) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001660 if (basedev->features & DASD_FEATURE_READONLY &&
1661 rq_data_dir(req) == WRITE) {
1662 DBF_DEV_EVENT(DBF_ERR, basedev,
1663 "Rejecting write request %p",
1664 req);
Tejun Heo9934c8c2009-05-08 11:54:16 +09001665 blk_start_request(req);
Tejun Heo40cbbb72009-04-23 11:05:19 +09001666 __blk_end_request_all(req, -EIO);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001667 continue;
1668 }
1669 cqr = basedev->discipline->build_cp(basedev, block, req);
1670 if (IS_ERR(cqr)) {
1671 if (PTR_ERR(cqr) == -EBUSY)
1672 break; /* normal end condition */
1673 if (PTR_ERR(cqr) == -ENOMEM)
1674 break; /* terminate request queue loop */
1675 if (PTR_ERR(cqr) == -EAGAIN) {
1676 /*
1677 * The current request cannot be build right
1678 * now, we have to try later. If this request
1679 * is the head-of-queue we stop the device
1680 * for 1/2 second.
1681 */
1682 if (!list_empty(&block->ccw_queue))
1683 break;
1684 spin_lock_irqsave(get_ccwdev_lock(basedev->cdev), flags);
1685 basedev->stopped |= DASD_STOPPED_PENDING;
1686 spin_unlock_irqrestore(get_ccwdev_lock(basedev->cdev), flags);
1687 dasd_block_set_timer(block, HZ/2);
1688 break;
1689 }
1690 DBF_DEV_EVENT(DBF_ERR, basedev,
1691 "CCW creation failed (rc=%ld) "
1692 "on request %p",
1693 PTR_ERR(cqr), req);
Tejun Heo9934c8c2009-05-08 11:54:16 +09001694 blk_start_request(req);
Tejun Heo40cbbb72009-04-23 11:05:19 +09001695 __blk_end_request_all(req, -EIO);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001696 continue;
1697 }
1698 /*
1699 * Note: callback is set to dasd_return_cqr_cb in
1700 * __dasd_block_start_head to cover erp requests as well
1701 */
1702 cqr->callback_data = (void *) req;
1703 cqr->status = DASD_CQR_FILLED;
Tejun Heo9934c8c2009-05-08 11:54:16 +09001704 blk_start_request(req);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001705 list_add_tail(&cqr->blocklist, &block->ccw_queue);
1706 dasd_profile_start(block, cqr, req);
1707 }
1708}
1709
1710static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
1711{
1712 struct request *req;
1713 int status;
Kiyoshi Ueda4c4e2142008-01-28 10:29:42 +01001714 int error = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001715
1716 req = (struct request *) cqr->callback_data;
1717 dasd_profile_end(cqr->block, cqr, req);
Stefan Weinhuberfe6b8e72008-02-05 16:50:47 +01001718 status = cqr->block->base->discipline->free_cp(cqr, req);
Kiyoshi Ueda4c4e2142008-01-28 10:29:42 +01001719 if (status <= 0)
1720 error = status ? status : -EIO;
Tejun Heo40cbbb72009-04-23 11:05:19 +09001721 __blk_end_request_all(req, error);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001722}
1723
1724/*
1725 * Process ccw request queue.
1726 */
1727static void __dasd_process_block_ccw_queue(struct dasd_block *block,
1728 struct list_head *final_queue)
1729{
1730 struct list_head *l, *n;
1731 struct dasd_ccw_req *cqr;
1732 dasd_erp_fn_t erp_fn;
1733 unsigned long flags;
1734 struct dasd_device *base = block->base;
1735
1736restart:
1737 /* Process request with final status. */
1738 list_for_each_safe(l, n, &block->ccw_queue) {
1739 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
1740 if (cqr->status != DASD_CQR_DONE &&
1741 cqr->status != DASD_CQR_FAILED &&
1742 cqr->status != DASD_CQR_NEED_ERP &&
1743 cqr->status != DASD_CQR_TERMINATED)
1744 continue;
1745
1746 if (cqr->status == DASD_CQR_TERMINATED) {
1747 base->discipline->handle_terminated_request(cqr);
1748 goto restart;
1749 }
1750
1751 /* Process requests that may be recovered */
1752 if (cqr->status == DASD_CQR_NEED_ERP) {
Stefan Haberland6c5f57c2008-02-05 16:50:46 +01001753 erp_fn = base->discipline->erp_action(cqr);
1754 erp_fn(cqr);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001755 goto restart;
1756 }
1757
Stefan Haberlanda9cffb22008-11-14 18:18:08 +01001758 /* log sense for fatal error */
1759 if (cqr->status == DASD_CQR_FAILED) {
1760 dasd_log_sense(cqr, &cqr->irb);
1761 }
1762
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001763 /* First of all call extended error reporting. */
1764 if (dasd_eer_enabled(base) &&
1765 cqr->status == DASD_CQR_FAILED) {
1766 dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
1767
1768 /* restart request */
1769 cqr->status = DASD_CQR_FILLED;
1770 cqr->retries = 255;
1771 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
1772 base->stopped |= DASD_STOPPED_QUIESCE;
1773 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
1774 flags);
1775 goto restart;
1776 }
1777
1778 /* Process finished ERP request. */
1779 if (cqr->refers) {
1780 __dasd_block_process_erp(block, cqr);
1781 goto restart;
1782 }
1783
1784 /* Rechain finished requests to final queue */
1785 cqr->endclk = get_clock();
1786 list_move_tail(&cqr->blocklist, final_queue);
1787 }
1788}
1789
1790static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
1791{
1792 dasd_schedule_block_bh(cqr->block);
1793}
1794
1795static void __dasd_block_start_head(struct dasd_block *block)
1796{
1797 struct dasd_ccw_req *cqr;
1798
1799 if (list_empty(&block->ccw_queue))
1800 return;
1801 /* We allways begin with the first requests on the queue, as some
1802 * of previously started requests have to be enqueued on a
1803 * dasd_device again for error recovery.
1804 */
1805 list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
1806 if (cqr->status != DASD_CQR_FILLED)
1807 continue;
1808 /* Non-temporary stop condition will trigger fail fast */
1809 if (block->base->stopped & ~DASD_STOPPED_PENDING &&
1810 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
1811 (!dasd_eer_enabled(block->base))) {
1812 cqr->status = DASD_CQR_FAILED;
1813 dasd_schedule_block_bh(block);
1814 continue;
1815 }
1816 /* Don't try to start requests if device is stopped */
1817 if (block->base->stopped)
1818 return;
1819
1820 /* just a fail safe check, should not happen */
1821 if (!cqr->startdev)
1822 cqr->startdev = block->base;
1823
1824 /* make sure that the requests we submit find their way back */
1825 cqr->callback = dasd_return_cqr_cb;
1826
1827 dasd_add_request_tail(cqr);
1828 }
1829}
1830
1831/*
1832 * Central dasd_block layer routine. Takes requests from the generic
1833 * block layer request queue, creates ccw requests, enqueues them on
1834 * a dasd_device and processes ccw requests that have been returned.
1835 */
1836static void dasd_block_tasklet(struct dasd_block *block)
1837{
1838 struct list_head final_queue;
1839 struct list_head *l, *n;
1840 struct dasd_ccw_req *cqr;
1841
1842 atomic_set(&block->tasklet_scheduled, 0);
1843 INIT_LIST_HEAD(&final_queue);
1844 spin_lock(&block->queue_lock);
1845 /* Finish off requests on ccw queue */
1846 __dasd_process_block_ccw_queue(block, &final_queue);
1847 spin_unlock(&block->queue_lock);
1848 /* Now call the callback function of requests with final status */
1849 spin_lock_irq(&block->request_queue_lock);
1850 list_for_each_safe(l, n, &final_queue) {
1851 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
1852 list_del_init(&cqr->blocklist);
1853 __dasd_cleanup_cqr(cqr);
1854 }
1855 spin_lock(&block->queue_lock);
1856 /* Get new request from the block device request queue */
1857 __dasd_process_request_queue(block);
1858 /* Now check if the head of the ccw queue needs to be started. */
1859 __dasd_block_start_head(block);
1860 spin_unlock(&block->queue_lock);
1861 spin_unlock_irq(&block->request_queue_lock);
1862 dasd_put_device(block->base);
1863}
1864
1865static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
1866{
1867 wake_up(&dasd_flush_wq);
1868}
1869
1870/*
1871 * Go through all request on the dasd_block request queue, cancel them
1872 * on the respective dasd_device, and return them to the generic
1873 * block layer.
1874 */
1875static int dasd_flush_block_queue(struct dasd_block *block)
1876{
1877 struct dasd_ccw_req *cqr, *n;
1878 int rc, i;
1879 struct list_head flush_queue;
1880
1881 INIT_LIST_HEAD(&flush_queue);
1882 spin_lock_bh(&block->queue_lock);
1883 rc = 0;
1884restart:
1885 list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
1886 /* if this request currently owned by a dasd_device cancel it */
1887 if (cqr->status >= DASD_CQR_QUEUED)
1888 rc = dasd_cancel_req(cqr);
1889 if (rc < 0)
1890 break;
1891 /* Rechain request (including erp chain) so it won't be
1892 * touched by the dasd_block_tasklet anymore.
1893 * Replace the callback so we notice when the request
1894 * is returned from the dasd_device layer.
1895 */
1896 cqr->callback = _dasd_wake_block_flush_cb;
1897 for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
1898 list_move_tail(&cqr->blocklist, &flush_queue);
1899 if (i > 1)
1900 /* moved more than one request - need to restart */
1901 goto restart;
1902 }
1903 spin_unlock_bh(&block->queue_lock);
1904 /* Now call the callback function of flushed requests */
1905restart_cb:
1906 list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
1907 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
1908 /* Process finished ERP request. */
1909 if (cqr->refers) {
Stefan Haberland0cd4bd42008-12-25 13:38:54 +01001910 spin_lock_bh(&block->queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001911 __dasd_block_process_erp(block, cqr);
Stefan Haberland0cd4bd42008-12-25 13:38:54 +01001912 spin_unlock_bh(&block->queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001913 /* restart list_for_xx loop since dasd_process_erp
1914 * might remove multiple elements */
1915 goto restart_cb;
1916 }
1917 /* call the callback function */
Stefan Haberland0cd4bd42008-12-25 13:38:54 +01001918 spin_lock_irq(&block->request_queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001919 cqr->endclk = get_clock();
1920 list_del_init(&cqr->blocklist);
1921 __dasd_cleanup_cqr(cqr);
Stefan Haberland0cd4bd42008-12-25 13:38:54 +01001922 spin_unlock_irq(&block->request_queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001923 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 return rc;
1925}
1926
1927/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001928 * Schedules a call to dasd_tasklet over the device tasklet.
1929 */
1930void dasd_schedule_block_bh(struct dasd_block *block)
1931{
1932 /* Protect against rescheduling. */
1933 if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
1934 return;
1935 /* life cycle of block is bound to it's base device */
1936 dasd_get_device(block->base);
1937 tasklet_hi_schedule(&block->tasklet);
1938}
1939
1940
1941/*
1942 * SECTION: external block device operations
1943 * (request queue handling, open, release, etc.)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 */
1945
1946/*
1947 * Dasd request queue function. Called from ll_rw_blk.c
1948 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001949static void do_dasd_request(struct request_queue *queue)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001951 struct dasd_block *block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001953 block = queue->queuedata;
1954 spin_lock(&block->queue_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 /* Get new request from the block device request queue */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001956 __dasd_process_request_queue(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 /* Now check if the head of the ccw queue needs to be started. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001958 __dasd_block_start_head(block);
1959 spin_unlock(&block->queue_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960}
1961
1962/*
1963 * Allocate and initialize request queue and default I/O scheduler.
1964 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001965static int dasd_alloc_queue(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966{
1967 int rc;
1968
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001969 block->request_queue = blk_init_queue(do_dasd_request,
1970 &block->request_queue_lock);
1971 if (block->request_queue == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 return -ENOMEM;
1973
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001974 block->request_queue->queuedata = block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001976 elevator_exit(block->request_queue->elevator);
Josef 'Jeff' Sipek08a8a0c2008-04-17 07:45:56 +02001977 block->request_queue->elevator = NULL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001978 rc = elevator_init(block->request_queue, "deadline");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 if (rc) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001980 blk_cleanup_queue(block->request_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 return rc;
1982 }
1983 return 0;
1984}
1985
1986/*
1987 * Allocate and initialize request queue.
1988 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001989static void dasd_setup_queue(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990{
1991 int max;
1992
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001993 blk_queue_hardsect_size(block->request_queue, block->bp_block);
1994 max = block->base->discipline->max_blocks << block->s2b_shift;
1995 blk_queue_max_sectors(block->request_queue, max);
1996 blk_queue_max_phys_segments(block->request_queue, -1L);
1997 blk_queue_max_hw_segments(block->request_queue, -1L);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001998 /* with page sized segments we can translate each segement into
1999 * one idaw/tidaw
2000 */
2001 blk_queue_max_segment_size(block->request_queue, PAGE_SIZE);
2002 blk_queue_segment_boundary(block->request_queue, PAGE_SIZE - 1);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002003 blk_queue_ordered(block->request_queue, QUEUE_ORDERED_DRAIN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004}
2005
2006/*
2007 * Deactivate and free request queue.
2008 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002009static void dasd_free_queue(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002011 if (block->request_queue) {
2012 blk_cleanup_queue(block->request_queue);
2013 block->request_queue = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 }
2015}
2016
2017/*
2018 * Flush request on the request queue.
2019 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002020static void dasd_flush_request_queue(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021{
2022 struct request *req;
2023
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002024 if (!block->request_queue)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 return;
Horst Hummel138c0142006-06-29 14:58:12 +02002026
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002027 spin_lock_irq(&block->request_queue_lock);
Tejun Heo9934c8c2009-05-08 11:54:16 +09002028 while ((req = blk_fetch_request(block->request_queue)))
Tejun Heo40cbbb72009-04-23 11:05:19 +09002029 __blk_end_request_all(req, -EIO);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002030 spin_unlock_irq(&block->request_queue_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031}
2032
Al Viro57a7c0b2008-03-02 10:36:08 -05002033static int dasd_open(struct block_device *bdev, fmode_t mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034{
Al Viro57a7c0b2008-03-02 10:36:08 -05002035 struct dasd_block *block = bdev->bd_disk->private_data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002036 struct dasd_device *base = block->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 int rc;
2038
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002039 atomic_inc(&block->open_count);
2040 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 rc = -ENODEV;
2042 goto unlock;
2043 }
2044
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002045 if (!try_module_get(base->discipline->owner)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 rc = -EINVAL;
2047 goto unlock;
2048 }
2049
2050 if (dasd_probeonly) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002051 dev_info(&base->cdev->dev,
2052 "Accessing the DASD failed because it is in "
2053 "probeonly mode\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 rc = -EPERM;
2055 goto out;
2056 }
2057
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002058 if (base->state <= DASD_STATE_BASIC) {
2059 DBF_DEV_EVENT(DBF_ERR, base, " %s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 " Cannot open unrecognized device");
2061 rc = -ENODEV;
2062 goto out;
2063 }
2064
2065 return 0;
2066
2067out:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002068 module_put(base->discipline->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069unlock:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002070 atomic_dec(&block->open_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 return rc;
2072}
2073
Al Viro57a7c0b2008-03-02 10:36:08 -05002074static int dasd_release(struct gendisk *disk, fmode_t mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002076 struct dasd_block *block = disk->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002078 atomic_dec(&block->open_count);
2079 module_put(block->base->discipline->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 return 0;
2081}
2082
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08002083/*
2084 * Return disk geometry.
2085 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002086static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08002087{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002088 struct dasd_block *block;
2089 struct dasd_device *base;
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08002090
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002091 block = bdev->bd_disk->private_data;
2092 base = block->base;
2093 if (!block)
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08002094 return -ENODEV;
2095
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002096 if (!base->discipline ||
2097 !base->discipline->fill_geometry)
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08002098 return -EINVAL;
2099
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002100 base->discipline->fill_geometry(block, geo);
2101 geo->start = get_start_sect(bdev) >> block->s2b_shift;
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08002102 return 0;
2103}
2104
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105struct block_device_operations
2106dasd_device_operations = {
2107 .owner = THIS_MODULE,
Al Viro57a7c0b2008-03-02 10:36:08 -05002108 .open = dasd_open,
2109 .release = dasd_release,
Heiko Carstens0000d032009-03-26 15:23:45 +01002110 .ioctl = dasd_ioctl,
2111 .compat_ioctl = dasd_ioctl,
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08002112 .getgeo = dasd_getgeo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113};
2114
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002115/*******************************************************************************
2116 * end of block device operations
2117 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
2119static void
2120dasd_exit(void)
2121{
2122#ifdef CONFIG_PROC_FS
2123 dasd_proc_exit();
2124#endif
Stefan Weinhuber20c64462006-03-24 03:15:25 -08002125 dasd_eer_exit();
Horst Hummel6bb0e012005-07-27 11:45:03 -07002126 if (dasd_page_cache != NULL) {
2127 kmem_cache_destroy(dasd_page_cache);
2128 dasd_page_cache = NULL;
2129 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 dasd_gendisk_exit();
2131 dasd_devmap_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 if (dasd_debug_area != NULL) {
2133 debug_unregister(dasd_debug_area);
2134 dasd_debug_area = NULL;
2135 }
2136}
2137
2138/*
2139 * SECTION: common functions for ccw_driver use
2140 */
2141
Cornelia Huckf3445a12009-04-14 15:36:23 +02002142static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
2143{
2144 struct ccw_device *cdev = data;
2145 int ret;
2146
2147 ret = ccw_device_set_online(cdev);
2148 if (ret)
2149 pr_warning("%s: Setting the DASD online failed with rc=%d\n",
2150 dev_name(&cdev->dev), ret);
2151 else {
2152 struct dasd_device *device = dasd_device_from_cdev(cdev);
2153 wait_event(dasd_init_waitq, _wait_for_device(device));
2154 dasd_put_device(device);
2155 }
2156}
2157
Horst Hummel1c01b8a2006-01-06 00:19:15 -08002158/*
2159 * Initial attempt at a probe function. this can be simplified once
2160 * the other detection code is gone.
2161 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002162int dasd_generic_probe(struct ccw_device *cdev,
2163 struct dasd_discipline *discipline)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164{
2165 int ret;
2166
Horst Hummel40545572006-06-29 15:08:18 +02002167 ret = ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
2168 if (ret) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002169 DBF_EVENT(DBF_WARNING,
Horst Hummel40545572006-06-29 15:08:18 +02002170 "dasd_generic_probe: could not set ccw-device options "
Kay Sievers2a0217d2008-10-10 21:33:09 +02002171 "for %s\n", dev_name(&cdev->dev));
Horst Hummel40545572006-06-29 15:08:18 +02002172 return ret;
2173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 ret = dasd_add_sysfs_files(cdev);
2175 if (ret) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002176 DBF_EVENT(DBF_WARNING,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 "dasd_generic_probe: could not add sysfs entries "
Kay Sievers2a0217d2008-10-10 21:33:09 +02002178 "for %s\n", dev_name(&cdev->dev));
Horst Hummel40545572006-06-29 15:08:18 +02002179 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 }
Horst Hummel40545572006-06-29 15:08:18 +02002181 cdev->handler = &dasd_int_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
Horst Hummel40545572006-06-29 15:08:18 +02002183 /*
2184 * Automatically online either all dasd devices (dasd_autodetect)
2185 * or all devices specified with dasd= parameters during
2186 * initial probe.
2187 */
2188 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
Kay Sievers2a0217d2008-10-10 21:33:09 +02002189 (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
Cornelia Huckf3445a12009-04-14 15:36:23 +02002190 async_schedule(dasd_generic_auto_online, cdev);
Stefan Haberlandde3e0da2008-01-26 14:11:08 +01002191 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192}
2193
Horst Hummel1c01b8a2006-01-06 00:19:15 -08002194/*
2195 * This will one day be called from a global not_oper handler.
2196 * It is also used by driver_unregister during module unload.
2197 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002198void dasd_generic_remove(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199{
2200 struct dasd_device *device;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002201 struct dasd_block *block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
Horst Hummel59afda72005-05-16 21:53:39 -07002203 cdev->handler = NULL;
2204
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 dasd_remove_sysfs_files(cdev);
2206 device = dasd_device_from_cdev(cdev);
2207 if (IS_ERR(device))
2208 return;
2209 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2210 /* Already doing offline processing */
2211 dasd_put_device(device);
2212 return;
2213 }
2214 /*
2215 * This device is removed unconditionally. Set offline
2216 * flag to prevent dasd_open from opening it while it is
2217 * no quite down yet.
2218 */
2219 dasd_set_target_state(device, DASD_STATE_NEW);
2220 /* dasd_delete_device destroys the device reference. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002221 block = device->block;
2222 device->block = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 dasd_delete_device(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002224 /*
2225 * life cycle of block is bound to device, so delete it after
2226 * device was safely removed
2227 */
2228 if (block)
2229 dasd_free_block(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230}
2231
Horst Hummel1c01b8a2006-01-06 00:19:15 -08002232/*
2233 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 * the device is detected for the first time and is supposed to be used
Horst Hummel1c01b8a2006-01-06 00:19:15 -08002235 * or the user has started activation through sysfs.
2236 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002237int dasd_generic_set_online(struct ccw_device *cdev,
2238 struct dasd_discipline *base_discipline)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239{
Peter Oberparleiteraa888612006-02-20 18:28:13 -08002240 struct dasd_discipline *discipline;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 struct dasd_device *device;
Horst Hummelc6eb7b72005-09-03 15:57:58 -07002242 int rc;
Horst Hummelf24acd42005-05-01 08:58:59 -07002243
Horst Hummel40545572006-06-29 15:08:18 +02002244 /* first online clears initial online feature flag */
2245 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 device = dasd_create_device(cdev);
2247 if (IS_ERR(device))
2248 return PTR_ERR(device);
2249
Peter Oberparleiteraa888612006-02-20 18:28:13 -08002250 discipline = base_discipline;
Horst Hummelc6eb7b72005-09-03 15:57:58 -07002251 if (device->features & DASD_FEATURE_USEDIAG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 if (!dasd_diag_discipline_pointer) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002253 pr_warning("%s Setting the DASD online failed because "
2254 "of missing DIAG discipline\n",
2255 dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 dasd_delete_device(device);
2257 return -ENODEV;
2258 }
2259 discipline = dasd_diag_discipline_pointer;
2260 }
Peter Oberparleiteraa888612006-02-20 18:28:13 -08002261 if (!try_module_get(base_discipline->owner)) {
2262 dasd_delete_device(device);
2263 return -EINVAL;
2264 }
2265 if (!try_module_get(discipline->owner)) {
2266 module_put(base_discipline->owner);
2267 dasd_delete_device(device);
2268 return -EINVAL;
2269 }
2270 device->base_discipline = base_discipline;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 device->discipline = discipline;
2272
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002273 /* check_device will allocate block device if necessary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 rc = discipline->check_device(device);
2275 if (rc) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002276 pr_warning("%s Setting the DASD online with discipline %s "
2277 "failed with rc=%i\n",
2278 dev_name(&cdev->dev), discipline->name, rc);
Peter Oberparleiteraa888612006-02-20 18:28:13 -08002279 module_put(discipline->owner);
2280 module_put(base_discipline->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 dasd_delete_device(device);
2282 return rc;
2283 }
2284
2285 dasd_set_target_state(device, DASD_STATE_ONLINE);
2286 if (device->state <= DASD_STATE_KNOWN) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002287 pr_warning("%s Setting the DASD online failed because of a "
2288 "missing discipline\n", dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 rc = -ENODEV;
2290 dasd_set_target_state(device, DASD_STATE_NEW);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002291 if (device->block)
2292 dasd_free_block(device->block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 dasd_delete_device(device);
2294 } else
2295 pr_debug("dasd_generic device %s found\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +02002296 dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 dasd_put_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 return rc;
2299}
2300
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002301int dasd_generic_set_offline(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302{
2303 struct dasd_device *device;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002304 struct dasd_block *block;
Horst Hummeldafd87a2006-04-10 22:53:47 -07002305 int max_count, open_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306
2307 device = dasd_device_from_cdev(cdev);
2308 if (IS_ERR(device))
2309 return PTR_ERR(device);
2310 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2311 /* Already doing offline processing */
2312 dasd_put_device(device);
2313 return 0;
2314 }
2315 /*
2316 * We must make sure that this device is currently not in use.
2317 * The open_count is increased for every opener, that includes
2318 * the blkdev_get in dasd_scan_partitions. We are only interested
2319 * in the other openers.
2320 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002321 if (device->block) {
Heiko Carstensa8061702008-04-17 07:46:26 +02002322 max_count = device->block->bdev ? 0 : -1;
2323 open_count = atomic_read(&device->block->open_count);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002324 if (open_count > max_count) {
2325 if (open_count > 0)
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002326 pr_warning("%s: The DASD cannot be set offline "
2327 "with open count %i\n",
2328 dev_name(&cdev->dev), open_count);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002329 else
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002330 pr_warning("%s: The DASD cannot be set offline "
2331 "while it is in use\n",
2332 dev_name(&cdev->dev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002333 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
2334 dasd_put_device(device);
2335 return -EBUSY;
2336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 }
2338 dasd_set_target_state(device, DASD_STATE_NEW);
2339 /* dasd_delete_device destroys the device reference. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002340 block = device->block;
2341 device->block = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 dasd_delete_device(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002343 /*
2344 * life cycle of block is bound to device, so delete it after
2345 * device was safely removed
2346 */
2347 if (block)
2348 dasd_free_block(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 return 0;
2350}
2351
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002352int dasd_generic_notify(struct ccw_device *cdev, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353{
2354 struct dasd_device *device;
2355 struct dasd_ccw_req *cqr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 int ret;
2357
Peter Oberparleiter91c36912008-08-21 19:46:39 +02002358 device = dasd_device_from_cdev_locked(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 if (IS_ERR(device))
2360 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 ret = 0;
2362 switch (event) {
2363 case CIO_GONE:
Sebastian Ott47593bf2009-03-31 19:16:05 +02002364 case CIO_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 case CIO_NO_PATH:
Stefan Weinhuber20c64462006-03-24 03:15:25 -08002366 /* First of all call extended error reporting. */
2367 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
2368
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 if (device->state < DASD_STATE_BASIC)
2370 break;
2371 /* Device is active. We want to keep it. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002372 list_for_each_entry(cqr, &device->ccw_queue, devlist)
2373 if (cqr->status == DASD_CQR_IN_IO) {
2374 cqr->status = DASD_CQR_QUEUED;
2375 cqr->retries++;
2376 }
2377 device->stopped |= DASD_STOPPED_DC_WAIT;
2378 dasd_device_clear_timer(device);
2379 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 ret = 1;
2381 break;
2382 case CIO_OPER:
2383 /* FIXME: add a sanity check. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002384 device->stopped &= ~DASD_STOPPED_DC_WAIT;
2385 dasd_schedule_device_bh(device);
2386 if (device->block)
2387 dasd_schedule_block_bh(device->block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 ret = 1;
2389 break;
2390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 dasd_put_device(device);
2392 return ret;
2393}
2394
Heiko Carstens763968e2007-05-10 15:45:46 +02002395static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
2396 void *rdc_buffer,
2397 int rdc_buffer_size,
2398 char *magic)
Cornelia Huck17283b52007-05-04 18:47:51 +02002399{
2400 struct dasd_ccw_req *cqr;
2401 struct ccw1 *ccw;
2402
2403 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device);
2404
2405 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002406 /* internal error 13 - Allocating the RDC request failed*/
2407 dev_err(&device->cdev->dev,
2408 "An error occurred in the DASD device driver, "
2409 "reason=%s\n", "13");
Cornelia Huck17283b52007-05-04 18:47:51 +02002410 return cqr;
2411 }
2412
2413 ccw = cqr->cpaddr;
2414 ccw->cmd_code = CCW_CMD_RDC;
2415 ccw->cda = (__u32)(addr_t)rdc_buffer;
2416 ccw->count = rdc_buffer_size;
2417
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002418 cqr->startdev = device;
2419 cqr->memdev = device;
Cornelia Huck17283b52007-05-04 18:47:51 +02002420 cqr->expires = 10*HZ;
2421 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
2422 cqr->retries = 2;
2423 cqr->buildclk = get_clock();
2424 cqr->status = DASD_CQR_FILLED;
2425 return cqr;
2426}
2427
2428
2429int dasd_generic_read_dev_chars(struct dasd_device *device, char *magic,
2430 void **rdc_buffer, int rdc_buffer_size)
2431{
2432 int ret;
2433 struct dasd_ccw_req *cqr;
2434
2435 cqr = dasd_generic_build_rdc(device, *rdc_buffer, rdc_buffer_size,
2436 magic);
2437 if (IS_ERR(cqr))
2438 return PTR_ERR(cqr);
2439
2440 ret = dasd_sleep_on(cqr);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002441 dasd_sfree_request(cqr, cqr->memdev);
Cornelia Huck17283b52007-05-04 18:47:51 +02002442 return ret;
2443}
Cornelia Huckaaff0f62007-05-10 15:45:45 +02002444EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
Stefan Weinhuber20c64462006-03-24 03:15:25 -08002445
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01002446/*
2447 * In command mode and transport mode we need to look for sense
2448 * data in different places. The sense data itself is allways
2449 * an array of 32 bytes, so we can unify the sense data access
2450 * for both modes.
2451 */
2452char *dasd_get_sense(struct irb *irb)
2453{
2454 struct tsb *tsb = NULL;
2455 char *sense = NULL;
2456
2457 if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
2458 if (irb->scsw.tm.tcw)
2459 tsb = tcw_get_tsb((struct tcw *)(unsigned long)
2460 irb->scsw.tm.tcw);
2461 if (tsb && tsb->length == 64 && tsb->flags)
2462 switch (tsb->flags & 0x07) {
2463 case 1: /* tsa_iostat */
2464 sense = tsb->tsa.iostat.sense;
2465 break;
2466 case 2: /* tsa_ddpc */
2467 sense = tsb->tsa.ddpc.sense;
2468 break;
2469 default:
2470 /* currently we don't use interrogate data */
2471 break;
2472 }
2473 } else if (irb->esw.esw0.erw.cons) {
2474 sense = irb->ecw;
2475 }
2476 return sense;
2477}
2478EXPORT_SYMBOL_GPL(dasd_get_sense);
2479
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002480static int __init dasd_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481{
2482 int rc;
2483
2484 init_waitqueue_head(&dasd_init_waitq);
Horst Hummel8f617012006-08-30 14:33:33 +02002485 init_waitqueue_head(&dasd_flush_wq);
Stefan Haberlandc80ee722008-05-30 10:03:31 +02002486 init_waitqueue_head(&generic_waitq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
2488 /* register 'common' DASD debug area, used for all DBF_XXX calls */
Peter Tiedemann361f4942008-01-26 14:11:30 +01002489 dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 if (dasd_debug_area == NULL) {
2491 rc = -ENOMEM;
2492 goto failed;
2493 }
2494 debug_register_view(dasd_debug_area, &debug_sprintf_view);
Horst Hummelb0035f12006-09-20 15:59:07 +02002495 debug_set_level(dasd_debug_area, DBF_WARNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496
2497 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
2498
2499 dasd_diag_discipline_pointer = NULL;
2500
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 rc = dasd_devmap_init();
2502 if (rc)
2503 goto failed;
2504 rc = dasd_gendisk_init();
2505 if (rc)
2506 goto failed;
2507 rc = dasd_parse();
2508 if (rc)
2509 goto failed;
Stefan Weinhuber20c64462006-03-24 03:15:25 -08002510 rc = dasd_eer_init();
2511 if (rc)
2512 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513#ifdef CONFIG_PROC_FS
2514 rc = dasd_proc_init();
2515 if (rc)
2516 goto failed;
2517#endif
2518
2519 return 0;
2520failed:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002521 pr_info("The DASD device driver could not be initialized\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 dasd_exit();
2523 return rc;
2524}
2525
2526module_init(dasd_init);
2527module_exit(dasd_exit);
2528
2529EXPORT_SYMBOL(dasd_debug_area);
2530EXPORT_SYMBOL(dasd_diag_discipline_pointer);
2531
2532EXPORT_SYMBOL(dasd_add_request_head);
2533EXPORT_SYMBOL(dasd_add_request_tail);
2534EXPORT_SYMBOL(dasd_cancel_req);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002535EXPORT_SYMBOL(dasd_device_clear_timer);
2536EXPORT_SYMBOL(dasd_block_clear_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537EXPORT_SYMBOL(dasd_enable_device);
2538EXPORT_SYMBOL(dasd_int_handler);
2539EXPORT_SYMBOL(dasd_kfree_request);
2540EXPORT_SYMBOL(dasd_kick_device);
2541EXPORT_SYMBOL(dasd_kmalloc_request);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002542EXPORT_SYMBOL(dasd_schedule_device_bh);
2543EXPORT_SYMBOL(dasd_schedule_block_bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544EXPORT_SYMBOL(dasd_set_target_state);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002545EXPORT_SYMBOL(dasd_device_set_timer);
2546EXPORT_SYMBOL(dasd_block_set_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547EXPORT_SYMBOL(dasd_sfree_request);
2548EXPORT_SYMBOL(dasd_sleep_on);
2549EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2550EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2551EXPORT_SYMBOL(dasd_smalloc_request);
2552EXPORT_SYMBOL(dasd_start_IO);
2553EXPORT_SYMBOL(dasd_term_IO);
2554
2555EXPORT_SYMBOL_GPL(dasd_generic_probe);
2556EXPORT_SYMBOL_GPL(dasd_generic_remove);
2557EXPORT_SYMBOL_GPL(dasd_generic_notify);
2558EXPORT_SYMBOL_GPL(dasd_generic_set_online);
2559EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002560EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
2561EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
2562EXPORT_SYMBOL_GPL(dasd_alloc_block);
2563EXPORT_SYMBOL_GPL(dasd_free_block);