Greg Kroah-Hartman | 6a55d2c | 2017-11-14 18:38:00 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> |
| 4 | * Horst Hummel <Horst.Hummel@de.ibm.com> |
| 5 | * Carsten Otte <Cotte@de.ibm.com> |
| 6 | * Martin Schwidefsky <schwidefsky@de.ibm.com> |
| 7 | * Bugreports.to..: <Linux390@de.ibm.com> |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 8 | * Copyright IBM Corp. 1999, 2009 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 11 | #define KMSG_COMPONENT "dasd" |
| 12 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/kmod.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/ctype.h> |
| 18 | #include <linux/major.h> |
| 19 | #include <linux/slab.h> |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 20 | #include <linux/hdreg.h> |
Cornelia Huck | f3445a1 | 2009-04-14 15:36:23 +0200 | [diff] [blame] | 21 | #include <linux/async.h> |
Stefan Haberland | 9eb2512 | 2010-02-26 22:37:46 +0100 | [diff] [blame] | 22 | #include <linux/mutex.h> |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 23 | #include <linux/debugfs.h> |
| 24 | #include <linux/seq_file.h> |
Stefan Weinhuber | e4258d5 | 2011-08-03 16:44:20 +0200 | [diff] [blame] | 25 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #include <asm/ccwdev.h> |
| 28 | #include <asm/ebcdic.h> |
| 29 | #include <asm/idals.h> |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 30 | #include <asm/itcw.h> |
Stefan Weinhuber | 33b62a3 | 2010-03-08 12:26:24 +0100 | [diff] [blame] | 31 | #include <asm/diag.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 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 Oberparleiter | 7c53fcb | 2015-05-11 13:08:05 +0200 | [diff] [blame] | 42 | #define DASD_DIAG_MOD "dasd_diag_mod" |
| 43 | |
Stefan Haberland | 3284da3 | 2018-06-12 16:47:10 +0200 | [diff] [blame] | 44 | static unsigned int queue_depth = 32; |
| 45 | static unsigned int nr_hw_queues = 4; |
| 46 | |
| 47 | module_param(queue_depth, uint, 0444); |
| 48 | MODULE_PARM_DESC(queue_depth, "Default queue depth for new DASD devices"); |
| 49 | |
| 50 | module_param(nr_hw_queues, uint, 0444); |
| 51 | MODULE_PARM_DESC(nr_hw_queues, "Default number of hardware queues for new DASD devices"); |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /* |
| 54 | * SECTION: exported variables of dasd.c |
| 55 | */ |
| 56 | debug_info_t *dasd_debug_area; |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 57 | EXPORT_SYMBOL(dasd_debug_area); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 58 | static struct dentry *dasd_debugfs_root_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | struct dasd_discipline *dasd_diag_discipline_pointer; |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 60 | EXPORT_SYMBOL(dasd_diag_discipline_pointer); |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 61 | void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
| 63 | MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>"); |
| 64 | MODULE_DESCRIPTION("Linux on S/390 DASD device driver," |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 65 | " Copyright IBM Corp. 2000"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | MODULE_SUPPORTED_DEVICE("dasd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | MODULE_LICENSE("GPL"); |
| 68 | |
| 69 | /* |
| 70 | * SECTION: prototypes for static functions of dasd.c |
| 71 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 72 | static int dasd_alloc_queue(struct dasd_block *); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 73 | static void dasd_free_queue(struct dasd_block *); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 74 | static int dasd_flush_block_queue(struct dasd_block *); |
Sebastian Ott | d2f2df6 | 2018-07-03 13:06:45 +0200 | [diff] [blame] | 75 | static void dasd_device_tasklet(unsigned long); |
| 76 | static void dasd_block_tasklet(unsigned long); |
Al Viro | 4927b3f | 2006-12-06 19:18:20 +0000 | [diff] [blame] | 77 | static void do_kick_device(struct work_struct *); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 78 | static void do_restore_device(struct work_struct *); |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 79 | static void do_reload_device(struct work_struct *); |
Stefan Haberland | a521b04 | 2016-08-08 15:56:54 +0200 | [diff] [blame] | 80 | static void do_requeue_requests(struct work_struct *); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 81 | static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *); |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 82 | static void dasd_device_timeout(struct timer_list *); |
| 83 | static void dasd_block_timeout(struct timer_list *); |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 84 | static void __dasd_process_erp(struct dasd_device *, struct dasd_ccw_req *); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 85 | static void dasd_profile_init(struct dasd_profile *, struct dentry *); |
| 86 | static void dasd_profile_exit(struct dasd_profile *); |
Stefan Haberland | 5a3b7b1 | 2016-03-18 09:42:13 +0100 | [diff] [blame] | 87 | static void dasd_hosts_init(struct dentry *, struct dasd_device *); |
| 88 | static void dasd_hosts_exit(struct dasd_device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * SECTION: Operations on the device structure. |
| 92 | */ |
| 93 | static wait_queue_head_t dasd_init_waitq; |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 94 | static wait_queue_head_t dasd_flush_wq; |
Stefan Haberland | c80ee72 | 2008-05-30 10:03:31 +0200 | [diff] [blame] | 95 | static wait_queue_head_t generic_waitq; |
Stefan Haberland | 4679e89 | 2012-06-19 17:30:12 +0200 | [diff] [blame] | 96 | static wait_queue_head_t shutdown_waitq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | * Allocate memory for a new device structure. |
| 100 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 101 | struct dasd_device *dasd_alloc_device(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { |
| 103 | struct dasd_device *device; |
| 104 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 105 | device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC); |
| 106 | if (!device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | return ERR_PTR(-ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | /* Get two pages for normal block device operations. */ |
| 110 | device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 111 | if (!device->ccw_mem) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | kfree(device); |
| 113 | return ERR_PTR(-ENOMEM); |
| 114 | } |
| 115 | /* Get one page for error recovery. */ |
| 116 | device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 117 | if (!device->erp_mem) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | free_pages((unsigned long) device->ccw_mem, 1); |
| 119 | kfree(device); |
| 120 | return ERR_PTR(-ENOMEM); |
| 121 | } |
Jan Höppner | 5e2b17e | 2018-04-27 16:51:22 +0200 | [diff] [blame] | 122 | /* Get two pages for ese format. */ |
| 123 | device->ese_mem = (void *)__get_free_pages(GFP_ATOMIC | GFP_DMA, 1); |
| 124 | if (!device->ese_mem) { |
| 125 | free_page((unsigned long) device->erp_mem); |
| 126 | free_pages((unsigned long) device->ccw_mem, 1); |
| 127 | kfree(device); |
| 128 | return ERR_PTR(-ENOMEM); |
| 129 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2); |
| 132 | dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE); |
Jan Höppner | 5e2b17e | 2018-04-27 16:51:22 +0200 | [diff] [blame] | 133 | dasd_init_chunklist(&device->ese_chunks, device->ese_mem, PAGE_SIZE * 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | spin_lock_init(&device->mem_lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 135 | atomic_set(&device->tasklet_scheduled, 0); |
Sebastian Ott | d2f2df6 | 2018-07-03 13:06:45 +0200 | [diff] [blame] | 136 | tasklet_init(&device->tasklet, dasd_device_tasklet, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | (unsigned long) device); |
| 138 | INIT_LIST_HEAD(&device->ccw_queue); |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 139 | timer_setup(&device->timer, dasd_device_timeout, 0); |
Al Viro | 4927b3f | 2006-12-06 19:18:20 +0000 | [diff] [blame] | 140 | INIT_WORK(&device->kick_work, do_kick_device); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 141 | INIT_WORK(&device->restore_device, do_restore_device); |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 142 | INIT_WORK(&device->reload_device, do_reload_device); |
Stefan Haberland | a521b04 | 2016-08-08 15:56:54 +0200 | [diff] [blame] | 143 | INIT_WORK(&device->requeue_requests, do_requeue_requests); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | device->state = DASD_STATE_NEW; |
| 145 | device->target = DASD_STATE_NEW; |
Stefan Haberland | 9eb2512 | 2010-02-26 22:37:46 +0100 | [diff] [blame] | 146 | mutex_init(&device->state_mutex); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 147 | spin_lock_init(&device->profile.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | return device; |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | * Free memory of a device structure. |
| 153 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 154 | void dasd_free_device(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { |
Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 156 | kfree(device->private); |
Jan Höppner | 5e2b17e | 2018-04-27 16:51:22 +0200 | [diff] [blame] | 157 | free_pages((unsigned long) device->ese_mem, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | free_page((unsigned long) device->erp_mem); |
| 159 | free_pages((unsigned long) device->ccw_mem, 1); |
| 160 | kfree(device); |
| 161 | } |
| 162 | |
| 163 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 164 | * Allocate memory for a new device structure. |
| 165 | */ |
| 166 | struct dasd_block *dasd_alloc_block(void) |
| 167 | { |
| 168 | struct dasd_block *block; |
| 169 | |
| 170 | block = kzalloc(sizeof(*block), GFP_ATOMIC); |
| 171 | if (!block) |
| 172 | return ERR_PTR(-ENOMEM); |
| 173 | /* open_count = 0 means device online but not in use */ |
| 174 | atomic_set(&block->open_count, -1); |
| 175 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 176 | atomic_set(&block->tasklet_scheduled, 0); |
Sebastian Ott | d2f2df6 | 2018-07-03 13:06:45 +0200 | [diff] [blame] | 177 | tasklet_init(&block->tasklet, dasd_block_tasklet, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 178 | (unsigned long) block); |
| 179 | INIT_LIST_HEAD(&block->ccw_queue); |
| 180 | spin_lock_init(&block->queue_lock); |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 181 | timer_setup(&block->timer, dasd_block_timeout, 0); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 182 | spin_lock_init(&block->profile.lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 183 | |
| 184 | return block; |
| 185 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 186 | EXPORT_SYMBOL_GPL(dasd_alloc_block); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 187 | |
| 188 | /* |
| 189 | * Free memory of a device structure. |
| 190 | */ |
| 191 | void dasd_free_block(struct dasd_block *block) |
| 192 | { |
| 193 | kfree(block); |
| 194 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 195 | EXPORT_SYMBOL_GPL(dasd_free_block); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 196 | |
| 197 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | * Make a new device known to the system. |
| 199 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 200 | static int dasd_state_new_to_known(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
| 202 | int rc; |
| 203 | |
| 204 | /* |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 205 | * As long as the device is not in state DASD_STATE_NEW we want to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | * keep the reference count > 0. |
| 207 | */ |
| 208 | dasd_get_device(device); |
| 209 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 210 | if (device->block) { |
| 211 | rc = dasd_alloc_queue(device->block); |
| 212 | if (rc) { |
| 213 | dasd_put_device(device); |
| 214 | return rc; |
| 215 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | device->state = DASD_STATE_KNOWN; |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | * Let the system forget about a device. |
| 223 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 224 | static int dasd_state_known_to_new(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | { |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 226 | /* Disable extended error reporting for this device. */ |
| 227 | dasd_eer_disable(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | device->state = DASD_STATE_NEW; |
| 229 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 230 | if (device->block) |
| 231 | dasd_free_queue(device->block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
| 233 | /* Give up reference we took in dasd_state_new_to_known. */ |
| 234 | dasd_put_device(device); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 235 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 238 | static struct dentry *dasd_debugfs_setup(const char *name, |
| 239 | struct dentry *base_dentry) |
| 240 | { |
| 241 | struct dentry *pde; |
| 242 | |
| 243 | if (!base_dentry) |
| 244 | return NULL; |
| 245 | pde = debugfs_create_dir(name, base_dentry); |
| 246 | if (!pde || IS_ERR(pde)) |
| 247 | return NULL; |
| 248 | return pde; |
| 249 | } |
| 250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | /* |
| 252 | * Request the irq line for the device. |
| 253 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 254 | static int dasd_state_known_to_basic(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 256 | struct dasd_block *block = device->block; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 257 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | /* Allocate and register gendisk structure. */ |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 260 | if (block) { |
| 261 | rc = dasd_gendisk_alloc(block); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 262 | if (rc) |
| 263 | return rc; |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 264 | block->debugfs_dentry = |
| 265 | dasd_debugfs_setup(block->gdp->disk_name, |
| 266 | dasd_debugfs_root_entry); |
| 267 | dasd_profile_init(&block->profile, block->debugfs_dentry); |
| 268 | if (dasd_global_profile_level == DASD_PROFILE_ON) |
| 269 | dasd_profile_on(&device->block->profile); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 270 | } |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 271 | device->debugfs_dentry = |
| 272 | dasd_debugfs_setup(dev_name(&device->cdev->dev), |
| 273 | dasd_debugfs_root_entry); |
| 274 | dasd_profile_init(&device->profile, device->debugfs_dentry); |
Stefan Haberland | 5a3b7b1 | 2016-03-18 09:42:13 +0100 | [diff] [blame] | 275 | dasd_hosts_init(device->debugfs_dentry, device); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | /* register 'device' debug area, used for all DBF_DEV_XXX calls */ |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 278 | device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 279 | 8 * sizeof(long)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | debug_register_view(device->debug_area, &debug_sprintf_view); |
Horst Hummel | b0035f1 | 2006-09-20 15:59:07 +0200 | [diff] [blame] | 281 | debug_set_level(device->debug_area, DBF_WARNING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created"); |
| 283 | |
| 284 | device->state = DASD_STATE_BASIC; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 285 | |
| 286 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /* |
| 290 | * Release the irq line for the device. Terminate any running i/o. |
| 291 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 292 | static int dasd_state_basic_to_known(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | { |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 294 | int rc; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 295 | |
Stefan Haberland | daa991b | 2014-07-18 14:19:25 +0200 | [diff] [blame] | 296 | if (device->discipline->basic_to_known) { |
| 297 | rc = device->discipline->basic_to_known(device); |
| 298 | if (rc) |
| 299 | return rc; |
| 300 | } |
| 301 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 302 | if (device->block) { |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 303 | dasd_profile_exit(&device->block->profile); |
Fabian Frederick | d7309aa | 2014-06-26 19:41:46 +0200 | [diff] [blame] | 304 | debugfs_remove(device->block->debugfs_dentry); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 305 | dasd_gendisk_free(device->block); |
| 306 | dasd_block_clear_timer(device->block); |
| 307 | } |
| 308 | rc = dasd_flush_device_queue(device); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 309 | if (rc) |
| 310 | return rc; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 311 | dasd_device_clear_timer(device); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 312 | dasd_profile_exit(&device->profile); |
Stefan Haberland | 5a3b7b1 | 2016-03-18 09:42:13 +0100 | [diff] [blame] | 313 | dasd_hosts_exit(device); |
Fabian Frederick | d7309aa | 2014-06-26 19:41:46 +0200 | [diff] [blame] | 314 | debugfs_remove(device->debugfs_dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device); |
| 316 | if (device->debug_area != NULL) { |
| 317 | debug_unregister(device->debug_area); |
| 318 | device->debug_area = NULL; |
| 319 | } |
| 320 | device->state = DASD_STATE_KNOWN; |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 321 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /* |
| 325 | * Do the initial analysis. The do_analysis function may return |
| 326 | * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC |
| 327 | * until the discipline decides to continue the startup sequence |
| 328 | * by calling the function dasd_change_state. The eckd disciplines |
| 329 | * uses this to start a ccw that detects the format. The completion |
| 330 | * interrupt for this detection ccw uses the kernel event daemon to |
| 331 | * trigger the call to dasd_change_state. All this is done in the |
| 332 | * discipline code, see dasd_eckd.c. |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 333 | * After the analysis ccw is done (do_analysis returned 0) the block |
| 334 | * device is setup. |
| 335 | * In case the analysis returns an error, the device setup is stopped |
| 336 | * (a fake disk was already added to allow formatting). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 338 | static int dasd_state_basic_to_ready(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | { |
| 340 | int rc; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 341 | struct dasd_block *block; |
Stefan Haberland | eed5c4b | 2016-08-31 13:31:10 +0200 | [diff] [blame] | 342 | struct gendisk *disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
| 344 | rc = 0; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 345 | block = device->block; |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 346 | /* make disk known with correct capacity */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 347 | if (block) { |
| 348 | if (block->base->discipline->do_analysis != NULL) |
| 349 | rc = block->base->discipline->do_analysis(block); |
| 350 | if (rc) { |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 351 | if (rc != -EAGAIN) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 352 | device->state = DASD_STATE_UNFMT; |
Stefan Haberland | eed5c4b | 2016-08-31 13:31:10 +0200 | [diff] [blame] | 353 | disk = device->block->gdp; |
| 354 | kobject_uevent(&disk_to_dev(disk)->kobj, |
| 355 | KOBJ_CHANGE); |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 356 | goto out; |
| 357 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 358 | return rc; |
| 359 | } |
Jan Höppner | a0610a8 | 2018-04-27 16:55:27 +0200 | [diff] [blame] | 360 | if (device->discipline->setup_blk_queue) |
| 361 | device->discipline->setup_blk_queue(block); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 362 | set_capacity(block->gdp, |
| 363 | block->blocks << block->s2b_shift); |
| 364 | device->state = DASD_STATE_READY; |
| 365 | rc = dasd_scan_partitions(block); |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 366 | if (rc) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 367 | device->state = DASD_STATE_BASIC; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 368 | return rc; |
| 369 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 370 | } else { |
| 371 | device->state = DASD_STATE_READY; |
| 372 | } |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 373 | out: |
| 374 | if (device->discipline->basic_to_ready) |
| 375 | rc = device->discipline->basic_to_ready(device); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 376 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 379 | static inline |
| 380 | int _wait_for_empty_queues(struct dasd_device *device) |
| 381 | { |
| 382 | if (device->block) |
| 383 | return list_empty(&device->ccw_queue) && |
| 384 | list_empty(&device->block->ccw_queue); |
| 385 | else |
| 386 | return list_empty(&device->ccw_queue); |
| 387 | } |
| 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | /* |
| 390 | * Remove device from block device layer. Destroy dirty buffers. |
| 391 | * Forget format information. Check if the target level is basic |
| 392 | * and if it is create fake disk for formatting. |
| 393 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 394 | static int dasd_state_ready_to_basic(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | { |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 396 | int rc; |
| 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | device->state = DASD_STATE_BASIC; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 399 | if (device->block) { |
| 400 | struct dasd_block *block = device->block; |
| 401 | rc = dasd_flush_block_queue(block); |
| 402 | if (rc) { |
| 403 | device->state = DASD_STATE_READY; |
| 404 | return rc; |
| 405 | } |
Stefan Haberland | b695adf | 2010-02-26 22:37:48 +0100 | [diff] [blame] | 406 | dasd_destroy_partitions(block); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 407 | block->blocks = 0; |
| 408 | block->bp_block = 0; |
| 409 | block->s2b_shift = 0; |
| 410 | } |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 411 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | /* |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 415 | * Back to basic. |
| 416 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 417 | static int dasd_state_unfmt_to_basic(struct dasd_device *device) |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 418 | { |
| 419 | device->state = DASD_STATE_BASIC; |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 420 | return 0; |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | * Make the device online and schedule the bottom half to start |
| 425 | * the requeueing of requests from the linux request queue to the |
| 426 | * ccw queue. |
| 427 | */ |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 428 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | dasd_state_ready_to_online(struct dasd_device * device) |
| 430 | { |
Stefan Weinhuber | 1301809 | 2009-01-09 12:14:50 +0100 | [diff] [blame] | 431 | struct gendisk *disk; |
| 432 | struct disk_part_iter piter; |
| 433 | struct hd_struct *part; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | device->state = DASD_STATE_ONLINE; |
Stefan Weinhuber | 1301809 | 2009-01-09 12:14:50 +0100 | [diff] [blame] | 436 | if (device->block) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 437 | dasd_schedule_block_bh(device->block); |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 438 | if ((device->features & DASD_FEATURE_USERAW)) { |
| 439 | disk = device->block->gdp; |
| 440 | kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE); |
| 441 | return 0; |
| 442 | } |
Stefan Weinhuber | 1301809 | 2009-01-09 12:14:50 +0100 | [diff] [blame] | 443 | disk = device->block->bdev->bd_disk; |
| 444 | disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0); |
| 445 | while ((part = disk_part_iter_next(&piter))) |
| 446 | kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE); |
| 447 | disk_part_iter_exit(&piter); |
| 448 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | /* |
| 453 | * Stop the requeueing of requests again. |
| 454 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 455 | static int dasd_state_online_to_ready(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 457 | int rc; |
Stefan Weinhuber | 1301809 | 2009-01-09 12:14:50 +0100 | [diff] [blame] | 458 | struct gendisk *disk; |
| 459 | struct disk_part_iter piter; |
| 460 | struct hd_struct *part; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 461 | |
| 462 | if (device->discipline->online_to_ready) { |
| 463 | rc = device->discipline->online_to_ready(device); |
| 464 | if (rc) |
| 465 | return rc; |
| 466 | } |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | device->state = DASD_STATE_READY; |
Stefan Haberland | e4dbb0f | 2011-01-05 12:48:06 +0100 | [diff] [blame] | 469 | if (device->block && !(device->features & DASD_FEATURE_USERAW)) { |
Stefan Weinhuber | 1301809 | 2009-01-09 12:14:50 +0100 | [diff] [blame] | 470 | disk = device->block->bdev->bd_disk; |
| 471 | disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0); |
| 472 | while ((part = disk_part_iter_next(&piter))) |
| 473 | kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE); |
| 474 | disk_part_iter_exit(&piter); |
| 475 | } |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 476 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /* |
| 480 | * Device startup state changes. |
| 481 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 482 | static int dasd_increase_state(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | { |
| 484 | int rc; |
| 485 | |
| 486 | rc = 0; |
| 487 | if (device->state == DASD_STATE_NEW && |
| 488 | device->target >= DASD_STATE_KNOWN) |
| 489 | rc = dasd_state_new_to_known(device); |
| 490 | |
| 491 | if (!rc && |
| 492 | device->state == DASD_STATE_KNOWN && |
| 493 | device->target >= DASD_STATE_BASIC) |
| 494 | rc = dasd_state_known_to_basic(device); |
| 495 | |
| 496 | if (!rc && |
| 497 | device->state == DASD_STATE_BASIC && |
| 498 | device->target >= DASD_STATE_READY) |
| 499 | rc = dasd_state_basic_to_ready(device); |
| 500 | |
| 501 | if (!rc && |
Horst Hummel | 39ccf95 | 2006-04-27 18:40:10 -0700 | [diff] [blame] | 502 | device->state == DASD_STATE_UNFMT && |
| 503 | device->target > DASD_STATE_UNFMT) |
| 504 | rc = -EPERM; |
| 505 | |
| 506 | if (!rc && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | device->state == DASD_STATE_READY && |
| 508 | device->target >= DASD_STATE_ONLINE) |
| 509 | rc = dasd_state_ready_to_online(device); |
| 510 | |
| 511 | return rc; |
| 512 | } |
| 513 | |
| 514 | /* |
| 515 | * Device shutdown state changes. |
| 516 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 517 | static int dasd_decrease_state(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | { |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 519 | int rc; |
| 520 | |
| 521 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | if (device->state == DASD_STATE_ONLINE && |
| 523 | device->target <= DASD_STATE_READY) |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 524 | rc = dasd_state_online_to_ready(device); |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 525 | |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 526 | if (!rc && |
| 527 | device->state == DASD_STATE_READY && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | device->target <= DASD_STATE_BASIC) |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 529 | rc = dasd_state_ready_to_basic(device); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 530 | |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 531 | if (!rc && |
| 532 | device->state == DASD_STATE_UNFMT && |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 533 | device->target <= DASD_STATE_BASIC) |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 534 | rc = dasd_state_unfmt_to_basic(device); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 535 | |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 536 | if (!rc && |
| 537 | device->state == DASD_STATE_BASIC && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | device->target <= DASD_STATE_KNOWN) |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 539 | rc = dasd_state_basic_to_known(device); |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 540 | |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 541 | if (!rc && |
| 542 | device->state == DASD_STATE_KNOWN && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | device->target <= DASD_STATE_NEW) |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 544 | rc = dasd_state_known_to_new(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 546 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | /* |
| 550 | * This is the main startup/shutdown routine. |
| 551 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 552 | static void dasd_change_state(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | { |
Sebastian Ott | 181d952 | 2009-06-22 12:08:21 +0200 | [diff] [blame] | 554 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
| 556 | if (device->state == device->target) |
| 557 | /* Already where we want to go today... */ |
| 558 | return; |
| 559 | if (device->state < device->target) |
| 560 | rc = dasd_increase_state(device); |
| 561 | else |
| 562 | rc = dasd_decrease_state(device); |
Sebastian Ott | 181d952 | 2009-06-22 12:08:21 +0200 | [diff] [blame] | 563 | if (rc == -EAGAIN) |
| 564 | return; |
| 565 | if (rc) |
| 566 | device->target = device->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
Horst Hummel | 4dfd5c4 | 2007-04-27 16:01:47 +0200 | [diff] [blame] | 568 | /* let user-space know that the device status changed */ |
| 569 | kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE); |
Sebastian Ott | 1f08be8 | 2012-09-05 14:18:22 +0200 | [diff] [blame] | 570 | |
| 571 | if (device->state == device->target) |
| 572 | wake_up(&dasd_init_waitq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /* |
| 576 | * Kick starter for devices that did not complete the startup/shutdown |
| 577 | * procedure or were sleeping because of a pending state. |
| 578 | * dasd_kick_device will schedule a call do do_kick_device to the kernel |
| 579 | * event daemon. |
| 580 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 581 | static void do_kick_device(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | { |
Al Viro | 4927b3f | 2006-12-06 19:18:20 +0000 | [diff] [blame] | 583 | struct dasd_device *device = container_of(work, struct dasd_device, kick_work); |
Stefan Haberland | 9eb2512 | 2010-02-26 22:37:46 +0100 | [diff] [blame] | 584 | mutex_lock(&device->state_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | dasd_change_state(device); |
Stefan Haberland | 9eb2512 | 2010-02-26 22:37:46 +0100 | [diff] [blame] | 586 | mutex_unlock(&device->state_mutex); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 587 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | dasd_put_device(device); |
| 589 | } |
| 590 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 591 | void dasd_kick_device(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | { |
| 593 | dasd_get_device(device); |
| 594 | /* queue call to dasd_kick_device to the kernel event daemon. */ |
Stefan Haberland | f2608cd | 2015-04-02 12:27:25 +0200 | [diff] [blame] | 595 | if (!schedule_work(&device->kick_work)) |
| 596 | dasd_put_device(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 598 | EXPORT_SYMBOL(dasd_kick_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
| 600 | /* |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 601 | * dasd_reload_device will schedule a call do do_reload_device to the kernel |
| 602 | * event daemon. |
| 603 | */ |
| 604 | static void do_reload_device(struct work_struct *work) |
| 605 | { |
| 606 | struct dasd_device *device = container_of(work, struct dasd_device, |
| 607 | reload_device); |
| 608 | device->discipline->reload(device); |
| 609 | dasd_put_device(device); |
| 610 | } |
| 611 | |
| 612 | void dasd_reload_device(struct dasd_device *device) |
| 613 | { |
| 614 | dasd_get_device(device); |
| 615 | /* queue call to dasd_reload_device to the kernel event daemon. */ |
Stefan Haberland | f2608cd | 2015-04-02 12:27:25 +0200 | [diff] [blame] | 616 | if (!schedule_work(&device->reload_device)) |
| 617 | dasd_put_device(device); |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 618 | } |
| 619 | EXPORT_SYMBOL(dasd_reload_device); |
| 620 | |
| 621 | /* |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 622 | * dasd_restore_device will schedule a call do do_restore_device to the kernel |
| 623 | * event daemon. |
| 624 | */ |
| 625 | static void do_restore_device(struct work_struct *work) |
| 626 | { |
| 627 | struct dasd_device *device = container_of(work, struct dasd_device, |
| 628 | restore_device); |
| 629 | device->cdev->drv->restore(device->cdev); |
| 630 | dasd_put_device(device); |
| 631 | } |
| 632 | |
| 633 | void dasd_restore_device(struct dasd_device *device) |
| 634 | { |
| 635 | dasd_get_device(device); |
| 636 | /* queue call to dasd_restore_device to the kernel event daemon. */ |
Stefan Haberland | f2608cd | 2015-04-02 12:27:25 +0200 | [diff] [blame] | 637 | if (!schedule_work(&device->restore_device)) |
| 638 | dasd_put_device(device); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | * Set the target state for a device and starts the state change. |
| 643 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 644 | void dasd_set_target_state(struct dasd_device *device, int target) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | { |
Cornelia Huck | f3445a1 | 2009-04-14 15:36:23 +0200 | [diff] [blame] | 646 | dasd_get_device(device); |
Stefan Haberland | 9eb2512 | 2010-02-26 22:37:46 +0100 | [diff] [blame] | 647 | mutex_lock(&device->state_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | /* If we are in probeonly mode stop at DASD_STATE_READY. */ |
| 649 | if (dasd_probeonly && target > DASD_STATE_READY) |
| 650 | target = DASD_STATE_READY; |
| 651 | if (device->target != target) { |
Stefan Haberland | 9eb2512 | 2010-02-26 22:37:46 +0100 | [diff] [blame] | 652 | if (device->state == target) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | wake_up(&dasd_init_waitq); |
| 654 | device->target = target; |
| 655 | } |
| 656 | if (device->state != device->target) |
| 657 | dasd_change_state(device); |
Stefan Haberland | 9eb2512 | 2010-02-26 22:37:46 +0100 | [diff] [blame] | 658 | mutex_unlock(&device->state_mutex); |
| 659 | dasd_put_device(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 661 | EXPORT_SYMBOL(dasd_set_target_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
| 663 | /* |
| 664 | * Enable devices with device numbers in [from..to]. |
| 665 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 666 | static inline int _wait_for_device(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | { |
| 668 | return (device->state == device->target); |
| 669 | } |
| 670 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 671 | void dasd_enable_device(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | { |
| 673 | dasd_set_target_state(device, DASD_STATE_ONLINE); |
| 674 | if (device->state <= DASD_STATE_KNOWN) |
| 675 | /* No discipline for device found. */ |
| 676 | dasd_set_target_state(device, DASD_STATE_NEW); |
| 677 | /* Now wait for the devices to come up. */ |
| 678 | wait_event(dasd_init_waitq, _wait_for_device(device)); |
Stefan Haberland | 25e2cf1 | 2012-03-11 11:59:37 -0400 | [diff] [blame] | 679 | |
| 680 | dasd_reload_device(device); |
| 681 | if (device->discipline->kick_validate) |
| 682 | device->discipline->kick_validate(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 684 | EXPORT_SYMBOL(dasd_enable_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
| 686 | /* |
| 687 | * SECTION: device operation (interrupt handler, start i/o, term i/o ...) |
| 688 | */ |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 689 | |
| 690 | unsigned int dasd_global_profile_level = DASD_PROFILE_OFF; |
| 691 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | #ifdef CONFIG_DASD_PROFILE |
Sebastian Ott | 8ea55c9 | 2015-01-28 18:44:17 +0100 | [diff] [blame] | 693 | struct dasd_profile dasd_global_profile = { |
Sebastian Ott | 8ea55c9 | 2015-01-28 18:44:17 +0100 | [diff] [blame] | 694 | .lock = __SPIN_LOCK_UNLOCKED(dasd_global_profile.lock), |
| 695 | }; |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 696 | static struct dentry *dasd_debugfs_global_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | |
| 698 | /* |
| 699 | * Add profiling information for cqr before execution. |
| 700 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 701 | static void dasd_profile_start(struct dasd_block *block, |
| 702 | struct dasd_ccw_req *cqr, |
| 703 | struct request *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | { |
| 705 | struct list_head *l; |
| 706 | unsigned int counter; |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 707 | struct dasd_device *device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
| 709 | /* count the length of the chanq for statistics */ |
| 710 | counter = 0; |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 711 | if (dasd_global_profile_level || block->profile.data) |
| 712 | list_for_each(l, &block->ccw_queue) |
| 713 | if (++counter >= 31) |
| 714 | break; |
| 715 | |
Sebastian Ott | 8ea55c9 | 2015-01-28 18:44:17 +0100 | [diff] [blame] | 716 | spin_lock(&dasd_global_profile.lock); |
Sebastian Ott | 6765cc2 | 2015-01-28 19:06:29 +0100 | [diff] [blame] | 717 | if (dasd_global_profile.data) { |
Sebastian Ott | 8ea55c9 | 2015-01-28 18:44:17 +0100 | [diff] [blame] | 718 | dasd_global_profile.data->dasd_io_nr_req[counter]++; |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 719 | if (rq_data_dir(req) == READ) |
Sebastian Ott | 8ea55c9 | 2015-01-28 18:44:17 +0100 | [diff] [blame] | 720 | dasd_global_profile.data->dasd_read_nr_req[counter]++; |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 721 | } |
Sebastian Ott | 8ea55c9 | 2015-01-28 18:44:17 +0100 | [diff] [blame] | 722 | spin_unlock(&dasd_global_profile.lock); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 723 | |
| 724 | spin_lock(&block->profile.lock); |
Stefan Weinhuber | c81a90c | 2013-10-25 11:08:06 +0200 | [diff] [blame] | 725 | if (block->profile.data) { |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 726 | block->profile.data->dasd_io_nr_req[counter]++; |
| 727 | if (rq_data_dir(req) == READ) |
| 728 | block->profile.data->dasd_read_nr_req[counter]++; |
Stefan Weinhuber | c81a90c | 2013-10-25 11:08:06 +0200 | [diff] [blame] | 729 | } |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 730 | spin_unlock(&block->profile.lock); |
| 731 | |
| 732 | /* |
| 733 | * We count the request for the start device, even though it may run on |
| 734 | * some other device due to error recovery. This way we make sure that |
| 735 | * we count each request only once. |
| 736 | */ |
| 737 | device = cqr->startdev; |
| 738 | if (device->profile.data) { |
| 739 | counter = 1; /* request is not yet queued on the start device */ |
| 740 | list_for_each(l, &device->ccw_queue) |
| 741 | if (++counter >= 31) |
| 742 | break; |
| 743 | } |
| 744 | spin_lock(&device->profile.lock); |
| 745 | if (device->profile.data) { |
| 746 | device->profile.data->dasd_io_nr_req[counter]++; |
| 747 | if (rq_data_dir(req) == READ) |
| 748 | device->profile.data->dasd_read_nr_req[counter]++; |
| 749 | } |
| 750 | spin_unlock(&device->profile.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | /* |
| 754 | * Add profiling information for cqr after execution. |
| 755 | */ |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 756 | |
| 757 | #define dasd_profile_counter(value, index) \ |
| 758 | { \ |
| 759 | for (index = 0; index < 31 && value >> (2+index); index++) \ |
| 760 | ; \ |
| 761 | } |
| 762 | |
| 763 | static void dasd_profile_end_add_data(struct dasd_profile_info *data, |
| 764 | int is_alias, |
| 765 | int is_tpm, |
| 766 | int is_read, |
| 767 | long sectors, |
| 768 | int sectors_ind, |
| 769 | int tottime_ind, |
| 770 | int tottimeps_ind, |
| 771 | int strtime_ind, |
| 772 | int irqtime_ind, |
| 773 | int irqtimeps_ind, |
| 774 | int endtime_ind) |
| 775 | { |
| 776 | /* in case of an overflow, reset the whole profile */ |
| 777 | if (data->dasd_io_reqs == UINT_MAX) { |
| 778 | memset(data, 0, sizeof(*data)); |
Arnd Bergmann | bd7a9b3 | 2017-11-27 12:46:57 +0100 | [diff] [blame] | 779 | ktime_get_real_ts64(&data->starttod); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 780 | } |
| 781 | data->dasd_io_reqs++; |
| 782 | data->dasd_io_sects += sectors; |
| 783 | if (is_alias) |
| 784 | data->dasd_io_alias++; |
| 785 | if (is_tpm) |
| 786 | data->dasd_io_tpm++; |
| 787 | |
| 788 | data->dasd_io_secs[sectors_ind]++; |
| 789 | data->dasd_io_times[tottime_ind]++; |
| 790 | data->dasd_io_timps[tottimeps_ind]++; |
| 791 | data->dasd_io_time1[strtime_ind]++; |
| 792 | data->dasd_io_time2[irqtime_ind]++; |
| 793 | data->dasd_io_time2ps[irqtimeps_ind]++; |
| 794 | data->dasd_io_time3[endtime_ind]++; |
| 795 | |
| 796 | if (is_read) { |
| 797 | data->dasd_read_reqs++; |
| 798 | data->dasd_read_sects += sectors; |
| 799 | if (is_alias) |
| 800 | data->dasd_read_alias++; |
| 801 | if (is_tpm) |
| 802 | data->dasd_read_tpm++; |
| 803 | data->dasd_read_secs[sectors_ind]++; |
| 804 | data->dasd_read_times[tottime_ind]++; |
| 805 | data->dasd_read_time1[strtime_ind]++; |
| 806 | data->dasd_read_time2[irqtime_ind]++; |
| 807 | data->dasd_read_time3[endtime_ind]++; |
| 808 | } |
| 809 | } |
| 810 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 811 | static void dasd_profile_end(struct dasd_block *block, |
| 812 | struct dasd_ccw_req *cqr, |
| 813 | struct request *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | { |
Stefan Haberland | d290722 | 2017-07-14 10:33:18 +0200 | [diff] [blame] | 815 | unsigned long strtime, irqtime, endtime, tottime; |
| 816 | unsigned long tottimeps, sectors; |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 817 | struct dasd_device *device; |
| 818 | int sectors_ind, tottime_ind, tottimeps_ind, strtime_ind; |
| 819 | int irqtime_ind, irqtimeps_ind, endtime_ind; |
Stefan Haberland | d290722 | 2017-07-14 10:33:18 +0200 | [diff] [blame] | 820 | struct dasd_profile_info *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 822 | device = cqr->startdev; |
| 823 | if (!(dasd_global_profile_level || |
| 824 | block->profile.data || |
| 825 | device->profile.data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | return; |
| 827 | |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 828 | sectors = blk_rq_sectors(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | if (!cqr->buildclk || !cqr->startclk || |
| 830 | !cqr->stopclk || !cqr->endclk || |
| 831 | !sectors) |
| 832 | return; |
| 833 | |
| 834 | strtime = ((cqr->startclk - cqr->buildclk) >> 12); |
| 835 | irqtime = ((cqr->stopclk - cqr->startclk) >> 12); |
| 836 | endtime = ((cqr->endclk - cqr->stopclk) >> 12); |
| 837 | tottime = ((cqr->endclk - cqr->buildclk) >> 12); |
| 838 | tottimeps = tottime / sectors; |
| 839 | |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 840 | dasd_profile_counter(sectors, sectors_ind); |
| 841 | dasd_profile_counter(tottime, tottime_ind); |
| 842 | dasd_profile_counter(tottimeps, tottimeps_ind); |
| 843 | dasd_profile_counter(strtime, strtime_ind); |
| 844 | dasd_profile_counter(irqtime, irqtime_ind); |
| 845 | dasd_profile_counter(irqtime / sectors, irqtimeps_ind); |
| 846 | dasd_profile_counter(endtime, endtime_ind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | |
Sebastian Ott | 8ea55c9 | 2015-01-28 18:44:17 +0100 | [diff] [blame] | 848 | spin_lock(&dasd_global_profile.lock); |
Sebastian Ott | 6765cc2 | 2015-01-28 19:06:29 +0100 | [diff] [blame] | 849 | if (dasd_global_profile.data) { |
Stefan Haberland | d290722 | 2017-07-14 10:33:18 +0200 | [diff] [blame] | 850 | data = dasd_global_profile.data; |
| 851 | data->dasd_sum_times += tottime; |
| 852 | data->dasd_sum_time_str += strtime; |
| 853 | data->dasd_sum_time_irq += irqtime; |
| 854 | data->dasd_sum_time_end += endtime; |
Sebastian Ott | 8ea55c9 | 2015-01-28 18:44:17 +0100 | [diff] [blame] | 855 | dasd_profile_end_add_data(dasd_global_profile.data, |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 856 | cqr->startdev != block->base, |
| 857 | cqr->cpmode == 1, |
| 858 | rq_data_dir(req) == READ, |
| 859 | sectors, sectors_ind, tottime_ind, |
| 860 | tottimeps_ind, strtime_ind, |
| 861 | irqtime_ind, irqtimeps_ind, |
| 862 | endtime_ind); |
| 863 | } |
Sebastian Ott | 8ea55c9 | 2015-01-28 18:44:17 +0100 | [diff] [blame] | 864 | spin_unlock(&dasd_global_profile.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 866 | spin_lock(&block->profile.lock); |
Stefan Haberland | d290722 | 2017-07-14 10:33:18 +0200 | [diff] [blame] | 867 | if (block->profile.data) { |
| 868 | data = block->profile.data; |
| 869 | data->dasd_sum_times += tottime; |
| 870 | data->dasd_sum_time_str += strtime; |
| 871 | data->dasd_sum_time_irq += irqtime; |
| 872 | data->dasd_sum_time_end += endtime; |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 873 | dasd_profile_end_add_data(block->profile.data, |
| 874 | cqr->startdev != block->base, |
| 875 | cqr->cpmode == 1, |
| 876 | rq_data_dir(req) == READ, |
| 877 | sectors, sectors_ind, tottime_ind, |
| 878 | tottimeps_ind, strtime_ind, |
| 879 | irqtime_ind, irqtimeps_ind, |
| 880 | endtime_ind); |
Stefan Haberland | d290722 | 2017-07-14 10:33:18 +0200 | [diff] [blame] | 881 | } |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 882 | spin_unlock(&block->profile.lock); |
| 883 | |
| 884 | spin_lock(&device->profile.lock); |
Stefan Haberland | d290722 | 2017-07-14 10:33:18 +0200 | [diff] [blame] | 885 | if (device->profile.data) { |
| 886 | data = device->profile.data; |
| 887 | data->dasd_sum_times += tottime; |
| 888 | data->dasd_sum_time_str += strtime; |
| 889 | data->dasd_sum_time_irq += irqtime; |
| 890 | data->dasd_sum_time_end += endtime; |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 891 | dasd_profile_end_add_data(device->profile.data, |
| 892 | cqr->startdev != block->base, |
| 893 | cqr->cpmode == 1, |
| 894 | rq_data_dir(req) == READ, |
| 895 | sectors, sectors_ind, tottime_ind, |
| 896 | tottimeps_ind, strtime_ind, |
| 897 | irqtime_ind, irqtimeps_ind, |
| 898 | endtime_ind); |
Stefan Haberland | d290722 | 2017-07-14 10:33:18 +0200 | [diff] [blame] | 899 | } |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 900 | spin_unlock(&device->profile.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | } |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 902 | |
| 903 | void dasd_profile_reset(struct dasd_profile *profile) |
| 904 | { |
| 905 | struct dasd_profile_info *data; |
| 906 | |
| 907 | spin_lock_bh(&profile->lock); |
| 908 | data = profile->data; |
| 909 | if (!data) { |
| 910 | spin_unlock_bh(&profile->lock); |
| 911 | return; |
| 912 | } |
| 913 | memset(data, 0, sizeof(*data)); |
Arnd Bergmann | bd7a9b3 | 2017-11-27 12:46:57 +0100 | [diff] [blame] | 914 | ktime_get_real_ts64(&data->starttod); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 915 | spin_unlock_bh(&profile->lock); |
| 916 | } |
| 917 | |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 918 | int dasd_profile_on(struct dasd_profile *profile) |
| 919 | { |
| 920 | struct dasd_profile_info *data; |
| 921 | |
| 922 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 923 | if (!data) |
| 924 | return -ENOMEM; |
| 925 | spin_lock_bh(&profile->lock); |
| 926 | if (profile->data) { |
| 927 | spin_unlock_bh(&profile->lock); |
| 928 | kfree(data); |
| 929 | return 0; |
| 930 | } |
Arnd Bergmann | bd7a9b3 | 2017-11-27 12:46:57 +0100 | [diff] [blame] | 931 | ktime_get_real_ts64(&data->starttod); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 932 | profile->data = data; |
| 933 | spin_unlock_bh(&profile->lock); |
| 934 | return 0; |
| 935 | } |
| 936 | |
| 937 | void dasd_profile_off(struct dasd_profile *profile) |
| 938 | { |
| 939 | spin_lock_bh(&profile->lock); |
| 940 | kfree(profile->data); |
| 941 | profile->data = NULL; |
| 942 | spin_unlock_bh(&profile->lock); |
| 943 | } |
| 944 | |
| 945 | char *dasd_get_user_string(const char __user *user_buf, size_t user_len) |
| 946 | { |
| 947 | char *buffer; |
| 948 | |
Stefan Weinhuber | e4258d5 | 2011-08-03 16:44:20 +0200 | [diff] [blame] | 949 | buffer = vmalloc(user_len + 1); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 950 | if (buffer == NULL) |
| 951 | return ERR_PTR(-ENOMEM); |
| 952 | if (copy_from_user(buffer, user_buf, user_len) != 0) { |
Stefan Weinhuber | e4258d5 | 2011-08-03 16:44:20 +0200 | [diff] [blame] | 953 | vfree(buffer); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 954 | return ERR_PTR(-EFAULT); |
| 955 | } |
| 956 | /* got the string, now strip linefeed. */ |
| 957 | if (buffer[user_len - 1] == '\n') |
| 958 | buffer[user_len - 1] = 0; |
| 959 | else |
| 960 | buffer[user_len] = 0; |
| 961 | return buffer; |
| 962 | } |
| 963 | |
| 964 | static ssize_t dasd_stats_write(struct file *file, |
| 965 | const char __user *user_buf, |
| 966 | size_t user_len, loff_t *pos) |
| 967 | { |
| 968 | char *buffer, *str; |
| 969 | int rc; |
| 970 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 971 | struct dasd_profile *prof = m->private; |
| 972 | |
| 973 | if (user_len > 65536) |
| 974 | user_len = 65536; |
| 975 | buffer = dasd_get_user_string(user_buf, user_len); |
| 976 | if (IS_ERR(buffer)) |
| 977 | return PTR_ERR(buffer); |
| 978 | |
| 979 | str = skip_spaces(buffer); |
| 980 | rc = user_len; |
| 981 | if (strncmp(str, "reset", 5) == 0) { |
| 982 | dasd_profile_reset(prof); |
| 983 | } else if (strncmp(str, "on", 2) == 0) { |
| 984 | rc = dasd_profile_on(prof); |
Sebastian Ott | 6765cc2 | 2015-01-28 19:06:29 +0100 | [diff] [blame] | 985 | if (rc) |
| 986 | goto out; |
| 987 | rc = user_len; |
| 988 | if (prof == &dasd_global_profile) { |
| 989 | dasd_profile_reset(prof); |
| 990 | dasd_global_profile_level = DASD_PROFILE_GLOBAL_ONLY; |
| 991 | } |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 992 | } else if (strncmp(str, "off", 3) == 0) { |
Sebastian Ott | 6765cc2 | 2015-01-28 19:06:29 +0100 | [diff] [blame] | 993 | if (prof == &dasd_global_profile) |
| 994 | dasd_global_profile_level = DASD_PROFILE_OFF; |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 995 | dasd_profile_off(prof); |
| 996 | } else |
| 997 | rc = -EINVAL; |
Sebastian Ott | 6765cc2 | 2015-01-28 19:06:29 +0100 | [diff] [blame] | 998 | out: |
Stefan Weinhuber | e4258d5 | 2011-08-03 16:44:20 +0200 | [diff] [blame] | 999 | vfree(buffer); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1000 | return rc; |
| 1001 | } |
| 1002 | |
| 1003 | static void dasd_stats_array(struct seq_file *m, unsigned int *array) |
| 1004 | { |
| 1005 | int i; |
| 1006 | |
| 1007 | for (i = 0; i < 32; i++) |
| 1008 | seq_printf(m, "%u ", array[i]); |
| 1009 | seq_putc(m, '\n'); |
| 1010 | } |
| 1011 | |
| 1012 | static void dasd_stats_seq_print(struct seq_file *m, |
| 1013 | struct dasd_profile_info *data) |
| 1014 | { |
Arnd Bergmann | bd7a9b3 | 2017-11-27 12:46:57 +0100 | [diff] [blame] | 1015 | seq_printf(m, "start_time %lld.%09ld\n", |
| 1016 | (s64)data->starttod.tv_sec, data->starttod.tv_nsec); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1017 | seq_printf(m, "total_requests %u\n", data->dasd_io_reqs); |
| 1018 | seq_printf(m, "total_sectors %u\n", data->dasd_io_sects); |
| 1019 | seq_printf(m, "total_pav %u\n", data->dasd_io_alias); |
| 1020 | seq_printf(m, "total_hpf %u\n", data->dasd_io_tpm); |
Stefan Haberland | d290722 | 2017-07-14 10:33:18 +0200 | [diff] [blame] | 1021 | seq_printf(m, "avg_total %lu\n", data->dasd_io_reqs ? |
| 1022 | data->dasd_sum_times / data->dasd_io_reqs : 0UL); |
| 1023 | seq_printf(m, "avg_build_to_ssch %lu\n", data->dasd_io_reqs ? |
| 1024 | data->dasd_sum_time_str / data->dasd_io_reqs : 0UL); |
| 1025 | seq_printf(m, "avg_ssch_to_irq %lu\n", data->dasd_io_reqs ? |
| 1026 | data->dasd_sum_time_irq / data->dasd_io_reqs : 0UL); |
| 1027 | seq_printf(m, "avg_irq_to_end %lu\n", data->dasd_io_reqs ? |
| 1028 | data->dasd_sum_time_end / data->dasd_io_reqs : 0UL); |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1029 | seq_puts(m, "histogram_sectors "); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1030 | dasd_stats_array(m, data->dasd_io_secs); |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1031 | seq_puts(m, "histogram_io_times "); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1032 | dasd_stats_array(m, data->dasd_io_times); |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1033 | seq_puts(m, "histogram_io_times_weighted "); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1034 | dasd_stats_array(m, data->dasd_io_timps); |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1035 | seq_puts(m, "histogram_time_build_to_ssch "); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1036 | dasd_stats_array(m, data->dasd_io_time1); |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1037 | seq_puts(m, "histogram_time_ssch_to_irq "); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1038 | dasd_stats_array(m, data->dasd_io_time2); |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1039 | seq_puts(m, "histogram_time_ssch_to_irq_weighted "); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1040 | dasd_stats_array(m, data->dasd_io_time2ps); |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1041 | seq_puts(m, "histogram_time_irq_to_end "); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1042 | dasd_stats_array(m, data->dasd_io_time3); |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1043 | seq_puts(m, "histogram_ccw_queue_length "); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1044 | dasd_stats_array(m, data->dasd_io_nr_req); |
| 1045 | seq_printf(m, "total_read_requests %u\n", data->dasd_read_reqs); |
| 1046 | seq_printf(m, "total_read_sectors %u\n", data->dasd_read_sects); |
| 1047 | seq_printf(m, "total_read_pav %u\n", data->dasd_read_alias); |
| 1048 | seq_printf(m, "total_read_hpf %u\n", data->dasd_read_tpm); |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1049 | seq_puts(m, "histogram_read_sectors "); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1050 | dasd_stats_array(m, data->dasd_read_secs); |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1051 | seq_puts(m, "histogram_read_times "); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1052 | dasd_stats_array(m, data->dasd_read_times); |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1053 | seq_puts(m, "histogram_read_time_build_to_ssch "); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1054 | dasd_stats_array(m, data->dasd_read_time1); |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1055 | seq_puts(m, "histogram_read_time_ssch_to_irq "); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1056 | dasd_stats_array(m, data->dasd_read_time2); |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1057 | seq_puts(m, "histogram_read_time_irq_to_end "); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1058 | dasd_stats_array(m, data->dasd_read_time3); |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1059 | seq_puts(m, "histogram_read_ccw_queue_length "); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1060 | dasd_stats_array(m, data->dasd_read_nr_req); |
| 1061 | } |
| 1062 | |
| 1063 | static int dasd_stats_show(struct seq_file *m, void *v) |
| 1064 | { |
| 1065 | struct dasd_profile *profile; |
| 1066 | struct dasd_profile_info *data; |
| 1067 | |
| 1068 | profile = m->private; |
| 1069 | spin_lock_bh(&profile->lock); |
| 1070 | data = profile->data; |
| 1071 | if (!data) { |
| 1072 | spin_unlock_bh(&profile->lock); |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1073 | seq_puts(m, "disabled\n"); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1074 | return 0; |
| 1075 | } |
| 1076 | dasd_stats_seq_print(m, data); |
| 1077 | spin_unlock_bh(&profile->lock); |
| 1078 | return 0; |
| 1079 | } |
| 1080 | |
| 1081 | static int dasd_stats_open(struct inode *inode, struct file *file) |
| 1082 | { |
| 1083 | struct dasd_profile *profile = inode->i_private; |
| 1084 | return single_open(file, dasd_stats_show, profile); |
| 1085 | } |
| 1086 | |
| 1087 | static const struct file_operations dasd_stats_raw_fops = { |
| 1088 | .owner = THIS_MODULE, |
| 1089 | .open = dasd_stats_open, |
| 1090 | .read = seq_read, |
| 1091 | .llseek = seq_lseek, |
| 1092 | .release = single_release, |
| 1093 | .write = dasd_stats_write, |
| 1094 | }; |
| 1095 | |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1096 | static void dasd_profile_init(struct dasd_profile *profile, |
| 1097 | struct dentry *base_dentry) |
| 1098 | { |
Al Viro | f4ae40a6 | 2011-07-24 04:33:43 -0400 | [diff] [blame] | 1099 | umode_t mode; |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1100 | struct dentry *pde; |
| 1101 | |
| 1102 | if (!base_dentry) |
| 1103 | return; |
| 1104 | profile->dentry = NULL; |
| 1105 | profile->data = NULL; |
| 1106 | mode = (S_IRUSR | S_IWUSR | S_IFREG); |
| 1107 | pde = debugfs_create_file("statistics", mode, base_dentry, |
| 1108 | profile, &dasd_stats_raw_fops); |
| 1109 | if (pde && !IS_ERR(pde)) |
| 1110 | profile->dentry = pde; |
| 1111 | return; |
| 1112 | } |
| 1113 | |
| 1114 | static void dasd_profile_exit(struct dasd_profile *profile) |
| 1115 | { |
| 1116 | dasd_profile_off(profile); |
Fabian Frederick | d7309aa | 2014-06-26 19:41:46 +0200 | [diff] [blame] | 1117 | debugfs_remove(profile->dentry); |
| 1118 | profile->dentry = NULL; |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | static void dasd_statistics_removeroot(void) |
| 1122 | { |
| 1123 | dasd_global_profile_level = DASD_PROFILE_OFF; |
Sebastian Ott | 6765cc2 | 2015-01-28 19:06:29 +0100 | [diff] [blame] | 1124 | dasd_profile_exit(&dasd_global_profile); |
Fabian Frederick | d7309aa | 2014-06-26 19:41:46 +0200 | [diff] [blame] | 1125 | debugfs_remove(dasd_debugfs_global_entry); |
| 1126 | debugfs_remove(dasd_debugfs_root_entry); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | static void dasd_statistics_createroot(void) |
| 1130 | { |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1131 | struct dentry *pde; |
| 1132 | |
| 1133 | dasd_debugfs_root_entry = NULL; |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1134 | pde = debugfs_create_dir("dasd", NULL); |
| 1135 | if (!pde || IS_ERR(pde)) |
| 1136 | goto error; |
| 1137 | dasd_debugfs_root_entry = pde; |
| 1138 | pde = debugfs_create_dir("global", dasd_debugfs_root_entry); |
| 1139 | if (!pde || IS_ERR(pde)) |
| 1140 | goto error; |
| 1141 | dasd_debugfs_global_entry = pde; |
Sebastian Ott | 6765cc2 | 2015-01-28 19:06:29 +0100 | [diff] [blame] | 1142 | dasd_profile_init(&dasd_global_profile, dasd_debugfs_global_entry); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1143 | return; |
| 1144 | |
| 1145 | error: |
| 1146 | DBF_EVENT(DBF_ERR, "%s", |
| 1147 | "Creation of the dasd debugfs interface failed"); |
| 1148 | dasd_statistics_removeroot(); |
| 1149 | return; |
| 1150 | } |
| 1151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | #else |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1153 | #define dasd_profile_start(block, cqr, req) do {} while (0) |
| 1154 | #define dasd_profile_end(block, cqr, req) do {} while (0) |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1155 | |
| 1156 | static void dasd_statistics_createroot(void) |
| 1157 | { |
| 1158 | return; |
| 1159 | } |
| 1160 | |
| 1161 | static void dasd_statistics_removeroot(void) |
| 1162 | { |
| 1163 | return; |
| 1164 | } |
| 1165 | |
| 1166 | int dasd_stats_generic_show(struct seq_file *m, void *v) |
| 1167 | { |
Fabian Frederick | c794caf | 2014-06-26 19:41:49 +0200 | [diff] [blame] | 1168 | seq_puts(m, "Statistics are not activated in this kernel\n"); |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 1169 | return 0; |
| 1170 | } |
| 1171 | |
| 1172 | static void dasd_profile_init(struct dasd_profile *profile, |
| 1173 | struct dentry *base_dentry) |
| 1174 | { |
| 1175 | return; |
| 1176 | } |
| 1177 | |
| 1178 | static void dasd_profile_exit(struct dasd_profile *profile) |
| 1179 | { |
| 1180 | return; |
| 1181 | } |
| 1182 | |
| 1183 | int dasd_profile_on(struct dasd_profile *profile) |
| 1184 | { |
| 1185 | return 0; |
| 1186 | } |
| 1187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | #endif /* CONFIG_DASD_PROFILE */ |
| 1189 | |
Stefan Haberland | 5a3b7b1 | 2016-03-18 09:42:13 +0100 | [diff] [blame] | 1190 | static int dasd_hosts_show(struct seq_file *m, void *v) |
| 1191 | { |
| 1192 | struct dasd_device *device; |
| 1193 | int rc = -EOPNOTSUPP; |
| 1194 | |
| 1195 | device = m->private; |
| 1196 | dasd_get_device(device); |
| 1197 | |
| 1198 | if (device->discipline->hosts_print) |
| 1199 | rc = device->discipline->hosts_print(device, m); |
| 1200 | |
| 1201 | dasd_put_device(device); |
| 1202 | return rc; |
| 1203 | } |
| 1204 | |
Yangtao Li | ca92b93 | 2018-12-01 22:28:11 -0500 | [diff] [blame] | 1205 | DEFINE_SHOW_ATTRIBUTE(dasd_hosts); |
Stefan Haberland | 5a3b7b1 | 2016-03-18 09:42:13 +0100 | [diff] [blame] | 1206 | |
| 1207 | static void dasd_hosts_exit(struct dasd_device *device) |
| 1208 | { |
| 1209 | debugfs_remove(device->hosts_dentry); |
| 1210 | device->hosts_dentry = NULL; |
| 1211 | } |
| 1212 | |
| 1213 | static void dasd_hosts_init(struct dentry *base_dentry, |
| 1214 | struct dasd_device *device) |
| 1215 | { |
| 1216 | struct dentry *pde; |
| 1217 | umode_t mode; |
| 1218 | |
| 1219 | if (!base_dentry) |
| 1220 | return; |
| 1221 | |
| 1222 | mode = S_IRUSR | S_IFREG; |
| 1223 | pde = debugfs_create_file("host_access_list", mode, base_dentry, |
| 1224 | device, &dasd_hosts_fops); |
| 1225 | if (pde && !IS_ERR(pde)) |
| 1226 | device->hosts_dentry = pde; |
| 1227 | } |
| 1228 | |
Sebastian Ott | c5205f2 | 2018-06-04 19:07:39 +0200 | [diff] [blame] | 1229 | struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength, int datasize, |
| 1230 | struct dasd_device *device, |
| 1231 | struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | { |
| 1233 | unsigned long flags; |
Sebastian Ott | c5205f2 | 2018-06-04 19:07:39 +0200 | [diff] [blame] | 1234 | char *data, *chunk; |
| 1235 | int size = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | if (cplength > 0) |
| 1238 | size += cplength * sizeof(struct ccw1); |
| 1239 | if (datasize > 0) |
| 1240 | size += datasize; |
Sebastian Ott | c5205f2 | 2018-06-04 19:07:39 +0200 | [diff] [blame] | 1241 | if (!cqr) |
| 1242 | size += (sizeof(*cqr) + 7L) & -8L; |
| 1243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | spin_lock_irqsave(&device->mem_lock, flags); |
Sebastian Ott | c5205f2 | 2018-06-04 19:07:39 +0200 | [diff] [blame] | 1245 | data = chunk = dasd_alloc_chunk(&device->ccw_chunks, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | spin_unlock_irqrestore(&device->mem_lock, flags); |
Sebastian Ott | c5205f2 | 2018-06-04 19:07:39 +0200 | [diff] [blame] | 1247 | if (!chunk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | return ERR_PTR(-ENOMEM); |
Sebastian Ott | c5205f2 | 2018-06-04 19:07:39 +0200 | [diff] [blame] | 1249 | if (!cqr) { |
| 1250 | cqr = (void *) data; |
| 1251 | data += (sizeof(*cqr) + 7L) & -8L; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | } |
Sebastian Ott | c5205f2 | 2018-06-04 19:07:39 +0200 | [diff] [blame] | 1253 | memset(cqr, 0, sizeof(*cqr)); |
| 1254 | cqr->mem_chunk = chunk; |
| 1255 | if (cplength > 0) { |
| 1256 | cqr->cpaddr = data; |
| 1257 | data += cplength * sizeof(struct ccw1); |
| 1258 | memset(cqr->cpaddr, 0, cplength * sizeof(struct ccw1)); |
| 1259 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | if (datasize > 0) { |
| 1261 | cqr->data = data; |
| 1262 | memset(cqr->data, 0, datasize); |
| 1263 | } |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 1264 | cqr->magic = magic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 1266 | dasd_get_device(device); |
| 1267 | return cqr; |
| 1268 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 1269 | EXPORT_SYMBOL(dasd_smalloc_request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | |
Jan Höppner | 5e2b17e | 2018-04-27 16:51:22 +0200 | [diff] [blame] | 1271 | struct dasd_ccw_req *dasd_fmalloc_request(int magic, int cplength, |
| 1272 | int datasize, |
| 1273 | struct dasd_device *device) |
| 1274 | { |
| 1275 | struct dasd_ccw_req *cqr; |
| 1276 | unsigned long flags; |
| 1277 | int size, cqr_size; |
| 1278 | char *data; |
| 1279 | |
| 1280 | cqr_size = (sizeof(*cqr) + 7L) & -8L; |
| 1281 | size = cqr_size; |
| 1282 | if (cplength > 0) |
| 1283 | size += cplength * sizeof(struct ccw1); |
| 1284 | if (datasize > 0) |
| 1285 | size += datasize; |
| 1286 | |
| 1287 | spin_lock_irqsave(&device->mem_lock, flags); |
| 1288 | cqr = dasd_alloc_chunk(&device->ese_chunks, size); |
| 1289 | spin_unlock_irqrestore(&device->mem_lock, flags); |
| 1290 | if (!cqr) |
| 1291 | return ERR_PTR(-ENOMEM); |
| 1292 | memset(cqr, 0, sizeof(*cqr)); |
| 1293 | data = (char *)cqr + cqr_size; |
| 1294 | cqr->cpaddr = NULL; |
| 1295 | if (cplength > 0) { |
| 1296 | cqr->cpaddr = data; |
| 1297 | data += cplength * sizeof(struct ccw1); |
| 1298 | memset(cqr->cpaddr, 0, cplength * sizeof(struct ccw1)); |
| 1299 | } |
| 1300 | cqr->data = NULL; |
| 1301 | if (datasize > 0) { |
| 1302 | cqr->data = data; |
| 1303 | memset(cqr->data, 0, datasize); |
| 1304 | } |
| 1305 | |
| 1306 | cqr->magic = magic; |
| 1307 | set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 1308 | dasd_get_device(device); |
| 1309 | |
| 1310 | return cqr; |
| 1311 | } |
| 1312 | EXPORT_SYMBOL(dasd_fmalloc_request); |
| 1313 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1314 | void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | { |
| 1316 | unsigned long flags; |
| 1317 | |
| 1318 | spin_lock_irqsave(&device->mem_lock, flags); |
Sebastian Ott | c5205f2 | 2018-06-04 19:07:39 +0200 | [diff] [blame] | 1319 | dasd_free_chunk(&device->ccw_chunks, cqr->mem_chunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | spin_unlock_irqrestore(&device->mem_lock, flags); |
| 1321 | dasd_put_device(device); |
| 1322 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 1323 | EXPORT_SYMBOL(dasd_sfree_request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | |
Jan Höppner | 5e2b17e | 2018-04-27 16:51:22 +0200 | [diff] [blame] | 1325 | void dasd_ffree_request(struct dasd_ccw_req *cqr, struct dasd_device *device) |
| 1326 | { |
| 1327 | unsigned long flags; |
| 1328 | |
| 1329 | spin_lock_irqsave(&device->mem_lock, flags); |
| 1330 | dasd_free_chunk(&device->ese_chunks, cqr); |
| 1331 | spin_unlock_irqrestore(&device->mem_lock, flags); |
| 1332 | dasd_put_device(device); |
| 1333 | } |
| 1334 | EXPORT_SYMBOL(dasd_ffree_request); |
| 1335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | /* |
| 1337 | * Check discipline magic in cqr. |
| 1338 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1339 | static inline int dasd_check_cqr(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | { |
| 1341 | struct dasd_device *device; |
| 1342 | |
| 1343 | if (cqr == NULL) |
| 1344 | return -EINVAL; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1345 | device = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1347 | DBF_DEV_EVENT(DBF_WARNING, device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | " dasd_ccw_req 0x%08x magic doesn't match" |
| 1349 | " discipline 0x%08x", |
| 1350 | cqr->magic, |
| 1351 | *(unsigned int *) device->discipline->name); |
| 1352 | return -EINVAL; |
| 1353 | } |
| 1354 | return 0; |
| 1355 | } |
| 1356 | |
| 1357 | /* |
| 1358 | * Terminate the current i/o and set the request to clear_pending. |
| 1359 | * Timer keeps device runnig. |
| 1360 | * ccw_device_clear can fail if the i/o subsystem |
| 1361 | * is in a bad mood. |
| 1362 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1363 | int dasd_term_IO(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | { |
| 1365 | struct dasd_device *device; |
| 1366 | int retries, rc; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1367 | char errorstring[ERRORLENGTH]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | |
| 1369 | /* Check the cqr */ |
| 1370 | rc = dasd_check_cqr(cqr); |
| 1371 | if (rc) |
| 1372 | return rc; |
| 1373 | retries = 0; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1374 | device = (struct dasd_device *) cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) { |
| 1376 | rc = ccw_device_clear(device->cdev, (long) cqr); |
| 1377 | switch (rc) { |
| 1378 | case 0: /* termination successful */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1379 | cqr->status = DASD_CQR_CLEAR_PENDING; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 1380 | cqr->stopclk = get_tod_clock(); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 1381 | cqr->starttime = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | DBF_DEV_EVENT(DBF_DEBUG, device, |
| 1383 | "terminate cqr %p successful", |
| 1384 | cqr); |
| 1385 | break; |
| 1386 | case -ENODEV: |
| 1387 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
| 1388 | "device gone, retry"); |
| 1389 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | case -EINVAL: |
Stefan Haberland | 2c17124 | 2014-11-24 10:53:19 +0100 | [diff] [blame] | 1391 | /* |
| 1392 | * device not valid so no I/O could be running |
| 1393 | * handle CQR as termination successful |
| 1394 | */ |
| 1395 | cqr->status = DASD_CQR_CLEARED; |
| 1396 | cqr->stopclk = get_tod_clock(); |
| 1397 | cqr->starttime = 0; |
| 1398 | /* no retries for invalid devices */ |
| 1399 | cqr->retries = -1; |
| 1400 | DBF_DEV_EVENT(DBF_ERR, device, "%s", |
| 1401 | "EINVAL, handle as terminated"); |
| 1402 | /* fake rc to success */ |
| 1403 | rc = 0; |
| 1404 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | default: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1406 | /* internal error 10 - unknown rc*/ |
| 1407 | snprintf(errorstring, ERRORLENGTH, "10 %d", rc); |
| 1408 | dev_err(&device->cdev->dev, "An error occurred in the " |
| 1409 | "DASD device driver, reason=%s\n", errorstring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | BUG(); |
| 1411 | break; |
| 1412 | } |
| 1413 | retries++; |
| 1414 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1415 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | return rc; |
| 1417 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 1418 | EXPORT_SYMBOL(dasd_term_IO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | |
| 1420 | /* |
| 1421 | * Start the i/o. This start_IO can fail if the channel is really busy. |
| 1422 | * In that case set up a timer to start the request later. |
| 1423 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1424 | int dasd_start_IO(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | { |
| 1426 | struct dasd_device *device; |
| 1427 | int rc; |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1428 | char errorstring[ERRORLENGTH]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | |
| 1430 | /* Check the cqr */ |
| 1431 | rc = dasd_check_cqr(cqr); |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 1432 | if (rc) { |
| 1433 | cqr->intrc = rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | return rc; |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 1435 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1436 | device = (struct dasd_device *) cqr->startdev; |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 1437 | if (((cqr->block && |
| 1438 | test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) || |
| 1439 | test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) && |
| 1440 | !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) { |
| 1441 | DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p " |
| 1442 | "because of stolen lock", cqr); |
| 1443 | cqr->status = DASD_CQR_ERROR; |
| 1444 | cqr->intrc = -EPERM; |
| 1445 | return -EPERM; |
| 1446 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | if (cqr->retries < 0) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1448 | /* internal error 14 - start_IO run out of retries */ |
| 1449 | sprintf(errorstring, "14 %p", cqr); |
| 1450 | dev_err(&device->cdev->dev, "An error occurred in the DASD " |
| 1451 | "device driver, reason=%s\n", errorstring); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1452 | cqr->status = DASD_CQR_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | return -EIO; |
| 1454 | } |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 1455 | cqr->startclk = get_tod_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | cqr->starttime = jiffies; |
| 1457 | cqr->retries--; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1458 | if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) { |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 1459 | cqr->lpm &= dasd_path_get_opm(device); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1460 | if (!cqr->lpm) |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 1461 | cqr->lpm = dasd_path_get_opm(device); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1462 | } |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1463 | if (cqr->cpmode == 1) { |
| 1464 | rc = ccw_device_tm_start(device->cdev, cqr->cpaddr, |
| 1465 | (long) cqr, cqr->lpm); |
| 1466 | } else { |
| 1467 | rc = ccw_device_start(device->cdev, cqr->cpaddr, |
| 1468 | (long) cqr, cqr->lpm, 0); |
| 1469 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | switch (rc) { |
| 1471 | case 0: |
| 1472 | cqr->status = DASD_CQR_IN_IO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | break; |
| 1474 | case -EBUSY: |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1475 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | "start_IO: device busy, retry later"); |
| 1477 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | case -EACCES: |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1479 | /* -EACCES indicates that the request used only a subset of the |
| 1480 | * available paths and all these paths are gone. If the lpm of |
| 1481 | * this request was only a subset of the opm (e.g. the ppm) then |
| 1482 | * we just do a retry with all available paths. |
| 1483 | * If we already use the full opm, something is amiss, and we |
| 1484 | * need a full path verification. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | */ |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1486 | if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) { |
| 1487 | DBF_DEV_EVENT(DBF_WARNING, device, |
| 1488 | "start_IO: selected paths gone (%x)", |
| 1489 | cqr->lpm); |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 1490 | } else if (cqr->lpm != dasd_path_get_opm(device)) { |
| 1491 | cqr->lpm = dasd_path_get_opm(device); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1492 | DBF_DEV_EVENT(DBF_DEBUG, device, "%s", |
| 1493 | "start_IO: selected paths gone," |
| 1494 | " retry on all paths"); |
| 1495 | } else { |
| 1496 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
| 1497 | "start_IO: all paths in opm gone," |
| 1498 | " do path verification"); |
| 1499 | dasd_generic_last_path_gone(device); |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 1500 | dasd_path_no_path(device); |
| 1501 | dasd_path_set_tbvpm(device, |
| 1502 | ccw_device_get_path_mask( |
| 1503 | device->cdev)); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1504 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | break; |
| 1506 | case -ENODEV: |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1507 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1508 | "start_IO: -ENODEV device gone, retry"); |
| 1509 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | case -EIO: |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1511 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1512 | "start_IO: -EIO device gone, retry"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | break; |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 1514 | case -EINVAL: |
| 1515 | /* most likely caused in power management context */ |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1516 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 1517 | "start_IO: -EINVAL device currently " |
| 1518 | "not accessible"); |
| 1519 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | default: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1521 | /* internal error 11 - unknown rc */ |
| 1522 | snprintf(errorstring, ERRORLENGTH, "11 %d", rc); |
| 1523 | dev_err(&device->cdev->dev, |
| 1524 | "An error occurred in the DASD device driver, " |
| 1525 | "reason=%s\n", errorstring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | BUG(); |
| 1527 | break; |
| 1528 | } |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 1529 | cqr->intrc = rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | return rc; |
| 1531 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 1532 | EXPORT_SYMBOL(dasd_start_IO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | |
| 1534 | /* |
| 1535 | * Timeout function for dasd devices. This is used for different purposes |
| 1536 | * 1) missing interrupt handler for normal operation |
| 1537 | * 2) delayed start of request where start_IO failed with -EBUSY |
| 1538 | * 3) timeout for missing state change interrupts |
| 1539 | * The head of the ccw queue will have status DASD_CQR_IN_IO for 1), |
| 1540 | * DASD_CQR_QUEUED for 2) and 3). |
| 1541 | */ |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 1542 | static void dasd_device_timeout(struct timer_list *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | { |
| 1544 | unsigned long flags; |
| 1545 | struct dasd_device *device; |
| 1546 | |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 1547 | device = from_timer(device, t, timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 1549 | /* re-activate request queue */ |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1550 | dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1552 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | /* |
| 1556 | * Setup timeout for a device in jiffies. |
| 1557 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1558 | void dasd_device_set_timer(struct dasd_device *device, int expires) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | { |
Stefan Weinhuber | 48cae88 | 2009-02-11 10:37:31 +0100 | [diff] [blame] | 1560 | if (expires == 0) |
| 1561 | del_timer(&device->timer); |
| 1562 | else |
| 1563 | mod_timer(&device->timer, jiffies + expires); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 1565 | EXPORT_SYMBOL(dasd_device_set_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | |
| 1567 | /* |
| 1568 | * Clear timeout for a device. |
| 1569 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1570 | void dasd_device_clear_timer(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | { |
Stefan Weinhuber | 48cae88 | 2009-02-11 10:37:31 +0100 | [diff] [blame] | 1572 | del_timer(&device->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 1574 | EXPORT_SYMBOL(dasd_device_clear_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1576 | static void dasd_handle_killed_request(struct ccw_device *cdev, |
| 1577 | unsigned long intparm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | { |
| 1579 | struct dasd_ccw_req *cqr; |
| 1580 | struct dasd_device *device; |
| 1581 | |
Stefan Weinhuber | f16f5843 | 2008-05-15 16:52:36 +0200 | [diff] [blame] | 1582 | if (!intparm) |
| 1583 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | cqr = (struct dasd_ccw_req *) intparm; |
| 1585 | if (cqr->status != DASD_CQR_IN_IO) { |
Stefan Haberland | b8ed5dd | 2009-12-07 12:51:52 +0100 | [diff] [blame] | 1586 | DBF_EVENT_DEVID(DBF_DEBUG, cdev, |
| 1587 | "invalid status in handle_killed_request: " |
| 1588 | "%02x", cqr->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | return; |
| 1590 | } |
| 1591 | |
Stefan Haberland | 589c74d | 2010-02-26 22:37:47 +0100 | [diff] [blame] | 1592 | device = dasd_device_from_cdev_locked(cdev); |
| 1593 | if (IS_ERR(device)) { |
| 1594 | DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s", |
| 1595 | "unable to get device from cdev"); |
| 1596 | return; |
| 1597 | } |
| 1598 | |
| 1599 | if (!cqr->startdev || |
| 1600 | device != cqr->startdev || |
| 1601 | strncmp(cqr->startdev->discipline->ebcname, |
| 1602 | (char *) &cqr->magic, 4)) { |
Stefan Haberland | 294001a | 2010-01-27 10:12:35 +0100 | [diff] [blame] | 1603 | DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s", |
| 1604 | "invalid device in request"); |
Stefan Haberland | 589c74d | 2010-02-26 22:37:47 +0100 | [diff] [blame] | 1605 | dasd_put_device(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | return; |
| 1607 | } |
| 1608 | |
| 1609 | /* Schedule request to be retried. */ |
| 1610 | cqr->status = DASD_CQR_QUEUED; |
| 1611 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1612 | dasd_device_clear_timer(device); |
| 1613 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | dasd_put_device(device); |
| 1615 | } |
| 1616 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1617 | void dasd_generic_handle_state_change(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | { |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 1619 | /* First of all start sense subsystem status request. */ |
| 1620 | dasd_eer_snss(device); |
| 1621 | |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 1622 | dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1623 | dasd_schedule_device_bh(device); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 1624 | if (device->block) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1625 | dasd_schedule_block_bh(device->block); |
Stefan Haberland | 673514a | 2017-09-12 17:22:42 +0200 | [diff] [blame] | 1626 | if (device->block->request_queue) |
| 1627 | blk_mq_run_hw_queues(device->block->request_queue, |
| 1628 | true); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 1629 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 1631 | EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | |
Stefan Haberland | a521b04 | 2016-08-08 15:56:54 +0200 | [diff] [blame] | 1633 | static int dasd_check_hpf_error(struct irb *irb) |
| 1634 | { |
| 1635 | return (scsw_tm_is_valid_schxs(&irb->scsw) && |
| 1636 | (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX || |
| 1637 | irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX)); |
| 1638 | } |
| 1639 | |
Jan Höppner | 5e2b17e | 2018-04-27 16:51:22 +0200 | [diff] [blame] | 1640 | static int dasd_ese_needs_format(struct dasd_block *block, struct irb *irb) |
| 1641 | { |
| 1642 | struct dasd_device *device = NULL; |
| 1643 | u8 *sense = NULL; |
| 1644 | |
| 1645 | if (!block) |
| 1646 | return 0; |
| 1647 | device = block->base; |
| 1648 | if (!device || !device->discipline->is_ese) |
| 1649 | return 0; |
| 1650 | if (!device->discipline->is_ese(device)) |
| 1651 | return 0; |
| 1652 | |
| 1653 | sense = dasd_get_sense(irb); |
| 1654 | if (!sense) |
| 1655 | return 0; |
| 1656 | |
| 1657 | return !!(sense[1] & SNS1_NO_REC_FOUND) || |
| 1658 | !!(sense[1] & SNS1_FILE_PROTECTED) || |
| 1659 | scsw_cstat(&irb->scsw) == SCHN_STAT_INCORR_LEN; |
| 1660 | } |
| 1661 | |
Jan Höppner | 9e12e54 | 2018-07-03 10:56:51 +0200 | [diff] [blame] | 1662 | static int dasd_ese_oos_cond(u8 *sense) |
| 1663 | { |
| 1664 | return sense[0] & SNS0_EQUIPMENT_CHECK && |
| 1665 | sense[1] & SNS1_PERM_ERR && |
| 1666 | sense[1] & SNS1_WRITE_INHIBITED && |
| 1667 | sense[25] == 0x01; |
| 1668 | } |
| 1669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | /* |
| 1671 | * Interrupt handler for "normal" ssch-io based dasd devices. |
| 1672 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1673 | void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm, |
| 1674 | struct irb *irb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | { |
Jan Höppner | 5e2b17e | 2018-04-27 16:51:22 +0200 | [diff] [blame] | 1676 | struct dasd_ccw_req *cqr, *next, *fcqr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | struct dasd_device *device; |
Jan Höppner | 7bf76f01 | 2017-08-15 16:40:18 +0200 | [diff] [blame] | 1678 | unsigned long now; |
Jan Höppner | 8fd5752 | 2015-08-19 13:41:20 +0200 | [diff] [blame] | 1679 | int nrf_suppressed = 0; |
| 1680 | int fp_suppressed = 0; |
| 1681 | u8 *sense = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | int expires; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | |
Stefan Haberland | 9ba333d | 2016-08-08 14:08:17 +0200 | [diff] [blame] | 1684 | cqr = (struct dasd_ccw_req *) intparm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | if (IS_ERR(irb)) { |
| 1686 | switch (PTR_ERR(irb)) { |
| 1687 | case -EIO: |
Stefan Haberland | 9ba333d | 2016-08-08 14:08:17 +0200 | [diff] [blame] | 1688 | if (cqr && cqr->status == DASD_CQR_CLEAR_PENDING) { |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 1689 | device = cqr->startdev; |
Stefan Haberland | 9ba333d | 2016-08-08 14:08:17 +0200 | [diff] [blame] | 1690 | cqr->status = DASD_CQR_CLEARED; |
| 1691 | dasd_device_clear_timer(device); |
| 1692 | wake_up(&dasd_flush_wq); |
| 1693 | dasd_schedule_device_bh(device); |
| 1694 | return; |
| 1695 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | break; |
| 1697 | case -ETIMEDOUT: |
Stefan Haberland | b8ed5dd | 2009-12-07 12:51:52 +0100 | [diff] [blame] | 1698 | DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: " |
| 1699 | "request timed out\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | break; |
| 1701 | default: |
Stefan Haberland | b8ed5dd | 2009-12-07 12:51:52 +0100 | [diff] [blame] | 1702 | DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: " |
| 1703 | "unknown error %ld\n", __func__, |
| 1704 | PTR_ERR(irb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | } |
Stefan Weinhuber | f16f5843 | 2008-05-15 16:52:36 +0200 | [diff] [blame] | 1706 | dasd_handle_killed_request(cdev, intparm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | return; |
| 1708 | } |
| 1709 | |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 1710 | now = get_tod_clock(); |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 1711 | /* check for conditions that should be handled immediately */ |
| 1712 | if (!cqr || |
| 1713 | !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) && |
| 1714 | scsw_cstat(&irb->scsw) == 0)) { |
Stefan Weinhuber | a5a0061 | 2010-10-25 16:10:47 +0200 | [diff] [blame] | 1715 | if (cqr) |
| 1716 | memcpy(&cqr->irb, irb, sizeof(*irb)); |
Martin Schwidefsky | a00bfd7 | 2006-09-20 15:59:05 +0200 | [diff] [blame] | 1717 | device = dasd_device_from_cdev_locked(cdev); |
Stefan Haberland | 56b86b6 | 2010-10-25 16:10:49 +0200 | [diff] [blame] | 1718 | if (IS_ERR(device)) |
| 1719 | return; |
| 1720 | /* ignore unsolicited interrupts for DIAG discipline */ |
| 1721 | if (device->discipline == dasd_diag_discipline_pointer) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | dasd_put_device(device); |
Stefan Haberland | 56b86b6 | 2010-10-25 16:10:49 +0200 | [diff] [blame] | 1723 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | } |
Jan Höppner | 8fd5752 | 2015-08-19 13:41:20 +0200 | [diff] [blame] | 1725 | |
| 1726 | /* |
| 1727 | * In some cases 'File Protected' or 'No Record Found' errors |
| 1728 | * might be expected and debug log messages for the |
| 1729 | * corresponding interrupts shouldn't be written then. |
| 1730 | * Check if either of the according suppress bits is set. |
| 1731 | */ |
| 1732 | sense = dasd_get_sense(irb); |
| 1733 | if (sense) { |
| 1734 | fp_suppressed = (sense[1] & SNS1_FILE_PROTECTED) && |
| 1735 | test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags); |
| 1736 | nrf_suppressed = (sense[1] & SNS1_NO_REC_FOUND) && |
| 1737 | test_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags); |
Jan Höppner | 9e12e54 | 2018-07-03 10:56:51 +0200 | [diff] [blame] | 1738 | |
| 1739 | /* |
| 1740 | * Extent pool probably out-of-space. |
| 1741 | * Stop device and check exhaust level. |
| 1742 | */ |
| 1743 | if (dasd_ese_oos_cond(sense)) { |
| 1744 | dasd_generic_space_exhaust(device, cqr); |
| 1745 | device->discipline->ext_pool_exhaust(device, cqr); |
| 1746 | dasd_put_device(device); |
| 1747 | return; |
| 1748 | } |
Jan Höppner | 8fd5752 | 2015-08-19 13:41:20 +0200 | [diff] [blame] | 1749 | } |
| 1750 | if (!(fp_suppressed || nrf_suppressed)) |
| 1751 | device->discipline->dump_sense_dbf(device, irb, "int"); |
| 1752 | |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 1753 | if (device->features & DASD_FEATURE_ERPLOG) |
| 1754 | device->discipline->dump_sense(device, cqr, irb); |
| 1755 | device->discipline->check_for_device_change(device, cqr, irb); |
Stefan Haberland | 56b86b6 | 2010-10-25 16:10:49 +0200 | [diff] [blame] | 1756 | dasd_put_device(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | } |
Stefan Haberland | 5db8440 | 2014-10-01 14:39:47 +0200 | [diff] [blame] | 1758 | |
| 1759 | /* check for for attention message */ |
| 1760 | if (scsw_dstat(&irb->scsw) & DEV_STAT_ATTENTION) { |
| 1761 | device = dasd_device_from_cdev_locked(cdev); |
Stefan Haberland | 2202134 | 2017-01-25 14:47:32 +0100 | [diff] [blame] | 1762 | if (!IS_ERR(device)) { |
| 1763 | device->discipline->check_attention(device, |
| 1764 | irb->esw.esw1.lpum); |
| 1765 | dasd_put_device(device); |
| 1766 | } |
Stefan Haberland | 5db8440 | 2014-10-01 14:39:47 +0200 | [diff] [blame] | 1767 | } |
| 1768 | |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 1769 | if (!cqr) |
| 1770 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1772 | device = (struct dasd_device *) cqr->startdev; |
| 1773 | if (!device || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) { |
Stefan Haberland | 294001a | 2010-01-27 10:12:35 +0100 | [diff] [blame] | 1775 | DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s", |
| 1776 | "invalid device in request"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | return; |
| 1778 | } |
| 1779 | |
Jan Höppner | 5e2b17e | 2018-04-27 16:51:22 +0200 | [diff] [blame] | 1780 | if (dasd_ese_needs_format(cqr->block, irb)) { |
| 1781 | if (rq_data_dir((struct request *)cqr->callback_data) == READ) { |
| 1782 | device->discipline->ese_read(cqr); |
| 1783 | cqr->status = DASD_CQR_SUCCESS; |
| 1784 | cqr->stopclk = now; |
| 1785 | dasd_device_clear_timer(device); |
| 1786 | dasd_schedule_device_bh(device); |
| 1787 | return; |
| 1788 | } |
| 1789 | fcqr = device->discipline->ese_format(device, cqr); |
| 1790 | if (IS_ERR(fcqr)) { |
| 1791 | /* |
| 1792 | * If we can't format now, let the request go |
| 1793 | * one extra round. Maybe we can format later. |
| 1794 | */ |
| 1795 | cqr->status = DASD_CQR_QUEUED; |
| 1796 | } else { |
| 1797 | fcqr->status = DASD_CQR_QUEUED; |
| 1798 | cqr->status = DASD_CQR_QUEUED; |
| 1799 | list_add(&fcqr->devlist, &device->ccw_queue); |
| 1800 | dasd_schedule_device_bh(device); |
| 1801 | return; |
| 1802 | } |
| 1803 | } |
| 1804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | /* Check for clear pending */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1806 | if (cqr->status == DASD_CQR_CLEAR_PENDING && |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1807 | scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1808 | cqr->status = DASD_CQR_CLEARED; |
| 1809 | dasd_device_clear_timer(device); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 1810 | wake_up(&dasd_flush_wq); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1811 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | return; |
| 1813 | } |
| 1814 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1815 | /* check status - the request might have been killed by dyn detach */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | if (cqr->status != DASD_CQR_IN_IO) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1817 | DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, " |
| 1818 | "status %02x", dev_name(&cdev->dev), cqr->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | return; |
| 1820 | } |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1821 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1822 | next = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | expires = 0; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1824 | if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) && |
| 1825 | scsw_cstat(&irb->scsw) == 0) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1826 | /* request was completed successfully */ |
| 1827 | cqr->status = DASD_CQR_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | cqr->stopclk = now; |
| 1829 | /* Start first request on queue if possible -> fast_io. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1830 | if (cqr->devlist.next != &device->ccw_queue) { |
| 1831 | next = list_entry(cqr->devlist.next, |
| 1832 | struct dasd_ccw_req, devlist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1834 | } else { /* error */ |
Stefan Haberland | a521b04 | 2016-08-08 15:56:54 +0200 | [diff] [blame] | 1835 | /* check for HPF error |
| 1836 | * call discipline function to requeue all requests |
| 1837 | * and disable HPF accordingly |
| 1838 | */ |
| 1839 | if (cqr->cpmode && dasd_check_hpf_error(irb) && |
| 1840 | device->discipline->handle_hpf_error) |
| 1841 | device->discipline->handle_hpf_error(device, irb); |
Stefan Haberland | 6c5f57c | 2008-02-05 16:50:46 +0100 | [diff] [blame] | 1842 | /* |
| 1843 | * If we don't want complex ERP for this request, then just |
| 1844 | * reset this and retry it in the fastpath |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1845 | */ |
Stefan Haberland | 6c5f57c | 2008-02-05 16:50:46 +0100 | [diff] [blame] | 1846 | if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) && |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1847 | cqr->retries > 0) { |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 1848 | if (cqr->lpm == dasd_path_get_opm(device)) |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1849 | DBF_DEV_EVENT(DBF_DEBUG, device, |
| 1850 | "default ERP in fastpath " |
| 1851 | "(%i retries left)", |
| 1852 | cqr->retries); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 1853 | if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 1854 | cqr->lpm = dasd_path_get_opm(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1855 | cqr->status = DASD_CQR_QUEUED; |
| 1856 | next = cqr; |
| 1857 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | cqr->status = DASD_CQR_ERROR; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1859 | } |
| 1860 | if (next && (next->status == DASD_CQR_QUEUED) && |
| 1861 | (!device->stopped)) { |
| 1862 | if (device->discipline->start_IO(next) == 0) |
| 1863 | expires = next->expires; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | } |
| 1865 | if (expires != 0) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1866 | dasd_device_set_timer(device, expires); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | else |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1868 | dasd_device_clear_timer(device); |
| 1869 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 1871 | EXPORT_SYMBOL(dasd_int_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | |
Stefan Haberland | a23ed00 | 2010-05-26 23:27:09 +0200 | [diff] [blame] | 1873 | enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb) |
| 1874 | { |
| 1875 | struct dasd_device *device; |
| 1876 | |
| 1877 | device = dasd_device_from_cdev_locked(cdev); |
| 1878 | |
| 1879 | if (IS_ERR(device)) |
| 1880 | goto out; |
| 1881 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags) || |
| 1882 | device->state != device->target || |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 1883 | !device->discipline->check_for_device_change){ |
Stefan Haberland | a23ed00 | 2010-05-26 23:27:09 +0200 | [diff] [blame] | 1884 | dasd_put_device(device); |
| 1885 | goto out; |
| 1886 | } |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 1887 | if (device->discipline->dump_sense_dbf) |
| 1888 | device->discipline->dump_sense_dbf(device, irb, "uc"); |
| 1889 | device->discipline->check_for_device_change(device, NULL, irb); |
Stefan Haberland | a23ed00 | 2010-05-26 23:27:09 +0200 | [diff] [blame] | 1890 | dasd_put_device(device); |
| 1891 | out: |
| 1892 | return UC_TODO_RETRY; |
| 1893 | } |
| 1894 | EXPORT_SYMBOL_GPL(dasd_generic_uc_handler); |
| 1895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1897 | * If we have an error on a dasd_block layer request then we cancel |
| 1898 | * and return all further requests from the same dasd_block as well. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1900 | static void __dasd_device_recovery(struct dasd_device *device, |
| 1901 | struct dasd_ccw_req *ref_cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | { |
| 1903 | struct list_head *l, *n; |
| 1904 | struct dasd_ccw_req *cqr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | |
| 1906 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1907 | * only requeue request that came from the dasd_block layer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1909 | if (!ref_cqr->block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | return; |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 1911 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1912 | list_for_each_safe(l, n, &device->ccw_queue) { |
| 1913 | cqr = list_entry(l, struct dasd_ccw_req, devlist); |
| 1914 | if (cqr->status == DASD_CQR_QUEUED && |
| 1915 | ref_cqr->block == cqr->block) { |
| 1916 | cqr->status = DASD_CQR_CLEARED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1918 | } |
| 1919 | }; |
| 1920 | |
| 1921 | /* |
| 1922 | * Remove those ccw requests from the queue that need to be returned |
| 1923 | * to the upper layer. |
| 1924 | */ |
| 1925 | static void __dasd_device_process_ccw_queue(struct dasd_device *device, |
| 1926 | struct list_head *final_queue) |
| 1927 | { |
| 1928 | struct list_head *l, *n; |
| 1929 | struct dasd_ccw_req *cqr; |
| 1930 | |
| 1931 | /* Process request with final status. */ |
| 1932 | list_for_each_safe(l, n, &device->ccw_queue) { |
| 1933 | cqr = list_entry(l, struct dasd_ccw_req, devlist); |
| 1934 | |
Hannes Reinecke | 1fbdb8b | 2013-01-30 09:26:13 +0000 | [diff] [blame] | 1935 | /* Skip any non-final request. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1936 | if (cqr->status == DASD_CQR_QUEUED || |
| 1937 | cqr->status == DASD_CQR_IN_IO || |
| 1938 | cqr->status == DASD_CQR_CLEAR_PENDING) |
Hannes Reinecke | 1fbdb8b | 2013-01-30 09:26:13 +0000 | [diff] [blame] | 1939 | continue; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1940 | if (cqr->status == DASD_CQR_ERROR) { |
| 1941 | __dasd_device_recovery(device, cqr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1943 | /* Rechain finished requests to final queue */ |
| 1944 | list_move_tail(&cqr->devlist, final_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | } |
| 1946 | } |
| 1947 | |
Sebastian Ott | 5c618c0 | 2018-05-24 12:18:58 +0200 | [diff] [blame] | 1948 | static void __dasd_process_cqr(struct dasd_device *device, |
| 1949 | struct dasd_ccw_req *cqr) |
| 1950 | { |
| 1951 | char errorstring[ERRORLENGTH]; |
| 1952 | |
| 1953 | switch (cqr->status) { |
| 1954 | case DASD_CQR_SUCCESS: |
| 1955 | cqr->status = DASD_CQR_DONE; |
| 1956 | break; |
| 1957 | case DASD_CQR_ERROR: |
| 1958 | cqr->status = DASD_CQR_NEED_ERP; |
| 1959 | break; |
| 1960 | case DASD_CQR_CLEARED: |
| 1961 | cqr->status = DASD_CQR_TERMINATED; |
| 1962 | break; |
| 1963 | default: |
| 1964 | /* internal error 12 - wrong cqr status*/ |
| 1965 | snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status); |
| 1966 | dev_err(&device->cdev->dev, |
| 1967 | "An error occurred in the DASD device driver, " |
| 1968 | "reason=%s\n", errorstring); |
| 1969 | BUG(); |
| 1970 | } |
| 1971 | if (cqr->callback) |
| 1972 | cqr->callback(cqr, cqr->callback_data); |
| 1973 | } |
| 1974 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1976 | * the cqrs from the final queue are returned to the upper layer |
| 1977 | * by setting a dasd_block state and calling the callback function |
| 1978 | */ |
| 1979 | static void __dasd_device_process_final_queue(struct dasd_device *device, |
| 1980 | struct list_head *final_queue) |
| 1981 | { |
| 1982 | struct list_head *l, *n; |
| 1983 | struct dasd_ccw_req *cqr; |
Stefan Weinhuber | 03513bc | 2008-02-19 15:29:27 +0100 | [diff] [blame] | 1984 | struct dasd_block *block; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1985 | |
| 1986 | list_for_each_safe(l, n, final_queue) { |
| 1987 | cqr = list_entry(l, struct dasd_ccw_req, devlist); |
| 1988 | list_del_init(&cqr->devlist); |
Stefan Weinhuber | 03513bc | 2008-02-19 15:29:27 +0100 | [diff] [blame] | 1989 | block = cqr->block; |
Sebastian Ott | 5c618c0 | 2018-05-24 12:18:58 +0200 | [diff] [blame] | 1990 | if (!block) { |
| 1991 | __dasd_process_cqr(device, cqr); |
| 1992 | } else { |
Stefan Weinhuber | 03513bc | 2008-02-19 15:29:27 +0100 | [diff] [blame] | 1993 | spin_lock_bh(&block->queue_lock); |
Sebastian Ott | 5c618c0 | 2018-05-24 12:18:58 +0200 | [diff] [blame] | 1994 | __dasd_process_cqr(device, cqr); |
Stefan Weinhuber | 03513bc | 2008-02-19 15:29:27 +0100 | [diff] [blame] | 1995 | spin_unlock_bh(&block->queue_lock); |
Sebastian Ott | 5c618c0 | 2018-05-24 12:18:58 +0200 | [diff] [blame] | 1996 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1997 | } |
| 1998 | } |
| 1999 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2000 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | * Take a look at the first request on the ccw queue and check |
| 2002 | * if it reached its expire time. If so, terminate the IO. |
| 2003 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2004 | static void __dasd_device_check_expire(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | { |
| 2006 | struct dasd_ccw_req *cqr; |
| 2007 | |
| 2008 | if (list_empty(&device->ccw_queue)) |
| 2009 | return; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2010 | cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist); |
Horst Hummel | 29145a6 | 2006-12-04 15:40:15 +0100 | [diff] [blame] | 2011 | if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) && |
| 2012 | (time_after_eq(jiffies, cqr->expires + cqr->starttime))) { |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 2013 | if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) { |
| 2014 | /* |
| 2015 | * IO in safe offline processing should not |
| 2016 | * run out of retries |
| 2017 | */ |
| 2018 | cqr->retries++; |
| 2019 | } |
Horst Hummel | 29145a6 | 2006-12-04 15:40:15 +0100 | [diff] [blame] | 2020 | if (device->discipline->term_IO(cqr) != 0) { |
| 2021 | /* Hmpf, try again in 5 sec */ |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2022 | dev_err(&device->cdev->dev, |
Heiko Carstens | 625c94d | 2010-08-13 10:06:38 +0200 | [diff] [blame] | 2023 | "cqr %p timed out (%lus) but cannot be " |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2024 | "ended, retrying in 5 s\n", |
| 2025 | cqr, (cqr->expires/HZ)); |
Stefan Haberland | 7dc1da9 | 2008-01-26 14:11:26 +0100 | [diff] [blame] | 2026 | cqr->expires += 5*HZ; |
| 2027 | dasd_device_set_timer(device, 5*HZ); |
Horst Hummel | 29145a6 | 2006-12-04 15:40:15 +0100 | [diff] [blame] | 2028 | } else { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2029 | dev_err(&device->cdev->dev, |
Heiko Carstens | 625c94d | 2010-08-13 10:06:38 +0200 | [diff] [blame] | 2030 | "cqr %p timed out (%lus), %i retries " |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2031 | "remaining\n", cqr, (cqr->expires/HZ), |
| 2032 | cqr->retries); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | } |
| 2034 | } |
| 2035 | } |
| 2036 | |
| 2037 | /* |
Stefan Haberland | f81a49d | 2015-07-10 10:47:09 +0200 | [diff] [blame] | 2038 | * return 1 when device is not eligible for IO |
| 2039 | */ |
| 2040 | static int __dasd_device_is_unusable(struct dasd_device *device, |
| 2041 | struct dasd_ccw_req *cqr) |
| 2042 | { |
Jan Höppner | 9e12e54 | 2018-07-03 10:56:51 +0200 | [diff] [blame] | 2043 | int mask = ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM | DASD_STOPPED_NOSPC); |
Stefan Haberland | f81a49d | 2015-07-10 10:47:09 +0200 | [diff] [blame] | 2044 | |
Stefan Haberland | e8ac015 | 2017-05-18 13:24:45 +0200 | [diff] [blame] | 2045 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags) && |
| 2046 | !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) { |
| 2047 | /* |
| 2048 | * dasd is being set offline |
| 2049 | * but it is no safe offline where we have to allow I/O |
| 2050 | */ |
Stefan Haberland | f81a49d | 2015-07-10 10:47:09 +0200 | [diff] [blame] | 2051 | return 1; |
| 2052 | } |
| 2053 | if (device->stopped) { |
| 2054 | if (device->stopped & mask) { |
| 2055 | /* stopped and CQR will not change that. */ |
| 2056 | return 1; |
| 2057 | } |
| 2058 | if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) { |
| 2059 | /* CQR is not able to change device to |
| 2060 | * operational. */ |
| 2061 | return 1; |
| 2062 | } |
| 2063 | /* CQR required to get device operational. */ |
| 2064 | } |
| 2065 | return 0; |
| 2066 | } |
| 2067 | |
| 2068 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | * Take a look at the first request on the ccw queue and check |
| 2070 | * if it needs to be started. |
| 2071 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2072 | static void __dasd_device_start_head(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | { |
| 2074 | struct dasd_ccw_req *cqr; |
| 2075 | int rc; |
| 2076 | |
| 2077 | if (list_empty(&device->ccw_queue)) |
| 2078 | return; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2079 | cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist); |
Peter Oberparleiter | 25ee4cf | 2006-04-10 22:53:47 -0700 | [diff] [blame] | 2080 | if (cqr->status != DASD_CQR_QUEUED) |
| 2081 | return; |
Stefan Haberland | f81a49d | 2015-07-10 10:47:09 +0200 | [diff] [blame] | 2082 | /* if device is not usable return request to upper layer */ |
| 2083 | if (__dasd_device_is_unusable(device, cqr)) { |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 2084 | cqr->intrc = -EAGAIN; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2085 | cqr->status = DASD_CQR_CLEARED; |
| 2086 | dasd_schedule_device_bh(device); |
Peter Oberparleiter | 25ee4cf | 2006-04-10 22:53:47 -0700 | [diff] [blame] | 2087 | return; |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 2088 | } |
Peter Oberparleiter | 25ee4cf | 2006-04-10 22:53:47 -0700 | [diff] [blame] | 2089 | |
| 2090 | rc = device->discipline->start_IO(cqr); |
| 2091 | if (rc == 0) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2092 | dasd_device_set_timer(device, cqr->expires); |
Peter Oberparleiter | 25ee4cf | 2006-04-10 22:53:47 -0700 | [diff] [blame] | 2093 | else if (rc == -EACCES) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2094 | dasd_schedule_device_bh(device); |
Peter Oberparleiter | 25ee4cf | 2006-04-10 22:53:47 -0700 | [diff] [blame] | 2095 | } else |
| 2096 | /* Hmpf, try again in 1/2 sec */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2097 | dasd_device_set_timer(device, 50); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 2098 | } |
| 2099 | |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 2100 | static void __dasd_device_check_path_events(struct dasd_device *device) |
| 2101 | { |
| 2102 | int rc; |
| 2103 | |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 2104 | if (!dasd_path_get_tbvpm(device)) |
| 2105 | return; |
| 2106 | |
| 2107 | if (device->stopped & |
| 2108 | ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM)) |
| 2109 | return; |
| 2110 | rc = device->discipline->verify_path(device, |
| 2111 | dasd_path_get_tbvpm(device)); |
| 2112 | if (rc) |
| 2113 | dasd_device_set_timer(device, 50); |
| 2114 | else |
| 2115 | dasd_path_clear_all_verify(device); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 2116 | }; |
| 2117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2119 | * Go through all request on the dasd_device request queue, |
| 2120 | * terminate them on the cdev if necessary, and return them to the |
| 2121 | * submitting layer via callback. |
| 2122 | * Note: |
| 2123 | * Make sure that all 'submitting layers' still exist when |
| 2124 | * this function is called!. In other words, when 'device' is a base |
| 2125 | * device then all block layer requests must have been removed before |
| 2126 | * via dasd_flush_block_queue. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2128 | int dasd_flush_device_queue(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2130 | struct dasd_ccw_req *cqr, *n; |
| 2131 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | struct list_head flush_queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | |
| 2134 | INIT_LIST_HEAD(&flush_queue); |
| 2135 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 2136 | rc = 0; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2137 | list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) { |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 2138 | /* Check status and move request to flush_queue */ |
| 2139 | switch (cqr->status) { |
| 2140 | case DASD_CQR_IN_IO: |
| 2141 | rc = device->discipline->term_IO(cqr); |
| 2142 | if (rc) { |
| 2143 | /* unable to terminate requeust */ |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2144 | dev_err(&device->cdev->dev, |
| 2145 | "Flushing the DASD request queue " |
| 2146 | "failed for request %p\n", cqr); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 2147 | /* stop flush processing */ |
| 2148 | goto finished; |
| 2149 | } |
| 2150 | break; |
| 2151 | case DASD_CQR_QUEUED: |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 2152 | cqr->stopclk = get_tod_clock(); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2153 | cqr->status = DASD_CQR_CLEARED; |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 2154 | break; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2155 | default: /* no need to modify the others */ |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 2156 | break; |
| 2157 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2158 | list_move_tail(&cqr->devlist, &flush_queue); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 2159 | } |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 2160 | finished: |
| 2161 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2162 | /* |
| 2163 | * After this point all requests must be in state CLEAR_PENDING, |
| 2164 | * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become |
| 2165 | * one of the others. |
| 2166 | */ |
| 2167 | list_for_each_entry_safe(cqr, n, &flush_queue, devlist) |
| 2168 | wait_event(dasd_flush_wq, |
| 2169 | (cqr->status != DASD_CQR_CLEAR_PENDING)); |
| 2170 | /* |
| 2171 | * Now set each request back to TERMINATED, DONE or NEED_ERP |
| 2172 | * and call the callback function of flushed requests |
| 2173 | */ |
| 2174 | __dasd_device_process_final_queue(device, &flush_queue); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 2175 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 2177 | EXPORT_SYMBOL_GPL(dasd_flush_device_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | |
| 2179 | /* |
| 2180 | * Acquire the device lock and process queues for the device. |
| 2181 | */ |
Sebastian Ott | d2f2df6 | 2018-07-03 13:06:45 +0200 | [diff] [blame] | 2182 | static void dasd_device_tasklet(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | { |
Sebastian Ott | d2f2df6 | 2018-07-03 13:06:45 +0200 | [diff] [blame] | 2184 | struct dasd_device *device = (struct dasd_device *) data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | struct list_head final_queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | |
| 2187 | atomic_set (&device->tasklet_scheduled, 0); |
| 2188 | INIT_LIST_HEAD(&final_queue); |
| 2189 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
| 2190 | /* Check expire time of first request on the ccw queue. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2191 | __dasd_device_check_expire(device); |
| 2192 | /* find final requests on ccw queue */ |
| 2193 | __dasd_device_process_ccw_queue(device, &final_queue); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 2194 | __dasd_device_check_path_events(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 2196 | /* Now call the callback function of requests with final status */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2197 | __dasd_device_process_final_queue(device, &final_queue); |
| 2198 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | /* Now check if the head of the ccw queue needs to be started. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2200 | __dasd_device_start_head(device); |
| 2201 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
Stefan Haberland | 4679e89 | 2012-06-19 17:30:12 +0200 | [diff] [blame] | 2202 | if (waitqueue_active(&shutdown_waitq)) |
| 2203 | wake_up(&shutdown_waitq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | dasd_put_device(device); |
| 2205 | } |
| 2206 | |
| 2207 | /* |
| 2208 | * Schedules a call to dasd_tasklet over the device tasklet. |
| 2209 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2210 | void dasd_schedule_device_bh(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | { |
| 2212 | /* Protect against rescheduling. */ |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 2213 | if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | return; |
| 2215 | dasd_get_device(device); |
| 2216 | tasklet_hi_schedule(&device->tasklet); |
| 2217 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 2218 | EXPORT_SYMBOL(dasd_schedule_device_bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 2220 | void dasd_device_set_stop_bits(struct dasd_device *device, int bits) |
| 2221 | { |
| 2222 | device->stopped |= bits; |
| 2223 | } |
| 2224 | EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits); |
| 2225 | |
| 2226 | void dasd_device_remove_stop_bits(struct dasd_device *device, int bits) |
| 2227 | { |
| 2228 | device->stopped &= ~bits; |
| 2229 | if (!device->stopped) |
| 2230 | wake_up(&generic_waitq); |
| 2231 | } |
| 2232 | EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits); |
| 2233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2235 | * Queue a request to the head of the device ccw_queue. |
| 2236 | * Start the I/O if possible. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2238 | void dasd_add_request_head(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | { |
| 2240 | struct dasd_device *device; |
| 2241 | unsigned long flags; |
| 2242 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2243 | device = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2245 | cqr->status = DASD_CQR_QUEUED; |
| 2246 | list_add(&cqr->devlist, &device->ccw_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | /* let the bh start the request to keep them in order */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2248 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 2250 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 2251 | EXPORT_SYMBOL(dasd_add_request_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | |
| 2253 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2254 | * Queue a request to the tail of the device ccw_queue. |
| 2255 | * Start the I/O if possible. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2257 | void dasd_add_request_tail(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | { |
| 2259 | struct dasd_device *device; |
| 2260 | unsigned long flags; |
| 2261 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2262 | device = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2264 | cqr->status = DASD_CQR_QUEUED; |
| 2265 | list_add_tail(&cqr->devlist, &device->ccw_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | /* let the bh start the request to keep them in order */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2267 | dasd_schedule_device_bh(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 2269 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 2270 | EXPORT_SYMBOL(dasd_add_request_tail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | |
| 2272 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2273 | * Wakeup helper for the 'sleep_on' functions. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | */ |
Stefan Haberland | 5915a87 | 2011-10-30 15:16:57 +0100 | [diff] [blame] | 2275 | void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | { |
Stefan Weinhuber | 1c1e093 | 2010-05-12 09:32:11 +0200 | [diff] [blame] | 2277 | spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev)); |
| 2278 | cqr->callback_data = DASD_SLEEPON_END_TAG; |
| 2279 | spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev)); |
| 2280 | wake_up(&generic_waitq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | } |
Stefan Haberland | 5915a87 | 2011-10-30 15:16:57 +0100 | [diff] [blame] | 2282 | EXPORT_SYMBOL_GPL(dasd_wakeup_cb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2284 | static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | { |
| 2286 | struct dasd_device *device; |
| 2287 | int rc; |
| 2288 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2289 | device = cqr->startdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
Stefan Weinhuber | 1c1e093 | 2010-05-12 09:32:11 +0200 | [diff] [blame] | 2291 | rc = (cqr->callback_data == DASD_SLEEPON_END_TAG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 2293 | return rc; |
| 2294 | } |
| 2295 | |
| 2296 | /* |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 2297 | * checks if error recovery is necessary, returns 1 if yes, 0 otherwise. |
| 2298 | */ |
| 2299 | static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr) |
| 2300 | { |
| 2301 | struct dasd_device *device; |
| 2302 | dasd_erp_fn_t erp_fn; |
| 2303 | |
| 2304 | if (cqr->status == DASD_CQR_FILLED) |
| 2305 | return 0; |
| 2306 | device = cqr->startdev; |
| 2307 | if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) { |
| 2308 | if (cqr->status == DASD_CQR_TERMINATED) { |
| 2309 | device->discipline->handle_terminated_request(cqr); |
| 2310 | return 1; |
| 2311 | } |
| 2312 | if (cqr->status == DASD_CQR_NEED_ERP) { |
| 2313 | erp_fn = device->discipline->erp_action(cqr); |
| 2314 | erp_fn(cqr); |
| 2315 | return 1; |
| 2316 | } |
| 2317 | if (cqr->status == DASD_CQR_FAILED) |
| 2318 | dasd_log_sense(cqr, &cqr->irb); |
| 2319 | if (cqr->refers) { |
| 2320 | __dasd_process_erp(device, cqr); |
| 2321 | return 1; |
| 2322 | } |
| 2323 | } |
| 2324 | return 0; |
| 2325 | } |
| 2326 | |
| 2327 | static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr) |
| 2328 | { |
| 2329 | if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) { |
| 2330 | if (cqr->refers) /* erp is not done yet */ |
| 2331 | return 1; |
| 2332 | return ((cqr->status != DASD_CQR_DONE) && |
| 2333 | (cqr->status != DASD_CQR_FAILED)); |
| 2334 | } else |
| 2335 | return (cqr->status == DASD_CQR_FILLED); |
| 2336 | } |
| 2337 | |
| 2338 | static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible) |
| 2339 | { |
| 2340 | struct dasd_device *device; |
| 2341 | int rc; |
| 2342 | struct list_head ccw_queue; |
| 2343 | struct dasd_ccw_req *cqr; |
| 2344 | |
| 2345 | INIT_LIST_HEAD(&ccw_queue); |
| 2346 | maincqr->status = DASD_CQR_FILLED; |
| 2347 | device = maincqr->startdev; |
| 2348 | list_add(&maincqr->blocklist, &ccw_queue); |
| 2349 | for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr); |
| 2350 | cqr = list_first_entry(&ccw_queue, |
| 2351 | struct dasd_ccw_req, blocklist)) { |
| 2352 | |
| 2353 | if (__dasd_sleep_on_erp(cqr)) |
| 2354 | continue; |
| 2355 | if (cqr->status != DASD_CQR_FILLED) /* could be failed */ |
| 2356 | continue; |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 2357 | if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) && |
| 2358 | !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) { |
| 2359 | cqr->status = DASD_CQR_FAILED; |
| 2360 | cqr->intrc = -EPERM; |
| 2361 | continue; |
| 2362 | } |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 2363 | /* Non-temporary stop condition will trigger fail fast */ |
| 2364 | if (device->stopped & ~DASD_STOPPED_PENDING && |
| 2365 | test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) && |
| 2366 | (!dasd_eer_enabled(device))) { |
| 2367 | cqr->status = DASD_CQR_FAILED; |
Hannes Reinecke | d1ffc1f | 2013-01-30 09:26:16 +0000 | [diff] [blame] | 2368 | cqr->intrc = -ENOLINK; |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 2369 | continue; |
| 2370 | } |
Stefan Haberland | df3044f | 2015-04-02 13:18:39 +0200 | [diff] [blame] | 2371 | /* |
Stefan Haberland | a9f6273 | 2016-09-20 10:29:22 +0200 | [diff] [blame] | 2372 | * Don't try to start requests if device is in |
| 2373 | * offline processing, it might wait forever |
| 2374 | */ |
| 2375 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) { |
| 2376 | cqr->status = DASD_CQR_FAILED; |
| 2377 | cqr->intrc = -ENODEV; |
| 2378 | continue; |
| 2379 | } |
| 2380 | /* |
Stefan Haberland | df3044f | 2015-04-02 13:18:39 +0200 | [diff] [blame] | 2381 | * Don't try to start requests if device is stopped |
| 2382 | * except path verification requests |
| 2383 | */ |
| 2384 | if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) { |
| 2385 | if (interruptible) { |
| 2386 | rc = wait_event_interruptible( |
| 2387 | generic_waitq, !(device->stopped)); |
| 2388 | if (rc == -ERESTARTSYS) { |
| 2389 | cqr->status = DASD_CQR_FAILED; |
| 2390 | maincqr->intrc = rc; |
| 2391 | continue; |
| 2392 | } |
| 2393 | } else |
| 2394 | wait_event(generic_waitq, !(device->stopped)); |
| 2395 | } |
Stefan Haberland | 5915a87 | 2011-10-30 15:16:57 +0100 | [diff] [blame] | 2396 | if (!cqr->callback) |
| 2397 | cqr->callback = dasd_wakeup_cb; |
| 2398 | |
Stefan Weinhuber | 1c1e093 | 2010-05-12 09:32:11 +0200 | [diff] [blame] | 2399 | cqr->callback_data = DASD_SLEEPON_START_TAG; |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 2400 | dasd_add_request_tail(cqr); |
| 2401 | if (interruptible) { |
| 2402 | rc = wait_event_interruptible( |
| 2403 | generic_waitq, _wait_for_wakeup(cqr)); |
| 2404 | if (rc == -ERESTARTSYS) { |
| 2405 | dasd_cancel_req(cqr); |
| 2406 | /* wait (non-interruptible) for final status */ |
| 2407 | wait_event(generic_waitq, |
| 2408 | _wait_for_wakeup(cqr)); |
| 2409 | cqr->status = DASD_CQR_FAILED; |
| 2410 | maincqr->intrc = rc; |
| 2411 | continue; |
| 2412 | } |
| 2413 | } else |
| 2414 | wait_event(generic_waitq, _wait_for_wakeup(cqr)); |
| 2415 | } |
| 2416 | |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 2417 | maincqr->endclk = get_tod_clock(); |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 2418 | if ((maincqr->status != DASD_CQR_DONE) && |
| 2419 | (maincqr->intrc != -ERESTARTSYS)) |
| 2420 | dasd_log_sense(maincqr, &maincqr->irb); |
| 2421 | if (maincqr->status == DASD_CQR_DONE) |
| 2422 | rc = 0; |
| 2423 | else if (maincqr->intrc) |
| 2424 | rc = maincqr->intrc; |
| 2425 | else |
| 2426 | rc = -EIO; |
| 2427 | return rc; |
| 2428 | } |
| 2429 | |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2430 | static inline int _wait_for_wakeup_queue(struct list_head *ccw_queue) |
| 2431 | { |
| 2432 | struct dasd_ccw_req *cqr; |
| 2433 | |
| 2434 | list_for_each_entry(cqr, ccw_queue, blocklist) { |
| 2435 | if (cqr->callback_data != DASD_SLEEPON_END_TAG) |
| 2436 | return 0; |
| 2437 | } |
| 2438 | |
| 2439 | return 1; |
| 2440 | } |
| 2441 | |
| 2442 | static int _dasd_sleep_on_queue(struct list_head *ccw_queue, int interruptible) |
| 2443 | { |
| 2444 | struct dasd_device *device; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2445 | struct dasd_ccw_req *cqr, *n; |
Jan Höppner | 8fd5752 | 2015-08-19 13:41:20 +0200 | [diff] [blame] | 2446 | u8 *sense = NULL; |
Stefan Haberland | 362ce84 | 2014-10-01 13:04:54 +0200 | [diff] [blame] | 2447 | int rc; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2448 | |
| 2449 | retry: |
| 2450 | list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) { |
| 2451 | device = cqr->startdev; |
| 2452 | if (cqr->status != DASD_CQR_FILLED) /*could be failed*/ |
| 2453 | continue; |
| 2454 | |
| 2455 | if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) && |
| 2456 | !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) { |
| 2457 | cqr->status = DASD_CQR_FAILED; |
| 2458 | cqr->intrc = -EPERM; |
| 2459 | continue; |
| 2460 | } |
| 2461 | /*Non-temporary stop condition will trigger fail fast*/ |
| 2462 | if (device->stopped & ~DASD_STOPPED_PENDING && |
| 2463 | test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) && |
| 2464 | !dasd_eer_enabled(device)) { |
| 2465 | cqr->status = DASD_CQR_FAILED; |
| 2466 | cqr->intrc = -EAGAIN; |
| 2467 | continue; |
| 2468 | } |
| 2469 | |
| 2470 | /*Don't try to start requests if device is stopped*/ |
| 2471 | if (interruptible) { |
| 2472 | rc = wait_event_interruptible( |
| 2473 | generic_waitq, !device->stopped); |
| 2474 | if (rc == -ERESTARTSYS) { |
| 2475 | cqr->status = DASD_CQR_FAILED; |
| 2476 | cqr->intrc = rc; |
| 2477 | continue; |
| 2478 | } |
| 2479 | } else |
| 2480 | wait_event(generic_waitq, !(device->stopped)); |
| 2481 | |
| 2482 | if (!cqr->callback) |
| 2483 | cqr->callback = dasd_wakeup_cb; |
| 2484 | cqr->callback_data = DASD_SLEEPON_START_TAG; |
| 2485 | dasd_add_request_tail(cqr); |
| 2486 | } |
| 2487 | |
| 2488 | wait_event(generic_waitq, _wait_for_wakeup_queue(ccw_queue)); |
| 2489 | |
| 2490 | rc = 0; |
| 2491 | list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) { |
Stefan Haberland | 29b8dd9 | 2014-07-18 14:26:01 +0200 | [diff] [blame] | 2492 | /* |
Jan Höppner | 8fd5752 | 2015-08-19 13:41:20 +0200 | [diff] [blame] | 2493 | * In some cases the 'File Protected' or 'Incorrect Length' |
| 2494 | * error might be expected and error recovery would be |
| 2495 | * unnecessary in these cases. Check if the according suppress |
| 2496 | * bit is set. |
| 2497 | */ |
| 2498 | sense = dasd_get_sense(&cqr->irb); |
| 2499 | if (sense && sense[1] & SNS1_FILE_PROTECTED && |
| 2500 | test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags)) |
| 2501 | continue; |
| 2502 | if (scsw_cstat(&cqr->irb.scsw) == 0x40 && |
| 2503 | test_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags)) |
| 2504 | continue; |
| 2505 | |
| 2506 | /* |
Stefan Haberland | 29b8dd9 | 2014-07-18 14:26:01 +0200 | [diff] [blame] | 2507 | * for alias devices simplify error recovery and |
| 2508 | * return to upper layer |
Stefan Haberland | 362ce84 | 2014-10-01 13:04:54 +0200 | [diff] [blame] | 2509 | * do not skip ERP requests |
Stefan Haberland | 29b8dd9 | 2014-07-18 14:26:01 +0200 | [diff] [blame] | 2510 | */ |
Stefan Haberland | 362ce84 | 2014-10-01 13:04:54 +0200 | [diff] [blame] | 2511 | if (cqr->startdev != cqr->basedev && !cqr->refers && |
Stefan Haberland | 29b8dd9 | 2014-07-18 14:26:01 +0200 | [diff] [blame] | 2512 | (cqr->status == DASD_CQR_TERMINATED || |
| 2513 | cqr->status == DASD_CQR_NEED_ERP)) |
| 2514 | return -EAGAIN; |
Stefan Haberland | 362ce84 | 2014-10-01 13:04:54 +0200 | [diff] [blame] | 2515 | |
| 2516 | /* normal recovery for basedev IO */ |
Stefan Haberland | 590aeed | 2014-11-24 10:45:47 +0100 | [diff] [blame] | 2517 | if (__dasd_sleep_on_erp(cqr)) |
| 2518 | /* handle erp first */ |
Stefan Haberland | 362ce84 | 2014-10-01 13:04:54 +0200 | [diff] [blame] | 2519 | goto retry; |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2520 | } |
Stefan Haberland | 362ce84 | 2014-10-01 13:04:54 +0200 | [diff] [blame] | 2521 | |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2522 | return 0; |
| 2523 | } |
| 2524 | |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 2525 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2526 | * Queue a request to the tail of the device ccw_queue and wait for |
| 2527 | * it's completion. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2529 | int dasd_sleep_on(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | { |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 2531 | return _dasd_sleep_on(cqr, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 2533 | EXPORT_SYMBOL(dasd_sleep_on); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | |
| 2535 | /* |
Stefan Haberland | d42e171 | 2013-04-15 16:22:23 +0200 | [diff] [blame] | 2536 | * Start requests from a ccw_queue and wait for their completion. |
| 2537 | */ |
| 2538 | int dasd_sleep_on_queue(struct list_head *ccw_queue) |
| 2539 | { |
| 2540 | return _dasd_sleep_on_queue(ccw_queue, 0); |
| 2541 | } |
| 2542 | EXPORT_SYMBOL(dasd_sleep_on_queue); |
| 2543 | |
| 2544 | /* |
Jan Höppner | bcf3676 | 2019-06-27 14:33:17 +0200 | [diff] [blame] | 2545 | * Start requests from a ccw_queue and wait interruptible for their completion. |
| 2546 | */ |
| 2547 | int dasd_sleep_on_queue_interruptible(struct list_head *ccw_queue) |
| 2548 | { |
| 2549 | return _dasd_sleep_on_queue(ccw_queue, 1); |
| 2550 | } |
| 2551 | EXPORT_SYMBOL(dasd_sleep_on_queue_interruptible); |
| 2552 | |
| 2553 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2554 | * Queue a request to the tail of the device ccw_queue and wait |
| 2555 | * interruptible for it's completion. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2557 | int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | { |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 2559 | return _dasd_sleep_on(cqr, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 2561 | EXPORT_SYMBOL(dasd_sleep_on_interruptible); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | |
| 2563 | /* |
| 2564 | * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock |
| 2565 | * for eckd devices) the currently running request has to be terminated |
| 2566 | * and be put back to status queued, before the special request is added |
| 2567 | * to the head of the queue. Then the special request is waited on normally. |
| 2568 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2569 | static inline int _dasd_term_running_cqr(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | { |
| 2571 | struct dasd_ccw_req *cqr; |
Stefan Haberland | aade6c0 | 2011-05-10 17:13:38 +0200 | [diff] [blame] | 2572 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | |
| 2574 | if (list_empty(&device->ccw_queue)) |
| 2575 | return 0; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2576 | cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist); |
Stefan Haberland | aade6c0 | 2011-05-10 17:13:38 +0200 | [diff] [blame] | 2577 | rc = device->discipline->term_IO(cqr); |
| 2578 | if (!rc) |
| 2579 | /* |
| 2580 | * CQR terminated because a more important request is pending. |
| 2581 | * Undo decreasing of retry counter because this is |
| 2582 | * not an error case. |
| 2583 | */ |
| 2584 | cqr->retries++; |
| 2585 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | } |
| 2587 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2588 | int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | struct dasd_device *device; |
| 2591 | int rc; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 2592 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2593 | device = cqr->startdev; |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 2594 | if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) && |
| 2595 | !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) { |
| 2596 | cqr->status = DASD_CQR_FAILED; |
| 2597 | cqr->intrc = -EPERM; |
| 2598 | return -EIO; |
| 2599 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
| 2601 | rc = _dasd_term_running_cqr(device); |
| 2602 | if (rc) { |
| 2603 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 2604 | return rc; |
| 2605 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | cqr->callback = dasd_wakeup_cb; |
Stefan Weinhuber | 1c1e093 | 2010-05-12 09:32:11 +0200 | [diff] [blame] | 2607 | cqr->callback_data = DASD_SLEEPON_START_TAG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | cqr->status = DASD_CQR_QUEUED; |
Stefan Haberland | 214b8ff | 2011-10-30 15:16:56 +0100 | [diff] [blame] | 2609 | /* |
| 2610 | * add new request as second |
| 2611 | * first the terminated cqr needs to be finished |
| 2612 | */ |
| 2613 | list_add(&cqr->devlist, device->ccw_queue.next); |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 2614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2615 | /* let the bh start the request to keep them in order */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2616 | dasd_schedule_device_bh(device); |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 2617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 2619 | |
Stefan Haberland | c80ee72 | 2008-05-30 10:03:31 +0200 | [diff] [blame] | 2620 | wait_event(generic_waitq, _wait_for_wakeup(cqr)); |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 2621 | |
Stefan Weinhuber | 6cc7f16 | 2009-06-12 10:26:39 +0200 | [diff] [blame] | 2622 | if (cqr->status == DASD_CQR_DONE) |
| 2623 | rc = 0; |
| 2624 | else if (cqr->intrc) |
| 2625 | rc = cqr->intrc; |
| 2626 | else |
| 2627 | rc = -EIO; |
Stefan Haberland | 0e003b7 | 2013-07-30 10:49:43 +0200 | [diff] [blame] | 2628 | |
| 2629 | /* kick tasklets */ |
| 2630 | dasd_schedule_device_bh(device); |
| 2631 | if (device->block) |
| 2632 | dasd_schedule_block_bh(device->block); |
| 2633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | return rc; |
| 2635 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 2636 | EXPORT_SYMBOL(dasd_sleep_on_immediatly); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | |
| 2638 | /* |
| 2639 | * Cancels a request that was started with dasd_sleep_on_req. |
| 2640 | * This is useful to timeout requests. The request will be |
| 2641 | * terminated if it is currently in i/o. |
Hannes Reinecke | b99a946 | 2013-01-30 09:26:11 +0000 | [diff] [blame] | 2642 | * Returns 0 if request termination was successful |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2643 | * negative error code if termination failed |
| 2644 | * Cancellation of a request is an asynchronous operation! The calling |
| 2645 | * function has to wait until the request is properly returned via callback. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | */ |
Sebastian Ott | 1bcdb53 | 2018-05-16 11:25:21 +0200 | [diff] [blame] | 2647 | static int __dasd_cancel_req(struct dasd_ccw_req *cqr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2649 | struct dasd_device *device = cqr->startdev; |
Sebastian Ott | 1bcdb53 | 2018-05-16 11:25:21 +0200 | [diff] [blame] | 2650 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2652 | switch (cqr->status) { |
| 2653 | case DASD_CQR_QUEUED: |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2654 | /* request was not started - just set to cleared */ |
| 2655 | cqr->status = DASD_CQR_CLEARED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | break; |
| 2657 | case DASD_CQR_IN_IO: |
| 2658 | /* request in IO - terminate IO and release again */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2659 | rc = device->discipline->term_IO(cqr); |
| 2660 | if (rc) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2661 | dev_err(&device->cdev->dev, |
| 2662 | "Cancelling request %p failed with rc=%d\n", |
| 2663 | cqr, rc); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2664 | } else { |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 2665 | cqr->stopclk = get_tod_clock(); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2666 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | break; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2668 | default: /* already finished or clear pending - do nothing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2671 | dasd_schedule_device_bh(device); |
| 2672 | return rc; |
| 2673 | } |
Sebastian Ott | 1bcdb53 | 2018-05-16 11:25:21 +0200 | [diff] [blame] | 2674 | |
| 2675 | int dasd_cancel_req(struct dasd_ccw_req *cqr) |
| 2676 | { |
| 2677 | struct dasd_device *device = cqr->startdev; |
| 2678 | unsigned long flags; |
| 2679 | int rc; |
| 2680 | |
| 2681 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 2682 | rc = __dasd_cancel_req(cqr); |
| 2683 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 2684 | return rc; |
| 2685 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2686 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2687 | /* |
| 2688 | * SECTION: Operations of the dasd_block layer. |
| 2689 | */ |
| 2690 | |
| 2691 | /* |
| 2692 | * Timeout function for dasd_block. This is used when the block layer |
| 2693 | * is waiting for something that may not come reliably, (e.g. a state |
| 2694 | * change interrupt) |
| 2695 | */ |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 2696 | static void dasd_block_timeout(struct timer_list *t) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2697 | { |
| 2698 | unsigned long flags; |
| 2699 | struct dasd_block *block; |
| 2700 | |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 2701 | block = from_timer(block, t, timer); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2702 | spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags); |
| 2703 | /* re-activate request queue */ |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 2704 | dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2705 | spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags); |
| 2706 | dasd_schedule_block_bh(block); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 2707 | blk_mq_run_hw_queues(block->request_queue, true); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | /* |
| 2711 | * Setup timeout for a dasd_block in jiffies. |
| 2712 | */ |
| 2713 | void dasd_block_set_timer(struct dasd_block *block, int expires) |
| 2714 | { |
Stefan Weinhuber | 48cae88 | 2009-02-11 10:37:31 +0100 | [diff] [blame] | 2715 | if (expires == 0) |
| 2716 | del_timer(&block->timer); |
| 2717 | else |
| 2718 | mod_timer(&block->timer, jiffies + expires); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2719 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 2720 | EXPORT_SYMBOL(dasd_block_set_timer); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2721 | |
| 2722 | /* |
| 2723 | * Clear timeout for a dasd_block. |
| 2724 | */ |
| 2725 | void dasd_block_clear_timer(struct dasd_block *block) |
| 2726 | { |
Stefan Weinhuber | 48cae88 | 2009-02-11 10:37:31 +0100 | [diff] [blame] | 2727 | del_timer(&block->timer); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2728 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 2729 | EXPORT_SYMBOL(dasd_block_clear_timer); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2730 | |
| 2731 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2732 | * Process finished error recovery ccw. |
| 2733 | */ |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 2734 | static void __dasd_process_erp(struct dasd_device *device, |
| 2735 | struct dasd_ccw_req *cqr) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2736 | { |
| 2737 | dasd_erp_fn_t erp_fn; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2738 | |
| 2739 | if (cqr->status == DASD_CQR_DONE) |
| 2740 | DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful"); |
| 2741 | else |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 2742 | dev_err(&device->cdev->dev, "ERP failed for the DASD\n"); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2743 | erp_fn = device->discipline->erp_postaction(cqr); |
| 2744 | erp_fn(cqr); |
| 2745 | } |
| 2746 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2747 | static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr) |
| 2748 | { |
| 2749 | struct request *req; |
Christoph Hellwig | 2a842ac | 2017-06-03 09:38:04 +0200 | [diff] [blame] | 2750 | blk_status_t error = BLK_STS_OK; |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 2751 | int status; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2752 | |
| 2753 | req = (struct request *) cqr->callback_data; |
| 2754 | dasd_profile_end(cqr->block, cqr, req); |
Christoph Hellwig | 2a842ac | 2017-06-03 09:38:04 +0200 | [diff] [blame] | 2755 | |
Stefan Weinhuber | fe6b8e7 | 2008-02-05 16:50:47 +0100 | [diff] [blame] | 2756 | status = cqr->block->base->discipline->free_cp(cqr, req); |
Hannes Reinecke | d1ffc1f | 2013-01-30 09:26:16 +0000 | [diff] [blame] | 2757 | if (status < 0) |
Christoph Hellwig | 2a842ac | 2017-06-03 09:38:04 +0200 | [diff] [blame] | 2758 | error = errno_to_blk_status(status); |
Hannes Reinecke | d1ffc1f | 2013-01-30 09:26:16 +0000 | [diff] [blame] | 2759 | else if (status == 0) { |
Christoph Hellwig | 2a842ac | 2017-06-03 09:38:04 +0200 | [diff] [blame] | 2760 | switch (cqr->intrc) { |
| 2761 | case -EPERM: |
| 2762 | error = BLK_STS_NEXUS; |
| 2763 | break; |
| 2764 | case -ENOLINK: |
| 2765 | error = BLK_STS_TRANSPORT; |
| 2766 | break; |
| 2767 | case -ETIMEDOUT: |
| 2768 | error = BLK_STS_TIMEOUT; |
| 2769 | break; |
| 2770 | default: |
| 2771 | error = BLK_STS_IOERR; |
| 2772 | break; |
| 2773 | } |
Hannes Reinecke | d1ffc1f | 2013-01-30 09:26:16 +0000 | [diff] [blame] | 2774 | } |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 2775 | |
| 2776 | /* |
| 2777 | * We need to take care for ETIMEDOUT errors here since the |
| 2778 | * complete callback does not get called in this case. |
| 2779 | * Take care of all errors here and avoid additional code to |
| 2780 | * transfer the error value to the complete callback. |
| 2781 | */ |
| 2782 | if (error) { |
| 2783 | blk_mq_end_request(req, error); |
| 2784 | blk_mq_run_hw_queues(req->q, true); |
| 2785 | } else { |
| 2786 | blk_mq_complete_request(req); |
| 2787 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2788 | } |
| 2789 | |
| 2790 | /* |
| 2791 | * Process ccw request queue. |
| 2792 | */ |
| 2793 | static void __dasd_process_block_ccw_queue(struct dasd_block *block, |
| 2794 | struct list_head *final_queue) |
| 2795 | { |
| 2796 | struct list_head *l, *n; |
| 2797 | struct dasd_ccw_req *cqr; |
| 2798 | dasd_erp_fn_t erp_fn; |
| 2799 | unsigned long flags; |
| 2800 | struct dasd_device *base = block->base; |
| 2801 | |
| 2802 | restart: |
| 2803 | /* Process request with final status. */ |
| 2804 | list_for_each_safe(l, n, &block->ccw_queue) { |
| 2805 | cqr = list_entry(l, struct dasd_ccw_req, blocklist); |
| 2806 | if (cqr->status != DASD_CQR_DONE && |
| 2807 | cqr->status != DASD_CQR_FAILED && |
| 2808 | cqr->status != DASD_CQR_NEED_ERP && |
| 2809 | cqr->status != DASD_CQR_TERMINATED) |
| 2810 | continue; |
| 2811 | |
| 2812 | if (cqr->status == DASD_CQR_TERMINATED) { |
| 2813 | base->discipline->handle_terminated_request(cqr); |
| 2814 | goto restart; |
| 2815 | } |
| 2816 | |
| 2817 | /* Process requests that may be recovered */ |
| 2818 | if (cqr->status == DASD_CQR_NEED_ERP) { |
Stefan Haberland | 6c5f57c | 2008-02-05 16:50:46 +0100 | [diff] [blame] | 2819 | erp_fn = base->discipline->erp_action(cqr); |
Stefan Haberland | 6a5176c | 2010-04-22 17:17:02 +0200 | [diff] [blame] | 2820 | if (IS_ERR(erp_fn(cqr))) |
| 2821 | continue; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2822 | goto restart; |
| 2823 | } |
| 2824 | |
Stefan Haberland | a9cffb2 | 2008-11-14 18:18:08 +0100 | [diff] [blame] | 2825 | /* log sense for fatal error */ |
| 2826 | if (cqr->status == DASD_CQR_FAILED) { |
| 2827 | dasd_log_sense(cqr, &cqr->irb); |
| 2828 | } |
| 2829 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2830 | /* First of all call extended error reporting. */ |
| 2831 | if (dasd_eer_enabled(base) && |
| 2832 | cqr->status == DASD_CQR_FAILED) { |
| 2833 | dasd_eer_write(base, cqr, DASD_EER_FATALERROR); |
| 2834 | |
| 2835 | /* restart request */ |
| 2836 | cqr->status = DASD_CQR_FILLED; |
| 2837 | cqr->retries = 255; |
| 2838 | spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags); |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 2839 | dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2840 | spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), |
| 2841 | flags); |
| 2842 | goto restart; |
| 2843 | } |
| 2844 | |
| 2845 | /* Process finished ERP request. */ |
| 2846 | if (cqr->refers) { |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 2847 | __dasd_process_erp(base, cqr); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2848 | goto restart; |
| 2849 | } |
| 2850 | |
| 2851 | /* Rechain finished requests to final queue */ |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 2852 | cqr->endclk = get_tod_clock(); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2853 | list_move_tail(&cqr->blocklist, final_queue); |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data) |
| 2858 | { |
| 2859 | dasd_schedule_block_bh(cqr->block); |
| 2860 | } |
| 2861 | |
| 2862 | static void __dasd_block_start_head(struct dasd_block *block) |
| 2863 | { |
| 2864 | struct dasd_ccw_req *cqr; |
| 2865 | |
| 2866 | if (list_empty(&block->ccw_queue)) |
| 2867 | return; |
| 2868 | /* We allways begin with the first requests on the queue, as some |
| 2869 | * of previously started requests have to be enqueued on a |
| 2870 | * dasd_device again for error recovery. |
| 2871 | */ |
| 2872 | list_for_each_entry(cqr, &block->ccw_queue, blocklist) { |
| 2873 | if (cqr->status != DASD_CQR_FILLED) |
| 2874 | continue; |
Stefan Weinhuber | 5a27e60 | 2011-01-05 12:48:04 +0100 | [diff] [blame] | 2875 | if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) && |
| 2876 | !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) { |
| 2877 | cqr->status = DASD_CQR_FAILED; |
| 2878 | cqr->intrc = -EPERM; |
| 2879 | dasd_schedule_block_bh(block); |
| 2880 | continue; |
| 2881 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2882 | /* Non-temporary stop condition will trigger fail fast */ |
| 2883 | if (block->base->stopped & ~DASD_STOPPED_PENDING && |
| 2884 | test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) && |
| 2885 | (!dasd_eer_enabled(block->base))) { |
| 2886 | cqr->status = DASD_CQR_FAILED; |
Hannes Reinecke | d1ffc1f | 2013-01-30 09:26:16 +0000 | [diff] [blame] | 2887 | cqr->intrc = -ENOLINK; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2888 | dasd_schedule_block_bh(block); |
| 2889 | continue; |
| 2890 | } |
| 2891 | /* Don't try to start requests if device is stopped */ |
| 2892 | if (block->base->stopped) |
| 2893 | return; |
| 2894 | |
| 2895 | /* just a fail safe check, should not happen */ |
| 2896 | if (!cqr->startdev) |
| 2897 | cqr->startdev = block->base; |
| 2898 | |
| 2899 | /* make sure that the requests we submit find their way back */ |
| 2900 | cqr->callback = dasd_return_cqr_cb; |
| 2901 | |
| 2902 | dasd_add_request_tail(cqr); |
| 2903 | } |
| 2904 | } |
| 2905 | |
| 2906 | /* |
| 2907 | * Central dasd_block layer routine. Takes requests from the generic |
| 2908 | * block layer request queue, creates ccw requests, enqueues them on |
| 2909 | * a dasd_device and processes ccw requests that have been returned. |
| 2910 | */ |
Sebastian Ott | d2f2df6 | 2018-07-03 13:06:45 +0200 | [diff] [blame] | 2911 | static void dasd_block_tasklet(unsigned long data) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2912 | { |
Sebastian Ott | d2f2df6 | 2018-07-03 13:06:45 +0200 | [diff] [blame] | 2913 | struct dasd_block *block = (struct dasd_block *) data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2914 | struct list_head final_queue; |
| 2915 | struct list_head *l, *n; |
| 2916 | struct dasd_ccw_req *cqr; |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 2917 | struct dasd_queue *dq; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2918 | |
| 2919 | atomic_set(&block->tasklet_scheduled, 0); |
| 2920 | INIT_LIST_HEAD(&final_queue); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 2921 | spin_lock_irq(&block->queue_lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2922 | /* Finish off requests on ccw queue */ |
| 2923 | __dasd_process_block_ccw_queue(block, &final_queue); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 2924 | spin_unlock_irq(&block->queue_lock); |
| 2925 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2926 | /* Now call the callback function of requests with final status */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2927 | list_for_each_safe(l, n, &final_queue) { |
| 2928 | cqr = list_entry(l, struct dasd_ccw_req, blocklist); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 2929 | dq = cqr->dq; |
| 2930 | spin_lock_irq(&dq->lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2931 | list_del_init(&cqr->blocklist); |
| 2932 | __dasd_cleanup_cqr(cqr); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 2933 | spin_unlock_irq(&dq->lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2934 | } |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 2935 | |
| 2936 | spin_lock_irq(&block->queue_lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2937 | /* Now check if the head of the ccw queue needs to be started. */ |
| 2938 | __dasd_block_start_head(block); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 2939 | spin_unlock_irq(&block->queue_lock); |
| 2940 | |
Stefan Haberland | 4679e89 | 2012-06-19 17:30:12 +0200 | [diff] [blame] | 2941 | if (waitqueue_active(&shutdown_waitq)) |
| 2942 | wake_up(&shutdown_waitq); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2943 | dasd_put_device(block->base); |
| 2944 | } |
| 2945 | |
| 2946 | static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data) |
| 2947 | { |
| 2948 | wake_up(&dasd_flush_wq); |
| 2949 | } |
| 2950 | |
| 2951 | /* |
Stefan Haberland | c557687 | 2013-04-15 16:41:31 +0200 | [diff] [blame] | 2952 | * Requeue a request back to the block request queue |
| 2953 | * only works for block requests |
| 2954 | */ |
| 2955 | static int _dasd_requeue_request(struct dasd_ccw_req *cqr) |
| 2956 | { |
| 2957 | struct dasd_block *block = cqr->block; |
| 2958 | struct request *req; |
Stefan Haberland | c557687 | 2013-04-15 16:41:31 +0200 | [diff] [blame] | 2959 | |
| 2960 | if (!block) |
| 2961 | return -EINVAL; |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 2962 | spin_lock_irq(&cqr->dq->lock); |
Stefan Haberland | c557687 | 2013-04-15 16:41:31 +0200 | [diff] [blame] | 2963 | req = (struct request *) cqr->callback_data; |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 2964 | blk_mq_requeue_request(req, false); |
| 2965 | spin_unlock_irq(&cqr->dq->lock); |
Stefan Haberland | c557687 | 2013-04-15 16:41:31 +0200 | [diff] [blame] | 2966 | |
| 2967 | return 0; |
| 2968 | } |
| 2969 | |
| 2970 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2971 | * Go through all request on the dasd_block request queue, cancel them |
| 2972 | * on the respective dasd_device, and return them to the generic |
| 2973 | * block layer. |
| 2974 | */ |
| 2975 | static int dasd_flush_block_queue(struct dasd_block *block) |
| 2976 | { |
| 2977 | struct dasd_ccw_req *cqr, *n; |
| 2978 | int rc, i; |
| 2979 | struct list_head flush_queue; |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 2980 | unsigned long flags; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 2981 | |
| 2982 | INIT_LIST_HEAD(&flush_queue); |
| 2983 | spin_lock_bh(&block->queue_lock); |
| 2984 | rc = 0; |
| 2985 | restart: |
| 2986 | list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) { |
| 2987 | /* if this request currently owned by a dasd_device cancel it */ |
| 2988 | if (cqr->status >= DASD_CQR_QUEUED) |
| 2989 | rc = dasd_cancel_req(cqr); |
| 2990 | if (rc < 0) |
| 2991 | break; |
| 2992 | /* Rechain request (including erp chain) so it won't be |
| 2993 | * touched by the dasd_block_tasklet anymore. |
| 2994 | * Replace the callback so we notice when the request |
| 2995 | * is returned from the dasd_device layer. |
| 2996 | */ |
| 2997 | cqr->callback = _dasd_wake_block_flush_cb; |
| 2998 | for (i = 0; cqr != NULL; cqr = cqr->refers, i++) |
| 2999 | list_move_tail(&cqr->blocklist, &flush_queue); |
| 3000 | if (i > 1) |
| 3001 | /* moved more than one request - need to restart */ |
| 3002 | goto restart; |
| 3003 | } |
| 3004 | spin_unlock_bh(&block->queue_lock); |
| 3005 | /* Now call the callback function of flushed requests */ |
| 3006 | restart_cb: |
| 3007 | list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) { |
| 3008 | wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED)); |
| 3009 | /* Process finished ERP request. */ |
| 3010 | if (cqr->refers) { |
Stefan Haberland | 0cd4bd4 | 2008-12-25 13:38:54 +0100 | [diff] [blame] | 3011 | spin_lock_bh(&block->queue_lock); |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 3012 | __dasd_process_erp(block->base, cqr); |
Stefan Haberland | 0cd4bd4 | 2008-12-25 13:38:54 +0100 | [diff] [blame] | 3013 | spin_unlock_bh(&block->queue_lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3014 | /* restart list_for_xx loop since dasd_process_erp |
| 3015 | * might remove multiple elements */ |
| 3016 | goto restart_cb; |
| 3017 | } |
| 3018 | /* call the callback function */ |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3019 | spin_lock_irqsave(&cqr->dq->lock, flags); |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 3020 | cqr->endclk = get_tod_clock(); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3021 | list_del_init(&cqr->blocklist); |
| 3022 | __dasd_cleanup_cqr(cqr); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3023 | spin_unlock_irqrestore(&cqr->dq->lock, flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3024 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | return rc; |
| 3026 | } |
| 3027 | |
| 3028 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3029 | * Schedules a call to dasd_tasklet over the device tasklet. |
| 3030 | */ |
| 3031 | void dasd_schedule_block_bh(struct dasd_block *block) |
| 3032 | { |
| 3033 | /* Protect against rescheduling. */ |
| 3034 | if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0) |
| 3035 | return; |
| 3036 | /* life cycle of block is bound to it's base device */ |
| 3037 | dasd_get_device(block->base); |
| 3038 | tasklet_hi_schedule(&block->tasklet); |
| 3039 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 3040 | EXPORT_SYMBOL(dasd_schedule_block_bh); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3041 | |
| 3042 | |
| 3043 | /* |
| 3044 | * SECTION: external block device operations |
| 3045 | * (request queue handling, open, release, etc.) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | */ |
| 3047 | |
| 3048 | /* |
| 3049 | * Dasd request queue function. Called from ll_rw_blk.c |
| 3050 | */ |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3051 | static blk_status_t do_dasd_request(struct blk_mq_hw_ctx *hctx, |
| 3052 | const struct blk_mq_queue_data *qd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | { |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3054 | struct dasd_block *block = hctx->queue->queuedata; |
| 3055 | struct dasd_queue *dq = hctx->driver_data; |
| 3056 | struct request *req = qd->rq; |
| 3057 | struct dasd_device *basedev; |
| 3058 | struct dasd_ccw_req *cqr; |
| 3059 | blk_status_t rc = BLK_STS_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3061 | basedev = block->base; |
| 3062 | spin_lock_irq(&dq->lock); |
| 3063 | if (basedev->state < DASD_STATE_READY) { |
| 3064 | DBF_DEV_EVENT(DBF_ERR, basedev, |
| 3065 | "device not ready for request %p", req); |
| 3066 | rc = BLK_STS_IOERR; |
| 3067 | goto out; |
| 3068 | } |
| 3069 | |
| 3070 | /* |
| 3071 | * if device is stopped do not fetch new requests |
| 3072 | * except failfast is active which will let requests fail |
| 3073 | * immediately in __dasd_block_start_head() |
| 3074 | */ |
| 3075 | if (basedev->stopped && !(basedev->features & DASD_FEATURE_FAILFAST)) { |
| 3076 | DBF_DEV_EVENT(DBF_ERR, basedev, |
| 3077 | "device stopped request %p", req); |
| 3078 | rc = BLK_STS_RESOURCE; |
| 3079 | goto out; |
| 3080 | } |
| 3081 | |
| 3082 | if (basedev->features & DASD_FEATURE_READONLY && |
| 3083 | rq_data_dir(req) == WRITE) { |
| 3084 | DBF_DEV_EVENT(DBF_ERR, basedev, |
| 3085 | "Rejecting write request %p", req); |
| 3086 | rc = BLK_STS_IOERR; |
| 3087 | goto out; |
| 3088 | } |
| 3089 | |
| 3090 | if (test_bit(DASD_FLAG_ABORTALL, &basedev->flags) && |
| 3091 | (basedev->features & DASD_FEATURE_FAILFAST || |
| 3092 | blk_noretry_request(req))) { |
| 3093 | DBF_DEV_EVENT(DBF_ERR, basedev, |
| 3094 | "Rejecting failfast request %p", req); |
| 3095 | rc = BLK_STS_IOERR; |
| 3096 | goto out; |
| 3097 | } |
| 3098 | |
| 3099 | cqr = basedev->discipline->build_cp(basedev, block, req); |
| 3100 | if (IS_ERR(cqr)) { |
| 3101 | if (PTR_ERR(cqr) == -EBUSY || |
| 3102 | PTR_ERR(cqr) == -ENOMEM || |
| 3103 | PTR_ERR(cqr) == -EAGAIN) { |
| 3104 | rc = BLK_STS_RESOURCE; |
| 3105 | goto out; |
| 3106 | } |
| 3107 | DBF_DEV_EVENT(DBF_ERR, basedev, |
| 3108 | "CCW creation failed (rc=%ld) on request %p", |
| 3109 | PTR_ERR(cqr), req); |
| 3110 | rc = BLK_STS_IOERR; |
| 3111 | goto out; |
| 3112 | } |
| 3113 | /* |
| 3114 | * Note: callback is set to dasd_return_cqr_cb in |
| 3115 | * __dasd_block_start_head to cover erp requests as well |
| 3116 | */ |
| 3117 | cqr->callback_data = req; |
| 3118 | cqr->status = DASD_CQR_FILLED; |
| 3119 | cqr->dq = dq; |
Sebastian Ott | f0f59a2 | 2018-05-15 14:05:13 +0200 | [diff] [blame] | 3120 | |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3121 | blk_mq_start_request(req); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3122 | spin_lock(&block->queue_lock); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3123 | list_add_tail(&cqr->blocklist, &block->ccw_queue); |
| 3124 | INIT_LIST_HEAD(&cqr->devlist); |
| 3125 | dasd_profile_start(block, cqr, req); |
| 3126 | dasd_schedule_block_bh(block); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3127 | spin_unlock(&block->queue_lock); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3128 | |
| 3129 | out: |
| 3130 | spin_unlock_irq(&dq->lock); |
| 3131 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | } |
| 3133 | |
| 3134 | /* |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3135 | * Block timeout callback, called from the block layer |
| 3136 | * |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3137 | * Return values: |
| 3138 | * BLK_EH_RESET_TIMER if the request should be left running |
Christoph Hellwig | 6600593 | 2018-05-29 15:52:29 +0200 | [diff] [blame] | 3139 | * BLK_EH_DONE if the request is handled or terminated |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3140 | * by the driver. |
| 3141 | */ |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3142 | enum blk_eh_timer_return dasd_times_out(struct request *req, bool reserved) |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3143 | { |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3144 | struct dasd_block *block = req->q->queuedata; |
| 3145 | struct dasd_device *device; |
Sebastian Ott | f0f59a2 | 2018-05-15 14:05:13 +0200 | [diff] [blame] | 3146 | struct dasd_ccw_req *cqr; |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3147 | unsigned long flags; |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3148 | int rc = 0; |
| 3149 | |
Sebastian Ott | c5205f2 | 2018-06-04 19:07:39 +0200 | [diff] [blame] | 3150 | cqr = blk_mq_rq_to_pdu(req); |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3151 | if (!cqr) |
Christoph Hellwig | 6600593 | 2018-05-29 15:52:29 +0200 | [diff] [blame] | 3152 | return BLK_EH_DONE; |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3153 | |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3154 | spin_lock_irqsave(&cqr->dq->lock, flags); |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3155 | device = cqr->startdev ? cqr->startdev : block->base; |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3156 | if (!device->blk_timeout) { |
| 3157 | spin_unlock_irqrestore(&cqr->dq->lock, flags); |
Hannes Reinecke | 3d71ad3 | 2013-01-30 09:26:18 +0000 | [diff] [blame] | 3158 | return BLK_EH_RESET_TIMER; |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3159 | } |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3160 | DBF_DEV_EVENT(DBF_WARNING, device, |
| 3161 | " dasd_times_out cqr %p status %x", |
| 3162 | cqr, cqr->status); |
| 3163 | |
| 3164 | spin_lock(&block->queue_lock); |
| 3165 | spin_lock(get_ccwdev_lock(device->cdev)); |
| 3166 | cqr->retries = -1; |
| 3167 | cqr->intrc = -ETIMEDOUT; |
| 3168 | if (cqr->status >= DASD_CQR_QUEUED) { |
Sebastian Ott | 1bcdb53 | 2018-05-16 11:25:21 +0200 | [diff] [blame] | 3169 | rc = __dasd_cancel_req(cqr); |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3170 | } else if (cqr->status == DASD_CQR_FILLED || |
| 3171 | cqr->status == DASD_CQR_NEED_ERP) { |
| 3172 | cqr->status = DASD_CQR_TERMINATED; |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3173 | } else if (cqr->status == DASD_CQR_IN_ERP) { |
| 3174 | struct dasd_ccw_req *searchcqr, *nextcqr, *tmpcqr; |
| 3175 | |
| 3176 | list_for_each_entry_safe(searchcqr, nextcqr, |
| 3177 | &block->ccw_queue, blocklist) { |
| 3178 | tmpcqr = searchcqr; |
| 3179 | while (tmpcqr->refers) |
| 3180 | tmpcqr = tmpcqr->refers; |
| 3181 | if (tmpcqr != cqr) |
| 3182 | continue; |
| 3183 | /* searchcqr is an ERP request for cqr */ |
| 3184 | searchcqr->retries = -1; |
| 3185 | searchcqr->intrc = -ETIMEDOUT; |
| 3186 | if (searchcqr->status >= DASD_CQR_QUEUED) { |
Sebastian Ott | 1bcdb53 | 2018-05-16 11:25:21 +0200 | [diff] [blame] | 3187 | rc = __dasd_cancel_req(searchcqr); |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3188 | } else if ((searchcqr->status == DASD_CQR_FILLED) || |
| 3189 | (searchcqr->status == DASD_CQR_NEED_ERP)) { |
| 3190 | searchcqr->status = DASD_CQR_TERMINATED; |
| 3191 | rc = 0; |
| 3192 | } else if (searchcqr->status == DASD_CQR_IN_ERP) { |
| 3193 | /* |
| 3194 | * Shouldn't happen; most recent ERP |
| 3195 | * request is at the front of queue |
| 3196 | */ |
| 3197 | continue; |
| 3198 | } |
| 3199 | break; |
| 3200 | } |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3201 | } |
Sebastian Ott | 1bcdb53 | 2018-05-16 11:25:21 +0200 | [diff] [blame] | 3202 | spin_unlock(get_ccwdev_lock(device->cdev)); |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3203 | dasd_schedule_block_bh(block); |
| 3204 | spin_unlock(&block->queue_lock); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3205 | spin_unlock_irqrestore(&cqr->dq->lock, flags); |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3206 | |
Christoph Hellwig | 6600593 | 2018-05-29 15:52:29 +0200 | [diff] [blame] | 3207 | return rc ? BLK_EH_RESET_TIMER : BLK_EH_DONE; |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3208 | } |
| 3209 | |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3210 | static int dasd_init_hctx(struct blk_mq_hw_ctx *hctx, void *data, |
| 3211 | unsigned int idx) |
| 3212 | { |
| 3213 | struct dasd_queue *dq = kzalloc(sizeof(*dq), GFP_KERNEL); |
| 3214 | |
| 3215 | if (!dq) |
| 3216 | return -ENOMEM; |
| 3217 | |
| 3218 | spin_lock_init(&dq->lock); |
| 3219 | hctx->driver_data = dq; |
| 3220 | |
| 3221 | return 0; |
| 3222 | } |
| 3223 | |
| 3224 | static void dasd_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int idx) |
| 3225 | { |
| 3226 | kfree(hctx->driver_data); |
| 3227 | hctx->driver_data = NULL; |
| 3228 | } |
| 3229 | |
| 3230 | static void dasd_request_done(struct request *req) |
| 3231 | { |
| 3232 | blk_mq_end_request(req, 0); |
| 3233 | blk_mq_run_hw_queues(req->q, true); |
| 3234 | } |
| 3235 | |
| 3236 | static struct blk_mq_ops dasd_mq_ops = { |
| 3237 | .queue_rq = do_dasd_request, |
| 3238 | .complete = dasd_request_done, |
| 3239 | .timeout = dasd_times_out, |
| 3240 | .init_hctx = dasd_init_hctx, |
| 3241 | .exit_hctx = dasd_exit_hctx, |
| 3242 | }; |
| 3243 | |
Hannes Reinecke | a2ace46 | 2013-01-30 09:26:14 +0000 | [diff] [blame] | 3244 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | * Allocate and initialize request queue and default I/O scheduler. |
| 3246 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3247 | static int dasd_alloc_queue(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | { |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3249 | int rc; |
| 3250 | |
| 3251 | block->tag_set.ops = &dasd_mq_ops; |
Sebastian Ott | c5205f2 | 2018-06-04 19:07:39 +0200 | [diff] [blame] | 3252 | block->tag_set.cmd_size = sizeof(struct dasd_ccw_req); |
Stefan Haberland | 3284da3 | 2018-06-12 16:47:10 +0200 | [diff] [blame] | 3253 | block->tag_set.nr_hw_queues = nr_hw_queues; |
| 3254 | block->tag_set.queue_depth = queue_depth; |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3255 | block->tag_set.flags = BLK_MQ_F_SHOULD_MERGE; |
Vasily Gorbik | b17e3ab | 2018-06-24 09:21:59 +0200 | [diff] [blame] | 3256 | block->tag_set.numa_node = NUMA_NO_NODE; |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3257 | |
| 3258 | rc = blk_mq_alloc_tag_set(&block->tag_set); |
| 3259 | if (rc) |
| 3260 | return rc; |
| 3261 | |
| 3262 | block->request_queue = blk_mq_init_queue(&block->tag_set); |
| 3263 | if (IS_ERR(block->request_queue)) |
| 3264 | return PTR_ERR(block->request_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3266 | block->request_queue->queuedata = block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | |
Stefan Haberland | a5fd8dd | 2015-03-04 14:29:47 +0100 | [diff] [blame] | 3268 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | } |
| 3270 | |
| 3271 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | * Deactivate and free request queue. |
| 3273 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3274 | static void dasd_free_queue(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3276 | if (block->request_queue) { |
| 3277 | blk_cleanup_queue(block->request_queue); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3278 | blk_mq_free_tag_set(&block->tag_set); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3279 | block->request_queue = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | } |
| 3281 | } |
| 3282 | |
Al Viro | 57a7c0b | 2008-03-02 10:36:08 -0500 | [diff] [blame] | 3283 | static int dasd_open(struct block_device *bdev, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | { |
Stefan Haberland | 9eb2512 | 2010-02-26 22:37:46 +0100 | [diff] [blame] | 3285 | struct dasd_device *base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3286 | int rc; |
| 3287 | |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 3288 | base = dasd_device_from_gendisk(bdev->bd_disk); |
| 3289 | if (!base) |
Stefan Haberland | 9eb2512 | 2010-02-26 22:37:46 +0100 | [diff] [blame] | 3290 | return -ENODEV; |
| 3291 | |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 3292 | atomic_inc(&base->block->open_count); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3293 | if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | rc = -ENODEV; |
| 3295 | goto unlock; |
| 3296 | } |
| 3297 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3298 | if (!try_module_get(base->discipline->owner)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | rc = -EINVAL; |
| 3300 | goto unlock; |
| 3301 | } |
| 3302 | |
| 3303 | if (dasd_probeonly) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 3304 | dev_info(&base->cdev->dev, |
| 3305 | "Accessing the DASD failed because it is in " |
| 3306 | "probeonly mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3307 | rc = -EPERM; |
| 3308 | goto out; |
| 3309 | } |
| 3310 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3311 | if (base->state <= DASD_STATE_BASIC) { |
| 3312 | DBF_DEV_EVENT(DBF_ERR, base, " %s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | " Cannot open unrecognized device"); |
| 3314 | rc = -ENODEV; |
| 3315 | goto out; |
| 3316 | } |
| 3317 | |
Stefan Weinhuber | 33b62a3 | 2010-03-08 12:26:24 +0100 | [diff] [blame] | 3318 | if ((mode & FMODE_WRITE) && |
| 3319 | (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) || |
| 3320 | (base->features & DASD_FEATURE_READONLY))) { |
| 3321 | rc = -EROFS; |
| 3322 | goto out; |
| 3323 | } |
| 3324 | |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 3325 | dasd_put_device(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | return 0; |
| 3327 | |
| 3328 | out: |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3329 | module_put(base->discipline->owner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | unlock: |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 3331 | atomic_dec(&base->block->open_count); |
| 3332 | dasd_put_device(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | return rc; |
| 3334 | } |
| 3335 | |
Al Viro | db2a144 | 2013-05-05 21:52:57 -0400 | [diff] [blame] | 3336 | static void dasd_release(struct gendisk *disk, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | { |
Al Viro | db2a144 | 2013-05-05 21:52:57 -0400 | [diff] [blame] | 3338 | struct dasd_device *base = dasd_device_from_gendisk(disk); |
| 3339 | if (base) { |
| 3340 | atomic_dec(&base->block->open_count); |
| 3341 | module_put(base->discipline->owner); |
| 3342 | dasd_put_device(base); |
| 3343 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | } |
| 3345 | |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 3346 | /* |
| 3347 | * Return disk geometry. |
| 3348 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3349 | static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 3350 | { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3351 | struct dasd_device *base; |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 3352 | |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 3353 | base = dasd_device_from_gendisk(bdev->bd_disk); |
| 3354 | if (!base) |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 3355 | return -ENODEV; |
| 3356 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3357 | if (!base->discipline || |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 3358 | !base->discipline->fill_geometry) { |
| 3359 | dasd_put_device(base); |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 3360 | return -EINVAL; |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 3361 | } |
| 3362 | base->discipline->fill_geometry(base->block, geo); |
| 3363 | geo->start = get_start_sect(bdev) >> base->block->s2b_shift; |
| 3364 | dasd_put_device(base); |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 3365 | return 0; |
| 3366 | } |
| 3367 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 3368 | const struct block_device_operations |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | dasd_device_operations = { |
| 3370 | .owner = THIS_MODULE, |
Al Viro | 57a7c0b | 2008-03-02 10:36:08 -0500 | [diff] [blame] | 3371 | .open = dasd_open, |
| 3372 | .release = dasd_release, |
Heiko Carstens | 0000d03 | 2009-03-26 15:23:45 +0100 | [diff] [blame] | 3373 | .ioctl = dasd_ioctl, |
| 3374 | .compat_ioctl = dasd_ioctl, |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 3375 | .getgeo = dasd_getgeo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | }; |
| 3377 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3378 | /******************************************************************************* |
| 3379 | * end of block device operations |
| 3380 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | |
| 3382 | static void |
| 3383 | dasd_exit(void) |
| 3384 | { |
| 3385 | #ifdef CONFIG_PROC_FS |
| 3386 | dasd_proc_exit(); |
| 3387 | #endif |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 3388 | dasd_eer_exit(); |
Chengguang Xu | 734781a | 2018-08-28 07:51:30 +0800 | [diff] [blame] | 3389 | kmem_cache_destroy(dasd_page_cache); |
| 3390 | dasd_page_cache = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | dasd_gendisk_exit(); |
| 3392 | dasd_devmap_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | if (dasd_debug_area != NULL) { |
| 3394 | debug_unregister(dasd_debug_area); |
| 3395 | dasd_debug_area = NULL; |
| 3396 | } |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 3397 | dasd_statistics_removeroot(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | } |
| 3399 | |
| 3400 | /* |
| 3401 | * SECTION: common functions for ccw_driver use |
| 3402 | */ |
| 3403 | |
Stefan Weinhuber | 33b62a3 | 2010-03-08 12:26:24 +0100 | [diff] [blame] | 3404 | /* |
| 3405 | * Is the device read-only? |
| 3406 | * Note that this function does not report the setting of the |
| 3407 | * readonly device attribute, but how it is configured in z/VM. |
| 3408 | */ |
| 3409 | int dasd_device_is_ro(struct dasd_device *device) |
| 3410 | { |
| 3411 | struct ccw_dev_id dev_id; |
| 3412 | struct diag210 diag_data; |
| 3413 | int rc; |
| 3414 | |
| 3415 | if (!MACHINE_IS_VM) |
| 3416 | return 0; |
| 3417 | ccw_device_get_id(device->cdev, &dev_id); |
| 3418 | memset(&diag_data, 0, sizeof(diag_data)); |
| 3419 | diag_data.vrdcdvno = dev_id.devno; |
| 3420 | diag_data.vrdclen = sizeof(diag_data); |
| 3421 | rc = diag210(&diag_data); |
| 3422 | if (rc == 0 || rc == 2) { |
| 3423 | return diag_data.vrdcvfla & 0x80; |
| 3424 | } else { |
| 3425 | DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d", |
| 3426 | dev_id.devno, rc); |
| 3427 | return 0; |
| 3428 | } |
| 3429 | } |
| 3430 | EXPORT_SYMBOL_GPL(dasd_device_is_ro); |
| 3431 | |
Cornelia Huck | f3445a1 | 2009-04-14 15:36:23 +0200 | [diff] [blame] | 3432 | static void dasd_generic_auto_online(void *data, async_cookie_t cookie) |
| 3433 | { |
| 3434 | struct ccw_device *cdev = data; |
| 3435 | int ret; |
| 3436 | |
| 3437 | ret = ccw_device_set_online(cdev); |
| 3438 | if (ret) |
Fabian Frederick | 4ce2596 | 2014-06-26 19:41:48 +0200 | [diff] [blame] | 3439 | pr_warn("%s: Setting the DASD online failed with rc=%d\n", |
| 3440 | dev_name(&cdev->dev), ret); |
Cornelia Huck | f3445a1 | 2009-04-14 15:36:23 +0200 | [diff] [blame] | 3441 | } |
| 3442 | |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 3443 | /* |
| 3444 | * Initial attempt at a probe function. this can be simplified once |
| 3445 | * the other detection code is gone. |
| 3446 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3447 | int dasd_generic_probe(struct ccw_device *cdev, |
| 3448 | struct dasd_discipline *discipline) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | { |
| 3450 | int ret; |
| 3451 | |
| 3452 | ret = dasd_add_sysfs_files(cdev); |
| 3453 | if (ret) { |
Stefan Haberland | b8ed5dd | 2009-12-07 12:51:52 +0100 | [diff] [blame] | 3454 | DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s", |
| 3455 | "dasd_generic_probe: could not add " |
| 3456 | "sysfs entries"); |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 3457 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | } |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 3459 | cdev->handler = &dasd_int_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 3461 | /* |
| 3462 | * Automatically online either all dasd devices (dasd_autodetect) |
| 3463 | * or all devices specified with dasd= parameters during |
| 3464 | * initial probe. |
| 3465 | */ |
| 3466 | if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) || |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 3467 | (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0)) |
Cornelia Huck | f3445a1 | 2009-04-14 15:36:23 +0200 | [diff] [blame] | 3468 | async_schedule(dasd_generic_auto_online, cdev); |
Stefan Haberland | de3e0da | 2008-01-26 14:11:08 +0100 | [diff] [blame] | 3469 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 3471 | EXPORT_SYMBOL_GPL(dasd_generic_probe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | |
Stefan Haberland | c020d72 | 2016-09-20 10:42:38 +0200 | [diff] [blame] | 3473 | void dasd_generic_free_discipline(struct dasd_device *device) |
| 3474 | { |
| 3475 | /* Forget the discipline information. */ |
| 3476 | if (device->discipline) { |
| 3477 | if (device->discipline->uncheck_device) |
| 3478 | device->discipline->uncheck_device(device); |
| 3479 | module_put(device->discipline->owner); |
| 3480 | device->discipline = NULL; |
| 3481 | } |
| 3482 | if (device->base_discipline) { |
| 3483 | module_put(device->base_discipline->owner); |
| 3484 | device->base_discipline = NULL; |
| 3485 | } |
| 3486 | } |
| 3487 | EXPORT_SYMBOL_GPL(dasd_generic_free_discipline); |
| 3488 | |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 3489 | /* |
| 3490 | * This will one day be called from a global not_oper handler. |
| 3491 | * It is also used by driver_unregister during module unload. |
| 3492 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3493 | void dasd_generic_remove(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | { |
| 3495 | struct dasd_device *device; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3496 | struct dasd_block *block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | |
Horst Hummel | 59afda7 | 2005-05-16 21:53:39 -0700 | [diff] [blame] | 3498 | cdev->handler = NULL; |
| 3499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | device = dasd_device_from_cdev(cdev); |
Stefan Weinhuber | be4904e | 2013-02-04 13:10:35 +0100 | [diff] [blame] | 3501 | if (IS_ERR(device)) { |
| 3502 | dasd_remove_sysfs_files(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | return; |
Stefan Weinhuber | be4904e | 2013-02-04 13:10:35 +0100 | [diff] [blame] | 3504 | } |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 3505 | if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) && |
| 3506 | !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3507 | /* Already doing offline processing */ |
| 3508 | dasd_put_device(device); |
Stefan Weinhuber | be4904e | 2013-02-04 13:10:35 +0100 | [diff] [blame] | 3509 | dasd_remove_sysfs_files(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3510 | return; |
| 3511 | } |
| 3512 | /* |
| 3513 | * This device is removed unconditionally. Set offline |
| 3514 | * flag to prevent dasd_open from opening it while it is |
| 3515 | * no quite down yet. |
| 3516 | */ |
| 3517 | dasd_set_target_state(device, DASD_STATE_NEW); |
| 3518 | /* dasd_delete_device destroys the device reference. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3519 | block = device->block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | dasd_delete_device(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3521 | /* |
| 3522 | * life cycle of block is bound to device, so delete it after |
| 3523 | * device was safely removed |
| 3524 | */ |
| 3525 | if (block) |
| 3526 | dasd_free_block(block); |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 3527 | |
| 3528 | dasd_remove_sysfs_files(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 3530 | EXPORT_SYMBOL_GPL(dasd_generic_remove); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 3532 | /* |
| 3533 | * Activate a device. This is called from dasd_{eckd,fba}_probe() when either |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | * the device is detected for the first time and is supposed to be used |
Horst Hummel | 1c01b8a | 2006-01-06 00:19:15 -0800 | [diff] [blame] | 3535 | * or the user has started activation through sysfs. |
| 3536 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3537 | int dasd_generic_set_online(struct ccw_device *cdev, |
| 3538 | struct dasd_discipline *base_discipline) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | { |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 3540 | struct dasd_discipline *discipline; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | struct dasd_device *device; |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 3542 | int rc; |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 3543 | |
Horst Hummel | 4054557 | 2006-06-29 15:08:18 +0200 | [diff] [blame] | 3544 | /* first online clears initial online feature flag */ |
| 3545 | dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | device = dasd_create_device(cdev); |
| 3547 | if (IS_ERR(device)) |
| 3548 | return PTR_ERR(device); |
| 3549 | |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 3550 | discipline = base_discipline; |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 3551 | if (device->features & DASD_FEATURE_USEDIAG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | if (!dasd_diag_discipline_pointer) { |
Peter Oberparleiter | 7c53fcb | 2015-05-11 13:08:05 +0200 | [diff] [blame] | 3553 | /* Try to load the required module. */ |
| 3554 | rc = request_module(DASD_DIAG_MOD); |
| 3555 | if (rc) { |
| 3556 | pr_warn("%s Setting the DASD online failed " |
| 3557 | "because the required module %s " |
| 3558 | "could not be loaded (rc=%d)\n", |
| 3559 | dev_name(&cdev->dev), DASD_DIAG_MOD, |
| 3560 | rc); |
| 3561 | dasd_delete_device(device); |
| 3562 | return -ENODEV; |
| 3563 | } |
| 3564 | } |
| 3565 | /* Module init could have failed, so check again here after |
| 3566 | * request_module(). */ |
| 3567 | if (!dasd_diag_discipline_pointer) { |
Fabian Frederick | 4ce2596 | 2014-06-26 19:41:48 +0200 | [diff] [blame] | 3568 | pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n", |
| 3569 | dev_name(&cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | dasd_delete_device(device); |
| 3571 | return -ENODEV; |
| 3572 | } |
| 3573 | discipline = dasd_diag_discipline_pointer; |
| 3574 | } |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 3575 | if (!try_module_get(base_discipline->owner)) { |
| 3576 | dasd_delete_device(device); |
| 3577 | return -EINVAL; |
| 3578 | } |
| 3579 | if (!try_module_get(discipline->owner)) { |
| 3580 | module_put(base_discipline->owner); |
| 3581 | dasd_delete_device(device); |
| 3582 | return -EINVAL; |
| 3583 | } |
| 3584 | device->base_discipline = base_discipline; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | device->discipline = discipline; |
| 3586 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3587 | /* check_device will allocate block device if necessary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | rc = discipline->check_device(device); |
| 3589 | if (rc) { |
Fabian Frederick | 4ce2596 | 2014-06-26 19:41:48 +0200 | [diff] [blame] | 3590 | pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n", |
| 3591 | dev_name(&cdev->dev), discipline->name, rc); |
Peter Oberparleiter | aa88861 | 2006-02-20 18:28:13 -0800 | [diff] [blame] | 3592 | module_put(discipline->owner); |
| 3593 | module_put(base_discipline->owner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3594 | dasd_delete_device(device); |
| 3595 | return rc; |
| 3596 | } |
| 3597 | |
| 3598 | dasd_set_target_state(device, DASD_STATE_ONLINE); |
| 3599 | if (device->state <= DASD_STATE_KNOWN) { |
Fabian Frederick | 4ce2596 | 2014-06-26 19:41:48 +0200 | [diff] [blame] | 3600 | pr_warn("%s Setting the DASD online failed because of a missing discipline\n", |
| 3601 | dev_name(&cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3602 | rc = -ENODEV; |
| 3603 | dasd_set_target_state(device, DASD_STATE_NEW); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3604 | if (device->block) |
| 3605 | dasd_free_block(device->block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | dasd_delete_device(device); |
| 3607 | } else |
| 3608 | pr_debug("dasd_generic device %s found\n", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 3609 | dev_name(&cdev->dev)); |
Stefan Haberland | 589c74d | 2010-02-26 22:37:47 +0100 | [diff] [blame] | 3610 | |
| 3611 | wait_event(dasd_init_waitq, _wait_for_device(device)); |
| 3612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | dasd_put_device(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 | return rc; |
| 3615 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 3616 | EXPORT_SYMBOL_GPL(dasd_generic_set_online); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3618 | int dasd_generic_set_offline(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | { |
| 3620 | struct dasd_device *device; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3621 | struct dasd_block *block; |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 3622 | int max_count, open_count, rc; |
Jan Höppner | 0f57c97 | 2016-10-18 17:54:49 +0200 | [diff] [blame] | 3623 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 3625 | rc = 0; |
Jan Höppner | 0f57c97 | 2016-10-18 17:54:49 +0200 | [diff] [blame] | 3626 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
| 3627 | device = dasd_device_from_cdev_locked(cdev); |
| 3628 | if (IS_ERR(device)) { |
| 3629 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | return PTR_ERR(device); |
Jan Höppner | 0f57c97 | 2016-10-18 17:54:49 +0200 | [diff] [blame] | 3631 | } |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 3632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3633 | /* |
| 3634 | * We must make sure that this device is currently not in use. |
| 3635 | * The open_count is increased for every opener, that includes |
| 3636 | * the blkdev_get in dasd_scan_partitions. We are only interested |
| 3637 | * in the other openers. |
| 3638 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3639 | if (device->block) { |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 3640 | max_count = device->block->bdev ? 0 : -1; |
| 3641 | open_count = atomic_read(&device->block->open_count); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3642 | if (open_count > max_count) { |
| 3643 | if (open_count > 0) |
Fabian Frederick | 4ce2596 | 2014-06-26 19:41:48 +0200 | [diff] [blame] | 3644 | pr_warn("%s: The DASD cannot be set offline with open count %i\n", |
| 3645 | dev_name(&cdev->dev), open_count); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3646 | else |
Fabian Frederick | 4ce2596 | 2014-06-26 19:41:48 +0200 | [diff] [blame] | 3647 | pr_warn("%s: The DASD cannot be set offline while it is in use\n", |
| 3648 | dev_name(&cdev->dev)); |
Stefan Haberland | 2757fe1d | 2017-05-16 10:30:13 +0200 | [diff] [blame] | 3649 | rc = -EBUSY; |
| 3650 | goto out_err; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3651 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | } |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 3653 | |
Stefan Haberland | 2757fe1d | 2017-05-16 10:30:13 +0200 | [diff] [blame] | 3654 | /* |
| 3655 | * Test if the offline processing is already running and exit if so. |
| 3656 | * If a safe offline is being processed this could only be a normal |
| 3657 | * offline that should be able to overtake the safe offline and |
| 3658 | * cancel any I/O we do not want to wait for any longer |
| 3659 | */ |
| 3660 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) { |
| 3661 | if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) { |
| 3662 | clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, |
| 3663 | &device->flags); |
| 3664 | } else { |
| 3665 | rc = -EBUSY; |
| 3666 | goto out_err; |
| 3667 | } |
Jan Höppner | 0f57c97 | 2016-10-18 17:54:49 +0200 | [diff] [blame] | 3668 | } |
Jan Höppner | 0f57c97 | 2016-10-18 17:54:49 +0200 | [diff] [blame] | 3669 | set_bit(DASD_FLAG_OFFLINE, &device->flags); |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 3670 | |
| 3671 | /* |
Stefan Haberland | 2757fe1d | 2017-05-16 10:30:13 +0200 | [diff] [blame] | 3672 | * if safe_offline is called set safe_offline_running flag and |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 3673 | * clear safe_offline so that a call to normal offline |
| 3674 | * can overrun safe_offline processing |
| 3675 | */ |
| 3676 | if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) && |
| 3677 | !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) { |
Stefan Haberland | 2757fe1d | 2017-05-16 10:30:13 +0200 | [diff] [blame] | 3678 | /* need to unlock here to wait for outstanding I/O */ |
| 3679 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 3680 | /* |
| 3681 | * If we want to set the device safe offline all IO operations |
| 3682 | * should be finished before continuing the offline process |
| 3683 | * so sync bdev first and then wait for our queues to become |
| 3684 | * empty |
| 3685 | */ |
Stefan Haberland | ca732e1 | 2017-01-25 16:56:41 +0100 | [diff] [blame] | 3686 | if (device->block) { |
| 3687 | rc = fsync_bdev(device->block->bdev); |
| 3688 | if (rc != 0) |
| 3689 | goto interrupted; |
| 3690 | } |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 3691 | dasd_schedule_device_bh(device); |
| 3692 | rc = wait_event_interruptible(shutdown_waitq, |
| 3693 | _wait_for_empty_queues(device)); |
| 3694 | if (rc != 0) |
| 3695 | goto interrupted; |
Stefan Haberland | 2757fe1d | 2017-05-16 10:30:13 +0200 | [diff] [blame] | 3696 | |
| 3697 | /* |
| 3698 | * check if a normal offline process overtook the offline |
| 3699 | * processing in this case simply do nothing beside returning |
| 3700 | * that we got interrupted |
| 3701 | * otherwise mark safe offline as not running any longer and |
| 3702 | * continue with normal offline |
| 3703 | */ |
| 3704 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
| 3705 | if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) { |
| 3706 | rc = -ERESTARTSYS; |
| 3707 | goto out_err; |
| 3708 | } |
| 3709 | clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags); |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 3710 | } |
Stefan Haberland | 2757fe1d | 2017-05-16 10:30:13 +0200 | [diff] [blame] | 3711 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 3712 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | dasd_set_target_state(device, DASD_STATE_NEW); |
| 3714 | /* dasd_delete_device destroys the device reference. */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3715 | block = device->block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | dasd_delete_device(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3717 | /* |
| 3718 | * life cycle of block is bound to device, so delete it after |
| 3719 | * device was safely removed |
| 3720 | */ |
| 3721 | if (block) |
| 3722 | dasd_free_block(block); |
Stefan Haberland | 2757fe1d | 2017-05-16 10:30:13 +0200 | [diff] [blame] | 3723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3724 | return 0; |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 3725 | |
| 3726 | interrupted: |
| 3727 | /* interrupted by signal */ |
Stefan Haberland | 2757fe1d | 2017-05-16 10:30:13 +0200 | [diff] [blame] | 3728 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
Stefan Haberland | d07dc5d | 2012-11-28 13:43:38 +0100 | [diff] [blame] | 3729 | clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags); |
| 3730 | clear_bit(DASD_FLAG_OFFLINE, &device->flags); |
Stefan Haberland | 2757fe1d | 2017-05-16 10:30:13 +0200 | [diff] [blame] | 3731 | out_err: |
Jan Höppner | 0f57c97 | 2016-10-18 17:54:49 +0200 | [diff] [blame] | 3732 | dasd_put_device(device); |
| 3733 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
Stefan Haberland | 2757fe1d | 2017-05-16 10:30:13 +0200 | [diff] [blame] | 3734 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 3736 | EXPORT_SYMBOL_GPL(dasd_generic_set_offline); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3737 | |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3738 | int dasd_generic_last_path_gone(struct dasd_device *device) |
| 3739 | { |
| 3740 | struct dasd_ccw_req *cqr; |
| 3741 | |
| 3742 | dev_warn(&device->cdev->dev, "No operational channel path is left " |
| 3743 | "for the device\n"); |
| 3744 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone"); |
| 3745 | /* First of all call extended error reporting. */ |
| 3746 | dasd_eer_write(device, NULL, DASD_EER_NOPATH); |
| 3747 | |
| 3748 | if (device->state < DASD_STATE_BASIC) |
| 3749 | return 0; |
| 3750 | /* Device is active. We want to keep it. */ |
| 3751 | list_for_each_entry(cqr, &device->ccw_queue, devlist) |
| 3752 | if ((cqr->status == DASD_CQR_IN_IO) || |
| 3753 | (cqr->status == DASD_CQR_CLEAR_PENDING)) { |
| 3754 | cqr->status = DASD_CQR_QUEUED; |
| 3755 | cqr->retries++; |
| 3756 | } |
| 3757 | dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT); |
| 3758 | dasd_device_clear_timer(device); |
| 3759 | dasd_schedule_device_bh(device); |
| 3760 | return 1; |
| 3761 | } |
| 3762 | EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone); |
| 3763 | |
| 3764 | int dasd_generic_path_operational(struct dasd_device *device) |
| 3765 | { |
| 3766 | dev_info(&device->cdev->dev, "A channel path to the device has become " |
| 3767 | "operational\n"); |
| 3768 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational"); |
| 3769 | dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT); |
| 3770 | if (device->stopped & DASD_UNRESUMED_PM) { |
| 3771 | dasd_device_remove_stop_bits(device, DASD_UNRESUMED_PM); |
| 3772 | dasd_restore_device(device); |
| 3773 | return 1; |
| 3774 | } |
| 3775 | dasd_schedule_device_bh(device); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3776 | if (device->block) { |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3777 | dasd_schedule_block_bh(device->block); |
Stefan Haberland | 673514a | 2017-09-12 17:22:42 +0200 | [diff] [blame] | 3778 | if (device->block->request_queue) |
| 3779 | blk_mq_run_hw_queues(device->block->request_queue, |
| 3780 | true); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 3781 | } |
Stefan Haberland | 931a3dc | 2014-07-18 14:22:41 +0200 | [diff] [blame] | 3782 | |
| 3783 | if (!device->stopped) |
| 3784 | wake_up(&generic_waitq); |
| 3785 | |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3786 | return 1; |
| 3787 | } |
| 3788 | EXPORT_SYMBOL_GPL(dasd_generic_path_operational); |
| 3789 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 3790 | int dasd_generic_notify(struct ccw_device *cdev, int event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | { |
| 3792 | struct dasd_device *device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3793 | int ret; |
| 3794 | |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 3795 | device = dasd_device_from_cdev_locked(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | if (IS_ERR(device)) |
| 3797 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | ret = 0; |
| 3799 | switch (event) { |
| 3800 | case CIO_GONE: |
Sebastian Ott | 47593bf | 2009-03-31 19:16:05 +0200 | [diff] [blame] | 3801 | case CIO_BOXED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | case CIO_NO_PATH: |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 3803 | dasd_path_no_path(device); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3804 | ret = dasd_generic_last_path_gone(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | break; |
| 3806 | case CIO_OPER: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | ret = 1; |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 3808 | if (dasd_path_get_opm(device)) |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3809 | ret = dasd_generic_path_operational(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | break; |
| 3811 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | dasd_put_device(device); |
| 3813 | return ret; |
| 3814 | } |
Fabian Frederick | 7048a2b | 2014-06-26 19:41:47 +0200 | [diff] [blame] | 3815 | EXPORT_SYMBOL_GPL(dasd_generic_notify); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3816 | |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3817 | void dasd_generic_path_event(struct ccw_device *cdev, int *path_event) |
| 3818 | { |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3819 | struct dasd_device *device; |
Stefan Haberland | a521b04 | 2016-08-08 15:56:54 +0200 | [diff] [blame] | 3820 | int chp, oldopm, hpfpm, ifccpm; |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3821 | |
| 3822 | device = dasd_device_from_cdev_locked(cdev); |
| 3823 | if (IS_ERR(device)) |
| 3824 | return; |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 3825 | |
| 3826 | oldopm = dasd_path_get_opm(device); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3827 | for (chp = 0; chp < 8; chp++) { |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3828 | if (path_event[chp] & PE_PATH_GONE) { |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 3829 | dasd_path_notoper(device, chp); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3830 | } |
| 3831 | if (path_event[chp] & PE_PATH_AVAILABLE) { |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 3832 | dasd_path_available(device, chp); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3833 | dasd_schedule_device_bh(device); |
| 3834 | } |
Stefan Haberland | f163303 | 2012-01-18 18:03:41 +0100 | [diff] [blame] | 3835 | if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) { |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 3836 | if (!dasd_path_is_operational(device, chp) && |
| 3837 | !dasd_path_need_verify(device, chp)) { |
Stefan Haberland | 12d7b10 | 2012-09-11 15:10:58 +0200 | [diff] [blame] | 3838 | /* |
| 3839 | * we can not establish a pathgroup on an |
| 3840 | * unavailable path, so trigger a path |
| 3841 | * verification first |
| 3842 | */ |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 3843 | dasd_path_available(device, chp); |
| 3844 | dasd_schedule_device_bh(device); |
Stefan Haberland | 12d7b10 | 2012-09-11 15:10:58 +0200 | [diff] [blame] | 3845 | } |
Stefan Haberland | f163303 | 2012-01-18 18:03:41 +0100 | [diff] [blame] | 3846 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
| 3847 | "Pathgroup re-established\n"); |
| 3848 | if (device->discipline->kick_validate) |
| 3849 | device->discipline->kick_validate(device); |
| 3850 | } |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3851 | } |
Stefan Haberland | a521b04 | 2016-08-08 15:56:54 +0200 | [diff] [blame] | 3852 | hpfpm = dasd_path_get_hpfpm(device); |
| 3853 | ifccpm = dasd_path_get_ifccpm(device); |
| 3854 | if (!dasd_path_get_opm(device) && hpfpm) { |
| 3855 | /* |
| 3856 | * device has no operational paths but at least one path is |
| 3857 | * disabled due to HPF errors |
| 3858 | * disable HPF at all and use the path(s) again |
| 3859 | */ |
| 3860 | if (device->discipline->disable_hpf) |
| 3861 | device->discipline->disable_hpf(device); |
| 3862 | dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC); |
| 3863 | dasd_path_set_tbvpm(device, hpfpm); |
| 3864 | dasd_schedule_device_bh(device); |
| 3865 | dasd_schedule_requeue(device); |
| 3866 | } else if (!dasd_path_get_opm(device) && ifccpm) { |
| 3867 | /* |
| 3868 | * device has no operational paths but at least one path is |
| 3869 | * disabled due to IFCC errors |
| 3870 | * trigger path verification on paths with IFCC errors |
| 3871 | */ |
| 3872 | dasd_path_set_tbvpm(device, ifccpm); |
| 3873 | dasd_schedule_device_bh(device); |
| 3874 | } |
| 3875 | if (oldopm && !dasd_path_get_opm(device) && !hpfpm && !ifccpm) { |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 3876 | dev_warn(&device->cdev->dev, |
| 3877 | "No verified channel paths remain for the device\n"); |
| 3878 | DBF_DEV_EVENT(DBF_WARNING, device, |
| 3879 | "%s", "last verified path gone"); |
| 3880 | dasd_eer_write(device, NULL, DASD_EER_NOPATH); |
| 3881 | dasd_device_set_stop_bits(device, |
| 3882 | DASD_STOPPED_DC_WAIT); |
| 3883 | } |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3884 | dasd_put_device(device); |
| 3885 | } |
| 3886 | EXPORT_SYMBOL_GPL(dasd_generic_path_event); |
| 3887 | |
| 3888 | int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm) |
| 3889 | { |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 3890 | if (!dasd_path_get_opm(device) && lpm) { |
| 3891 | dasd_path_set_opm(device, lpm); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3892 | dasd_generic_path_operational(device); |
| 3893 | } else |
Stefan Haberland | c934615 | 2016-08-08 15:53:54 +0200 | [diff] [blame] | 3894 | dasd_path_add_opm(device, lpm); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 3895 | return 0; |
| 3896 | } |
| 3897 | EXPORT_SYMBOL_GPL(dasd_generic_verify_path); |
| 3898 | |
Jan Höppner | 9e12e54 | 2018-07-03 10:56:51 +0200 | [diff] [blame] | 3899 | void dasd_generic_space_exhaust(struct dasd_device *device, |
| 3900 | struct dasd_ccw_req *cqr) |
| 3901 | { |
| 3902 | dasd_eer_write(device, NULL, DASD_EER_NOSPC); |
| 3903 | |
| 3904 | if (device->state < DASD_STATE_BASIC) |
| 3905 | return; |
| 3906 | |
| 3907 | if (cqr->status == DASD_CQR_IN_IO || |
| 3908 | cqr->status == DASD_CQR_CLEAR_PENDING) { |
| 3909 | cqr->status = DASD_CQR_QUEUED; |
| 3910 | cqr->retries++; |
| 3911 | } |
| 3912 | dasd_device_set_stop_bits(device, DASD_STOPPED_NOSPC); |
| 3913 | dasd_device_clear_timer(device); |
| 3914 | dasd_schedule_device_bh(device); |
| 3915 | } |
| 3916 | EXPORT_SYMBOL_GPL(dasd_generic_space_exhaust); |
| 3917 | |
| 3918 | void dasd_generic_space_avail(struct dasd_device *device) |
| 3919 | { |
| 3920 | dev_info(&device->cdev->dev, "Extent pool space is available\n"); |
| 3921 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", "space available"); |
| 3922 | |
| 3923 | dasd_device_remove_stop_bits(device, DASD_STOPPED_NOSPC); |
| 3924 | dasd_schedule_device_bh(device); |
| 3925 | |
| 3926 | if (device->block) { |
| 3927 | dasd_schedule_block_bh(device->block); |
| 3928 | if (device->block->request_queue) |
| 3929 | blk_mq_run_hw_queues(device->block->request_queue, true); |
| 3930 | } |
| 3931 | if (!device->stopped) |
| 3932 | wake_up(&generic_waitq); |
| 3933 | } |
| 3934 | EXPORT_SYMBOL_GPL(dasd_generic_space_avail); |
| 3935 | |
Stefan Haberland | a521b04 | 2016-08-08 15:56:54 +0200 | [diff] [blame] | 3936 | /* |
| 3937 | * clear active requests and requeue them to block layer if possible |
| 3938 | */ |
| 3939 | static int dasd_generic_requeue_all_requests(struct dasd_device *device) |
| 3940 | { |
| 3941 | struct list_head requeue_queue; |
| 3942 | struct dasd_ccw_req *cqr, *n; |
| 3943 | struct dasd_ccw_req *refers; |
| 3944 | int rc; |
| 3945 | |
| 3946 | INIT_LIST_HEAD(&requeue_queue); |
| 3947 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
| 3948 | rc = 0; |
| 3949 | list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) { |
| 3950 | /* Check status and move request to flush_queue */ |
| 3951 | if (cqr->status == DASD_CQR_IN_IO) { |
| 3952 | rc = device->discipline->term_IO(cqr); |
| 3953 | if (rc) { |
| 3954 | /* unable to terminate requeust */ |
| 3955 | dev_err(&device->cdev->dev, |
| 3956 | "Unable to terminate request %p " |
| 3957 | "on suspend\n", cqr); |
| 3958 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 3959 | dasd_put_device(device); |
| 3960 | return rc; |
| 3961 | } |
| 3962 | } |
| 3963 | list_move_tail(&cqr->devlist, &requeue_queue); |
| 3964 | } |
| 3965 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 3966 | |
| 3967 | list_for_each_entry_safe(cqr, n, &requeue_queue, devlist) { |
| 3968 | wait_event(dasd_flush_wq, |
| 3969 | (cqr->status != DASD_CQR_CLEAR_PENDING)); |
| 3970 | |
Stefan Haberland | 9487cfd | 2018-02-07 17:39:14 +0100 | [diff] [blame] | 3971 | /* |
| 3972 | * requeue requests to blocklayer will only work |
| 3973 | * for block device requests |
| 3974 | */ |
| 3975 | if (_dasd_requeue_request(cqr)) |
| 3976 | continue; |
Stefan Haberland | a521b04 | 2016-08-08 15:56:54 +0200 | [diff] [blame] | 3977 | |
| 3978 | /* remove requests from device and block queue */ |
| 3979 | list_del_init(&cqr->devlist); |
| 3980 | while (cqr->refers != NULL) { |
| 3981 | refers = cqr->refers; |
| 3982 | /* remove the request from the block queue */ |
| 3983 | list_del(&cqr->blocklist); |
| 3984 | /* free the finished erp request */ |
| 3985 | dasd_free_erp_request(cqr, cqr->memdev); |
| 3986 | cqr = refers; |
| 3987 | } |
| 3988 | |
Stefan Haberland | a1fc818 | 2018-02-19 12:24:39 +0100 | [diff] [blame] | 3989 | /* |
| 3990 | * _dasd_requeue_request already checked for a valid |
| 3991 | * blockdevice, no need to check again |
| 3992 | * all erp requests (cqr->refers) have a cqr->block |
| 3993 | * pointer copy from the original cqr |
| 3994 | */ |
| 3995 | list_del_init(&cqr->blocklist); |
Stefan Haberland | a521b04 | 2016-08-08 15:56:54 +0200 | [diff] [blame] | 3996 | cqr->block->base->discipline->free_cp( |
| 3997 | cqr, (struct request *) cqr->callback_data); |
| 3998 | } |
| 3999 | |
| 4000 | /* |
| 4001 | * if requests remain then they are internal request |
| 4002 | * and go back to the device queue |
| 4003 | */ |
| 4004 | if (!list_empty(&requeue_queue)) { |
| 4005 | /* move freeze_queue to start of the ccw_queue */ |
| 4006 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
| 4007 | list_splice_tail(&requeue_queue, &device->ccw_queue); |
| 4008 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
| 4009 | } |
Stefan Haberland | 9487cfd | 2018-02-07 17:39:14 +0100 | [diff] [blame] | 4010 | dasd_schedule_device_bh(device); |
Stefan Haberland | a521b04 | 2016-08-08 15:56:54 +0200 | [diff] [blame] | 4011 | return rc; |
| 4012 | } |
| 4013 | |
| 4014 | static void do_requeue_requests(struct work_struct *work) |
| 4015 | { |
| 4016 | struct dasd_device *device = container_of(work, struct dasd_device, |
| 4017 | requeue_requests); |
| 4018 | dasd_generic_requeue_all_requests(device); |
| 4019 | dasd_device_remove_stop_bits(device, DASD_STOPPED_NOT_ACC); |
| 4020 | if (device->block) |
| 4021 | dasd_schedule_block_bh(device->block); |
| 4022 | dasd_put_device(device); |
| 4023 | } |
| 4024 | |
| 4025 | void dasd_schedule_requeue(struct dasd_device *device) |
| 4026 | { |
| 4027 | dasd_get_device(device); |
| 4028 | /* queue call to dasd_reload_device to the kernel event daemon. */ |
| 4029 | if (!schedule_work(&device->requeue_requests)) |
| 4030 | dasd_put_device(device); |
| 4031 | } |
| 4032 | EXPORT_SYMBOL(dasd_schedule_requeue); |
Stefan Weinhuber | a4d26c6 | 2011-01-05 12:48:03 +0100 | [diff] [blame] | 4033 | |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4034 | int dasd_generic_pm_freeze(struct ccw_device *cdev) |
| 4035 | { |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4036 | struct dasd_device *device = dasd_device_from_cdev(cdev); |
| 4037 | |
| 4038 | if (IS_ERR(device)) |
| 4039 | return PTR_ERR(device); |
Stefan Haberland | 6f272b9 | 2011-01-05 12:48:05 +0100 | [diff] [blame] | 4040 | |
Stefan Haberland | c8d1c0f | 2011-10-30 15:17:09 +0100 | [diff] [blame] | 4041 | /* mark device as suspended */ |
| 4042 | set_bit(DASD_FLAG_SUSPENDED, &device->flags); |
| 4043 | |
Stefan Haberland | 6f272b9 | 2011-01-05 12:48:05 +0100 | [diff] [blame] | 4044 | if (device->discipline->freeze) |
Sebastian Ott | 4bca698 | 2017-06-26 19:26:55 +0200 | [diff] [blame] | 4045 | device->discipline->freeze(device); |
Stefan Haberland | 6f272b9 | 2011-01-05 12:48:05 +0100 | [diff] [blame] | 4046 | |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4047 | /* disallow new I/O */ |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 4048 | dasd_device_set_stop_bits(device, DASD_STOPPED_PM); |
Stefan Haberland | c557687 | 2013-04-15 16:41:31 +0200 | [diff] [blame] | 4049 | |
Stefan Haberland | a521b04 | 2016-08-08 15:56:54 +0200 | [diff] [blame] | 4050 | return dasd_generic_requeue_all_requests(device); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4051 | } |
| 4052 | EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze); |
| 4053 | |
| 4054 | int dasd_generic_restore_device(struct ccw_device *cdev) |
| 4055 | { |
| 4056 | struct dasd_device *device = dasd_device_from_cdev(cdev); |
| 4057 | int rc = 0; |
| 4058 | |
| 4059 | if (IS_ERR(device)) |
| 4060 | return PTR_ERR(device); |
| 4061 | |
Stefan Haberland | e6125fb | 2009-06-22 12:08:17 +0200 | [diff] [blame] | 4062 | /* allow new IO again */ |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 4063 | dasd_device_remove_stop_bits(device, |
| 4064 | (DASD_STOPPED_PM | DASD_UNRESUMED_PM)); |
Stefan Haberland | e6125fb | 2009-06-22 12:08:17 +0200 | [diff] [blame] | 4065 | |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4066 | dasd_schedule_device_bh(device); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4067 | |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 4068 | /* |
| 4069 | * call discipline restore function |
| 4070 | * if device is stopped do nothing e.g. for disconnected devices |
| 4071 | */ |
| 4072 | if (device->discipline->restore && !(device->stopped)) |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4073 | rc = device->discipline->restore(device); |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 4074 | if (rc || device->stopped) |
Stefan Haberland | e6125fb | 2009-06-22 12:08:17 +0200 | [diff] [blame] | 4075 | /* |
| 4076 | * if the resume failed for the DASD we put it in |
| 4077 | * an UNRESUMED stop state |
| 4078 | */ |
| 4079 | device->stopped |= DASD_UNRESUMED_PM; |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4080 | |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 4081 | if (device->block) { |
Stefan Haberland | 6fca97a | 2009-10-06 10:34:15 +0200 | [diff] [blame] | 4082 | dasd_schedule_block_bh(device->block); |
Stefan Haberland | 673514a | 2017-09-12 17:22:42 +0200 | [diff] [blame] | 4083 | if (device->block->request_queue) |
| 4084 | blk_mq_run_hw_queues(device->block->request_queue, |
| 4085 | true); |
Stefan Haberland | e443343 | 2017-05-22 10:59:11 +0200 | [diff] [blame] | 4086 | } |
Stefan Haberland | 6fca97a | 2009-10-06 10:34:15 +0200 | [diff] [blame] | 4087 | |
Stefan Haberland | c8d1c0f | 2011-10-30 15:17:09 +0100 | [diff] [blame] | 4088 | clear_bit(DASD_FLAG_SUSPENDED, &device->flags); |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4089 | dasd_put_device(device); |
Stefan Haberland | e6125fb | 2009-06-22 12:08:17 +0200 | [diff] [blame] | 4090 | return 0; |
Stefan Haberland | d41dd12 | 2009-06-16 10:30:25 +0200 | [diff] [blame] | 4091 | } |
| 4092 | EXPORT_SYMBOL_GPL(dasd_generic_restore_device); |
| 4093 | |
Heiko Carstens | 763968e | 2007-05-10 15:45:46 +0200 | [diff] [blame] | 4094 | static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device, |
Heiko Carstens | 763968e | 2007-05-10 15:45:46 +0200 | [diff] [blame] | 4095 | int rdc_buffer_size, |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 4096 | int magic) |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 4097 | { |
| 4098 | struct dasd_ccw_req *cqr; |
| 4099 | struct ccw1 *ccw; |
| 4100 | |
Sebastian Ott | c5205f2 | 2018-06-04 19:07:39 +0200 | [diff] [blame] | 4101 | cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device, |
| 4102 | NULL); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 4103 | |
| 4104 | if (IS_ERR(cqr)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 4105 | /* internal error 13 - Allocating the RDC request failed*/ |
| 4106 | dev_err(&device->cdev->dev, |
| 4107 | "An error occurred in the DASD device driver, " |
| 4108 | "reason=%s\n", "13"); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 4109 | return cqr; |
| 4110 | } |
| 4111 | |
| 4112 | ccw = cqr->cpaddr; |
| 4113 | ccw->cmd_code = CCW_CMD_RDC; |
Martin Schwidefsky | 9fe567d | 2019-03-01 16:03:47 +0100 | [diff] [blame] | 4114 | ccw->cda = (__u32)(addr_t) cqr->data; |
| 4115 | ccw->flags = 0; |
Stefan Haberland | d9fa944 | 2009-10-14 12:43:48 +0200 | [diff] [blame] | 4116 | ccw->count = rdc_buffer_size; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 4117 | cqr->startdev = device; |
| 4118 | cqr->memdev = device; |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 4119 | cqr->expires = 10*HZ; |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 4120 | cqr->retries = 256; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 4121 | cqr->buildclk = get_tod_clock(); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 4122 | cqr->status = DASD_CQR_FILLED; |
| 4123 | return cqr; |
| 4124 | } |
| 4125 | |
| 4126 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 4127 | int dasd_generic_read_dev_chars(struct dasd_device *device, int magic, |
Sebastian Ott | 92636b1 | 2009-06-12 10:26:37 +0200 | [diff] [blame] | 4128 | void *rdc_buffer, int rdc_buffer_size) |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 4129 | { |
| 4130 | int ret; |
| 4131 | struct dasd_ccw_req *cqr; |
| 4132 | |
Martin Schwidefsky | 9fe567d | 2019-03-01 16:03:47 +0100 | [diff] [blame] | 4133 | cqr = dasd_generic_build_rdc(device, rdc_buffer_size, magic); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 4134 | if (IS_ERR(cqr)) |
| 4135 | return PTR_ERR(cqr); |
| 4136 | |
| 4137 | ret = dasd_sleep_on(cqr); |
Martin Schwidefsky | 9fe567d | 2019-03-01 16:03:47 +0100 | [diff] [blame] | 4138 | if (ret == 0) |
| 4139 | memcpy(rdc_buffer, cqr->data, rdc_buffer_size); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 4140 | dasd_sfree_request(cqr, cqr->memdev); |
Cornelia Huck | 17283b5 | 2007-05-04 18:47:51 +0200 | [diff] [blame] | 4141 | return ret; |
| 4142 | } |
Cornelia Huck | aaff0f6 | 2007-05-10 15:45:45 +0200 | [diff] [blame] | 4143 | EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars); |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 4144 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 4145 | /* |
| 4146 | * In command mode and transport mode we need to look for sense |
| 4147 | * data in different places. The sense data itself is allways |
| 4148 | * an array of 32 bytes, so we can unify the sense data access |
| 4149 | * for both modes. |
| 4150 | */ |
| 4151 | char *dasd_get_sense(struct irb *irb) |
| 4152 | { |
| 4153 | struct tsb *tsb = NULL; |
| 4154 | char *sense = NULL; |
| 4155 | |
| 4156 | if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) { |
| 4157 | if (irb->scsw.tm.tcw) |
| 4158 | tsb = tcw_get_tsb((struct tcw *)(unsigned long) |
| 4159 | irb->scsw.tm.tcw); |
| 4160 | if (tsb && tsb->length == 64 && tsb->flags) |
| 4161 | switch (tsb->flags & 0x07) { |
| 4162 | case 1: /* tsa_iostat */ |
| 4163 | sense = tsb->tsa.iostat.sense; |
| 4164 | break; |
| 4165 | case 2: /* tsa_ddpc */ |
| 4166 | sense = tsb->tsa.ddpc.sense; |
| 4167 | break; |
| 4168 | default: |
| 4169 | /* currently we don't use interrogate data */ |
| 4170 | break; |
| 4171 | } |
| 4172 | } else if (irb->esw.esw0.erw.cons) { |
| 4173 | sense = irb->ecw; |
| 4174 | } |
| 4175 | return sense; |
| 4176 | } |
| 4177 | EXPORT_SYMBOL_GPL(dasd_get_sense); |
| 4178 | |
Stefan Haberland | 4679e89 | 2012-06-19 17:30:12 +0200 | [diff] [blame] | 4179 | void dasd_generic_shutdown(struct ccw_device *cdev) |
| 4180 | { |
| 4181 | struct dasd_device *device; |
| 4182 | |
| 4183 | device = dasd_device_from_cdev(cdev); |
| 4184 | if (IS_ERR(device)) |
| 4185 | return; |
| 4186 | |
| 4187 | if (device->block) |
| 4188 | dasd_schedule_block_bh(device->block); |
| 4189 | |
| 4190 | dasd_schedule_device_bh(device); |
| 4191 | |
| 4192 | wait_event(shutdown_waitq, _wait_for_empty_queues(device)); |
| 4193 | } |
| 4194 | EXPORT_SYMBOL_GPL(dasd_generic_shutdown); |
| 4195 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 4196 | static int __init dasd_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4197 | { |
| 4198 | int rc; |
| 4199 | |
| 4200 | init_waitqueue_head(&dasd_init_waitq); |
Horst Hummel | 8f61701 | 2006-08-30 14:33:33 +0200 | [diff] [blame] | 4201 | init_waitqueue_head(&dasd_flush_wq); |
Stefan Haberland | c80ee72 | 2008-05-30 10:03:31 +0200 | [diff] [blame] | 4202 | init_waitqueue_head(&generic_waitq); |
Stefan Haberland | 4679e89 | 2012-06-19 17:30:12 +0200 | [diff] [blame] | 4203 | init_waitqueue_head(&shutdown_waitq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | |
| 4205 | /* register 'common' DASD debug area, used for all DBF_XXX calls */ |
Peter Tiedemann | 361f494 | 2008-01-26 14:11:30 +0100 | [diff] [blame] | 4206 | dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | if (dasd_debug_area == NULL) { |
| 4208 | rc = -ENOMEM; |
| 4209 | goto failed; |
| 4210 | } |
| 4211 | debug_register_view(dasd_debug_area, &debug_sprintf_view); |
Horst Hummel | b0035f1 | 2006-09-20 15:59:07 +0200 | [diff] [blame] | 4212 | debug_set_level(dasd_debug_area, DBF_WARNING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | |
| 4214 | DBF_EVENT(DBF_EMERG, "%s", "debug area created"); |
| 4215 | |
| 4216 | dasd_diag_discipline_pointer = NULL; |
| 4217 | |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 4218 | dasd_statistics_createroot(); |
| 4219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | rc = dasd_devmap_init(); |
| 4221 | if (rc) |
| 4222 | goto failed; |
| 4223 | rc = dasd_gendisk_init(); |
| 4224 | if (rc) |
| 4225 | goto failed; |
| 4226 | rc = dasd_parse(); |
| 4227 | if (rc) |
| 4228 | goto failed; |
Stefan Weinhuber | 20c6446 | 2006-03-24 03:15:25 -0800 | [diff] [blame] | 4229 | rc = dasd_eer_init(); |
| 4230 | if (rc) |
| 4231 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | #ifdef CONFIG_PROC_FS |
| 4233 | rc = dasd_proc_init(); |
| 4234 | if (rc) |
| 4235 | goto failed; |
| 4236 | #endif |
| 4237 | |
| 4238 | return 0; |
| 4239 | failed: |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 4240 | pr_info("The DASD device driver could not be initialized\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | dasd_exit(); |
| 4242 | return rc; |
| 4243 | } |
| 4244 | |
| 4245 | module_init(dasd_init); |
| 4246 | module_exit(dasd_exit); |