blob: 1e50626909264a8a8bb9c9636cee033eb2c816c9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
3 * Horst Hummel <Horst.Hummel@de.ibm.com>
4 * Carsten Otte <Cotte@de.ibm.com>
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Bugreports.to..: <Linux390@de.ibm.com>
Stefan Haberlandd41dd122009-06-16 10:30:25 +02007 * Copyright IBM Corp. 1999, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
Stefan Haberlandfc19f382009-03-26 15:23:49 +010010#define KMSG_COMPONENT "dasd"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/kmod.h>
14#include <linux/init.h>
15#include <linux/interrupt.h>
16#include <linux/ctype.h>
17#include <linux/major.h>
18#include <linux/slab.h>
Christoph Hellwiga885c8c2006-01-08 01:02:50 -080019#include <linux/hdreg.h>
Cornelia Huckf3445a12009-04-14 15:36:23 +020020#include <linux/async.h>
Stefan Haberland9eb25122010-02-26 22:37:46 +010021#include <linux/mutex.h>
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +020022#include <linux/debugfs.h>
23#include <linux/seq_file.h>
Stefan Weinhubere4258d52011-08-03 16:44:20 +020024#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include <asm/ccwdev.h>
27#include <asm/ebcdic.h>
28#include <asm/idals.h>
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +010029#include <asm/itcw.h>
Stefan Weinhuber33b62a32010-03-08 12:26:24 +010030#include <asm/diag.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32/* This is ugly... */
33#define PRINTK_HEADER "dasd:"
34
35#include "dasd_int.h"
36/*
37 * SECTION: Constant definitions to be used within this file
38 */
39#define DASD_CHANQ_MAX_SIZE 4
40
41/*
42 * SECTION: exported variables of dasd.c
43 */
44debug_info_t *dasd_debug_area;
Fabian Frederick7048a2b2014-06-26 19:41:47 +020045EXPORT_SYMBOL(dasd_debug_area);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +020046static struct dentry *dasd_debugfs_root_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047struct dasd_discipline *dasd_diag_discipline_pointer;
Fabian Frederick7048a2b2014-06-26 19:41:47 +020048EXPORT_SYMBOL(dasd_diag_discipline_pointer);
Heiko Carstens2b67fc42007-02-05 21:16:47 +010049void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
52MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
Heiko Carstensa53c8fa2012-07-20 11:15:04 +020053 " Copyright IBM Corp. 2000");
Linus Torvalds1da177e2005-04-16 15:20:36 -070054MODULE_SUPPORTED_DEVICE("dasd");
Linus Torvalds1da177e2005-04-16 15:20:36 -070055MODULE_LICENSE("GPL");
56
57/*
58 * SECTION: prototypes for static functions of dasd.c
59 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010060static int dasd_alloc_queue(struct dasd_block *);
61static void dasd_setup_queue(struct dasd_block *);
62static void dasd_free_queue(struct dasd_block *);
63static void dasd_flush_request_queue(struct dasd_block *);
64static int dasd_flush_block_queue(struct dasd_block *);
65static void dasd_device_tasklet(struct dasd_device *);
66static void dasd_block_tasklet(struct dasd_block *);
Al Viro4927b3f2006-12-06 19:18:20 +000067static void do_kick_device(struct work_struct *);
Stefan Haberlandd41dd122009-06-16 10:30:25 +020068static void do_restore_device(struct work_struct *);
Stefan Haberland501183f2010-05-17 10:00:10 +020069static void do_reload_device(struct work_struct *);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010070static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
Stefan Weinhuber48cae882009-02-11 10:37:31 +010071static void dasd_device_timeout(unsigned long);
72static void dasd_block_timeout(unsigned long);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +010073static void __dasd_process_erp(struct dasd_device *, struct dasd_ccw_req *);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +020074static void dasd_profile_init(struct dasd_profile *, struct dentry *);
75static void dasd_profile_exit(struct dasd_profile *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77/*
78 * SECTION: Operations on the device structure.
79 */
80static wait_queue_head_t dasd_init_waitq;
Horst Hummel8f617012006-08-30 14:33:33 +020081static wait_queue_head_t dasd_flush_wq;
Stefan Haberlandc80ee722008-05-30 10:03:31 +020082static wait_queue_head_t generic_waitq;
Stefan Haberland4679e892012-06-19 17:30:12 +020083static wait_queue_head_t shutdown_waitq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85/*
86 * Allocate memory for a new device structure.
87 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010088struct dasd_device *dasd_alloc_device(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
90 struct dasd_device *device;
91
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010092 device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
93 if (!device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96 /* Get two pages for normal block device operations. */
97 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010098 if (!device->ccw_mem) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 kfree(device);
100 return ERR_PTR(-ENOMEM);
101 }
102 /* Get one page for error recovery. */
103 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100104 if (!device->erp_mem) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 free_pages((unsigned long) device->ccw_mem, 1);
106 kfree(device);
107 return ERR_PTR(-ENOMEM);
108 }
109
110 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
111 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
112 spin_lock_init(&device->mem_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100113 atomic_set(&device->tasklet_scheduled, 0);
Horst Hummel138c0142006-06-29 14:58:12 +0200114 tasklet_init(&device->tasklet,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100115 (void (*)(unsigned long)) dasd_device_tasklet,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 (unsigned long) device);
117 INIT_LIST_HEAD(&device->ccw_queue);
118 init_timer(&device->timer);
Stefan Weinhuber48cae882009-02-11 10:37:31 +0100119 device->timer.function = dasd_device_timeout;
120 device->timer.data = (unsigned long) device;
Al Viro4927b3f2006-12-06 19:18:20 +0000121 INIT_WORK(&device->kick_work, do_kick_device);
Stefan Haberlandd41dd122009-06-16 10:30:25 +0200122 INIT_WORK(&device->restore_device, do_restore_device);
Stefan Haberland501183f2010-05-17 10:00:10 +0200123 INIT_WORK(&device->reload_device, do_reload_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 device->state = DASD_STATE_NEW;
125 device->target = DASD_STATE_NEW;
Stefan Haberland9eb25122010-02-26 22:37:46 +0100126 mutex_init(&device->state_mutex);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200127 spin_lock_init(&device->profile.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 return device;
129}
130
131/*
132 * Free memory of a device structure.
133 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100134void dasd_free_device(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
Jesper Juhl17fd6822005-11-07 01:01:30 -0800136 kfree(device->private);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 free_page((unsigned long) device->erp_mem);
138 free_pages((unsigned long) device->ccw_mem, 1);
139 kfree(device);
140}
141
142/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100143 * Allocate memory for a new device structure.
144 */
145struct dasd_block *dasd_alloc_block(void)
146{
147 struct dasd_block *block;
148
149 block = kzalloc(sizeof(*block), GFP_ATOMIC);
150 if (!block)
151 return ERR_PTR(-ENOMEM);
152 /* open_count = 0 means device online but not in use */
153 atomic_set(&block->open_count, -1);
154
155 spin_lock_init(&block->request_queue_lock);
156 atomic_set(&block->tasklet_scheduled, 0);
157 tasklet_init(&block->tasklet,
158 (void (*)(unsigned long)) dasd_block_tasklet,
159 (unsigned long) block);
160 INIT_LIST_HEAD(&block->ccw_queue);
161 spin_lock_init(&block->queue_lock);
162 init_timer(&block->timer);
Stefan Weinhuber48cae882009-02-11 10:37:31 +0100163 block->timer.function = dasd_block_timeout;
164 block->timer.data = (unsigned long) block;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200165 spin_lock_init(&block->profile.lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100166
167 return block;
168}
Fabian Frederick7048a2b2014-06-26 19:41:47 +0200169EXPORT_SYMBOL_GPL(dasd_alloc_block);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100170
171/*
172 * Free memory of a device structure.
173 */
174void dasd_free_block(struct dasd_block *block)
175{
176 kfree(block);
177}
Fabian Frederick7048a2b2014-06-26 19:41:47 +0200178EXPORT_SYMBOL_GPL(dasd_free_block);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100179
180/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 * Make a new device known to the system.
182 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100183static int dasd_state_new_to_known(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
185 int rc;
186
187 /*
Horst Hummel138c0142006-06-29 14:58:12 +0200188 * As long as the device is not in state DASD_STATE_NEW we want to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 * keep the reference count > 0.
190 */
191 dasd_get_device(device);
192
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100193 if (device->block) {
194 rc = dasd_alloc_queue(device->block);
195 if (rc) {
196 dasd_put_device(device);
197 return rc;
198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 device->state = DASD_STATE_KNOWN;
201 return 0;
202}
203
204/*
205 * Let the system forget about a device.
206 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100207static int dasd_state_known_to_new(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
Stefan Weinhuber20c64462006-03-24 03:15:25 -0800209 /* Disable extended error reporting for this device. */
210 dasd_eer_disable(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 /* Forget the discipline information. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100212 if (device->discipline) {
213 if (device->discipline->uncheck_device)
214 device->discipline->uncheck_device(device);
Peter Oberparleiteraa888612006-02-20 18:28:13 -0800215 module_put(device->discipline->owner);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100216 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 device->discipline = NULL;
Peter Oberparleiteraa888612006-02-20 18:28:13 -0800218 if (device->base_discipline)
219 module_put(device->base_discipline->owner);
220 device->base_discipline = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 device->state = DASD_STATE_NEW;
222
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100223 if (device->block)
224 dasd_free_queue(device->block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 /* Give up reference we took in dasd_state_new_to_known. */
227 dasd_put_device(device);
Horst Hummel8f617012006-08-30 14:33:33 +0200228 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229}
230
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200231static struct dentry *dasd_debugfs_setup(const char *name,
232 struct dentry *base_dentry)
233{
234 struct dentry *pde;
235
236 if (!base_dentry)
237 return NULL;
238 pde = debugfs_create_dir(name, base_dentry);
239 if (!pde || IS_ERR(pde))
240 return NULL;
241 return pde;
242}
243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244/*
245 * Request the irq line for the device.
246 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100247static int dasd_state_known_to_basic(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200249 struct dasd_block *block = device->block;
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200250 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252 /* Allocate and register gendisk structure. */
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200253 if (block) {
254 rc = dasd_gendisk_alloc(block);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100255 if (rc)
256 return rc;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200257 block->debugfs_dentry =
258 dasd_debugfs_setup(block->gdp->disk_name,
259 dasd_debugfs_root_entry);
260 dasd_profile_init(&block->profile, block->debugfs_dentry);
261 if (dasd_global_profile_level == DASD_PROFILE_ON)
262 dasd_profile_on(&device->block->profile);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100263 }
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200264 device->debugfs_dentry =
265 dasd_debugfs_setup(dev_name(&device->cdev->dev),
266 dasd_debugfs_root_entry);
267 dasd_profile_init(&device->profile, device->debugfs_dentry);
268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100270 device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100271 8 * sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 debug_register_view(device->debug_area, &debug_sprintf_view);
Horst Hummelb0035f12006-09-20 15:59:07 +0200273 debug_set_level(device->debug_area, DBF_WARNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
275
276 device->state = DASD_STATE_BASIC;
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200277
278 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279}
280
281/*
282 * Release the irq line for the device. Terminate any running i/o.
283 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100284static int dasd_state_basic_to_known(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
Horst Hummel8f617012006-08-30 14:33:33 +0200286 int rc;
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200287
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100288 if (device->block) {
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200289 dasd_profile_exit(&device->block->profile);
Fabian Frederickd7309aa2014-06-26 19:41:46 +0200290 debugfs_remove(device->block->debugfs_dentry);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100291 dasd_gendisk_free(device->block);
292 dasd_block_clear_timer(device->block);
293 }
294 rc = dasd_flush_device_queue(device);
Horst Hummel8f617012006-08-30 14:33:33 +0200295 if (rc)
296 return rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100297 dasd_device_clear_timer(device);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200298 dasd_profile_exit(&device->profile);
Fabian Frederickd7309aa2014-06-26 19:41:46 +0200299 debugfs_remove(device->debugfs_dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
301 if (device->debug_area != NULL) {
302 debug_unregister(device->debug_area);
303 device->debug_area = NULL;
304 }
305 device->state = DASD_STATE_KNOWN;
Horst Hummel8f617012006-08-30 14:33:33 +0200306 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
308
309/*
310 * Do the initial analysis. The do_analysis function may return
311 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
312 * until the discipline decides to continue the startup sequence
313 * by calling the function dasd_change_state. The eckd disciplines
314 * uses this to start a ccw that detects the format. The completion
315 * interrupt for this detection ccw uses the kernel event daemon to
316 * trigger the call to dasd_change_state. All this is done in the
317 * discipline code, see dasd_eckd.c.
Horst Hummel90f00942006-03-07 21:55:39 -0800318 * After the analysis ccw is done (do_analysis returned 0) the block
319 * device is setup.
320 * In case the analysis returns an error, the device setup is stopped
321 * (a fake disk was already added to allow formatting).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100323static int dasd_state_basic_to_ready(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
325 int rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100326 struct dasd_block *block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 rc = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100329 block = device->block;
Horst Hummel90f00942006-03-07 21:55:39 -0800330 /* make disk known with correct capacity */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100331 if (block) {
332 if (block->base->discipline->do_analysis != NULL)
333 rc = block->base->discipline->do_analysis(block);
334 if (rc) {
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200335 if (rc != -EAGAIN) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100336 device->state = DASD_STATE_UNFMT;
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200337 goto out;
338 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100339 return rc;
340 }
341 dasd_setup_queue(block);
342 set_capacity(block->gdp,
343 block->blocks << block->s2b_shift);
344 device->state = DASD_STATE_READY;
345 rc = dasd_scan_partitions(block);
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200346 if (rc) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100347 device->state = DASD_STATE_BASIC;
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200348 return rc;
349 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100350 } else {
351 device->state = DASD_STATE_READY;
352 }
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200353out:
354 if (device->discipline->basic_to_ready)
355 rc = device->discipline->basic_to_ready(device);
Horst Hummel90f00942006-03-07 21:55:39 -0800356 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
358
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +0100359static inline
360int _wait_for_empty_queues(struct dasd_device *device)
361{
362 if (device->block)
363 return list_empty(&device->ccw_queue) &&
364 list_empty(&device->block->ccw_queue);
365 else
366 return list_empty(&device->ccw_queue);
367}
368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369/*
370 * Remove device from block device layer. Destroy dirty buffers.
371 * Forget format information. Check if the target level is basic
372 * and if it is create fake disk for formatting.
373 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100374static int dasd_state_ready_to_basic(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
Horst Hummel8f617012006-08-30 14:33:33 +0200376 int rc;
377
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200378 if (device->discipline->ready_to_basic) {
379 rc = device->discipline->ready_to_basic(device);
380 if (rc)
381 return rc;
382 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 device->state = DASD_STATE_BASIC;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100384 if (device->block) {
385 struct dasd_block *block = device->block;
386 rc = dasd_flush_block_queue(block);
387 if (rc) {
388 device->state = DASD_STATE_READY;
389 return rc;
390 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100391 dasd_flush_request_queue(block);
Stefan Haberlandb695adf2010-02-26 22:37:48 +0100392 dasd_destroy_partitions(block);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100393 block->blocks = 0;
394 block->bp_block = 0;
395 block->s2b_shift = 0;
396 }
Horst Hummel8f617012006-08-30 14:33:33 +0200397 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398}
399
400/*
Horst Hummel90f00942006-03-07 21:55:39 -0800401 * Back to basic.
402 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100403static int dasd_state_unfmt_to_basic(struct dasd_device *device)
Horst Hummel90f00942006-03-07 21:55:39 -0800404{
405 device->state = DASD_STATE_BASIC;
Horst Hummel8f617012006-08-30 14:33:33 +0200406 return 0;
Horst Hummel90f00942006-03-07 21:55:39 -0800407}
408
409/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 * Make the device online and schedule the bottom half to start
411 * the requeueing of requests from the linux request queue to the
412 * ccw queue.
413 */
Horst Hummel8f617012006-08-30 14:33:33 +0200414static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415dasd_state_ready_to_online(struct dasd_device * device)
416{
Stefan Weinhuber13018092009-01-09 12:14:50 +0100417 struct gendisk *disk;
418 struct disk_part_iter piter;
419 struct hd_struct *part;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 device->state = DASD_STATE_ONLINE;
Stefan Weinhuber13018092009-01-09 12:14:50 +0100422 if (device->block) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100423 dasd_schedule_block_bh(device->block);
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100424 if ((device->features & DASD_FEATURE_USERAW)) {
425 disk = device->block->gdp;
426 kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
427 return 0;
428 }
Stefan Weinhuber13018092009-01-09 12:14:50 +0100429 disk = device->block->bdev->bd_disk;
430 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
431 while ((part = disk_part_iter_next(&piter)))
432 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
433 disk_part_iter_exit(&piter);
434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 return 0;
436}
437
438/*
439 * Stop the requeueing of requests again.
440 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100441static int dasd_state_online_to_ready(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100443 int rc;
Stefan Weinhuber13018092009-01-09 12:14:50 +0100444 struct gendisk *disk;
445 struct disk_part_iter piter;
446 struct hd_struct *part;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100447
448 if (device->discipline->online_to_ready) {
449 rc = device->discipline->online_to_ready(device);
450 if (rc)
451 return rc;
452 }
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 device->state = DASD_STATE_READY;
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100455 if (device->block && !(device->features & DASD_FEATURE_USERAW)) {
Stefan Weinhuber13018092009-01-09 12:14:50 +0100456 disk = device->block->bdev->bd_disk;
457 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
458 while ((part = disk_part_iter_next(&piter)))
459 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
460 disk_part_iter_exit(&piter);
461 }
Horst Hummel8f617012006-08-30 14:33:33 +0200462 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463}
464
465/*
466 * Device startup state changes.
467 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100468static int dasd_increase_state(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
470 int rc;
471
472 rc = 0;
473 if (device->state == DASD_STATE_NEW &&
474 device->target >= DASD_STATE_KNOWN)
475 rc = dasd_state_new_to_known(device);
476
477 if (!rc &&
478 device->state == DASD_STATE_KNOWN &&
479 device->target >= DASD_STATE_BASIC)
480 rc = dasd_state_known_to_basic(device);
481
482 if (!rc &&
483 device->state == DASD_STATE_BASIC &&
484 device->target >= DASD_STATE_READY)
485 rc = dasd_state_basic_to_ready(device);
486
487 if (!rc &&
Horst Hummel39ccf952006-04-27 18:40:10 -0700488 device->state == DASD_STATE_UNFMT &&
489 device->target > DASD_STATE_UNFMT)
490 rc = -EPERM;
491
492 if (!rc &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 device->state == DASD_STATE_READY &&
494 device->target >= DASD_STATE_ONLINE)
495 rc = dasd_state_ready_to_online(device);
496
497 return rc;
498}
499
500/*
501 * Device shutdown state changes.
502 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100503static int dasd_decrease_state(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
Horst Hummel8f617012006-08-30 14:33:33 +0200505 int rc;
506
507 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 if (device->state == DASD_STATE_ONLINE &&
509 device->target <= DASD_STATE_READY)
Horst Hummel8f617012006-08-30 14:33:33 +0200510 rc = dasd_state_online_to_ready(device);
Horst Hummel138c0142006-06-29 14:58:12 +0200511
Horst Hummel8f617012006-08-30 14:33:33 +0200512 if (!rc &&
513 device->state == DASD_STATE_READY &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 device->target <= DASD_STATE_BASIC)
Horst Hummel8f617012006-08-30 14:33:33 +0200515 rc = dasd_state_ready_to_basic(device);
Horst Hummel90f00942006-03-07 21:55:39 -0800516
Horst Hummel8f617012006-08-30 14:33:33 +0200517 if (!rc &&
518 device->state == DASD_STATE_UNFMT &&
Horst Hummel90f00942006-03-07 21:55:39 -0800519 device->target <= DASD_STATE_BASIC)
Horst Hummel8f617012006-08-30 14:33:33 +0200520 rc = dasd_state_unfmt_to_basic(device);
Horst Hummel90f00942006-03-07 21:55:39 -0800521
Horst Hummel8f617012006-08-30 14:33:33 +0200522 if (!rc &&
523 device->state == DASD_STATE_BASIC &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 device->target <= DASD_STATE_KNOWN)
Horst Hummel8f617012006-08-30 14:33:33 +0200525 rc = dasd_state_basic_to_known(device);
Horst Hummel138c0142006-06-29 14:58:12 +0200526
Horst Hummel8f617012006-08-30 14:33:33 +0200527 if (!rc &&
528 device->state == DASD_STATE_KNOWN &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 device->target <= DASD_STATE_NEW)
Horst Hummel8f617012006-08-30 14:33:33 +0200530 rc = dasd_state_known_to_new(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Horst Hummel8f617012006-08-30 14:33:33 +0200532 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533}
534
535/*
536 * This is the main startup/shutdown routine.
537 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100538static void dasd_change_state(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539{
Sebastian Ott181d9522009-06-22 12:08:21 +0200540 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 if (device->state == device->target)
543 /* Already where we want to go today... */
544 return;
545 if (device->state < device->target)
546 rc = dasd_increase_state(device);
547 else
548 rc = dasd_decrease_state(device);
Sebastian Ott181d9522009-06-22 12:08:21 +0200549 if (rc == -EAGAIN)
550 return;
551 if (rc)
552 device->target = device->state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Horst Hummel4dfd5c42007-04-27 16:01:47 +0200554 /* let user-space know that the device status changed */
555 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
Sebastian Ott1f08be82012-09-05 14:18:22 +0200556
557 if (device->state == device->target)
558 wake_up(&dasd_init_waitq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559}
560
561/*
562 * Kick starter for devices that did not complete the startup/shutdown
563 * procedure or were sleeping because of a pending state.
564 * dasd_kick_device will schedule a call do do_kick_device to the kernel
565 * event daemon.
566 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100567static void do_kick_device(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
Al Viro4927b3f2006-12-06 19:18:20 +0000569 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
Stefan Haberland9eb25122010-02-26 22:37:46 +0100570 mutex_lock(&device->state_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 dasd_change_state(device);
Stefan Haberland9eb25122010-02-26 22:37:46 +0100572 mutex_unlock(&device->state_mutex);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100573 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 dasd_put_device(device);
575}
576
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100577void dasd_kick_device(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
579 dasd_get_device(device);
580 /* queue call to dasd_kick_device to the kernel event daemon. */
581 schedule_work(&device->kick_work);
582}
Fabian Frederick7048a2b2014-06-26 19:41:47 +0200583EXPORT_SYMBOL(dasd_kick_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585/*
Stefan Haberland501183f2010-05-17 10:00:10 +0200586 * dasd_reload_device will schedule a call do do_reload_device to the kernel
587 * event daemon.
588 */
589static void do_reload_device(struct work_struct *work)
590{
591 struct dasd_device *device = container_of(work, struct dasd_device,
592 reload_device);
593 device->discipline->reload(device);
594 dasd_put_device(device);
595}
596
597void dasd_reload_device(struct dasd_device *device)
598{
599 dasd_get_device(device);
600 /* queue call to dasd_reload_device to the kernel event daemon. */
601 schedule_work(&device->reload_device);
602}
603EXPORT_SYMBOL(dasd_reload_device);
604
605/*
Stefan Haberlandd41dd122009-06-16 10:30:25 +0200606 * dasd_restore_device will schedule a call do do_restore_device to the kernel
607 * event daemon.
608 */
609static void do_restore_device(struct work_struct *work)
610{
611 struct dasd_device *device = container_of(work, struct dasd_device,
612 restore_device);
613 device->cdev->drv->restore(device->cdev);
614 dasd_put_device(device);
615}
616
617void dasd_restore_device(struct dasd_device *device)
618{
619 dasd_get_device(device);
620 /* queue call to dasd_restore_device to the kernel event daemon. */
621 schedule_work(&device->restore_device);
622}
623
624/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 * Set the target state for a device and starts the state change.
626 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100627void dasd_set_target_state(struct dasd_device *device, int target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628{
Cornelia Huckf3445a12009-04-14 15:36:23 +0200629 dasd_get_device(device);
Stefan Haberland9eb25122010-02-26 22:37:46 +0100630 mutex_lock(&device->state_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 /* If we are in probeonly mode stop at DASD_STATE_READY. */
632 if (dasd_probeonly && target > DASD_STATE_READY)
633 target = DASD_STATE_READY;
634 if (device->target != target) {
Stefan Haberland9eb25122010-02-26 22:37:46 +0100635 if (device->state == target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 wake_up(&dasd_init_waitq);
637 device->target = target;
638 }
639 if (device->state != device->target)
640 dasd_change_state(device);
Stefan Haberland9eb25122010-02-26 22:37:46 +0100641 mutex_unlock(&device->state_mutex);
642 dasd_put_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643}
Fabian Frederick7048a2b2014-06-26 19:41:47 +0200644EXPORT_SYMBOL(dasd_set_target_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646/*
647 * Enable devices with device numbers in [from..to].
648 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100649static inline int _wait_for_device(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650{
651 return (device->state == device->target);
652}
653
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100654void dasd_enable_device(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655{
656 dasd_set_target_state(device, DASD_STATE_ONLINE);
657 if (device->state <= DASD_STATE_KNOWN)
658 /* No discipline for device found. */
659 dasd_set_target_state(device, DASD_STATE_NEW);
660 /* Now wait for the devices to come up. */
661 wait_event(dasd_init_waitq, _wait_for_device(device));
Stefan Haberland25e2cf12012-03-11 11:59:37 -0400662
663 dasd_reload_device(device);
664 if (device->discipline->kick_validate)
665 device->discipline->kick_validate(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
Fabian Frederick7048a2b2014-06-26 19:41:47 +0200667EXPORT_SYMBOL(dasd_enable_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
669/*
670 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
671 */
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200672
673unsigned int dasd_global_profile_level = DASD_PROFILE_OFF;
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675#ifdef CONFIG_DASD_PROFILE
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200676struct dasd_profile_info dasd_global_profile_data;
677static struct dentry *dasd_global_profile_dentry;
678static struct dentry *dasd_debugfs_global_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
680/*
681 * Add profiling information for cqr before execution.
682 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100683static void dasd_profile_start(struct dasd_block *block,
684 struct dasd_ccw_req *cqr,
685 struct request *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
687 struct list_head *l;
688 unsigned int counter;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200689 struct dasd_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691 /* count the length of the chanq for statistics */
692 counter = 0;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200693 if (dasd_global_profile_level || block->profile.data)
694 list_for_each(l, &block->ccw_queue)
695 if (++counter >= 31)
696 break;
697
698 if (dasd_global_profile_level) {
699 dasd_global_profile_data.dasd_io_nr_req[counter]++;
700 if (rq_data_dir(req) == READ)
701 dasd_global_profile_data.dasd_read_nr_req[counter]++;
702 }
703
704 spin_lock(&block->profile.lock);
Stefan Weinhuberc81a90c2013-10-25 11:08:06 +0200705 if (block->profile.data) {
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200706 block->profile.data->dasd_io_nr_req[counter]++;
707 if (rq_data_dir(req) == READ)
708 block->profile.data->dasd_read_nr_req[counter]++;
Stefan Weinhuberc81a90c2013-10-25 11:08:06 +0200709 }
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200710 spin_unlock(&block->profile.lock);
711
712 /*
713 * We count the request for the start device, even though it may run on
714 * some other device due to error recovery. This way we make sure that
715 * we count each request only once.
716 */
717 device = cqr->startdev;
718 if (device->profile.data) {
719 counter = 1; /* request is not yet queued on the start device */
720 list_for_each(l, &device->ccw_queue)
721 if (++counter >= 31)
722 break;
723 }
724 spin_lock(&device->profile.lock);
725 if (device->profile.data) {
726 device->profile.data->dasd_io_nr_req[counter]++;
727 if (rq_data_dir(req) == READ)
728 device->profile.data->dasd_read_nr_req[counter]++;
729 }
730 spin_unlock(&device->profile.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731}
732
733/*
734 * Add profiling information for cqr after execution.
735 */
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200736
737#define dasd_profile_counter(value, index) \
738{ \
739 for (index = 0; index < 31 && value >> (2+index); index++) \
740 ; \
741}
742
743static void dasd_profile_end_add_data(struct dasd_profile_info *data,
744 int is_alias,
745 int is_tpm,
746 int is_read,
747 long sectors,
748 int sectors_ind,
749 int tottime_ind,
750 int tottimeps_ind,
751 int strtime_ind,
752 int irqtime_ind,
753 int irqtimeps_ind,
754 int endtime_ind)
755{
756 /* in case of an overflow, reset the whole profile */
757 if (data->dasd_io_reqs == UINT_MAX) {
758 memset(data, 0, sizeof(*data));
759 getnstimeofday(&data->starttod);
760 }
761 data->dasd_io_reqs++;
762 data->dasd_io_sects += sectors;
763 if (is_alias)
764 data->dasd_io_alias++;
765 if (is_tpm)
766 data->dasd_io_tpm++;
767
768 data->dasd_io_secs[sectors_ind]++;
769 data->dasd_io_times[tottime_ind]++;
770 data->dasd_io_timps[tottimeps_ind]++;
771 data->dasd_io_time1[strtime_ind]++;
772 data->dasd_io_time2[irqtime_ind]++;
773 data->dasd_io_time2ps[irqtimeps_ind]++;
774 data->dasd_io_time3[endtime_ind]++;
775
776 if (is_read) {
777 data->dasd_read_reqs++;
778 data->dasd_read_sects += sectors;
779 if (is_alias)
780 data->dasd_read_alias++;
781 if (is_tpm)
782 data->dasd_read_tpm++;
783 data->dasd_read_secs[sectors_ind]++;
784 data->dasd_read_times[tottime_ind]++;
785 data->dasd_read_time1[strtime_ind]++;
786 data->dasd_read_time2[irqtime_ind]++;
787 data->dasd_read_time3[endtime_ind]++;
788 }
789}
790
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100791static void dasd_profile_end(struct dasd_block *block,
792 struct dasd_ccw_req *cqr,
793 struct request *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794{
795 long strtime, irqtime, endtime, tottime; /* in microseconds */
796 long tottimeps, sectors;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200797 struct dasd_device *device;
798 int sectors_ind, tottime_ind, tottimeps_ind, strtime_ind;
799 int irqtime_ind, irqtimeps_ind, endtime_ind;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200801 device = cqr->startdev;
802 if (!(dasd_global_profile_level ||
803 block->profile.data ||
804 device->profile.data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 return;
806
Tejun Heo83096eb2009-05-07 22:24:39 +0900807 sectors = blk_rq_sectors(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 if (!cqr->buildclk || !cqr->startclk ||
809 !cqr->stopclk || !cqr->endclk ||
810 !sectors)
811 return;
812
813 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
814 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
815 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
816 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
817 tottimeps = tottime / sectors;
818
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200819 dasd_profile_counter(sectors, sectors_ind);
820 dasd_profile_counter(tottime, tottime_ind);
821 dasd_profile_counter(tottimeps, tottimeps_ind);
822 dasd_profile_counter(strtime, strtime_ind);
823 dasd_profile_counter(irqtime, irqtime_ind);
824 dasd_profile_counter(irqtime / sectors, irqtimeps_ind);
825 dasd_profile_counter(endtime, endtime_ind);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200827 if (dasd_global_profile_level) {
828 dasd_profile_end_add_data(&dasd_global_profile_data,
829 cqr->startdev != block->base,
830 cqr->cpmode == 1,
831 rq_data_dir(req) == READ,
832 sectors, sectors_ind, tottime_ind,
833 tottimeps_ind, strtime_ind,
834 irqtime_ind, irqtimeps_ind,
835 endtime_ind);
836 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200838 spin_lock(&block->profile.lock);
839 if (block->profile.data)
840 dasd_profile_end_add_data(block->profile.data,
841 cqr->startdev != block->base,
842 cqr->cpmode == 1,
843 rq_data_dir(req) == READ,
844 sectors, sectors_ind, tottime_ind,
845 tottimeps_ind, strtime_ind,
846 irqtime_ind, irqtimeps_ind,
847 endtime_ind);
848 spin_unlock(&block->profile.lock);
849
850 spin_lock(&device->profile.lock);
851 if (device->profile.data)
852 dasd_profile_end_add_data(device->profile.data,
853 cqr->startdev != block->base,
854 cqr->cpmode == 1,
855 rq_data_dir(req) == READ,
856 sectors, sectors_ind, tottime_ind,
857 tottimeps_ind, strtime_ind,
858 irqtime_ind, irqtimeps_ind,
859 endtime_ind);
860 spin_unlock(&device->profile.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861}
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200862
863void dasd_profile_reset(struct dasd_profile *profile)
864{
865 struct dasd_profile_info *data;
866
867 spin_lock_bh(&profile->lock);
868 data = profile->data;
869 if (!data) {
870 spin_unlock_bh(&profile->lock);
871 return;
872 }
873 memset(data, 0, sizeof(*data));
874 getnstimeofday(&data->starttod);
875 spin_unlock_bh(&profile->lock);
876}
877
878void dasd_global_profile_reset(void)
879{
880 memset(&dasd_global_profile_data, 0, sizeof(dasd_global_profile_data));
881 getnstimeofday(&dasd_global_profile_data.starttod);
882}
883
884int dasd_profile_on(struct dasd_profile *profile)
885{
886 struct dasd_profile_info *data;
887
888 data = kzalloc(sizeof(*data), GFP_KERNEL);
889 if (!data)
890 return -ENOMEM;
891 spin_lock_bh(&profile->lock);
892 if (profile->data) {
893 spin_unlock_bh(&profile->lock);
894 kfree(data);
895 return 0;
896 }
897 getnstimeofday(&data->starttod);
898 profile->data = data;
899 spin_unlock_bh(&profile->lock);
900 return 0;
901}
902
903void dasd_profile_off(struct dasd_profile *profile)
904{
905 spin_lock_bh(&profile->lock);
906 kfree(profile->data);
907 profile->data = NULL;
908 spin_unlock_bh(&profile->lock);
909}
910
911char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
912{
913 char *buffer;
914
Stefan Weinhubere4258d52011-08-03 16:44:20 +0200915 buffer = vmalloc(user_len + 1);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200916 if (buffer == NULL)
917 return ERR_PTR(-ENOMEM);
918 if (copy_from_user(buffer, user_buf, user_len) != 0) {
Stefan Weinhubere4258d52011-08-03 16:44:20 +0200919 vfree(buffer);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200920 return ERR_PTR(-EFAULT);
921 }
922 /* got the string, now strip linefeed. */
923 if (buffer[user_len - 1] == '\n')
924 buffer[user_len - 1] = 0;
925 else
926 buffer[user_len] = 0;
927 return buffer;
928}
929
930static ssize_t dasd_stats_write(struct file *file,
931 const char __user *user_buf,
932 size_t user_len, loff_t *pos)
933{
934 char *buffer, *str;
935 int rc;
936 struct seq_file *m = (struct seq_file *)file->private_data;
937 struct dasd_profile *prof = m->private;
938
939 if (user_len > 65536)
940 user_len = 65536;
941 buffer = dasd_get_user_string(user_buf, user_len);
942 if (IS_ERR(buffer))
943 return PTR_ERR(buffer);
944
945 str = skip_spaces(buffer);
946 rc = user_len;
947 if (strncmp(str, "reset", 5) == 0) {
948 dasd_profile_reset(prof);
949 } else if (strncmp(str, "on", 2) == 0) {
950 rc = dasd_profile_on(prof);
951 if (!rc)
952 rc = user_len;
953 } else if (strncmp(str, "off", 3) == 0) {
954 dasd_profile_off(prof);
955 } else
956 rc = -EINVAL;
Stefan Weinhubere4258d52011-08-03 16:44:20 +0200957 vfree(buffer);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200958 return rc;
959}
960
961static void dasd_stats_array(struct seq_file *m, unsigned int *array)
962{
963 int i;
964
965 for (i = 0; i < 32; i++)
966 seq_printf(m, "%u ", array[i]);
967 seq_putc(m, '\n');
968}
969
970static void dasd_stats_seq_print(struct seq_file *m,
971 struct dasd_profile_info *data)
972{
973 seq_printf(m, "start_time %ld.%09ld\n",
974 data->starttod.tv_sec, data->starttod.tv_nsec);
975 seq_printf(m, "total_requests %u\n", data->dasd_io_reqs);
976 seq_printf(m, "total_sectors %u\n", data->dasd_io_sects);
977 seq_printf(m, "total_pav %u\n", data->dasd_io_alias);
978 seq_printf(m, "total_hpf %u\n", data->dasd_io_tpm);
Fabian Frederickc794caf2014-06-26 19:41:49 +0200979 seq_puts(m, "histogram_sectors ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200980 dasd_stats_array(m, data->dasd_io_secs);
Fabian Frederickc794caf2014-06-26 19:41:49 +0200981 seq_puts(m, "histogram_io_times ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200982 dasd_stats_array(m, data->dasd_io_times);
Fabian Frederickc794caf2014-06-26 19:41:49 +0200983 seq_puts(m, "histogram_io_times_weighted ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200984 dasd_stats_array(m, data->dasd_io_timps);
Fabian Frederickc794caf2014-06-26 19:41:49 +0200985 seq_puts(m, "histogram_time_build_to_ssch ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200986 dasd_stats_array(m, data->dasd_io_time1);
Fabian Frederickc794caf2014-06-26 19:41:49 +0200987 seq_puts(m, "histogram_time_ssch_to_irq ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200988 dasd_stats_array(m, data->dasd_io_time2);
Fabian Frederickc794caf2014-06-26 19:41:49 +0200989 seq_puts(m, "histogram_time_ssch_to_irq_weighted ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200990 dasd_stats_array(m, data->dasd_io_time2ps);
Fabian Frederickc794caf2014-06-26 19:41:49 +0200991 seq_puts(m, "histogram_time_irq_to_end ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200992 dasd_stats_array(m, data->dasd_io_time3);
Fabian Frederickc794caf2014-06-26 19:41:49 +0200993 seq_puts(m, "histogram_ccw_queue_length ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200994 dasd_stats_array(m, data->dasd_io_nr_req);
995 seq_printf(m, "total_read_requests %u\n", data->dasd_read_reqs);
996 seq_printf(m, "total_read_sectors %u\n", data->dasd_read_sects);
997 seq_printf(m, "total_read_pav %u\n", data->dasd_read_alias);
998 seq_printf(m, "total_read_hpf %u\n", data->dasd_read_tpm);
Fabian Frederickc794caf2014-06-26 19:41:49 +0200999 seq_puts(m, "histogram_read_sectors ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001000 dasd_stats_array(m, data->dasd_read_secs);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001001 seq_puts(m, "histogram_read_times ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001002 dasd_stats_array(m, data->dasd_read_times);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001003 seq_puts(m, "histogram_read_time_build_to_ssch ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001004 dasd_stats_array(m, data->dasd_read_time1);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001005 seq_puts(m, "histogram_read_time_ssch_to_irq ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001006 dasd_stats_array(m, data->dasd_read_time2);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001007 seq_puts(m, "histogram_read_time_irq_to_end ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001008 dasd_stats_array(m, data->dasd_read_time3);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001009 seq_puts(m, "histogram_read_ccw_queue_length ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001010 dasd_stats_array(m, data->dasd_read_nr_req);
1011}
1012
1013static int dasd_stats_show(struct seq_file *m, void *v)
1014{
1015 struct dasd_profile *profile;
1016 struct dasd_profile_info *data;
1017
1018 profile = m->private;
1019 spin_lock_bh(&profile->lock);
1020 data = profile->data;
1021 if (!data) {
1022 spin_unlock_bh(&profile->lock);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001023 seq_puts(m, "disabled\n");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001024 return 0;
1025 }
1026 dasd_stats_seq_print(m, data);
1027 spin_unlock_bh(&profile->lock);
1028 return 0;
1029}
1030
1031static int dasd_stats_open(struct inode *inode, struct file *file)
1032{
1033 struct dasd_profile *profile = inode->i_private;
1034 return single_open(file, dasd_stats_show, profile);
1035}
1036
1037static const struct file_operations dasd_stats_raw_fops = {
1038 .owner = THIS_MODULE,
1039 .open = dasd_stats_open,
1040 .read = seq_read,
1041 .llseek = seq_lseek,
1042 .release = single_release,
1043 .write = dasd_stats_write,
1044};
1045
1046static ssize_t dasd_stats_global_write(struct file *file,
1047 const char __user *user_buf,
1048 size_t user_len, loff_t *pos)
1049{
1050 char *buffer, *str;
1051 ssize_t rc;
1052
1053 if (user_len > 65536)
1054 user_len = 65536;
1055 buffer = dasd_get_user_string(user_buf, user_len);
1056 if (IS_ERR(buffer))
1057 return PTR_ERR(buffer);
1058 str = skip_spaces(buffer);
1059 rc = user_len;
1060 if (strncmp(str, "reset", 5) == 0) {
1061 dasd_global_profile_reset();
1062 } else if (strncmp(str, "on", 2) == 0) {
1063 dasd_global_profile_reset();
1064 dasd_global_profile_level = DASD_PROFILE_GLOBAL_ONLY;
1065 } else if (strncmp(str, "off", 3) == 0) {
1066 dasd_global_profile_level = DASD_PROFILE_OFF;
1067 } else
1068 rc = -EINVAL;
Stefan Weinhubere4258d52011-08-03 16:44:20 +02001069 vfree(buffer);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001070 return rc;
1071}
1072
1073static int dasd_stats_global_show(struct seq_file *m, void *v)
1074{
1075 if (!dasd_global_profile_level) {
Fabian Frederickc794caf2014-06-26 19:41:49 +02001076 seq_puts(m, "disabled\n");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001077 return 0;
1078 }
1079 dasd_stats_seq_print(m, &dasd_global_profile_data);
1080 return 0;
1081}
1082
1083static int dasd_stats_global_open(struct inode *inode, struct file *file)
1084{
1085 return single_open(file, dasd_stats_global_show, NULL);
1086}
1087
1088static const struct file_operations dasd_stats_global_fops = {
1089 .owner = THIS_MODULE,
1090 .open = dasd_stats_global_open,
1091 .read = seq_read,
1092 .llseek = seq_lseek,
1093 .release = single_release,
1094 .write = dasd_stats_global_write,
1095};
1096
1097static void dasd_profile_init(struct dasd_profile *profile,
1098 struct dentry *base_dentry)
1099{
Al Virof4ae40a2011-07-24 04:33:43 -04001100 umode_t mode;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001101 struct dentry *pde;
1102
1103 if (!base_dentry)
1104 return;
1105 profile->dentry = NULL;
1106 profile->data = NULL;
1107 mode = (S_IRUSR | S_IWUSR | S_IFREG);
1108 pde = debugfs_create_file("statistics", mode, base_dentry,
1109 profile, &dasd_stats_raw_fops);
1110 if (pde && !IS_ERR(pde))
1111 profile->dentry = pde;
1112 return;
1113}
1114
1115static void dasd_profile_exit(struct dasd_profile *profile)
1116{
1117 dasd_profile_off(profile);
Fabian Frederickd7309aa2014-06-26 19:41:46 +02001118 debugfs_remove(profile->dentry);
1119 profile->dentry = NULL;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001120}
1121
1122static void dasd_statistics_removeroot(void)
1123{
1124 dasd_global_profile_level = DASD_PROFILE_OFF;
Fabian Frederickd7309aa2014-06-26 19:41:46 +02001125 debugfs_remove(dasd_global_profile_dentry);
1126 dasd_global_profile_dentry = NULL;
1127 debugfs_remove(dasd_debugfs_global_entry);
1128 debugfs_remove(dasd_debugfs_root_entry);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001129}
1130
1131static void dasd_statistics_createroot(void)
1132{
Al Virof4ae40a2011-07-24 04:33:43 -04001133 umode_t mode;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001134 struct dentry *pde;
1135
1136 dasd_debugfs_root_entry = NULL;
1137 dasd_debugfs_global_entry = NULL;
1138 dasd_global_profile_dentry = NULL;
1139 pde = debugfs_create_dir("dasd", NULL);
1140 if (!pde || IS_ERR(pde))
1141 goto error;
1142 dasd_debugfs_root_entry = pde;
1143 pde = debugfs_create_dir("global", dasd_debugfs_root_entry);
1144 if (!pde || IS_ERR(pde))
1145 goto error;
1146 dasd_debugfs_global_entry = pde;
1147
1148 mode = (S_IRUSR | S_IWUSR | S_IFREG);
1149 pde = debugfs_create_file("statistics", mode, dasd_debugfs_global_entry,
1150 NULL, &dasd_stats_global_fops);
1151 if (!pde || IS_ERR(pde))
1152 goto error;
1153 dasd_global_profile_dentry = pde;
1154 return;
1155
1156error:
1157 DBF_EVENT(DBF_ERR, "%s",
1158 "Creation of the dasd debugfs interface failed");
1159 dasd_statistics_removeroot();
1160 return;
1161}
1162
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163#else
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001164#define dasd_profile_start(block, cqr, req) do {} while (0)
1165#define dasd_profile_end(block, cqr, req) do {} while (0)
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001166
1167static void dasd_statistics_createroot(void)
1168{
1169 return;
1170}
1171
1172static void dasd_statistics_removeroot(void)
1173{
1174 return;
1175}
1176
1177int dasd_stats_generic_show(struct seq_file *m, void *v)
1178{
Fabian Frederickc794caf2014-06-26 19:41:49 +02001179 seq_puts(m, "Statistics are not activated in this kernel\n");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001180 return 0;
1181}
1182
1183static void dasd_profile_init(struct dasd_profile *profile,
1184 struct dentry *base_dentry)
1185{
1186 return;
1187}
1188
1189static void dasd_profile_exit(struct dasd_profile *profile)
1190{
1191 return;
1192}
1193
1194int dasd_profile_on(struct dasd_profile *profile)
1195{
1196 return 0;
1197}
1198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199#endif /* CONFIG_DASD_PROFILE */
1200
1201/*
1202 * Allocate memory for a channel program with 'cplength' channel
1203 * command words and 'datasize' additional space. There are two
1204 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
1205 * memory and 2) dasd_smalloc_request uses the static ccw memory
1206 * that gets allocated for each device.
1207 */
Stefan Haberland68b781f2009-09-11 10:28:29 +02001208struct dasd_ccw_req *dasd_kmalloc_request(int magic, int cplength,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001209 int datasize,
1210 struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211{
1212 struct dasd_ccw_req *cqr;
1213
1214 /* Sanity checks */
Stefan Haberland68b781f2009-09-11 10:28:29 +02001215 BUG_ON(datasize > PAGE_SIZE ||
Eric Sesterhenn7ac1e872006-03-24 18:48:13 +01001216 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08001218 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 if (cqr == NULL)
1220 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 cqr->cpaddr = NULL;
1222 if (cplength > 0) {
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08001223 cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 GFP_ATOMIC | GFP_DMA);
1225 if (cqr->cpaddr == NULL) {
1226 kfree(cqr);
1227 return ERR_PTR(-ENOMEM);
1228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 }
1230 cqr->data = NULL;
1231 if (datasize > 0) {
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08001232 cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 if (cqr->data == NULL) {
Jesper Juhl17fd6822005-11-07 01:01:30 -08001234 kfree(cqr->cpaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 kfree(cqr);
1236 return ERR_PTR(-ENOMEM);
1237 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 }
Stefan Haberland68b781f2009-09-11 10:28:29 +02001239 cqr->magic = magic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1241 dasd_get_device(device);
1242 return cqr;
1243}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001244EXPORT_SYMBOL(dasd_kmalloc_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
Stefan Haberland68b781f2009-09-11 10:28:29 +02001246struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001247 int datasize,
1248 struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
1250 unsigned long flags;
1251 struct dasd_ccw_req *cqr;
1252 char *data;
1253 int size;
1254
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
1256 if (cplength > 0)
1257 size += cplength * sizeof(struct ccw1);
1258 if (datasize > 0)
1259 size += datasize;
1260 spin_lock_irqsave(&device->mem_lock, flags);
1261 cqr = (struct dasd_ccw_req *)
1262 dasd_alloc_chunk(&device->ccw_chunks, size);
1263 spin_unlock_irqrestore(&device->mem_lock, flags);
1264 if (cqr == NULL)
1265 return ERR_PTR(-ENOMEM);
1266 memset(cqr, 0, sizeof(struct dasd_ccw_req));
1267 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
1268 cqr->cpaddr = NULL;
1269 if (cplength > 0) {
1270 cqr->cpaddr = (struct ccw1 *) data;
1271 data += cplength*sizeof(struct ccw1);
1272 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
1273 }
1274 cqr->data = NULL;
1275 if (datasize > 0) {
1276 cqr->data = data;
1277 memset(cqr->data, 0, datasize);
1278 }
Stefan Haberland68b781f2009-09-11 10:28:29 +02001279 cqr->magic = magic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1281 dasd_get_device(device);
1282 return cqr;
1283}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001284EXPORT_SYMBOL(dasd_smalloc_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
1286/*
1287 * Free memory of a channel program. This function needs to free all the
1288 * idal lists that might have been created by dasd_set_cda and the
1289 * struct dasd_ccw_req itself.
1290 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001291void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -08001293#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 struct ccw1 *ccw;
1295
1296 /* Clear any idals used for the request. */
1297 ccw = cqr->cpaddr;
1298 do {
1299 clear_normalized_cda(ccw);
1300 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
1301#endif
Jesper Juhl17fd6822005-11-07 01:01:30 -08001302 kfree(cqr->cpaddr);
1303 kfree(cqr->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 kfree(cqr);
1305 dasd_put_device(device);
1306}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001307EXPORT_SYMBOL(dasd_kfree_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001309void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310{
1311 unsigned long flags;
1312
1313 spin_lock_irqsave(&device->mem_lock, flags);
1314 dasd_free_chunk(&device->ccw_chunks, cqr);
1315 spin_unlock_irqrestore(&device->mem_lock, flags);
1316 dasd_put_device(device);
1317}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001318EXPORT_SYMBOL(dasd_sfree_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
1320/*
1321 * Check discipline magic in cqr.
1322 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001323static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324{
1325 struct dasd_device *device;
1326
1327 if (cqr == NULL)
1328 return -EINVAL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001329 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001331 DBF_DEV_EVENT(DBF_WARNING, device,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 " dasd_ccw_req 0x%08x magic doesn't match"
1333 " discipline 0x%08x",
1334 cqr->magic,
1335 *(unsigned int *) device->discipline->name);
1336 return -EINVAL;
1337 }
1338 return 0;
1339}
1340
1341/*
1342 * Terminate the current i/o and set the request to clear_pending.
1343 * Timer keeps device runnig.
1344 * ccw_device_clear can fail if the i/o subsystem
1345 * is in a bad mood.
1346 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001347int dasd_term_IO(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348{
1349 struct dasd_device *device;
1350 int retries, rc;
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001351 char errorstring[ERRORLENGTH];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
1353 /* Check the cqr */
1354 rc = dasd_check_cqr(cqr);
1355 if (rc)
1356 return rc;
1357 retries = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001358 device = (struct dasd_device *) cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
1360 rc = ccw_device_clear(device->cdev, (long) cqr);
1361 switch (rc) {
1362 case 0: /* termination successful */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001363 cqr->status = DASD_CQR_CLEAR_PENDING;
Heiko Carstens1aae0562013-01-30 09:49:40 +01001364 cqr->stopclk = get_tod_clock();
Horst Hummel8f617012006-08-30 14:33:33 +02001365 cqr->starttime = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 DBF_DEV_EVENT(DBF_DEBUG, device,
1367 "terminate cqr %p successful",
1368 cqr);
1369 break;
1370 case -ENODEV:
1371 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1372 "device gone, retry");
1373 break;
1374 case -EIO:
1375 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1376 "I/O error, retry");
1377 break;
1378 case -EINVAL:
1379 case -EBUSY:
1380 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1381 "device busy, retry later");
1382 break;
1383 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001384 /* internal error 10 - unknown rc*/
1385 snprintf(errorstring, ERRORLENGTH, "10 %d", rc);
1386 dev_err(&device->cdev->dev, "An error occurred in the "
1387 "DASD device driver, reason=%s\n", errorstring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 BUG();
1389 break;
1390 }
1391 retries++;
1392 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001393 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 return rc;
1395}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001396EXPORT_SYMBOL(dasd_term_IO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
1398/*
1399 * Start the i/o. This start_IO can fail if the channel is really busy.
1400 * In that case set up a timer to start the request later.
1401 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001402int dasd_start_IO(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403{
1404 struct dasd_device *device;
1405 int rc;
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001406 char errorstring[ERRORLENGTH];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
1408 /* Check the cqr */
1409 rc = dasd_check_cqr(cqr);
Stefan Weinhuber6cc7f162009-06-12 10:26:39 +02001410 if (rc) {
1411 cqr->intrc = rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 return rc;
Stefan Weinhuber6cc7f162009-06-12 10:26:39 +02001413 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001414 device = (struct dasd_device *) cqr->startdev;
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001415 if (((cqr->block &&
1416 test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) ||
1417 test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
1418 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
1419 DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
1420 "because of stolen lock", cqr);
1421 cqr->status = DASD_CQR_ERROR;
1422 cqr->intrc = -EPERM;
1423 return -EPERM;
1424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 if (cqr->retries < 0) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001426 /* internal error 14 - start_IO run out of retries */
1427 sprintf(errorstring, "14 %p", cqr);
1428 dev_err(&device->cdev->dev, "An error occurred in the DASD "
1429 "device driver, reason=%s\n", errorstring);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001430 cqr->status = DASD_CQR_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 return -EIO;
1432 }
Heiko Carstens1aae0562013-01-30 09:49:40 +01001433 cqr->startclk = get_tod_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 cqr->starttime = jiffies;
1435 cqr->retries--;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001436 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1437 cqr->lpm &= device->path_data.opm;
1438 if (!cqr->lpm)
1439 cqr->lpm = device->path_data.opm;
1440 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001441 if (cqr->cpmode == 1) {
1442 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
1443 (long) cqr, cqr->lpm);
1444 } else {
1445 rc = ccw_device_start(device->cdev, cqr->cpaddr,
1446 (long) cqr, cqr->lpm, 0);
1447 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 switch (rc) {
1449 case 0:
1450 cqr->status = DASD_CQR_IN_IO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 break;
1452 case -EBUSY:
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001453 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 "start_IO: device busy, retry later");
1455 break;
1456 case -ETIMEDOUT:
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001457 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 "start_IO: request timeout, retry later");
1459 break;
1460 case -EACCES:
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001461 /* -EACCES indicates that the request used only a subset of the
1462 * available paths and all these paths are gone. If the lpm of
1463 * this request was only a subset of the opm (e.g. the ppm) then
1464 * we just do a retry with all available paths.
1465 * If we already use the full opm, something is amiss, and we
1466 * need a full path verification.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 */
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001468 if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1469 DBF_DEV_EVENT(DBF_WARNING, device,
1470 "start_IO: selected paths gone (%x)",
1471 cqr->lpm);
1472 } else if (cqr->lpm != device->path_data.opm) {
1473 cqr->lpm = device->path_data.opm;
1474 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
1475 "start_IO: selected paths gone,"
1476 " retry on all paths");
1477 } else {
1478 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1479 "start_IO: all paths in opm gone,"
1480 " do path verification");
1481 dasd_generic_last_path_gone(device);
1482 device->path_data.opm = 0;
1483 device->path_data.ppm = 0;
1484 device->path_data.npm = 0;
1485 device->path_data.tbvpm =
1486 ccw_device_get_path_mask(device->cdev);
1487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 break;
1489 case -ENODEV:
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001490 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001491 "start_IO: -ENODEV device gone, retry");
1492 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 case -EIO:
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001494 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001495 "start_IO: -EIO device gone, retry");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 break;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02001497 case -EINVAL:
1498 /* most likely caused in power management context */
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001499 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Stefan Haberlandd41dd122009-06-16 10:30:25 +02001500 "start_IO: -EINVAL device currently "
1501 "not accessible");
1502 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001504 /* internal error 11 - unknown rc */
1505 snprintf(errorstring, ERRORLENGTH, "11 %d", rc);
1506 dev_err(&device->cdev->dev,
1507 "An error occurred in the DASD device driver, "
1508 "reason=%s\n", errorstring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 BUG();
1510 break;
1511 }
Stefan Weinhuber6cc7f162009-06-12 10:26:39 +02001512 cqr->intrc = rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 return rc;
1514}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001515EXPORT_SYMBOL(dasd_start_IO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
1517/*
1518 * Timeout function for dasd devices. This is used for different purposes
1519 * 1) missing interrupt handler for normal operation
1520 * 2) delayed start of request where start_IO failed with -EBUSY
1521 * 3) timeout for missing state change interrupts
1522 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1523 * DASD_CQR_QUEUED for 2) and 3).
1524 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001525static void dasd_device_timeout(unsigned long ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
1527 unsigned long flags;
1528 struct dasd_device *device;
1529
1530 device = (struct dasd_device *) ptr;
1531 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1532 /* re-activate request queue */
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001533 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001535 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536}
1537
1538/*
1539 * Setup timeout for a device in jiffies.
1540 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001541void dasd_device_set_timer(struct dasd_device *device, int expires)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542{
Stefan Weinhuber48cae882009-02-11 10:37:31 +01001543 if (expires == 0)
1544 del_timer(&device->timer);
1545 else
1546 mod_timer(&device->timer, jiffies + expires);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001548EXPORT_SYMBOL(dasd_device_set_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
1550/*
1551 * Clear timeout for a device.
1552 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001553void dasd_device_clear_timer(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554{
Stefan Weinhuber48cae882009-02-11 10:37:31 +01001555 del_timer(&device->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001557EXPORT_SYMBOL(dasd_device_clear_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001559static void dasd_handle_killed_request(struct ccw_device *cdev,
1560 unsigned long intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
1562 struct dasd_ccw_req *cqr;
1563 struct dasd_device *device;
1564
Stefan Weinhuberf16f5842008-05-15 16:52:36 +02001565 if (!intparm)
1566 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 cqr = (struct dasd_ccw_req *) intparm;
1568 if (cqr->status != DASD_CQR_IN_IO) {
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01001569 DBF_EVENT_DEVID(DBF_DEBUG, cdev,
1570 "invalid status in handle_killed_request: "
1571 "%02x", cqr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 return;
1573 }
1574
Stefan Haberland589c74d2010-02-26 22:37:47 +01001575 device = dasd_device_from_cdev_locked(cdev);
1576 if (IS_ERR(device)) {
1577 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1578 "unable to get device from cdev");
1579 return;
1580 }
1581
1582 if (!cqr->startdev ||
1583 device != cqr->startdev ||
1584 strncmp(cqr->startdev->discipline->ebcname,
1585 (char *) &cqr->magic, 4)) {
Stefan Haberland294001a2010-01-27 10:12:35 +01001586 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1587 "invalid device in request");
Stefan Haberland589c74d2010-02-26 22:37:47 +01001588 dasd_put_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 return;
1590 }
1591
1592 /* Schedule request to be retried. */
1593 cqr->status = DASD_CQR_QUEUED;
1594
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001595 dasd_device_clear_timer(device);
1596 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 dasd_put_device(device);
1598}
1599
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001600void dasd_generic_handle_state_change(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601{
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001602 /* First of all start sense subsystem status request. */
1603 dasd_eer_snss(device);
1604
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001605 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001606 dasd_schedule_device_bh(device);
1607 if (device->block)
1608 dasd_schedule_block_bh(device->block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001610EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612/*
1613 * Interrupt handler for "normal" ssch-io based dasd devices.
1614 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001615void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1616 struct irb *irb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617{
1618 struct dasd_ccw_req *cqr, *next;
1619 struct dasd_device *device;
1620 unsigned long long now;
1621 int expires;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
1623 if (IS_ERR(irb)) {
1624 switch (PTR_ERR(irb)) {
1625 case -EIO:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 break;
1627 case -ETIMEDOUT:
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01001628 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1629 "request timed out\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 break;
1631 default:
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01001632 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1633 "unknown error %ld\n", __func__,
1634 PTR_ERR(irb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 }
Stefan Weinhuberf16f5842008-05-15 16:52:36 +02001636 dasd_handle_killed_request(cdev, intparm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 return;
1638 }
1639
Heiko Carstens1aae0562013-01-30 09:49:40 +01001640 now = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001641 cqr = (struct dasd_ccw_req *) intparm;
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001642 /* check for conditions that should be handled immediately */
1643 if (!cqr ||
1644 !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1645 scsw_cstat(&irb->scsw) == 0)) {
Stefan Weinhubera5a00612010-10-25 16:10:47 +02001646 if (cqr)
1647 memcpy(&cqr->irb, irb, sizeof(*irb));
Martin Schwidefskya00bfd72006-09-20 15:59:05 +02001648 device = dasd_device_from_cdev_locked(cdev);
Stefan Haberland56b86b62010-10-25 16:10:49 +02001649 if (IS_ERR(device))
1650 return;
1651 /* ignore unsolicited interrupts for DIAG discipline */
1652 if (device->discipline == dasd_diag_discipline_pointer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 dasd_put_device(device);
Stefan Haberland56b86b62010-10-25 16:10:49 +02001654 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 }
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001656 device->discipline->dump_sense_dbf(device, irb, "int");
1657 if (device->features & DASD_FEATURE_ERPLOG)
1658 device->discipline->dump_sense(device, cqr, irb);
1659 device->discipline->check_for_device_change(device, cqr, irb);
Stefan Haberland56b86b62010-10-25 16:10:49 +02001660 dasd_put_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 }
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001662 if (!cqr)
1663 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001665 device = (struct dasd_device *) cqr->startdev;
1666 if (!device ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
Stefan Haberland294001a2010-01-27 10:12:35 +01001668 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1669 "invalid device in request");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 return;
1671 }
1672
1673 /* Check for clear pending */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001674 if (cqr->status == DASD_CQR_CLEAR_PENDING &&
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001675 scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001676 cqr->status = DASD_CQR_CLEARED;
1677 dasd_device_clear_timer(device);
Horst Hummel8f617012006-08-30 14:33:33 +02001678 wake_up(&dasd_flush_wq);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001679 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 return;
1681 }
1682
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001683 /* check status - the request might have been killed by dyn detach */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 if (cqr->status != DASD_CQR_IN_IO) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001685 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1686 "status %02x", dev_name(&cdev->dev), cqr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 return;
1688 }
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001689
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001690 next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 expires = 0;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001692 if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1693 scsw_cstat(&irb->scsw) == 0) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001694 /* request was completed successfully */
1695 cqr->status = DASD_CQR_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 cqr->stopclk = now;
1697 /* Start first request on queue if possible -> fast_io. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001698 if (cqr->devlist.next != &device->ccw_queue) {
1699 next = list_entry(cqr->devlist.next,
1700 struct dasd_ccw_req, devlist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001702 } else { /* error */
Stefan Haberland6c5f57c2008-02-05 16:50:46 +01001703 /*
1704 * If we don't want complex ERP for this request, then just
1705 * reset this and retry it in the fastpath
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001706 */
Stefan Haberland6c5f57c2008-02-05 16:50:46 +01001707 if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001708 cqr->retries > 0) {
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001709 if (cqr->lpm == device->path_data.opm)
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001710 DBF_DEV_EVENT(DBF_DEBUG, device,
1711 "default ERP in fastpath "
1712 "(%i retries left)",
1713 cqr->retries);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001714 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
1715 cqr->lpm = device->path_data.opm;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001716 cqr->status = DASD_CQR_QUEUED;
1717 next = cqr;
1718 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 cqr->status = DASD_CQR_ERROR;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001720 }
1721 if (next && (next->status == DASD_CQR_QUEUED) &&
1722 (!device->stopped)) {
1723 if (device->discipline->start_IO(next) == 0)
1724 expires = next->expires;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 }
1726 if (expires != 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001727 dasd_device_set_timer(device, expires);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 else
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001729 dasd_device_clear_timer(device);
1730 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001732EXPORT_SYMBOL(dasd_int_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
Stefan Haberlanda23ed002010-05-26 23:27:09 +02001734enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb)
1735{
1736 struct dasd_device *device;
1737
1738 device = dasd_device_from_cdev_locked(cdev);
1739
1740 if (IS_ERR(device))
1741 goto out;
1742 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1743 device->state != device->target ||
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001744 !device->discipline->check_for_device_change){
Stefan Haberlanda23ed002010-05-26 23:27:09 +02001745 dasd_put_device(device);
1746 goto out;
1747 }
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001748 if (device->discipline->dump_sense_dbf)
1749 device->discipline->dump_sense_dbf(device, irb, "uc");
1750 device->discipline->check_for_device_change(device, NULL, irb);
Stefan Haberlanda23ed002010-05-26 23:27:09 +02001751 dasd_put_device(device);
1752out:
1753 return UC_TODO_RETRY;
1754}
1755EXPORT_SYMBOL_GPL(dasd_generic_uc_handler);
1756
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001758 * If we have an error on a dasd_block layer request then we cancel
1759 * and return all further requests from the same dasd_block as well.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001761static void __dasd_device_recovery(struct dasd_device *device,
1762 struct dasd_ccw_req *ref_cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763{
1764 struct list_head *l, *n;
1765 struct dasd_ccw_req *cqr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
1767 /*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001768 * only requeue request that came from the dasd_block layer
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001770 if (!ref_cqr->block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 return;
Horst Hummelf24acd42005-05-01 08:58:59 -07001772
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001773 list_for_each_safe(l, n, &device->ccw_queue) {
1774 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1775 if (cqr->status == DASD_CQR_QUEUED &&
1776 ref_cqr->block == cqr->block) {
1777 cqr->status = DASD_CQR_CLEARED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001779 }
1780};
1781
1782/*
1783 * Remove those ccw requests from the queue that need to be returned
1784 * to the upper layer.
1785 */
1786static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1787 struct list_head *final_queue)
1788{
1789 struct list_head *l, *n;
1790 struct dasd_ccw_req *cqr;
1791
1792 /* Process request with final status. */
1793 list_for_each_safe(l, n, &device->ccw_queue) {
1794 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1795
Hannes Reinecke1fbdb8b2013-01-30 09:26:13 +00001796 /* Skip any non-final request. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001797 if (cqr->status == DASD_CQR_QUEUED ||
1798 cqr->status == DASD_CQR_IN_IO ||
1799 cqr->status == DASD_CQR_CLEAR_PENDING)
Hannes Reinecke1fbdb8b2013-01-30 09:26:13 +00001800 continue;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001801 if (cqr->status == DASD_CQR_ERROR) {
1802 __dasd_device_recovery(device, cqr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001804 /* Rechain finished requests to final queue */
1805 list_move_tail(&cqr->devlist, final_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 }
1807}
1808
1809/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001810 * the cqrs from the final queue are returned to the upper layer
1811 * by setting a dasd_block state and calling the callback function
1812 */
1813static void __dasd_device_process_final_queue(struct dasd_device *device,
1814 struct list_head *final_queue)
1815{
1816 struct list_head *l, *n;
1817 struct dasd_ccw_req *cqr;
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001818 struct dasd_block *block;
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001819 void (*callback)(struct dasd_ccw_req *, void *data);
1820 void *callback_data;
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001821 char errorstring[ERRORLENGTH];
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001822
1823 list_for_each_safe(l, n, final_queue) {
1824 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1825 list_del_init(&cqr->devlist);
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001826 block = cqr->block;
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001827 callback = cqr->callback;
1828 callback_data = cqr->callback_data;
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001829 if (block)
1830 spin_lock_bh(&block->queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001831 switch (cqr->status) {
1832 case DASD_CQR_SUCCESS:
1833 cqr->status = DASD_CQR_DONE;
1834 break;
1835 case DASD_CQR_ERROR:
1836 cqr->status = DASD_CQR_NEED_ERP;
1837 break;
1838 case DASD_CQR_CLEARED:
1839 cqr->status = DASD_CQR_TERMINATED;
1840 break;
1841 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001842 /* internal error 12 - wrong cqr status*/
1843 snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status);
1844 dev_err(&device->cdev->dev,
1845 "An error occurred in the DASD device driver, "
1846 "reason=%s\n", errorstring);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001847 BUG();
1848 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001849 if (cqr->callback != NULL)
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001850 (callback)(cqr, callback_data);
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001851 if (block)
1852 spin_unlock_bh(&block->queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001853 }
1854}
1855
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001856/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 * Take a look at the first request on the ccw queue and check
1858 * if it reached its expire time. If so, terminate the IO.
1859 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001860static void __dasd_device_check_expire(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861{
1862 struct dasd_ccw_req *cqr;
1863
1864 if (list_empty(&device->ccw_queue))
1865 return;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001866 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
Horst Hummel29145a62006-12-04 15:40:15 +01001867 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1868 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01001869 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1870 /*
1871 * IO in safe offline processing should not
1872 * run out of retries
1873 */
1874 cqr->retries++;
1875 }
Horst Hummel29145a62006-12-04 15:40:15 +01001876 if (device->discipline->term_IO(cqr) != 0) {
1877 /* Hmpf, try again in 5 sec */
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001878 dev_err(&device->cdev->dev,
Heiko Carstens625c94d2010-08-13 10:06:38 +02001879 "cqr %p timed out (%lus) but cannot be "
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001880 "ended, retrying in 5 s\n",
1881 cqr, (cqr->expires/HZ));
Stefan Haberland7dc1da92008-01-26 14:11:26 +01001882 cqr->expires += 5*HZ;
1883 dasd_device_set_timer(device, 5*HZ);
Horst Hummel29145a62006-12-04 15:40:15 +01001884 } else {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001885 dev_err(&device->cdev->dev,
Heiko Carstens625c94d2010-08-13 10:06:38 +02001886 "cqr %p timed out (%lus), %i retries "
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001887 "remaining\n", cqr, (cqr->expires/HZ),
1888 cqr->retries);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 }
1890 }
1891}
1892
1893/*
1894 * Take a look at the first request on the ccw queue and check
1895 * if it needs to be started.
1896 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001897static void __dasd_device_start_head(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898{
1899 struct dasd_ccw_req *cqr;
1900 int rc;
1901
1902 if (list_empty(&device->ccw_queue))
1903 return;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001904 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07001905 if (cqr->status != DASD_CQR_QUEUED)
1906 return;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001907 /* when device is stopped, return request to previous layer
1908 * exception: only the disconnect or unresumed bits are set and the
1909 * cqr is a path verification request
1910 */
1911 if (device->stopped &&
1912 !(!(device->stopped & ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM))
1913 && test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))) {
1914 cqr->intrc = -EAGAIN;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001915 cqr->status = DASD_CQR_CLEARED;
1916 dasd_schedule_device_bh(device);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07001917 return;
Horst Hummel1c01b8a2006-01-06 00:19:15 -08001918 }
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07001919
1920 rc = device->discipline->start_IO(cqr);
1921 if (rc == 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001922 dasd_device_set_timer(device, cqr->expires);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07001923 else if (rc == -EACCES) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001924 dasd_schedule_device_bh(device);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07001925 } else
1926 /* Hmpf, try again in 1/2 sec */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001927 dasd_device_set_timer(device, 50);
Horst Hummel8f617012006-08-30 14:33:33 +02001928}
1929
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001930static void __dasd_device_check_path_events(struct dasd_device *device)
1931{
1932 int rc;
1933
1934 if (device->path_data.tbvpm) {
1935 if (device->stopped & ~(DASD_STOPPED_DC_WAIT |
1936 DASD_UNRESUMED_PM))
1937 return;
1938 rc = device->discipline->verify_path(
1939 device, device->path_data.tbvpm);
1940 if (rc)
1941 dasd_device_set_timer(device, 50);
1942 else
1943 device->path_data.tbvpm = 0;
1944 }
1945};
1946
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001948 * Go through all request on the dasd_device request queue,
1949 * terminate them on the cdev if necessary, and return them to the
1950 * submitting layer via callback.
1951 * Note:
1952 * Make sure that all 'submitting layers' still exist when
1953 * this function is called!. In other words, when 'device' is a base
1954 * device then all block layer requests must have been removed before
1955 * via dasd_flush_block_queue.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001957int dasd_flush_device_queue(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001959 struct dasd_ccw_req *cqr, *n;
1960 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 struct list_head flush_queue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
1963 INIT_LIST_HEAD(&flush_queue);
1964 spin_lock_irq(get_ccwdev_lock(device->cdev));
Horst Hummel8f617012006-08-30 14:33:33 +02001965 rc = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001966 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
Horst Hummel8f617012006-08-30 14:33:33 +02001967 /* Check status and move request to flush_queue */
1968 switch (cqr->status) {
1969 case DASD_CQR_IN_IO:
1970 rc = device->discipline->term_IO(cqr);
1971 if (rc) {
1972 /* unable to terminate requeust */
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001973 dev_err(&device->cdev->dev,
1974 "Flushing the DASD request queue "
1975 "failed for request %p\n", cqr);
Horst Hummel8f617012006-08-30 14:33:33 +02001976 /* stop flush processing */
1977 goto finished;
1978 }
1979 break;
1980 case DASD_CQR_QUEUED:
Heiko Carstens1aae0562013-01-30 09:49:40 +01001981 cqr->stopclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001982 cqr->status = DASD_CQR_CLEARED;
Horst Hummel8f617012006-08-30 14:33:33 +02001983 break;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001984 default: /* no need to modify the others */
Horst Hummel8f617012006-08-30 14:33:33 +02001985 break;
1986 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001987 list_move_tail(&cqr->devlist, &flush_queue);
Horst Hummel8f617012006-08-30 14:33:33 +02001988 }
Horst Hummel8f617012006-08-30 14:33:33 +02001989finished:
1990 spin_unlock_irq(get_ccwdev_lock(device->cdev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001991 /*
1992 * After this point all requests must be in state CLEAR_PENDING,
1993 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
1994 * one of the others.
1995 */
1996 list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
1997 wait_event(dasd_flush_wq,
1998 (cqr->status != DASD_CQR_CLEAR_PENDING));
1999 /*
2000 * Now set each request back to TERMINATED, DONE or NEED_ERP
2001 * and call the callback function of flushed requests
2002 */
2003 __dasd_device_process_final_queue(device, &flush_queue);
Horst Hummel8f617012006-08-30 14:33:33 +02002004 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002006EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007
2008/*
2009 * Acquire the device lock and process queues for the device.
2010 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002011static void dasd_device_tasklet(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012{
2013 struct list_head final_queue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014
2015 atomic_set (&device->tasklet_scheduled, 0);
2016 INIT_LIST_HEAD(&final_queue);
2017 spin_lock_irq(get_ccwdev_lock(device->cdev));
2018 /* Check expire time of first request on the ccw queue. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002019 __dasd_device_check_expire(device);
2020 /* find final requests on ccw queue */
2021 __dasd_device_process_ccw_queue(device, &final_queue);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01002022 __dasd_device_check_path_events(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2024 /* Now call the callback function of requests with final status */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002025 __dasd_device_process_final_queue(device, &final_queue);
2026 spin_lock_irq(get_ccwdev_lock(device->cdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 /* Now check if the head of the ccw queue needs to be started. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002028 __dasd_device_start_head(device);
2029 spin_unlock_irq(get_ccwdev_lock(device->cdev));
Stefan Haberland4679e892012-06-19 17:30:12 +02002030 if (waitqueue_active(&shutdown_waitq))
2031 wake_up(&shutdown_waitq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 dasd_put_device(device);
2033}
2034
2035/*
2036 * Schedules a call to dasd_tasklet over the device tasklet.
2037 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002038void dasd_schedule_device_bh(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039{
2040 /* Protect against rescheduling. */
Martin Schwidefsky973bd992006-01-06 00:19:07 -08002041 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 return;
2043 dasd_get_device(device);
2044 tasklet_hi_schedule(&device->tasklet);
2045}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002046EXPORT_SYMBOL(dasd_schedule_device_bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002048void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
2049{
2050 device->stopped |= bits;
2051}
2052EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits);
2053
2054void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
2055{
2056 device->stopped &= ~bits;
2057 if (!device->stopped)
2058 wake_up(&generic_waitq);
2059}
2060EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits);
2061
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002063 * Queue a request to the head of the device ccw_queue.
2064 * Start the I/O if possible.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002066void dasd_add_request_head(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067{
2068 struct dasd_device *device;
2069 unsigned long flags;
2070
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002071 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002073 cqr->status = DASD_CQR_QUEUED;
2074 list_add(&cqr->devlist, &device->ccw_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 /* let the bh start the request to keep them in order */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002076 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2078}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002079EXPORT_SYMBOL(dasd_add_request_head);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
2081/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002082 * Queue a request to the tail of the device ccw_queue.
2083 * Start the I/O if possible.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002085void dasd_add_request_tail(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086{
2087 struct dasd_device *device;
2088 unsigned long flags;
2089
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002090 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002092 cqr->status = DASD_CQR_QUEUED;
2093 list_add_tail(&cqr->devlist, &device->ccw_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 /* let the bh start the request to keep them in order */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002095 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2097}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002098EXPORT_SYMBOL(dasd_add_request_tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
2100/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002101 * Wakeup helper for the 'sleep_on' functions.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 */
Stefan Haberland5915a872011-10-30 15:16:57 +01002103void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104{
Stefan Weinhuber1c1e0932010-05-12 09:32:11 +02002105 spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2106 cqr->callback_data = DASD_SLEEPON_END_TAG;
2107 spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2108 wake_up(&generic_waitq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109}
Stefan Haberland5915a872011-10-30 15:16:57 +01002110EXPORT_SYMBOL_GPL(dasd_wakeup_cb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002112static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
2114 struct dasd_device *device;
2115 int rc;
2116
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002117 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 spin_lock_irq(get_ccwdev_lock(device->cdev));
Stefan Weinhuber1c1e0932010-05-12 09:32:11 +02002119 rc = (cqr->callback_data == DASD_SLEEPON_END_TAG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2121 return rc;
2122}
2123
2124/*
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002125 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2126 */
2127static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr)
2128{
2129 struct dasd_device *device;
2130 dasd_erp_fn_t erp_fn;
2131
2132 if (cqr->status == DASD_CQR_FILLED)
2133 return 0;
2134 device = cqr->startdev;
2135 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2136 if (cqr->status == DASD_CQR_TERMINATED) {
2137 device->discipline->handle_terminated_request(cqr);
2138 return 1;
2139 }
2140 if (cqr->status == DASD_CQR_NEED_ERP) {
2141 erp_fn = device->discipline->erp_action(cqr);
2142 erp_fn(cqr);
2143 return 1;
2144 }
2145 if (cqr->status == DASD_CQR_FAILED)
2146 dasd_log_sense(cqr, &cqr->irb);
2147 if (cqr->refers) {
2148 __dasd_process_erp(device, cqr);
2149 return 1;
2150 }
2151 }
2152 return 0;
2153}
2154
2155static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr)
2156{
2157 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2158 if (cqr->refers) /* erp is not done yet */
2159 return 1;
2160 return ((cqr->status != DASD_CQR_DONE) &&
2161 (cqr->status != DASD_CQR_FAILED));
2162 } else
2163 return (cqr->status == DASD_CQR_FILLED);
2164}
2165
2166static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
2167{
2168 struct dasd_device *device;
2169 int rc;
2170 struct list_head ccw_queue;
2171 struct dasd_ccw_req *cqr;
2172
2173 INIT_LIST_HEAD(&ccw_queue);
2174 maincqr->status = DASD_CQR_FILLED;
2175 device = maincqr->startdev;
2176 list_add(&maincqr->blocklist, &ccw_queue);
2177 for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr);
2178 cqr = list_first_entry(&ccw_queue,
2179 struct dasd_ccw_req, blocklist)) {
2180
2181 if (__dasd_sleep_on_erp(cqr))
2182 continue;
2183 if (cqr->status != DASD_CQR_FILLED) /* could be failed */
2184 continue;
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01002185 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2186 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2187 cqr->status = DASD_CQR_FAILED;
2188 cqr->intrc = -EPERM;
2189 continue;
2190 }
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002191 /* Non-temporary stop condition will trigger fail fast */
2192 if (device->stopped & ~DASD_STOPPED_PENDING &&
2193 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2194 (!dasd_eer_enabled(device))) {
2195 cqr->status = DASD_CQR_FAILED;
Hannes Reinecked1ffc1f2013-01-30 09:26:16 +00002196 cqr->intrc = -ENOLINK;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002197 continue;
2198 }
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002199 /* Don't try to start requests if device is stopped */
2200 if (interruptible) {
2201 rc = wait_event_interruptible(
2202 generic_waitq, !(device->stopped));
2203 if (rc == -ERESTARTSYS) {
2204 cqr->status = DASD_CQR_FAILED;
2205 maincqr->intrc = rc;
2206 continue;
2207 }
2208 } else
2209 wait_event(generic_waitq, !(device->stopped));
2210
Stefan Haberland5915a872011-10-30 15:16:57 +01002211 if (!cqr->callback)
2212 cqr->callback = dasd_wakeup_cb;
2213
Stefan Weinhuber1c1e0932010-05-12 09:32:11 +02002214 cqr->callback_data = DASD_SLEEPON_START_TAG;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002215 dasd_add_request_tail(cqr);
2216 if (interruptible) {
2217 rc = wait_event_interruptible(
2218 generic_waitq, _wait_for_wakeup(cqr));
2219 if (rc == -ERESTARTSYS) {
2220 dasd_cancel_req(cqr);
2221 /* wait (non-interruptible) for final status */
2222 wait_event(generic_waitq,
2223 _wait_for_wakeup(cqr));
2224 cqr->status = DASD_CQR_FAILED;
2225 maincqr->intrc = rc;
2226 continue;
2227 }
2228 } else
2229 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2230 }
2231
Heiko Carstens1aae0562013-01-30 09:49:40 +01002232 maincqr->endclk = get_tod_clock();
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002233 if ((maincqr->status != DASD_CQR_DONE) &&
2234 (maincqr->intrc != -ERESTARTSYS))
2235 dasd_log_sense(maincqr, &maincqr->irb);
2236 if (maincqr->status == DASD_CQR_DONE)
2237 rc = 0;
2238 else if (maincqr->intrc)
2239 rc = maincqr->intrc;
2240 else
2241 rc = -EIO;
2242 return rc;
2243}
2244
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002245static inline int _wait_for_wakeup_queue(struct list_head *ccw_queue)
2246{
2247 struct dasd_ccw_req *cqr;
2248
2249 list_for_each_entry(cqr, ccw_queue, blocklist) {
2250 if (cqr->callback_data != DASD_SLEEPON_END_TAG)
2251 return 0;
2252 }
2253
2254 return 1;
2255}
2256
2257static int _dasd_sleep_on_queue(struct list_head *ccw_queue, int interruptible)
2258{
2259 struct dasd_device *device;
2260 int rc;
2261 struct dasd_ccw_req *cqr, *n;
2262
2263retry:
2264 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2265 device = cqr->startdev;
2266 if (cqr->status != DASD_CQR_FILLED) /*could be failed*/
2267 continue;
2268
2269 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2270 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2271 cqr->status = DASD_CQR_FAILED;
2272 cqr->intrc = -EPERM;
2273 continue;
2274 }
2275 /*Non-temporary stop condition will trigger fail fast*/
2276 if (device->stopped & ~DASD_STOPPED_PENDING &&
2277 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2278 !dasd_eer_enabled(device)) {
2279 cqr->status = DASD_CQR_FAILED;
2280 cqr->intrc = -EAGAIN;
2281 continue;
2282 }
2283
2284 /*Don't try to start requests if device is stopped*/
2285 if (interruptible) {
2286 rc = wait_event_interruptible(
2287 generic_waitq, !device->stopped);
2288 if (rc == -ERESTARTSYS) {
2289 cqr->status = DASD_CQR_FAILED;
2290 cqr->intrc = rc;
2291 continue;
2292 }
2293 } else
2294 wait_event(generic_waitq, !(device->stopped));
2295
2296 if (!cqr->callback)
2297 cqr->callback = dasd_wakeup_cb;
2298 cqr->callback_data = DASD_SLEEPON_START_TAG;
2299 dasd_add_request_tail(cqr);
2300 }
2301
2302 wait_event(generic_waitq, _wait_for_wakeup_queue(ccw_queue));
2303
2304 rc = 0;
2305 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2306 if (__dasd_sleep_on_erp(cqr))
2307 rc = 1;
2308 }
2309 if (rc)
2310 goto retry;
2311
2312
2313 return 0;
2314}
2315
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002316/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002317 * Queue a request to the tail of the device ccw_queue and wait for
2318 * it's completion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002320int dasd_sleep_on(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321{
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002322 return _dasd_sleep_on(cqr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002324EXPORT_SYMBOL(dasd_sleep_on);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
2326/*
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002327 * Start requests from a ccw_queue and wait for their completion.
2328 */
2329int dasd_sleep_on_queue(struct list_head *ccw_queue)
2330{
2331 return _dasd_sleep_on_queue(ccw_queue, 0);
2332}
2333EXPORT_SYMBOL(dasd_sleep_on_queue);
2334
2335/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002336 * Queue a request to the tail of the device ccw_queue and wait
2337 * interruptible for it's completion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002339int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340{
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002341 return _dasd_sleep_on(cqr, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002343EXPORT_SYMBOL(dasd_sleep_on_interruptible);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344
2345/*
2346 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2347 * for eckd devices) the currently running request has to be terminated
2348 * and be put back to status queued, before the special request is added
2349 * to the head of the queue. Then the special request is waited on normally.
2350 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002351static inline int _dasd_term_running_cqr(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352{
2353 struct dasd_ccw_req *cqr;
Stefan Haberlandaade6c02011-05-10 17:13:38 +02002354 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
2356 if (list_empty(&device->ccw_queue))
2357 return 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002358 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
Stefan Haberlandaade6c02011-05-10 17:13:38 +02002359 rc = device->discipline->term_IO(cqr);
2360 if (!rc)
2361 /*
2362 * CQR terminated because a more important request is pending.
2363 * Undo decreasing of retry counter because this is
2364 * not an error case.
2365 */
2366 cqr->retries++;
2367 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368}
2369
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002370int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 struct dasd_device *device;
2373 int rc;
Horst Hummel138c0142006-06-29 14:58:12 +02002374
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002375 device = cqr->startdev;
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01002376 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2377 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2378 cqr->status = DASD_CQR_FAILED;
2379 cqr->intrc = -EPERM;
2380 return -EIO;
2381 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 spin_lock_irq(get_ccwdev_lock(device->cdev));
2383 rc = _dasd_term_running_cqr(device);
2384 if (rc) {
2385 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2386 return rc;
2387 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 cqr->callback = dasd_wakeup_cb;
Stefan Weinhuber1c1e0932010-05-12 09:32:11 +02002389 cqr->callback_data = DASD_SLEEPON_START_TAG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 cqr->status = DASD_CQR_QUEUED;
Stefan Haberland214b8ff2011-10-30 15:16:56 +01002391 /*
2392 * add new request as second
2393 * first the terminated cqr needs to be finished
2394 */
2395 list_add(&cqr->devlist, device->ccw_queue.next);
Horst Hummel138c0142006-06-29 14:58:12 +02002396
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 /* let the bh start the request to keep them in order */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002398 dasd_schedule_device_bh(device);
Horst Hummel138c0142006-06-29 14:58:12 +02002399
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2401
Stefan Haberlandc80ee722008-05-30 10:03:31 +02002402 wait_event(generic_waitq, _wait_for_wakeup(cqr));
Horst Hummel138c0142006-06-29 14:58:12 +02002403
Stefan Weinhuber6cc7f162009-06-12 10:26:39 +02002404 if (cqr->status == DASD_CQR_DONE)
2405 rc = 0;
2406 else if (cqr->intrc)
2407 rc = cqr->intrc;
2408 else
2409 rc = -EIO;
Stefan Haberland0e003b72013-07-30 10:49:43 +02002410
2411 /* kick tasklets */
2412 dasd_schedule_device_bh(device);
2413 if (device->block)
2414 dasd_schedule_block_bh(device->block);
2415
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 return rc;
2417}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002418EXPORT_SYMBOL(dasd_sleep_on_immediatly);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
2420/*
2421 * Cancels a request that was started with dasd_sleep_on_req.
2422 * This is useful to timeout requests. The request will be
2423 * terminated if it is currently in i/o.
Hannes Reineckeb99a9462013-01-30 09:26:11 +00002424 * Returns 0 if request termination was successful
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002425 * negative error code if termination failed
2426 * Cancellation of a request is an asynchronous operation! The calling
2427 * function has to wait until the request is properly returned via callback.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002429int dasd_cancel_req(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002431 struct dasd_device *device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 unsigned long flags;
2433 int rc;
2434
2435 rc = 0;
2436 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2437 switch (cqr->status) {
2438 case DASD_CQR_QUEUED:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002439 /* request was not started - just set to cleared */
2440 cqr->status = DASD_CQR_CLEARED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 break;
2442 case DASD_CQR_IN_IO:
2443 /* request in IO - terminate IO and release again */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002444 rc = device->discipline->term_IO(cqr);
2445 if (rc) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002446 dev_err(&device->cdev->dev,
2447 "Cancelling request %p failed with rc=%d\n",
2448 cqr, rc);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002449 } else {
Heiko Carstens1aae0562013-01-30 09:49:40 +01002450 cqr->stopclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002451 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 break;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002453 default: /* already finished or clear pending - do nothing */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 }
2456 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002457 dasd_schedule_device_bh(device);
2458 return rc;
2459}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002460EXPORT_SYMBOL(dasd_cancel_req);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002461
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002462/*
2463 * SECTION: Operations of the dasd_block layer.
2464 */
2465
2466/*
2467 * Timeout function for dasd_block. This is used when the block layer
2468 * is waiting for something that may not come reliably, (e.g. a state
2469 * change interrupt)
2470 */
2471static void dasd_block_timeout(unsigned long ptr)
2472{
2473 unsigned long flags;
2474 struct dasd_block *block;
2475
2476 block = (struct dasd_block *) ptr;
2477 spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
2478 /* re-activate request queue */
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002479 dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002480 spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
2481 dasd_schedule_block_bh(block);
2482}
2483
2484/*
2485 * Setup timeout for a dasd_block in jiffies.
2486 */
2487void dasd_block_set_timer(struct dasd_block *block, int expires)
2488{
Stefan Weinhuber48cae882009-02-11 10:37:31 +01002489 if (expires == 0)
2490 del_timer(&block->timer);
2491 else
2492 mod_timer(&block->timer, jiffies + expires);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002493}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002494EXPORT_SYMBOL(dasd_block_set_timer);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002495
2496/*
2497 * Clear timeout for a dasd_block.
2498 */
2499void dasd_block_clear_timer(struct dasd_block *block)
2500{
Stefan Weinhuber48cae882009-02-11 10:37:31 +01002501 del_timer(&block->timer);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002502}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002503EXPORT_SYMBOL(dasd_block_clear_timer);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002504
2505/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002506 * Process finished error recovery ccw.
2507 */
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002508static void __dasd_process_erp(struct dasd_device *device,
2509 struct dasd_ccw_req *cqr)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002510{
2511 dasd_erp_fn_t erp_fn;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002512
2513 if (cqr->status == DASD_CQR_DONE)
2514 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
2515 else
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002516 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002517 erp_fn = device->discipline->erp_postaction(cqr);
2518 erp_fn(cqr);
2519}
2520
2521/*
2522 * Fetch requests from the block device queue.
2523 */
2524static void __dasd_process_request_queue(struct dasd_block *block)
2525{
2526 struct request_queue *queue;
2527 struct request *req;
2528 struct dasd_ccw_req *cqr;
2529 struct dasd_device *basedev;
2530 unsigned long flags;
2531 queue = block->request_queue;
2532 basedev = block->base;
2533 /* No queue ? Then there is nothing to do. */
2534 if (queue == NULL)
2535 return;
2536
2537 /*
2538 * We requeue request from the block device queue to the ccw
2539 * queue only in two states. In state DASD_STATE_READY the
2540 * partition detection is done and we need to requeue requests
2541 * for that. State DASD_STATE_ONLINE is normal block device
2542 * operation.
2543 */
Stefan Weinhuber97f604b2009-09-11 10:28:28 +02002544 if (basedev->state < DASD_STATE_READY) {
2545 while ((req = blk_fetch_request(block->request_queue)))
2546 __blk_end_request_all(req, -EIO);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002547 return;
Stefan Weinhuber97f604b2009-09-11 10:28:28 +02002548 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002549 /* Now we try to fetch requests from the request queue */
Jens Axboe7eaceac2011-03-10 08:52:07 +01002550 while ((req = blk_peek_request(queue))) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002551 if (basedev->features & DASD_FEATURE_READONLY &&
2552 rq_data_dir(req) == WRITE) {
2553 DBF_DEV_EVENT(DBF_ERR, basedev,
2554 "Rejecting write request %p",
2555 req);
Tejun Heo9934c8c2009-05-08 11:54:16 +09002556 blk_start_request(req);
Tejun Heo40cbbb72009-04-23 11:05:19 +09002557 __blk_end_request_all(req, -EIO);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002558 continue;
2559 }
Hannes Reinecke5ea34a02013-01-30 09:26:19 +00002560 if (test_bit(DASD_FLAG_ABORTALL, &basedev->flags) &&
2561 (basedev->features & DASD_FEATURE_FAILFAST ||
2562 blk_noretry_request(req))) {
2563 DBF_DEV_EVENT(DBF_ERR, basedev,
2564 "Rejecting failfast request %p",
2565 req);
2566 blk_start_request(req);
2567 __blk_end_request_all(req, -ETIMEDOUT);
2568 continue;
2569 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002570 cqr = basedev->discipline->build_cp(basedev, block, req);
2571 if (IS_ERR(cqr)) {
2572 if (PTR_ERR(cqr) == -EBUSY)
2573 break; /* normal end condition */
2574 if (PTR_ERR(cqr) == -ENOMEM)
2575 break; /* terminate request queue loop */
2576 if (PTR_ERR(cqr) == -EAGAIN) {
2577 /*
2578 * The current request cannot be build right
2579 * now, we have to try later. If this request
2580 * is the head-of-queue we stop the device
2581 * for 1/2 second.
2582 */
2583 if (!list_empty(&block->ccw_queue))
2584 break;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002585 spin_lock_irqsave(
2586 get_ccwdev_lock(basedev->cdev), flags);
2587 dasd_device_set_stop_bits(basedev,
2588 DASD_STOPPED_PENDING);
2589 spin_unlock_irqrestore(
2590 get_ccwdev_lock(basedev->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002591 dasd_block_set_timer(block, HZ/2);
2592 break;
2593 }
2594 DBF_DEV_EVENT(DBF_ERR, basedev,
2595 "CCW creation failed (rc=%ld) "
2596 "on request %p",
2597 PTR_ERR(cqr), req);
Tejun Heo9934c8c2009-05-08 11:54:16 +09002598 blk_start_request(req);
Tejun Heo40cbbb72009-04-23 11:05:19 +09002599 __blk_end_request_all(req, -EIO);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002600 continue;
2601 }
2602 /*
2603 * Note: callback is set to dasd_return_cqr_cb in
2604 * __dasd_block_start_head to cover erp requests as well
2605 */
2606 cqr->callback_data = (void *) req;
2607 cqr->status = DASD_CQR_FILLED;
Hannes Reineckea2ace462013-01-30 09:26:14 +00002608 req->completion_data = cqr;
Tejun Heo9934c8c2009-05-08 11:54:16 +09002609 blk_start_request(req);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002610 list_add_tail(&cqr->blocklist, &block->ccw_queue);
Hannes Reineckea2ace462013-01-30 09:26:14 +00002611 INIT_LIST_HEAD(&cqr->devlist);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002612 dasd_profile_start(block, cqr, req);
2613 }
2614}
2615
2616static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
2617{
2618 struct request *req;
2619 int status;
Kiyoshi Ueda4c4e2142008-01-28 10:29:42 +01002620 int error = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002621
2622 req = (struct request *) cqr->callback_data;
2623 dasd_profile_end(cqr->block, cqr, req);
Stefan Weinhuberfe6b8e72008-02-05 16:50:47 +01002624 status = cqr->block->base->discipline->free_cp(cqr, req);
Hannes Reinecked1ffc1f2013-01-30 09:26:16 +00002625 if (status < 0)
2626 error = status;
2627 else if (status == 0) {
2628 if (cqr->intrc == -EPERM)
2629 error = -EBADE;
2630 else if (cqr->intrc == -ENOLINK ||
2631 cqr->intrc == -ETIMEDOUT)
2632 error = cqr->intrc;
2633 else
2634 error = -EIO;
2635 }
Tejun Heo40cbbb72009-04-23 11:05:19 +09002636 __blk_end_request_all(req, error);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002637}
2638
2639/*
2640 * Process ccw request queue.
2641 */
2642static void __dasd_process_block_ccw_queue(struct dasd_block *block,
2643 struct list_head *final_queue)
2644{
2645 struct list_head *l, *n;
2646 struct dasd_ccw_req *cqr;
2647 dasd_erp_fn_t erp_fn;
2648 unsigned long flags;
2649 struct dasd_device *base = block->base;
2650
2651restart:
2652 /* Process request with final status. */
2653 list_for_each_safe(l, n, &block->ccw_queue) {
2654 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2655 if (cqr->status != DASD_CQR_DONE &&
2656 cqr->status != DASD_CQR_FAILED &&
2657 cqr->status != DASD_CQR_NEED_ERP &&
2658 cqr->status != DASD_CQR_TERMINATED)
2659 continue;
2660
2661 if (cqr->status == DASD_CQR_TERMINATED) {
2662 base->discipline->handle_terminated_request(cqr);
2663 goto restart;
2664 }
2665
2666 /* Process requests that may be recovered */
2667 if (cqr->status == DASD_CQR_NEED_ERP) {
Stefan Haberland6c5f57c2008-02-05 16:50:46 +01002668 erp_fn = base->discipline->erp_action(cqr);
Stefan Haberland6a5176c2010-04-22 17:17:02 +02002669 if (IS_ERR(erp_fn(cqr)))
2670 continue;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002671 goto restart;
2672 }
2673
Stefan Haberlanda9cffb22008-11-14 18:18:08 +01002674 /* log sense for fatal error */
2675 if (cqr->status == DASD_CQR_FAILED) {
2676 dasd_log_sense(cqr, &cqr->irb);
2677 }
2678
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002679 /* First of all call extended error reporting. */
2680 if (dasd_eer_enabled(base) &&
2681 cqr->status == DASD_CQR_FAILED) {
2682 dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
2683
2684 /* restart request */
2685 cqr->status = DASD_CQR_FILLED;
2686 cqr->retries = 255;
2687 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002688 dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002689 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
2690 flags);
2691 goto restart;
2692 }
2693
2694 /* Process finished ERP request. */
2695 if (cqr->refers) {
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002696 __dasd_process_erp(base, cqr);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002697 goto restart;
2698 }
2699
2700 /* Rechain finished requests to final queue */
Heiko Carstens1aae0562013-01-30 09:49:40 +01002701 cqr->endclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002702 list_move_tail(&cqr->blocklist, final_queue);
2703 }
2704}
2705
2706static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
2707{
2708 dasd_schedule_block_bh(cqr->block);
2709}
2710
2711static void __dasd_block_start_head(struct dasd_block *block)
2712{
2713 struct dasd_ccw_req *cqr;
2714
2715 if (list_empty(&block->ccw_queue))
2716 return;
2717 /* We allways begin with the first requests on the queue, as some
2718 * of previously started requests have to be enqueued on a
2719 * dasd_device again for error recovery.
2720 */
2721 list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
2722 if (cqr->status != DASD_CQR_FILLED)
2723 continue;
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01002724 if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) &&
2725 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2726 cqr->status = DASD_CQR_FAILED;
2727 cqr->intrc = -EPERM;
2728 dasd_schedule_block_bh(block);
2729 continue;
2730 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002731 /* Non-temporary stop condition will trigger fail fast */
2732 if (block->base->stopped & ~DASD_STOPPED_PENDING &&
2733 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2734 (!dasd_eer_enabled(block->base))) {
2735 cqr->status = DASD_CQR_FAILED;
Hannes Reinecked1ffc1f2013-01-30 09:26:16 +00002736 cqr->intrc = -ENOLINK;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002737 dasd_schedule_block_bh(block);
2738 continue;
2739 }
2740 /* Don't try to start requests if device is stopped */
2741 if (block->base->stopped)
2742 return;
2743
2744 /* just a fail safe check, should not happen */
2745 if (!cqr->startdev)
2746 cqr->startdev = block->base;
2747
2748 /* make sure that the requests we submit find their way back */
2749 cqr->callback = dasd_return_cqr_cb;
2750
2751 dasd_add_request_tail(cqr);
2752 }
2753}
2754
2755/*
2756 * Central dasd_block layer routine. Takes requests from the generic
2757 * block layer request queue, creates ccw requests, enqueues them on
2758 * a dasd_device and processes ccw requests that have been returned.
2759 */
2760static void dasd_block_tasklet(struct dasd_block *block)
2761{
2762 struct list_head final_queue;
2763 struct list_head *l, *n;
2764 struct dasd_ccw_req *cqr;
2765
2766 atomic_set(&block->tasklet_scheduled, 0);
2767 INIT_LIST_HEAD(&final_queue);
2768 spin_lock(&block->queue_lock);
2769 /* Finish off requests on ccw queue */
2770 __dasd_process_block_ccw_queue(block, &final_queue);
2771 spin_unlock(&block->queue_lock);
2772 /* Now call the callback function of requests with final status */
2773 spin_lock_irq(&block->request_queue_lock);
2774 list_for_each_safe(l, n, &final_queue) {
2775 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2776 list_del_init(&cqr->blocklist);
2777 __dasd_cleanup_cqr(cqr);
2778 }
2779 spin_lock(&block->queue_lock);
2780 /* Get new request from the block device request queue */
2781 __dasd_process_request_queue(block);
2782 /* Now check if the head of the ccw queue needs to be started. */
2783 __dasd_block_start_head(block);
2784 spin_unlock(&block->queue_lock);
2785 spin_unlock_irq(&block->request_queue_lock);
Stefan Haberland4679e892012-06-19 17:30:12 +02002786 if (waitqueue_active(&shutdown_waitq))
2787 wake_up(&shutdown_waitq);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002788 dasd_put_device(block->base);
2789}
2790
2791static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
2792{
2793 wake_up(&dasd_flush_wq);
2794}
2795
2796/*
Stefan Haberlandc5576872013-04-15 16:41:31 +02002797 * Requeue a request back to the block request queue
2798 * only works for block requests
2799 */
2800static int _dasd_requeue_request(struct dasd_ccw_req *cqr)
2801{
2802 struct dasd_block *block = cqr->block;
2803 struct request *req;
2804 unsigned long flags;
2805
2806 if (!block)
2807 return -EINVAL;
2808 spin_lock_irqsave(&block->queue_lock, flags);
2809 req = (struct request *) cqr->callback_data;
2810 blk_requeue_request(block->request_queue, req);
2811 spin_unlock_irqrestore(&block->queue_lock, flags);
2812
2813 return 0;
2814}
2815
2816/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002817 * Go through all request on the dasd_block request queue, cancel them
2818 * on the respective dasd_device, and return them to the generic
2819 * block layer.
2820 */
2821static int dasd_flush_block_queue(struct dasd_block *block)
2822{
2823 struct dasd_ccw_req *cqr, *n;
2824 int rc, i;
2825 struct list_head flush_queue;
2826
2827 INIT_LIST_HEAD(&flush_queue);
2828 spin_lock_bh(&block->queue_lock);
2829 rc = 0;
2830restart:
2831 list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
2832 /* if this request currently owned by a dasd_device cancel it */
2833 if (cqr->status >= DASD_CQR_QUEUED)
2834 rc = dasd_cancel_req(cqr);
2835 if (rc < 0)
2836 break;
2837 /* Rechain request (including erp chain) so it won't be
2838 * touched by the dasd_block_tasklet anymore.
2839 * Replace the callback so we notice when the request
2840 * is returned from the dasd_device layer.
2841 */
2842 cqr->callback = _dasd_wake_block_flush_cb;
2843 for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
2844 list_move_tail(&cqr->blocklist, &flush_queue);
2845 if (i > 1)
2846 /* moved more than one request - need to restart */
2847 goto restart;
2848 }
2849 spin_unlock_bh(&block->queue_lock);
2850 /* Now call the callback function of flushed requests */
2851restart_cb:
2852 list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
2853 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
2854 /* Process finished ERP request. */
2855 if (cqr->refers) {
Stefan Haberland0cd4bd42008-12-25 13:38:54 +01002856 spin_lock_bh(&block->queue_lock);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002857 __dasd_process_erp(block->base, cqr);
Stefan Haberland0cd4bd42008-12-25 13:38:54 +01002858 spin_unlock_bh(&block->queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002859 /* restart list_for_xx loop since dasd_process_erp
2860 * might remove multiple elements */
2861 goto restart_cb;
2862 }
2863 /* call the callback function */
Stefan Haberland0cd4bd42008-12-25 13:38:54 +01002864 spin_lock_irq(&block->request_queue_lock);
Heiko Carstens1aae0562013-01-30 09:49:40 +01002865 cqr->endclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002866 list_del_init(&cqr->blocklist);
2867 __dasd_cleanup_cqr(cqr);
Stefan Haberland0cd4bd42008-12-25 13:38:54 +01002868 spin_unlock_irq(&block->request_queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002869 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 return rc;
2871}
2872
2873/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002874 * Schedules a call to dasd_tasklet over the device tasklet.
2875 */
2876void dasd_schedule_block_bh(struct dasd_block *block)
2877{
2878 /* Protect against rescheduling. */
2879 if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
2880 return;
2881 /* life cycle of block is bound to it's base device */
2882 dasd_get_device(block->base);
2883 tasklet_hi_schedule(&block->tasklet);
2884}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002885EXPORT_SYMBOL(dasd_schedule_block_bh);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002886
2887
2888/*
2889 * SECTION: external block device operations
2890 * (request queue handling, open, release, etc.)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 */
2892
2893/*
2894 * Dasd request queue function. Called from ll_rw_blk.c
2895 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002896static void do_dasd_request(struct request_queue *queue)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002898 struct dasd_block *block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002900 block = queue->queuedata;
2901 spin_lock(&block->queue_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 /* Get new request from the block device request queue */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002903 __dasd_process_request_queue(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 /* Now check if the head of the ccw queue needs to be started. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002905 __dasd_block_start_head(block);
2906 spin_unlock(&block->queue_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907}
2908
2909/*
Hannes Reineckea2ace462013-01-30 09:26:14 +00002910 * Block timeout callback, called from the block layer
2911 *
2912 * request_queue lock is held on entry.
2913 *
2914 * Return values:
2915 * BLK_EH_RESET_TIMER if the request should be left running
2916 * BLK_EH_NOT_HANDLED if the request is handled or terminated
2917 * by the driver.
2918 */
2919enum blk_eh_timer_return dasd_times_out(struct request *req)
2920{
2921 struct dasd_ccw_req *cqr = req->completion_data;
2922 struct dasd_block *block = req->q->queuedata;
2923 struct dasd_device *device;
2924 int rc = 0;
2925
2926 if (!cqr)
2927 return BLK_EH_NOT_HANDLED;
2928
2929 device = cqr->startdev ? cqr->startdev : block->base;
Hannes Reinecke3d71ad32013-01-30 09:26:18 +00002930 if (!device->blk_timeout)
2931 return BLK_EH_RESET_TIMER;
Hannes Reineckea2ace462013-01-30 09:26:14 +00002932 DBF_DEV_EVENT(DBF_WARNING, device,
2933 " dasd_times_out cqr %p status %x",
2934 cqr, cqr->status);
2935
2936 spin_lock(&block->queue_lock);
2937 spin_lock(get_ccwdev_lock(device->cdev));
2938 cqr->retries = -1;
2939 cqr->intrc = -ETIMEDOUT;
2940 if (cqr->status >= DASD_CQR_QUEUED) {
2941 spin_unlock(get_ccwdev_lock(device->cdev));
2942 rc = dasd_cancel_req(cqr);
2943 } else if (cqr->status == DASD_CQR_FILLED ||
2944 cqr->status == DASD_CQR_NEED_ERP) {
2945 cqr->status = DASD_CQR_TERMINATED;
2946 spin_unlock(get_ccwdev_lock(device->cdev));
2947 } else if (cqr->status == DASD_CQR_IN_ERP) {
2948 struct dasd_ccw_req *searchcqr, *nextcqr, *tmpcqr;
2949
2950 list_for_each_entry_safe(searchcqr, nextcqr,
2951 &block->ccw_queue, blocklist) {
2952 tmpcqr = searchcqr;
2953 while (tmpcqr->refers)
2954 tmpcqr = tmpcqr->refers;
2955 if (tmpcqr != cqr)
2956 continue;
2957 /* searchcqr is an ERP request for cqr */
2958 searchcqr->retries = -1;
2959 searchcqr->intrc = -ETIMEDOUT;
2960 if (searchcqr->status >= DASD_CQR_QUEUED) {
2961 spin_unlock(get_ccwdev_lock(device->cdev));
2962 rc = dasd_cancel_req(searchcqr);
2963 spin_lock(get_ccwdev_lock(device->cdev));
2964 } else if ((searchcqr->status == DASD_CQR_FILLED) ||
2965 (searchcqr->status == DASD_CQR_NEED_ERP)) {
2966 searchcqr->status = DASD_CQR_TERMINATED;
2967 rc = 0;
2968 } else if (searchcqr->status == DASD_CQR_IN_ERP) {
2969 /*
2970 * Shouldn't happen; most recent ERP
2971 * request is at the front of queue
2972 */
2973 continue;
2974 }
2975 break;
2976 }
2977 spin_unlock(get_ccwdev_lock(device->cdev));
2978 }
2979 dasd_schedule_block_bh(block);
2980 spin_unlock(&block->queue_lock);
2981
2982 return rc ? BLK_EH_RESET_TIMER : BLK_EH_NOT_HANDLED;
2983}
2984
2985/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 * Allocate and initialize request queue and default I/O scheduler.
2987 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002988static int dasd_alloc_queue(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989{
2990 int rc;
2991
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002992 block->request_queue = blk_init_queue(do_dasd_request,
2993 &block->request_queue_lock);
2994 if (block->request_queue == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 return -ENOMEM;
2996
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002997 block->request_queue->queuedata = block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002999 elevator_exit(block->request_queue->elevator);
Josef 'Jeff' Sipek08a8a0c2008-04-17 07:45:56 +02003000 block->request_queue->elevator = NULL;
Heiko Carstensef089942013-10-31 13:24:28 +01003001 mutex_lock(&block->request_queue->sysfs_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003002 rc = elevator_init(block->request_queue, "deadline");
Heiko Carstensef089942013-10-31 13:24:28 +01003003 if (rc)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003004 blk_cleanup_queue(block->request_queue);
Heiko Carstensef089942013-10-31 13:24:28 +01003005 mutex_unlock(&block->request_queue->sysfs_lock);
3006 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007}
3008
3009/*
3010 * Allocate and initialize request queue.
3011 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003012static void dasd_setup_queue(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013{
3014 int max;
3015
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01003016 if (block->base->features & DASD_FEATURE_USERAW) {
3017 /*
3018 * the max_blocks value for raw_track access is 256
3019 * it is higher than the native ECKD value because we
3020 * only need one ccw per track
3021 * so the max_hw_sectors are
3022 * 2048 x 512B = 1024kB = 16 tracks
3023 */
3024 max = 2048;
3025 } else {
3026 max = block->base->discipline->max_blocks << block->s2b_shift;
3027 }
3028 blk_queue_logical_block_size(block->request_queue,
3029 block->bp_block);
Martin K. Petersen086fa5f2010-02-26 00:20:38 -05003030 blk_queue_max_hw_sectors(block->request_queue, max);
Martin K. Petersen8a783622010-02-26 00:20:39 -05003031 blk_queue_max_segments(block->request_queue, -1L);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003032 /* with page sized segments we can translate each segement into
3033 * one idaw/tidaw
3034 */
3035 blk_queue_max_segment_size(block->request_queue, PAGE_SIZE);
3036 blk_queue_segment_boundary(block->request_queue, PAGE_SIZE - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037}
3038
3039/*
3040 * Deactivate and free request queue.
3041 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003042static void dasd_free_queue(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003044 if (block->request_queue) {
3045 blk_cleanup_queue(block->request_queue);
3046 block->request_queue = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 }
3048}
3049
3050/*
3051 * Flush request on the request queue.
3052 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003053static void dasd_flush_request_queue(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054{
3055 struct request *req;
3056
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003057 if (!block->request_queue)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 return;
Horst Hummel138c0142006-06-29 14:58:12 +02003059
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003060 spin_lock_irq(&block->request_queue_lock);
Tejun Heo9934c8c2009-05-08 11:54:16 +09003061 while ((req = blk_fetch_request(block->request_queue)))
Tejun Heo40cbbb72009-04-23 11:05:19 +09003062 __blk_end_request_all(req, -EIO);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003063 spin_unlock_irq(&block->request_queue_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064}
3065
Al Viro57a7c0b2008-03-02 10:36:08 -05003066static int dasd_open(struct block_device *bdev, fmode_t mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067{
Stefan Haberland9eb25122010-02-26 22:37:46 +01003068 struct dasd_device *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 int rc;
3070
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003071 base = dasd_device_from_gendisk(bdev->bd_disk);
3072 if (!base)
Stefan Haberland9eb25122010-02-26 22:37:46 +01003073 return -ENODEV;
3074
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003075 atomic_inc(&base->block->open_count);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003076 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 rc = -ENODEV;
3078 goto unlock;
3079 }
3080
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003081 if (!try_module_get(base->discipline->owner)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 rc = -EINVAL;
3083 goto unlock;
3084 }
3085
3086 if (dasd_probeonly) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01003087 dev_info(&base->cdev->dev,
3088 "Accessing the DASD failed because it is in "
3089 "probeonly mode\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 rc = -EPERM;
3091 goto out;
3092 }
3093
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003094 if (base->state <= DASD_STATE_BASIC) {
3095 DBF_DEV_EVENT(DBF_ERR, base, " %s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 " Cannot open unrecognized device");
3097 rc = -ENODEV;
3098 goto out;
3099 }
3100
Stefan Weinhuber33b62a32010-03-08 12:26:24 +01003101 if ((mode & FMODE_WRITE) &&
3102 (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) ||
3103 (base->features & DASD_FEATURE_READONLY))) {
3104 rc = -EROFS;
3105 goto out;
3106 }
3107
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003108 dasd_put_device(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 return 0;
3110
3111out:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003112 module_put(base->discipline->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113unlock:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003114 atomic_dec(&base->block->open_count);
3115 dasd_put_device(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 return rc;
3117}
3118
Al Virodb2a1442013-05-05 21:52:57 -04003119static void dasd_release(struct gendisk *disk, fmode_t mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120{
Al Virodb2a1442013-05-05 21:52:57 -04003121 struct dasd_device *base = dasd_device_from_gendisk(disk);
3122 if (base) {
3123 atomic_dec(&base->block->open_count);
3124 module_put(base->discipline->owner);
3125 dasd_put_device(base);
3126 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127}
3128
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003129/*
3130 * Return disk geometry.
3131 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003132static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003133{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003134 struct dasd_device *base;
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003135
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003136 base = dasd_device_from_gendisk(bdev->bd_disk);
3137 if (!base)
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003138 return -ENODEV;
3139
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003140 if (!base->discipline ||
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003141 !base->discipline->fill_geometry) {
3142 dasd_put_device(base);
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003143 return -EINVAL;
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003144 }
3145 base->discipline->fill_geometry(base->block, geo);
3146 geo->start = get_start_sect(bdev) >> base->block->s2b_shift;
3147 dasd_put_device(base);
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003148 return 0;
3149}
3150
Alexey Dobriyan83d5cde2009-09-21 17:01:13 -07003151const struct block_device_operations
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152dasd_device_operations = {
3153 .owner = THIS_MODULE,
Al Viro57a7c0b2008-03-02 10:36:08 -05003154 .open = dasd_open,
3155 .release = dasd_release,
Heiko Carstens0000d032009-03-26 15:23:45 +01003156 .ioctl = dasd_ioctl,
3157 .compat_ioctl = dasd_ioctl,
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003158 .getgeo = dasd_getgeo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159};
3160
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003161/*******************************************************************************
3162 * end of block device operations
3163 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164
3165static void
3166dasd_exit(void)
3167{
3168#ifdef CONFIG_PROC_FS
3169 dasd_proc_exit();
3170#endif
Stefan Weinhuber20c64462006-03-24 03:15:25 -08003171 dasd_eer_exit();
Horst Hummel6bb0e012005-07-27 11:45:03 -07003172 if (dasd_page_cache != NULL) {
3173 kmem_cache_destroy(dasd_page_cache);
3174 dasd_page_cache = NULL;
3175 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 dasd_gendisk_exit();
3177 dasd_devmap_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 if (dasd_debug_area != NULL) {
3179 debug_unregister(dasd_debug_area);
3180 dasd_debug_area = NULL;
3181 }
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02003182 dasd_statistics_removeroot();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183}
3184
3185/*
3186 * SECTION: common functions for ccw_driver use
3187 */
3188
Stefan Weinhuber33b62a32010-03-08 12:26:24 +01003189/*
3190 * Is the device read-only?
3191 * Note that this function does not report the setting of the
3192 * readonly device attribute, but how it is configured in z/VM.
3193 */
3194int dasd_device_is_ro(struct dasd_device *device)
3195{
3196 struct ccw_dev_id dev_id;
3197 struct diag210 diag_data;
3198 int rc;
3199
3200 if (!MACHINE_IS_VM)
3201 return 0;
3202 ccw_device_get_id(device->cdev, &dev_id);
3203 memset(&diag_data, 0, sizeof(diag_data));
3204 diag_data.vrdcdvno = dev_id.devno;
3205 diag_data.vrdclen = sizeof(diag_data);
3206 rc = diag210(&diag_data);
3207 if (rc == 0 || rc == 2) {
3208 return diag_data.vrdcvfla & 0x80;
3209 } else {
3210 DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d",
3211 dev_id.devno, rc);
3212 return 0;
3213 }
3214}
3215EXPORT_SYMBOL_GPL(dasd_device_is_ro);
3216
Cornelia Huckf3445a12009-04-14 15:36:23 +02003217static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
3218{
3219 struct ccw_device *cdev = data;
3220 int ret;
3221
3222 ret = ccw_device_set_online(cdev);
3223 if (ret)
Fabian Frederick4ce25962014-06-26 19:41:48 +02003224 pr_warn("%s: Setting the DASD online failed with rc=%d\n",
3225 dev_name(&cdev->dev), ret);
Cornelia Huckf3445a12009-04-14 15:36:23 +02003226}
3227
Horst Hummel1c01b8a2006-01-06 00:19:15 -08003228/*
3229 * Initial attempt at a probe function. this can be simplified once
3230 * the other detection code is gone.
3231 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003232int dasd_generic_probe(struct ccw_device *cdev,
3233 struct dasd_discipline *discipline)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234{
3235 int ret;
3236
3237 ret = dasd_add_sysfs_files(cdev);
3238 if (ret) {
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01003239 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
3240 "dasd_generic_probe: could not add "
3241 "sysfs entries");
Horst Hummel40545572006-06-29 15:08:18 +02003242 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 }
Horst Hummel40545572006-06-29 15:08:18 +02003244 cdev->handler = &dasd_int_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245
Horst Hummel40545572006-06-29 15:08:18 +02003246 /*
3247 * Automatically online either all dasd devices (dasd_autodetect)
3248 * or all devices specified with dasd= parameters during
3249 * initial probe.
3250 */
3251 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
Kay Sievers2a0217d2008-10-10 21:33:09 +02003252 (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
Cornelia Huckf3445a12009-04-14 15:36:23 +02003253 async_schedule(dasd_generic_auto_online, cdev);
Stefan Haberlandde3e0da2008-01-26 14:11:08 +01003254 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003256EXPORT_SYMBOL_GPL(dasd_generic_probe);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257
Horst Hummel1c01b8a2006-01-06 00:19:15 -08003258/*
3259 * This will one day be called from a global not_oper handler.
3260 * It is also used by driver_unregister during module unload.
3261 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003262void dasd_generic_remove(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263{
3264 struct dasd_device *device;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003265 struct dasd_block *block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266
Horst Hummel59afda72005-05-16 21:53:39 -07003267 cdev->handler = NULL;
3268
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 device = dasd_device_from_cdev(cdev);
Stefan Weinhuberbe4904e2013-02-04 13:10:35 +01003270 if (IS_ERR(device)) {
3271 dasd_remove_sysfs_files(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 return;
Stefan Weinhuberbe4904e2013-02-04 13:10:35 +01003273 }
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003274 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3275 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 /* Already doing offline processing */
3277 dasd_put_device(device);
Stefan Weinhuberbe4904e2013-02-04 13:10:35 +01003278 dasd_remove_sysfs_files(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 return;
3280 }
3281 /*
3282 * This device is removed unconditionally. Set offline
3283 * flag to prevent dasd_open from opening it while it is
3284 * no quite down yet.
3285 */
3286 dasd_set_target_state(device, DASD_STATE_NEW);
3287 /* dasd_delete_device destroys the device reference. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003288 block = device->block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 dasd_delete_device(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003290 /*
3291 * life cycle of block is bound to device, so delete it after
3292 * device was safely removed
3293 */
3294 if (block)
3295 dasd_free_block(block);
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003296
3297 dasd_remove_sysfs_files(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003299EXPORT_SYMBOL_GPL(dasd_generic_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300
Horst Hummel1c01b8a2006-01-06 00:19:15 -08003301/*
3302 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 * the device is detected for the first time and is supposed to be used
Horst Hummel1c01b8a2006-01-06 00:19:15 -08003304 * or the user has started activation through sysfs.
3305 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003306int dasd_generic_set_online(struct ccw_device *cdev,
3307 struct dasd_discipline *base_discipline)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308{
Peter Oberparleiteraa888612006-02-20 18:28:13 -08003309 struct dasd_discipline *discipline;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 struct dasd_device *device;
Horst Hummelc6eb7b72005-09-03 15:57:58 -07003311 int rc;
Horst Hummelf24acd42005-05-01 08:58:59 -07003312
Horst Hummel40545572006-06-29 15:08:18 +02003313 /* first online clears initial online feature flag */
3314 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 device = dasd_create_device(cdev);
3316 if (IS_ERR(device))
3317 return PTR_ERR(device);
3318
Peter Oberparleiteraa888612006-02-20 18:28:13 -08003319 discipline = base_discipline;
Horst Hummelc6eb7b72005-09-03 15:57:58 -07003320 if (device->features & DASD_FEATURE_USEDIAG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 if (!dasd_diag_discipline_pointer) {
Fabian Frederick4ce25962014-06-26 19:41:48 +02003322 pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n",
3323 dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 dasd_delete_device(device);
3325 return -ENODEV;
3326 }
3327 discipline = dasd_diag_discipline_pointer;
3328 }
Peter Oberparleiteraa888612006-02-20 18:28:13 -08003329 if (!try_module_get(base_discipline->owner)) {
3330 dasd_delete_device(device);
3331 return -EINVAL;
3332 }
3333 if (!try_module_get(discipline->owner)) {
3334 module_put(base_discipline->owner);
3335 dasd_delete_device(device);
3336 return -EINVAL;
3337 }
3338 device->base_discipline = base_discipline;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 device->discipline = discipline;
3340
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003341 /* check_device will allocate block device if necessary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 rc = discipline->check_device(device);
3343 if (rc) {
Fabian Frederick4ce25962014-06-26 19:41:48 +02003344 pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
3345 dev_name(&cdev->dev), discipline->name, rc);
Peter Oberparleiteraa888612006-02-20 18:28:13 -08003346 module_put(discipline->owner);
3347 module_put(base_discipline->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 dasd_delete_device(device);
3349 return rc;
3350 }
3351
3352 dasd_set_target_state(device, DASD_STATE_ONLINE);
3353 if (device->state <= DASD_STATE_KNOWN) {
Fabian Frederick4ce25962014-06-26 19:41:48 +02003354 pr_warn("%s Setting the DASD online failed because of a missing discipline\n",
3355 dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 rc = -ENODEV;
3357 dasd_set_target_state(device, DASD_STATE_NEW);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003358 if (device->block)
3359 dasd_free_block(device->block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 dasd_delete_device(device);
3361 } else
3362 pr_debug("dasd_generic device %s found\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +02003363 dev_name(&cdev->dev));
Stefan Haberland589c74d2010-02-26 22:37:47 +01003364
3365 wait_event(dasd_init_waitq, _wait_for_device(device));
3366
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 dasd_put_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 return rc;
3369}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003370EXPORT_SYMBOL_GPL(dasd_generic_set_online);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003372int dasd_generic_set_offline(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373{
3374 struct dasd_device *device;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003375 struct dasd_block *block;
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003376 int max_count, open_count, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003378 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 device = dasd_device_from_cdev(cdev);
3380 if (IS_ERR(device))
3381 return PTR_ERR(device);
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003382
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 /*
3384 * We must make sure that this device is currently not in use.
3385 * The open_count is increased for every opener, that includes
3386 * the blkdev_get in dasd_scan_partitions. We are only interested
3387 * in the other openers.
3388 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003389 if (device->block) {
Heiko Carstensa8061702008-04-17 07:46:26 +02003390 max_count = device->block->bdev ? 0 : -1;
3391 open_count = atomic_read(&device->block->open_count);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003392 if (open_count > max_count) {
3393 if (open_count > 0)
Fabian Frederick4ce25962014-06-26 19:41:48 +02003394 pr_warn("%s: The DASD cannot be set offline with open count %i\n",
3395 dev_name(&cdev->dev), open_count);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003396 else
Fabian Frederick4ce25962014-06-26 19:41:48 +02003397 pr_warn("%s: The DASD cannot be set offline while it is in use\n",
3398 dev_name(&cdev->dev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003399 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
3400 dasd_put_device(device);
3401 return -EBUSY;
3402 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 }
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003404
3405 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3406 /*
Hendrik Bruecknerb4a96012013-12-13 12:53:42 +01003407 * safe offline already running
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003408 * could only be called by normal offline so safe_offline flag
3409 * needs to be removed to run normal offline and kill all I/O
3410 */
3411 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3412 /* Already doing normal offline processing */
3413 dasd_put_device(device);
3414 return -EBUSY;
3415 } else
3416 clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags);
3417
3418 } else
3419 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3420 /* Already doing offline processing */
3421 dasd_put_device(device);
3422 return -EBUSY;
3423 }
3424
3425 /*
3426 * if safe_offline called set safe_offline_running flag and
3427 * clear safe_offline so that a call to normal offline
3428 * can overrun safe_offline processing
3429 */
3430 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
3431 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3432 /*
3433 * If we want to set the device safe offline all IO operations
3434 * should be finished before continuing the offline process
3435 * so sync bdev first and then wait for our queues to become
3436 * empty
3437 */
3438 /* sync blockdev and partitions */
3439 rc = fsync_bdev(device->block->bdev);
3440 if (rc != 0)
3441 goto interrupted;
3442
3443 /* schedule device tasklet and wait for completion */
3444 dasd_schedule_device_bh(device);
3445 rc = wait_event_interruptible(shutdown_waitq,
3446 _wait_for_empty_queues(device));
3447 if (rc != 0)
3448 goto interrupted;
3449 }
3450
3451 set_bit(DASD_FLAG_OFFLINE, &device->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 dasd_set_target_state(device, DASD_STATE_NEW);
3453 /* dasd_delete_device destroys the device reference. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003454 block = device->block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 dasd_delete_device(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003456 /*
3457 * life cycle of block is bound to device, so delete it after
3458 * device was safely removed
3459 */
3460 if (block)
3461 dasd_free_block(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 return 0;
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003463
3464interrupted:
3465 /* interrupted by signal */
3466 clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags);
3467 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3468 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
3469 dasd_put_device(device);
3470 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003472EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003474int dasd_generic_last_path_gone(struct dasd_device *device)
3475{
3476 struct dasd_ccw_req *cqr;
3477
3478 dev_warn(&device->cdev->dev, "No operational channel path is left "
3479 "for the device\n");
3480 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
3481 /* First of all call extended error reporting. */
3482 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3483
3484 if (device->state < DASD_STATE_BASIC)
3485 return 0;
3486 /* Device is active. We want to keep it. */
3487 list_for_each_entry(cqr, &device->ccw_queue, devlist)
3488 if ((cqr->status == DASD_CQR_IN_IO) ||
3489 (cqr->status == DASD_CQR_CLEAR_PENDING)) {
3490 cqr->status = DASD_CQR_QUEUED;
3491 cqr->retries++;
3492 }
3493 dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
3494 dasd_device_clear_timer(device);
3495 dasd_schedule_device_bh(device);
3496 return 1;
3497}
3498EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone);
3499
3500int dasd_generic_path_operational(struct dasd_device *device)
3501{
3502 dev_info(&device->cdev->dev, "A channel path to the device has become "
3503 "operational\n");
3504 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
3505 dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
3506 if (device->stopped & DASD_UNRESUMED_PM) {
3507 dasd_device_remove_stop_bits(device, DASD_UNRESUMED_PM);
3508 dasd_restore_device(device);
3509 return 1;
3510 }
3511 dasd_schedule_device_bh(device);
3512 if (device->block)
3513 dasd_schedule_block_bh(device->block);
3514 return 1;
3515}
3516EXPORT_SYMBOL_GPL(dasd_generic_path_operational);
3517
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003518int dasd_generic_notify(struct ccw_device *cdev, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519{
3520 struct dasd_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 int ret;
3522
Peter Oberparleiter91c36912008-08-21 19:46:39 +02003523 device = dasd_device_from_cdev_locked(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524 if (IS_ERR(device))
3525 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 ret = 0;
3527 switch (event) {
3528 case CIO_GONE:
Sebastian Ott47593bf2009-03-31 19:16:05 +02003529 case CIO_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 case CIO_NO_PATH:
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003531 device->path_data.opm = 0;
3532 device->path_data.ppm = 0;
3533 device->path_data.npm = 0;
3534 ret = dasd_generic_last_path_gone(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 break;
3536 case CIO_OPER:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 ret = 1;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003538 if (device->path_data.opm)
3539 ret = dasd_generic_path_operational(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 break;
3541 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 dasd_put_device(device);
3543 return ret;
3544}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003545EXPORT_SYMBOL_GPL(dasd_generic_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003547void dasd_generic_path_event(struct ccw_device *cdev, int *path_event)
3548{
3549 int chp;
3550 __u8 oldopm, eventlpm;
3551 struct dasd_device *device;
3552
3553 device = dasd_device_from_cdev_locked(cdev);
3554 if (IS_ERR(device))
3555 return;
3556 for (chp = 0; chp < 8; chp++) {
3557 eventlpm = 0x80 >> chp;
3558 if (path_event[chp] & PE_PATH_GONE) {
3559 oldopm = device->path_data.opm;
3560 device->path_data.opm &= ~eventlpm;
3561 device->path_data.ppm &= ~eventlpm;
3562 device->path_data.npm &= ~eventlpm;
Stefan Weinhuber8b811ba2013-05-28 15:26:06 +02003563 if (oldopm && !device->path_data.opm) {
3564 dev_warn(&device->cdev->dev,
3565 "No verified channel paths remain "
3566 "for the device\n");
3567 DBF_DEV_EVENT(DBF_WARNING, device,
3568 "%s", "last verified path gone");
3569 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3570 dasd_device_set_stop_bits(device,
3571 DASD_STOPPED_DC_WAIT);
3572 }
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003573 }
3574 if (path_event[chp] & PE_PATH_AVAILABLE) {
3575 device->path_data.opm &= ~eventlpm;
3576 device->path_data.ppm &= ~eventlpm;
3577 device->path_data.npm &= ~eventlpm;
3578 device->path_data.tbvpm |= eventlpm;
3579 dasd_schedule_device_bh(device);
3580 }
Stefan Haberlandf1633032012-01-18 18:03:41 +01003581 if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) {
Stefan Haberland12d7b102012-09-11 15:10:58 +02003582 if (!(device->path_data.opm & eventlpm) &&
3583 !(device->path_data.tbvpm & eventlpm)) {
3584 /*
3585 * we can not establish a pathgroup on an
3586 * unavailable path, so trigger a path
3587 * verification first
3588 */
3589 device->path_data.tbvpm |= eventlpm;
3590 dasd_schedule_device_bh(device);
3591 }
Stefan Haberlandf1633032012-01-18 18:03:41 +01003592 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3593 "Pathgroup re-established\n");
3594 if (device->discipline->kick_validate)
3595 device->discipline->kick_validate(device);
3596 }
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003597 }
3598 dasd_put_device(device);
3599}
3600EXPORT_SYMBOL_GPL(dasd_generic_path_event);
3601
3602int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
3603{
3604 if (!device->path_data.opm && lpm) {
3605 device->path_data.opm = lpm;
3606 dasd_generic_path_operational(device);
3607 } else
3608 device->path_data.opm |= lpm;
3609 return 0;
3610}
3611EXPORT_SYMBOL_GPL(dasd_generic_verify_path);
3612
3613
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003614int dasd_generic_pm_freeze(struct ccw_device *cdev)
3615{
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003616 struct dasd_device *device = dasd_device_from_cdev(cdev);
Stefan Haberlandc5576872013-04-15 16:41:31 +02003617 struct list_head freeze_queue;
3618 struct dasd_ccw_req *cqr, *n;
3619 struct dasd_ccw_req *refers;
3620 int rc;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003621
3622 if (IS_ERR(device))
3623 return PTR_ERR(device);
Stefan Haberland6f272b92011-01-05 12:48:05 +01003624
Stefan Haberlandc8d1c0f2011-10-30 15:17:09 +01003625 /* mark device as suspended */
3626 set_bit(DASD_FLAG_SUSPENDED, &device->flags);
3627
Stefan Haberland6f272b92011-01-05 12:48:05 +01003628 if (device->discipline->freeze)
3629 rc = device->discipline->freeze(device);
3630
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003631 /* disallow new I/O */
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01003632 dasd_device_set_stop_bits(device, DASD_STOPPED_PM);
Stefan Haberlandc5576872013-04-15 16:41:31 +02003633
3634 /* clear active requests and requeue them to block layer if possible */
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003635 INIT_LIST_HEAD(&freeze_queue);
3636 spin_lock_irq(get_ccwdev_lock(cdev));
3637 rc = 0;
3638 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
3639 /* Check status and move request to flush_queue */
3640 if (cqr->status == DASD_CQR_IN_IO) {
3641 rc = device->discipline->term_IO(cqr);
3642 if (rc) {
3643 /* unable to terminate requeust */
3644 dev_err(&device->cdev->dev,
3645 "Unable to terminate request %p "
3646 "on suspend\n", cqr);
3647 spin_unlock_irq(get_ccwdev_lock(cdev));
3648 dasd_put_device(device);
3649 return rc;
3650 }
3651 }
3652 list_move_tail(&cqr->devlist, &freeze_queue);
3653 }
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003654 spin_unlock_irq(get_ccwdev_lock(cdev));
3655
3656 list_for_each_entry_safe(cqr, n, &freeze_queue, devlist) {
3657 wait_event(dasd_flush_wq,
3658 (cqr->status != DASD_CQR_CLEAR_PENDING));
3659 if (cqr->status == DASD_CQR_CLEARED)
3660 cqr->status = DASD_CQR_QUEUED;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003661
Stefan Haberlandc5576872013-04-15 16:41:31 +02003662 /* requeue requests to blocklayer will only work for
3663 block device requests */
3664 if (_dasd_requeue_request(cqr))
3665 continue;
3666
3667 /* remove requests from device and block queue */
3668 list_del_init(&cqr->devlist);
3669 while (cqr->refers != NULL) {
3670 refers = cqr->refers;
3671 /* remove the request from the block queue */
3672 list_del(&cqr->blocklist);
3673 /* free the finished erp request */
3674 dasd_free_erp_request(cqr, cqr->memdev);
3675 cqr = refers;
3676 }
3677 if (cqr->block)
3678 list_del_init(&cqr->blocklist);
3679 cqr->block->base->discipline->free_cp(
3680 cqr, (struct request *) cqr->callback_data);
3681 }
3682
3683 /*
3684 * if requests remain then they are internal request
3685 * and go back to the device queue
3686 */
3687 if (!list_empty(&freeze_queue)) {
3688 /* move freeze_queue to start of the ccw_queue */
3689 spin_lock_irq(get_ccwdev_lock(cdev));
3690 list_splice_tail(&freeze_queue, &device->ccw_queue);
3691 spin_unlock_irq(get_ccwdev_lock(cdev));
3692 }
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003693 dasd_put_device(device);
3694 return rc;
3695}
3696EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze);
3697
3698int dasd_generic_restore_device(struct ccw_device *cdev)
3699{
3700 struct dasd_device *device = dasd_device_from_cdev(cdev);
3701 int rc = 0;
3702
3703 if (IS_ERR(device))
3704 return PTR_ERR(device);
3705
Stefan Haberlande6125fb2009-06-22 12:08:17 +02003706 /* allow new IO again */
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01003707 dasd_device_remove_stop_bits(device,
3708 (DASD_STOPPED_PM | DASD_UNRESUMED_PM));
Stefan Haberlande6125fb2009-06-22 12:08:17 +02003709
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003710 dasd_schedule_device_bh(device);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003711
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01003712 /*
3713 * call discipline restore function
3714 * if device is stopped do nothing e.g. for disconnected devices
3715 */
3716 if (device->discipline->restore && !(device->stopped))
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003717 rc = device->discipline->restore(device);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01003718 if (rc || device->stopped)
Stefan Haberlande6125fb2009-06-22 12:08:17 +02003719 /*
3720 * if the resume failed for the DASD we put it in
3721 * an UNRESUMED stop state
3722 */
3723 device->stopped |= DASD_UNRESUMED_PM;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003724
Stefan Haberland6fca97a2009-10-06 10:34:15 +02003725 if (device->block)
3726 dasd_schedule_block_bh(device->block);
3727
Stefan Haberlandc8d1c0f2011-10-30 15:17:09 +01003728 clear_bit(DASD_FLAG_SUSPENDED, &device->flags);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003729 dasd_put_device(device);
Stefan Haberlande6125fb2009-06-22 12:08:17 +02003730 return 0;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003731}
3732EXPORT_SYMBOL_GPL(dasd_generic_restore_device);
3733
Heiko Carstens763968e2007-05-10 15:45:46 +02003734static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
3735 void *rdc_buffer,
3736 int rdc_buffer_size,
Stefan Haberland68b781f2009-09-11 10:28:29 +02003737 int magic)
Cornelia Huck17283b52007-05-04 18:47:51 +02003738{
3739 struct dasd_ccw_req *cqr;
3740 struct ccw1 *ccw;
Stefan Haberlandd9fa9442009-10-14 12:43:48 +02003741 unsigned long *idaw;
Cornelia Huck17283b52007-05-04 18:47:51 +02003742
3743 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device);
3744
3745 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01003746 /* internal error 13 - Allocating the RDC request failed*/
3747 dev_err(&device->cdev->dev,
3748 "An error occurred in the DASD device driver, "
3749 "reason=%s\n", "13");
Cornelia Huck17283b52007-05-04 18:47:51 +02003750 return cqr;
3751 }
3752
3753 ccw = cqr->cpaddr;
3754 ccw->cmd_code = CCW_CMD_RDC;
Stefan Haberlandd9fa9442009-10-14 12:43:48 +02003755 if (idal_is_needed(rdc_buffer, rdc_buffer_size)) {
3756 idaw = (unsigned long *) (cqr->data);
3757 ccw->cda = (__u32)(addr_t) idaw;
3758 ccw->flags = CCW_FLAG_IDA;
3759 idaw = idal_create_words(idaw, rdc_buffer, rdc_buffer_size);
3760 } else {
3761 ccw->cda = (__u32)(addr_t) rdc_buffer;
3762 ccw->flags = 0;
3763 }
Cornelia Huck17283b52007-05-04 18:47:51 +02003764
Stefan Haberlandd9fa9442009-10-14 12:43:48 +02003765 ccw->count = rdc_buffer_size;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003766 cqr->startdev = device;
3767 cqr->memdev = device;
Cornelia Huck17283b52007-05-04 18:47:51 +02003768 cqr->expires = 10*HZ;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01003769 cqr->retries = 256;
Heiko Carstens1aae0562013-01-30 09:49:40 +01003770 cqr->buildclk = get_tod_clock();
Cornelia Huck17283b52007-05-04 18:47:51 +02003771 cqr->status = DASD_CQR_FILLED;
3772 return cqr;
3773}
3774
3775
Stefan Haberland68b781f2009-09-11 10:28:29 +02003776int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
Sebastian Ott92636b12009-06-12 10:26:37 +02003777 void *rdc_buffer, int rdc_buffer_size)
Cornelia Huck17283b52007-05-04 18:47:51 +02003778{
3779 int ret;
3780 struct dasd_ccw_req *cqr;
3781
Sebastian Ott92636b12009-06-12 10:26:37 +02003782 cqr = dasd_generic_build_rdc(device, rdc_buffer, rdc_buffer_size,
Cornelia Huck17283b52007-05-04 18:47:51 +02003783 magic);
3784 if (IS_ERR(cqr))
3785 return PTR_ERR(cqr);
3786
3787 ret = dasd_sleep_on(cqr);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003788 dasd_sfree_request(cqr, cqr->memdev);
Cornelia Huck17283b52007-05-04 18:47:51 +02003789 return ret;
3790}
Cornelia Huckaaff0f62007-05-10 15:45:45 +02003791EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
Stefan Weinhuber20c64462006-03-24 03:15:25 -08003792
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003793/*
3794 * In command mode and transport mode we need to look for sense
3795 * data in different places. The sense data itself is allways
3796 * an array of 32 bytes, so we can unify the sense data access
3797 * for both modes.
3798 */
3799char *dasd_get_sense(struct irb *irb)
3800{
3801 struct tsb *tsb = NULL;
3802 char *sense = NULL;
3803
3804 if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
3805 if (irb->scsw.tm.tcw)
3806 tsb = tcw_get_tsb((struct tcw *)(unsigned long)
3807 irb->scsw.tm.tcw);
3808 if (tsb && tsb->length == 64 && tsb->flags)
3809 switch (tsb->flags & 0x07) {
3810 case 1: /* tsa_iostat */
3811 sense = tsb->tsa.iostat.sense;
3812 break;
3813 case 2: /* tsa_ddpc */
3814 sense = tsb->tsa.ddpc.sense;
3815 break;
3816 default:
3817 /* currently we don't use interrogate data */
3818 break;
3819 }
3820 } else if (irb->esw.esw0.erw.cons) {
3821 sense = irb->ecw;
3822 }
3823 return sense;
3824}
3825EXPORT_SYMBOL_GPL(dasd_get_sense);
3826
Stefan Haberland4679e892012-06-19 17:30:12 +02003827void dasd_generic_shutdown(struct ccw_device *cdev)
3828{
3829 struct dasd_device *device;
3830
3831 device = dasd_device_from_cdev(cdev);
3832 if (IS_ERR(device))
3833 return;
3834
3835 if (device->block)
3836 dasd_schedule_block_bh(device->block);
3837
3838 dasd_schedule_device_bh(device);
3839
3840 wait_event(shutdown_waitq, _wait_for_empty_queues(device));
3841}
3842EXPORT_SYMBOL_GPL(dasd_generic_shutdown);
3843
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003844static int __init dasd_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845{
3846 int rc;
3847
3848 init_waitqueue_head(&dasd_init_waitq);
Horst Hummel8f617012006-08-30 14:33:33 +02003849 init_waitqueue_head(&dasd_flush_wq);
Stefan Haberlandc80ee722008-05-30 10:03:31 +02003850 init_waitqueue_head(&generic_waitq);
Stefan Haberland4679e892012-06-19 17:30:12 +02003851 init_waitqueue_head(&shutdown_waitq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852
3853 /* register 'common' DASD debug area, used for all DBF_XXX calls */
Peter Tiedemann361f4942008-01-26 14:11:30 +01003854 dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 if (dasd_debug_area == NULL) {
3856 rc = -ENOMEM;
3857 goto failed;
3858 }
3859 debug_register_view(dasd_debug_area, &debug_sprintf_view);
Horst Hummelb0035f12006-09-20 15:59:07 +02003860 debug_set_level(dasd_debug_area, DBF_WARNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861
3862 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
3863
3864 dasd_diag_discipline_pointer = NULL;
3865
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02003866 dasd_statistics_createroot();
3867
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 rc = dasd_devmap_init();
3869 if (rc)
3870 goto failed;
3871 rc = dasd_gendisk_init();
3872 if (rc)
3873 goto failed;
3874 rc = dasd_parse();
3875 if (rc)
3876 goto failed;
Stefan Weinhuber20c64462006-03-24 03:15:25 -08003877 rc = dasd_eer_init();
3878 if (rc)
3879 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880#ifdef CONFIG_PROC_FS
3881 rc = dasd_proc_init();
3882 if (rc)
3883 goto failed;
3884#endif
3885
3886 return 0;
3887failed:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01003888 pr_info("The DASD device driver could not be initialized\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889 dasd_exit();
3890 return rc;
3891}
3892
3893module_init(dasd_init);
3894module_exit(dasd_exit);