blob: 8e87a31e329d047c0172f55d31bb9e6989d71755 [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
Stefan Haberland3284da32018-06-12 16:47:10 +020044static unsigned int queue_depth = 32;
45static unsigned int nr_hw_queues = 4;
46
47module_param(queue_depth, uint, 0444);
48MODULE_PARM_DESC(queue_depth, "Default queue depth for new DASD devices");
49
50module_param(nr_hw_queues, uint, 0444);
51MODULE_PARM_DESC(nr_hw_queues, "Default number of hardware queues for new DASD devices");
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053/*
54 * SECTION: exported variables of dasd.c
55 */
56debug_info_t *dasd_debug_area;
Fabian Frederick7048a2b2014-06-26 19:41:47 +020057EXPORT_SYMBOL(dasd_debug_area);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +020058static struct dentry *dasd_debugfs_root_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059struct dasd_discipline *dasd_diag_discipline_pointer;
Fabian Frederick7048a2b2014-06-26 19:41:47 +020060EXPORT_SYMBOL(dasd_diag_discipline_pointer);
Heiko Carstens2b67fc42007-02-05 21:16:47 +010061void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
64MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
Heiko Carstensa53c8fa2012-07-20 11:15:04 +020065 " Copyright IBM Corp. 2000");
Linus Torvalds1da177e2005-04-16 15:20:36 -070066MODULE_LICENSE("GPL");
67
68/*
69 * SECTION: prototypes for static functions of dasd.c
70 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010071static int dasd_alloc_queue(struct dasd_block *);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010072static void dasd_free_queue(struct dasd_block *);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010073static int dasd_flush_block_queue(struct dasd_block *);
Sebastian Ottd2f2df62018-07-03 13:06:45 +020074static void dasd_device_tasklet(unsigned long);
75static void dasd_block_tasklet(unsigned long);
Al Viro4927b3f2006-12-06 19:18:20 +000076static void do_kick_device(struct work_struct *);
Stefan Haberland501183f2010-05-17 10:00:10 +020077static void do_reload_device(struct work_struct *);
Stefan Haberlanda521b042016-08-08 15:56:54 +020078static void do_requeue_requests(struct work_struct *);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010079static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
Kees Cooke99e88a2017-10-16 14:43:17 -070080static void dasd_device_timeout(struct timer_list *);
81static void dasd_block_timeout(struct timer_list *);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +010082static void __dasd_process_erp(struct dasd_device *, struct dasd_ccw_req *);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +020083static void dasd_profile_init(struct dasd_profile *, struct dentry *);
84static void dasd_profile_exit(struct dasd_profile *);
Stefan Haberland5a3b7b12016-03-18 09:42:13 +010085static void dasd_hosts_init(struct dentry *, struct dasd_device *);
86static void dasd_hosts_exit(struct dasd_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88/*
89 * SECTION: Operations on the device structure.
90 */
91static wait_queue_head_t dasd_init_waitq;
Horst Hummel8f617012006-08-30 14:33:33 +020092static wait_queue_head_t dasd_flush_wq;
Stefan Haberlandc80ee722008-05-30 10:03:31 +020093static wait_queue_head_t generic_waitq;
Stefan Haberland4679e892012-06-19 17:30:12 +020094static wait_queue_head_t shutdown_waitq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96/*
97 * Allocate memory for a new device structure.
98 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010099struct dasd_device *dasd_alloc_device(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
101 struct dasd_device *device;
102
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100103 device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
104 if (!device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 /* Get two pages for normal block device operations. */
108 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100109 if (!device->ccw_mem) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 kfree(device);
111 return ERR_PTR(-ENOMEM);
112 }
113 /* Get one page for error recovery. */
114 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100115 if (!device->erp_mem) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 free_pages((unsigned long) device->ccw_mem, 1);
117 kfree(device);
118 return ERR_PTR(-ENOMEM);
119 }
Jan Höppner5e2b17e2018-04-27 16:51:22 +0200120 /* Get two pages for ese format. */
121 device->ese_mem = (void *)__get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
122 if (!device->ese_mem) {
123 free_page((unsigned long) device->erp_mem);
124 free_pages((unsigned long) device->ccw_mem, 1);
125 kfree(device);
126 return ERR_PTR(-ENOMEM);
127 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
130 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
Jan Höppner5e2b17e2018-04-27 16:51:22 +0200131 dasd_init_chunklist(&device->ese_chunks, device->ese_mem, PAGE_SIZE * 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 spin_lock_init(&device->mem_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100133 atomic_set(&device->tasklet_scheduled, 0);
Sebastian Ottd2f2df62018-07-03 13:06:45 +0200134 tasklet_init(&device->tasklet, dasd_device_tasklet,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 (unsigned long) device);
136 INIT_LIST_HEAD(&device->ccw_queue);
Kees Cooke99e88a2017-10-16 14:43:17 -0700137 timer_setup(&device->timer, dasd_device_timeout, 0);
Al Viro4927b3f2006-12-06 19:18:20 +0000138 INIT_WORK(&device->kick_work, do_kick_device);
Stefan Haberland501183f2010-05-17 10:00:10 +0200139 INIT_WORK(&device->reload_device, do_reload_device);
Stefan Haberlanda521b042016-08-08 15:56:54 +0200140 INIT_WORK(&device->requeue_requests, do_requeue_requests);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 device->state = DASD_STATE_NEW;
142 device->target = DASD_STATE_NEW;
Stefan Haberland9eb25122010-02-26 22:37:46 +0100143 mutex_init(&device->state_mutex);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200144 spin_lock_init(&device->profile.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 return device;
146}
147
148/*
149 * Free memory of a device structure.
150 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100151void dasd_free_device(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Jesper Juhl17fd6822005-11-07 01:01:30 -0800153 kfree(device->private);
Jan Höppner5e2b17e2018-04-27 16:51:22 +0200154 free_pages((unsigned long) device->ese_mem, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 free_page((unsigned long) device->erp_mem);
156 free_pages((unsigned long) device->ccw_mem, 1);
157 kfree(device);
158}
159
160/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100161 * Allocate memory for a new device structure.
162 */
163struct dasd_block *dasd_alloc_block(void)
164{
165 struct dasd_block *block;
166
167 block = kzalloc(sizeof(*block), GFP_ATOMIC);
168 if (!block)
169 return ERR_PTR(-ENOMEM);
170 /* open_count = 0 means device online but not in use */
171 atomic_set(&block->open_count, -1);
172
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100173 atomic_set(&block->tasklet_scheduled, 0);
Sebastian Ottd2f2df62018-07-03 13:06:45 +0200174 tasklet_init(&block->tasklet, dasd_block_tasklet,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100175 (unsigned long) block);
176 INIT_LIST_HEAD(&block->ccw_queue);
177 spin_lock_init(&block->queue_lock);
Stefan Haberland5e6bdd32020-03-12 14:17:15 +0100178 INIT_LIST_HEAD(&block->format_list);
179 spin_lock_init(&block->format_lock);
Kees Cooke99e88a2017-10-16 14:43:17 -0700180 timer_setup(&block->timer, dasd_block_timeout, 0);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200181 spin_lock_init(&block->profile.lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100182
183 return block;
184}
Fabian Frederick7048a2b2014-06-26 19:41:47 +0200185EXPORT_SYMBOL_GPL(dasd_alloc_block);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100186
187/*
188 * Free memory of a device structure.
189 */
190void dasd_free_block(struct dasd_block *block)
191{
192 kfree(block);
193}
Fabian Frederick7048a2b2014-06-26 19:41:47 +0200194EXPORT_SYMBOL_GPL(dasd_free_block);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100195
196/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 * Make a new device known to the system.
198 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100199static int dasd_state_new_to_known(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
201 int rc;
202
203 /*
Horst Hummel138c0142006-06-29 14:58:12 +0200204 * As long as the device is not in state DASD_STATE_NEW we want to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 * keep the reference count > 0.
206 */
207 dasd_get_device(device);
208
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100209 if (device->block) {
210 rc = dasd_alloc_queue(device->block);
211 if (rc) {
212 dasd_put_device(device);
213 return rc;
214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 device->state = DASD_STATE_KNOWN;
217 return 0;
218}
219
220/*
221 * Let the system forget about a device.
222 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100223static int dasd_state_known_to_new(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
Stefan Weinhuber20c64462006-03-24 03:15:25 -0800225 /* Disable extended error reporting for this device. */
226 dasd_eer_disable(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 device->state = DASD_STATE_NEW;
228
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100229 if (device->block)
230 dasd_free_queue(device->block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 /* Give up reference we took in dasd_state_new_to_known. */
233 dasd_put_device(device);
Horst Hummel8f617012006-08-30 14:33:33 +0200234 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235}
236
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200237static struct dentry *dasd_debugfs_setup(const char *name,
238 struct dentry *base_dentry)
239{
240 struct dentry *pde;
241
242 if (!base_dentry)
243 return NULL;
244 pde = debugfs_create_dir(name, base_dentry);
245 if (!pde || IS_ERR(pde))
246 return NULL;
247 return pde;
248}
249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250/*
251 * Request the irq line for the device.
252 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100253static int dasd_state_known_to_basic(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200255 struct dasd_block *block = device->block;
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200256 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258 /* Allocate and register gendisk structure. */
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200259 if (block) {
260 rc = dasd_gendisk_alloc(block);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100261 if (rc)
262 return rc;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200263 block->debugfs_dentry =
264 dasd_debugfs_setup(block->gdp->disk_name,
265 dasd_debugfs_root_entry);
266 dasd_profile_init(&block->profile, block->debugfs_dentry);
267 if (dasd_global_profile_level == DASD_PROFILE_ON)
268 dasd_profile_on(&device->block->profile);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100269 }
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200270 device->debugfs_dentry =
271 dasd_debugfs_setup(dev_name(&device->cdev->dev),
272 dasd_debugfs_root_entry);
273 dasd_profile_init(&device->profile, device->debugfs_dentry);
Stefan Haberland5a3b7b12016-03-18 09:42:13 +0100274 dasd_hosts_init(device->debugfs_dentry, device);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100277 device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100278 8 * sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 debug_register_view(device->debug_area, &debug_sprintf_view);
Horst Hummelb0035f12006-09-20 15:59:07 +0200280 debug_set_level(device->debug_area, DBF_WARNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
282
283 device->state = DASD_STATE_BASIC;
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200284
285 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286}
287
288/*
289 * Release the irq line for the device. Terminate any running i/o.
290 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100291static int dasd_state_basic_to_known(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
Horst Hummel8f617012006-08-30 14:33:33 +0200293 int rc;
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200294
Stefan Haberlanddaa991b2014-07-18 14:19:25 +0200295 if (device->discipline->basic_to_known) {
296 rc = device->discipline->basic_to_known(device);
297 if (rc)
298 return rc;
299 }
300
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100301 if (device->block) {
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200302 dasd_profile_exit(&device->block->profile);
Fabian Frederickd7309aa2014-06-26 19:41:46 +0200303 debugfs_remove(device->block->debugfs_dentry);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100304 dasd_gendisk_free(device->block);
305 dasd_block_clear_timer(device->block);
306 }
307 rc = dasd_flush_device_queue(device);
Horst Hummel8f617012006-08-30 14:33:33 +0200308 if (rc)
309 return rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100310 dasd_device_clear_timer(device);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200311 dasd_profile_exit(&device->profile);
Stefan Haberland5a3b7b12016-03-18 09:42:13 +0100312 dasd_hosts_exit(device);
Fabian Frederickd7309aa2014-06-26 19:41:46 +0200313 debugfs_remove(device->debugfs_dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
315 if (device->debug_area != NULL) {
316 debug_unregister(device->debug_area);
317 device->debug_area = NULL;
318 }
319 device->state = DASD_STATE_KNOWN;
Horst Hummel8f617012006-08-30 14:33:33 +0200320 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321}
322
323/*
324 * Do the initial analysis. The do_analysis function may return
325 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
326 * until the discipline decides to continue the startup sequence
327 * by calling the function dasd_change_state. The eckd disciplines
328 * uses this to start a ccw that detects the format. The completion
329 * interrupt for this detection ccw uses the kernel event daemon to
330 * trigger the call to dasd_change_state. All this is done in the
331 * discipline code, see dasd_eckd.c.
Horst Hummel90f00942006-03-07 21:55:39 -0800332 * After the analysis ccw is done (do_analysis returned 0) the block
333 * device is setup.
334 * In case the analysis returns an error, the device setup is stopped
335 * (a fake disk was already added to allow formatting).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100337static int dasd_state_basic_to_ready(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
339 int rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100340 struct dasd_block *block;
Stefan Haberlandeed5c4b2016-08-31 13:31:10 +0200341 struct gendisk *disk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 rc = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100344 block = device->block;
Horst Hummel90f00942006-03-07 21:55:39 -0800345 /* make disk known with correct capacity */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100346 if (block) {
347 if (block->base->discipline->do_analysis != NULL)
348 rc = block->base->discipline->do_analysis(block);
349 if (rc) {
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200350 if (rc != -EAGAIN) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100351 device->state = DASD_STATE_UNFMT;
Stefan Haberlandeed5c4b2016-08-31 13:31:10 +0200352 disk = device->block->gdp;
353 kobject_uevent(&disk_to_dev(disk)->kobj,
354 KOBJ_CHANGE);
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200355 goto out;
356 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100357 return rc;
358 }
Jan Höppnera0610a82018-04-27 16:55:27 +0200359 if (device->discipline->setup_blk_queue)
360 device->discipline->setup_blk_queue(block);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100361 set_capacity(block->gdp,
362 block->blocks << block->s2b_shift);
363 device->state = DASD_STATE_READY;
364 rc = dasd_scan_partitions(block);
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200365 if (rc) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100366 device->state = DASD_STATE_BASIC;
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200367 return rc;
368 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100369 } else {
370 device->state = DASD_STATE_READY;
371 }
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200372out:
373 if (device->discipline->basic_to_ready)
374 rc = device->discipline->basic_to_ready(device);
Horst Hummel90f00942006-03-07 21:55:39 -0800375 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +0100378static inline
379int _wait_for_empty_queues(struct dasd_device *device)
380{
381 if (device->block)
382 return list_empty(&device->ccw_queue) &&
383 list_empty(&device->block->ccw_queue);
384 else
385 return list_empty(&device->ccw_queue);
386}
387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388/*
389 * Remove device from block device layer. Destroy dirty buffers.
390 * Forget format information. Check if the target level is basic
391 * and if it is create fake disk for formatting.
392 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100393static int dasd_state_ready_to_basic(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
Horst Hummel8f617012006-08-30 14:33:33 +0200395 int rc;
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 device->state = DASD_STATE_BASIC;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100398 if (device->block) {
399 struct dasd_block *block = device->block;
400 rc = dasd_flush_block_queue(block);
401 if (rc) {
402 device->state = DASD_STATE_READY;
403 return rc;
404 }
Stefan Haberlandb695adf2010-02-26 22:37:48 +0100405 dasd_destroy_partitions(block);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100406 block->blocks = 0;
407 block->bp_block = 0;
408 block->s2b_shift = 0;
409 }
Horst Hummel8f617012006-08-30 14:33:33 +0200410 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
412
413/*
Horst Hummel90f00942006-03-07 21:55:39 -0800414 * Back to basic.
415 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100416static int dasd_state_unfmt_to_basic(struct dasd_device *device)
Horst Hummel90f00942006-03-07 21:55:39 -0800417{
418 device->state = DASD_STATE_BASIC;
Horst Hummel8f617012006-08-30 14:33:33 +0200419 return 0;
Horst Hummel90f00942006-03-07 21:55:39 -0800420}
421
422/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 * Make the device online and schedule the bottom half to start
424 * the requeueing of requests from the linux request queue to the
425 * ccw queue.
426 */
Horst Hummel8f617012006-08-30 14:33:33 +0200427static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428dasd_state_ready_to_online(struct dasd_device * device)
429{
430 device->state = DASD_STATE_ONLINE;
Stefan Weinhuber13018092009-01-09 12:14:50 +0100431 if (device->block) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100432 dasd_schedule_block_bh(device->block);
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100433 if ((device->features & DASD_FEATURE_USERAW)) {
Christoph Hellwigbc359d02021-01-24 11:02:39 +0100434 kobject_uevent(&disk_to_dev(device->block->gdp)->kobj,
435 KOBJ_CHANGE);
Stefan Haberlande4dbb0f2011-01-05 12:48:06 +0100436 return 0;
437 }
Christoph Hellwigbc359d02021-01-24 11:02:39 +0100438 disk_uevent(device->block->bdev->bd_disk, KOBJ_CHANGE);
Stefan Weinhuber13018092009-01-09 12:14:50 +0100439 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 return 0;
441}
442
443/*
444 * Stop the requeueing of requests again.
445 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100446static int dasd_state_online_to_ready(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100448 int rc;
449
450 if (device->discipline->online_to_ready) {
451 rc = device->discipline->online_to_ready(device);
452 if (rc)
453 return rc;
454 }
Stefan Haberlandd42e1712013-04-15 16:22:23 +0200455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 device->state = DASD_STATE_READY;
Christoph Hellwigbc359d02021-01-24 11:02:39 +0100457 if (device->block && !(device->features & DASD_FEATURE_USERAW))
458 disk_uevent(device->block->bdev->bd_disk, KOBJ_CHANGE);
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/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 * Set the target state for a device and starts the state change.
606 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100607void dasd_set_target_state(struct dasd_device *device, int target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608{
Cornelia Huckf3445a12009-04-14 15:36:23 +0200609 dasd_get_device(device);
Stefan Haberland9eb25122010-02-26 22:37:46 +0100610 mutex_lock(&device->state_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 /* If we are in probeonly mode stop at DASD_STATE_READY. */
612 if (dasd_probeonly && target > DASD_STATE_READY)
613 target = DASD_STATE_READY;
614 if (device->target != target) {
Stefan Haberland9eb25122010-02-26 22:37:46 +0100615 if (device->state == target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 wake_up(&dasd_init_waitq);
617 device->target = target;
618 }
619 if (device->state != device->target)
620 dasd_change_state(device);
Stefan Haberland9eb25122010-02-26 22:37:46 +0100621 mutex_unlock(&device->state_mutex);
622 dasd_put_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623}
624
625/*
626 * Enable devices with device numbers in [from..to].
627 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100628static inline int _wait_for_device(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629{
630 return (device->state == device->target);
631}
632
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100633void dasd_enable_device(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634{
635 dasd_set_target_state(device, DASD_STATE_ONLINE);
636 if (device->state <= DASD_STATE_KNOWN)
637 /* No discipline for device found. */
638 dasd_set_target_state(device, DASD_STATE_NEW);
639 /* Now wait for the devices to come up. */
640 wait_event(dasd_init_waitq, _wait_for_device(device));
Stefan Haberland25e2cf12012-03-11 11:59:37 -0400641
642 dasd_reload_device(device);
643 if (device->discipline->kick_validate)
644 device->discipline->kick_validate(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645}
Fabian Frederick7048a2b2014-06-26 19:41:47 +0200646EXPORT_SYMBOL(dasd_enable_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
648/*
649 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
650 */
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200651
652unsigned int dasd_global_profile_level = DASD_PROFILE_OFF;
653
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654#ifdef CONFIG_DASD_PROFILE
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100655struct dasd_profile dasd_global_profile = {
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100656 .lock = __SPIN_LOCK_UNLOCKED(dasd_global_profile.lock),
657};
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200658static struct dentry *dasd_debugfs_global_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
660/*
661 * Add profiling information for cqr before execution.
662 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100663static void dasd_profile_start(struct dasd_block *block,
664 struct dasd_ccw_req *cqr,
665 struct request *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666{
667 struct list_head *l;
668 unsigned int counter;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200669 struct dasd_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
671 /* count the length of the chanq for statistics */
672 counter = 0;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200673 if (dasd_global_profile_level || block->profile.data)
674 list_for_each(l, &block->ccw_queue)
675 if (++counter >= 31)
676 break;
677
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100678 spin_lock(&dasd_global_profile.lock);
Sebastian Ott6765cc22015-01-28 19:06:29 +0100679 if (dasd_global_profile.data) {
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100680 dasd_global_profile.data->dasd_io_nr_req[counter]++;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200681 if (rq_data_dir(req) == READ)
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100682 dasd_global_profile.data->dasd_read_nr_req[counter]++;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200683 }
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100684 spin_unlock(&dasd_global_profile.lock);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200685
686 spin_lock(&block->profile.lock);
Stefan Weinhuberc81a90c2013-10-25 11:08:06 +0200687 if (block->profile.data) {
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200688 block->profile.data->dasd_io_nr_req[counter]++;
689 if (rq_data_dir(req) == READ)
690 block->profile.data->dasd_read_nr_req[counter]++;
Stefan Weinhuberc81a90c2013-10-25 11:08:06 +0200691 }
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200692 spin_unlock(&block->profile.lock);
693
694 /*
695 * We count the request for the start device, even though it may run on
696 * some other device due to error recovery. This way we make sure that
697 * we count each request only once.
698 */
699 device = cqr->startdev;
700 if (device->profile.data) {
701 counter = 1; /* request is not yet queued on the start device */
702 list_for_each(l, &device->ccw_queue)
703 if (++counter >= 31)
704 break;
705 }
706 spin_lock(&device->profile.lock);
707 if (device->profile.data) {
708 device->profile.data->dasd_io_nr_req[counter]++;
709 if (rq_data_dir(req) == READ)
710 device->profile.data->dasd_read_nr_req[counter]++;
711 }
712 spin_unlock(&device->profile.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713}
714
715/*
716 * Add profiling information for cqr after execution.
717 */
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200718
719#define dasd_profile_counter(value, index) \
720{ \
721 for (index = 0; index < 31 && value >> (2+index); index++) \
722 ; \
723}
724
725static void dasd_profile_end_add_data(struct dasd_profile_info *data,
726 int is_alias,
727 int is_tpm,
728 int is_read,
729 long sectors,
730 int sectors_ind,
731 int tottime_ind,
732 int tottimeps_ind,
733 int strtime_ind,
734 int irqtime_ind,
735 int irqtimeps_ind,
736 int endtime_ind)
737{
738 /* in case of an overflow, reset the whole profile */
739 if (data->dasd_io_reqs == UINT_MAX) {
740 memset(data, 0, sizeof(*data));
Arnd Bergmannbd7a9b32017-11-27 12:46:57 +0100741 ktime_get_real_ts64(&data->starttod);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200742 }
743 data->dasd_io_reqs++;
744 data->dasd_io_sects += sectors;
745 if (is_alias)
746 data->dasd_io_alias++;
747 if (is_tpm)
748 data->dasd_io_tpm++;
749
750 data->dasd_io_secs[sectors_ind]++;
751 data->dasd_io_times[tottime_ind]++;
752 data->dasd_io_timps[tottimeps_ind]++;
753 data->dasd_io_time1[strtime_ind]++;
754 data->dasd_io_time2[irqtime_ind]++;
755 data->dasd_io_time2ps[irqtimeps_ind]++;
756 data->dasd_io_time3[endtime_ind]++;
757
758 if (is_read) {
759 data->dasd_read_reqs++;
760 data->dasd_read_sects += sectors;
761 if (is_alias)
762 data->dasd_read_alias++;
763 if (is_tpm)
764 data->dasd_read_tpm++;
765 data->dasd_read_secs[sectors_ind]++;
766 data->dasd_read_times[tottime_ind]++;
767 data->dasd_read_time1[strtime_ind]++;
768 data->dasd_read_time2[irqtime_ind]++;
769 data->dasd_read_time3[endtime_ind]++;
770 }
771}
772
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100773static void dasd_profile_end(struct dasd_block *block,
774 struct dasd_ccw_req *cqr,
775 struct request *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776{
Stefan Haberlandd2907222017-07-14 10:33:18 +0200777 unsigned long strtime, irqtime, endtime, tottime;
778 unsigned long tottimeps, sectors;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200779 struct dasd_device *device;
780 int sectors_ind, tottime_ind, tottimeps_ind, strtime_ind;
781 int irqtime_ind, irqtimeps_ind, endtime_ind;
Stefan Haberlandd2907222017-07-14 10:33:18 +0200782 struct dasd_profile_info *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200784 device = cqr->startdev;
785 if (!(dasd_global_profile_level ||
786 block->profile.data ||
787 device->profile.data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 return;
789
Tejun Heo83096eb2009-05-07 22:24:39 +0900790 sectors = blk_rq_sectors(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 if (!cqr->buildclk || !cqr->startclk ||
792 !cqr->stopclk || !cqr->endclk ||
793 !sectors)
794 return;
795
796 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
797 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
798 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
799 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
800 tottimeps = tottime / sectors;
801
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200802 dasd_profile_counter(sectors, sectors_ind);
803 dasd_profile_counter(tottime, tottime_ind);
804 dasd_profile_counter(tottimeps, tottimeps_ind);
805 dasd_profile_counter(strtime, strtime_ind);
806 dasd_profile_counter(irqtime, irqtime_ind);
807 dasd_profile_counter(irqtime / sectors, irqtimeps_ind);
808 dasd_profile_counter(endtime, endtime_ind);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100810 spin_lock(&dasd_global_profile.lock);
Sebastian Ott6765cc22015-01-28 19:06:29 +0100811 if (dasd_global_profile.data) {
Stefan Haberlandd2907222017-07-14 10:33:18 +0200812 data = dasd_global_profile.data;
813 data->dasd_sum_times += tottime;
814 data->dasd_sum_time_str += strtime;
815 data->dasd_sum_time_irq += irqtime;
816 data->dasd_sum_time_end += endtime;
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100817 dasd_profile_end_add_data(dasd_global_profile.data,
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200818 cqr->startdev != block->base,
819 cqr->cpmode == 1,
820 rq_data_dir(req) == READ,
821 sectors, sectors_ind, tottime_ind,
822 tottimeps_ind, strtime_ind,
823 irqtime_ind, irqtimeps_ind,
824 endtime_ind);
825 }
Sebastian Ott8ea55c92015-01-28 18:44:17 +0100826 spin_unlock(&dasd_global_profile.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200828 spin_lock(&block->profile.lock);
Stefan Haberlandd2907222017-07-14 10:33:18 +0200829 if (block->profile.data) {
830 data = block->profile.data;
831 data->dasd_sum_times += tottime;
832 data->dasd_sum_time_str += strtime;
833 data->dasd_sum_time_irq += irqtime;
834 data->dasd_sum_time_end += endtime;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200835 dasd_profile_end_add_data(block->profile.data,
836 cqr->startdev != block->base,
837 cqr->cpmode == 1,
838 rq_data_dir(req) == READ,
839 sectors, sectors_ind, tottime_ind,
840 tottimeps_ind, strtime_ind,
841 irqtime_ind, irqtimeps_ind,
842 endtime_ind);
Stefan Haberlandd2907222017-07-14 10:33:18 +0200843 }
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200844 spin_unlock(&block->profile.lock);
845
846 spin_lock(&device->profile.lock);
Stefan Haberlandd2907222017-07-14 10:33:18 +0200847 if (device->profile.data) {
848 data = device->profile.data;
849 data->dasd_sum_times += tottime;
850 data->dasd_sum_time_str += strtime;
851 data->dasd_sum_time_irq += irqtime;
852 data->dasd_sum_time_end += endtime;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200853 dasd_profile_end_add_data(device->profile.data,
854 cqr->startdev != block->base,
855 cqr->cpmode == 1,
856 rq_data_dir(req) == READ,
857 sectors, sectors_ind, tottime_ind,
858 tottimeps_ind, strtime_ind,
859 irqtime_ind, irqtimeps_ind,
860 endtime_ind);
Stefan Haberlandd2907222017-07-14 10:33:18 +0200861 }
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200862 spin_unlock(&device->profile.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863}
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200864
865void dasd_profile_reset(struct dasd_profile *profile)
866{
867 struct dasd_profile_info *data;
868
869 spin_lock_bh(&profile->lock);
870 data = profile->data;
871 if (!data) {
872 spin_unlock_bh(&profile->lock);
873 return;
874 }
875 memset(data, 0, sizeof(*data));
Arnd Bergmannbd7a9b32017-11-27 12:46:57 +0100876 ktime_get_real_ts64(&data->starttod);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200877 spin_unlock_bh(&profile->lock);
878}
879
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200880int dasd_profile_on(struct dasd_profile *profile)
881{
882 struct dasd_profile_info *data;
883
884 data = kzalloc(sizeof(*data), GFP_KERNEL);
885 if (!data)
886 return -ENOMEM;
887 spin_lock_bh(&profile->lock);
888 if (profile->data) {
889 spin_unlock_bh(&profile->lock);
890 kfree(data);
891 return 0;
892 }
Arnd Bergmannbd7a9b32017-11-27 12:46:57 +0100893 ktime_get_real_ts64(&data->starttod);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200894 profile->data = data;
895 spin_unlock_bh(&profile->lock);
896 return 0;
897}
898
899void dasd_profile_off(struct dasd_profile *profile)
900{
901 spin_lock_bh(&profile->lock);
902 kfree(profile->data);
903 profile->data = NULL;
904 spin_unlock_bh(&profile->lock);
905}
906
907char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
908{
909 char *buffer;
910
Stefan Weinhubere4258d52011-08-03 16:44:20 +0200911 buffer = vmalloc(user_len + 1);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200912 if (buffer == NULL)
913 return ERR_PTR(-ENOMEM);
914 if (copy_from_user(buffer, user_buf, user_len) != 0) {
Stefan Weinhubere4258d52011-08-03 16:44:20 +0200915 vfree(buffer);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200916 return ERR_PTR(-EFAULT);
917 }
918 /* got the string, now strip linefeed. */
919 if (buffer[user_len - 1] == '\n')
920 buffer[user_len - 1] = 0;
921 else
922 buffer[user_len] = 0;
923 return buffer;
924}
925
926static ssize_t dasd_stats_write(struct file *file,
927 const char __user *user_buf,
928 size_t user_len, loff_t *pos)
929{
930 char *buffer, *str;
931 int rc;
932 struct seq_file *m = (struct seq_file *)file->private_data;
933 struct dasd_profile *prof = m->private;
934
935 if (user_len > 65536)
936 user_len = 65536;
937 buffer = dasd_get_user_string(user_buf, user_len);
938 if (IS_ERR(buffer))
939 return PTR_ERR(buffer);
940
941 str = skip_spaces(buffer);
942 rc = user_len;
943 if (strncmp(str, "reset", 5) == 0) {
944 dasd_profile_reset(prof);
945 } else if (strncmp(str, "on", 2) == 0) {
946 rc = dasd_profile_on(prof);
Sebastian Ott6765cc22015-01-28 19:06:29 +0100947 if (rc)
948 goto out;
949 rc = user_len;
950 if (prof == &dasd_global_profile) {
951 dasd_profile_reset(prof);
952 dasd_global_profile_level = DASD_PROFILE_GLOBAL_ONLY;
953 }
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200954 } else if (strncmp(str, "off", 3) == 0) {
Sebastian Ott6765cc22015-01-28 19:06:29 +0100955 if (prof == &dasd_global_profile)
956 dasd_global_profile_level = DASD_PROFILE_OFF;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200957 dasd_profile_off(prof);
958 } else
959 rc = -EINVAL;
Sebastian Ott6765cc22015-01-28 19:06:29 +0100960out:
Stefan Weinhubere4258d52011-08-03 16:44:20 +0200961 vfree(buffer);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200962 return rc;
963}
964
965static void dasd_stats_array(struct seq_file *m, unsigned int *array)
966{
967 int i;
968
969 for (i = 0; i < 32; i++)
970 seq_printf(m, "%u ", array[i]);
971 seq_putc(m, '\n');
972}
973
974static void dasd_stats_seq_print(struct seq_file *m,
975 struct dasd_profile_info *data)
976{
Arnd Bergmannbd7a9b32017-11-27 12:46:57 +0100977 seq_printf(m, "start_time %lld.%09ld\n",
978 (s64)data->starttod.tv_sec, data->starttod.tv_nsec);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200979 seq_printf(m, "total_requests %u\n", data->dasd_io_reqs);
980 seq_printf(m, "total_sectors %u\n", data->dasd_io_sects);
981 seq_printf(m, "total_pav %u\n", data->dasd_io_alias);
982 seq_printf(m, "total_hpf %u\n", data->dasd_io_tpm);
Stefan Haberlandd2907222017-07-14 10:33:18 +0200983 seq_printf(m, "avg_total %lu\n", data->dasd_io_reqs ?
984 data->dasd_sum_times / data->dasd_io_reqs : 0UL);
985 seq_printf(m, "avg_build_to_ssch %lu\n", data->dasd_io_reqs ?
986 data->dasd_sum_time_str / data->dasd_io_reqs : 0UL);
987 seq_printf(m, "avg_ssch_to_irq %lu\n", data->dasd_io_reqs ?
988 data->dasd_sum_time_irq / data->dasd_io_reqs : 0UL);
989 seq_printf(m, "avg_irq_to_end %lu\n", data->dasd_io_reqs ?
990 data->dasd_sum_time_end / data->dasd_io_reqs : 0UL);
Fabian Frederickc794caf2014-06-26 19:41:49 +0200991 seq_puts(m, "histogram_sectors ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200992 dasd_stats_array(m, data->dasd_io_secs);
Fabian Frederickc794caf2014-06-26 19:41:49 +0200993 seq_puts(m, "histogram_io_times ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200994 dasd_stats_array(m, data->dasd_io_times);
Fabian Frederickc794caf2014-06-26 19:41:49 +0200995 seq_puts(m, "histogram_io_times_weighted ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200996 dasd_stats_array(m, data->dasd_io_timps);
Fabian Frederickc794caf2014-06-26 19:41:49 +0200997 seq_puts(m, "histogram_time_build_to_ssch ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200998 dasd_stats_array(m, data->dasd_io_time1);
Fabian Frederickc794caf2014-06-26 19:41:49 +0200999 seq_puts(m, "histogram_time_ssch_to_irq ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001000 dasd_stats_array(m, data->dasd_io_time2);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001001 seq_puts(m, "histogram_time_ssch_to_irq_weighted ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001002 dasd_stats_array(m, data->dasd_io_time2ps);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001003 seq_puts(m, "histogram_time_irq_to_end ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001004 dasd_stats_array(m, data->dasd_io_time3);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001005 seq_puts(m, "histogram_ccw_queue_length ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001006 dasd_stats_array(m, data->dasd_io_nr_req);
1007 seq_printf(m, "total_read_requests %u\n", data->dasd_read_reqs);
1008 seq_printf(m, "total_read_sectors %u\n", data->dasd_read_sects);
1009 seq_printf(m, "total_read_pav %u\n", data->dasd_read_alias);
1010 seq_printf(m, "total_read_hpf %u\n", data->dasd_read_tpm);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001011 seq_puts(m, "histogram_read_sectors ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001012 dasd_stats_array(m, data->dasd_read_secs);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001013 seq_puts(m, "histogram_read_times ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001014 dasd_stats_array(m, data->dasd_read_times);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001015 seq_puts(m, "histogram_read_time_build_to_ssch ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001016 dasd_stats_array(m, data->dasd_read_time1);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001017 seq_puts(m, "histogram_read_time_ssch_to_irq ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001018 dasd_stats_array(m, data->dasd_read_time2);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001019 seq_puts(m, "histogram_read_time_irq_to_end ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001020 dasd_stats_array(m, data->dasd_read_time3);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001021 seq_puts(m, "histogram_read_ccw_queue_length ");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001022 dasd_stats_array(m, data->dasd_read_nr_req);
1023}
1024
1025static int dasd_stats_show(struct seq_file *m, void *v)
1026{
1027 struct dasd_profile *profile;
1028 struct dasd_profile_info *data;
1029
1030 profile = m->private;
1031 spin_lock_bh(&profile->lock);
1032 data = profile->data;
1033 if (!data) {
1034 spin_unlock_bh(&profile->lock);
Fabian Frederickc794caf2014-06-26 19:41:49 +02001035 seq_puts(m, "disabled\n");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001036 return 0;
1037 }
1038 dasd_stats_seq_print(m, data);
1039 spin_unlock_bh(&profile->lock);
1040 return 0;
1041}
1042
1043static int dasd_stats_open(struct inode *inode, struct file *file)
1044{
1045 struct dasd_profile *profile = inode->i_private;
1046 return single_open(file, dasd_stats_show, profile);
1047}
1048
1049static const struct file_operations dasd_stats_raw_fops = {
1050 .owner = THIS_MODULE,
1051 .open = dasd_stats_open,
1052 .read = seq_read,
1053 .llseek = seq_lseek,
1054 .release = single_release,
1055 .write = dasd_stats_write,
1056};
1057
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001058static void dasd_profile_init(struct dasd_profile *profile,
1059 struct dentry *base_dentry)
1060{
Al Virof4ae40a62011-07-24 04:33:43 -04001061 umode_t mode;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001062 struct dentry *pde;
1063
1064 if (!base_dentry)
1065 return;
1066 profile->dentry = NULL;
1067 profile->data = NULL;
1068 mode = (S_IRUSR | S_IWUSR | S_IFREG);
1069 pde = debugfs_create_file("statistics", mode, base_dentry,
1070 profile, &dasd_stats_raw_fops);
1071 if (pde && !IS_ERR(pde))
1072 profile->dentry = pde;
1073 return;
1074}
1075
1076static void dasd_profile_exit(struct dasd_profile *profile)
1077{
1078 dasd_profile_off(profile);
Fabian Frederickd7309aa2014-06-26 19:41:46 +02001079 debugfs_remove(profile->dentry);
1080 profile->dentry = NULL;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001081}
1082
1083static void dasd_statistics_removeroot(void)
1084{
1085 dasd_global_profile_level = DASD_PROFILE_OFF;
Sebastian Ott6765cc22015-01-28 19:06:29 +01001086 dasd_profile_exit(&dasd_global_profile);
Fabian Frederickd7309aa2014-06-26 19:41:46 +02001087 debugfs_remove(dasd_debugfs_global_entry);
1088 debugfs_remove(dasd_debugfs_root_entry);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001089}
1090
1091static void dasd_statistics_createroot(void)
1092{
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001093 struct dentry *pde;
1094
1095 dasd_debugfs_root_entry = NULL;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001096 pde = debugfs_create_dir("dasd", NULL);
1097 if (!pde || IS_ERR(pde))
1098 goto error;
1099 dasd_debugfs_root_entry = pde;
1100 pde = debugfs_create_dir("global", dasd_debugfs_root_entry);
1101 if (!pde || IS_ERR(pde))
1102 goto error;
1103 dasd_debugfs_global_entry = pde;
Sebastian Ott6765cc22015-01-28 19:06:29 +01001104 dasd_profile_init(&dasd_global_profile, dasd_debugfs_global_entry);
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001105 return;
1106
1107error:
1108 DBF_EVENT(DBF_ERR, "%s",
1109 "Creation of the dasd debugfs interface failed");
1110 dasd_statistics_removeroot();
1111 return;
1112}
1113
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114#else
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001115#define dasd_profile_start(block, cqr, req) do {} while (0)
1116#define dasd_profile_end(block, cqr, req) do {} while (0)
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001117
1118static void dasd_statistics_createroot(void)
1119{
1120 return;
1121}
1122
1123static void dasd_statistics_removeroot(void)
1124{
1125 return;
1126}
1127
1128int dasd_stats_generic_show(struct seq_file *m, void *v)
1129{
Fabian Frederickc794caf2014-06-26 19:41:49 +02001130 seq_puts(m, "Statistics are not activated in this kernel\n");
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02001131 return 0;
1132}
1133
1134static void dasd_profile_init(struct dasd_profile *profile,
1135 struct dentry *base_dentry)
1136{
1137 return;
1138}
1139
1140static void dasd_profile_exit(struct dasd_profile *profile)
1141{
1142 return;
1143}
1144
1145int dasd_profile_on(struct dasd_profile *profile)
1146{
1147 return 0;
1148}
1149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150#endif /* CONFIG_DASD_PROFILE */
1151
Stefan Haberland5a3b7b12016-03-18 09:42:13 +01001152static int dasd_hosts_show(struct seq_file *m, void *v)
1153{
1154 struct dasd_device *device;
1155 int rc = -EOPNOTSUPP;
1156
1157 device = m->private;
1158 dasd_get_device(device);
1159
1160 if (device->discipline->hosts_print)
1161 rc = device->discipline->hosts_print(device, m);
1162
1163 dasd_put_device(device);
1164 return rc;
1165}
1166
Yangtao Lica92b932018-12-01 22:28:11 -05001167DEFINE_SHOW_ATTRIBUTE(dasd_hosts);
Stefan Haberland5a3b7b12016-03-18 09:42:13 +01001168
1169static void dasd_hosts_exit(struct dasd_device *device)
1170{
1171 debugfs_remove(device->hosts_dentry);
1172 device->hosts_dentry = NULL;
1173}
1174
1175static void dasd_hosts_init(struct dentry *base_dentry,
1176 struct dasd_device *device)
1177{
1178 struct dentry *pde;
1179 umode_t mode;
1180
1181 if (!base_dentry)
1182 return;
1183
1184 mode = S_IRUSR | S_IFREG;
1185 pde = debugfs_create_file("host_access_list", mode, base_dentry,
1186 device, &dasd_hosts_fops);
1187 if (pde && !IS_ERR(pde))
1188 device->hosts_dentry = pde;
1189}
1190
Sebastian Ottc5205f22018-06-04 19:07:39 +02001191struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength, int datasize,
1192 struct dasd_device *device,
1193 struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194{
1195 unsigned long flags;
Sebastian Ottc5205f22018-06-04 19:07:39 +02001196 char *data, *chunk;
1197 int size = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 if (cplength > 0)
1200 size += cplength * sizeof(struct ccw1);
1201 if (datasize > 0)
1202 size += datasize;
Sebastian Ottc5205f22018-06-04 19:07:39 +02001203 if (!cqr)
1204 size += (sizeof(*cqr) + 7L) & -8L;
1205
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 spin_lock_irqsave(&device->mem_lock, flags);
Sebastian Ottc5205f22018-06-04 19:07:39 +02001207 data = chunk = dasd_alloc_chunk(&device->ccw_chunks, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 spin_unlock_irqrestore(&device->mem_lock, flags);
Sebastian Ottc5205f22018-06-04 19:07:39 +02001209 if (!chunk)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 return ERR_PTR(-ENOMEM);
Sebastian Ottc5205f22018-06-04 19:07:39 +02001211 if (!cqr) {
1212 cqr = (void *) data;
1213 data += (sizeof(*cqr) + 7L) & -8L;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 }
Sebastian Ottc5205f22018-06-04 19:07:39 +02001215 memset(cqr, 0, sizeof(*cqr));
1216 cqr->mem_chunk = chunk;
1217 if (cplength > 0) {
1218 cqr->cpaddr = data;
1219 data += cplength * sizeof(struct ccw1);
1220 memset(cqr->cpaddr, 0, cplength * sizeof(struct ccw1));
1221 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 if (datasize > 0) {
1223 cqr->data = data;
1224 memset(cqr->data, 0, datasize);
1225 }
Stefan Haberland68b781f2009-09-11 10:28:29 +02001226 cqr->magic = magic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1228 dasd_get_device(device);
1229 return cqr;
1230}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001231EXPORT_SYMBOL(dasd_smalloc_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Jan Höppner5e2b17e2018-04-27 16:51:22 +02001233struct dasd_ccw_req *dasd_fmalloc_request(int magic, int cplength,
1234 int datasize,
1235 struct dasd_device *device)
1236{
1237 struct dasd_ccw_req *cqr;
1238 unsigned long flags;
1239 int size, cqr_size;
1240 char *data;
1241
1242 cqr_size = (sizeof(*cqr) + 7L) & -8L;
1243 size = cqr_size;
1244 if (cplength > 0)
1245 size += cplength * sizeof(struct ccw1);
1246 if (datasize > 0)
1247 size += datasize;
1248
1249 spin_lock_irqsave(&device->mem_lock, flags);
1250 cqr = dasd_alloc_chunk(&device->ese_chunks, size);
1251 spin_unlock_irqrestore(&device->mem_lock, flags);
1252 if (!cqr)
1253 return ERR_PTR(-ENOMEM);
1254 memset(cqr, 0, sizeof(*cqr));
1255 data = (char *)cqr + cqr_size;
1256 cqr->cpaddr = NULL;
1257 if (cplength > 0) {
1258 cqr->cpaddr = data;
1259 data += cplength * sizeof(struct ccw1);
1260 memset(cqr->cpaddr, 0, cplength * sizeof(struct ccw1));
1261 }
1262 cqr->data = NULL;
1263 if (datasize > 0) {
1264 cqr->data = data;
1265 memset(cqr->data, 0, datasize);
1266 }
1267
1268 cqr->magic = magic;
1269 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1270 dasd_get_device(device);
1271
1272 return cqr;
1273}
1274EXPORT_SYMBOL(dasd_fmalloc_request);
1275
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001276void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277{
1278 unsigned long flags;
1279
1280 spin_lock_irqsave(&device->mem_lock, flags);
Sebastian Ottc5205f22018-06-04 19:07:39 +02001281 dasd_free_chunk(&device->ccw_chunks, cqr->mem_chunk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 spin_unlock_irqrestore(&device->mem_lock, flags);
1283 dasd_put_device(device);
1284}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001285EXPORT_SYMBOL(dasd_sfree_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
Jan Höppner5e2b17e2018-04-27 16:51:22 +02001287void dasd_ffree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1288{
1289 unsigned long flags;
1290
1291 spin_lock_irqsave(&device->mem_lock, flags);
1292 dasd_free_chunk(&device->ese_chunks, cqr);
1293 spin_unlock_irqrestore(&device->mem_lock, flags);
1294 dasd_put_device(device);
1295}
1296EXPORT_SYMBOL(dasd_ffree_request);
1297
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298/*
1299 * Check discipline magic in cqr.
1300 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001301static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302{
1303 struct dasd_device *device;
1304
1305 if (cqr == NULL)
1306 return -EINVAL;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001307 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001309 DBF_DEV_EVENT(DBF_WARNING, device,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 " dasd_ccw_req 0x%08x magic doesn't match"
1311 " discipline 0x%08x",
1312 cqr->magic,
1313 *(unsigned int *) device->discipline->name);
1314 return -EINVAL;
1315 }
1316 return 0;
1317}
1318
1319/*
1320 * Terminate the current i/o and set the request to clear_pending.
1321 * Timer keeps device runnig.
1322 * ccw_device_clear can fail if the i/o subsystem
1323 * is in a bad mood.
1324 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001325int dasd_term_IO(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326{
1327 struct dasd_device *device;
1328 int retries, rc;
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001329 char errorstring[ERRORLENGTH];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
1331 /* Check the cqr */
1332 rc = dasd_check_cqr(cqr);
1333 if (rc)
1334 return rc;
1335 retries = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001336 device = (struct dasd_device *) cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
1338 rc = ccw_device_clear(device->cdev, (long) cqr);
1339 switch (rc) {
1340 case 0: /* termination successful */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001341 cqr->status = DASD_CQR_CLEAR_PENDING;
Heiko Carstens1aae0562013-01-30 09:49:40 +01001342 cqr->stopclk = get_tod_clock();
Horst Hummel8f617012006-08-30 14:33:33 +02001343 cqr->starttime = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 DBF_DEV_EVENT(DBF_DEBUG, device,
1345 "terminate cqr %p successful",
1346 cqr);
1347 break;
1348 case -ENODEV:
1349 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1350 "device gone, retry");
1351 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 case -EINVAL:
Stefan Haberland2c171242014-11-24 10:53:19 +01001353 /*
1354 * device not valid so no I/O could be running
1355 * handle CQR as termination successful
1356 */
1357 cqr->status = DASD_CQR_CLEARED;
1358 cqr->stopclk = get_tod_clock();
1359 cqr->starttime = 0;
1360 /* no retries for invalid devices */
1361 cqr->retries = -1;
1362 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1363 "EINVAL, handle as terminated");
1364 /* fake rc to success */
1365 rc = 0;
1366 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001368 /* internal error 10 - unknown rc*/
1369 snprintf(errorstring, ERRORLENGTH, "10 %d", rc);
1370 dev_err(&device->cdev->dev, "An error occurred in the "
1371 "DASD device driver, reason=%s\n", errorstring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 BUG();
1373 break;
1374 }
1375 retries++;
1376 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001377 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 return rc;
1379}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001380EXPORT_SYMBOL(dasd_term_IO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
1382/*
1383 * Start the i/o. This start_IO can fail if the channel is really busy.
1384 * In that case set up a timer to start the request later.
1385 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001386int dasd_start_IO(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387{
1388 struct dasd_device *device;
1389 int rc;
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001390 char errorstring[ERRORLENGTH];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
1392 /* Check the cqr */
1393 rc = dasd_check_cqr(cqr);
Stefan Weinhuber6cc7f162009-06-12 10:26:39 +02001394 if (rc) {
1395 cqr->intrc = rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 return rc;
Stefan Weinhuber6cc7f162009-06-12 10:26:39 +02001397 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001398 device = (struct dasd_device *) cqr->startdev;
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001399 if (((cqr->block &&
1400 test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) ||
1401 test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
1402 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
1403 DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
1404 "because of stolen lock", cqr);
1405 cqr->status = DASD_CQR_ERROR;
1406 cqr->intrc = -EPERM;
1407 return -EPERM;
1408 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 if (cqr->retries < 0) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001410 /* internal error 14 - start_IO run out of retries */
1411 sprintf(errorstring, "14 %p", cqr);
1412 dev_err(&device->cdev->dev, "An error occurred in the DASD "
1413 "device driver, reason=%s\n", errorstring);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001414 cqr->status = DASD_CQR_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 return -EIO;
1416 }
Heiko Carstens1aae0562013-01-30 09:49:40 +01001417 cqr->startclk = get_tod_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 cqr->starttime = jiffies;
1419 cqr->retries--;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001420 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
Stefan Haberlandc9346152016-08-08 15:53:54 +02001421 cqr->lpm &= dasd_path_get_opm(device);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001422 if (!cqr->lpm)
Stefan Haberlandc9346152016-08-08 15:53:54 +02001423 cqr->lpm = dasd_path_get_opm(device);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001424 }
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001425 if (cqr->cpmode == 1) {
1426 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
1427 (long) cqr, cqr->lpm);
1428 } else {
1429 rc = ccw_device_start(device->cdev, cqr->cpaddr,
1430 (long) cqr, cqr->lpm, 0);
1431 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 switch (rc) {
1433 case 0:
1434 cqr->status = DASD_CQR_IN_IO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 break;
1436 case -EBUSY:
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001437 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 "start_IO: device busy, retry later");
1439 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 case -EACCES:
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001441 /* -EACCES indicates that the request used only a subset of the
1442 * available paths and all these paths are gone. If the lpm of
1443 * this request was only a subset of the opm (e.g. the ppm) then
1444 * we just do a retry with all available paths.
1445 * If we already use the full opm, something is amiss, and we
1446 * need a full path verification.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 */
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001448 if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1449 DBF_DEV_EVENT(DBF_WARNING, device,
1450 "start_IO: selected paths gone (%x)",
1451 cqr->lpm);
Stefan Haberlandc9346152016-08-08 15:53:54 +02001452 } else if (cqr->lpm != dasd_path_get_opm(device)) {
1453 cqr->lpm = dasd_path_get_opm(device);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001454 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
1455 "start_IO: selected paths gone,"
1456 " retry on all paths");
1457 } else {
1458 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1459 "start_IO: all paths in opm gone,"
1460 " do path verification");
1461 dasd_generic_last_path_gone(device);
Stefan Haberlandc9346152016-08-08 15:53:54 +02001462 dasd_path_no_path(device);
1463 dasd_path_set_tbvpm(device,
1464 ccw_device_get_path_mask(
1465 device->cdev));
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 break;
1468 case -ENODEV:
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001469 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001470 "start_IO: -ENODEV device gone, retry");
1471 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 case -EIO:
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001473 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001474 "start_IO: -EIO device gone, retry");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 break;
Stefan Haberlandd41dd122009-06-16 10:30:25 +02001476 case -EINVAL:
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001477 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Stefan Haberlandd41dd122009-06-16 10:30:25 +02001478 "start_IO: -EINVAL device currently "
1479 "not accessible");
1480 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 default:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001482 /* internal error 11 - unknown rc */
1483 snprintf(errorstring, ERRORLENGTH, "11 %d", rc);
1484 dev_err(&device->cdev->dev,
1485 "An error occurred in the DASD device driver, "
1486 "reason=%s\n", errorstring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 BUG();
1488 break;
1489 }
Stefan Weinhuber6cc7f162009-06-12 10:26:39 +02001490 cqr->intrc = rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 return rc;
1492}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001493EXPORT_SYMBOL(dasd_start_IO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
1495/*
1496 * Timeout function for dasd devices. This is used for different purposes
1497 * 1) missing interrupt handler for normal operation
1498 * 2) delayed start of request where start_IO failed with -EBUSY
1499 * 3) timeout for missing state change interrupts
1500 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1501 * DASD_CQR_QUEUED for 2) and 3).
1502 */
Kees Cooke99e88a2017-10-16 14:43:17 -07001503static void dasd_device_timeout(struct timer_list *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504{
1505 unsigned long flags;
1506 struct dasd_device *device;
1507
Kees Cooke99e88a2017-10-16 14:43:17 -07001508 device = from_timer(device, t, timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1510 /* re-activate request queue */
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001511 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001513 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514}
1515
1516/*
1517 * Setup timeout for a device in jiffies.
1518 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001519void dasd_device_set_timer(struct dasd_device *device, int expires)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520{
Stefan Weinhuber48cae882009-02-11 10:37:31 +01001521 if (expires == 0)
1522 del_timer(&device->timer);
1523 else
1524 mod_timer(&device->timer, jiffies + expires);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001526EXPORT_SYMBOL(dasd_device_set_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
1528/*
1529 * Clear timeout for a device.
1530 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001531void dasd_device_clear_timer(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532{
Stefan Weinhuber48cae882009-02-11 10:37:31 +01001533 del_timer(&device->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001535EXPORT_SYMBOL(dasd_device_clear_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001537static void dasd_handle_killed_request(struct ccw_device *cdev,
1538 unsigned long intparm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539{
1540 struct dasd_ccw_req *cqr;
1541 struct dasd_device *device;
1542
Stefan Weinhuberf16f58432008-05-15 16:52:36 +02001543 if (!intparm)
1544 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 cqr = (struct dasd_ccw_req *) intparm;
1546 if (cqr->status != DASD_CQR_IN_IO) {
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01001547 DBF_EVENT_DEVID(DBF_DEBUG, cdev,
1548 "invalid status in handle_killed_request: "
1549 "%02x", cqr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 return;
1551 }
1552
Stefan Haberland589c74d2010-02-26 22:37:47 +01001553 device = dasd_device_from_cdev_locked(cdev);
1554 if (IS_ERR(device)) {
1555 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1556 "unable to get device from cdev");
1557 return;
1558 }
1559
1560 if (!cqr->startdev ||
1561 device != cqr->startdev ||
1562 strncmp(cqr->startdev->discipline->ebcname,
1563 (char *) &cqr->magic, 4)) {
Stefan Haberland294001a2010-01-27 10:12:35 +01001564 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1565 "invalid device in request");
Stefan Haberland589c74d2010-02-26 22:37:47 +01001566 dasd_put_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 return;
1568 }
1569
1570 /* Schedule request to be retried. */
1571 cqr->status = DASD_CQR_QUEUED;
1572
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001573 dasd_device_clear_timer(device);
1574 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 dasd_put_device(device);
1576}
1577
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001578void dasd_generic_handle_state_change(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579{
Stefan Weinhuber20c64462006-03-24 03:15:25 -08001580 /* First of all start sense subsystem status request. */
1581 dasd_eer_snss(device);
1582
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01001583 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001584 dasd_schedule_device_bh(device);
Stefan Haberlande4433432017-05-22 10:59:11 +02001585 if (device->block) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001586 dasd_schedule_block_bh(device->block);
Stefan Haberland673514a2017-09-12 17:22:42 +02001587 if (device->block->request_queue)
1588 blk_mq_run_hw_queues(device->block->request_queue,
1589 true);
Stefan Haberlande4433432017-05-22 10:59:11 +02001590 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001592EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
Stefan Haberlanda521b042016-08-08 15:56:54 +02001594static int dasd_check_hpf_error(struct irb *irb)
1595{
1596 return (scsw_tm_is_valid_schxs(&irb->scsw) &&
1597 (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX ||
1598 irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX));
1599}
1600
Jan Höppner5e2b17e2018-04-27 16:51:22 +02001601static int dasd_ese_needs_format(struct dasd_block *block, struct irb *irb)
1602{
1603 struct dasd_device *device = NULL;
1604 u8 *sense = NULL;
1605
1606 if (!block)
1607 return 0;
1608 device = block->base;
1609 if (!device || !device->discipline->is_ese)
1610 return 0;
1611 if (!device->discipline->is_ese(device))
1612 return 0;
1613
1614 sense = dasd_get_sense(irb);
1615 if (!sense)
1616 return 0;
1617
1618 return !!(sense[1] & SNS1_NO_REC_FOUND) ||
1619 !!(sense[1] & SNS1_FILE_PROTECTED) ||
1620 scsw_cstat(&irb->scsw) == SCHN_STAT_INCORR_LEN;
1621}
1622
Jan Höppner9e12e542018-07-03 10:56:51 +02001623static int dasd_ese_oos_cond(u8 *sense)
1624{
1625 return sense[0] & SNS0_EQUIPMENT_CHECK &&
1626 sense[1] & SNS1_PERM_ERR &&
1627 sense[1] & SNS1_WRITE_INHIBITED &&
1628 sense[25] == 0x01;
1629}
1630
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631/*
1632 * Interrupt handler for "normal" ssch-io based dasd devices.
1633 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001634void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1635 struct irb *irb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636{
Jan Höppner5e2b17e2018-04-27 16:51:22 +02001637 struct dasd_ccw_req *cqr, *next, *fcqr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 struct dasd_device *device;
Jan Höppner7bf76f012017-08-15 16:40:18 +02001639 unsigned long now;
Jan Höppner8fd57522015-08-19 13:41:20 +02001640 int nrf_suppressed = 0;
1641 int fp_suppressed = 0;
1642 u8 *sense = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 int expires;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
Stefan Haberland9ba333d2016-08-08 14:08:17 +02001645 cqr = (struct dasd_ccw_req *) intparm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 if (IS_ERR(irb)) {
1647 switch (PTR_ERR(irb)) {
1648 case -EIO:
Stefan Haberland9ba333d2016-08-08 14:08:17 +02001649 if (cqr && cqr->status == DASD_CQR_CLEAR_PENDING) {
Stefan Haberlandc9346152016-08-08 15:53:54 +02001650 device = cqr->startdev;
Stefan Haberland9ba333d2016-08-08 14:08:17 +02001651 cqr->status = DASD_CQR_CLEARED;
1652 dasd_device_clear_timer(device);
1653 wake_up(&dasd_flush_wq);
1654 dasd_schedule_device_bh(device);
1655 return;
1656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 break;
1658 case -ETIMEDOUT:
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01001659 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1660 "request timed out\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 break;
1662 default:
Stefan Haberlandb8ed5dd2009-12-07 12:51:52 +01001663 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1664 "unknown error %ld\n", __func__,
1665 PTR_ERR(irb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 }
Stefan Weinhuberf16f58432008-05-15 16:52:36 +02001667 dasd_handle_killed_request(cdev, intparm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 return;
1669 }
1670
Heiko Carstens1aae0562013-01-30 09:49:40 +01001671 now = get_tod_clock();
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001672 /* check for conditions that should be handled immediately */
1673 if (!cqr ||
1674 !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1675 scsw_cstat(&irb->scsw) == 0)) {
Stefan Weinhubera5a00612010-10-25 16:10:47 +02001676 if (cqr)
1677 memcpy(&cqr->irb, irb, sizeof(*irb));
Martin Schwidefskya00bfd72006-09-20 15:59:05 +02001678 device = dasd_device_from_cdev_locked(cdev);
Stefan Haberland56b86b62010-10-25 16:10:49 +02001679 if (IS_ERR(device))
1680 return;
1681 /* ignore unsolicited interrupts for DIAG discipline */
1682 if (device->discipline == dasd_diag_discipline_pointer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 dasd_put_device(device);
Stefan Haberland56b86b62010-10-25 16:10:49 +02001684 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 }
Jan Höppner8fd57522015-08-19 13:41:20 +02001686
1687 /*
1688 * In some cases 'File Protected' or 'No Record Found' errors
1689 * might be expected and debug log messages for the
1690 * corresponding interrupts shouldn't be written then.
1691 * Check if either of the according suppress bits is set.
1692 */
1693 sense = dasd_get_sense(irb);
1694 if (sense) {
1695 fp_suppressed = (sense[1] & SNS1_FILE_PROTECTED) &&
1696 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
1697 nrf_suppressed = (sense[1] & SNS1_NO_REC_FOUND) &&
1698 test_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
Jan Höppner9e12e542018-07-03 10:56:51 +02001699
1700 /*
1701 * Extent pool probably out-of-space.
1702 * Stop device and check exhaust level.
1703 */
1704 if (dasd_ese_oos_cond(sense)) {
1705 dasd_generic_space_exhaust(device, cqr);
1706 device->discipline->ext_pool_exhaust(device, cqr);
1707 dasd_put_device(device);
1708 return;
1709 }
Jan Höppner8fd57522015-08-19 13:41:20 +02001710 }
1711 if (!(fp_suppressed || nrf_suppressed))
1712 device->discipline->dump_sense_dbf(device, irb, "int");
1713
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001714 if (device->features & DASD_FEATURE_ERPLOG)
1715 device->discipline->dump_sense(device, cqr, irb);
1716 device->discipline->check_for_device_change(device, cqr, irb);
Stefan Haberland56b86b62010-10-25 16:10:49 +02001717 dasd_put_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 }
Stefan Haberland5db84402014-10-01 14:39:47 +02001719
1720 /* check for for attention message */
1721 if (scsw_dstat(&irb->scsw) & DEV_STAT_ATTENTION) {
1722 device = dasd_device_from_cdev_locked(cdev);
Stefan Haberland22021342017-01-25 14:47:32 +01001723 if (!IS_ERR(device)) {
1724 device->discipline->check_attention(device,
1725 irb->esw.esw1.lpum);
1726 dasd_put_device(device);
1727 }
Stefan Haberland5db84402014-10-01 14:39:47 +02001728 }
1729
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001730 if (!cqr)
1731 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001733 device = (struct dasd_device *) cqr->startdev;
1734 if (!device ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
Stefan Haberland294001a2010-01-27 10:12:35 +01001736 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1737 "invalid device in request");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 return;
1739 }
1740
Jan Höppner5e2b17e2018-04-27 16:51:22 +02001741 if (dasd_ese_needs_format(cqr->block, irb)) {
1742 if (rq_data_dir((struct request *)cqr->callback_data) == READ) {
Stefan Haberland5e6bdd32020-03-12 14:17:15 +01001743 device->discipline->ese_read(cqr, irb);
Jan Höppner5e2b17e2018-04-27 16:51:22 +02001744 cqr->status = DASD_CQR_SUCCESS;
1745 cqr->stopclk = now;
1746 dasd_device_clear_timer(device);
1747 dasd_schedule_device_bh(device);
1748 return;
1749 }
Stefan Haberland5e6bdd32020-03-12 14:17:15 +01001750 fcqr = device->discipline->ese_format(device, cqr, irb);
Jan Höppner5e2b17e2018-04-27 16:51:22 +02001751 if (IS_ERR(fcqr)) {
Stefan Haberland5e6bdd32020-03-12 14:17:15 +01001752 if (PTR_ERR(fcqr) == -EINVAL) {
1753 cqr->status = DASD_CQR_ERROR;
1754 return;
1755 }
Jan Höppner5e2b17e2018-04-27 16:51:22 +02001756 /*
1757 * If we can't format now, let the request go
1758 * one extra round. Maybe we can format later.
1759 */
1760 cqr->status = DASD_CQR_QUEUED;
Stefan Haberland5e6bdd32020-03-12 14:17:15 +01001761 dasd_schedule_device_bh(device);
1762 return;
Jan Höppner5e2b17e2018-04-27 16:51:22 +02001763 } else {
1764 fcqr->status = DASD_CQR_QUEUED;
1765 cqr->status = DASD_CQR_QUEUED;
1766 list_add(&fcqr->devlist, &device->ccw_queue);
1767 dasd_schedule_device_bh(device);
1768 return;
1769 }
1770 }
1771
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 /* Check for clear pending */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001773 if (cqr->status == DASD_CQR_CLEAR_PENDING &&
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001774 scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001775 cqr->status = DASD_CQR_CLEARED;
1776 dasd_device_clear_timer(device);
Horst Hummel8f617012006-08-30 14:33:33 +02001777 wake_up(&dasd_flush_wq);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001778 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 return;
1780 }
1781
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001782 /* check status - the request might have been killed by dyn detach */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 if (cqr->status != DASD_CQR_IN_IO) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001784 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1785 "status %02x", dev_name(&cdev->dev), cqr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 return;
1787 }
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001788
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001789 next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 expires = 0;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01001791 if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1792 scsw_cstat(&irb->scsw) == 0) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001793 /* request was completed successfully */
1794 cqr->status = DASD_CQR_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 cqr->stopclk = now;
1796 /* Start first request on queue if possible -> fast_io. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001797 if (cqr->devlist.next != &device->ccw_queue) {
1798 next = list_entry(cqr->devlist.next,
1799 struct dasd_ccw_req, devlist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001801 } else { /* error */
Stefan Haberlanda521b042016-08-08 15:56:54 +02001802 /* check for HPF error
1803 * call discipline function to requeue all requests
1804 * and disable HPF accordingly
1805 */
1806 if (cqr->cpmode && dasd_check_hpf_error(irb) &&
1807 device->discipline->handle_hpf_error)
1808 device->discipline->handle_hpf_error(device, irb);
Stefan Haberland6c5f57c2008-02-05 16:50:46 +01001809 /*
1810 * If we don't want complex ERP for this request, then just
1811 * reset this and retry it in the fastpath
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001812 */
Stefan Haberland6c5f57c2008-02-05 16:50:46 +01001813 if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001814 cqr->retries > 0) {
Stefan Haberlandc9346152016-08-08 15:53:54 +02001815 if (cqr->lpm == dasd_path_get_opm(device))
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001816 DBF_DEV_EVENT(DBF_DEBUG, device,
1817 "default ERP in fastpath "
1818 "(%i retries left)",
1819 cqr->retries);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01001820 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
Stefan Haberlandc9346152016-08-08 15:53:54 +02001821 cqr->lpm = dasd_path_get_opm(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001822 cqr->status = DASD_CQR_QUEUED;
1823 next = cqr;
1824 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 cqr->status = DASD_CQR_ERROR;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001826 }
1827 if (next && (next->status == DASD_CQR_QUEUED) &&
1828 (!device->stopped)) {
1829 if (device->discipline->start_IO(next) == 0)
1830 expires = next->expires;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 }
1832 if (expires != 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001833 dasd_device_set_timer(device, expires);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 else
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001835 dasd_device_clear_timer(device);
1836 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02001838EXPORT_SYMBOL(dasd_int_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
Stefan Haberlanda23ed002010-05-26 23:27:09 +02001840enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb)
1841{
1842 struct dasd_device *device;
1843
1844 device = dasd_device_from_cdev_locked(cdev);
1845
1846 if (IS_ERR(device))
1847 goto out;
1848 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1849 device->state != device->target ||
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001850 !device->discipline->check_for_device_change){
Stefan Haberlanda23ed002010-05-26 23:27:09 +02001851 dasd_put_device(device);
1852 goto out;
1853 }
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01001854 if (device->discipline->dump_sense_dbf)
1855 device->discipline->dump_sense_dbf(device, irb, "uc");
1856 device->discipline->check_for_device_change(device, NULL, irb);
Stefan Haberlanda23ed002010-05-26 23:27:09 +02001857 dasd_put_device(device);
1858out:
1859 return UC_TODO_RETRY;
1860}
1861EXPORT_SYMBOL_GPL(dasd_generic_uc_handler);
1862
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001864 * If we have an error on a dasd_block layer request then we cancel
1865 * and return all further requests from the same dasd_block as well.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001867static void __dasd_device_recovery(struct dasd_device *device,
1868 struct dasd_ccw_req *ref_cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869{
1870 struct list_head *l, *n;
1871 struct dasd_ccw_req *cqr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
1873 /*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001874 * only requeue request that came from the dasd_block layer
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001876 if (!ref_cqr->block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 return;
Horst Hummelf24acd42005-05-01 08:58:59 -07001878
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001879 list_for_each_safe(l, n, &device->ccw_queue) {
1880 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1881 if (cqr->status == DASD_CQR_QUEUED &&
1882 ref_cqr->block == cqr->block) {
1883 cqr->status = DASD_CQR_CLEARED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001885 }
1886};
1887
1888/*
1889 * Remove those ccw requests from the queue that need to be returned
1890 * to the upper layer.
1891 */
1892static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1893 struct list_head *final_queue)
1894{
1895 struct list_head *l, *n;
1896 struct dasd_ccw_req *cqr;
1897
1898 /* Process request with final status. */
1899 list_for_each_safe(l, n, &device->ccw_queue) {
1900 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1901
Hannes Reinecke1fbdb8b2013-01-30 09:26:13 +00001902 /* Skip any non-final request. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001903 if (cqr->status == DASD_CQR_QUEUED ||
1904 cqr->status == DASD_CQR_IN_IO ||
1905 cqr->status == DASD_CQR_CLEAR_PENDING)
Hannes Reinecke1fbdb8b2013-01-30 09:26:13 +00001906 continue;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001907 if (cqr->status == DASD_CQR_ERROR) {
1908 __dasd_device_recovery(device, cqr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001910 /* Rechain finished requests to final queue */
1911 list_move_tail(&cqr->devlist, final_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 }
1913}
1914
Sebastian Ott5c618c02018-05-24 12:18:58 +02001915static void __dasd_process_cqr(struct dasd_device *device,
1916 struct dasd_ccw_req *cqr)
1917{
1918 char errorstring[ERRORLENGTH];
1919
1920 switch (cqr->status) {
1921 case DASD_CQR_SUCCESS:
1922 cqr->status = DASD_CQR_DONE;
1923 break;
1924 case DASD_CQR_ERROR:
1925 cqr->status = DASD_CQR_NEED_ERP;
1926 break;
1927 case DASD_CQR_CLEARED:
1928 cqr->status = DASD_CQR_TERMINATED;
1929 break;
1930 default:
1931 /* internal error 12 - wrong cqr status*/
1932 snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status);
1933 dev_err(&device->cdev->dev,
1934 "An error occurred in the DASD device driver, "
1935 "reason=%s\n", errorstring);
1936 BUG();
1937 }
1938 if (cqr->callback)
1939 cqr->callback(cqr, cqr->callback_data);
1940}
1941
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001943 * the cqrs from the final queue are returned to the upper layer
1944 * by setting a dasd_block state and calling the callback function
1945 */
1946static void __dasd_device_process_final_queue(struct dasd_device *device,
1947 struct list_head *final_queue)
1948{
1949 struct list_head *l, *n;
1950 struct dasd_ccw_req *cqr;
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001951 struct dasd_block *block;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001952
1953 list_for_each_safe(l, n, final_queue) {
1954 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1955 list_del_init(&cqr->devlist);
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001956 block = cqr->block;
Sebastian Ott5c618c02018-05-24 12:18:58 +02001957 if (!block) {
1958 __dasd_process_cqr(device, cqr);
1959 } else {
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001960 spin_lock_bh(&block->queue_lock);
Sebastian Ott5c618c02018-05-24 12:18:58 +02001961 __dasd_process_cqr(device, cqr);
Stefan Weinhuber03513bc2008-02-19 15:29:27 +01001962 spin_unlock_bh(&block->queue_lock);
Sebastian Ott5c618c02018-05-24 12:18:58 +02001963 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001964 }
1965}
1966
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001967/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 * Take a look at the first request on the ccw queue and check
1969 * if it reached its expire time. If so, terminate the IO.
1970 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001971static void __dasd_device_check_expire(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972{
1973 struct dasd_ccw_req *cqr;
1974
1975 if (list_empty(&device->ccw_queue))
1976 return;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001977 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
Horst Hummel29145a62006-12-04 15:40:15 +01001978 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1979 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01001980 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1981 /*
1982 * IO in safe offline processing should not
1983 * run out of retries
1984 */
1985 cqr->retries++;
1986 }
Horst Hummel29145a62006-12-04 15:40:15 +01001987 if (device->discipline->term_IO(cqr) != 0) {
1988 /* Hmpf, try again in 5 sec */
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001989 dev_err(&device->cdev->dev,
Heiko Carstens625c94d2010-08-13 10:06:38 +02001990 "cqr %p timed out (%lus) but cannot be "
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001991 "ended, retrying in 5 s\n",
1992 cqr, (cqr->expires/HZ));
Stefan Haberland7dc1da92008-01-26 14:11:26 +01001993 cqr->expires += 5*HZ;
1994 dasd_device_set_timer(device, 5*HZ);
Horst Hummel29145a62006-12-04 15:40:15 +01001995 } else {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001996 dev_err(&device->cdev->dev,
Heiko Carstens625c94d2010-08-13 10:06:38 +02001997 "cqr %p timed out (%lus), %i retries "
Stefan Haberlandfc19f382009-03-26 15:23:49 +01001998 "remaining\n", cqr, (cqr->expires/HZ),
1999 cqr->retries);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 }
2001 }
2002}
2003
2004/*
Stefan Haberlandf81a49d2015-07-10 10:47:09 +02002005 * return 1 when device is not eligible for IO
2006 */
2007static int __dasd_device_is_unusable(struct dasd_device *device,
2008 struct dasd_ccw_req *cqr)
2009{
Vineeth Vijayan127fca62020-11-10 09:28:33 +01002010 int mask = ~(DASD_STOPPED_DC_WAIT | DASD_STOPPED_NOSPC);
Stefan Haberlandf81a49d2015-07-10 10:47:09 +02002011
Stefan Haberlande8ac0152017-05-18 13:24:45 +02002012 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
2013 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
2014 /*
2015 * dasd is being set offline
2016 * but it is no safe offline where we have to allow I/O
2017 */
Stefan Haberlandf81a49d2015-07-10 10:47:09 +02002018 return 1;
2019 }
2020 if (device->stopped) {
2021 if (device->stopped & mask) {
2022 /* stopped and CQR will not change that. */
2023 return 1;
2024 }
2025 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2026 /* CQR is not able to change device to
2027 * operational. */
2028 return 1;
2029 }
2030 /* CQR required to get device operational. */
2031 }
2032 return 0;
2033}
2034
2035/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 * Take a look at the first request on the ccw queue and check
2037 * if it needs to be started.
2038 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002039static void __dasd_device_start_head(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040{
2041 struct dasd_ccw_req *cqr;
2042 int rc;
2043
2044 if (list_empty(&device->ccw_queue))
2045 return;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002046 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07002047 if (cqr->status != DASD_CQR_QUEUED)
2048 return;
Stefan Haberlandf81a49d2015-07-10 10:47:09 +02002049 /* if device is not usable return request to upper layer */
2050 if (__dasd_device_is_unusable(device, cqr)) {
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01002051 cqr->intrc = -EAGAIN;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002052 cqr->status = DASD_CQR_CLEARED;
2053 dasd_schedule_device_bh(device);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07002054 return;
Horst Hummel1c01b8a2006-01-06 00:19:15 -08002055 }
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07002056
2057 rc = device->discipline->start_IO(cqr);
2058 if (rc == 0)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002059 dasd_device_set_timer(device, cqr->expires);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07002060 else if (rc == -EACCES) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002061 dasd_schedule_device_bh(device);
Peter Oberparleiter25ee4cf2006-04-10 22:53:47 -07002062 } else
2063 /* Hmpf, try again in 1/2 sec */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002064 dasd_device_set_timer(device, 50);
Horst Hummel8f617012006-08-30 14:33:33 +02002065}
2066
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01002067static void __dasd_device_check_path_events(struct dasd_device *device)
2068{
Jan Höppner4d063e62020-10-08 15:13:36 +02002069 __u8 tbvpm, fcsecpm;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01002070 int rc;
2071
Jan Höppner4d063e62020-10-08 15:13:36 +02002072 tbvpm = dasd_path_get_tbvpm(device);
2073 fcsecpm = dasd_path_get_fcsecpm(device);
2074
2075 if (!tbvpm && !fcsecpm)
Stefan Haberlandc9346152016-08-08 15:53:54 +02002076 return;
2077
Vineeth Vijayan127fca62020-11-10 09:28:33 +01002078 if (device->stopped & ~(DASD_STOPPED_DC_WAIT))
Stefan Haberlandc9346152016-08-08 15:53:54 +02002079 return;
Stefan Haberlanda8e5d492021-10-20 13:51:24 +02002080
2081 dasd_path_clear_all_verify(device);
2082 dasd_path_clear_all_fcsec(device);
2083
Jan Höppner4d063e62020-10-08 15:13:36 +02002084 rc = device->discipline->pe_handler(device, tbvpm, fcsecpm);
2085 if (rc) {
Stefan Haberlanda8e5d492021-10-20 13:51:24 +02002086 dasd_path_add_tbvpm(device, tbvpm);
2087 dasd_path_add_fcsecpm(device, fcsecpm);
Stefan Haberlandc9346152016-08-08 15:53:54 +02002088 dasd_device_set_timer(device, 50);
Jan Höppner4d063e62020-10-08 15:13:36 +02002089 }
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01002090};
2091
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002093 * Go through all request on the dasd_device request queue,
2094 * terminate them on the cdev if necessary, and return them to the
2095 * submitting layer via callback.
2096 * Note:
2097 * Make sure that all 'submitting layers' still exist when
2098 * this function is called!. In other words, when 'device' is a base
2099 * device then all block layer requests must have been removed before
2100 * via dasd_flush_block_queue.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002102int dasd_flush_device_queue(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002104 struct dasd_ccw_req *cqr, *n;
2105 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 struct list_head flush_queue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
2108 INIT_LIST_HEAD(&flush_queue);
2109 spin_lock_irq(get_ccwdev_lock(device->cdev));
Horst Hummel8f617012006-08-30 14:33:33 +02002110 rc = 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002111 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
Horst Hummel8f617012006-08-30 14:33:33 +02002112 /* Check status and move request to flush_queue */
2113 switch (cqr->status) {
2114 case DASD_CQR_IN_IO:
2115 rc = device->discipline->term_IO(cqr);
2116 if (rc) {
2117 /* unable to terminate requeust */
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002118 dev_err(&device->cdev->dev,
2119 "Flushing the DASD request queue "
2120 "failed for request %p\n", cqr);
Horst Hummel8f617012006-08-30 14:33:33 +02002121 /* stop flush processing */
2122 goto finished;
2123 }
2124 break;
2125 case DASD_CQR_QUEUED:
Heiko Carstens1aae0562013-01-30 09:49:40 +01002126 cqr->stopclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002127 cqr->status = DASD_CQR_CLEARED;
Horst Hummel8f617012006-08-30 14:33:33 +02002128 break;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002129 default: /* no need to modify the others */
Horst Hummel8f617012006-08-30 14:33:33 +02002130 break;
2131 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002132 list_move_tail(&cqr->devlist, &flush_queue);
Horst Hummel8f617012006-08-30 14:33:33 +02002133 }
Horst Hummel8f617012006-08-30 14:33:33 +02002134finished:
2135 spin_unlock_irq(get_ccwdev_lock(device->cdev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002136 /*
2137 * After this point all requests must be in state CLEAR_PENDING,
2138 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
2139 * one of the others.
2140 */
2141 list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
2142 wait_event(dasd_flush_wq,
2143 (cqr->status != DASD_CQR_CLEAR_PENDING));
2144 /*
2145 * Now set each request back to TERMINATED, DONE or NEED_ERP
2146 * and call the callback function of flushed requests
2147 */
2148 __dasd_device_process_final_queue(device, &flush_queue);
Horst Hummel8f617012006-08-30 14:33:33 +02002149 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002151EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152
2153/*
2154 * Acquire the device lock and process queues for the device.
2155 */
Sebastian Ottd2f2df62018-07-03 13:06:45 +02002156static void dasd_device_tasklet(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157{
Sebastian Ottd2f2df62018-07-03 13:06:45 +02002158 struct dasd_device *device = (struct dasd_device *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 struct list_head final_queue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
2161 atomic_set (&device->tasklet_scheduled, 0);
2162 INIT_LIST_HEAD(&final_queue);
2163 spin_lock_irq(get_ccwdev_lock(device->cdev));
2164 /* Check expire time of first request on the ccw queue. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002165 __dasd_device_check_expire(device);
2166 /* find final requests on ccw queue */
2167 __dasd_device_process_ccw_queue(device, &final_queue);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01002168 __dasd_device_check_path_events(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2170 /* Now call the callback function of requests with final status */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002171 __dasd_device_process_final_queue(device, &final_queue);
2172 spin_lock_irq(get_ccwdev_lock(device->cdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 /* Now check if the head of the ccw queue needs to be started. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002174 __dasd_device_start_head(device);
2175 spin_unlock_irq(get_ccwdev_lock(device->cdev));
Stefan Haberland4679e892012-06-19 17:30:12 +02002176 if (waitqueue_active(&shutdown_waitq))
2177 wake_up(&shutdown_waitq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 dasd_put_device(device);
2179}
2180
2181/*
2182 * Schedules a call to dasd_tasklet over the device tasklet.
2183 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002184void dasd_schedule_device_bh(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185{
2186 /* Protect against rescheduling. */
Martin Schwidefsky973bd992006-01-06 00:19:07 -08002187 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 return;
2189 dasd_get_device(device);
2190 tasklet_hi_schedule(&device->tasklet);
2191}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002192EXPORT_SYMBOL(dasd_schedule_device_bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002194void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
2195{
2196 device->stopped |= bits;
2197}
2198EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits);
2199
2200void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
2201{
2202 device->stopped &= ~bits;
2203 if (!device->stopped)
2204 wake_up(&generic_waitq);
2205}
2206EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits);
2207
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002209 * Queue a request to the head of the device ccw_queue.
2210 * Start the I/O if possible.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002212void dasd_add_request_head(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213{
2214 struct dasd_device *device;
2215 unsigned long flags;
2216
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002217 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002219 cqr->status = DASD_CQR_QUEUED;
2220 list_add(&cqr->devlist, &device->ccw_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 /* let the bh start the request to keep them in order */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002222 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2224}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002225EXPORT_SYMBOL(dasd_add_request_head);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
2227/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002228 * Queue a request to the tail of the device ccw_queue.
2229 * Start the I/O if possible.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002231void dasd_add_request_tail(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232{
2233 struct dasd_device *device;
2234 unsigned long flags;
2235
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002236 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002238 cqr->status = DASD_CQR_QUEUED;
2239 list_add_tail(&cqr->devlist, &device->ccw_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 /* let the bh start the request to keep them in order */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002241 dasd_schedule_device_bh(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2243}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002244EXPORT_SYMBOL(dasd_add_request_tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
2246/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002247 * Wakeup helper for the 'sleep_on' functions.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 */
Stefan Haberland5915a872011-10-30 15:16:57 +01002249void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250{
Stefan Weinhuber1c1e0932010-05-12 09:32:11 +02002251 spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2252 cqr->callback_data = DASD_SLEEPON_END_TAG;
2253 spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2254 wake_up(&generic_waitq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255}
Stefan Haberland5915a872011-10-30 15:16:57 +01002256EXPORT_SYMBOL_GPL(dasd_wakeup_cb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002258static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259{
2260 struct dasd_device *device;
2261 int rc;
2262
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002263 device = cqr->startdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 spin_lock_irq(get_ccwdev_lock(device->cdev));
Stefan Weinhuber1c1e0932010-05-12 09:32:11 +02002265 rc = (cqr->callback_data == DASD_SLEEPON_END_TAG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2267 return rc;
2268}
2269
2270/*
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002271 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2272 */
2273static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr)
2274{
2275 struct dasd_device *device;
2276 dasd_erp_fn_t erp_fn;
2277
2278 if (cqr->status == DASD_CQR_FILLED)
2279 return 0;
2280 device = cqr->startdev;
2281 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2282 if (cqr->status == DASD_CQR_TERMINATED) {
2283 device->discipline->handle_terminated_request(cqr);
2284 return 1;
2285 }
2286 if (cqr->status == DASD_CQR_NEED_ERP) {
2287 erp_fn = device->discipline->erp_action(cqr);
2288 erp_fn(cqr);
2289 return 1;
2290 }
2291 if (cqr->status == DASD_CQR_FAILED)
2292 dasd_log_sense(cqr, &cqr->irb);
2293 if (cqr->refers) {
2294 __dasd_process_erp(device, cqr);
2295 return 1;
2296 }
2297 }
2298 return 0;
2299}
2300
2301static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr)
2302{
2303 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2304 if (cqr->refers) /* erp is not done yet */
2305 return 1;
2306 return ((cqr->status != DASD_CQR_DONE) &&
2307 (cqr->status != DASD_CQR_FAILED));
2308 } else
2309 return (cqr->status == DASD_CQR_FILLED);
2310}
2311
2312static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
2313{
2314 struct dasd_device *device;
2315 int rc;
2316 struct list_head ccw_queue;
2317 struct dasd_ccw_req *cqr;
2318
2319 INIT_LIST_HEAD(&ccw_queue);
2320 maincqr->status = DASD_CQR_FILLED;
2321 device = maincqr->startdev;
2322 list_add(&maincqr->blocklist, &ccw_queue);
2323 for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr);
2324 cqr = list_first_entry(&ccw_queue,
2325 struct dasd_ccw_req, blocklist)) {
2326
2327 if (__dasd_sleep_on_erp(cqr))
2328 continue;
2329 if (cqr->status != DASD_CQR_FILLED) /* could be failed */
2330 continue;
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01002331 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2332 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2333 cqr->status = DASD_CQR_FAILED;
2334 cqr->intrc = -EPERM;
2335 continue;
2336 }
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002337 /* Non-temporary stop condition will trigger fail fast */
2338 if (device->stopped & ~DASD_STOPPED_PENDING &&
2339 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2340 (!dasd_eer_enabled(device))) {
2341 cqr->status = DASD_CQR_FAILED;
Hannes Reinecked1ffc1f2013-01-30 09:26:16 +00002342 cqr->intrc = -ENOLINK;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002343 continue;
2344 }
Stefan Haberlanddf3044f2015-04-02 13:18:39 +02002345 /*
Stefan Haberlanda9f62732016-09-20 10:29:22 +02002346 * Don't try to start requests if device is in
2347 * offline processing, it might wait forever
2348 */
2349 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2350 cqr->status = DASD_CQR_FAILED;
2351 cqr->intrc = -ENODEV;
2352 continue;
2353 }
2354 /*
Stefan Haberlanddf3044f2015-04-02 13:18:39 +02002355 * Don't try to start requests if device is stopped
2356 * except path verification requests
2357 */
2358 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2359 if (interruptible) {
2360 rc = wait_event_interruptible(
2361 generic_waitq, !(device->stopped));
2362 if (rc == -ERESTARTSYS) {
2363 cqr->status = DASD_CQR_FAILED;
2364 maincqr->intrc = rc;
2365 continue;
2366 }
2367 } else
2368 wait_event(generic_waitq, !(device->stopped));
2369 }
Stefan Haberland5915a872011-10-30 15:16:57 +01002370 if (!cqr->callback)
2371 cqr->callback = dasd_wakeup_cb;
2372
Stefan Weinhuber1c1e0932010-05-12 09:32:11 +02002373 cqr->callback_data = DASD_SLEEPON_START_TAG;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002374 dasd_add_request_tail(cqr);
2375 if (interruptible) {
2376 rc = wait_event_interruptible(
2377 generic_waitq, _wait_for_wakeup(cqr));
2378 if (rc == -ERESTARTSYS) {
2379 dasd_cancel_req(cqr);
2380 /* wait (non-interruptible) for final status */
2381 wait_event(generic_waitq,
2382 _wait_for_wakeup(cqr));
2383 cqr->status = DASD_CQR_FAILED;
2384 maincqr->intrc = rc;
2385 continue;
2386 }
2387 } else
2388 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2389 }
2390
Heiko Carstens1aae0562013-01-30 09:49:40 +01002391 maincqr->endclk = get_tod_clock();
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002392 if ((maincqr->status != DASD_CQR_DONE) &&
2393 (maincqr->intrc != -ERESTARTSYS))
2394 dasd_log_sense(maincqr, &maincqr->irb);
2395 if (maincqr->status == DASD_CQR_DONE)
2396 rc = 0;
2397 else if (maincqr->intrc)
2398 rc = maincqr->intrc;
2399 else
2400 rc = -EIO;
2401 return rc;
2402}
2403
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002404static inline int _wait_for_wakeup_queue(struct list_head *ccw_queue)
2405{
2406 struct dasd_ccw_req *cqr;
2407
2408 list_for_each_entry(cqr, ccw_queue, blocklist) {
2409 if (cqr->callback_data != DASD_SLEEPON_END_TAG)
2410 return 0;
2411 }
2412
2413 return 1;
2414}
2415
2416static int _dasd_sleep_on_queue(struct list_head *ccw_queue, int interruptible)
2417{
2418 struct dasd_device *device;
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002419 struct dasd_ccw_req *cqr, *n;
Jan Höppner8fd57522015-08-19 13:41:20 +02002420 u8 *sense = NULL;
Stefan Haberland362ce842014-10-01 13:04:54 +02002421 int rc;
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002422
2423retry:
2424 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2425 device = cqr->startdev;
2426 if (cqr->status != DASD_CQR_FILLED) /*could be failed*/
2427 continue;
2428
2429 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2430 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2431 cqr->status = DASD_CQR_FAILED;
2432 cqr->intrc = -EPERM;
2433 continue;
2434 }
2435 /*Non-temporary stop condition will trigger fail fast*/
2436 if (device->stopped & ~DASD_STOPPED_PENDING &&
2437 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2438 !dasd_eer_enabled(device)) {
2439 cqr->status = DASD_CQR_FAILED;
2440 cqr->intrc = -EAGAIN;
2441 continue;
2442 }
2443
2444 /*Don't try to start requests if device is stopped*/
2445 if (interruptible) {
2446 rc = wait_event_interruptible(
2447 generic_waitq, !device->stopped);
2448 if (rc == -ERESTARTSYS) {
2449 cqr->status = DASD_CQR_FAILED;
2450 cqr->intrc = rc;
2451 continue;
2452 }
2453 } else
2454 wait_event(generic_waitq, !(device->stopped));
2455
2456 if (!cqr->callback)
2457 cqr->callback = dasd_wakeup_cb;
2458 cqr->callback_data = DASD_SLEEPON_START_TAG;
2459 dasd_add_request_tail(cqr);
2460 }
2461
2462 wait_event(generic_waitq, _wait_for_wakeup_queue(ccw_queue));
2463
2464 rc = 0;
2465 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
Stefan Haberland29b8dd92014-07-18 14:26:01 +02002466 /*
Jan Höppner8fd57522015-08-19 13:41:20 +02002467 * In some cases the 'File Protected' or 'Incorrect Length'
2468 * error might be expected and error recovery would be
2469 * unnecessary in these cases. Check if the according suppress
2470 * bit is set.
2471 */
2472 sense = dasd_get_sense(&cqr->irb);
2473 if (sense && sense[1] & SNS1_FILE_PROTECTED &&
2474 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags))
2475 continue;
2476 if (scsw_cstat(&cqr->irb.scsw) == 0x40 &&
2477 test_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags))
2478 continue;
2479
2480 /*
Stefan Haberland29b8dd92014-07-18 14:26:01 +02002481 * for alias devices simplify error recovery and
2482 * return to upper layer
Stefan Haberland362ce842014-10-01 13:04:54 +02002483 * do not skip ERP requests
Stefan Haberland29b8dd92014-07-18 14:26:01 +02002484 */
Stefan Haberland362ce842014-10-01 13:04:54 +02002485 if (cqr->startdev != cqr->basedev && !cqr->refers &&
Stefan Haberland29b8dd92014-07-18 14:26:01 +02002486 (cqr->status == DASD_CQR_TERMINATED ||
2487 cqr->status == DASD_CQR_NEED_ERP))
2488 return -EAGAIN;
Stefan Haberland362ce842014-10-01 13:04:54 +02002489
2490 /* normal recovery for basedev IO */
Stefan Haberland590aeed2014-11-24 10:45:47 +01002491 if (__dasd_sleep_on_erp(cqr))
2492 /* handle erp first */
Stefan Haberland362ce842014-10-01 13:04:54 +02002493 goto retry;
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002494 }
Stefan Haberland362ce842014-10-01 13:04:54 +02002495
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002496 return 0;
2497}
2498
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002499/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002500 * Queue a request to the tail of the device ccw_queue and wait for
2501 * it's completion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002503int dasd_sleep_on(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504{
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002505 return _dasd_sleep_on(cqr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002507EXPORT_SYMBOL(dasd_sleep_on);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508
2509/*
Stefan Haberlandd42e1712013-04-15 16:22:23 +02002510 * Start requests from a ccw_queue and wait for their completion.
2511 */
2512int dasd_sleep_on_queue(struct list_head *ccw_queue)
2513{
2514 return _dasd_sleep_on_queue(ccw_queue, 0);
2515}
2516EXPORT_SYMBOL(dasd_sleep_on_queue);
2517
2518/*
Jan Höppnerbcf36762019-06-27 14:33:17 +02002519 * Start requests from a ccw_queue and wait interruptible for their completion.
2520 */
2521int dasd_sleep_on_queue_interruptible(struct list_head *ccw_queue)
2522{
2523 return _dasd_sleep_on_queue(ccw_queue, 1);
2524}
2525EXPORT_SYMBOL(dasd_sleep_on_queue_interruptible);
2526
2527/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002528 * Queue a request to the tail of the device ccw_queue and wait
2529 * interruptible for it's completion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002531int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532{
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002533 return _dasd_sleep_on(cqr, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002535EXPORT_SYMBOL(dasd_sleep_on_interruptible);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536
2537/*
2538 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2539 * for eckd devices) the currently running request has to be terminated
2540 * and be put back to status queued, before the special request is added
2541 * to the head of the queue. Then the special request is waited on normally.
2542 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002543static inline int _dasd_term_running_cqr(struct dasd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544{
2545 struct dasd_ccw_req *cqr;
Stefan Haberlandaade6c02011-05-10 17:13:38 +02002546 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547
2548 if (list_empty(&device->ccw_queue))
2549 return 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002550 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
Stefan Haberlandaade6c02011-05-10 17:13:38 +02002551 rc = device->discipline->term_IO(cqr);
2552 if (!rc)
2553 /*
2554 * CQR terminated because a more important request is pending.
2555 * Undo decreasing of retry counter because this is
2556 * not an error case.
2557 */
2558 cqr->retries++;
2559 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560}
2561
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002562int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 struct dasd_device *device;
2565 int rc;
Horst Hummel138c0142006-06-29 14:58:12 +02002566
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002567 device = cqr->startdev;
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01002568 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2569 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2570 cqr->status = DASD_CQR_FAILED;
2571 cqr->intrc = -EPERM;
2572 return -EIO;
2573 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 spin_lock_irq(get_ccwdev_lock(device->cdev));
2575 rc = _dasd_term_running_cqr(device);
2576 if (rc) {
2577 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2578 return rc;
2579 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 cqr->callback = dasd_wakeup_cb;
Stefan Weinhuber1c1e0932010-05-12 09:32:11 +02002581 cqr->callback_data = DASD_SLEEPON_START_TAG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 cqr->status = DASD_CQR_QUEUED;
Stefan Haberland214b8ff2011-10-30 15:16:56 +01002583 /*
2584 * add new request as second
2585 * first the terminated cqr needs to be finished
2586 */
2587 list_add(&cqr->devlist, device->ccw_queue.next);
Horst Hummel138c0142006-06-29 14:58:12 +02002588
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 /* let the bh start the request to keep them in order */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002590 dasd_schedule_device_bh(device);
Horst Hummel138c0142006-06-29 14:58:12 +02002591
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2593
Stefan Haberlandc80ee722008-05-30 10:03:31 +02002594 wait_event(generic_waitq, _wait_for_wakeup(cqr));
Horst Hummel138c0142006-06-29 14:58:12 +02002595
Stefan Weinhuber6cc7f162009-06-12 10:26:39 +02002596 if (cqr->status == DASD_CQR_DONE)
2597 rc = 0;
2598 else if (cqr->intrc)
2599 rc = cqr->intrc;
2600 else
2601 rc = -EIO;
Stefan Haberland0e003b72013-07-30 10:49:43 +02002602
2603 /* kick tasklets */
2604 dasd_schedule_device_bh(device);
2605 if (device->block)
2606 dasd_schedule_block_bh(device->block);
2607
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 return rc;
2609}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002610EXPORT_SYMBOL(dasd_sleep_on_immediatly);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611
2612/*
2613 * Cancels a request that was started with dasd_sleep_on_req.
2614 * This is useful to timeout requests. The request will be
2615 * terminated if it is currently in i/o.
Hannes Reineckeb99a9462013-01-30 09:26:11 +00002616 * Returns 0 if request termination was successful
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002617 * negative error code if termination failed
2618 * Cancellation of a request is an asynchronous operation! The calling
2619 * function has to wait until the request is properly returned via callback.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 */
Sebastian Ott1bcdb532018-05-16 11:25:21 +02002621static int __dasd_cancel_req(struct dasd_ccw_req *cqr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002623 struct dasd_device *device = cqr->startdev;
Sebastian Ott1bcdb532018-05-16 11:25:21 +02002624 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 switch (cqr->status) {
2627 case DASD_CQR_QUEUED:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002628 /* request was not started - just set to cleared */
2629 cqr->status = DASD_CQR_CLEARED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 break;
2631 case DASD_CQR_IN_IO:
2632 /* request in IO - terminate IO and release again */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002633 rc = device->discipline->term_IO(cqr);
2634 if (rc) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002635 dev_err(&device->cdev->dev,
2636 "Cancelling request %p failed with rc=%d\n",
2637 cqr, rc);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002638 } else {
Heiko Carstens1aae0562013-01-30 09:49:40 +01002639 cqr->stopclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002640 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 break;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002642 default: /* already finished or clear pending - do nothing */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002645 dasd_schedule_device_bh(device);
2646 return rc;
2647}
Sebastian Ott1bcdb532018-05-16 11:25:21 +02002648
2649int dasd_cancel_req(struct dasd_ccw_req *cqr)
2650{
2651 struct dasd_device *device = cqr->startdev;
2652 unsigned long flags;
2653 int rc;
2654
2655 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2656 rc = __dasd_cancel_req(cqr);
2657 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2658 return rc;
2659}
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002660
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002661/*
2662 * SECTION: Operations of the dasd_block layer.
2663 */
2664
2665/*
2666 * Timeout function for dasd_block. This is used when the block layer
2667 * is waiting for something that may not come reliably, (e.g. a state
2668 * change interrupt)
2669 */
Kees Cooke99e88a2017-10-16 14:43:17 -07002670static void dasd_block_timeout(struct timer_list *t)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002671{
2672 unsigned long flags;
2673 struct dasd_block *block;
2674
Kees Cooke99e88a2017-10-16 14:43:17 -07002675 block = from_timer(block, t, timer);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002676 spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
2677 /* re-activate request queue */
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002678 dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002679 spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
2680 dasd_schedule_block_bh(block);
Stefan Haberlande4433432017-05-22 10:59:11 +02002681 blk_mq_run_hw_queues(block->request_queue, true);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002682}
2683
2684/*
2685 * Setup timeout for a dasd_block in jiffies.
2686 */
2687void dasd_block_set_timer(struct dasd_block *block, int expires)
2688{
Stefan Weinhuber48cae882009-02-11 10:37:31 +01002689 if (expires == 0)
2690 del_timer(&block->timer);
2691 else
2692 mod_timer(&block->timer, jiffies + expires);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002693}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002694EXPORT_SYMBOL(dasd_block_set_timer);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002695
2696/*
2697 * Clear timeout for a dasd_block.
2698 */
2699void dasd_block_clear_timer(struct dasd_block *block)
2700{
Stefan Weinhuber48cae882009-02-11 10:37:31 +01002701 del_timer(&block->timer);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002702}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02002703EXPORT_SYMBOL(dasd_block_clear_timer);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002704
2705/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002706 * Process finished error recovery ccw.
2707 */
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002708static void __dasd_process_erp(struct dasd_device *device,
2709 struct dasd_ccw_req *cqr)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002710{
2711 dasd_erp_fn_t erp_fn;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002712
2713 if (cqr->status == DASD_CQR_DONE)
2714 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
2715 else
Stefan Haberlandfc19f382009-03-26 15:23:49 +01002716 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002717 erp_fn = device->discipline->erp_postaction(cqr);
2718 erp_fn(cqr);
2719}
2720
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002721static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
2722{
2723 struct request *req;
Christoph Hellwig2a842ac2017-06-03 09:38:04 +02002724 blk_status_t error = BLK_STS_OK;
Stefan Haberland5e6bdd32020-03-12 14:17:15 +01002725 unsigned int proc_bytes;
Stefan Haberlande4433432017-05-22 10:59:11 +02002726 int status;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002727
2728 req = (struct request *) cqr->callback_data;
2729 dasd_profile_end(cqr->block, cqr, req);
Christoph Hellwig2a842ac2017-06-03 09:38:04 +02002730
Stefan Haberland5e6bdd32020-03-12 14:17:15 +01002731 proc_bytes = cqr->proc_bytes;
Stefan Weinhuberfe6b8e72008-02-05 16:50:47 +01002732 status = cqr->block->base->discipline->free_cp(cqr, req);
Hannes Reinecked1ffc1f2013-01-30 09:26:16 +00002733 if (status < 0)
Christoph Hellwig2a842ac2017-06-03 09:38:04 +02002734 error = errno_to_blk_status(status);
Hannes Reinecked1ffc1f2013-01-30 09:26:16 +00002735 else if (status == 0) {
Christoph Hellwig2a842ac2017-06-03 09:38:04 +02002736 switch (cqr->intrc) {
2737 case -EPERM:
2738 error = BLK_STS_NEXUS;
2739 break;
2740 case -ENOLINK:
2741 error = BLK_STS_TRANSPORT;
2742 break;
2743 case -ETIMEDOUT:
2744 error = BLK_STS_TIMEOUT;
2745 break;
2746 default:
2747 error = BLK_STS_IOERR;
2748 break;
2749 }
Hannes Reinecked1ffc1f2013-01-30 09:26:16 +00002750 }
Stefan Haberlande4433432017-05-22 10:59:11 +02002751
2752 /*
2753 * We need to take care for ETIMEDOUT errors here since the
2754 * complete callback does not get called in this case.
2755 * Take care of all errors here and avoid additional code to
2756 * transfer the error value to the complete callback.
2757 */
2758 if (error) {
2759 blk_mq_end_request(req, error);
2760 blk_mq_run_hw_queues(req->q, true);
2761 } else {
Stefan Haberland5e6bdd32020-03-12 14:17:15 +01002762 /*
2763 * Partial completed requests can happen with ESE devices.
2764 * During read we might have gotten a NRF error and have to
2765 * complete a request partially.
2766 */
2767 if (proc_bytes) {
2768 blk_update_request(req, BLK_STS_OK,
2769 blk_rq_bytes(req) - proc_bytes);
2770 blk_mq_requeue_request(req, true);
Christoph Hellwig15f73f52020-06-11 08:44:47 +02002771 } else if (likely(!blk_should_fake_timeout(req->q))) {
Stefan Haberland5e6bdd32020-03-12 14:17:15 +01002772 blk_mq_complete_request(req);
2773 }
Stefan Haberlande4433432017-05-22 10:59:11 +02002774 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002775}
2776
2777/*
2778 * Process ccw request queue.
2779 */
2780static void __dasd_process_block_ccw_queue(struct dasd_block *block,
2781 struct list_head *final_queue)
2782{
2783 struct list_head *l, *n;
2784 struct dasd_ccw_req *cqr;
2785 dasd_erp_fn_t erp_fn;
2786 unsigned long flags;
2787 struct dasd_device *base = block->base;
2788
2789restart:
2790 /* Process request with final status. */
2791 list_for_each_safe(l, n, &block->ccw_queue) {
2792 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2793 if (cqr->status != DASD_CQR_DONE &&
2794 cqr->status != DASD_CQR_FAILED &&
2795 cqr->status != DASD_CQR_NEED_ERP &&
2796 cqr->status != DASD_CQR_TERMINATED)
2797 continue;
2798
2799 if (cqr->status == DASD_CQR_TERMINATED) {
2800 base->discipline->handle_terminated_request(cqr);
2801 goto restart;
2802 }
2803
2804 /* Process requests that may be recovered */
2805 if (cqr->status == DASD_CQR_NEED_ERP) {
Stefan Haberland6c5f57c2008-02-05 16:50:46 +01002806 erp_fn = base->discipline->erp_action(cqr);
Stefan Haberland6a5176c2010-04-22 17:17:02 +02002807 if (IS_ERR(erp_fn(cqr)))
2808 continue;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002809 goto restart;
2810 }
2811
Stefan Haberlanda9cffb22008-11-14 18:18:08 +01002812 /* log sense for fatal error */
2813 if (cqr->status == DASD_CQR_FAILED) {
2814 dasd_log_sense(cqr, &cqr->irb);
2815 }
2816
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002817 /* First of all call extended error reporting. */
2818 if (dasd_eer_enabled(base) &&
2819 cqr->status == DASD_CQR_FAILED) {
2820 dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
2821
2822 /* restart request */
2823 cqr->status = DASD_CQR_FILLED;
2824 cqr->retries = 255;
2825 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002826 dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002827 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
2828 flags);
2829 goto restart;
2830 }
2831
2832 /* Process finished ERP request. */
2833 if (cqr->refers) {
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01002834 __dasd_process_erp(base, cqr);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002835 goto restart;
2836 }
2837
2838 /* Rechain finished requests to final queue */
Heiko Carstens1aae0562013-01-30 09:49:40 +01002839 cqr->endclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002840 list_move_tail(&cqr->blocklist, final_queue);
2841 }
2842}
2843
2844static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
2845{
2846 dasd_schedule_block_bh(cqr->block);
2847}
2848
2849static void __dasd_block_start_head(struct dasd_block *block)
2850{
2851 struct dasd_ccw_req *cqr;
2852
2853 if (list_empty(&block->ccw_queue))
2854 return;
2855 /* We allways begin with the first requests on the queue, as some
2856 * of previously started requests have to be enqueued on a
2857 * dasd_device again for error recovery.
2858 */
2859 list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
2860 if (cqr->status != DASD_CQR_FILLED)
2861 continue;
Stefan Weinhuber5a27e602011-01-05 12:48:04 +01002862 if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) &&
2863 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2864 cqr->status = DASD_CQR_FAILED;
2865 cqr->intrc = -EPERM;
2866 dasd_schedule_block_bh(block);
2867 continue;
2868 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002869 /* Non-temporary stop condition will trigger fail fast */
2870 if (block->base->stopped & ~DASD_STOPPED_PENDING &&
2871 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2872 (!dasd_eer_enabled(block->base))) {
2873 cqr->status = DASD_CQR_FAILED;
Hannes Reinecked1ffc1f2013-01-30 09:26:16 +00002874 cqr->intrc = -ENOLINK;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002875 dasd_schedule_block_bh(block);
2876 continue;
2877 }
2878 /* Don't try to start requests if device is stopped */
2879 if (block->base->stopped)
2880 return;
2881
2882 /* just a fail safe check, should not happen */
2883 if (!cqr->startdev)
2884 cqr->startdev = block->base;
2885
2886 /* make sure that the requests we submit find their way back */
2887 cqr->callback = dasd_return_cqr_cb;
2888
2889 dasd_add_request_tail(cqr);
2890 }
2891}
2892
2893/*
2894 * Central dasd_block layer routine. Takes requests from the generic
2895 * block layer request queue, creates ccw requests, enqueues them on
2896 * a dasd_device and processes ccw requests that have been returned.
2897 */
Sebastian Ottd2f2df62018-07-03 13:06:45 +02002898static void dasd_block_tasklet(unsigned long data)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002899{
Sebastian Ottd2f2df62018-07-03 13:06:45 +02002900 struct dasd_block *block = (struct dasd_block *) data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002901 struct list_head final_queue;
2902 struct list_head *l, *n;
2903 struct dasd_ccw_req *cqr;
Stefan Haberlande4433432017-05-22 10:59:11 +02002904 struct dasd_queue *dq;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002905
2906 atomic_set(&block->tasklet_scheduled, 0);
2907 INIT_LIST_HEAD(&final_queue);
Stefan Haberlande4433432017-05-22 10:59:11 +02002908 spin_lock_irq(&block->queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002909 /* Finish off requests on ccw queue */
2910 __dasd_process_block_ccw_queue(block, &final_queue);
Stefan Haberlande4433432017-05-22 10:59:11 +02002911 spin_unlock_irq(&block->queue_lock);
2912
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002913 /* Now call the callback function of requests with final status */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002914 list_for_each_safe(l, n, &final_queue) {
2915 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
Stefan Haberlande4433432017-05-22 10:59:11 +02002916 dq = cqr->dq;
2917 spin_lock_irq(&dq->lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002918 list_del_init(&cqr->blocklist);
2919 __dasd_cleanup_cqr(cqr);
Stefan Haberlande4433432017-05-22 10:59:11 +02002920 spin_unlock_irq(&dq->lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002921 }
Stefan Haberlande4433432017-05-22 10:59:11 +02002922
2923 spin_lock_irq(&block->queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002924 /* Now check if the head of the ccw queue needs to be started. */
2925 __dasd_block_start_head(block);
Stefan Haberlande4433432017-05-22 10:59:11 +02002926 spin_unlock_irq(&block->queue_lock);
2927
Stefan Haberland4679e892012-06-19 17:30:12 +02002928 if (waitqueue_active(&shutdown_waitq))
2929 wake_up(&shutdown_waitq);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002930 dasd_put_device(block->base);
2931}
2932
2933static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
2934{
2935 wake_up(&dasd_flush_wq);
2936}
2937
2938/*
Stefan Haberlandc5576872013-04-15 16:41:31 +02002939 * Requeue a request back to the block request queue
2940 * only works for block requests
2941 */
2942static int _dasd_requeue_request(struct dasd_ccw_req *cqr)
2943{
2944 struct dasd_block *block = cqr->block;
2945 struct request *req;
Stefan Haberlandc5576872013-04-15 16:41:31 +02002946
2947 if (!block)
2948 return -EINVAL;
Stefan Haberland6f117cb2020-11-16 16:23:47 +01002949 /*
2950 * If the request is an ERP request there is nothing to requeue.
2951 * This will be done with the remaining original request.
2952 */
2953 if (cqr->refers)
2954 return 0;
Stefan Haberlande4433432017-05-22 10:59:11 +02002955 spin_lock_irq(&cqr->dq->lock);
Stefan Haberlandc5576872013-04-15 16:41:31 +02002956 req = (struct request *) cqr->callback_data;
Stefan Haberlande4433432017-05-22 10:59:11 +02002957 blk_mq_requeue_request(req, false);
2958 spin_unlock_irq(&cqr->dq->lock);
Stefan Haberlandc5576872013-04-15 16:41:31 +02002959
2960 return 0;
2961}
2962
2963/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002964 * Go through all request on the dasd_block request queue, cancel them
2965 * on the respective dasd_device, and return them to the generic
2966 * block layer.
2967 */
2968static int dasd_flush_block_queue(struct dasd_block *block)
2969{
2970 struct dasd_ccw_req *cqr, *n;
2971 int rc, i;
2972 struct list_head flush_queue;
Stefan Haberlande4433432017-05-22 10:59:11 +02002973 unsigned long flags;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01002974
2975 INIT_LIST_HEAD(&flush_queue);
2976 spin_lock_bh(&block->queue_lock);
2977 rc = 0;
2978restart:
2979 list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
2980 /* if this request currently owned by a dasd_device cancel it */
2981 if (cqr->status >= DASD_CQR_QUEUED)
2982 rc = dasd_cancel_req(cqr);
2983 if (rc < 0)
2984 break;
2985 /* Rechain request (including erp chain) so it won't be
2986 * touched by the dasd_block_tasklet anymore.
2987 * Replace the callback so we notice when the request
2988 * is returned from the dasd_device layer.
2989 */
2990 cqr->callback = _dasd_wake_block_flush_cb;
2991 for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
2992 list_move_tail(&cqr->blocklist, &flush_queue);
2993 if (i > 1)
2994 /* moved more than one request - need to restart */
2995 goto restart;
2996 }
2997 spin_unlock_bh(&block->queue_lock);
2998 /* Now call the callback function of flushed requests */
2999restart_cb:
3000 list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
3001 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
3002 /* Process finished ERP request. */
3003 if (cqr->refers) {
Stefan Haberland0cd4bd42008-12-25 13:38:54 +01003004 spin_lock_bh(&block->queue_lock);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01003005 __dasd_process_erp(block->base, cqr);
Stefan Haberland0cd4bd42008-12-25 13:38:54 +01003006 spin_unlock_bh(&block->queue_lock);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003007 /* restart list_for_xx loop since dasd_process_erp
3008 * might remove multiple elements */
3009 goto restart_cb;
3010 }
3011 /* call the callback function */
Stefan Haberlande4433432017-05-22 10:59:11 +02003012 spin_lock_irqsave(&cqr->dq->lock, flags);
Heiko Carstens1aae0562013-01-30 09:49:40 +01003013 cqr->endclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003014 list_del_init(&cqr->blocklist);
3015 __dasd_cleanup_cqr(cqr);
Stefan Haberlande4433432017-05-22 10:59:11 +02003016 spin_unlock_irqrestore(&cqr->dq->lock, flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003017 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 return rc;
3019}
3020
3021/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003022 * Schedules a call to dasd_tasklet over the device tasklet.
3023 */
3024void dasd_schedule_block_bh(struct dasd_block *block)
3025{
3026 /* Protect against rescheduling. */
3027 if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
3028 return;
3029 /* life cycle of block is bound to it's base device */
3030 dasd_get_device(block->base);
3031 tasklet_hi_schedule(&block->tasklet);
3032}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003033EXPORT_SYMBOL(dasd_schedule_block_bh);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003034
3035
3036/*
3037 * SECTION: external block device operations
3038 * (request queue handling, open, release, etc.)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 */
3040
3041/*
3042 * Dasd request queue function. Called from ll_rw_blk.c
3043 */
Stefan Haberlande4433432017-05-22 10:59:11 +02003044static blk_status_t do_dasd_request(struct blk_mq_hw_ctx *hctx,
3045 const struct blk_mq_queue_data *qd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046{
Stefan Haberlande4433432017-05-22 10:59:11 +02003047 struct dasd_block *block = hctx->queue->queuedata;
3048 struct dasd_queue *dq = hctx->driver_data;
3049 struct request *req = qd->rq;
3050 struct dasd_device *basedev;
3051 struct dasd_ccw_req *cqr;
3052 blk_status_t rc = BLK_STS_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053
Stefan Haberlande4433432017-05-22 10:59:11 +02003054 basedev = block->base;
3055 spin_lock_irq(&dq->lock);
Stefan Haberland66f669a2021-03-05 13:54:39 +01003056 if (basedev->state < DASD_STATE_READY ||
3057 test_bit(DASD_FLAG_OFFLINE, &basedev->flags)) {
Stefan Haberlande4433432017-05-22 10:59:11 +02003058 DBF_DEV_EVENT(DBF_ERR, basedev,
3059 "device not ready for request %p", req);
3060 rc = BLK_STS_IOERR;
3061 goto out;
3062 }
3063
3064 /*
3065 * if device is stopped do not fetch new requests
3066 * except failfast is active which will let requests fail
3067 * immediately in __dasd_block_start_head()
3068 */
3069 if (basedev->stopped && !(basedev->features & DASD_FEATURE_FAILFAST)) {
3070 DBF_DEV_EVENT(DBF_ERR, basedev,
3071 "device stopped request %p", req);
3072 rc = BLK_STS_RESOURCE;
3073 goto out;
3074 }
3075
3076 if (basedev->features & DASD_FEATURE_READONLY &&
3077 rq_data_dir(req) == WRITE) {
3078 DBF_DEV_EVENT(DBF_ERR, basedev,
3079 "Rejecting write request %p", req);
3080 rc = BLK_STS_IOERR;
3081 goto out;
3082 }
3083
3084 if (test_bit(DASD_FLAG_ABORTALL, &basedev->flags) &&
3085 (basedev->features & DASD_FEATURE_FAILFAST ||
3086 blk_noretry_request(req))) {
3087 DBF_DEV_EVENT(DBF_ERR, basedev,
3088 "Rejecting failfast request %p", req);
3089 rc = BLK_STS_IOERR;
3090 goto out;
3091 }
3092
3093 cqr = basedev->discipline->build_cp(basedev, block, req);
3094 if (IS_ERR(cqr)) {
3095 if (PTR_ERR(cqr) == -EBUSY ||
3096 PTR_ERR(cqr) == -ENOMEM ||
3097 PTR_ERR(cqr) == -EAGAIN) {
3098 rc = BLK_STS_RESOURCE;
3099 goto out;
3100 }
3101 DBF_DEV_EVENT(DBF_ERR, basedev,
3102 "CCW creation failed (rc=%ld) on request %p",
3103 PTR_ERR(cqr), req);
3104 rc = BLK_STS_IOERR;
3105 goto out;
3106 }
3107 /*
3108 * Note: callback is set to dasd_return_cqr_cb in
3109 * __dasd_block_start_head to cover erp requests as well
3110 */
3111 cqr->callback_data = req;
3112 cqr->status = DASD_CQR_FILLED;
3113 cqr->dq = dq;
Sebastian Ottf0f59a22018-05-15 14:05:13 +02003114
Stefan Haberlande4433432017-05-22 10:59:11 +02003115 blk_mq_start_request(req);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003116 spin_lock(&block->queue_lock);
Stefan Haberlande4433432017-05-22 10:59:11 +02003117 list_add_tail(&cqr->blocklist, &block->ccw_queue);
3118 INIT_LIST_HEAD(&cqr->devlist);
3119 dasd_profile_start(block, cqr, req);
3120 dasd_schedule_block_bh(block);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003121 spin_unlock(&block->queue_lock);
Stefan Haberlande4433432017-05-22 10:59:11 +02003122
3123out:
3124 spin_unlock_irq(&dq->lock);
3125 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126}
3127
3128/*
Hannes Reineckea2ace462013-01-30 09:26:14 +00003129 * Block timeout callback, called from the block layer
3130 *
Hannes Reineckea2ace462013-01-30 09:26:14 +00003131 * Return values:
3132 * BLK_EH_RESET_TIMER if the request should be left running
Christoph Hellwig66005932018-05-29 15:52:29 +02003133 * BLK_EH_DONE if the request is handled or terminated
Hannes Reineckea2ace462013-01-30 09:26:14 +00003134 * by the driver.
3135 */
Stefan Haberlande4433432017-05-22 10:59:11 +02003136enum blk_eh_timer_return dasd_times_out(struct request *req, bool reserved)
Hannes Reineckea2ace462013-01-30 09:26:14 +00003137{
Hannes Reineckea2ace462013-01-30 09:26:14 +00003138 struct dasd_block *block = req->q->queuedata;
3139 struct dasd_device *device;
Sebastian Ottf0f59a22018-05-15 14:05:13 +02003140 struct dasd_ccw_req *cqr;
Stefan Haberlande4433432017-05-22 10:59:11 +02003141 unsigned long flags;
Hannes Reineckea2ace462013-01-30 09:26:14 +00003142 int rc = 0;
3143
Sebastian Ottc5205f22018-06-04 19:07:39 +02003144 cqr = blk_mq_rq_to_pdu(req);
Hannes Reineckea2ace462013-01-30 09:26:14 +00003145 if (!cqr)
Christoph Hellwig66005932018-05-29 15:52:29 +02003146 return BLK_EH_DONE;
Hannes Reineckea2ace462013-01-30 09:26:14 +00003147
Stefan Haberlande4433432017-05-22 10:59:11 +02003148 spin_lock_irqsave(&cqr->dq->lock, flags);
Hannes Reineckea2ace462013-01-30 09:26:14 +00003149 device = cqr->startdev ? cqr->startdev : block->base;
Stefan Haberlande4433432017-05-22 10:59:11 +02003150 if (!device->blk_timeout) {
3151 spin_unlock_irqrestore(&cqr->dq->lock, flags);
Hannes Reinecke3d71ad32013-01-30 09:26:18 +00003152 return BLK_EH_RESET_TIMER;
Stefan Haberlande4433432017-05-22 10:59:11 +02003153 }
Hannes Reineckea2ace462013-01-30 09:26:14 +00003154 DBF_DEV_EVENT(DBF_WARNING, device,
3155 " dasd_times_out cqr %p status %x",
3156 cqr, cqr->status);
3157
3158 spin_lock(&block->queue_lock);
3159 spin_lock(get_ccwdev_lock(device->cdev));
3160 cqr->retries = -1;
3161 cqr->intrc = -ETIMEDOUT;
3162 if (cqr->status >= DASD_CQR_QUEUED) {
Sebastian Ott1bcdb532018-05-16 11:25:21 +02003163 rc = __dasd_cancel_req(cqr);
Hannes Reineckea2ace462013-01-30 09:26:14 +00003164 } else if (cqr->status == DASD_CQR_FILLED ||
3165 cqr->status == DASD_CQR_NEED_ERP) {
3166 cqr->status = DASD_CQR_TERMINATED;
Hannes Reineckea2ace462013-01-30 09:26:14 +00003167 } else if (cqr->status == DASD_CQR_IN_ERP) {
3168 struct dasd_ccw_req *searchcqr, *nextcqr, *tmpcqr;
3169
3170 list_for_each_entry_safe(searchcqr, nextcqr,
3171 &block->ccw_queue, blocklist) {
3172 tmpcqr = searchcqr;
3173 while (tmpcqr->refers)
3174 tmpcqr = tmpcqr->refers;
3175 if (tmpcqr != cqr)
3176 continue;
3177 /* searchcqr is an ERP request for cqr */
3178 searchcqr->retries = -1;
3179 searchcqr->intrc = -ETIMEDOUT;
3180 if (searchcqr->status >= DASD_CQR_QUEUED) {
Sebastian Ott1bcdb532018-05-16 11:25:21 +02003181 rc = __dasd_cancel_req(searchcqr);
Hannes Reineckea2ace462013-01-30 09:26:14 +00003182 } else if ((searchcqr->status == DASD_CQR_FILLED) ||
3183 (searchcqr->status == DASD_CQR_NEED_ERP)) {
3184 searchcqr->status = DASD_CQR_TERMINATED;
3185 rc = 0;
3186 } else if (searchcqr->status == DASD_CQR_IN_ERP) {
3187 /*
3188 * Shouldn't happen; most recent ERP
3189 * request is at the front of queue
3190 */
3191 continue;
3192 }
3193 break;
3194 }
Hannes Reineckea2ace462013-01-30 09:26:14 +00003195 }
Sebastian Ott1bcdb532018-05-16 11:25:21 +02003196 spin_unlock(get_ccwdev_lock(device->cdev));
Hannes Reineckea2ace462013-01-30 09:26:14 +00003197 dasd_schedule_block_bh(block);
3198 spin_unlock(&block->queue_lock);
Stefan Haberlande4433432017-05-22 10:59:11 +02003199 spin_unlock_irqrestore(&cqr->dq->lock, flags);
Hannes Reineckea2ace462013-01-30 09:26:14 +00003200
Christoph Hellwig66005932018-05-29 15:52:29 +02003201 return rc ? BLK_EH_RESET_TIMER : BLK_EH_DONE;
Hannes Reineckea2ace462013-01-30 09:26:14 +00003202}
3203
Stefan Haberlande4433432017-05-22 10:59:11 +02003204static int dasd_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
3205 unsigned int idx)
3206{
3207 struct dasd_queue *dq = kzalloc(sizeof(*dq), GFP_KERNEL);
3208
3209 if (!dq)
3210 return -ENOMEM;
3211
3212 spin_lock_init(&dq->lock);
3213 hctx->driver_data = dq;
3214
3215 return 0;
3216}
3217
3218static void dasd_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int idx)
3219{
3220 kfree(hctx->driver_data);
3221 hctx->driver_data = NULL;
3222}
3223
3224static void dasd_request_done(struct request *req)
3225{
3226 blk_mq_end_request(req, 0);
3227 blk_mq_run_hw_queues(req->q, true);
3228}
3229
3230static struct blk_mq_ops dasd_mq_ops = {
3231 .queue_rq = do_dasd_request,
3232 .complete = dasd_request_done,
3233 .timeout = dasd_times_out,
3234 .init_hctx = dasd_init_hctx,
3235 .exit_hctx = dasd_exit_hctx,
3236};
3237
Hannes Reineckea2ace462013-01-30 09:26:14 +00003238/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 * Allocate and initialize request queue and default I/O scheduler.
3240 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003241static int dasd_alloc_queue(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242{
Stefan Haberlande4433432017-05-22 10:59:11 +02003243 int rc;
3244
3245 block->tag_set.ops = &dasd_mq_ops;
Sebastian Ottc5205f22018-06-04 19:07:39 +02003246 block->tag_set.cmd_size = sizeof(struct dasd_ccw_req);
Stefan Haberland3284da32018-06-12 16:47:10 +02003247 block->tag_set.nr_hw_queues = nr_hw_queues;
3248 block->tag_set.queue_depth = queue_depth;
Stefan Haberlande4433432017-05-22 10:59:11 +02003249 block->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
Vasily Gorbikb17e3ab2018-06-24 09:21:59 +02003250 block->tag_set.numa_node = NUMA_NO_NODE;
Stefan Haberlande4433432017-05-22 10:59:11 +02003251
3252 rc = blk_mq_alloc_tag_set(&block->tag_set);
3253 if (rc)
3254 return rc;
3255
3256 block->request_queue = blk_mq_init_queue(&block->tag_set);
3257 if (IS_ERR(block->request_queue))
3258 return PTR_ERR(block->request_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003260 block->request_queue->queuedata = block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261
Stefan Haberlanda5fd8dd2015-03-04 14:29:47 +01003262 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263}
3264
3265/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 * Deactivate and free request queue.
3267 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003268static void dasd_free_queue(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003270 if (block->request_queue) {
3271 blk_cleanup_queue(block->request_queue);
Stefan Haberlande4433432017-05-22 10:59:11 +02003272 blk_mq_free_tag_set(&block->tag_set);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003273 block->request_queue = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 }
3275}
3276
Al Viro57a7c0b2008-03-02 10:36:08 -05003277static int dasd_open(struct block_device *bdev, fmode_t mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278{
Stefan Haberland9eb25122010-02-26 22:37:46 +01003279 struct dasd_device *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 int rc;
3281
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003282 base = dasd_device_from_gendisk(bdev->bd_disk);
3283 if (!base)
Stefan Haberland9eb25122010-02-26 22:37:46 +01003284 return -ENODEV;
3285
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003286 atomic_inc(&base->block->open_count);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003287 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 rc = -ENODEV;
3289 goto unlock;
3290 }
3291
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003292 if (!try_module_get(base->discipline->owner)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 rc = -EINVAL;
3294 goto unlock;
3295 }
3296
3297 if (dasd_probeonly) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01003298 dev_info(&base->cdev->dev,
3299 "Accessing the DASD failed because it is in "
3300 "probeonly mode\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 rc = -EPERM;
3302 goto out;
3303 }
3304
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003305 if (base->state <= DASD_STATE_BASIC) {
3306 DBF_DEV_EVENT(DBF_ERR, base, " %s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 " Cannot open unrecognized device");
3308 rc = -ENODEV;
3309 goto out;
3310 }
3311
Stefan Weinhuber33b62a32010-03-08 12:26:24 +01003312 if ((mode & FMODE_WRITE) &&
3313 (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) ||
3314 (base->features & DASD_FEATURE_READONLY))) {
3315 rc = -EROFS;
3316 goto out;
3317 }
3318
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003319 dasd_put_device(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 return 0;
3321
3322out:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003323 module_put(base->discipline->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324unlock:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003325 atomic_dec(&base->block->open_count);
3326 dasd_put_device(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 return rc;
3328}
3329
Al Virodb2a1442013-05-05 21:52:57 -04003330static void dasd_release(struct gendisk *disk, fmode_t mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331{
Al Virodb2a1442013-05-05 21:52:57 -04003332 struct dasd_device *base = dasd_device_from_gendisk(disk);
3333 if (base) {
3334 atomic_dec(&base->block->open_count);
3335 module_put(base->discipline->owner);
3336 dasd_put_device(base);
3337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338}
3339
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003340/*
3341 * Return disk geometry.
3342 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003343static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003344{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003345 struct dasd_device *base;
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003346
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003347 base = dasd_device_from_gendisk(bdev->bd_disk);
3348 if (!base)
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003349 return -ENODEV;
3350
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003351 if (!base->discipline ||
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003352 !base->discipline->fill_geometry) {
3353 dasd_put_device(base);
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003354 return -EINVAL;
Stefan Weinhuber65f8da42011-04-20 10:15:30 +02003355 }
3356 base->discipline->fill_geometry(base->block, geo);
3357 geo->start = get_start_sect(bdev) >> base->block->s2b_shift;
3358 dasd_put_device(base);
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003359 return 0;
3360}
3361
Alexey Dobriyan83d5cde2009-09-21 17:01:13 -07003362const struct block_device_operations
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363dasd_device_operations = {
3364 .owner = THIS_MODULE,
Al Viro57a7c0b2008-03-02 10:36:08 -05003365 .open = dasd_open,
3366 .release = dasd_release,
Heiko Carstens0000d032009-03-26 15:23:45 +01003367 .ioctl = dasd_ioctl,
3368 .compat_ioctl = dasd_ioctl,
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08003369 .getgeo = dasd_getgeo,
Christoph Hellwig2c1b6ec2020-11-03 11:00:14 +01003370 .set_read_only = dasd_set_read_only,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371};
3372
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003373/*******************************************************************************
3374 * end of block device operations
3375 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376
3377static void
3378dasd_exit(void)
3379{
3380#ifdef CONFIG_PROC_FS
3381 dasd_proc_exit();
3382#endif
Stefan Weinhuber20c64462006-03-24 03:15:25 -08003383 dasd_eer_exit();
Chengguang Xu734781a2018-08-28 07:51:30 +08003384 kmem_cache_destroy(dasd_page_cache);
3385 dasd_page_cache = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 dasd_gendisk_exit();
3387 dasd_devmap_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 if (dasd_debug_area != NULL) {
3389 debug_unregister(dasd_debug_area);
3390 dasd_debug_area = NULL;
3391 }
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02003392 dasd_statistics_removeroot();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393}
3394
3395/*
3396 * SECTION: common functions for ccw_driver use
3397 */
3398
Stefan Weinhuber33b62a32010-03-08 12:26:24 +01003399/*
3400 * Is the device read-only?
3401 * Note that this function does not report the setting of the
3402 * readonly device attribute, but how it is configured in z/VM.
3403 */
3404int dasd_device_is_ro(struct dasd_device *device)
3405{
3406 struct ccw_dev_id dev_id;
3407 struct diag210 diag_data;
3408 int rc;
3409
3410 if (!MACHINE_IS_VM)
3411 return 0;
3412 ccw_device_get_id(device->cdev, &dev_id);
3413 memset(&diag_data, 0, sizeof(diag_data));
3414 diag_data.vrdcdvno = dev_id.devno;
3415 diag_data.vrdclen = sizeof(diag_data);
3416 rc = diag210(&diag_data);
3417 if (rc == 0 || rc == 2) {
3418 return diag_data.vrdcvfla & 0x80;
3419 } else {
3420 DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d",
3421 dev_id.devno, rc);
3422 return 0;
3423 }
3424}
3425EXPORT_SYMBOL_GPL(dasd_device_is_ro);
3426
Cornelia Huckf3445a12009-04-14 15:36:23 +02003427static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
3428{
3429 struct ccw_device *cdev = data;
3430 int ret;
3431
3432 ret = ccw_device_set_online(cdev);
3433 if (ret)
Fabian Frederick4ce25962014-06-26 19:41:48 +02003434 pr_warn("%s: Setting the DASD online failed with rc=%d\n",
3435 dev_name(&cdev->dev), ret);
Cornelia Huckf3445a12009-04-14 15:36:23 +02003436}
3437
Horst Hummel1c01b8a2006-01-06 00:19:15 -08003438/*
3439 * Initial attempt at a probe function. this can be simplified once
3440 * the other detection code is gone.
3441 */
Jan Höppnere03c5942020-10-08 15:13:30 +02003442int dasd_generic_probe(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443{
Horst Hummel40545572006-06-29 15:08:18 +02003444 cdev->handler = &dasd_int_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445
Horst Hummel40545572006-06-29 15:08:18 +02003446 /*
3447 * Automatically online either all dasd devices (dasd_autodetect)
3448 * or all devices specified with dasd= parameters during
3449 * initial probe.
3450 */
3451 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
Kay Sievers2a0217d2008-10-10 21:33:09 +02003452 (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
Cornelia Huckf3445a12009-04-14 15:36:23 +02003453 async_schedule(dasd_generic_auto_online, cdev);
Stefan Haberlandde3e0da2008-01-26 14:11:08 +01003454 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003456EXPORT_SYMBOL_GPL(dasd_generic_probe);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457
Stefan Haberlandc020d722016-09-20 10:42:38 +02003458void dasd_generic_free_discipline(struct dasd_device *device)
3459{
3460 /* Forget the discipline information. */
3461 if (device->discipline) {
3462 if (device->discipline->uncheck_device)
3463 device->discipline->uncheck_device(device);
3464 module_put(device->discipline->owner);
3465 device->discipline = NULL;
3466 }
3467 if (device->base_discipline) {
3468 module_put(device->base_discipline->owner);
3469 device->base_discipline = NULL;
3470 }
3471}
3472EXPORT_SYMBOL_GPL(dasd_generic_free_discipline);
3473
Horst Hummel1c01b8a2006-01-06 00:19:15 -08003474/*
3475 * This will one day be called from a global not_oper handler.
3476 * It is also used by driver_unregister during module unload.
3477 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003478void dasd_generic_remove(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479{
3480 struct dasd_device *device;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003481 struct dasd_block *block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 device = dasd_device_from_cdev(cdev);
Julian Wiedmann1987c552021-03-16 10:45:13 +01003484 if (IS_ERR(device))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 return;
Julian Wiedmann1987c552021-03-16 10:45:13 +01003486
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003487 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3488 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 /* Already doing offline processing */
3490 dasd_put_device(device);
3491 return;
3492 }
3493 /*
3494 * This device is removed unconditionally. Set offline
3495 * flag to prevent dasd_open from opening it while it is
3496 * no quite down yet.
3497 */
3498 dasd_set_target_state(device, DASD_STATE_NEW);
Stefan Haberland7d365bd2021-03-05 13:54:38 +01003499 cdev->handler = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 /* dasd_delete_device destroys the device reference. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003501 block = device->block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502 dasd_delete_device(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003503 /*
3504 * life cycle of block is bound to device, so delete it after
3505 * device was safely removed
3506 */
3507 if (block)
3508 dasd_free_block(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003510EXPORT_SYMBOL_GPL(dasd_generic_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511
Horst Hummel1c01b8a2006-01-06 00:19:15 -08003512/*
3513 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 * the device is detected for the first time and is supposed to be used
Horst Hummel1c01b8a2006-01-06 00:19:15 -08003515 * or the user has started activation through sysfs.
3516 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003517int dasd_generic_set_online(struct ccw_device *cdev,
3518 struct dasd_discipline *base_discipline)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519{
Peter Oberparleiteraa888612006-02-20 18:28:13 -08003520 struct dasd_discipline *discipline;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 struct dasd_device *device;
Horst Hummelc6eb7b72005-09-03 15:57:58 -07003522 int rc;
Horst Hummelf24acd42005-05-01 08:58:59 -07003523
Horst Hummel40545572006-06-29 15:08:18 +02003524 /* first online clears initial online feature flag */
3525 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 device = dasd_create_device(cdev);
3527 if (IS_ERR(device))
3528 return PTR_ERR(device);
3529
Peter Oberparleiteraa888612006-02-20 18:28:13 -08003530 discipline = base_discipline;
Horst Hummelc6eb7b72005-09-03 15:57:58 -07003531 if (device->features & DASD_FEATURE_USEDIAG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 if (!dasd_diag_discipline_pointer) {
Peter Oberparleiter7c53fcb2015-05-11 13:08:05 +02003533 /* Try to load the required module. */
3534 rc = request_module(DASD_DIAG_MOD);
3535 if (rc) {
3536 pr_warn("%s Setting the DASD online failed "
3537 "because the required module %s "
3538 "could not be loaded (rc=%d)\n",
3539 dev_name(&cdev->dev), DASD_DIAG_MOD,
3540 rc);
3541 dasd_delete_device(device);
3542 return -ENODEV;
3543 }
3544 }
3545 /* Module init could have failed, so check again here after
3546 * request_module(). */
3547 if (!dasd_diag_discipline_pointer) {
Fabian Frederick4ce25962014-06-26 19:41:48 +02003548 pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n",
3549 dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 dasd_delete_device(device);
3551 return -ENODEV;
3552 }
3553 discipline = dasd_diag_discipline_pointer;
3554 }
Peter Oberparleiteraa888612006-02-20 18:28:13 -08003555 if (!try_module_get(base_discipline->owner)) {
3556 dasd_delete_device(device);
3557 return -EINVAL;
3558 }
3559 if (!try_module_get(discipline->owner)) {
3560 module_put(base_discipline->owner);
3561 dasd_delete_device(device);
3562 return -EINVAL;
3563 }
3564 device->base_discipline = base_discipline;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565 device->discipline = discipline;
3566
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003567 /* check_device will allocate block device if necessary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568 rc = discipline->check_device(device);
3569 if (rc) {
Fabian Frederick4ce25962014-06-26 19:41:48 +02003570 pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
3571 dev_name(&cdev->dev), discipline->name, rc);
Peter Oberparleiteraa888612006-02-20 18:28:13 -08003572 module_put(discipline->owner);
3573 module_put(base_discipline->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 dasd_delete_device(device);
3575 return rc;
3576 }
3577
3578 dasd_set_target_state(device, DASD_STATE_ONLINE);
3579 if (device->state <= DASD_STATE_KNOWN) {
Fabian Frederick4ce25962014-06-26 19:41:48 +02003580 pr_warn("%s Setting the DASD online failed because of a missing discipline\n",
3581 dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582 rc = -ENODEV;
3583 dasd_set_target_state(device, DASD_STATE_NEW);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003584 if (device->block)
3585 dasd_free_block(device->block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586 dasd_delete_device(device);
3587 } else
3588 pr_debug("dasd_generic device %s found\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +02003589 dev_name(&cdev->dev));
Stefan Haberland589c74d2010-02-26 22:37:47 +01003590
3591 wait_event(dasd_init_waitq, _wait_for_device(device));
3592
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 dasd_put_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594 return rc;
3595}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003596EXPORT_SYMBOL_GPL(dasd_generic_set_online);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003598int dasd_generic_set_offline(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599{
3600 struct dasd_device *device;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003601 struct dasd_block *block;
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003602 int max_count, open_count, rc;
Jan Höppner0f57c972016-10-18 17:54:49 +02003603 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003605 rc = 0;
Jan Höppner0f57c972016-10-18 17:54:49 +02003606 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3607 device = dasd_device_from_cdev_locked(cdev);
3608 if (IS_ERR(device)) {
3609 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 return PTR_ERR(device);
Jan Höppner0f57c972016-10-18 17:54:49 +02003611 }
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003612
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 /*
3614 * We must make sure that this device is currently not in use.
3615 * The open_count is increased for every opener, that includes
3616 * the blkdev_get in dasd_scan_partitions. We are only interested
3617 * in the other openers.
3618 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003619 if (device->block) {
Heiko Carstensa8061702008-04-17 07:46:26 +02003620 max_count = device->block->bdev ? 0 : -1;
3621 open_count = atomic_read(&device->block->open_count);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003622 if (open_count > max_count) {
3623 if (open_count > 0)
Fabian Frederick4ce25962014-06-26 19:41:48 +02003624 pr_warn("%s: The DASD cannot be set offline with open count %i\n",
3625 dev_name(&cdev->dev), open_count);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003626 else
Fabian Frederick4ce25962014-06-26 19:41:48 +02003627 pr_warn("%s: The DASD cannot be set offline while it is in use\n",
3628 dev_name(&cdev->dev));
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003629 rc = -EBUSY;
3630 goto out_err;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003631 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 }
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003633
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003634 /*
3635 * Test if the offline processing is already running and exit if so.
3636 * If a safe offline is being processed this could only be a normal
3637 * offline that should be able to overtake the safe offline and
3638 * cancel any I/O we do not want to wait for any longer
3639 */
3640 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3641 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3642 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING,
3643 &device->flags);
3644 } else {
3645 rc = -EBUSY;
3646 goto out_err;
3647 }
Jan Höppner0f57c972016-10-18 17:54:49 +02003648 }
Jan Höppner0f57c972016-10-18 17:54:49 +02003649 set_bit(DASD_FLAG_OFFLINE, &device->flags);
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003650
3651 /*
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003652 * if safe_offline is called set safe_offline_running flag and
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003653 * clear safe_offline so that a call to normal offline
3654 * can overrun safe_offline processing
3655 */
3656 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
3657 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003658 /* need to unlock here to wait for outstanding I/O */
3659 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003660 /*
3661 * If we want to set the device safe offline all IO operations
3662 * should be finished before continuing the offline process
3663 * so sync bdev first and then wait for our queues to become
3664 * empty
3665 */
Stefan Haberlandca732e12017-01-25 16:56:41 +01003666 if (device->block) {
3667 rc = fsync_bdev(device->block->bdev);
3668 if (rc != 0)
3669 goto interrupted;
3670 }
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003671 dasd_schedule_device_bh(device);
3672 rc = wait_event_interruptible(shutdown_waitq,
3673 _wait_for_empty_queues(device));
3674 if (rc != 0)
3675 goto interrupted;
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003676
3677 /*
3678 * check if a normal offline process overtook the offline
3679 * processing in this case simply do nothing beside returning
3680 * that we got interrupted
3681 * otherwise mark safe offline as not running any longer and
3682 * continue with normal offline
3683 */
3684 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3685 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3686 rc = -ERESTARTSYS;
3687 goto out_err;
3688 }
3689 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003690 }
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003691 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003692
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 dasd_set_target_state(device, DASD_STATE_NEW);
3694 /* dasd_delete_device destroys the device reference. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003695 block = device->block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 dasd_delete_device(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003697 /*
3698 * life cycle of block is bound to device, so delete it after
3699 * device was safely removed
3700 */
3701 if (block)
3702 dasd_free_block(block);
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003703
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 return 0;
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003705
3706interrupted:
3707 /* interrupted by signal */
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003708 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
Stefan Haberlandd07dc5d2012-11-28 13:43:38 +01003709 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3710 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003711out_err:
Jan Höppner0f57c972016-10-18 17:54:49 +02003712 dasd_put_device(device);
3713 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
Stefan Haberland2757fe1d2017-05-16 10:30:13 +02003714 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003716EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003718int dasd_generic_last_path_gone(struct dasd_device *device)
3719{
3720 struct dasd_ccw_req *cqr;
3721
3722 dev_warn(&device->cdev->dev, "No operational channel path is left "
3723 "for the device\n");
3724 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
3725 /* First of all call extended error reporting. */
3726 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3727
3728 if (device->state < DASD_STATE_BASIC)
3729 return 0;
3730 /* Device is active. We want to keep it. */
3731 list_for_each_entry(cqr, &device->ccw_queue, devlist)
3732 if ((cqr->status == DASD_CQR_IN_IO) ||
3733 (cqr->status == DASD_CQR_CLEAR_PENDING)) {
3734 cqr->status = DASD_CQR_QUEUED;
3735 cqr->retries++;
3736 }
3737 dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
3738 dasd_device_clear_timer(device);
3739 dasd_schedule_device_bh(device);
3740 return 1;
3741}
3742EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone);
3743
3744int dasd_generic_path_operational(struct dasd_device *device)
3745{
3746 dev_info(&device->cdev->dev, "A channel path to the device has become "
3747 "operational\n");
3748 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
3749 dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003750 dasd_schedule_device_bh(device);
Stefan Haberlande4433432017-05-22 10:59:11 +02003751 if (device->block) {
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003752 dasd_schedule_block_bh(device->block);
Stefan Haberland673514a2017-09-12 17:22:42 +02003753 if (device->block->request_queue)
3754 blk_mq_run_hw_queues(device->block->request_queue,
3755 true);
Stefan Haberlande4433432017-05-22 10:59:11 +02003756 }
Stefan Haberland931a3dc2014-07-18 14:22:41 +02003757
3758 if (!device->stopped)
3759 wake_up(&generic_waitq);
3760
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003761 return 1;
3762}
3763EXPORT_SYMBOL_GPL(dasd_generic_path_operational);
3764
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01003765int dasd_generic_notify(struct ccw_device *cdev, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766{
3767 struct dasd_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 int ret;
3769
Peter Oberparleiter91c36912008-08-21 19:46:39 +02003770 device = dasd_device_from_cdev_locked(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 if (IS_ERR(device))
3772 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773 ret = 0;
3774 switch (event) {
3775 case CIO_GONE:
Sebastian Ott47593bf2009-03-31 19:16:05 +02003776 case CIO_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 case CIO_NO_PATH:
Stefan Haberlandc9346152016-08-08 15:53:54 +02003778 dasd_path_no_path(device);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003779 ret = dasd_generic_last_path_gone(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780 break;
3781 case CIO_OPER:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782 ret = 1;
Stefan Haberlandc9346152016-08-08 15:53:54 +02003783 if (dasd_path_get_opm(device))
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003784 ret = dasd_generic_path_operational(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 break;
3786 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787 dasd_put_device(device);
3788 return ret;
3789}
Fabian Frederick7048a2b2014-06-26 19:41:47 +02003790EXPORT_SYMBOL_GPL(dasd_generic_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003792void dasd_generic_path_event(struct ccw_device *cdev, int *path_event)
3793{
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003794 struct dasd_device *device;
Stefan Haberlanda521b042016-08-08 15:56:54 +02003795 int chp, oldopm, hpfpm, ifccpm;
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003796
3797 device = dasd_device_from_cdev_locked(cdev);
3798 if (IS_ERR(device))
3799 return;
Stefan Haberlandc9346152016-08-08 15:53:54 +02003800
3801 oldopm = dasd_path_get_opm(device);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003802 for (chp = 0; chp < 8; chp++) {
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003803 if (path_event[chp] & PE_PATH_GONE) {
Stefan Haberlandc9346152016-08-08 15:53:54 +02003804 dasd_path_notoper(device, chp);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003805 }
3806 if (path_event[chp] & PE_PATH_AVAILABLE) {
Stefan Haberlandc9346152016-08-08 15:53:54 +02003807 dasd_path_available(device, chp);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003808 dasd_schedule_device_bh(device);
3809 }
Stefan Haberlandf1633032012-01-18 18:03:41 +01003810 if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) {
Stefan Haberlandc9346152016-08-08 15:53:54 +02003811 if (!dasd_path_is_operational(device, chp) &&
3812 !dasd_path_need_verify(device, chp)) {
Stefan Haberland12d7b102012-09-11 15:10:58 +02003813 /*
3814 * we can not establish a pathgroup on an
3815 * unavailable path, so trigger a path
3816 * verification first
3817 */
Stefan Haberlandc9346152016-08-08 15:53:54 +02003818 dasd_path_available(device, chp);
3819 dasd_schedule_device_bh(device);
Stefan Haberland12d7b102012-09-11 15:10:58 +02003820 }
Stefan Haberlandf1633032012-01-18 18:03:41 +01003821 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3822 "Pathgroup re-established\n");
3823 if (device->discipline->kick_validate)
3824 device->discipline->kick_validate(device);
3825 }
Jan Höppner4d063e62020-10-08 15:13:36 +02003826 if (path_event[chp] & PE_PATH_FCES_EVENT) {
3827 dasd_path_fcsec_update(device, chp);
3828 dasd_schedule_device_bh(device);
3829 }
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003830 }
Stefan Haberlanda521b042016-08-08 15:56:54 +02003831 hpfpm = dasd_path_get_hpfpm(device);
3832 ifccpm = dasd_path_get_ifccpm(device);
3833 if (!dasd_path_get_opm(device) && hpfpm) {
3834 /*
3835 * device has no operational paths but at least one path is
3836 * disabled due to HPF errors
3837 * disable HPF at all and use the path(s) again
3838 */
3839 if (device->discipline->disable_hpf)
3840 device->discipline->disable_hpf(device);
3841 dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
3842 dasd_path_set_tbvpm(device, hpfpm);
3843 dasd_schedule_device_bh(device);
3844 dasd_schedule_requeue(device);
3845 } else if (!dasd_path_get_opm(device) && ifccpm) {
3846 /*
3847 * device has no operational paths but at least one path is
3848 * disabled due to IFCC errors
3849 * trigger path verification on paths with IFCC errors
3850 */
3851 dasd_path_set_tbvpm(device, ifccpm);
3852 dasd_schedule_device_bh(device);
3853 }
3854 if (oldopm && !dasd_path_get_opm(device) && !hpfpm && !ifccpm) {
Stefan Haberlandc9346152016-08-08 15:53:54 +02003855 dev_warn(&device->cdev->dev,
3856 "No verified channel paths remain for the device\n");
3857 DBF_DEV_EVENT(DBF_WARNING, device,
3858 "%s", "last verified path gone");
3859 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3860 dasd_device_set_stop_bits(device,
3861 DASD_STOPPED_DC_WAIT);
3862 }
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003863 dasd_put_device(device);
3864}
3865EXPORT_SYMBOL_GPL(dasd_generic_path_event);
3866
3867int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
3868{
Stefan Haberlandc9346152016-08-08 15:53:54 +02003869 if (!dasd_path_get_opm(device) && lpm) {
3870 dasd_path_set_opm(device, lpm);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003871 dasd_generic_path_operational(device);
3872 } else
Stefan Haberlandc9346152016-08-08 15:53:54 +02003873 dasd_path_add_opm(device, lpm);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01003874 return 0;
3875}
3876EXPORT_SYMBOL_GPL(dasd_generic_verify_path);
3877
Jan Höppner9e12e542018-07-03 10:56:51 +02003878void dasd_generic_space_exhaust(struct dasd_device *device,
3879 struct dasd_ccw_req *cqr)
3880{
3881 dasd_eer_write(device, NULL, DASD_EER_NOSPC);
3882
3883 if (device->state < DASD_STATE_BASIC)
3884 return;
3885
3886 if (cqr->status == DASD_CQR_IN_IO ||
3887 cqr->status == DASD_CQR_CLEAR_PENDING) {
3888 cqr->status = DASD_CQR_QUEUED;
3889 cqr->retries++;
3890 }
3891 dasd_device_set_stop_bits(device, DASD_STOPPED_NOSPC);
3892 dasd_device_clear_timer(device);
3893 dasd_schedule_device_bh(device);
3894}
3895EXPORT_SYMBOL_GPL(dasd_generic_space_exhaust);
3896
3897void dasd_generic_space_avail(struct dasd_device *device)
3898{
3899 dev_info(&device->cdev->dev, "Extent pool space is available\n");
3900 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "space available");
3901
3902 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOSPC);
3903 dasd_schedule_device_bh(device);
3904
3905 if (device->block) {
3906 dasd_schedule_block_bh(device->block);
3907 if (device->block->request_queue)
3908 blk_mq_run_hw_queues(device->block->request_queue, true);
3909 }
3910 if (!device->stopped)
3911 wake_up(&generic_waitq);
3912}
3913EXPORT_SYMBOL_GPL(dasd_generic_space_avail);
3914
Stefan Haberlanda521b042016-08-08 15:56:54 +02003915/*
3916 * clear active requests and requeue them to block layer if possible
3917 */
3918static int dasd_generic_requeue_all_requests(struct dasd_device *device)
3919{
3920 struct list_head requeue_queue;
3921 struct dasd_ccw_req *cqr, *n;
3922 struct dasd_ccw_req *refers;
3923 int rc;
3924
3925 INIT_LIST_HEAD(&requeue_queue);
3926 spin_lock_irq(get_ccwdev_lock(device->cdev));
3927 rc = 0;
3928 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
3929 /* Check status and move request to flush_queue */
3930 if (cqr->status == DASD_CQR_IN_IO) {
3931 rc = device->discipline->term_IO(cqr);
3932 if (rc) {
3933 /* unable to terminate requeust */
3934 dev_err(&device->cdev->dev,
3935 "Unable to terminate request %p "
3936 "on suspend\n", cqr);
3937 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3938 dasd_put_device(device);
3939 return rc;
3940 }
3941 }
3942 list_move_tail(&cqr->devlist, &requeue_queue);
3943 }
3944 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3945
3946 list_for_each_entry_safe(cqr, n, &requeue_queue, devlist) {
3947 wait_event(dasd_flush_wq,
3948 (cqr->status != DASD_CQR_CLEAR_PENDING));
3949
Stefan Haberland9487cfd2018-02-07 17:39:14 +01003950 /*
3951 * requeue requests to blocklayer will only work
3952 * for block device requests
3953 */
3954 if (_dasd_requeue_request(cqr))
3955 continue;
Stefan Haberlanda521b042016-08-08 15:56:54 +02003956
3957 /* remove requests from device and block queue */
3958 list_del_init(&cqr->devlist);
3959 while (cqr->refers != NULL) {
3960 refers = cqr->refers;
3961 /* remove the request from the block queue */
3962 list_del(&cqr->blocklist);
3963 /* free the finished erp request */
3964 dasd_free_erp_request(cqr, cqr->memdev);
3965 cqr = refers;
3966 }
3967
Stefan Haberlanda1fc8182018-02-19 12:24:39 +01003968 /*
3969 * _dasd_requeue_request already checked for a valid
3970 * blockdevice, no need to check again
3971 * all erp requests (cqr->refers) have a cqr->block
3972 * pointer copy from the original cqr
3973 */
3974 list_del_init(&cqr->blocklist);
Stefan Haberlanda521b042016-08-08 15:56:54 +02003975 cqr->block->base->discipline->free_cp(
3976 cqr, (struct request *) cqr->callback_data);
3977 }
3978
3979 /*
3980 * if requests remain then they are internal request
3981 * and go back to the device queue
3982 */
3983 if (!list_empty(&requeue_queue)) {
3984 /* move freeze_queue to start of the ccw_queue */
3985 spin_lock_irq(get_ccwdev_lock(device->cdev));
3986 list_splice_tail(&requeue_queue, &device->ccw_queue);
3987 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3988 }
Stefan Haberland9487cfd2018-02-07 17:39:14 +01003989 dasd_schedule_device_bh(device);
Stefan Haberlanda521b042016-08-08 15:56:54 +02003990 return rc;
3991}
3992
3993static void do_requeue_requests(struct work_struct *work)
3994{
3995 struct dasd_device *device = container_of(work, struct dasd_device,
3996 requeue_requests);
3997 dasd_generic_requeue_all_requests(device);
3998 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOT_ACC);
3999 if (device->block)
4000 dasd_schedule_block_bh(device->block);
4001 dasd_put_device(device);
4002}
4003
4004void dasd_schedule_requeue(struct dasd_device *device)
4005{
4006 dasd_get_device(device);
4007 /* queue call to dasd_reload_device to the kernel event daemon. */
4008 if (!schedule_work(&device->requeue_requests))
4009 dasd_put_device(device);
4010}
4011EXPORT_SYMBOL(dasd_schedule_requeue);
Stefan Weinhubera4d26c62011-01-05 12:48:03 +01004012
Heiko Carstens763968e2007-05-10 15:45:46 +02004013static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
Heiko Carstens763968e2007-05-10 15:45:46 +02004014 int rdc_buffer_size,
Stefan Haberland68b781f2009-09-11 10:28:29 +02004015 int magic)
Cornelia Huck17283b52007-05-04 18:47:51 +02004016{
4017 struct dasd_ccw_req *cqr;
4018 struct ccw1 *ccw;
4019
Sebastian Ottc5205f22018-06-04 19:07:39 +02004020 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device,
4021 NULL);
Cornelia Huck17283b52007-05-04 18:47:51 +02004022
4023 if (IS_ERR(cqr)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +01004024 /* internal error 13 - Allocating the RDC request failed*/
4025 dev_err(&device->cdev->dev,
4026 "An error occurred in the DASD device driver, "
4027 "reason=%s\n", "13");
Cornelia Huck17283b52007-05-04 18:47:51 +02004028 return cqr;
4029 }
4030
4031 ccw = cqr->cpaddr;
4032 ccw->cmd_code = CCW_CMD_RDC;
Martin Schwidefsky9fe567d2019-03-01 16:03:47 +01004033 ccw->cda = (__u32)(addr_t) cqr->data;
4034 ccw->flags = 0;
Stefan Haberlandd9fa9442009-10-14 12:43:48 +02004035 ccw->count = rdc_buffer_size;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004036 cqr->startdev = device;
4037 cqr->memdev = device;
Cornelia Huck17283b52007-05-04 18:47:51 +02004038 cqr->expires = 10*HZ;
Stefan Weinhubereb6e1992009-12-07 12:51:51 +01004039 cqr->retries = 256;
Heiko Carstens1aae0562013-01-30 09:49:40 +01004040 cqr->buildclk = get_tod_clock();
Cornelia Huck17283b52007-05-04 18:47:51 +02004041 cqr->status = DASD_CQR_FILLED;
4042 return cqr;
4043}
4044
4045
Stefan Haberland68b781f2009-09-11 10:28:29 +02004046int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
Sebastian Ott92636b12009-06-12 10:26:37 +02004047 void *rdc_buffer, int rdc_buffer_size)
Cornelia Huck17283b52007-05-04 18:47:51 +02004048{
4049 int ret;
4050 struct dasd_ccw_req *cqr;
4051
Martin Schwidefsky9fe567d2019-03-01 16:03:47 +01004052 cqr = dasd_generic_build_rdc(device, rdc_buffer_size, magic);
Cornelia Huck17283b52007-05-04 18:47:51 +02004053 if (IS_ERR(cqr))
4054 return PTR_ERR(cqr);
4055
4056 ret = dasd_sleep_on(cqr);
Martin Schwidefsky9fe567d2019-03-01 16:03:47 +01004057 if (ret == 0)
4058 memcpy(rdc_buffer, cqr->data, rdc_buffer_size);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004059 dasd_sfree_request(cqr, cqr->memdev);
Cornelia Huck17283b52007-05-04 18:47:51 +02004060 return ret;
4061}
Cornelia Huckaaff0f62007-05-10 15:45:45 +02004062EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
Stefan Weinhuber20c64462006-03-24 03:15:25 -08004063
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +01004064/*
4065 * In command mode and transport mode we need to look for sense
4066 * data in different places. The sense data itself is allways
4067 * an array of 32 bytes, so we can unify the sense data access
4068 * for both modes.
4069 */
4070char *dasd_get_sense(struct irb *irb)
4071{
4072 struct tsb *tsb = NULL;
4073 char *sense = NULL;
4074
4075 if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
4076 if (irb->scsw.tm.tcw)
4077 tsb = tcw_get_tsb((struct tcw *)(unsigned long)
4078 irb->scsw.tm.tcw);
4079 if (tsb && tsb->length == 64 && tsb->flags)
4080 switch (tsb->flags & 0x07) {
4081 case 1: /* tsa_iostat */
4082 sense = tsb->tsa.iostat.sense;
4083 break;
4084 case 2: /* tsa_ddpc */
4085 sense = tsb->tsa.ddpc.sense;
4086 break;
4087 default:
4088 /* currently we don't use interrogate data */
4089 break;
4090 }
4091 } else if (irb->esw.esw0.erw.cons) {
4092 sense = irb->ecw;
4093 }
4094 return sense;
4095}
4096EXPORT_SYMBOL_GPL(dasd_get_sense);
4097
Stefan Haberland4679e892012-06-19 17:30:12 +02004098void dasd_generic_shutdown(struct ccw_device *cdev)
4099{
4100 struct dasd_device *device;
4101
4102 device = dasd_device_from_cdev(cdev);
4103 if (IS_ERR(device))
4104 return;
4105
4106 if (device->block)
4107 dasd_schedule_block_bh(device->block);
4108
4109 dasd_schedule_device_bh(device);
4110
4111 wait_event(shutdown_waitq, _wait_for_empty_queues(device));
4112}
4113EXPORT_SYMBOL_GPL(dasd_generic_shutdown);
4114
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01004115static int __init dasd_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116{
4117 int rc;
4118
4119 init_waitqueue_head(&dasd_init_waitq);
Horst Hummel8f617012006-08-30 14:33:33 +02004120 init_waitqueue_head(&dasd_flush_wq);
Stefan Haberlandc80ee722008-05-30 10:03:31 +02004121 init_waitqueue_head(&generic_waitq);
Stefan Haberland4679e892012-06-19 17:30:12 +02004122 init_waitqueue_head(&shutdown_waitq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123
4124 /* register 'common' DASD debug area, used for all DBF_XXX calls */
Peter Tiedemann361f4942008-01-26 14:11:30 +01004125 dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126 if (dasd_debug_area == NULL) {
4127 rc = -ENOMEM;
4128 goto failed;
4129 }
4130 debug_register_view(dasd_debug_area, &debug_sprintf_view);
Horst Hummelb0035f12006-09-20 15:59:07 +02004131 debug_set_level(dasd_debug_area, DBF_WARNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132
4133 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
4134
4135 dasd_diag_discipline_pointer = NULL;
4136
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +02004137 dasd_statistics_createroot();
4138
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139 rc = dasd_devmap_init();
4140 if (rc)
4141 goto failed;
4142 rc = dasd_gendisk_init();
4143 if (rc)
4144 goto failed;
4145 rc = dasd_parse();
4146 if (rc)
4147 goto failed;
Stefan Weinhuber20c64462006-03-24 03:15:25 -08004148 rc = dasd_eer_init();
4149 if (rc)
4150 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151#ifdef CONFIG_PROC_FS
4152 rc = dasd_proc_init();
4153 if (rc)
4154 goto failed;
4155#endif
4156
4157 return 0;
4158failed:
Stefan Haberlandfc19f382009-03-26 15:23:49 +01004159 pr_info("The DASD device driver could not be initialized\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 dasd_exit();
4161 return rc;
4162}
4163
4164module_init(dasd_init);
4165module_exit(dasd_exit);