blob: c89c26e401651ef05e126843757431394ca80b71 [file] [log] [blame]
Greg Kroah-Hartman6a55d2c2017-11-14 18:38:00 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Horst Hummel <Horst.Hummel@de.ibm.com>
5 * Carsten Otte <Cotte@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Bugreports.to..: <Linux390@de.ibm.com>
Stefan Haberlandd41dd122009-06-16 10:30:25 +02008 * Copyright IBM Corp. 1999, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
Stefan Haberlandfc19f382009-03-26 15:23:49 +010011#define KMSG_COMPONENT "dasd"
12#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/kmod.h>
15#include <linux/init.h>
16#include <linux/interrupt.h>
17#include <linux/ctype.h>
18#include <linux/major.h>
19#include <linux/slab.h>
Christoph Hellwiga885c8c2006-01-08 01:02:50 -080020#include <linux/hdreg.h>
Cornelia Huckf3445a12009-04-14 15:36:23 +020021#include <linux/async.h>
Stefan Haberland9eb25122010-02-26 22:37:46 +010022#include <linux/mutex.h>
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +020023#include <linux/debugfs.h>
24#include <linux/seq_file.h>
Stefan Weinhubere4258d52011-08-03 16:44:20 +020025#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#include <asm/ccwdev.h>
28#include <asm/ebcdic.h>
29#include <asm/idals.h>
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +010030#include <asm/itcw.h>
Stefan Weinhuber33b62a32010-03-08 12:26:24 +010031#include <asm/diag.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33/* This is ugly... */
34#define PRINTK_HEADER "dasd:"
35
36#include "dasd_int.h"
37/*
38 * SECTION: Constant definitions to be used within this file
39 */
40#define DASD_CHANQ_MAX_SIZE 4
41
Peter Oberparleiter7c53fcb2015-05-11 13:08:05 +020042#define DASD_DIAG_MOD "dasd_diag_mod"
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/*
45 * SECTION: exported variables of dasd.c
46 */
47debug_info_t *dasd_debug_area;
Fabian Frederick7048a2b2014-06-26 19:41:47 +020048EXPORT_SYMBOL(dasd_debug_area);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +020049static struct dentry *dasd_debugfs_root_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050struct dasd_discipline *dasd_diag_discipline_pointer;
Fabian Frederick7048a2b2014-06-26 19:41:47 +020051EXPORT_SYMBOL(dasd_diag_discipline_pointer);
Heiko Carstens2b67fc42007-02-05 21:16:47 +010052void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
55MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
Heiko Carstensa53c8fa2012-07-20 11:15:04 +020056 " Copyright IBM Corp. 2000");
Linus Torvalds1da177e2005-04-16 15:20:36 -070057MODULE_SUPPORTED_DEVICE("dasd");
Linus Torvalds1da177e2005-04-16 15:20:36 -070058MODULE_LICENSE("GPL");
59
60/*
61 * SECTION: prototypes for static functions of dasd.c
62 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010063static int dasd_alloc_queue(struct dasd_block *);
64static void dasd_setup_queue(struct dasd_block *);
65static void dasd_free_queue(struct dasd_block *);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010066static int dasd_flush_block_queue(struct dasd_block *);
67static void dasd_device_tasklet(struct dasd_device *);
68static void dasd_block_tasklet(struct dasd_block *);
Al Viro4927b3f2006-12-06 19:18:20 +000069static void do_kick_device(struct work_struct *);
Stefan Haberlandd41dd122009-06-16 10:30:25 +020070static void do_restore_device(struct work_struct *);
Stefan Haberland501183f2010-05-17 10:00:10 +020071static void do_reload_device(struct work_struct *);
Stefan Haberlanda521b042016-08-08 15:56:54 +020072static void do_requeue_requests(struct work_struct *);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010073static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
Kees Cooke99e88a2017-10-16 14:43:17 -070074static void dasd_device_timeout(struct timer_list *);
75static void dasd_block_timeout(struct timer_list *);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +010076static void __dasd_process_erp(struct dasd_device *, struct dasd_ccw_req *);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +020077static void dasd_profile_init(struct dasd_profile *, struct dentry *);
78static void dasd_profile_exit(struct dasd_profile *);
Stefan Haberland5a3b7b12016-03-18 09:42:13 +010079static void dasd_hosts_init(struct dentry *, struct dasd_device *);
80static void dasd_hosts_exit(struct dasd_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82/*
83 * SECTION: Operations on the device structure.
84 */
85static wait_queue_head_t dasd_init_waitq;
Horst Hummel8f617012006-08-30 14:33:33 +020086static wait_queue_head_t dasd_flush_wq;
Stefan Haberlandc80ee722008-05-30 10:03:31 +020087static wait_queue_head_t generic_waitq;
Stefan Haberland4679e892012-06-19 17:30:12 +020088static wait_queue_head_t shutdown_waitq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90/*
91 * Allocate memory for a new device structure.
92 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010093struct dasd_device *dasd_alloc_device(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
95 struct dasd_device *device;
96
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010097 device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
98 if (!device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101 /* Get two pages for normal block device operations. */
102 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100103 if (!device->ccw_mem) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 kfree(device);
105 return ERR_PTR(-ENOMEM);
106 }
107 /* Get one page for error recovery. */
108 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100109 if (!device->erp_mem) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 free_pages((unsigned long) device->ccw_mem, 1);
111 kfree(device);
112 return ERR_PTR(-ENOMEM);
113 }
114
115 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
116 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
117 spin_lock_init(&device->mem_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100118 atomic_set(&device->tasklet_scheduled, 0);
Horst Hummel138c0142006-06-29 14:58:12 +0200119 tasklet_init(&device->tasklet,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100120 (void (*)(unsigned long)) dasd_device_tasklet,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 (unsigned long) device);
122 INIT_LIST_HEAD(&device->ccw_queue);
Kees Cooke99e88a2017-10-16 14:43:17 -0700123 timer_setup(&device->timer, dasd_device_timeout, 0);
Al Viro4927b3f2006-12-06 19:18:20 +0000124 INIT_WORK(&device->kick_work, do_kick_device);
Stefan Haberlandd41dd122009-06-16 10:30:25 +0200125 INIT_WORK(&device->restore_device, do_restore_device);
Stefan Haberland501183f2010-05-17 10:00:10 +0200126 INIT_WORK(&device->reload_device, do_reload_device);
Stefan Haberlanda521b042016-08-08 15:56:54 +0200127 INIT_WORK(&device->requeue_requests, do_requeue_requests);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 device->state = DASD_STATE_NEW;
129 device->target = DASD_STATE_NEW;
Stefan Haberland9eb25122010-02-26 22:37:46 +0100130 mutex_init(&device->state_mutex);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200131 spin_lock_init(&device->profile.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 return device;
133}
134
135/*
136 * Free memory of a device structure.
137 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100138void dasd_free_device(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Jesper Juhl17fd6822005-11-07 01:01:30 -0800140 kfree(device->private);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 free_page((unsigned long) device->erp_mem);
142 free_pages((unsigned long) device->ccw_mem, 1);
143 kfree(device);
144}
145
146/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100147 * Allocate memory for a new device structure.
148 */
149struct dasd_block *dasd_alloc_block(void)
150{
151 struct dasd_block *block;
152
153 block = kzalloc(sizeof(*block), GFP_ATOMIC);
154 if (!block)
155 return ERR_PTR(-ENOMEM);
156 /* open_count = 0 means device online but not in use */
157 atomic_set(&block->open_count, -1);
158
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100159 atomic_set(&block->tasklet_scheduled, 0);
160 tasklet_init(&block->tasklet,
161 (void (*)(unsigned long)) dasd_block_tasklet,
162 (unsigned long) block);
163 INIT_LIST_HEAD(&block->ccw_queue);
164 spin_lock_init(&block->queue_lock);
Kees Cooke99e88a2017-10-16 14:43:17 -0700165 timer_setup(&block->timer, dasd_block_timeout, 0);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200166 spin_lock_init(&block->profile.lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100167
168 return block;
169}
Fabian Frederick7048a2b2014-06-26 19:41:47 +0200170EXPORT_SYMBOL_GPL(dasd_alloc_block);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100171
172/*
173 * Free memory of a device structure.
174 */
175void dasd_free_block(struct dasd_block *block)
176{
177 kfree(block);
178}
Fabian Frederick7048a2b2014-06-26 19:41:47 +0200179EXPORT_SYMBOL_GPL(dasd_free_block);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100180
181/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 * Make a new device known to the system.
183 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100184static int dasd_state_new_to_known(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
186 int rc;
187
188 /*
Horst Hummel138c0142006-06-29 14:58:12 +0200189 * As long as the device is not in state DASD_STATE_NEW we want to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 * keep the reference count > 0.
191 */
192 dasd_get_device(device);
193
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100194 if (device->block) {
195 rc = dasd_alloc_queue(device->block);
196 if (rc) {
197 dasd_put_device(device);
198 return rc;
199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 device->state = DASD_STATE_KNOWN;
202 return 0;
203}
204
205/*
206 * Let the system forget about a device.
207 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100208static int dasd_state_known_to_new(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Stefan Weinhuber20c64462006-03-24 03:15:25 -0800210 /* Disable extended error reporting for this device. */
211 dasd_eer_disable(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 device->state = DASD_STATE_NEW;
213
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100214 if (device->block)
215 dasd_free_queue(device->block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 /* Give up reference we took in dasd_state_new_to_known. */
218 dasd_put_device(device);
Horst Hummel8f617012006-08-30 14:33:33 +0200219 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220}
221
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200222static struct dentry *dasd_debugfs_setup(const char *name,
223 struct dentry *base_dentry)
224{
225 struct dentry *pde;
226
227 if (!base_dentry)
228 return NULL;
229 pde = debugfs_create_dir(name, base_dentry);
230 if (!pde || IS_ERR(pde))
231 return NULL;
232 return pde;
233}
234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235/*
236 * Request the irq line for the device.
237 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100238static int dasd_state_known_to_basic(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200240 struct dasd_block *block = device->block;
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200241 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243 /* Allocate and register gendisk structure. */
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200244 if (block) {
245 rc = dasd_gendisk_alloc(block);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100246 if (rc)
247 return rc;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200248 block->debugfs_dentry =
249 dasd_debugfs_setup(block->gdp->disk_name,
250 dasd_debugfs_root_entry);
251 dasd_profile_init(&block->profile, block->debugfs_dentry);
252 if (dasd_global_profile_level == DASD_PROFILE_ON)
253 dasd_profile_on(&device->block->profile);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100254 }
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200255 device->debugfs_dentry =
256 dasd_debugfs_setup(dev_name(&device->cdev->dev),
257 dasd_debugfs_root_entry);
258 dasd_profile_init(&device->profile, device->debugfs_dentry);
Stefan Haberland5a3b7b12016-03-18 09:42:13 +0100259 dasd_hosts_init(device->debugfs_dentry, device);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100262 device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100263 8 * sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 debug_register_view(device->debug_area, &debug_sprintf_view);
Horst Hummelb0035f12006-09-20 15:59:07 +0200265 debug_set_level(device->debug_area, DBF_WARNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
267
268 device->state = DASD_STATE_BASIC;
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200269
270 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271}
272
273/*
274 * Release the irq line for the device. Terminate any running i/o.
275 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100276static int dasd_state_basic_to_known(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
Horst Hummel8f617012006-08-30 14:33:33 +0200278 int rc;
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200279
Stefan Haberlanddaa991b2014-07-18 14:19:25 +0200280 if (device->discipline->basic_to_known) {
281 rc = device->discipline->basic_to_known(device);
282 if (rc)
283 return rc;
284 }
285
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100286 if (device->block) {
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200287 dasd_profile_exit(&device->block->profile);
Fabian Frederickd7309aa2014-06-26 19:41:46 +0200288 debugfs_remove(device->block->debugfs_dentry);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100289 dasd_gendisk_free(device->block);
290 dasd_block_clear_timer(device->block);
291 }
292 rc = dasd_flush_device_queue(device);
Horst Hummel8f617012006-08-30 14:33:33 +0200293 if (rc)
294 return rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100295 dasd_device_clear_timer(device);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200296 dasd_profile_exit(&device->profile);
Stefan Haberland5a3b7b12016-03-18 09:42:13 +0100297 dasd_hosts_exit(device);
Fabian Frederickd7309aa2014-06-26 19:41:46 +0200298 debugfs_remove(device->debugfs_dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
300 if (device->debug_area != NULL) {
301 debug_unregister(device->debug_area);
302 device->debug_area = NULL;
303 }
304 device->state = DASD_STATE_KNOWN;
Horst Hummel8f617012006-08-30 14:33:33 +0200305 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306}
307
308/*
309 * Do the initial analysis. The do_analysis function may return
310 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
311 * until the discipline decides to continue the startup sequence
312 * by calling the function dasd_change_state. The eckd disciplines
313 * uses this to start a ccw that detects the format. The completion
314 * interrupt for this detection ccw uses the kernel event daemon to
315 * trigger the call to dasd_change_state. All this is done in the
316 * discipline code, see dasd_eckd.c.
Horst Hummel90f00942006-03-07 21:55:39 -0800317 * After the analysis ccw is done (do_analysis returned 0) the block
318 * device is setup.
319 * In case the analysis returns an error, the device setup is stopped
320 * (a fake disk was already added to allow formatting).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100322static int dasd_state_basic_to_ready(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
324 int rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100325 struct dasd_block *block;
Stefan Haberlandeed5c4b2016-08-31 13:31:10 +0200326 struct gendisk *disk;
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 Haberlandeed5c4b2016-08-31 13:31:10 +0200337 disk = device->block->gdp;
338 kobject_uevent(&disk_to_dev(disk)->kobj,
339 KOBJ_CHANGE);
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200340 goto out;
341 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100342 return rc;
343 }
344 dasd_setup_queue(block);
345 set_capacity(block->gdp,
346 block->blocks << block->s2b_shift);
347 device->state = DASD_STATE_READY;
348 rc = dasd_scan_partitions(block);
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200349 if (rc) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100350 device->state = DASD_STATE_BASIC;
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200351 return rc;
352 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100353 } else {
354 device->state = DASD_STATE_READY;
355 }
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200356out:
357 if (device->discipline->basic_to_ready)
358 rc = device->discipline->basic_to_ready(device);
Horst Hummel90f00942006-03-07 21:55:39 -0800359 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360}
361
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +0100362static inline
363int _wait_for_empty_queues(struct dasd_device *device)
364{
365 if (device->block)
366 return list_empty(&device->ccw_queue) &&
367 list_empty(&device->block->ccw_queue);
368 else
369 return list_empty(&device->ccw_queue);
370}
371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372/*
373 * Remove device from block device layer. Destroy dirty buffers.
374 * Forget format information. Check if the target level is basic
375 * and if it is create fake disk for formatting.
376 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100377static int dasd_state_ready_to_basic(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
Horst Hummel8f617012006-08-30 14:33:33 +0200379 int rc;
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 device->state = DASD_STATE_BASIC;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100382 if (device->block) {
383 struct dasd_block *block = device->block;
384 rc = dasd_flush_block_queue(block);
385 if (rc) {
386 device->state = DASD_STATE_READY;
387 return rc;
388 }
Stefan Haberlandb695adf2010-02-26 22:37:48 +0100389 dasd_destroy_partitions(block);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100390 block->blocks = 0;
391 block->bp_block = 0;
392 block->s2b_shift = 0;
393 }
Horst Hummel8f617012006-08-30 14:33:33 +0200394 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395}
396
397/*
Horst Hummel90f00942006-03-07 21:55:39 -0800398 * Back to basic.
399 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100400static int dasd_state_unfmt_to_basic(struct dasd_device *device)
Horst Hummel90f00942006-03-07 21:55:39 -0800401{
402 device->state = DASD_STATE_BASIC;
Horst Hummel8f617012006-08-30 14:33:33 +0200403 return 0;
Horst Hummel90f00942006-03-07 21:55:39 -0800404}
405
406/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 * Make the device online and schedule the bottom half to start
408 * the requeueing of requests from the linux request queue to the
409 * ccw queue.
410 */
Horst Hummel8f617012006-08-30 14:33:33 +0200411static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412dasd_state_ready_to_online(struct dasd_device * device)
413{
Stefan Weinhuber13018092009-01-09 12:14:50 +0100414 struct gendisk *disk;
415 struct disk_part_iter piter;
416 struct hd_struct *part;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 device->state = DASD_STATE_ONLINE;
Stefan Weinhuber13018092009-01-09 12:14:50 +0100419 if (device->block) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100420 dasd_schedule_block_bh(device->block);
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100421 if ((device->features & DASD_FEATURE_USERAW)) {
422 disk = device->block->gdp;
423 kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
424 return 0;
425 }
Stefan Weinhuber13018092009-01-09 12:14:50 +0100426 disk = device->block->bdev->bd_disk;
427 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
428 while ((part = disk_part_iter_next(&piter)))
429 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
430 disk_part_iter_exit(&piter);
431 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 return 0;
433}
434
435/*
436 * Stop the requeueing of requests again.
437 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100438static int dasd_state_online_to_ready(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100440 int rc;
Stefan Weinhuber13018092009-01-09 12:14:50 +0100441 struct gendisk *disk;
442 struct disk_part_iter piter;
443 struct hd_struct *part;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100444
445 if (device->discipline->online_to_ready) {
446 rc = device->discipline->online_to_ready(device);
447 if (rc)
448 return rc;
449 }
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 device->state = DASD_STATE_READY;
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100452 if (device->block && !(device->features & DASD_FEATURE_USERAW)) {
Stefan Weinhuber13018092009-01-09 12:14:50 +0100453 disk = device->block->bdev->bd_disk;
454 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
455 while ((part = disk_part_iter_next(&piter)))
456 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
457 disk_part_iter_exit(&piter);
458 }
Horst Hummel8f617012006-08-30 14:33:33 +0200459 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460}
461
462/*
463 * Device startup state changes.
464 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100465static int dasd_increase_state(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466{
467 int rc;
468
469 rc = 0;
470 if (device->state == DASD_STATE_NEW &&
471 device->target >= DASD_STATE_KNOWN)
472 rc = dasd_state_new_to_known(device);
473
474 if (!rc &&
475 device->state == DASD_STATE_KNOWN &&
476 device->target >= DASD_STATE_BASIC)
477 rc = dasd_state_known_to_basic(device);
478
479 if (!rc &&
480 device->state == DASD_STATE_BASIC &&
481 device->target >= DASD_STATE_READY)
482 rc = dasd_state_basic_to_ready(device);
483
484 if (!rc &&
Horst Hummel39ccf952006-04-27 18:40:10 -0700485 device->state == DASD_STATE_UNFMT &&
486 device->target > DASD_STATE_UNFMT)
487 rc = -EPERM;
488
489 if (!rc &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 device->state == DASD_STATE_READY &&
491 device->target >= DASD_STATE_ONLINE)
492 rc = dasd_state_ready_to_online(device);
493
494 return rc;
495}
496
497/*
498 * Device shutdown state changes.
499 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100500static int dasd_decrease_state(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
Horst Hummel8f617012006-08-30 14:33:33 +0200502 int rc;
503
504 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 if (device->state == DASD_STATE_ONLINE &&
506 device->target <= DASD_STATE_READY)
Horst Hummel8f617012006-08-30 14:33:33 +0200507 rc = dasd_state_online_to_ready(device);
Horst Hummel138c0142006-06-29 14:58:12 +0200508
Horst Hummel8f617012006-08-30 14:33:33 +0200509 if (!rc &&
510 device->state == DASD_STATE_READY &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 device->target <= DASD_STATE_BASIC)
Horst Hummel8f617012006-08-30 14:33:33 +0200512 rc = dasd_state_ready_to_basic(device);
Horst Hummel90f00942006-03-07 21:55:39 -0800513
Horst Hummel8f617012006-08-30 14:33:33 +0200514 if (!rc &&
515 device->state == DASD_STATE_UNFMT &&
Horst Hummel90f00942006-03-07 21:55:39 -0800516 device->target <= DASD_STATE_BASIC)
Horst Hummel8f617012006-08-30 14:33:33 +0200517 rc = dasd_state_unfmt_to_basic(device);
Horst Hummel90f00942006-03-07 21:55:39 -0800518
Horst Hummel8f617012006-08-30 14:33:33 +0200519 if (!rc &&
520 device->state == DASD_STATE_BASIC &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 device->target <= DASD_STATE_KNOWN)
Horst Hummel8f617012006-08-30 14:33:33 +0200522 rc = dasd_state_basic_to_known(device);
Horst Hummel138c0142006-06-29 14:58:12 +0200523
Horst Hummel8f617012006-08-30 14:33:33 +0200524 if (!rc &&
525 device->state == DASD_STATE_KNOWN &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 device->target <= DASD_STATE_NEW)
Horst Hummel8f617012006-08-30 14:33:33 +0200527 rc = dasd_state_known_to_new(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Horst Hummel8f617012006-08-30 14:33:33 +0200529 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530}
531
532/*
533 * This is the main startup/shutdown routine.
534 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100535static void dasd_change_state(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536{
Sebastian Ott181d9522009-06-22 12:08:21 +0200537 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
539 if (device->state == device->target)
540 /* Already where we want to go today... */
541 return;
542 if (device->state < device->target)
543 rc = dasd_increase_state(device);
544 else
545 rc = dasd_decrease_state(device);
Sebastian Ott181d9522009-06-22 12:08:21 +0200546 if (rc == -EAGAIN)
547 return;
548 if (rc)
549 device->target = device->state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Horst Hummel4dfd5c42007-04-27 16:01:47 +0200551 /* let user-space know that the device status changed */
552 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
Sebastian Ott1f08be82012-09-05 14:18:22 +0200553
554 if (device->state == device->target)
555 wake_up(&dasd_init_waitq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556}
557
558/*
559 * Kick starter for devices that did not complete the startup/shutdown
560 * procedure or were sleeping because of a pending state.
561 * dasd_kick_device will schedule a call do do_kick_device to the kernel
562 * event daemon.
563 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100564static void do_kick_device(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565{
Al Viro4927b3f2006-12-06 19:18:20 +0000566 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
Stefan Haberland9eb25122010-02-26 22:37:46 +0100567 mutex_lock(&device->state_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 dasd_change_state(device);
Stefan Haberland9eb25122010-02-26 22:37:46 +0100569 mutex_unlock(&device->state_mutex);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100570 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 dasd_put_device(device);
572}
573
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100574void dasd_kick_device(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575{
576 dasd_get_device(device);
577 /* queue call to dasd_kick_device to the kernel event daemon. */
Stefan Haberlandf2608cd2015-04-02 12:27:25 +0200578 if (!schedule_work(&device->kick_work))
579 dasd_put_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580}
Fabian Frederick7048a2b2014-06-26 19:41:47 +0200581EXPORT_SYMBOL(dasd_kick_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583/*
Stefan Haberland501183f2010-05-17 10:00:10 +0200584 * dasd_reload_device will schedule a call do do_reload_device to the kernel
585 * event daemon.
586 */
587static void do_reload_device(struct work_struct *work)
588{
589 struct dasd_device *device = container_of(work, struct dasd_device,
590 reload_device);
591 device->discipline->reload(device);
592 dasd_put_device(device);
593}
594
595void dasd_reload_device(struct dasd_device *device)
596{
597 dasd_get_device(device);
598 /* queue call to dasd_reload_device to the kernel event daemon. */
Stefan Haberlandf2608cd2015-04-02 12:27:25 +0200599 if (!schedule_work(&device->reload_device))
600 dasd_put_device(device);
Stefan Haberland501183f2010-05-17 10:00:10 +0200601}
602EXPORT_SYMBOL(dasd_reload_device);
603
604/*
Stefan Haberlandd41dd122009-06-16 10:30:25 +0200605 * dasd_restore_device will schedule a call do do_restore_device to the kernel
606 * event daemon.
607 */
608static void do_restore_device(struct work_struct *work)
609{
610 struct dasd_device *device = container_of(work, struct dasd_device,
611 restore_device);
612 device->cdev->drv->restore(device->cdev);
613 dasd_put_device(device);
614}
615
616void dasd_restore_device(struct dasd_device *device)
617{
618 dasd_get_device(device);
619 /* queue call to dasd_restore_device to the kernel event daemon. */
Stefan Haberlandf2608cd2015-04-02 12:27:25 +0200620 if (!schedule_work(&device->restore_device))
621 dasd_put_device(device);
Stefan Haberlandd41dd122009-06-16 10:30:25 +0200622}
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
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100676struct dasd_profile dasd_global_profile = {
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100677 .lock = __SPIN_LOCK_UNLOCKED(dasd_global_profile.lock),
678};
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200679static struct dentry *dasd_debugfs_global_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
681/*
682 * Add profiling information for cqr before execution.
683 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100684static void dasd_profile_start(struct dasd_block *block,
685 struct dasd_ccw_req *cqr,
686 struct request *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687{
688 struct list_head *l;
689 unsigned int counter;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200690 struct dasd_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
692 /* count the length of the chanq for statistics */
693 counter = 0;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200694 if (dasd_global_profile_level || block->profile.data)
695 list_for_each(l, &block->ccw_queue)
696 if (++counter >= 31)
697 break;
698
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100699 spin_lock(&dasd_global_profile.lock);
Sebastian Ott6765cc22015-01-28 19:06:29 +0100700 if (dasd_global_profile.data) {
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100701 dasd_global_profile.data->dasd_io_nr_req[counter]++;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200702 if (rq_data_dir(req) == READ)
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100703 dasd_global_profile.data->dasd_read_nr_req[counter]++;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200704 }
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100705 spin_unlock(&dasd_global_profile.lock);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200706
707 spin_lock(&block->profile.lock);
Stefan Weinhuberc81a90c2013-10-25 11:08:06 +0200708 if (block->profile.data) {
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200709 block->profile.data->dasd_io_nr_req[counter]++;
710 if (rq_data_dir(req) == READ)
711 block->profile.data->dasd_read_nr_req[counter]++;
Stefan Weinhuberc81a90c2013-10-25 11:08:06 +0200712 }
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200713 spin_unlock(&block->profile.lock);
714
715 /*
716 * We count the request for the start device, even though it may run on
717 * some other device due to error recovery. This way we make sure that
718 * we count each request only once.
719 */
720 device = cqr->startdev;
721 if (device->profile.data) {
722 counter = 1; /* request is not yet queued on the start device */
723 list_for_each(l, &device->ccw_queue)
724 if (++counter >= 31)
725 break;
726 }
727 spin_lock(&device->profile.lock);
728 if (device->profile.data) {
729 device->profile.data->dasd_io_nr_req[counter]++;
730 if (rq_data_dir(req) == READ)
731 device->profile.data->dasd_read_nr_req[counter]++;
732 }
733 spin_unlock(&device->profile.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734}
735
736/*
737 * Add profiling information for cqr after execution.
738 */
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200739
740#define dasd_profile_counter(value, index) \
741{ \
742 for (index = 0; index < 31 && value >> (2+index); index++) \
743 ; \
744}
745
746static void dasd_profile_end_add_data(struct dasd_profile_info *data,
747 int is_alias,
748 int is_tpm,
749 int is_read,
750 long sectors,
751 int sectors_ind,
752 int tottime_ind,
753 int tottimeps_ind,
754 int strtime_ind,
755 int irqtime_ind,
756 int irqtimeps_ind,
757 int endtime_ind)
758{
759 /* in case of an overflow, reset the whole profile */
760 if (data->dasd_io_reqs == UINT_MAX) {
761 memset(data, 0, sizeof(*data));
Arnd Bergmannbd7a9b32017-11-27 12:46:57 +0100762 ktime_get_real_ts64(&data->starttod);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200763 }
764 data->dasd_io_reqs++;
765 data->dasd_io_sects += sectors;
766 if (is_alias)
767 data->dasd_io_alias++;
768 if (is_tpm)
769 data->dasd_io_tpm++;
770
771 data->dasd_io_secs[sectors_ind]++;
772 data->dasd_io_times[tottime_ind]++;
773 data->dasd_io_timps[tottimeps_ind]++;
774 data->dasd_io_time1[strtime_ind]++;
775 data->dasd_io_time2[irqtime_ind]++;
776 data->dasd_io_time2ps[irqtimeps_ind]++;
777 data->dasd_io_time3[endtime_ind]++;
778
779 if (is_read) {
780 data->dasd_read_reqs++;
781 data->dasd_read_sects += sectors;
782 if (is_alias)
783 data->dasd_read_alias++;
784 if (is_tpm)
785 data->dasd_read_tpm++;
786 data->dasd_read_secs[sectors_ind]++;
787 data->dasd_read_times[tottime_ind]++;
788 data->dasd_read_time1[strtime_ind]++;
789 data->dasd_read_time2[irqtime_ind]++;
790 data->dasd_read_time3[endtime_ind]++;
791 }
792}
793
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100794static void dasd_profile_end(struct dasd_block *block,
795 struct dasd_ccw_req *cqr,
796 struct request *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797{
Stefan Haberlandd2907222017-07-14 10:33:18 +0200798 unsigned long strtime, irqtime, endtime, tottime;
799 unsigned long tottimeps, sectors;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200800 struct dasd_device *device;
801 int sectors_ind, tottime_ind, tottimeps_ind, strtime_ind;
802 int irqtime_ind, irqtimeps_ind, endtime_ind;
Stefan Haberlandd2907222017-07-14 10:33:18 +0200803 struct dasd_profile_info *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200805 device = cqr->startdev;
806 if (!(dasd_global_profile_level ||
807 block->profile.data ||
808 device->profile.data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 return;
810
Tejun Heo83096eb2009-05-07 22:24:39 +0900811 sectors = blk_rq_sectors(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 if (!cqr->buildclk || !cqr->startclk ||
813 !cqr->stopclk || !cqr->endclk ||
814 !sectors)
815 return;
816
817 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
818 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
819 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
820 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
821 tottimeps = tottime / sectors;
822
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200823 dasd_profile_counter(sectors, sectors_ind);
824 dasd_profile_counter(tottime, tottime_ind);
825 dasd_profile_counter(tottimeps, tottimeps_ind);
826 dasd_profile_counter(strtime, strtime_ind);
827 dasd_profile_counter(irqtime, irqtime_ind);
828 dasd_profile_counter(irqtime / sectors, irqtimeps_ind);
829 dasd_profile_counter(endtime, endtime_ind);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100831 spin_lock(&dasd_global_profile.lock);
Sebastian Ott6765cc22015-01-28 19:06:29 +0100832 if (dasd_global_profile.data) {
Stefan Haberlandd2907222017-07-14 10:33:18 +0200833 data = dasd_global_profile.data;
834 data->dasd_sum_times += tottime;
835 data->dasd_sum_time_str += strtime;
836 data->dasd_sum_time_irq += irqtime;
837 data->dasd_sum_time_end += endtime;
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100838 dasd_profile_end_add_data(dasd_global_profile.data,
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200839 cqr->startdev != block->base,
840 cqr->cpmode == 1,
841 rq_data_dir(req) == READ,
842 sectors, sectors_ind, tottime_ind,
843 tottimeps_ind, strtime_ind,
844 irqtime_ind, irqtimeps_ind,
845 endtime_ind);
846 }
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100847 spin_unlock(&dasd_global_profile.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200849 spin_lock(&block->profile.lock);
Stefan Haberlandd2907222017-07-14 10:33:18 +0200850 if (block->profile.data) {
851 data = block->profile.data;
852 data->dasd_sum_times += tottime;
853 data->dasd_sum_time_str += strtime;
854 data->dasd_sum_time_irq += irqtime;
855 data->dasd_sum_time_end += endtime;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200856 dasd_profile_end_add_data(block->profile.data,
857 cqr->startdev != block->base,
858 cqr->cpmode == 1,
859 rq_data_dir(req) == READ,
860 sectors, sectors_ind, tottime_ind,
861 tottimeps_ind, strtime_ind,
862 irqtime_ind, irqtimeps_ind,
863 endtime_ind);
Stefan Haberlandd2907222017-07-14 10:33:18 +0200864 }
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200865 spin_unlock(&block->profile.lock);
866
867 spin_lock(&device->profile.lock);
Stefan Haberlandd2907222017-07-14 10:33:18 +0200868 if (device->profile.data) {
869 data = device->profile.data;
870 data->dasd_sum_times += tottime;
871 data->dasd_sum_time_str += strtime;
872 data->dasd_sum_time_irq += irqtime;
873 data->dasd_sum_time_end += endtime;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200874 dasd_profile_end_add_data(device->profile.data,
875 cqr->startdev != block->base,
876 cqr->cpmode == 1,
877 rq_data_dir(req) == READ,
878 sectors, sectors_ind, tottime_ind,
879 tottimeps_ind, strtime_ind,
880 irqtime_ind, irqtimeps_ind,
881 endtime_ind);
Stefan Haberlandd2907222017-07-14 10:33:18 +0200882 }
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200883 spin_unlock(&device->profile.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884}
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200885
886void dasd_profile_reset(struct dasd_profile *profile)
887{
888 struct dasd_profile_info *data;
889
890 spin_lock_bh(&profile->lock);
891 data = profile->data;
892 if (!data) {
893 spin_unlock_bh(&profile->lock);
894 return;
895 }
896 memset(data, 0, sizeof(*data));
Arnd Bergmannbd7a9b32017-11-27 12:46:57 +0100897 ktime_get_real_ts64(&data->starttod);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200898 spin_unlock_bh(&profile->lock);
899}
900
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200901int dasd_profile_on(struct dasd_profile *profile)
902{
903 struct dasd_profile_info *data;
904
905 data = kzalloc(sizeof(*data), GFP_KERNEL);
906 if (!data)
907 return -ENOMEM;
908 spin_lock_bh(&profile->lock);
909 if (profile->data) {
910 spin_unlock_bh(&profile->lock);
911 kfree(data);
912 return 0;
913 }
Arnd Bergmannbd7a9b32017-11-27 12:46:57 +0100914 ktime_get_real_ts64(&data->starttod);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200915 profile->data = data;
916 spin_unlock_bh(&profile->lock);
917 return 0;
918}
919
920void dasd_profile_off(struct dasd_profile *profile)
921{
922 spin_lock_bh(&profile->lock);
923 kfree(profile->data);
924 profile->data = NULL;
925 spin_unlock_bh(&profile->lock);
926}
927
928char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
929{
930 char *buffer;
931
Stefan Weinhubere4258d52011-08-03 16:44:20 +0200932 buffer = vmalloc(user_len + 1);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200933 if (buffer == NULL)
934 return ERR_PTR(-ENOMEM);
935 if (copy_from_user(buffer, user_buf, user_len) != 0) {
Stefan Weinhubere4258d52011-08-03 16:44:20 +0200936 vfree(buffer);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200937 return ERR_PTR(-EFAULT);
938 }
939 /* got the string, now strip linefeed. */
940 if (buffer[user_len - 1] == '\n')
941 buffer[user_len - 1] = 0;
942 else
943 buffer[user_len] = 0;
944 return buffer;
945}
946
947static ssize_t dasd_stats_write(struct file *file,
948 const char __user *user_buf,
949 size_t user_len, loff_t *pos)
950{
951 char *buffer, *str;
952 int rc;
953 struct seq_file *m = (struct seq_file *)file->private_data;
954 struct dasd_profile *prof = m->private;
955
956 if (user_len > 65536)
957 user_len = 65536;
958 buffer = dasd_get_user_string(user_buf, user_len);
959 if (IS_ERR(buffer))
960 return PTR_ERR(buffer);
961
962 str = skip_spaces(buffer);
963 rc = user_len;
964 if (strncmp(str, "reset", 5) == 0) {
965 dasd_profile_reset(prof);
966 } else if (strncmp(str, "on", 2) == 0) {
967 rc = dasd_profile_on(prof);
Sebastian Ott6765cc22015-01-28 19:06:29 +0100968 if (rc)
969 goto out;
970 rc = user_len;
971 if (prof == &dasd_global_profile) {
972 dasd_profile_reset(prof);
973 dasd_global_profile_level = DASD_PROFILE_GLOBAL_ONLY;
974 }
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200975 } else if (strncmp(str, "off", 3) == 0) {
Sebastian Ott6765cc22015-01-28 19:06:29 +0100976 if (prof == &dasd_global_profile)
977 dasd_global_profile_level = DASD_PROFILE_OFF;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200978 dasd_profile_off(prof);
979 } else
980 rc = -EINVAL;
Sebastian Ott6765cc22015-01-28 19:06:29 +0100981out:
Stefan Weinhubere4258d52011-08-03 16:44:20 +0200982 vfree(buffer);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200983 return rc;
984}
985
986static void dasd_stats_array(struct seq_file *m, unsigned int *array)
987{
988 int i;
989
990 for (i = 0; i < 32; i++)
991 seq_printf(m, "%u ", array[i]);
992 seq_putc(m, '\n');
993}
994
995static void dasd_stats_seq_print(struct seq_file *m,
996 struct dasd_profile_info *data)
997{
Arnd Bergmannbd7a9b32017-11-27 12:46:57 +0100998 seq_printf(m, "start_time %lld.%09ld\n",
999 (s64)data->starttod.tv_sec, data->starttod.tv_nsec);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001000 seq_printf(m, "total_requests %u\n", data->dasd_io_reqs);
1001 seq_printf(m, "total_sectors %u\n", data->dasd_io_sects);
1002 seq_printf(m, "total_pav %u\n", data->dasd_io_alias);
1003 seq_printf(m, "total_hpf %u\n", data->dasd_io_tpm);
Stefan Haberlandd2907222017-07-14 10:33:18 +02001004 seq_printf(m, "avg_total %lu\n", data->dasd_io_reqs ?
1005 data->dasd_sum_times / data->dasd_io_reqs : 0UL);
1006 seq_printf(m, "avg_build_to_ssch %lu\n", data->dasd_io_reqs ?
1007 data->dasd_sum_time_str / data->dasd_io_reqs : 0UL);
1008 seq_printf(m, "avg_ssch_to_irq %lu\n", data->dasd_io_reqs ?
1009 data->dasd_sum_time_irq / data->dasd_io_reqs : 0UL);
1010 seq_printf(m, "avg_irq_to_end %lu\n", data->dasd_io_reqs ?
1011 data->dasd_sum_time_end / data->dasd_io_reqs : 0UL);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001012 seq_puts(m, "histogram_sectors ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001013 dasd_stats_array(m, data->dasd_io_secs);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001014 seq_puts(m, "histogram_io_times ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001015 dasd_stats_array(m, data->dasd_io_times);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001016 seq_puts(m, "histogram_io_times_weighted ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001017 dasd_stats_array(m, data->dasd_io_timps);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001018 seq_puts(m, "histogram_time_build_to_ssch ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001019 dasd_stats_array(m, data->dasd_io_time1);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001020 seq_puts(m, "histogram_time_ssch_to_irq ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001021 dasd_stats_array(m, data->dasd_io_time2);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001022 seq_puts(m, "histogram_time_ssch_to_irq_weighted ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001023 dasd_stats_array(m, data->dasd_io_time2ps);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001024 seq_puts(m, "histogram_time_irq_to_end ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001025 dasd_stats_array(m, data->dasd_io_time3);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001026 seq_puts(m, "histogram_ccw_queue_length ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001027 dasd_stats_array(m, data->dasd_io_nr_req);
1028 seq_printf(m, "total_read_requests %u\n", data->dasd_read_reqs);
1029 seq_printf(m, "total_read_sectors %u\n", data->dasd_read_sects);
1030 seq_printf(m, "total_read_pav %u\n", data->dasd_read_alias);
1031 seq_printf(m, "total_read_hpf %u\n", data->dasd_read_tpm);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001032 seq_puts(m, "histogram_read_sectors ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001033 dasd_stats_array(m, data->dasd_read_secs);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001034 seq_puts(m, "histogram_read_times ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001035 dasd_stats_array(m, data->dasd_read_times);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001036 seq_puts(m, "histogram_read_time_build_to_ssch ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001037 dasd_stats_array(m, data->dasd_read_time1);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001038 seq_puts(m, "histogram_read_time_ssch_to_irq ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001039 dasd_stats_array(m, data->dasd_read_time2);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001040 seq_puts(m, "histogram_read_time_irq_to_end ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001041 dasd_stats_array(m, data->dasd_read_time3);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001042 seq_puts(m, "histogram_read_ccw_queue_length ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001043 dasd_stats_array(m, data->dasd_read_nr_req);
1044}
1045
1046static int dasd_stats_show(struct seq_file *m, void *v)
1047{
1048 struct dasd_profile *profile;
1049 struct dasd_profile_info *data;
1050
1051 profile = m->private;
1052 spin_lock_bh(&profile->lock);
1053 data = profile->data;
1054 if (!data) {
1055 spin_unlock_bh(&profile->lock);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001056 seq_puts(m, "disabled\n");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001057 return 0;
1058 }
1059 dasd_stats_seq_print(m, data);
1060 spin_unlock_bh(&profile->lock);
1061 return 0;
1062}
1063
1064static int dasd_stats_open(struct inode *inode, struct file *file)
1065{
1066 struct dasd_profile *profile = inode->i_private;
1067 return single_open(file, dasd_stats_show, profile);
1068}
1069
1070static const struct file_operations dasd_stats_raw_fops = {
1071 .owner = THIS_MODULE,
1072 .open = dasd_stats_open,
1073 .read = seq_read,
1074 .llseek = seq_lseek,
1075 .release = single_release,
1076 .write = dasd_stats_write,
1077};
1078
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001079static void dasd_profile_init(struct dasd_profile *profile,
1080 struct dentry *base_dentry)
1081{
Al Virof4ae40a62011-07-24 04:33:43 -04001082 umode_t mode;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001083 struct dentry *pde;
1084
1085 if (!base_dentry)
1086 return;
1087 profile->dentry = NULL;
1088 profile->data = NULL;
1089 mode = (S_IRUSR | S_IWUSR | S_IFREG);
1090 pde = debugfs_create_file("statistics", mode, base_dentry,
1091 profile, &dasd_stats_raw_fops);
1092 if (pde && !IS_ERR(pde))
1093 profile->dentry = pde;
1094 return;
1095}
1096
1097static void dasd_profile_exit(struct dasd_profile *profile)
1098{
1099 dasd_profile_off(profile);
Fabian Frederickd7309aa2014-06-26 19:41:46 +02001100 debugfs_remove(profile->dentry);
1101 profile->dentry = NULL;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001102}
1103
1104static void dasd_statistics_removeroot(void)
1105{
1106 dasd_global_profile_level = DASD_PROFILE_OFF;
Sebastian Ott6765cc22015-01-28 19:06:29 +01001107 dasd_profile_exit(&dasd_global_profile);
Fabian Frederickd7309aa2014-06-26 19:41:46 +02001108 debugfs_remove(dasd_debugfs_global_entry);
1109 debugfs_remove(dasd_debugfs_root_entry);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001110}
1111
1112static void dasd_statistics_createroot(void)
1113{
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001114 struct dentry *pde;
1115
1116 dasd_debugfs_root_entry = NULL;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001117 pde = debugfs_create_dir("dasd", NULL);
1118 if (!pde || IS_ERR(pde))
1119 goto error;
1120 dasd_debugfs_root_entry = pde;
1121 pde = debugfs_create_dir("global", dasd_debugfs_root_entry);
1122 if (!pde || IS_ERR(pde))
1123 goto error;
1124 dasd_debugfs_global_entry = pde;
Sebastian Ott6765cc22015-01-28 19:06:29 +01001125 dasd_profile_init(&dasd_global_profile, dasd_debugfs_global_entry);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001126 return;
1127
1128error:
1129 DBF_EVENT(DBF_ERR, "%s",
1130 "Creation of the dasd debugfs interface failed");
1131 dasd_statistics_removeroot();
1132 return;
1133}
1134
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135#else
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001136#define dasd_profile_start(block, cqr, req) do {} while (0)
1137#define dasd_profile_end(block, cqr, req) do {} while (0)
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001138
1139static void dasd_statistics_createroot(void)
1140{
1141 return;
1142}
1143
1144static void dasd_statistics_removeroot(void)
1145{
1146 return;
1147}
1148
1149int dasd_stats_generic_show(struct seq_file *m, void *v)
1150{
Fabian Frederickc794caf2014-06-26 19:41:49 +02001151 seq_puts(m, "Statistics are not activated in this kernel\n");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001152 return 0;
1153}
1154
1155static void dasd_profile_init(struct dasd_profile *profile,
1156 struct dentry *base_dentry)
1157{
1158 return;
1159}
1160
1161static void dasd_profile_exit(struct dasd_profile *profile)
1162{
1163 return;
1164}
1165
1166int dasd_profile_on(struct dasd_profile *profile)
1167{
1168 return 0;
1169}
1170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171#endif /* CONFIG_DASD_PROFILE */
1172
Stefan Haberland5a3b7b12016-03-18 09:42:13 +01001173static int dasd_hosts_show(struct seq_file *m, void *v)
1174{
1175 struct dasd_device *device;
1176 int rc = -EOPNOTSUPP;
1177
1178 device = m->private;
1179 dasd_get_device(device);
1180
1181 if (device->discipline->hosts_print)
1182 rc = device->discipline->hosts_print(device, m);
1183
1184 dasd_put_device(device);
1185 return rc;
1186}
1187
1188static int dasd_hosts_open(struct inode *inode, struct file *file)
1189{
1190 struct dasd_device *device = inode->i_private;
1191
1192 return single_open(file, dasd_hosts_show, device);
1193}
1194
1195static const struct file_operations dasd_hosts_fops = {
1196 .owner = THIS_MODULE,
1197 .open = dasd_hosts_open,
1198 .read = seq_read,
1199 .llseek = seq_lseek,
1200 .release = single_release,
1201};
1202
1203static void dasd_hosts_exit(struct dasd_device *device)
1204{
1205 debugfs_remove(device->hosts_dentry);
1206 device->hosts_dentry = NULL;
1207}
1208
1209static void dasd_hosts_init(struct dentry *base_dentry,
1210 struct dasd_device *device)
1211{
1212 struct dentry *pde;
1213 umode_t mode;
1214
1215 if (!base_dentry)
1216 return;
1217
1218 mode = S_IRUSR | S_IFREG;
1219 pde = debugfs_create_file("host_access_list", mode, base_dentry,
1220 device, &dasd_hosts_fops);
1221 if (pde && !IS_ERR(pde))
1222 device->hosts_dentry = pde;
1223}
1224
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225/*
1226 * Allocate memory for a channel program with 'cplength' channel
1227 * command words and 'datasize' additional space. There are two
1228 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
1229 * memory and 2) dasd_smalloc_request uses the static ccw memory
1230 * that gets allocated for each device.
1231 */
Stefan Haberland68b781f2009-09-11 10:28:29 +02001232struct dasd_ccw_req *dasd_kmalloc_request(int magic, int cplength,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001233 int datasize,
1234 struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235{
1236 struct dasd_ccw_req *cqr;
1237
1238 /* Sanity checks */
Stefan Haberland68b781f2009-09-11 10:28:29 +02001239 BUG_ON(datasize > PAGE_SIZE ||
Eric Sesterhenn7ac1e872006-03-24 18:48:13 +01001240 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08001242 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 if (cqr == NULL)
1244 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 cqr->cpaddr = NULL;
1246 if (cplength > 0) {
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08001247 cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 GFP_ATOMIC | GFP_DMA);
1249 if (cqr->cpaddr == NULL) {
1250 kfree(cqr);
1251 return ERR_PTR(-ENOMEM);
1252 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 }
1254 cqr->data = NULL;
1255 if (datasize > 0) {
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08001256 cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 if (cqr->data == NULL) {
Jesper Juhl17fd6822005-11-07 01:01:30 -08001258 kfree(cqr->cpaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 kfree(cqr);
1260 return ERR_PTR(-ENOMEM);
1261 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 }
Stefan Haberland68b781f2009-09-11 10:28:29 +02001263 cqr->magic = magic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1265 dasd_get_device(device);
1266 return cqr;
1267}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001268EXPORT_SYMBOL(dasd_kmalloc_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
Stefan Haberland68b781f2009-09-11 10:28:29 +02001270struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001271 int datasize,
1272 struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273{
1274 unsigned long flags;
1275 struct dasd_ccw_req *cqr;
1276 char *data;
1277 int size;
1278
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
1280 if (cplength > 0)
1281 size += cplength * sizeof(struct ccw1);
1282 if (datasize > 0)
1283 size += datasize;
1284 spin_lock_irqsave(&device->mem_lock, flags);
1285 cqr = (struct dasd_ccw_req *)
1286 dasd_alloc_chunk(&device->ccw_chunks, size);
1287 spin_unlock_irqrestore(&device->mem_lock, flags);
1288 if (cqr == NULL)
1289 return ERR_PTR(-ENOMEM);
1290 memset(cqr, 0, sizeof(struct dasd_ccw_req));
1291 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
1292 cqr->cpaddr = NULL;
1293 if (cplength > 0) {
1294 cqr->cpaddr = (struct ccw1 *) data;
1295 data += cplength*sizeof(struct ccw1);
1296 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
1297 }
1298 cqr->data = NULL;
1299 if (datasize > 0) {
1300 cqr->data = data;
1301 memset(cqr->data, 0, datasize);
1302 }
Stefan Haberland68b781f2009-09-11 10:28:29 +02001303 cqr->magic = magic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1305 dasd_get_device(device);
1306 return cqr;
1307}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001308EXPORT_SYMBOL(dasd_smalloc_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
1310/*
1311 * Free memory of a channel program. This function needs to free all the
1312 * idal lists that might have been created by dasd_set_cda and the
1313 * struct dasd_ccw_req itself.
1314 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001315void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 struct ccw1 *ccw;
1318
1319 /* Clear any idals used for the request. */
1320 ccw = cqr->cpaddr;
1321 do {
1322 clear_normalized_cda(ccw);
1323 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
Jesper Juhl17fd6822005-11-07 01:01:30 -08001324 kfree(cqr->cpaddr);
1325 kfree(cqr->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 kfree(cqr);
1327 dasd_put_device(device);
1328}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001329EXPORT_SYMBOL(dasd_kfree_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001331void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332{
1333 unsigned long flags;
1334
1335 spin_lock_irqsave(&device->mem_lock, flags);
1336 dasd_free_chunk(&device->ccw_chunks, cqr);
1337 spin_unlock_irqrestore(&device->mem_lock, flags);
1338 dasd_put_device(device);
1339}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001340EXPORT_SYMBOL(dasd_sfree_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
1342/*
1343 * Check discipline magic in cqr.
1344 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001345static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346{
1347 struct dasd_device *device;
1348
1349 if (cqr == NULL)
1350 return -EINVAL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001351 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001353 DBF_DEV_EVENT(DBF_WARNING, device,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 " dasd_ccw_req 0x%08x magic doesn't match"
1355 " discipline 0x%08x",
1356 cqr->magic,
1357 *(unsigned int *) device->discipline->name);
1358 return -EINVAL;
1359 }
1360 return 0;
1361}
1362
1363/*
1364 * Terminate the current i/o and set the request to clear_pending.
1365 * Timer keeps device runnig.
1366 * ccw_device_clear can fail if the i/o subsystem
1367 * is in a bad mood.
1368 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001369int dasd_term_IO(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370{
1371 struct dasd_device *device;
1372 int retries, rc;
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001373 char errorstring[ERRORLENGTH];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
1375 /* Check the cqr */
1376 rc = dasd_check_cqr(cqr);
1377 if (rc)
1378 return rc;
1379 retries = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001380 device = (struct dasd_device *) cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
1382 rc = ccw_device_clear(device->cdev, (long) cqr);
1383 switch (rc) {
1384 case 0: /* termination successful */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001385 cqr->status = DASD_CQR_CLEAR_PENDING;
Heiko Carstens1aae0562013-01-30 09:49:40 +01001386 cqr->stopclk = get_tod_clock();
Horst Hummel8f617012006-08-30 14:33:33 +02001387 cqr->starttime = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 DBF_DEV_EVENT(DBF_DEBUG, device,
1389 "terminate cqr %p successful",
1390 cqr);
1391 break;
1392 case -ENODEV:
1393 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1394 "device gone, retry");
1395 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 case -EINVAL:
Stefan Haberland2c171242014-11-24 10:53:19 +01001397 /*
1398 * device not valid so no I/O could be running
1399 * handle CQR as termination successful
1400 */
1401 cqr->status = DASD_CQR_CLEARED;
1402 cqr->stopclk = get_tod_clock();
1403 cqr->starttime = 0;
1404 /* no retries for invalid devices */
1405 cqr->retries = -1;
1406 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1407 "EINVAL, handle as terminated");
1408 /* fake rc to success */
1409 rc = 0;
1410 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001412 /* internal error 10 - unknown rc*/
1413 snprintf(errorstring, ERRORLENGTH, "10 %d", rc);
1414 dev_err(&device->cdev->dev, "An error occurred in the "
1415 "DASD device driver, reason=%s\n", errorstring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 BUG();
1417 break;
1418 }
1419 retries++;
1420 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001421 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 return rc;
1423}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001424EXPORT_SYMBOL(dasd_term_IO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
1426/*
1427 * Start the i/o. This start_IO can fail if the channel is really busy.
1428 * In that case set up a timer to start the request later.
1429 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001430int dasd_start_IO(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431{
1432 struct dasd_device *device;
1433 int rc;
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001434 char errorstring[ERRORLENGTH];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
1436 /* Check the cqr */
1437 rc = dasd_check_cqr(cqr);
Stefan Weinhuber6cc7f162009-06-12 10:26:39 +02001438 if (rc) {
1439 cqr->intrc = rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 return rc;
Stefan Weinhuber6cc7f162009-06-12 10:26:39 +02001441 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001442 device = (struct dasd_device *) cqr->startdev;
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001443 if (((cqr->block &&
1444 test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) ||
1445 test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
1446 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
1447 DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
1448 "because of stolen lock", cqr);
1449 cqr->status = DASD_CQR_ERROR;
1450 cqr->intrc = -EPERM;
1451 return -EPERM;
1452 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 if (cqr->retries < 0) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001454 /* internal error 14 - start_IO run out of retries */
1455 sprintf(errorstring, "14 %p", cqr);
1456 dev_err(&device->cdev->dev, "An error occurred in the DASD "
1457 "device driver, reason=%s\n", errorstring);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001458 cqr->status = DASD_CQR_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 return -EIO;
1460 }
Heiko Carstens1aae0562013-01-30 09:49:40 +01001461 cqr->startclk = get_tod_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 cqr->starttime = jiffies;
1463 cqr->retries--;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001464 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
Stefan Haberlandc9346152016-08-08 15:53:54 +02001465 cqr->lpm &= dasd_path_get_opm(device);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001466 if (!cqr->lpm)
Stefan Haberlandc9346152016-08-08 15:53:54 +02001467 cqr->lpm = dasd_path_get_opm(device);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001468 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001469 if (cqr->cpmode == 1) {
1470 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
1471 (long) cqr, cqr->lpm);
1472 } else {
1473 rc = ccw_device_start(device->cdev, cqr->cpaddr,
1474 (long) cqr, cqr->lpm, 0);
1475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 switch (rc) {
1477 case 0:
1478 cqr->status = DASD_CQR_IN_IO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 break;
1480 case -EBUSY:
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001481 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 "start_IO: device busy, retry later");
1483 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 case -EACCES:
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001485 /* -EACCES indicates that the request used only a subset of the
1486 * available paths and all these paths are gone. If the lpm of
1487 * this request was only a subset of the opm (e.g. the ppm) then
1488 * we just do a retry with all available paths.
1489 * If we already use the full opm, something is amiss, and we
1490 * need a full path verification.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 */
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001492 if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1493 DBF_DEV_EVENT(DBF_WARNING, device,
1494 "start_IO: selected paths gone (%x)",
1495 cqr->lpm);
Stefan Haberlandc9346152016-08-08 15:53:54 +02001496 } else if (cqr->lpm != dasd_path_get_opm(device)) {
1497 cqr->lpm = dasd_path_get_opm(device);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001498 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
1499 "start_IO: selected paths gone,"
1500 " retry on all paths");
1501 } else {
1502 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1503 "start_IO: all paths in opm gone,"
1504 " do path verification");
1505 dasd_generic_last_path_gone(device);
Stefan Haberlandc9346152016-08-08 15:53:54 +02001506 dasd_path_no_path(device);
1507 dasd_path_set_tbvpm(device,
1508 ccw_device_get_path_mask(
1509 device->cdev));
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 break;
1512 case -ENODEV:
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001513 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001514 "start_IO: -ENODEV device gone, retry");
1515 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 case -EIO:
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001517 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001518 "start_IO: -EIO device gone, retry");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 break;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02001520 case -EINVAL:
1521 /* most likely caused in power management context */
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001522 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Stefan Haberlandd41dd122009-06-16 10:30:25 +02001523 "start_IO: -EINVAL device currently "
1524 "not accessible");
1525 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001527 /* internal error 11 - unknown rc */
1528 snprintf(errorstring, ERRORLENGTH, "11 %d", rc);
1529 dev_err(&device->cdev->dev,
1530 "An error occurred in the DASD device driver, "
1531 "reason=%s\n", errorstring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 BUG();
1533 break;
1534 }
Stefan Weinhuber6cc7f162009-06-12 10:26:39 +02001535 cqr->intrc = rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 return rc;
1537}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001538EXPORT_SYMBOL(dasd_start_IO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
1540/*
1541 * Timeout function for dasd devices. This is used for different purposes
1542 * 1) missing interrupt handler for normal operation
1543 * 2) delayed start of request where start_IO failed with -EBUSY
1544 * 3) timeout for missing state change interrupts
1545 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1546 * DASD_CQR_QUEUED for 2) and 3).
1547 */
Kees Cooke99e88a2017-10-16 14:43:17 -07001548static void dasd_device_timeout(struct timer_list *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549{
1550 unsigned long flags;
1551 struct dasd_device *device;
1552
Kees Cooke99e88a2017-10-16 14:43:17 -07001553 device = from_timer(device, t, timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1555 /* re-activate request queue */
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001556 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001558 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559}
1560
1561/*
1562 * Setup timeout for a device in jiffies.
1563 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001564void dasd_device_set_timer(struct dasd_device *device, int expires)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565{
Stefan Weinhuber48cae882009-02-11 10:37:31 +01001566 if (expires == 0)
1567 del_timer(&device->timer);
1568 else
1569 mod_timer(&device->timer, jiffies + expires);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001571EXPORT_SYMBOL(dasd_device_set_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
1573/*
1574 * Clear timeout for a device.
1575 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001576void dasd_device_clear_timer(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577{
Stefan Weinhuber48cae882009-02-11 10:37:31 +01001578 del_timer(&device->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001580EXPORT_SYMBOL(dasd_device_clear_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001582static void dasd_handle_killed_request(struct ccw_device *cdev,
1583 unsigned long intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584{
1585 struct dasd_ccw_req *cqr;
1586 struct dasd_device *device;
1587
Stefan Weinhuberf16f58432008-05-15 16:52:36 +02001588 if (!intparm)
1589 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 cqr = (struct dasd_ccw_req *) intparm;
1591 if (cqr->status != DASD_CQR_IN_IO) {
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01001592 DBF_EVENT_DEVID(DBF_DEBUG, cdev,
1593 "invalid status in handle_killed_request: "
1594 "%02x", cqr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 return;
1596 }
1597
Stefan Haberland589c74d2010-02-26 22:37:47 +01001598 device = dasd_device_from_cdev_locked(cdev);
1599 if (IS_ERR(device)) {
1600 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1601 "unable to get device from cdev");
1602 return;
1603 }
1604
1605 if (!cqr->startdev ||
1606 device != cqr->startdev ||
1607 strncmp(cqr->startdev->discipline->ebcname,
1608 (char *) &cqr->magic, 4)) {
Stefan Haberland294001a2010-01-27 10:12:35 +01001609 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1610 "invalid device in request");
Stefan Haberland589c74d2010-02-26 22:37:47 +01001611 dasd_put_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 return;
1613 }
1614
1615 /* Schedule request to be retried. */
1616 cqr->status = DASD_CQR_QUEUED;
1617
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001618 dasd_device_clear_timer(device);
1619 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 dasd_put_device(device);
1621}
1622
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001623void dasd_generic_handle_state_change(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624{
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001625 /* First of all start sense subsystem status request. */
1626 dasd_eer_snss(device);
1627
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001628 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001629 dasd_schedule_device_bh(device);
Stefan Haberlande4433432017-05-22 10:59:11 +02001630 if (device->block) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001631 dasd_schedule_block_bh(device->block);
Stefan Haberland673514a2017-09-12 17:22:42 +02001632 if (device->block->request_queue)
1633 blk_mq_run_hw_queues(device->block->request_queue,
1634 true);
Stefan Haberlande4433432017-05-22 10:59:11 +02001635 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001637EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
Stefan Haberlanda521b042016-08-08 15:56:54 +02001639static int dasd_check_hpf_error(struct irb *irb)
1640{
1641 return (scsw_tm_is_valid_schxs(&irb->scsw) &&
1642 (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX ||
1643 irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX));
1644}
1645
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646/*
1647 * Interrupt handler for "normal" ssch-io based dasd devices.
1648 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001649void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1650 struct irb *irb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651{
1652 struct dasd_ccw_req *cqr, *next;
1653 struct dasd_device *device;
Jan Höppner7bf76f012017-08-15 16:40:18 +02001654 unsigned long now;
Jan Höppner8fd57522015-08-19 13:41:20 +02001655 int nrf_suppressed = 0;
1656 int fp_suppressed = 0;
1657 u8 *sense = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 int expires;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
Stefan Haberland9ba333d2016-08-08 14:08:17 +02001660 cqr = (struct dasd_ccw_req *) intparm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 if (IS_ERR(irb)) {
1662 switch (PTR_ERR(irb)) {
1663 case -EIO:
Stefan Haberland9ba333d2016-08-08 14:08:17 +02001664 if (cqr && cqr->status == DASD_CQR_CLEAR_PENDING) {
Stefan Haberlandc9346152016-08-08 15:53:54 +02001665 device = cqr->startdev;
Stefan Haberland9ba333d2016-08-08 14:08:17 +02001666 cqr->status = DASD_CQR_CLEARED;
1667 dasd_device_clear_timer(device);
1668 wake_up(&dasd_flush_wq);
1669 dasd_schedule_device_bh(device);
1670 return;
1671 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 break;
1673 case -ETIMEDOUT:
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01001674 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1675 "request timed out\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 break;
1677 default:
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01001678 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1679 "unknown error %ld\n", __func__,
1680 PTR_ERR(irb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 }
Stefan Weinhuberf16f58432008-05-15 16:52:36 +02001682 dasd_handle_killed_request(cdev, intparm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 return;
1684 }
1685
Heiko Carstens1aae0562013-01-30 09:49:40 +01001686 now = get_tod_clock();
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001687 /* check for conditions that should be handled immediately */
1688 if (!cqr ||
1689 !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1690 scsw_cstat(&irb->scsw) == 0)) {
Stefan Weinhubera5a00612010-10-25 16:10:47 +02001691 if (cqr)
1692 memcpy(&cqr->irb, irb, sizeof(*irb));
Martin Schwidefskya00bfd72006-09-20 15:59:05 +02001693 device = dasd_device_from_cdev_locked(cdev);
Stefan Haberland56b86b62010-10-25 16:10:49 +02001694 if (IS_ERR(device))
1695 return;
1696 /* ignore unsolicited interrupts for DIAG discipline */
1697 if (device->discipline == dasd_diag_discipline_pointer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 dasd_put_device(device);
Stefan Haberland56b86b62010-10-25 16:10:49 +02001699 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 }
Jan Höppner8fd57522015-08-19 13:41:20 +02001701
1702 /*
1703 * In some cases 'File Protected' or 'No Record Found' errors
1704 * might be expected and debug log messages for the
1705 * corresponding interrupts shouldn't be written then.
1706 * Check if either of the according suppress bits is set.
1707 */
1708 sense = dasd_get_sense(irb);
1709 if (sense) {
1710 fp_suppressed = (sense[1] & SNS1_FILE_PROTECTED) &&
1711 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
1712 nrf_suppressed = (sense[1] & SNS1_NO_REC_FOUND) &&
1713 test_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
1714 }
1715 if (!(fp_suppressed || nrf_suppressed))
1716 device->discipline->dump_sense_dbf(device, irb, "int");
1717
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001718 if (device->features & DASD_FEATURE_ERPLOG)
1719 device->discipline->dump_sense(device, cqr, irb);
1720 device->discipline->check_for_device_change(device, cqr, irb);
Stefan Haberland56b86b62010-10-25 16:10:49 +02001721 dasd_put_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 }
Stefan Haberland5db84402014-10-01 14:39:47 +02001723
1724 /* check for for attention message */
1725 if (scsw_dstat(&irb->scsw) & DEV_STAT_ATTENTION) {
1726 device = dasd_device_from_cdev_locked(cdev);
Stefan Haberland22021342017-01-25 14:47:32 +01001727 if (!IS_ERR(device)) {
1728 device->discipline->check_attention(device,
1729 irb->esw.esw1.lpum);
1730 dasd_put_device(device);
1731 }
Stefan Haberland5db84402014-10-01 14:39:47 +02001732 }
1733
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001734 if (!cqr)
1735 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001737 device = (struct dasd_device *) cqr->startdev;
1738 if (!device ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
Stefan Haberland294001a2010-01-27 10:12:35 +01001740 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1741 "invalid device in request");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 return;
1743 }
1744
1745 /* Check for clear pending */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001746 if (cqr->status == DASD_CQR_CLEAR_PENDING &&
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001747 scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001748 cqr->status = DASD_CQR_CLEARED;
1749 dasd_device_clear_timer(device);
Horst Hummel8f617012006-08-30 14:33:33 +02001750 wake_up(&dasd_flush_wq);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001751 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 return;
1753 }
1754
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001755 /* check status - the request might have been killed by dyn detach */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 if (cqr->status != DASD_CQR_IN_IO) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001757 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1758 "status %02x", dev_name(&cdev->dev), cqr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 return;
1760 }
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001761
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001762 next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 expires = 0;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001764 if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1765 scsw_cstat(&irb->scsw) == 0) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001766 /* request was completed successfully */
1767 cqr->status = DASD_CQR_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 cqr->stopclk = now;
1769 /* Start first request on queue if possible -> fast_io. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001770 if (cqr->devlist.next != &device->ccw_queue) {
1771 next = list_entry(cqr->devlist.next,
1772 struct dasd_ccw_req, devlist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001774 } else { /* error */
Stefan Haberlanda521b042016-08-08 15:56:54 +02001775 /* check for HPF error
1776 * call discipline function to requeue all requests
1777 * and disable HPF accordingly
1778 */
1779 if (cqr->cpmode && dasd_check_hpf_error(irb) &&
1780 device->discipline->handle_hpf_error)
1781 device->discipline->handle_hpf_error(device, irb);
Stefan Haberland6c5f57c2008-02-05 16:50:46 +01001782 /*
1783 * If we don't want complex ERP for this request, then just
1784 * reset this and retry it in the fastpath
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001785 */
Stefan Haberland6c5f57c2008-02-05 16:50:46 +01001786 if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001787 cqr->retries > 0) {
Stefan Haberlandc9346152016-08-08 15:53:54 +02001788 if (cqr->lpm == dasd_path_get_opm(device))
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001789 DBF_DEV_EVENT(DBF_DEBUG, device,
1790 "default ERP in fastpath "
1791 "(%i retries left)",
1792 cqr->retries);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001793 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
Stefan Haberlandc9346152016-08-08 15:53:54 +02001794 cqr->lpm = dasd_path_get_opm(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001795 cqr->status = DASD_CQR_QUEUED;
1796 next = cqr;
1797 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 cqr->status = DASD_CQR_ERROR;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001799 }
1800 if (next && (next->status == DASD_CQR_QUEUED) &&
1801 (!device->stopped)) {
1802 if (device->discipline->start_IO(next) == 0)
1803 expires = next->expires;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 }
1805 if (expires != 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001806 dasd_device_set_timer(device, expires);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 else
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001808 dasd_device_clear_timer(device);
1809 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001811EXPORT_SYMBOL(dasd_int_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
Stefan Haberlanda23ed002010-05-26 23:27:09 +02001813enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb)
1814{
1815 struct dasd_device *device;
1816
1817 device = dasd_device_from_cdev_locked(cdev);
1818
1819 if (IS_ERR(device))
1820 goto out;
1821 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1822 device->state != device->target ||
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001823 !device->discipline->check_for_device_change){
Stefan Haberlanda23ed002010-05-26 23:27:09 +02001824 dasd_put_device(device);
1825 goto out;
1826 }
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001827 if (device->discipline->dump_sense_dbf)
1828 device->discipline->dump_sense_dbf(device, irb, "uc");
1829 device->discipline->check_for_device_change(device, NULL, irb);
Stefan Haberlanda23ed002010-05-26 23:27:09 +02001830 dasd_put_device(device);
1831out:
1832 return UC_TODO_RETRY;
1833}
1834EXPORT_SYMBOL_GPL(dasd_generic_uc_handler);
1835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001837 * If we have an error on a dasd_block layer request then we cancel
1838 * and return all further requests from the same dasd_block as well.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001840static void __dasd_device_recovery(struct dasd_device *device,
1841 struct dasd_ccw_req *ref_cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842{
1843 struct list_head *l, *n;
1844 struct dasd_ccw_req *cqr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
1846 /*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001847 * only requeue request that came from the dasd_block layer
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001849 if (!ref_cqr->block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 return;
Horst Hummelf24acd42005-05-01 08:58:59 -07001851
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001852 list_for_each_safe(l, n, &device->ccw_queue) {
1853 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1854 if (cqr->status == DASD_CQR_QUEUED &&
1855 ref_cqr->block == cqr->block) {
1856 cqr->status = DASD_CQR_CLEARED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001858 }
1859};
1860
1861/*
1862 * Remove those ccw requests from the queue that need to be returned
1863 * to the upper layer.
1864 */
1865static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1866 struct list_head *final_queue)
1867{
1868 struct list_head *l, *n;
1869 struct dasd_ccw_req *cqr;
1870
1871 /* Process request with final status. */
1872 list_for_each_safe(l, n, &device->ccw_queue) {
1873 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1874
Hannes Reinecke1fbdb8b2013-01-30 09:26:13 +00001875 /* Skip any non-final request. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001876 if (cqr->status == DASD_CQR_QUEUED ||
1877 cqr->status == DASD_CQR_IN_IO ||
1878 cqr->status == DASD_CQR_CLEAR_PENDING)
Hannes Reinecke1fbdb8b2013-01-30 09:26:13 +00001879 continue;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001880 if (cqr->status == DASD_CQR_ERROR) {
1881 __dasd_device_recovery(device, cqr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001883 /* Rechain finished requests to final queue */
1884 list_move_tail(&cqr->devlist, final_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 }
1886}
1887
1888/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001889 * the cqrs from the final queue are returned to the upper layer
1890 * by setting a dasd_block state and calling the callback function
1891 */
1892static void __dasd_device_process_final_queue(struct dasd_device *device,
1893 struct list_head *final_queue)
1894{
1895 struct list_head *l, *n;
1896 struct dasd_ccw_req *cqr;
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001897 struct dasd_block *block;
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001898 void (*callback)(struct dasd_ccw_req *, void *data);
1899 void *callback_data;
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001900 char errorstring[ERRORLENGTH];
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001901
1902 list_for_each_safe(l, n, final_queue) {
1903 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1904 list_del_init(&cqr->devlist);
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001905 block = cqr->block;
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001906 callback = cqr->callback;
1907 callback_data = cqr->callback_data;
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001908 if (block)
1909 spin_lock_bh(&block->queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001910 switch (cqr->status) {
1911 case DASD_CQR_SUCCESS:
1912 cqr->status = DASD_CQR_DONE;
1913 break;
1914 case DASD_CQR_ERROR:
1915 cqr->status = DASD_CQR_NEED_ERP;
1916 break;
1917 case DASD_CQR_CLEARED:
1918 cqr->status = DASD_CQR_TERMINATED;
1919 break;
1920 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001921 /* internal error 12 - wrong cqr status*/
1922 snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status);
1923 dev_err(&device->cdev->dev,
1924 "An error occurred in the DASD device driver, "
1925 "reason=%s\n", errorstring);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001926 BUG();
1927 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001928 if (cqr->callback != NULL)
Stefan Haberlandc80ee722008-05-30 10:03:31 +02001929 (callback)(cqr, callback_data);
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001930 if (block)
1931 spin_unlock_bh(&block->queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001932 }
1933}
1934
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001935/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 * Take a look at the first request on the ccw queue and check
1937 * if it reached its expire time. If so, terminate the IO.
1938 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001939static void __dasd_device_check_expire(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940{
1941 struct dasd_ccw_req *cqr;
1942
1943 if (list_empty(&device->ccw_queue))
1944 return;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001945 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
Horst Hummel29145a62006-12-04 15:40:15 +01001946 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1947 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01001948 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1949 /*
1950 * IO in safe offline processing should not
1951 * run out of retries
1952 */
1953 cqr->retries++;
1954 }
Horst Hummel29145a62006-12-04 15:40:15 +01001955 if (device->discipline->term_IO(cqr) != 0) {
1956 /* Hmpf, try again in 5 sec */
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001957 dev_err(&device->cdev->dev,
Heiko Carstens625c94d2010-08-13 10:06:38 +02001958 "cqr %p timed out (%lus) but cannot be "
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001959 "ended, retrying in 5 s\n",
1960 cqr, (cqr->expires/HZ));
Stefan Haberland7dc1da92008-01-26 14:11:26 +01001961 cqr->expires += 5*HZ;
1962 dasd_device_set_timer(device, 5*HZ);
Horst Hummel29145a62006-12-04 15:40:15 +01001963 } else {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001964 dev_err(&device->cdev->dev,
Heiko Carstens625c94d2010-08-13 10:06:38 +02001965 "cqr %p timed out (%lus), %i retries "
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001966 "remaining\n", cqr, (cqr->expires/HZ),
1967 cqr->retries);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 }
1969 }
1970}
1971
1972/*
Stefan Haberlandf81a49d2015-07-10 10:47:09 +02001973 * return 1 when device is not eligible for IO
1974 */
1975static int __dasd_device_is_unusable(struct dasd_device *device,
1976 struct dasd_ccw_req *cqr)
1977{
1978 int mask = ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM);
1979
Stefan Haberlande8ac0152017-05-18 13:24:45 +02001980 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
1981 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1982 /*
1983 * dasd is being set offline
1984 * but it is no safe offline where we have to allow I/O
1985 */
Stefan Haberlandf81a49d2015-07-10 10:47:09 +02001986 return 1;
1987 }
1988 if (device->stopped) {
1989 if (device->stopped & mask) {
1990 /* stopped and CQR will not change that. */
1991 return 1;
1992 }
1993 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1994 /* CQR is not able to change device to
1995 * operational. */
1996 return 1;
1997 }
1998 /* CQR required to get device operational. */
1999 }
2000 return 0;
2001}
2002
2003/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 * Take a look at the first request on the ccw queue and check
2005 * if it needs to be started.
2006 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002007static void __dasd_device_start_head(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008{
2009 struct dasd_ccw_req *cqr;
2010 int rc;
2011
2012 if (list_empty(&device->ccw_queue))
2013 return;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002014 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07002015 if (cqr->status != DASD_CQR_QUEUED)
2016 return;
Stefan Haberlandf81a49d2015-07-10 10:47:09 +02002017 /* if device is not usable return request to upper layer */
2018 if (__dasd_device_is_unusable(device, cqr)) {
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01002019 cqr->intrc = -EAGAIN;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002020 cqr->status = DASD_CQR_CLEARED;
2021 dasd_schedule_device_bh(device);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07002022 return;
Horst Hummel1c01b8a2006-01-06 00:19:15 -08002023 }
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07002024
2025 rc = device->discipline->start_IO(cqr);
2026 if (rc == 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002027 dasd_device_set_timer(device, cqr->expires);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07002028 else if (rc == -EACCES) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002029 dasd_schedule_device_bh(device);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07002030 } else
2031 /* Hmpf, try again in 1/2 sec */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002032 dasd_device_set_timer(device, 50);
Horst Hummel8f617012006-08-30 14:33:33 +02002033}
2034
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01002035static void __dasd_device_check_path_events(struct dasd_device *device)
2036{
2037 int rc;
2038
Stefan Haberlandc9346152016-08-08 15:53:54 +02002039 if (!dasd_path_get_tbvpm(device))
2040 return;
2041
2042 if (device->stopped &
2043 ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM))
2044 return;
2045 rc = device->discipline->verify_path(device,
2046 dasd_path_get_tbvpm(device));
2047 if (rc)
2048 dasd_device_set_timer(device, 50);
2049 else
2050 dasd_path_clear_all_verify(device);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01002051};
2052
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002054 * Go through all request on the dasd_device request queue,
2055 * terminate them on the cdev if necessary, and return them to the
2056 * submitting layer via callback.
2057 * Note:
2058 * Make sure that all 'submitting layers' still exist when
2059 * this function is called!. In other words, when 'device' is a base
2060 * device then all block layer requests must have been removed before
2061 * via dasd_flush_block_queue.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002063int dasd_flush_device_queue(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002065 struct dasd_ccw_req *cqr, *n;
2066 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 struct list_head flush_queue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
2069 INIT_LIST_HEAD(&flush_queue);
2070 spin_lock_irq(get_ccwdev_lock(device->cdev));
Horst Hummel8f617012006-08-30 14:33:33 +02002071 rc = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002072 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
Horst Hummel8f617012006-08-30 14:33:33 +02002073 /* Check status and move request to flush_queue */
2074 switch (cqr->status) {
2075 case DASD_CQR_IN_IO:
2076 rc = device->discipline->term_IO(cqr);
2077 if (rc) {
2078 /* unable to terminate requeust */
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002079 dev_err(&device->cdev->dev,
2080 "Flushing the DASD request queue "
2081 "failed for request %p\n", cqr);
Horst Hummel8f617012006-08-30 14:33:33 +02002082 /* stop flush processing */
2083 goto finished;
2084 }
2085 break;
2086 case DASD_CQR_QUEUED:
Heiko Carstens1aae0562013-01-30 09:49:40 +01002087 cqr->stopclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002088 cqr->status = DASD_CQR_CLEARED;
Horst Hummel8f617012006-08-30 14:33:33 +02002089 break;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002090 default: /* no need to modify the others */
Horst Hummel8f617012006-08-30 14:33:33 +02002091 break;
2092 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002093 list_move_tail(&cqr->devlist, &flush_queue);
Horst Hummel8f617012006-08-30 14:33:33 +02002094 }
Horst Hummel8f617012006-08-30 14:33:33 +02002095finished:
2096 spin_unlock_irq(get_ccwdev_lock(device->cdev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002097 /*
2098 * After this point all requests must be in state CLEAR_PENDING,
2099 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
2100 * one of the others.
2101 */
2102 list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
2103 wait_event(dasd_flush_wq,
2104 (cqr->status != DASD_CQR_CLEAR_PENDING));
2105 /*
2106 * Now set each request back to TERMINATED, DONE or NEED_ERP
2107 * and call the callback function of flushed requests
2108 */
2109 __dasd_device_process_final_queue(device, &flush_queue);
Horst Hummel8f617012006-08-30 14:33:33 +02002110 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002112EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
2114/*
2115 * Acquire the device lock and process queues for the device.
2116 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002117static void dasd_device_tasklet(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118{
2119 struct list_head final_queue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120
2121 atomic_set (&device->tasklet_scheduled, 0);
2122 INIT_LIST_HEAD(&final_queue);
2123 spin_lock_irq(get_ccwdev_lock(device->cdev));
2124 /* Check expire time of first request on the ccw queue. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002125 __dasd_device_check_expire(device);
2126 /* find final requests on ccw queue */
2127 __dasd_device_process_ccw_queue(device, &final_queue);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01002128 __dasd_device_check_path_events(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2130 /* Now call the callback function of requests with final status */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002131 __dasd_device_process_final_queue(device, &final_queue);
2132 spin_lock_irq(get_ccwdev_lock(device->cdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 /* Now check if the head of the ccw queue needs to be started. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002134 __dasd_device_start_head(device);
2135 spin_unlock_irq(get_ccwdev_lock(device->cdev));
Stefan Haberland4679e892012-06-19 17:30:12 +02002136 if (waitqueue_active(&shutdown_waitq))
2137 wake_up(&shutdown_waitq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 dasd_put_device(device);
2139}
2140
2141/*
2142 * Schedules a call to dasd_tasklet over the device tasklet.
2143 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002144void dasd_schedule_device_bh(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145{
2146 /* Protect against rescheduling. */
Martin Schwidefsky973bd992006-01-06 00:19:07 -08002147 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 return;
2149 dasd_get_device(device);
2150 tasklet_hi_schedule(&device->tasklet);
2151}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002152EXPORT_SYMBOL(dasd_schedule_device_bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002154void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
2155{
2156 device->stopped |= bits;
2157}
2158EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits);
2159
2160void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
2161{
2162 device->stopped &= ~bits;
2163 if (!device->stopped)
2164 wake_up(&generic_waitq);
2165}
2166EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits);
2167
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002169 * Queue a request to the head of the device ccw_queue.
2170 * Start the I/O if possible.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002172void dasd_add_request_head(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173{
2174 struct dasd_device *device;
2175 unsigned long flags;
2176
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002177 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002179 cqr->status = DASD_CQR_QUEUED;
2180 list_add(&cqr->devlist, &device->ccw_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 /* let the bh start the request to keep them in order */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002182 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2184}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002185EXPORT_SYMBOL(dasd_add_request_head);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186
2187/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002188 * Queue a request to the tail of the device ccw_queue.
2189 * Start the I/O if possible.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002191void dasd_add_request_tail(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192{
2193 struct dasd_device *device;
2194 unsigned long flags;
2195
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002196 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002198 cqr->status = DASD_CQR_QUEUED;
2199 list_add_tail(&cqr->devlist, &device->ccw_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 /* let the bh start the request to keep them in order */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002201 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2203}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002204EXPORT_SYMBOL(dasd_add_request_tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205
2206/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002207 * Wakeup helper for the 'sleep_on' functions.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 */
Stefan Haberland5915a872011-10-30 15:16:57 +01002209void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210{
Stefan Weinhuber1c1e0932010-05-12 09:32:11 +02002211 spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2212 cqr->callback_data = DASD_SLEEPON_END_TAG;
2213 spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2214 wake_up(&generic_waitq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215}
Stefan Haberland5915a872011-10-30 15:16:57 +01002216EXPORT_SYMBOL_GPL(dasd_wakeup_cb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002218static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219{
2220 struct dasd_device *device;
2221 int rc;
2222
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002223 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 spin_lock_irq(get_ccwdev_lock(device->cdev));
Stefan Weinhuber1c1e0932010-05-12 09:32:11 +02002225 rc = (cqr->callback_data == DASD_SLEEPON_END_TAG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2227 return rc;
2228}
2229
2230/*
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002231 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2232 */
2233static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr)
2234{
2235 struct dasd_device *device;
2236 dasd_erp_fn_t erp_fn;
2237
2238 if (cqr->status == DASD_CQR_FILLED)
2239 return 0;
2240 device = cqr->startdev;
2241 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2242 if (cqr->status == DASD_CQR_TERMINATED) {
2243 device->discipline->handle_terminated_request(cqr);
2244 return 1;
2245 }
2246 if (cqr->status == DASD_CQR_NEED_ERP) {
2247 erp_fn = device->discipline->erp_action(cqr);
2248 erp_fn(cqr);
2249 return 1;
2250 }
2251 if (cqr->status == DASD_CQR_FAILED)
2252 dasd_log_sense(cqr, &cqr->irb);
2253 if (cqr->refers) {
2254 __dasd_process_erp(device, cqr);
2255 return 1;
2256 }
2257 }
2258 return 0;
2259}
2260
2261static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr)
2262{
2263 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2264 if (cqr->refers) /* erp is not done yet */
2265 return 1;
2266 return ((cqr->status != DASD_CQR_DONE) &&
2267 (cqr->status != DASD_CQR_FAILED));
2268 } else
2269 return (cqr->status == DASD_CQR_FILLED);
2270}
2271
2272static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
2273{
2274 struct dasd_device *device;
2275 int rc;
2276 struct list_head ccw_queue;
2277 struct dasd_ccw_req *cqr;
2278
2279 INIT_LIST_HEAD(&ccw_queue);
2280 maincqr->status = DASD_CQR_FILLED;
2281 device = maincqr->startdev;
2282 list_add(&maincqr->blocklist, &ccw_queue);
2283 for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr);
2284 cqr = list_first_entry(&ccw_queue,
2285 struct dasd_ccw_req, blocklist)) {
2286
2287 if (__dasd_sleep_on_erp(cqr))
2288 continue;
2289 if (cqr->status != DASD_CQR_FILLED) /* could be failed */
2290 continue;
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01002291 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2292 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2293 cqr->status = DASD_CQR_FAILED;
2294 cqr->intrc = -EPERM;
2295 continue;
2296 }
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002297 /* Non-temporary stop condition will trigger fail fast */
2298 if (device->stopped & ~DASD_STOPPED_PENDING &&
2299 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2300 (!dasd_eer_enabled(device))) {
2301 cqr->status = DASD_CQR_FAILED;
Hannes Reinecked1ffc1f2013-01-30 09:26:16 +00002302 cqr->intrc = -ENOLINK;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002303 continue;
2304 }
Stefan Haberlanddf3044f2015-04-02 13:18:39 +02002305 /*
Stefan Haberlanda9f62732016-09-20 10:29:22 +02002306 * Don't try to start requests if device is in
2307 * offline processing, it might wait forever
2308 */
2309 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2310 cqr->status = DASD_CQR_FAILED;
2311 cqr->intrc = -ENODEV;
2312 continue;
2313 }
2314 /*
Stefan Haberlanddf3044f2015-04-02 13:18:39 +02002315 * Don't try to start requests if device is stopped
2316 * except path verification requests
2317 */
2318 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2319 if (interruptible) {
2320 rc = wait_event_interruptible(
2321 generic_waitq, !(device->stopped));
2322 if (rc == -ERESTARTSYS) {
2323 cqr->status = DASD_CQR_FAILED;
2324 maincqr->intrc = rc;
2325 continue;
2326 }
2327 } else
2328 wait_event(generic_waitq, !(device->stopped));
2329 }
Stefan Haberland5915a872011-10-30 15:16:57 +01002330 if (!cqr->callback)
2331 cqr->callback = dasd_wakeup_cb;
2332
Stefan Weinhuber1c1e0932010-05-12 09:32:11 +02002333 cqr->callback_data = DASD_SLEEPON_START_TAG;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002334 dasd_add_request_tail(cqr);
2335 if (interruptible) {
2336 rc = wait_event_interruptible(
2337 generic_waitq, _wait_for_wakeup(cqr));
2338 if (rc == -ERESTARTSYS) {
2339 dasd_cancel_req(cqr);
2340 /* wait (non-interruptible) for final status */
2341 wait_event(generic_waitq,
2342 _wait_for_wakeup(cqr));
2343 cqr->status = DASD_CQR_FAILED;
2344 maincqr->intrc = rc;
2345 continue;
2346 }
2347 } else
2348 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2349 }
2350
Heiko Carstens1aae0562013-01-30 09:49:40 +01002351 maincqr->endclk = get_tod_clock();
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002352 if ((maincqr->status != DASD_CQR_DONE) &&
2353 (maincqr->intrc != -ERESTARTSYS))
2354 dasd_log_sense(maincqr, &maincqr->irb);
2355 if (maincqr->status == DASD_CQR_DONE)
2356 rc = 0;
2357 else if (maincqr->intrc)
2358 rc = maincqr->intrc;
2359 else
2360 rc = -EIO;
2361 return rc;
2362}
2363
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002364static inline int _wait_for_wakeup_queue(struct list_head *ccw_queue)
2365{
2366 struct dasd_ccw_req *cqr;
2367
2368 list_for_each_entry(cqr, ccw_queue, blocklist) {
2369 if (cqr->callback_data != DASD_SLEEPON_END_TAG)
2370 return 0;
2371 }
2372
2373 return 1;
2374}
2375
2376static int _dasd_sleep_on_queue(struct list_head *ccw_queue, int interruptible)
2377{
2378 struct dasd_device *device;
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002379 struct dasd_ccw_req *cqr, *n;
Jan Höppner8fd57522015-08-19 13:41:20 +02002380 u8 *sense = NULL;
Stefan Haberland362ce842014-10-01 13:04:54 +02002381 int rc;
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002382
2383retry:
2384 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2385 device = cqr->startdev;
2386 if (cqr->status != DASD_CQR_FILLED) /*could be failed*/
2387 continue;
2388
2389 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2390 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2391 cqr->status = DASD_CQR_FAILED;
2392 cqr->intrc = -EPERM;
2393 continue;
2394 }
2395 /*Non-temporary stop condition will trigger fail fast*/
2396 if (device->stopped & ~DASD_STOPPED_PENDING &&
2397 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2398 !dasd_eer_enabled(device)) {
2399 cqr->status = DASD_CQR_FAILED;
2400 cqr->intrc = -EAGAIN;
2401 continue;
2402 }
2403
2404 /*Don't try to start requests if device is stopped*/
2405 if (interruptible) {
2406 rc = wait_event_interruptible(
2407 generic_waitq, !device->stopped);
2408 if (rc == -ERESTARTSYS) {
2409 cqr->status = DASD_CQR_FAILED;
2410 cqr->intrc = rc;
2411 continue;
2412 }
2413 } else
2414 wait_event(generic_waitq, !(device->stopped));
2415
2416 if (!cqr->callback)
2417 cqr->callback = dasd_wakeup_cb;
2418 cqr->callback_data = DASD_SLEEPON_START_TAG;
2419 dasd_add_request_tail(cqr);
2420 }
2421
2422 wait_event(generic_waitq, _wait_for_wakeup_queue(ccw_queue));
2423
2424 rc = 0;
2425 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
Stefan Haberland29b8dd92014-07-18 14:26:01 +02002426 /*
Jan Höppner8fd57522015-08-19 13:41:20 +02002427 * In some cases the 'File Protected' or 'Incorrect Length'
2428 * error might be expected and error recovery would be
2429 * unnecessary in these cases. Check if the according suppress
2430 * bit is set.
2431 */
2432 sense = dasd_get_sense(&cqr->irb);
2433 if (sense && sense[1] & SNS1_FILE_PROTECTED &&
2434 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags))
2435 continue;
2436 if (scsw_cstat(&cqr->irb.scsw) == 0x40 &&
2437 test_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags))
2438 continue;
2439
2440 /*
Stefan Haberland29b8dd92014-07-18 14:26:01 +02002441 * for alias devices simplify error recovery and
2442 * return to upper layer
Stefan Haberland362ce842014-10-01 13:04:54 +02002443 * do not skip ERP requests
Stefan Haberland29b8dd92014-07-18 14:26:01 +02002444 */
Stefan Haberland362ce842014-10-01 13:04:54 +02002445 if (cqr->startdev != cqr->basedev && !cqr->refers &&
Stefan Haberland29b8dd92014-07-18 14:26:01 +02002446 (cqr->status == DASD_CQR_TERMINATED ||
2447 cqr->status == DASD_CQR_NEED_ERP))
2448 return -EAGAIN;
Stefan Haberland362ce842014-10-01 13:04:54 +02002449
2450 /* normal recovery for basedev IO */
Stefan Haberland590aeed2014-11-24 10:45:47 +01002451 if (__dasd_sleep_on_erp(cqr))
2452 /* handle erp first */
Stefan Haberland362ce842014-10-01 13:04:54 +02002453 goto retry;
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002454 }
Stefan Haberland362ce842014-10-01 13:04:54 +02002455
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002456 return 0;
2457}
2458
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002459/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002460 * Queue a request to the tail of the device ccw_queue and wait for
2461 * it's completion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002463int dasd_sleep_on(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464{
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002465 return _dasd_sleep_on(cqr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002467EXPORT_SYMBOL(dasd_sleep_on);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468
2469/*
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002470 * Start requests from a ccw_queue and wait for their completion.
2471 */
2472int dasd_sleep_on_queue(struct list_head *ccw_queue)
2473{
2474 return _dasd_sleep_on_queue(ccw_queue, 0);
2475}
2476EXPORT_SYMBOL(dasd_sleep_on_queue);
2477
2478/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002479 * Queue a request to the tail of the device ccw_queue and wait
2480 * interruptible for it's completion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002482int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483{
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002484 return _dasd_sleep_on(cqr, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002486EXPORT_SYMBOL(dasd_sleep_on_interruptible);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
2488/*
2489 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2490 * for eckd devices) the currently running request has to be terminated
2491 * and be put back to status queued, before the special request is added
2492 * to the head of the queue. Then the special request is waited on normally.
2493 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002494static inline int _dasd_term_running_cqr(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495{
2496 struct dasd_ccw_req *cqr;
Stefan Haberlandaade6c02011-05-10 17:13:38 +02002497 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498
2499 if (list_empty(&device->ccw_queue))
2500 return 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002501 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
Stefan Haberlandaade6c02011-05-10 17:13:38 +02002502 rc = device->discipline->term_IO(cqr);
2503 if (!rc)
2504 /*
2505 * CQR terminated because a more important request is pending.
2506 * Undo decreasing of retry counter because this is
2507 * not an error case.
2508 */
2509 cqr->retries++;
2510 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511}
2512
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002513int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 struct dasd_device *device;
2516 int rc;
Horst Hummel138c0142006-06-29 14:58:12 +02002517
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002518 device = cqr->startdev;
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01002519 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2520 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2521 cqr->status = DASD_CQR_FAILED;
2522 cqr->intrc = -EPERM;
2523 return -EIO;
2524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 spin_lock_irq(get_ccwdev_lock(device->cdev));
2526 rc = _dasd_term_running_cqr(device);
2527 if (rc) {
2528 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2529 return rc;
2530 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 cqr->callback = dasd_wakeup_cb;
Stefan Weinhuber1c1e0932010-05-12 09:32:11 +02002532 cqr->callback_data = DASD_SLEEPON_START_TAG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 cqr->status = DASD_CQR_QUEUED;
Stefan Haberland214b8ff2011-10-30 15:16:56 +01002534 /*
2535 * add new request as second
2536 * first the terminated cqr needs to be finished
2537 */
2538 list_add(&cqr->devlist, device->ccw_queue.next);
Horst Hummel138c0142006-06-29 14:58:12 +02002539
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 /* let the bh start the request to keep them in order */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002541 dasd_schedule_device_bh(device);
Horst Hummel138c0142006-06-29 14:58:12 +02002542
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2544
Stefan Haberlandc80ee722008-05-30 10:03:31 +02002545 wait_event(generic_waitq, _wait_for_wakeup(cqr));
Horst Hummel138c0142006-06-29 14:58:12 +02002546
Stefan Weinhuber6cc7f162009-06-12 10:26:39 +02002547 if (cqr->status == DASD_CQR_DONE)
2548 rc = 0;
2549 else if (cqr->intrc)
2550 rc = cqr->intrc;
2551 else
2552 rc = -EIO;
Stefan Haberland0e003b72013-07-30 10:49:43 +02002553
2554 /* kick tasklets */
2555 dasd_schedule_device_bh(device);
2556 if (device->block)
2557 dasd_schedule_block_bh(device->block);
2558
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 return rc;
2560}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002561EXPORT_SYMBOL(dasd_sleep_on_immediatly);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562
2563/*
2564 * Cancels a request that was started with dasd_sleep_on_req.
2565 * This is useful to timeout requests. The request will be
2566 * terminated if it is currently in i/o.
Hannes Reineckeb99a9462013-01-30 09:26:11 +00002567 * Returns 0 if request termination was successful
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002568 * negative error code if termination failed
2569 * Cancellation of a request is an asynchronous operation! The calling
2570 * function has to wait until the request is properly returned via callback.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002572int dasd_cancel_req(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002574 struct dasd_device *device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 unsigned long flags;
2576 int rc;
2577
2578 rc = 0;
2579 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2580 switch (cqr->status) {
2581 case DASD_CQR_QUEUED:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002582 /* request was not started - just set to cleared */
2583 cqr->status = DASD_CQR_CLEARED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 break;
2585 case DASD_CQR_IN_IO:
2586 /* request in IO - terminate IO and release again */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002587 rc = device->discipline->term_IO(cqr);
2588 if (rc) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002589 dev_err(&device->cdev->dev,
2590 "Cancelling request %p failed with rc=%d\n",
2591 cqr, rc);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002592 } else {
Heiko Carstens1aae0562013-01-30 09:49:40 +01002593 cqr->stopclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002594 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 break;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002596 default: /* already finished or clear pending - do nothing */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 }
2599 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002600 dasd_schedule_device_bh(device);
2601 return rc;
2602}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002603EXPORT_SYMBOL(dasd_cancel_req);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002604
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002605/*
2606 * SECTION: Operations of the dasd_block layer.
2607 */
2608
2609/*
2610 * Timeout function for dasd_block. This is used when the block layer
2611 * is waiting for something that may not come reliably, (e.g. a state
2612 * change interrupt)
2613 */
Kees Cooke99e88a2017-10-16 14:43:17 -07002614static void dasd_block_timeout(struct timer_list *t)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002615{
2616 unsigned long flags;
2617 struct dasd_block *block;
2618
Kees Cooke99e88a2017-10-16 14:43:17 -07002619 block = from_timer(block, t, timer);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002620 spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
2621 /* re-activate request queue */
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002622 dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002623 spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
2624 dasd_schedule_block_bh(block);
Stefan Haberlande4433432017-05-22 10:59:11 +02002625 blk_mq_run_hw_queues(block->request_queue, true);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002626}
2627
2628/*
2629 * Setup timeout for a dasd_block in jiffies.
2630 */
2631void dasd_block_set_timer(struct dasd_block *block, int expires)
2632{
Stefan Weinhuber48cae882009-02-11 10:37:31 +01002633 if (expires == 0)
2634 del_timer(&block->timer);
2635 else
2636 mod_timer(&block->timer, jiffies + expires);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002637}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002638EXPORT_SYMBOL(dasd_block_set_timer);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002639
2640/*
2641 * Clear timeout for a dasd_block.
2642 */
2643void dasd_block_clear_timer(struct dasd_block *block)
2644{
Stefan Weinhuber48cae882009-02-11 10:37:31 +01002645 del_timer(&block->timer);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002646}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002647EXPORT_SYMBOL(dasd_block_clear_timer);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002648
2649/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002650 * Process finished error recovery ccw.
2651 */
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002652static void __dasd_process_erp(struct dasd_device *device,
2653 struct dasd_ccw_req *cqr)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002654{
2655 dasd_erp_fn_t erp_fn;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002656
2657 if (cqr->status == DASD_CQR_DONE)
2658 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
2659 else
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002660 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002661 erp_fn = device->discipline->erp_postaction(cqr);
2662 erp_fn(cqr);
2663}
2664
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002665static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
2666{
2667 struct request *req;
Christoph Hellwig2a842ac2017-06-03 09:38:04 +02002668 blk_status_t error = BLK_STS_OK;
Stefan Haberlande4433432017-05-22 10:59:11 +02002669 int status;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002670
2671 req = (struct request *) cqr->callback_data;
2672 dasd_profile_end(cqr->block, cqr, req);
Christoph Hellwig2a842ac2017-06-03 09:38:04 +02002673
Stefan Weinhuberfe6b8e72008-02-05 16:50:47 +01002674 status = cqr->block->base->discipline->free_cp(cqr, req);
Hannes Reinecked1ffc1f2013-01-30 09:26:16 +00002675 if (status < 0)
Christoph Hellwig2a842ac2017-06-03 09:38:04 +02002676 error = errno_to_blk_status(status);
Hannes Reinecked1ffc1f2013-01-30 09:26:16 +00002677 else if (status == 0) {
Christoph Hellwig2a842ac2017-06-03 09:38:04 +02002678 switch (cqr->intrc) {
2679 case -EPERM:
2680 error = BLK_STS_NEXUS;
2681 break;
2682 case -ENOLINK:
2683 error = BLK_STS_TRANSPORT;
2684 break;
2685 case -ETIMEDOUT:
2686 error = BLK_STS_TIMEOUT;
2687 break;
2688 default:
2689 error = BLK_STS_IOERR;
2690 break;
2691 }
Hannes Reinecked1ffc1f2013-01-30 09:26:16 +00002692 }
Stefan Haberlande4433432017-05-22 10:59:11 +02002693
2694 /*
2695 * We need to take care for ETIMEDOUT errors here since the
2696 * complete callback does not get called in this case.
2697 * Take care of all errors here and avoid additional code to
2698 * transfer the error value to the complete callback.
2699 */
2700 if (error) {
2701 blk_mq_end_request(req, error);
2702 blk_mq_run_hw_queues(req->q, true);
2703 } else {
2704 blk_mq_complete_request(req);
2705 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002706}
2707
2708/*
2709 * Process ccw request queue.
2710 */
2711static void __dasd_process_block_ccw_queue(struct dasd_block *block,
2712 struct list_head *final_queue)
2713{
2714 struct list_head *l, *n;
2715 struct dasd_ccw_req *cqr;
2716 dasd_erp_fn_t erp_fn;
2717 unsigned long flags;
2718 struct dasd_device *base = block->base;
2719
2720restart:
2721 /* Process request with final status. */
2722 list_for_each_safe(l, n, &block->ccw_queue) {
2723 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2724 if (cqr->status != DASD_CQR_DONE &&
2725 cqr->status != DASD_CQR_FAILED &&
2726 cqr->status != DASD_CQR_NEED_ERP &&
2727 cqr->status != DASD_CQR_TERMINATED)
2728 continue;
2729
2730 if (cqr->status == DASD_CQR_TERMINATED) {
2731 base->discipline->handle_terminated_request(cqr);
2732 goto restart;
2733 }
2734
2735 /* Process requests that may be recovered */
2736 if (cqr->status == DASD_CQR_NEED_ERP) {
Stefan Haberland6c5f57c2008-02-05 16:50:46 +01002737 erp_fn = base->discipline->erp_action(cqr);
Stefan Haberland6a5176c2010-04-22 17:17:02 +02002738 if (IS_ERR(erp_fn(cqr)))
2739 continue;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002740 goto restart;
2741 }
2742
Stefan Haberlanda9cffb22008-11-14 18:18:08 +01002743 /* log sense for fatal error */
2744 if (cqr->status == DASD_CQR_FAILED) {
2745 dasd_log_sense(cqr, &cqr->irb);
2746 }
2747
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002748 /* First of all call extended error reporting. */
2749 if (dasd_eer_enabled(base) &&
2750 cqr->status == DASD_CQR_FAILED) {
2751 dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
2752
2753 /* restart request */
2754 cqr->status = DASD_CQR_FILLED;
2755 cqr->retries = 255;
2756 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002757 dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002758 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
2759 flags);
2760 goto restart;
2761 }
2762
2763 /* Process finished ERP request. */
2764 if (cqr->refers) {
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002765 __dasd_process_erp(base, cqr);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002766 goto restart;
2767 }
2768
2769 /* Rechain finished requests to final queue */
Heiko Carstens1aae0562013-01-30 09:49:40 +01002770 cqr->endclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002771 list_move_tail(&cqr->blocklist, final_queue);
2772 }
2773}
2774
2775static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
2776{
2777 dasd_schedule_block_bh(cqr->block);
2778}
2779
2780static void __dasd_block_start_head(struct dasd_block *block)
2781{
2782 struct dasd_ccw_req *cqr;
2783
2784 if (list_empty(&block->ccw_queue))
2785 return;
2786 /* We allways begin with the first requests on the queue, as some
2787 * of previously started requests have to be enqueued on a
2788 * dasd_device again for error recovery.
2789 */
2790 list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
2791 if (cqr->status != DASD_CQR_FILLED)
2792 continue;
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01002793 if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) &&
2794 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2795 cqr->status = DASD_CQR_FAILED;
2796 cqr->intrc = -EPERM;
2797 dasd_schedule_block_bh(block);
2798 continue;
2799 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002800 /* Non-temporary stop condition will trigger fail fast */
2801 if (block->base->stopped & ~DASD_STOPPED_PENDING &&
2802 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2803 (!dasd_eer_enabled(block->base))) {
2804 cqr->status = DASD_CQR_FAILED;
Hannes Reinecked1ffc1f2013-01-30 09:26:16 +00002805 cqr->intrc = -ENOLINK;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002806 dasd_schedule_block_bh(block);
2807 continue;
2808 }
2809 /* Don't try to start requests if device is stopped */
2810 if (block->base->stopped)
2811 return;
2812
2813 /* just a fail safe check, should not happen */
2814 if (!cqr->startdev)
2815 cqr->startdev = block->base;
2816
2817 /* make sure that the requests we submit find their way back */
2818 cqr->callback = dasd_return_cqr_cb;
2819
2820 dasd_add_request_tail(cqr);
2821 }
2822}
2823
2824/*
2825 * Central dasd_block layer routine. Takes requests from the generic
2826 * block layer request queue, creates ccw requests, enqueues them on
2827 * a dasd_device and processes ccw requests that have been returned.
2828 */
2829static void dasd_block_tasklet(struct dasd_block *block)
2830{
2831 struct list_head final_queue;
2832 struct list_head *l, *n;
2833 struct dasd_ccw_req *cqr;
Stefan Haberlande4433432017-05-22 10:59:11 +02002834 struct dasd_queue *dq;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002835
2836 atomic_set(&block->tasklet_scheduled, 0);
2837 INIT_LIST_HEAD(&final_queue);
Stefan Haberlande4433432017-05-22 10:59:11 +02002838 spin_lock_irq(&block->queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002839 /* Finish off requests on ccw queue */
2840 __dasd_process_block_ccw_queue(block, &final_queue);
Stefan Haberlande4433432017-05-22 10:59:11 +02002841 spin_unlock_irq(&block->queue_lock);
2842
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002843 /* Now call the callback function of requests with final status */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002844 list_for_each_safe(l, n, &final_queue) {
2845 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
Stefan Haberlande4433432017-05-22 10:59:11 +02002846 dq = cqr->dq;
2847 spin_lock_irq(&dq->lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002848 list_del_init(&cqr->blocklist);
2849 __dasd_cleanup_cqr(cqr);
Stefan Haberlande4433432017-05-22 10:59:11 +02002850 spin_unlock_irq(&dq->lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002851 }
Stefan Haberlande4433432017-05-22 10:59:11 +02002852
2853 spin_lock_irq(&block->queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002854 /* Now check if the head of the ccw queue needs to be started. */
2855 __dasd_block_start_head(block);
Stefan Haberlande4433432017-05-22 10:59:11 +02002856 spin_unlock_irq(&block->queue_lock);
2857
Stefan Haberland4679e892012-06-19 17:30:12 +02002858 if (waitqueue_active(&shutdown_waitq))
2859 wake_up(&shutdown_waitq);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002860 dasd_put_device(block->base);
2861}
2862
2863static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
2864{
2865 wake_up(&dasd_flush_wq);
2866}
2867
2868/*
Stefan Haberlandc5576872013-04-15 16:41:31 +02002869 * Requeue a request back to the block request queue
2870 * only works for block requests
2871 */
2872static int _dasd_requeue_request(struct dasd_ccw_req *cqr)
2873{
2874 struct dasd_block *block = cqr->block;
2875 struct request *req;
Stefan Haberlandc5576872013-04-15 16:41:31 +02002876
2877 if (!block)
2878 return -EINVAL;
Stefan Haberlande4433432017-05-22 10:59:11 +02002879 spin_lock_irq(&cqr->dq->lock);
Stefan Haberlandc5576872013-04-15 16:41:31 +02002880 req = (struct request *) cqr->callback_data;
Stefan Haberlande4433432017-05-22 10:59:11 +02002881 blk_mq_requeue_request(req, false);
2882 spin_unlock_irq(&cqr->dq->lock);
Stefan Haberlandc5576872013-04-15 16:41:31 +02002883
2884 return 0;
2885}
2886
2887/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002888 * Go through all request on the dasd_block request queue, cancel them
2889 * on the respective dasd_device, and return them to the generic
2890 * block layer.
2891 */
2892static int dasd_flush_block_queue(struct dasd_block *block)
2893{
2894 struct dasd_ccw_req *cqr, *n;
2895 int rc, i;
2896 struct list_head flush_queue;
Stefan Haberlande4433432017-05-22 10:59:11 +02002897 unsigned long flags;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002898
2899 INIT_LIST_HEAD(&flush_queue);
2900 spin_lock_bh(&block->queue_lock);
2901 rc = 0;
2902restart:
2903 list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
2904 /* if this request currently owned by a dasd_device cancel it */
2905 if (cqr->status >= DASD_CQR_QUEUED)
2906 rc = dasd_cancel_req(cqr);
2907 if (rc < 0)
2908 break;
2909 /* Rechain request (including erp chain) so it won't be
2910 * touched by the dasd_block_tasklet anymore.
2911 * Replace the callback so we notice when the request
2912 * is returned from the dasd_device layer.
2913 */
2914 cqr->callback = _dasd_wake_block_flush_cb;
2915 for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
2916 list_move_tail(&cqr->blocklist, &flush_queue);
2917 if (i > 1)
2918 /* moved more than one request - need to restart */
2919 goto restart;
2920 }
2921 spin_unlock_bh(&block->queue_lock);
2922 /* Now call the callback function of flushed requests */
2923restart_cb:
2924 list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
2925 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
2926 /* Process finished ERP request. */
2927 if (cqr->refers) {
Stefan Haberland0cd4bd42008-12-25 13:38:54 +01002928 spin_lock_bh(&block->queue_lock);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002929 __dasd_process_erp(block->base, cqr);
Stefan Haberland0cd4bd42008-12-25 13:38:54 +01002930 spin_unlock_bh(&block->queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002931 /* restart list_for_xx loop since dasd_process_erp
2932 * might remove multiple elements */
2933 goto restart_cb;
2934 }
2935 /* call the callback function */
Stefan Haberlande4433432017-05-22 10:59:11 +02002936 spin_lock_irqsave(&cqr->dq->lock, flags);
Heiko Carstens1aae0562013-01-30 09:49:40 +01002937 cqr->endclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002938 list_del_init(&cqr->blocklist);
2939 __dasd_cleanup_cqr(cqr);
Stefan Haberlande4433432017-05-22 10:59:11 +02002940 spin_unlock_irqrestore(&cqr->dq->lock, flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002941 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 return rc;
2943}
2944
2945/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002946 * Schedules a call to dasd_tasklet over the device tasklet.
2947 */
2948void dasd_schedule_block_bh(struct dasd_block *block)
2949{
2950 /* Protect against rescheduling. */
2951 if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
2952 return;
2953 /* life cycle of block is bound to it's base device */
2954 dasd_get_device(block->base);
2955 tasklet_hi_schedule(&block->tasklet);
2956}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002957EXPORT_SYMBOL(dasd_schedule_block_bh);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002958
2959
2960/*
2961 * SECTION: external block device operations
2962 * (request queue handling, open, release, etc.)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 */
2964
2965/*
2966 * Dasd request queue function. Called from ll_rw_blk.c
2967 */
Stefan Haberlande4433432017-05-22 10:59:11 +02002968static blk_status_t do_dasd_request(struct blk_mq_hw_ctx *hctx,
2969 const struct blk_mq_queue_data *qd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970{
Stefan Haberlande4433432017-05-22 10:59:11 +02002971 struct dasd_block *block = hctx->queue->queuedata;
2972 struct dasd_queue *dq = hctx->driver_data;
2973 struct request *req = qd->rq;
2974 struct dasd_device *basedev;
2975 struct dasd_ccw_req *cqr;
2976 blk_status_t rc = BLK_STS_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977
Stefan Haberlande4433432017-05-22 10:59:11 +02002978 basedev = block->base;
2979 spin_lock_irq(&dq->lock);
2980 if (basedev->state < DASD_STATE_READY) {
2981 DBF_DEV_EVENT(DBF_ERR, basedev,
2982 "device not ready for request %p", req);
2983 rc = BLK_STS_IOERR;
2984 goto out;
2985 }
2986
2987 /*
2988 * if device is stopped do not fetch new requests
2989 * except failfast is active which will let requests fail
2990 * immediately in __dasd_block_start_head()
2991 */
2992 if (basedev->stopped && !(basedev->features & DASD_FEATURE_FAILFAST)) {
2993 DBF_DEV_EVENT(DBF_ERR, basedev,
2994 "device stopped request %p", req);
2995 rc = BLK_STS_RESOURCE;
2996 goto out;
2997 }
2998
2999 if (basedev->features & DASD_FEATURE_READONLY &&
3000 rq_data_dir(req) == WRITE) {
3001 DBF_DEV_EVENT(DBF_ERR, basedev,
3002 "Rejecting write request %p", req);
3003 rc = BLK_STS_IOERR;
3004 goto out;
3005 }
3006
3007 if (test_bit(DASD_FLAG_ABORTALL, &basedev->flags) &&
3008 (basedev->features & DASD_FEATURE_FAILFAST ||
3009 blk_noretry_request(req))) {
3010 DBF_DEV_EVENT(DBF_ERR, basedev,
3011 "Rejecting failfast request %p", req);
3012 rc = BLK_STS_IOERR;
3013 goto out;
3014 }
3015
3016 cqr = basedev->discipline->build_cp(basedev, block, req);
3017 if (IS_ERR(cqr)) {
3018 if (PTR_ERR(cqr) == -EBUSY ||
3019 PTR_ERR(cqr) == -ENOMEM ||
3020 PTR_ERR(cqr) == -EAGAIN) {
3021 rc = BLK_STS_RESOURCE;
3022 goto out;
3023 }
3024 DBF_DEV_EVENT(DBF_ERR, basedev,
3025 "CCW creation failed (rc=%ld) on request %p",
3026 PTR_ERR(cqr), req);
3027 rc = BLK_STS_IOERR;
3028 goto out;
3029 }
3030 /*
3031 * Note: callback is set to dasd_return_cqr_cb in
3032 * __dasd_block_start_head to cover erp requests as well
3033 */
3034 cqr->callback_data = req;
3035 cqr->status = DASD_CQR_FILLED;
3036 cqr->dq = dq;
3037 req->completion_data = cqr;
3038 blk_mq_start_request(req);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003039 spin_lock(&block->queue_lock);
Stefan Haberlande4433432017-05-22 10:59:11 +02003040 list_add_tail(&cqr->blocklist, &block->ccw_queue);
3041 INIT_LIST_HEAD(&cqr->devlist);
3042 dasd_profile_start(block, cqr, req);
3043 dasd_schedule_block_bh(block);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003044 spin_unlock(&block->queue_lock);
Stefan Haberlande4433432017-05-22 10:59:11 +02003045
3046out:
3047 spin_unlock_irq(&dq->lock);
3048 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049}
3050
3051/*
Hannes Reineckea2ace462013-01-30 09:26:14 +00003052 * Block timeout callback, called from the block layer
3053 *
Hannes Reineckea2ace462013-01-30 09:26:14 +00003054 * Return values:
3055 * BLK_EH_RESET_TIMER if the request should be left running
3056 * BLK_EH_NOT_HANDLED if the request is handled or terminated
3057 * by the driver.
3058 */
Stefan Haberlande4433432017-05-22 10:59:11 +02003059enum blk_eh_timer_return dasd_times_out(struct request *req, bool reserved)
Hannes Reineckea2ace462013-01-30 09:26:14 +00003060{
3061 struct dasd_ccw_req *cqr = req->completion_data;
3062 struct dasd_block *block = req->q->queuedata;
3063 struct dasd_device *device;
Stefan Haberlande4433432017-05-22 10:59:11 +02003064 unsigned long flags;
Hannes Reineckea2ace462013-01-30 09:26:14 +00003065 int rc = 0;
3066
3067 if (!cqr)
3068 return BLK_EH_NOT_HANDLED;
3069
Stefan Haberlande4433432017-05-22 10:59:11 +02003070 spin_lock_irqsave(&cqr->dq->lock, flags);
Hannes Reineckea2ace462013-01-30 09:26:14 +00003071 device = cqr->startdev ? cqr->startdev : block->base;
Stefan Haberlande4433432017-05-22 10:59:11 +02003072 if (!device->blk_timeout) {
3073 spin_unlock_irqrestore(&cqr->dq->lock, flags);
Hannes Reinecke3d71ad32013-01-30 09:26:18 +00003074 return BLK_EH_RESET_TIMER;
Stefan Haberlande4433432017-05-22 10:59:11 +02003075 }
Hannes Reineckea2ace462013-01-30 09:26:14 +00003076 DBF_DEV_EVENT(DBF_WARNING, device,
3077 " dasd_times_out cqr %p status %x",
3078 cqr, cqr->status);
3079
3080 spin_lock(&block->queue_lock);
3081 spin_lock(get_ccwdev_lock(device->cdev));
3082 cqr->retries = -1;
3083 cqr->intrc = -ETIMEDOUT;
3084 if (cqr->status >= DASD_CQR_QUEUED) {
3085 spin_unlock(get_ccwdev_lock(device->cdev));
3086 rc = dasd_cancel_req(cqr);
3087 } else if (cqr->status == DASD_CQR_FILLED ||
3088 cqr->status == DASD_CQR_NEED_ERP) {
3089 cqr->status = DASD_CQR_TERMINATED;
3090 spin_unlock(get_ccwdev_lock(device->cdev));
3091 } else if (cqr->status == DASD_CQR_IN_ERP) {
3092 struct dasd_ccw_req *searchcqr, *nextcqr, *tmpcqr;
3093
3094 list_for_each_entry_safe(searchcqr, nextcqr,
3095 &block->ccw_queue, blocklist) {
3096 tmpcqr = searchcqr;
3097 while (tmpcqr->refers)
3098 tmpcqr = tmpcqr->refers;
3099 if (tmpcqr != cqr)
3100 continue;
3101 /* searchcqr is an ERP request for cqr */
3102 searchcqr->retries = -1;
3103 searchcqr->intrc = -ETIMEDOUT;
3104 if (searchcqr->status >= DASD_CQR_QUEUED) {
3105 spin_unlock(get_ccwdev_lock(device->cdev));
3106 rc = dasd_cancel_req(searchcqr);
3107 spin_lock(get_ccwdev_lock(device->cdev));
3108 } else if ((searchcqr->status == DASD_CQR_FILLED) ||
3109 (searchcqr->status == DASD_CQR_NEED_ERP)) {
3110 searchcqr->status = DASD_CQR_TERMINATED;
3111 rc = 0;
3112 } else if (searchcqr->status == DASD_CQR_IN_ERP) {
3113 /*
3114 * Shouldn't happen; most recent ERP
3115 * request is at the front of queue
3116 */
3117 continue;
3118 }
3119 break;
3120 }
3121 spin_unlock(get_ccwdev_lock(device->cdev));
3122 }
3123 dasd_schedule_block_bh(block);
3124 spin_unlock(&block->queue_lock);
Stefan Haberlande4433432017-05-22 10:59:11 +02003125 spin_unlock_irqrestore(&cqr->dq->lock, flags);
Hannes Reineckea2ace462013-01-30 09:26:14 +00003126
3127 return rc ? BLK_EH_RESET_TIMER : BLK_EH_NOT_HANDLED;
3128}
3129
Stefan Haberlande4433432017-05-22 10:59:11 +02003130static int dasd_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
3131 unsigned int idx)
3132{
3133 struct dasd_queue *dq = kzalloc(sizeof(*dq), GFP_KERNEL);
3134
3135 if (!dq)
3136 return -ENOMEM;
3137
3138 spin_lock_init(&dq->lock);
3139 hctx->driver_data = dq;
3140
3141 return 0;
3142}
3143
3144static void dasd_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int idx)
3145{
3146 kfree(hctx->driver_data);
3147 hctx->driver_data = NULL;
3148}
3149
3150static void dasd_request_done(struct request *req)
3151{
3152 blk_mq_end_request(req, 0);
3153 blk_mq_run_hw_queues(req->q, true);
3154}
3155
3156static struct blk_mq_ops dasd_mq_ops = {
3157 .queue_rq = do_dasd_request,
3158 .complete = dasd_request_done,
3159 .timeout = dasd_times_out,
3160 .init_hctx = dasd_init_hctx,
3161 .exit_hctx = dasd_exit_hctx,
3162};
3163
Hannes Reineckea2ace462013-01-30 09:26:14 +00003164/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 * Allocate and initialize request queue and default I/O scheduler.
3166 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003167static int dasd_alloc_queue(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168{
Stefan Haberlande4433432017-05-22 10:59:11 +02003169 int rc;
3170
3171 block->tag_set.ops = &dasd_mq_ops;
3172 block->tag_set.nr_hw_queues = DASD_NR_HW_QUEUES;
3173 block->tag_set.queue_depth = DASD_MAX_LCU_DEV * DASD_REQ_PER_DEV;
3174 block->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
3175
3176 rc = blk_mq_alloc_tag_set(&block->tag_set);
3177 if (rc)
3178 return rc;
3179
3180 block->request_queue = blk_mq_init_queue(&block->tag_set);
3181 if (IS_ERR(block->request_queue))
3182 return PTR_ERR(block->request_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003184 block->request_queue->queuedata = block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185
Stefan Haberlanda5fd8dd2015-03-04 14:29:47 +01003186 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187}
3188
3189/*
3190 * Allocate and initialize request queue.
3191 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003192static void dasd_setup_queue(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193{
Jan Höppner28b841b2016-06-30 13:28:57 +02003194 unsigned int logical_block_size = block->bp_block;
Jan Höppner62ba6f82016-06-30 13:18:16 +02003195 struct request_queue *q = block->request_queue;
Jan Höppner28b841b2016-06-30 13:28:57 +02003196 unsigned int max_bytes, max_discard_sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 int max;
3198
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +01003199 if (block->base->features & DASD_FEATURE_USERAW) {
3200 /*
3201 * the max_blocks value for raw_track access is 256
3202 * it is higher than the native ECKD value because we
3203 * only need one ccw per track
3204 * so the max_hw_sectors are
3205 * 2048 x 512B = 1024kB = 16 tracks
3206 */
3207 max = 2048;
3208 } else {
3209 max = block->base->discipline->max_blocks << block->s2b_shift;
3210 }
Jan Höppner62ba6f82016-06-30 13:18:16 +02003211 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);
3212 q->limits.max_dev_sectors = max;
Jan Höppner28b841b2016-06-30 13:28:57 +02003213 blk_queue_logical_block_size(q, logical_block_size);
Jan Höppner62ba6f82016-06-30 13:18:16 +02003214 blk_queue_max_hw_sectors(q, max);
3215 blk_queue_max_segments(q, USHRT_MAX);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01003216 /* with page sized segments we can translate each segement into
3217 * one idaw/tidaw
3218 */
Jan Höppner62ba6f82016-06-30 13:18:16 +02003219 blk_queue_max_segment_size(q, PAGE_SIZE);
3220 blk_queue_segment_boundary(q, PAGE_SIZE - 1);
Jan Höppner28b841b2016-06-30 13:28:57 +02003221
3222 /* Only activate blocklayer discard support for devices that support it */
3223 if (block->base->features & DASD_FEATURE_DISCARD) {
3224 q->limits.discard_granularity = logical_block_size;
3225 q->limits.discard_alignment = PAGE_SIZE;
3226
3227 /* Calculate max_discard_sectors and make it PAGE aligned */
3228 max_bytes = USHRT_MAX * logical_block_size;
3229 max_bytes = ALIGN(max_bytes, PAGE_SIZE) - PAGE_SIZE;
3230 max_discard_sectors = max_bytes / logical_block_size;
3231
3232 blk_queue_max_discard_sectors(q, max_discard_sectors);
3233 blk_queue_max_write_zeroes_sectors(q, max_discard_sectors);
3234 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
3235 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236}
3237
3238/*
3239 * Deactivate and free request queue.
3240 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003241static void dasd_free_queue(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003243 if (block->request_queue) {
3244 blk_cleanup_queue(block->request_queue);
Stefan Haberlande4433432017-05-22 10:59:11 +02003245 blk_mq_free_tag_set(&block->tag_set);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003246 block->request_queue = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 }
3248}
3249
Al Viro57a7c0b2008-03-02 10:36:08 -05003250static int dasd_open(struct block_device *bdev, fmode_t mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251{
Stefan Haberland9eb25122010-02-26 22:37:46 +01003252 struct dasd_device *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 int rc;
3254
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003255 base = dasd_device_from_gendisk(bdev->bd_disk);
3256 if (!base)
Stefan Haberland9eb25122010-02-26 22:37:46 +01003257 return -ENODEV;
3258
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003259 atomic_inc(&base->block->open_count);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003260 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 rc = -ENODEV;
3262 goto unlock;
3263 }
3264
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003265 if (!try_module_get(base->discipline->owner)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 rc = -EINVAL;
3267 goto unlock;
3268 }
3269
3270 if (dasd_probeonly) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01003271 dev_info(&base->cdev->dev,
3272 "Accessing the DASD failed because it is in "
3273 "probeonly mode\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 rc = -EPERM;
3275 goto out;
3276 }
3277
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003278 if (base->state <= DASD_STATE_BASIC) {
3279 DBF_DEV_EVENT(DBF_ERR, base, " %s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 " Cannot open unrecognized device");
3281 rc = -ENODEV;
3282 goto out;
3283 }
3284
Stefan Weinhuber33b62a32010-03-08 12:26:24 +01003285 if ((mode & FMODE_WRITE) &&
3286 (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) ||
3287 (base->features & DASD_FEATURE_READONLY))) {
3288 rc = -EROFS;
3289 goto out;
3290 }
3291
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003292 dasd_put_device(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 return 0;
3294
3295out:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003296 module_put(base->discipline->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297unlock:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003298 atomic_dec(&base->block->open_count);
3299 dasd_put_device(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 return rc;
3301}
3302
Al Virodb2a1442013-05-05 21:52:57 -04003303static void dasd_release(struct gendisk *disk, fmode_t mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304{
Al Virodb2a1442013-05-05 21:52:57 -04003305 struct dasd_device *base = dasd_device_from_gendisk(disk);
3306 if (base) {
3307 atomic_dec(&base->block->open_count);
3308 module_put(base->discipline->owner);
3309 dasd_put_device(base);
3310 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311}
3312
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003313/*
3314 * Return disk geometry.
3315 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003316static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003317{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003318 struct dasd_device *base;
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003319
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003320 base = dasd_device_from_gendisk(bdev->bd_disk);
3321 if (!base)
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003322 return -ENODEV;
3323
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003324 if (!base->discipline ||
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003325 !base->discipline->fill_geometry) {
3326 dasd_put_device(base);
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003327 return -EINVAL;
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003328 }
3329 base->discipline->fill_geometry(base->block, geo);
3330 geo->start = get_start_sect(bdev) >> base->block->s2b_shift;
3331 dasd_put_device(base);
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003332 return 0;
3333}
3334
Alexey Dobriyan83d5cde2009-09-21 17:01:13 -07003335const struct block_device_operations
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336dasd_device_operations = {
3337 .owner = THIS_MODULE,
Al Viro57a7c0b2008-03-02 10:36:08 -05003338 .open = dasd_open,
3339 .release = dasd_release,
Heiko Carstens0000d032009-03-26 15:23:45 +01003340 .ioctl = dasd_ioctl,
3341 .compat_ioctl = dasd_ioctl,
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003342 .getgeo = dasd_getgeo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343};
3344
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003345/*******************************************************************************
3346 * end of block device operations
3347 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348
3349static void
3350dasd_exit(void)
3351{
3352#ifdef CONFIG_PROC_FS
3353 dasd_proc_exit();
3354#endif
Stefan Weinhuber20c64462006-03-24 03:15:25 -08003355 dasd_eer_exit();
Horst Hummel6bb0e012005-07-27 11:45:03 -07003356 if (dasd_page_cache != NULL) {
3357 kmem_cache_destroy(dasd_page_cache);
3358 dasd_page_cache = NULL;
3359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 dasd_gendisk_exit();
3361 dasd_devmap_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362 if (dasd_debug_area != NULL) {
3363 debug_unregister(dasd_debug_area);
3364 dasd_debug_area = NULL;
3365 }
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02003366 dasd_statistics_removeroot();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367}
3368
3369/*
3370 * SECTION: common functions for ccw_driver use
3371 */
3372
Stefan Weinhuber33b62a32010-03-08 12:26:24 +01003373/*
3374 * Is the device read-only?
3375 * Note that this function does not report the setting of the
3376 * readonly device attribute, but how it is configured in z/VM.
3377 */
3378int dasd_device_is_ro(struct dasd_device *device)
3379{
3380 struct ccw_dev_id dev_id;
3381 struct diag210 diag_data;
3382 int rc;
3383
3384 if (!MACHINE_IS_VM)
3385 return 0;
3386 ccw_device_get_id(device->cdev, &dev_id);
3387 memset(&diag_data, 0, sizeof(diag_data));
3388 diag_data.vrdcdvno = dev_id.devno;
3389 diag_data.vrdclen = sizeof(diag_data);
3390 rc = diag210(&diag_data);
3391 if (rc == 0 || rc == 2) {
3392 return diag_data.vrdcvfla & 0x80;
3393 } else {
3394 DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d",
3395 dev_id.devno, rc);
3396 return 0;
3397 }
3398}
3399EXPORT_SYMBOL_GPL(dasd_device_is_ro);
3400
Cornelia Huckf3445a12009-04-14 15:36:23 +02003401static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
3402{
3403 struct ccw_device *cdev = data;
3404 int ret;
3405
3406 ret = ccw_device_set_online(cdev);
3407 if (ret)
Fabian Frederick4ce25962014-06-26 19:41:48 +02003408 pr_warn("%s: Setting the DASD online failed with rc=%d\n",
3409 dev_name(&cdev->dev), ret);
Cornelia Huckf3445a12009-04-14 15:36:23 +02003410}
3411
Horst Hummel1c01b8a2006-01-06 00:19:15 -08003412/*
3413 * Initial attempt at a probe function. this can be simplified once
3414 * the other detection code is gone.
3415 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003416int dasd_generic_probe(struct ccw_device *cdev,
3417 struct dasd_discipline *discipline)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418{
3419 int ret;
3420
3421 ret = dasd_add_sysfs_files(cdev);
3422 if (ret) {
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01003423 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
3424 "dasd_generic_probe: could not add "
3425 "sysfs entries");
Horst Hummel40545572006-06-29 15:08:18 +02003426 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 }
Horst Hummel40545572006-06-29 15:08:18 +02003428 cdev->handler = &dasd_int_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429
Horst Hummel40545572006-06-29 15:08:18 +02003430 /*
3431 * Automatically online either all dasd devices (dasd_autodetect)
3432 * or all devices specified with dasd= parameters during
3433 * initial probe.
3434 */
3435 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
Kay Sievers2a0217d2008-10-10 21:33:09 +02003436 (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
Cornelia Huckf3445a12009-04-14 15:36:23 +02003437 async_schedule(dasd_generic_auto_online, cdev);
Stefan Haberlandde3e0da2008-01-26 14:11:08 +01003438 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003440EXPORT_SYMBOL_GPL(dasd_generic_probe);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441
Stefan Haberlandc020d722016-09-20 10:42:38 +02003442void dasd_generic_free_discipline(struct dasd_device *device)
3443{
3444 /* Forget the discipline information. */
3445 if (device->discipline) {
3446 if (device->discipline->uncheck_device)
3447 device->discipline->uncheck_device(device);
3448 module_put(device->discipline->owner);
3449 device->discipline = NULL;
3450 }
3451 if (device->base_discipline) {
3452 module_put(device->base_discipline->owner);
3453 device->base_discipline = NULL;
3454 }
3455}
3456EXPORT_SYMBOL_GPL(dasd_generic_free_discipline);
3457
Horst Hummel1c01b8a2006-01-06 00:19:15 -08003458/*
3459 * This will one day be called from a global not_oper handler.
3460 * It is also used by driver_unregister during module unload.
3461 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003462void dasd_generic_remove(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463{
3464 struct dasd_device *device;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003465 struct dasd_block *block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466
Horst Hummel59afda72005-05-16 21:53:39 -07003467 cdev->handler = NULL;
3468
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 device = dasd_device_from_cdev(cdev);
Stefan Weinhuberbe4904e2013-02-04 13:10:35 +01003470 if (IS_ERR(device)) {
3471 dasd_remove_sysfs_files(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 return;
Stefan Weinhuberbe4904e2013-02-04 13:10:35 +01003473 }
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003474 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3475 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476 /* Already doing offline processing */
3477 dasd_put_device(device);
Stefan Weinhuberbe4904e2013-02-04 13:10:35 +01003478 dasd_remove_sysfs_files(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 return;
3480 }
3481 /*
3482 * This device is removed unconditionally. Set offline
3483 * flag to prevent dasd_open from opening it while it is
3484 * no quite down yet.
3485 */
3486 dasd_set_target_state(device, DASD_STATE_NEW);
3487 /* dasd_delete_device destroys the device reference. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003488 block = device->block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 dasd_delete_device(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003490 /*
3491 * life cycle of block is bound to device, so delete it after
3492 * device was safely removed
3493 */
3494 if (block)
3495 dasd_free_block(block);
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003496
3497 dasd_remove_sysfs_files(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003499EXPORT_SYMBOL_GPL(dasd_generic_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500
Horst Hummel1c01b8a2006-01-06 00:19:15 -08003501/*
3502 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 * the device is detected for the first time and is supposed to be used
Horst Hummel1c01b8a2006-01-06 00:19:15 -08003504 * or the user has started activation through sysfs.
3505 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003506int dasd_generic_set_online(struct ccw_device *cdev,
3507 struct dasd_discipline *base_discipline)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508{
Peter Oberparleiteraa888612006-02-20 18:28:13 -08003509 struct dasd_discipline *discipline;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 struct dasd_device *device;
Horst Hummelc6eb7b72005-09-03 15:57:58 -07003511 int rc;
Horst Hummelf24acd42005-05-01 08:58:59 -07003512
Horst Hummel40545572006-06-29 15:08:18 +02003513 /* first online clears initial online feature flag */
3514 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515 device = dasd_create_device(cdev);
3516 if (IS_ERR(device))
3517 return PTR_ERR(device);
3518
Peter Oberparleiteraa888612006-02-20 18:28:13 -08003519 discipline = base_discipline;
Horst Hummelc6eb7b72005-09-03 15:57:58 -07003520 if (device->features & DASD_FEATURE_USEDIAG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 if (!dasd_diag_discipline_pointer) {
Peter Oberparleiter7c53fcb2015-05-11 13:08:05 +02003522 /* Try to load the required module. */
3523 rc = request_module(DASD_DIAG_MOD);
3524 if (rc) {
3525 pr_warn("%s Setting the DASD online failed "
3526 "because the required module %s "
3527 "could not be loaded (rc=%d)\n",
3528 dev_name(&cdev->dev), DASD_DIAG_MOD,
3529 rc);
3530 dasd_delete_device(device);
3531 return -ENODEV;
3532 }
3533 }
3534 /* Module init could have failed, so check again here after
3535 * request_module(). */
3536 if (!dasd_diag_discipline_pointer) {
Fabian Frederick4ce25962014-06-26 19:41:48 +02003537 pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n",
3538 dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539 dasd_delete_device(device);
3540 return -ENODEV;
3541 }
3542 discipline = dasd_diag_discipline_pointer;
3543 }
Peter Oberparleiteraa888612006-02-20 18:28:13 -08003544 if (!try_module_get(base_discipline->owner)) {
3545 dasd_delete_device(device);
3546 return -EINVAL;
3547 }
3548 if (!try_module_get(discipline->owner)) {
3549 module_put(base_discipline->owner);
3550 dasd_delete_device(device);
3551 return -EINVAL;
3552 }
3553 device->base_discipline = base_discipline;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554 device->discipline = discipline;
3555
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003556 /* check_device will allocate block device if necessary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 rc = discipline->check_device(device);
3558 if (rc) {
Fabian Frederick4ce25962014-06-26 19:41:48 +02003559 pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
3560 dev_name(&cdev->dev), discipline->name, rc);
Peter Oberparleiteraa888612006-02-20 18:28:13 -08003561 module_put(discipline->owner);
3562 module_put(base_discipline->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563 dasd_delete_device(device);
3564 return rc;
3565 }
3566
3567 dasd_set_target_state(device, DASD_STATE_ONLINE);
3568 if (device->state <= DASD_STATE_KNOWN) {
Fabian Frederick4ce25962014-06-26 19:41:48 +02003569 pr_warn("%s Setting the DASD online failed because of a missing discipline\n",
3570 dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571 rc = -ENODEV;
3572 dasd_set_target_state(device, DASD_STATE_NEW);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003573 if (device->block)
3574 dasd_free_block(device->block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 dasd_delete_device(device);
3576 } else
3577 pr_debug("dasd_generic device %s found\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +02003578 dev_name(&cdev->dev));
Stefan Haberland589c74d2010-02-26 22:37:47 +01003579
3580 wait_event(dasd_init_waitq, _wait_for_device(device));
3581
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582 dasd_put_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583 return rc;
3584}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003585EXPORT_SYMBOL_GPL(dasd_generic_set_online);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003587int dasd_generic_set_offline(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588{
3589 struct dasd_device *device;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003590 struct dasd_block *block;
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003591 int max_count, open_count, rc;
Jan Höppner0f57c972016-10-18 17:54:49 +02003592 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003594 rc = 0;
Jan Höppner0f57c972016-10-18 17:54:49 +02003595 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3596 device = dasd_device_from_cdev_locked(cdev);
3597 if (IS_ERR(device)) {
3598 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599 return PTR_ERR(device);
Jan Höppner0f57c972016-10-18 17:54:49 +02003600 }
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003601
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602 /*
3603 * We must make sure that this device is currently not in use.
3604 * The open_count is increased for every opener, that includes
3605 * the blkdev_get in dasd_scan_partitions. We are only interested
3606 * in the other openers.
3607 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003608 if (device->block) {
Heiko Carstensa8061702008-04-17 07:46:26 +02003609 max_count = device->block->bdev ? 0 : -1;
3610 open_count = atomic_read(&device->block->open_count);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003611 if (open_count > max_count) {
3612 if (open_count > 0)
Fabian Frederick4ce25962014-06-26 19:41:48 +02003613 pr_warn("%s: The DASD cannot be set offline with open count %i\n",
3614 dev_name(&cdev->dev), open_count);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003615 else
Fabian Frederick4ce25962014-06-26 19:41:48 +02003616 pr_warn("%s: The DASD cannot be set offline while it is in use\n",
3617 dev_name(&cdev->dev));
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003618 rc = -EBUSY;
3619 goto out_err;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003620 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 }
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003622
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003623 /*
3624 * Test if the offline processing is already running and exit if so.
3625 * If a safe offline is being processed this could only be a normal
3626 * offline that should be able to overtake the safe offline and
3627 * cancel any I/O we do not want to wait for any longer
3628 */
3629 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3630 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3631 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING,
3632 &device->flags);
3633 } else {
3634 rc = -EBUSY;
3635 goto out_err;
3636 }
Jan Höppner0f57c972016-10-18 17:54:49 +02003637 }
Jan Höppner0f57c972016-10-18 17:54:49 +02003638 set_bit(DASD_FLAG_OFFLINE, &device->flags);
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003639
3640 /*
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003641 * if safe_offline is called set safe_offline_running flag and
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003642 * clear safe_offline so that a call to normal offline
3643 * can overrun safe_offline processing
3644 */
3645 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
3646 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003647 /* need to unlock here to wait for outstanding I/O */
3648 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003649 /*
3650 * If we want to set the device safe offline all IO operations
3651 * should be finished before continuing the offline process
3652 * so sync bdev first and then wait for our queues to become
3653 * empty
3654 */
Stefan Haberlandca732e12017-01-25 16:56:41 +01003655 if (device->block) {
3656 rc = fsync_bdev(device->block->bdev);
3657 if (rc != 0)
3658 goto interrupted;
3659 }
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003660 dasd_schedule_device_bh(device);
3661 rc = wait_event_interruptible(shutdown_waitq,
3662 _wait_for_empty_queues(device));
3663 if (rc != 0)
3664 goto interrupted;
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003665
3666 /*
3667 * check if a normal offline process overtook the offline
3668 * processing in this case simply do nothing beside returning
3669 * that we got interrupted
3670 * otherwise mark safe offline as not running any longer and
3671 * continue with normal offline
3672 */
3673 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3674 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3675 rc = -ERESTARTSYS;
3676 goto out_err;
3677 }
3678 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003679 }
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003680 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003681
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 dasd_set_target_state(device, DASD_STATE_NEW);
3683 /* dasd_delete_device destroys the device reference. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003684 block = device->block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 dasd_delete_device(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003686 /*
3687 * life cycle of block is bound to device, so delete it after
3688 * device was safely removed
3689 */
3690 if (block)
3691 dasd_free_block(block);
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003692
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 return 0;
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003694
3695interrupted:
3696 /* interrupted by signal */
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003697 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003698 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3699 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003700out_err:
Jan Höppner0f57c972016-10-18 17:54:49 +02003701 dasd_put_device(device);
3702 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003703 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003705EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003707int dasd_generic_last_path_gone(struct dasd_device *device)
3708{
3709 struct dasd_ccw_req *cqr;
3710
3711 dev_warn(&device->cdev->dev, "No operational channel path is left "
3712 "for the device\n");
3713 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
3714 /* First of all call extended error reporting. */
3715 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3716
3717 if (device->state < DASD_STATE_BASIC)
3718 return 0;
3719 /* Device is active. We want to keep it. */
3720 list_for_each_entry(cqr, &device->ccw_queue, devlist)
3721 if ((cqr->status == DASD_CQR_IN_IO) ||
3722 (cqr->status == DASD_CQR_CLEAR_PENDING)) {
3723 cqr->status = DASD_CQR_QUEUED;
3724 cqr->retries++;
3725 }
3726 dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
3727 dasd_device_clear_timer(device);
3728 dasd_schedule_device_bh(device);
3729 return 1;
3730}
3731EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone);
3732
3733int dasd_generic_path_operational(struct dasd_device *device)
3734{
3735 dev_info(&device->cdev->dev, "A channel path to the device has become "
3736 "operational\n");
3737 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
3738 dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
3739 if (device->stopped & DASD_UNRESUMED_PM) {
3740 dasd_device_remove_stop_bits(device, DASD_UNRESUMED_PM);
3741 dasd_restore_device(device);
3742 return 1;
3743 }
3744 dasd_schedule_device_bh(device);
Stefan Haberlande4433432017-05-22 10:59:11 +02003745 if (device->block) {
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003746 dasd_schedule_block_bh(device->block);
Stefan Haberland673514a2017-09-12 17:22:42 +02003747 if (device->block->request_queue)
3748 blk_mq_run_hw_queues(device->block->request_queue,
3749 true);
Stefan Haberlande4433432017-05-22 10:59:11 +02003750 }
Stefan Haberland931a3dc2014-07-18 14:22:41 +02003751
3752 if (!device->stopped)
3753 wake_up(&generic_waitq);
3754
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003755 return 1;
3756}
3757EXPORT_SYMBOL_GPL(dasd_generic_path_operational);
3758
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003759int dasd_generic_notify(struct ccw_device *cdev, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760{
3761 struct dasd_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762 int ret;
3763
Peter Oberparleiter91c36912008-08-21 19:46:39 +02003764 device = dasd_device_from_cdev_locked(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 if (IS_ERR(device))
3766 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767 ret = 0;
3768 switch (event) {
3769 case CIO_GONE:
Sebastian Ott47593bf2009-03-31 19:16:05 +02003770 case CIO_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 case CIO_NO_PATH:
Stefan Haberlandc9346152016-08-08 15:53:54 +02003772 dasd_path_no_path(device);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003773 ret = dasd_generic_last_path_gone(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774 break;
3775 case CIO_OPER:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776 ret = 1;
Stefan Haberlandc9346152016-08-08 15:53:54 +02003777 if (dasd_path_get_opm(device))
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003778 ret = dasd_generic_path_operational(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 break;
3780 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 dasd_put_device(device);
3782 return ret;
3783}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003784EXPORT_SYMBOL_GPL(dasd_generic_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003786void dasd_generic_path_event(struct ccw_device *cdev, int *path_event)
3787{
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003788 struct dasd_device *device;
Stefan Haberlanda521b042016-08-08 15:56:54 +02003789 int chp, oldopm, hpfpm, ifccpm;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003790
3791 device = dasd_device_from_cdev_locked(cdev);
3792 if (IS_ERR(device))
3793 return;
Stefan Haberlandc9346152016-08-08 15:53:54 +02003794
3795 oldopm = dasd_path_get_opm(device);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003796 for (chp = 0; chp < 8; chp++) {
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003797 if (path_event[chp] & PE_PATH_GONE) {
Stefan Haberlandc9346152016-08-08 15:53:54 +02003798 dasd_path_notoper(device, chp);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003799 }
3800 if (path_event[chp] & PE_PATH_AVAILABLE) {
Stefan Haberlandc9346152016-08-08 15:53:54 +02003801 dasd_path_available(device, chp);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003802 dasd_schedule_device_bh(device);
3803 }
Stefan Haberlandf1633032012-01-18 18:03:41 +01003804 if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) {
Stefan Haberlandc9346152016-08-08 15:53:54 +02003805 if (!dasd_path_is_operational(device, chp) &&
3806 !dasd_path_need_verify(device, chp)) {
Stefan Haberland12d7b102012-09-11 15:10:58 +02003807 /*
3808 * we can not establish a pathgroup on an
3809 * unavailable path, so trigger a path
3810 * verification first
3811 */
Stefan Haberlandc9346152016-08-08 15:53:54 +02003812 dasd_path_available(device, chp);
3813 dasd_schedule_device_bh(device);
Stefan Haberland12d7b102012-09-11 15:10:58 +02003814 }
Stefan Haberlandf1633032012-01-18 18:03:41 +01003815 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3816 "Pathgroup re-established\n");
3817 if (device->discipline->kick_validate)
3818 device->discipline->kick_validate(device);
3819 }
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003820 }
Stefan Haberlanda521b042016-08-08 15:56:54 +02003821 hpfpm = dasd_path_get_hpfpm(device);
3822 ifccpm = dasd_path_get_ifccpm(device);
3823 if (!dasd_path_get_opm(device) && hpfpm) {
3824 /*
3825 * device has no operational paths but at least one path is
3826 * disabled due to HPF errors
3827 * disable HPF at all and use the path(s) again
3828 */
3829 if (device->discipline->disable_hpf)
3830 device->discipline->disable_hpf(device);
3831 dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
3832 dasd_path_set_tbvpm(device, hpfpm);
3833 dasd_schedule_device_bh(device);
3834 dasd_schedule_requeue(device);
3835 } else if (!dasd_path_get_opm(device) && ifccpm) {
3836 /*
3837 * device has no operational paths but at least one path is
3838 * disabled due to IFCC errors
3839 * trigger path verification on paths with IFCC errors
3840 */
3841 dasd_path_set_tbvpm(device, ifccpm);
3842 dasd_schedule_device_bh(device);
3843 }
3844 if (oldopm && !dasd_path_get_opm(device) && !hpfpm && !ifccpm) {
Stefan Haberlandc9346152016-08-08 15:53:54 +02003845 dev_warn(&device->cdev->dev,
3846 "No verified channel paths remain for the device\n");
3847 DBF_DEV_EVENT(DBF_WARNING, device,
3848 "%s", "last verified path gone");
3849 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3850 dasd_device_set_stop_bits(device,
3851 DASD_STOPPED_DC_WAIT);
3852 }
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003853 dasd_put_device(device);
3854}
3855EXPORT_SYMBOL_GPL(dasd_generic_path_event);
3856
3857int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
3858{
Stefan Haberlandc9346152016-08-08 15:53:54 +02003859 if (!dasd_path_get_opm(device) && lpm) {
3860 dasd_path_set_opm(device, lpm);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003861 dasd_generic_path_operational(device);
3862 } else
Stefan Haberlandc9346152016-08-08 15:53:54 +02003863 dasd_path_add_opm(device, lpm);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003864 return 0;
3865}
3866EXPORT_SYMBOL_GPL(dasd_generic_verify_path);
3867
Stefan Haberlanda521b042016-08-08 15:56:54 +02003868/*
3869 * clear active requests and requeue them to block layer if possible
3870 */
3871static int dasd_generic_requeue_all_requests(struct dasd_device *device)
3872{
3873 struct list_head requeue_queue;
3874 struct dasd_ccw_req *cqr, *n;
3875 struct dasd_ccw_req *refers;
3876 int rc;
3877
3878 INIT_LIST_HEAD(&requeue_queue);
3879 spin_lock_irq(get_ccwdev_lock(device->cdev));
3880 rc = 0;
3881 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
3882 /* Check status and move request to flush_queue */
3883 if (cqr->status == DASD_CQR_IN_IO) {
3884 rc = device->discipline->term_IO(cqr);
3885 if (rc) {
3886 /* unable to terminate requeust */
3887 dev_err(&device->cdev->dev,
3888 "Unable to terminate request %p "
3889 "on suspend\n", cqr);
3890 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3891 dasd_put_device(device);
3892 return rc;
3893 }
3894 }
3895 list_move_tail(&cqr->devlist, &requeue_queue);
3896 }
3897 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3898
3899 list_for_each_entry_safe(cqr, n, &requeue_queue, devlist) {
3900 wait_event(dasd_flush_wq,
3901 (cqr->status != DASD_CQR_CLEAR_PENDING));
3902
Stefan Haberland9487cfd2018-02-07 17:39:14 +01003903 /*
3904 * requeue requests to blocklayer will only work
3905 * for block device requests
3906 */
3907 if (_dasd_requeue_request(cqr))
3908 continue;
Stefan Haberlanda521b042016-08-08 15:56:54 +02003909
3910 /* remove requests from device and block queue */
3911 list_del_init(&cqr->devlist);
3912 while (cqr->refers != NULL) {
3913 refers = cqr->refers;
3914 /* remove the request from the block queue */
3915 list_del(&cqr->blocklist);
3916 /* free the finished erp request */
3917 dasd_free_erp_request(cqr, cqr->memdev);
3918 cqr = refers;
3919 }
3920
Stefan Haberlanda1fc8182018-02-19 12:24:39 +01003921 /*
3922 * _dasd_requeue_request already checked for a valid
3923 * blockdevice, no need to check again
3924 * all erp requests (cqr->refers) have a cqr->block
3925 * pointer copy from the original cqr
3926 */
3927 list_del_init(&cqr->blocklist);
Stefan Haberlanda521b042016-08-08 15:56:54 +02003928 cqr->block->base->discipline->free_cp(
3929 cqr, (struct request *) cqr->callback_data);
3930 }
3931
3932 /*
3933 * if requests remain then they are internal request
3934 * and go back to the device queue
3935 */
3936 if (!list_empty(&requeue_queue)) {
3937 /* move freeze_queue to start of the ccw_queue */
3938 spin_lock_irq(get_ccwdev_lock(device->cdev));
3939 list_splice_tail(&requeue_queue, &device->ccw_queue);
3940 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3941 }
Stefan Haberland9487cfd2018-02-07 17:39:14 +01003942 dasd_schedule_device_bh(device);
Stefan Haberlanda521b042016-08-08 15:56:54 +02003943 return rc;
3944}
3945
3946static void do_requeue_requests(struct work_struct *work)
3947{
3948 struct dasd_device *device = container_of(work, struct dasd_device,
3949 requeue_requests);
3950 dasd_generic_requeue_all_requests(device);
3951 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOT_ACC);
3952 if (device->block)
3953 dasd_schedule_block_bh(device->block);
3954 dasd_put_device(device);
3955}
3956
3957void dasd_schedule_requeue(struct dasd_device *device)
3958{
3959 dasd_get_device(device);
3960 /* queue call to dasd_reload_device to the kernel event daemon. */
3961 if (!schedule_work(&device->requeue_requests))
3962 dasd_put_device(device);
3963}
3964EXPORT_SYMBOL(dasd_schedule_requeue);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003965
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003966int dasd_generic_pm_freeze(struct ccw_device *cdev)
3967{
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003968 struct dasd_device *device = dasd_device_from_cdev(cdev);
3969
3970 if (IS_ERR(device))
3971 return PTR_ERR(device);
Stefan Haberland6f272b92011-01-05 12:48:05 +01003972
Stefan Haberlandc8d1c0f2011-10-30 15:17:09 +01003973 /* mark device as suspended */
3974 set_bit(DASD_FLAG_SUSPENDED, &device->flags);
3975
Stefan Haberland6f272b92011-01-05 12:48:05 +01003976 if (device->discipline->freeze)
Sebastian Ott4bca6982017-06-26 19:26:55 +02003977 device->discipline->freeze(device);
Stefan Haberland6f272b92011-01-05 12:48:05 +01003978
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003979 /* disallow new I/O */
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01003980 dasd_device_set_stop_bits(device, DASD_STOPPED_PM);
Stefan Haberlandc5576872013-04-15 16:41:31 +02003981
Stefan Haberlanda521b042016-08-08 15:56:54 +02003982 return dasd_generic_requeue_all_requests(device);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003983}
3984EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze);
3985
3986int dasd_generic_restore_device(struct ccw_device *cdev)
3987{
3988 struct dasd_device *device = dasd_device_from_cdev(cdev);
3989 int rc = 0;
3990
3991 if (IS_ERR(device))
3992 return PTR_ERR(device);
3993
Stefan Haberlande6125fb2009-06-22 12:08:17 +02003994 /* allow new IO again */
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01003995 dasd_device_remove_stop_bits(device,
3996 (DASD_STOPPED_PM | DASD_UNRESUMED_PM));
Stefan Haberlande6125fb2009-06-22 12:08:17 +02003997
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003998 dasd_schedule_device_bh(device);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02003999
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01004000 /*
4001 * call discipline restore function
4002 * if device is stopped do nothing e.g. for disconnected devices
4003 */
4004 if (device->discipline->restore && !(device->stopped))
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004005 rc = device->discipline->restore(device);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01004006 if (rc || device->stopped)
Stefan Haberlande6125fb2009-06-22 12:08:17 +02004007 /*
4008 * if the resume failed for the DASD we put it in
4009 * an UNRESUMED stop state
4010 */
4011 device->stopped |= DASD_UNRESUMED_PM;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004012
Stefan Haberlande4433432017-05-22 10:59:11 +02004013 if (device->block) {
Stefan Haberland6fca97a2009-10-06 10:34:15 +02004014 dasd_schedule_block_bh(device->block);
Stefan Haberland673514a2017-09-12 17:22:42 +02004015 if (device->block->request_queue)
4016 blk_mq_run_hw_queues(device->block->request_queue,
4017 true);
Stefan Haberlande4433432017-05-22 10:59:11 +02004018 }
Stefan Haberland6fca97a2009-10-06 10:34:15 +02004019
Stefan Haberlandc8d1c0f2011-10-30 15:17:09 +01004020 clear_bit(DASD_FLAG_SUSPENDED, &device->flags);
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004021 dasd_put_device(device);
Stefan Haberlande6125fb2009-06-22 12:08:17 +02004022 return 0;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02004023}
4024EXPORT_SYMBOL_GPL(dasd_generic_restore_device);
4025
Heiko Carstens763968e2007-05-10 15:45:46 +02004026static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
4027 void *rdc_buffer,
4028 int rdc_buffer_size,
Stefan Haberland68b781f2009-09-11 10:28:29 +02004029 int magic)
Cornelia Huck17283b52007-05-04 18:47:51 +02004030{
4031 struct dasd_ccw_req *cqr;
4032 struct ccw1 *ccw;
Stefan Haberlandd9fa9442009-10-14 12:43:48 +02004033 unsigned long *idaw;
Cornelia Huck17283b52007-05-04 18:47:51 +02004034
4035 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device);
4036
4037 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01004038 /* internal error 13 - Allocating the RDC request failed*/
4039 dev_err(&device->cdev->dev,
4040 "An error occurred in the DASD device driver, "
4041 "reason=%s\n", "13");
Cornelia Huck17283b52007-05-04 18:47:51 +02004042 return cqr;
4043 }
4044
4045 ccw = cqr->cpaddr;
4046 ccw->cmd_code = CCW_CMD_RDC;
Stefan Haberlandd9fa9442009-10-14 12:43:48 +02004047 if (idal_is_needed(rdc_buffer, rdc_buffer_size)) {
4048 idaw = (unsigned long *) (cqr->data);
4049 ccw->cda = (__u32)(addr_t) idaw;
4050 ccw->flags = CCW_FLAG_IDA;
4051 idaw = idal_create_words(idaw, rdc_buffer, rdc_buffer_size);
4052 } else {
4053 ccw->cda = (__u32)(addr_t) rdc_buffer;
4054 ccw->flags = 0;
4055 }
Cornelia Huck17283b52007-05-04 18:47:51 +02004056
Stefan Haberlandd9fa9442009-10-14 12:43:48 +02004057 ccw->count = rdc_buffer_size;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004058 cqr->startdev = device;
4059 cqr->memdev = device;
Cornelia Huck17283b52007-05-04 18:47:51 +02004060 cqr->expires = 10*HZ;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01004061 cqr->retries = 256;
Heiko Carstens1aae0562013-01-30 09:49:40 +01004062 cqr->buildclk = get_tod_clock();
Cornelia Huck17283b52007-05-04 18:47:51 +02004063 cqr->status = DASD_CQR_FILLED;
4064 return cqr;
4065}
4066
4067
Stefan Haberland68b781f2009-09-11 10:28:29 +02004068int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
Sebastian Ott92636b12009-06-12 10:26:37 +02004069 void *rdc_buffer, int rdc_buffer_size)
Cornelia Huck17283b52007-05-04 18:47:51 +02004070{
4071 int ret;
4072 struct dasd_ccw_req *cqr;
4073
Sebastian Ott92636b12009-06-12 10:26:37 +02004074 cqr = dasd_generic_build_rdc(device, rdc_buffer, rdc_buffer_size,
Cornelia Huck17283b52007-05-04 18:47:51 +02004075 magic);
4076 if (IS_ERR(cqr))
4077 return PTR_ERR(cqr);
4078
4079 ret = dasd_sleep_on(cqr);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004080 dasd_sfree_request(cqr, cqr->memdev);
Cornelia Huck17283b52007-05-04 18:47:51 +02004081 return ret;
4082}
Cornelia Huckaaff0f62007-05-10 15:45:45 +02004083EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
Stefan Weinhuber20c64462006-03-24 03:15:25 -08004084
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004085/*
4086 * In command mode and transport mode we need to look for sense
4087 * data in different places. The sense data itself is allways
4088 * an array of 32 bytes, so we can unify the sense data access
4089 * for both modes.
4090 */
4091char *dasd_get_sense(struct irb *irb)
4092{
4093 struct tsb *tsb = NULL;
4094 char *sense = NULL;
4095
4096 if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
4097 if (irb->scsw.tm.tcw)
4098 tsb = tcw_get_tsb((struct tcw *)(unsigned long)
4099 irb->scsw.tm.tcw);
4100 if (tsb && tsb->length == 64 && tsb->flags)
4101 switch (tsb->flags & 0x07) {
4102 case 1: /* tsa_iostat */
4103 sense = tsb->tsa.iostat.sense;
4104 break;
4105 case 2: /* tsa_ddpc */
4106 sense = tsb->tsa.ddpc.sense;
4107 break;
4108 default:
4109 /* currently we don't use interrogate data */
4110 break;
4111 }
4112 } else if (irb->esw.esw0.erw.cons) {
4113 sense = irb->ecw;
4114 }
4115 return sense;
4116}
4117EXPORT_SYMBOL_GPL(dasd_get_sense);
4118
Stefan Haberland4679e892012-06-19 17:30:12 +02004119void dasd_generic_shutdown(struct ccw_device *cdev)
4120{
4121 struct dasd_device *device;
4122
4123 device = dasd_device_from_cdev(cdev);
4124 if (IS_ERR(device))
4125 return;
4126
4127 if (device->block)
4128 dasd_schedule_block_bh(device->block);
4129
4130 dasd_schedule_device_bh(device);
4131
4132 wait_event(shutdown_waitq, _wait_for_empty_queues(device));
4133}
4134EXPORT_SYMBOL_GPL(dasd_generic_shutdown);
4135
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004136static int __init dasd_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137{
4138 int rc;
4139
4140 init_waitqueue_head(&dasd_init_waitq);
Horst Hummel8f617012006-08-30 14:33:33 +02004141 init_waitqueue_head(&dasd_flush_wq);
Stefan Haberlandc80ee722008-05-30 10:03:31 +02004142 init_waitqueue_head(&generic_waitq);
Stefan Haberland4679e892012-06-19 17:30:12 +02004143 init_waitqueue_head(&shutdown_waitq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144
4145 /* register 'common' DASD debug area, used for all DBF_XXX calls */
Peter Tiedemann361f4942008-01-26 14:11:30 +01004146 dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 if (dasd_debug_area == NULL) {
4148 rc = -ENOMEM;
4149 goto failed;
4150 }
4151 debug_register_view(dasd_debug_area, &debug_sprintf_view);
Horst Hummelb0035f12006-09-20 15:59:07 +02004152 debug_set_level(dasd_debug_area, DBF_WARNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153
4154 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
4155
4156 dasd_diag_discipline_pointer = NULL;
4157
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02004158 dasd_statistics_createroot();
4159
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 rc = dasd_devmap_init();
4161 if (rc)
4162 goto failed;
4163 rc = dasd_gendisk_init();
4164 if (rc)
4165 goto failed;
4166 rc = dasd_parse();
4167 if (rc)
4168 goto failed;
Stefan Weinhuber20c64462006-03-24 03:15:25 -08004169 rc = dasd_eer_init();
4170 if (rc)
4171 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172#ifdef CONFIG_PROC_FS
4173 rc = dasd_proc_init();
4174 if (rc)
4175 goto failed;
4176#endif
4177
4178 return 0;
4179failed:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01004180 pr_info("The DASD device driver could not be initialized\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181 dasd_exit();
4182 return rc;
4183}
4184
4185module_init(dasd_init);
4186module_exit(dasd_exit);