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