Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * PAV alias management for the DASD ECKD discipline |
| 3 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2007 |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 5 | * Author(s): Stefan Weinhuber <wein@de.ibm.com> |
| 6 | */ |
| 7 | |
Stefan Haberland | ca99dab | 2009-09-11 10:28:30 +0200 | [diff] [blame] | 8 | #define KMSG_COMPONENT "dasd-eckd" |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 9 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 10 | #include <linux/list.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 12 | #include <asm/ebcdic.h> |
| 13 | #include "dasd_int.h" |
| 14 | #include "dasd_eckd.h" |
| 15 | |
| 16 | #ifdef PRINTK_HEADER |
| 17 | #undef PRINTK_HEADER |
| 18 | #endif /* PRINTK_HEADER */ |
| 19 | #define PRINTK_HEADER "dasd(eckd):" |
| 20 | |
| 21 | |
| 22 | /* |
| 23 | * General concept of alias management: |
| 24 | * - PAV and DASD alias management is specific to the eckd discipline. |
| 25 | * - A device is connected to an lcu as long as the device exists. |
| 26 | * dasd_alias_make_device_known_to_lcu will be called wenn the |
| 27 | * device is checked by the eckd discipline and |
| 28 | * dasd_alias_disconnect_device_from_lcu will be called |
| 29 | * before the device is deleted. |
| 30 | * - The dasd_alias_add_device / dasd_alias_remove_device |
| 31 | * functions mark the point when a device is 'ready for service'. |
| 32 | * - A summary unit check is a rare occasion, but it is mandatory to |
| 33 | * support it. It requires some complex recovery actions before the |
| 34 | * devices can be used again (see dasd_alias_handle_summary_unit_check). |
| 35 | * - dasd_alias_get_start_dev will find an alias device that can be used |
| 36 | * instead of the base device and does some (very simple) load balancing. |
| 37 | * This is the function that gets called for each I/O, so when improving |
| 38 | * something, this function should get faster or better, the rest has just |
| 39 | * to be correct. |
| 40 | */ |
| 41 | |
| 42 | |
| 43 | static void summary_unit_check_handling_work(struct work_struct *); |
| 44 | static void lcu_update_work(struct work_struct *); |
| 45 | static int _schedule_lcu_update(struct alias_lcu *, struct dasd_device *); |
| 46 | |
| 47 | static struct alias_root aliastree = { |
| 48 | .serverlist = LIST_HEAD_INIT(aliastree.serverlist), |
| 49 | .lock = __SPIN_LOCK_UNLOCKED(aliastree.lock), |
| 50 | }; |
| 51 | |
| 52 | static struct alias_server *_find_server(struct dasd_uid *uid) |
| 53 | { |
| 54 | struct alias_server *pos; |
| 55 | list_for_each_entry(pos, &aliastree.serverlist, server) { |
| 56 | if (!strncmp(pos->uid.vendor, uid->vendor, |
| 57 | sizeof(uid->vendor)) |
| 58 | && !strncmp(pos->uid.serial, uid->serial, |
| 59 | sizeof(uid->serial))) |
| 60 | return pos; |
Peter Senna Tschudin | 3b97487 | 2015-08-04 17:11:15 +0200 | [diff] [blame] | 61 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 62 | return NULL; |
| 63 | } |
| 64 | |
| 65 | static struct alias_lcu *_find_lcu(struct alias_server *server, |
| 66 | struct dasd_uid *uid) |
| 67 | { |
| 68 | struct alias_lcu *pos; |
| 69 | list_for_each_entry(pos, &server->lculist, lcu) { |
| 70 | if (pos->uid.ssid == uid->ssid) |
| 71 | return pos; |
Peter Senna Tschudin | 3b97487 | 2015-08-04 17:11:15 +0200 | [diff] [blame] | 72 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 73 | return NULL; |
| 74 | } |
| 75 | |
| 76 | static struct alias_pav_group *_find_group(struct alias_lcu *lcu, |
| 77 | struct dasd_uid *uid) |
| 78 | { |
| 79 | struct alias_pav_group *pos; |
| 80 | __u8 search_unit_addr; |
| 81 | |
| 82 | /* for hyper pav there is only one group */ |
| 83 | if (lcu->pav == HYPER_PAV) { |
| 84 | if (list_empty(&lcu->grouplist)) |
| 85 | return NULL; |
| 86 | else |
| 87 | return list_first_entry(&lcu->grouplist, |
| 88 | struct alias_pav_group, group); |
| 89 | } |
| 90 | |
| 91 | /* for base pav we have to find the group that matches the base */ |
| 92 | if (uid->type == UA_BASE_DEVICE) |
| 93 | search_unit_addr = uid->real_unit_addr; |
| 94 | else |
| 95 | search_unit_addr = uid->base_unit_addr; |
| 96 | list_for_each_entry(pos, &lcu->grouplist, group) { |
Stefan Weinhuber | 4abb08c | 2008-08-01 16:39:09 +0200 | [diff] [blame] | 97 | if (pos->uid.base_unit_addr == search_unit_addr && |
| 98 | !strncmp(pos->uid.vduit, uid->vduit, sizeof(uid->vduit))) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 99 | return pos; |
Peter Senna Tschudin | 3b97487 | 2015-08-04 17:11:15 +0200 | [diff] [blame] | 100 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 101 | return NULL; |
| 102 | } |
| 103 | |
| 104 | static struct alias_server *_allocate_server(struct dasd_uid *uid) |
| 105 | { |
| 106 | struct alias_server *server; |
| 107 | |
| 108 | server = kzalloc(sizeof(*server), GFP_KERNEL); |
| 109 | if (!server) |
| 110 | return ERR_PTR(-ENOMEM); |
| 111 | memcpy(server->uid.vendor, uid->vendor, sizeof(uid->vendor)); |
| 112 | memcpy(server->uid.serial, uid->serial, sizeof(uid->serial)); |
| 113 | INIT_LIST_HEAD(&server->server); |
| 114 | INIT_LIST_HEAD(&server->lculist); |
| 115 | return server; |
| 116 | } |
| 117 | |
| 118 | static void _free_server(struct alias_server *server) |
| 119 | { |
| 120 | kfree(server); |
| 121 | } |
| 122 | |
| 123 | static struct alias_lcu *_allocate_lcu(struct dasd_uid *uid) |
| 124 | { |
| 125 | struct alias_lcu *lcu; |
| 126 | |
| 127 | lcu = kzalloc(sizeof(*lcu), GFP_KERNEL); |
| 128 | if (!lcu) |
| 129 | return ERR_PTR(-ENOMEM); |
| 130 | lcu->uac = kzalloc(sizeof(*(lcu->uac)), GFP_KERNEL | GFP_DMA); |
| 131 | if (!lcu->uac) |
| 132 | goto out_err1; |
| 133 | lcu->rsu_cqr = kzalloc(sizeof(*lcu->rsu_cqr), GFP_KERNEL | GFP_DMA); |
| 134 | if (!lcu->rsu_cqr) |
| 135 | goto out_err2; |
| 136 | lcu->rsu_cqr->cpaddr = kzalloc(sizeof(struct ccw1), |
| 137 | GFP_KERNEL | GFP_DMA); |
| 138 | if (!lcu->rsu_cqr->cpaddr) |
| 139 | goto out_err3; |
| 140 | lcu->rsu_cqr->data = kzalloc(16, GFP_KERNEL | GFP_DMA); |
| 141 | if (!lcu->rsu_cqr->data) |
| 142 | goto out_err4; |
| 143 | |
| 144 | memcpy(lcu->uid.vendor, uid->vendor, sizeof(uid->vendor)); |
| 145 | memcpy(lcu->uid.serial, uid->serial, sizeof(uid->serial)); |
| 146 | lcu->uid.ssid = uid->ssid; |
| 147 | lcu->pav = NO_PAV; |
| 148 | lcu->flags = NEED_UAC_UPDATE | UPDATE_PENDING; |
| 149 | INIT_LIST_HEAD(&lcu->lcu); |
| 150 | INIT_LIST_HEAD(&lcu->inactive_devices); |
| 151 | INIT_LIST_HEAD(&lcu->active_devices); |
| 152 | INIT_LIST_HEAD(&lcu->grouplist); |
| 153 | INIT_WORK(&lcu->suc_data.worker, summary_unit_check_handling_work); |
| 154 | INIT_DELAYED_WORK(&lcu->ruac_data.dwork, lcu_update_work); |
| 155 | spin_lock_init(&lcu->lock); |
Stefan Weinhuber | f4ac1d0 | 2009-12-07 12:51:53 +0100 | [diff] [blame] | 156 | init_completion(&lcu->lcu_setup); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 157 | return lcu; |
| 158 | |
| 159 | out_err4: |
| 160 | kfree(lcu->rsu_cqr->cpaddr); |
| 161 | out_err3: |
| 162 | kfree(lcu->rsu_cqr); |
| 163 | out_err2: |
| 164 | kfree(lcu->uac); |
| 165 | out_err1: |
| 166 | kfree(lcu); |
| 167 | return ERR_PTR(-ENOMEM); |
| 168 | } |
| 169 | |
| 170 | static void _free_lcu(struct alias_lcu *lcu) |
| 171 | { |
| 172 | kfree(lcu->rsu_cqr->data); |
| 173 | kfree(lcu->rsu_cqr->cpaddr); |
| 174 | kfree(lcu->rsu_cqr); |
| 175 | kfree(lcu->uac); |
| 176 | kfree(lcu); |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * This is the function that will allocate all the server and lcu data, |
| 181 | * so this function must be called first for a new device. |
| 182 | * If the return value is 1, the lcu was already known before, if it |
| 183 | * is 0, this is a new lcu. |
| 184 | * Negative return code indicates that something went wrong (e.g. -ENOMEM) |
| 185 | */ |
| 186 | int dasd_alias_make_device_known_to_lcu(struct dasd_device *device) |
| 187 | { |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 188 | struct dasd_eckd_private *private = device->private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 189 | unsigned long flags; |
| 190 | struct alias_server *server, *newserver; |
| 191 | struct alias_lcu *lcu, *newlcu; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 192 | struct dasd_uid uid; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 193 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 194 | device->discipline->get_uid(device, &uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 195 | spin_lock_irqsave(&aliastree.lock, flags); |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 196 | server = _find_server(&uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 197 | if (!server) { |
| 198 | spin_unlock_irqrestore(&aliastree.lock, flags); |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 199 | newserver = _allocate_server(&uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 200 | if (IS_ERR(newserver)) |
| 201 | return PTR_ERR(newserver); |
| 202 | spin_lock_irqsave(&aliastree.lock, flags); |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 203 | server = _find_server(&uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 204 | if (!server) { |
| 205 | list_add(&newserver->server, &aliastree.serverlist); |
| 206 | server = newserver; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 207 | } else { |
| 208 | /* someone was faster */ |
| 209 | _free_server(newserver); |
| 210 | } |
| 211 | } |
| 212 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 213 | lcu = _find_lcu(server, &uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 214 | if (!lcu) { |
| 215 | spin_unlock_irqrestore(&aliastree.lock, flags); |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 216 | newlcu = _allocate_lcu(&uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 217 | if (IS_ERR(newlcu)) |
Roel Kluin | 6d53cfe | 2009-12-18 17:43:17 +0100 | [diff] [blame] | 218 | return PTR_ERR(newlcu); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 219 | spin_lock_irqsave(&aliastree.lock, flags); |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 220 | lcu = _find_lcu(server, &uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 221 | if (!lcu) { |
| 222 | list_add(&newlcu->lcu, &server->lculist); |
| 223 | lcu = newlcu; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 224 | } else { |
| 225 | /* someone was faster */ |
| 226 | _free_lcu(newlcu); |
| 227 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 228 | } |
| 229 | spin_lock(&lcu->lock); |
| 230 | list_add(&device->alias_list, &lcu->inactive_devices); |
| 231 | private->lcu = lcu; |
| 232 | spin_unlock(&lcu->lock); |
| 233 | spin_unlock_irqrestore(&aliastree.lock, flags); |
| 234 | |
Stefan Haberland | f9f8d02 | 2012-01-18 18:03:40 +0100 | [diff] [blame] | 235 | return 0; |
Stefan Weinhuber | f4ac1d0 | 2009-12-07 12:51:53 +0100 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /* |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 239 | * This function removes a device from the scope of alias management. |
| 240 | * The complicated part is to make sure that it is not in use by |
| 241 | * any of the workers. If necessary cancel the work. |
| 242 | */ |
| 243 | void dasd_alias_disconnect_device_from_lcu(struct dasd_device *device) |
| 244 | { |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 245 | struct dasd_eckd_private *private = device->private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 246 | unsigned long flags; |
| 247 | struct alias_lcu *lcu; |
| 248 | struct alias_server *server; |
| 249 | int was_pending; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 250 | struct dasd_uid uid; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 251 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 252 | lcu = private->lcu; |
Stefan Haberland | f602f6d6 | 2011-01-31 11:30:03 +0100 | [diff] [blame] | 253 | /* nothing to do if already disconnected */ |
| 254 | if (!lcu) |
| 255 | return; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 256 | device->discipline->get_uid(device, &uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 257 | spin_lock_irqsave(&lcu->lock, flags); |
| 258 | list_del_init(&device->alias_list); |
| 259 | /* make sure that the workers don't use this device */ |
| 260 | if (device == lcu->suc_data.device) { |
| 261 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 262 | cancel_work_sync(&lcu->suc_data.worker); |
| 263 | spin_lock_irqsave(&lcu->lock, flags); |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 264 | if (device == lcu->suc_data.device) { |
| 265 | dasd_put_device(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 266 | lcu->suc_data.device = NULL; |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 267 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 268 | } |
| 269 | was_pending = 0; |
| 270 | if (device == lcu->ruac_data.device) { |
| 271 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 272 | was_pending = 1; |
| 273 | cancel_delayed_work_sync(&lcu->ruac_data.dwork); |
| 274 | spin_lock_irqsave(&lcu->lock, flags); |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 275 | if (device == lcu->ruac_data.device) { |
| 276 | dasd_put_device(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 277 | lcu->ruac_data.device = NULL; |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 278 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 279 | } |
| 280 | private->lcu = NULL; |
| 281 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 282 | |
| 283 | spin_lock_irqsave(&aliastree.lock, flags); |
| 284 | spin_lock(&lcu->lock); |
| 285 | if (list_empty(&lcu->grouplist) && |
| 286 | list_empty(&lcu->active_devices) && |
| 287 | list_empty(&lcu->inactive_devices)) { |
| 288 | list_del(&lcu->lcu); |
| 289 | spin_unlock(&lcu->lock); |
| 290 | _free_lcu(lcu); |
| 291 | lcu = NULL; |
| 292 | } else { |
| 293 | if (was_pending) |
| 294 | _schedule_lcu_update(lcu, NULL); |
| 295 | spin_unlock(&lcu->lock); |
| 296 | } |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 297 | server = _find_server(&uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 298 | if (server && list_empty(&server->lculist)) { |
| 299 | list_del(&server->server); |
| 300 | _free_server(server); |
| 301 | } |
| 302 | spin_unlock_irqrestore(&aliastree.lock, flags); |
| 303 | } |
| 304 | |
| 305 | /* |
| 306 | * This function assumes that the unit address configuration stored |
| 307 | * in the lcu is up to date and will update the device uid before |
| 308 | * adding it to a pav group. |
| 309 | */ |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 310 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 311 | static int _add_device_to_lcu(struct alias_lcu *lcu, |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 312 | struct dasd_device *device, |
| 313 | struct dasd_device *pos) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 314 | { |
| 315 | |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 316 | struct dasd_eckd_private *private = device->private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 317 | struct alias_pav_group *group; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 318 | struct dasd_uid uid; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 319 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 320 | private->uid.type = lcu->uac->unit[private->uid.real_unit_addr].ua_type; |
| 321 | private->uid.base_unit_addr = |
| 322 | lcu->uac->unit[private->uid.real_unit_addr].base_ua; |
| 323 | uid = private->uid; |
| 324 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 325 | /* if we have no PAV anyway, we don't need to bother with PAV groups */ |
| 326 | if (lcu->pav == NO_PAV) { |
| 327 | list_move(&device->alias_list, &lcu->active_devices); |
| 328 | return 0; |
| 329 | } |
| 330 | |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 331 | group = _find_group(lcu, &uid); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 332 | if (!group) { |
| 333 | group = kzalloc(sizeof(*group), GFP_ATOMIC); |
| 334 | if (!group) |
| 335 | return -ENOMEM; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 336 | memcpy(group->uid.vendor, uid.vendor, sizeof(uid.vendor)); |
| 337 | memcpy(group->uid.serial, uid.serial, sizeof(uid.serial)); |
| 338 | group->uid.ssid = uid.ssid; |
| 339 | if (uid.type == UA_BASE_DEVICE) |
| 340 | group->uid.base_unit_addr = uid.real_unit_addr; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 341 | else |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 342 | group->uid.base_unit_addr = uid.base_unit_addr; |
| 343 | memcpy(group->uid.vduit, uid.vduit, sizeof(uid.vduit)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 344 | INIT_LIST_HEAD(&group->group); |
| 345 | INIT_LIST_HEAD(&group->baselist); |
| 346 | INIT_LIST_HEAD(&group->aliaslist); |
| 347 | list_add(&group->group, &lcu->grouplist); |
| 348 | } |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 349 | if (uid.type == UA_BASE_DEVICE) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 350 | list_move(&device->alias_list, &group->baselist); |
| 351 | else |
| 352 | list_move(&device->alias_list, &group->aliaslist); |
| 353 | private->pavgroup = group; |
| 354 | return 0; |
| 355 | }; |
| 356 | |
| 357 | static void _remove_device_from_lcu(struct alias_lcu *lcu, |
| 358 | struct dasd_device *device) |
| 359 | { |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 360 | struct dasd_eckd_private *private = device->private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 361 | struct alias_pav_group *group; |
| 362 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 363 | list_move(&device->alias_list, &lcu->inactive_devices); |
| 364 | group = private->pavgroup; |
| 365 | if (!group) |
| 366 | return; |
| 367 | private->pavgroup = NULL; |
| 368 | if (list_empty(&group->baselist) && list_empty(&group->aliaslist)) { |
| 369 | list_del(&group->group); |
| 370 | kfree(group); |
| 371 | return; |
| 372 | } |
| 373 | if (group->next == device) |
| 374 | group->next = NULL; |
| 375 | }; |
| 376 | |
Stefan Haberland | 03429f3 | 2012-09-11 17:19:12 +0200 | [diff] [blame] | 377 | static int |
| 378 | suborder_not_supported(struct dasd_ccw_req *cqr) |
| 379 | { |
| 380 | char *sense; |
| 381 | char reason; |
| 382 | char msg_format; |
| 383 | char msg_no; |
| 384 | |
| 385 | sense = dasd_get_sense(&cqr->irb); |
| 386 | if (!sense) |
| 387 | return 0; |
| 388 | |
| 389 | reason = sense[0]; |
| 390 | msg_format = (sense[7] & 0xF0); |
| 391 | msg_no = (sense[7] & 0x0F); |
| 392 | |
| 393 | /* command reject, Format 0 MSG 4 - invalid parameter */ |
| 394 | if ((reason == 0x80) && (msg_format == 0x00) && (msg_no == 0x04)) |
| 395 | return 1; |
| 396 | |
| 397 | return 0; |
| 398 | } |
| 399 | |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 400 | /* |
| 401 | * This function tries to lock all devices on an lcu via trylock |
| 402 | * return NULL on success otherwise return first failed device |
| 403 | */ |
| 404 | static struct dasd_device *_trylock_all_devices_on_lcu(struct alias_lcu *lcu, |
| 405 | struct dasd_device *pos) |
| 406 | |
| 407 | { |
| 408 | struct alias_pav_group *pavgroup; |
| 409 | struct dasd_device *device; |
| 410 | |
| 411 | list_for_each_entry(device, &lcu->active_devices, alias_list) { |
| 412 | if (device == pos) |
| 413 | continue; |
| 414 | if (!spin_trylock(get_ccwdev_lock(device->cdev))) |
| 415 | return device; |
| 416 | } |
| 417 | list_for_each_entry(device, &lcu->inactive_devices, alias_list) { |
| 418 | if (device == pos) |
| 419 | continue; |
| 420 | if (!spin_trylock(get_ccwdev_lock(device->cdev))) |
| 421 | return device; |
| 422 | } |
| 423 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { |
| 424 | list_for_each_entry(device, &pavgroup->baselist, alias_list) { |
| 425 | if (device == pos) |
| 426 | continue; |
| 427 | if (!spin_trylock(get_ccwdev_lock(device->cdev))) |
| 428 | return device; |
| 429 | } |
| 430 | list_for_each_entry(device, &pavgroup->aliaslist, alias_list) { |
| 431 | if (device == pos) |
| 432 | continue; |
| 433 | if (!spin_trylock(get_ccwdev_lock(device->cdev))) |
| 434 | return device; |
| 435 | } |
| 436 | } |
| 437 | return NULL; |
| 438 | } |
| 439 | |
| 440 | /* |
| 441 | * unlock all devices except the one that is specified as pos |
| 442 | * stop if enddev is specified and reached |
| 443 | */ |
| 444 | static void _unlock_all_devices_on_lcu(struct alias_lcu *lcu, |
| 445 | struct dasd_device *pos, |
| 446 | struct dasd_device *enddev) |
| 447 | |
| 448 | { |
| 449 | struct alias_pav_group *pavgroup; |
| 450 | struct dasd_device *device; |
| 451 | |
| 452 | list_for_each_entry(device, &lcu->active_devices, alias_list) { |
| 453 | if (device == pos) |
| 454 | continue; |
| 455 | if (device == enddev) |
| 456 | return; |
| 457 | spin_unlock(get_ccwdev_lock(device->cdev)); |
| 458 | } |
| 459 | list_for_each_entry(device, &lcu->inactive_devices, alias_list) { |
| 460 | if (device == pos) |
| 461 | continue; |
| 462 | if (device == enddev) |
| 463 | return; |
| 464 | spin_unlock(get_ccwdev_lock(device->cdev)); |
| 465 | } |
| 466 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { |
| 467 | list_for_each_entry(device, &pavgroup->baselist, alias_list) { |
| 468 | if (device == pos) |
| 469 | continue; |
| 470 | if (device == enddev) |
| 471 | return; |
| 472 | spin_unlock(get_ccwdev_lock(device->cdev)); |
| 473 | } |
| 474 | list_for_each_entry(device, &pavgroup->aliaslist, alias_list) { |
| 475 | if (device == pos) |
| 476 | continue; |
| 477 | if (device == enddev) |
| 478 | return; |
| 479 | spin_unlock(get_ccwdev_lock(device->cdev)); |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | /* |
| 485 | * this function is needed because the locking order |
| 486 | * device lock -> lcu lock |
| 487 | * needs to be assured when iterating over devices in an LCU |
| 488 | * |
| 489 | * if a device is specified in pos then the device lock is already hold |
| 490 | */ |
| 491 | static void _trylock_and_lock_lcu_irqsave(struct alias_lcu *lcu, |
| 492 | struct dasd_device *pos, |
| 493 | unsigned long *flags) |
| 494 | { |
| 495 | struct dasd_device *failed; |
| 496 | |
| 497 | do { |
| 498 | spin_lock_irqsave(&lcu->lock, *flags); |
| 499 | failed = _trylock_all_devices_on_lcu(lcu, pos); |
| 500 | if (failed) { |
| 501 | _unlock_all_devices_on_lcu(lcu, pos, failed); |
| 502 | spin_unlock_irqrestore(&lcu->lock, *flags); |
| 503 | cpu_relax(); |
| 504 | } |
| 505 | } while (failed); |
| 506 | } |
| 507 | |
| 508 | static void _trylock_and_lock_lcu(struct alias_lcu *lcu, |
| 509 | struct dasd_device *pos) |
| 510 | { |
| 511 | struct dasd_device *failed; |
| 512 | |
| 513 | do { |
| 514 | spin_lock(&lcu->lock); |
| 515 | failed = _trylock_all_devices_on_lcu(lcu, pos); |
| 516 | if (failed) { |
| 517 | _unlock_all_devices_on_lcu(lcu, pos, failed); |
| 518 | spin_unlock(&lcu->lock); |
| 519 | cpu_relax(); |
| 520 | } |
| 521 | } while (failed); |
| 522 | } |
| 523 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 524 | static int read_unit_address_configuration(struct dasd_device *device, |
| 525 | struct alias_lcu *lcu) |
| 526 | { |
| 527 | struct dasd_psf_prssd_data *prssdp; |
| 528 | struct dasd_ccw_req *cqr; |
| 529 | struct ccw1 *ccw; |
| 530 | int rc; |
| 531 | unsigned long flags; |
| 532 | |
Stefan Haberland | 68b781f | 2009-09-11 10:28:29 +0200 | [diff] [blame] | 533 | cqr = dasd_kmalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 534 | (sizeof(struct dasd_psf_prssd_data)), |
| 535 | device); |
| 536 | if (IS_ERR(cqr)) |
| 537 | return PTR_ERR(cqr); |
| 538 | cqr->startdev = device; |
| 539 | cqr->memdev = device; |
| 540 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 541 | cqr->retries = 10; |
| 542 | cqr->expires = 20 * HZ; |
| 543 | |
| 544 | /* Prepare for Read Subsystem Data */ |
| 545 | prssdp = (struct dasd_psf_prssd_data *) cqr->data; |
| 546 | memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); |
| 547 | prssdp->order = PSF_ORDER_PRSSD; |
| 548 | prssdp->suborder = 0x0e; /* Read unit address configuration */ |
| 549 | /* all other bytes of prssdp must be zero */ |
| 550 | |
| 551 | ccw = cqr->cpaddr; |
| 552 | ccw->cmd_code = DASD_ECKD_CCW_PSF; |
| 553 | ccw->count = sizeof(struct dasd_psf_prssd_data); |
| 554 | ccw->flags |= CCW_FLAG_CC; |
| 555 | ccw->cda = (__u32)(addr_t) prssdp; |
| 556 | |
| 557 | /* Read Subsystem Data - feature codes */ |
| 558 | memset(lcu->uac, 0, sizeof(*(lcu->uac))); |
| 559 | |
| 560 | ccw++; |
| 561 | ccw->cmd_code = DASD_ECKD_CCW_RSSD; |
| 562 | ccw->count = sizeof(*(lcu->uac)); |
| 563 | ccw->cda = (__u32)(addr_t) lcu->uac; |
| 564 | |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 565 | cqr->buildclk = get_tod_clock(); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 566 | cqr->status = DASD_CQR_FILLED; |
| 567 | |
| 568 | /* need to unset flag here to detect race with summary unit check */ |
| 569 | spin_lock_irqsave(&lcu->lock, flags); |
| 570 | lcu->flags &= ~NEED_UAC_UPDATE; |
| 571 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 572 | |
| 573 | do { |
| 574 | rc = dasd_sleep_on(cqr); |
Stefan Haberland | 03429f3 | 2012-09-11 17:19:12 +0200 | [diff] [blame] | 575 | if (rc && suborder_not_supported(cqr)) |
| 576 | return -EOPNOTSUPP; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 577 | } while (rc && (cqr->retries > 0)); |
| 578 | if (rc) { |
| 579 | spin_lock_irqsave(&lcu->lock, flags); |
| 580 | lcu->flags |= NEED_UAC_UPDATE; |
| 581 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 582 | } |
| 583 | dasd_kfree_request(cqr, cqr->memdev); |
| 584 | return rc; |
| 585 | } |
| 586 | |
| 587 | static int _lcu_update(struct dasd_device *refdev, struct alias_lcu *lcu) |
| 588 | { |
| 589 | unsigned long flags; |
| 590 | struct alias_pav_group *pavgroup, *tempgroup; |
| 591 | struct dasd_device *device, *tempdev; |
| 592 | int i, rc; |
| 593 | struct dasd_eckd_private *private; |
| 594 | |
| 595 | spin_lock_irqsave(&lcu->lock, flags); |
| 596 | list_for_each_entry_safe(pavgroup, tempgroup, &lcu->grouplist, group) { |
| 597 | list_for_each_entry_safe(device, tempdev, &pavgroup->baselist, |
| 598 | alias_list) { |
| 599 | list_move(&device->alias_list, &lcu->active_devices); |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 600 | private = device->private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 601 | private->pavgroup = NULL; |
| 602 | } |
| 603 | list_for_each_entry_safe(device, tempdev, &pavgroup->aliaslist, |
| 604 | alias_list) { |
| 605 | list_move(&device->alias_list, &lcu->active_devices); |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 606 | private = device->private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 607 | private->pavgroup = NULL; |
| 608 | } |
| 609 | list_del(&pavgroup->group); |
| 610 | kfree(pavgroup); |
| 611 | } |
| 612 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 613 | |
| 614 | rc = read_unit_address_configuration(refdev, lcu); |
| 615 | if (rc) |
| 616 | return rc; |
| 617 | |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 618 | _trylock_and_lock_lcu_irqsave(lcu, NULL, &flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 619 | lcu->pav = NO_PAV; |
| 620 | for (i = 0; i < MAX_DEVICES_PER_LCU; ++i) { |
| 621 | switch (lcu->uac->unit[i].ua_type) { |
| 622 | case UA_BASE_PAV_ALIAS: |
| 623 | lcu->pav = BASE_PAV; |
| 624 | break; |
| 625 | case UA_HYPER_PAV_ALIAS: |
| 626 | lcu->pav = HYPER_PAV; |
| 627 | break; |
| 628 | } |
| 629 | if (lcu->pav != NO_PAV) |
| 630 | break; |
| 631 | } |
| 632 | |
| 633 | list_for_each_entry_safe(device, tempdev, &lcu->active_devices, |
| 634 | alias_list) { |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 635 | _add_device_to_lcu(lcu, device, refdev); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 636 | } |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 637 | _unlock_all_devices_on_lcu(lcu, NULL, NULL); |
| 638 | spin_unlock_irqrestore(&lcu->lock, flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 639 | return 0; |
| 640 | } |
| 641 | |
| 642 | static void lcu_update_work(struct work_struct *work) |
| 643 | { |
| 644 | struct alias_lcu *lcu; |
| 645 | struct read_uac_work_data *ruac_data; |
| 646 | struct dasd_device *device; |
| 647 | unsigned long flags; |
| 648 | int rc; |
| 649 | |
| 650 | ruac_data = container_of(work, struct read_uac_work_data, dwork.work); |
| 651 | lcu = container_of(ruac_data, struct alias_lcu, ruac_data); |
| 652 | device = ruac_data->device; |
| 653 | rc = _lcu_update(device, lcu); |
| 654 | /* |
| 655 | * Need to check flags again, as there could have been another |
| 656 | * prepare_update or a new device a new device while we were still |
| 657 | * processing the data |
| 658 | */ |
| 659 | spin_lock_irqsave(&lcu->lock, flags); |
Stefan Haberland | 03429f3 | 2012-09-11 17:19:12 +0200 | [diff] [blame] | 660 | if ((rc && (rc != -EOPNOTSUPP)) || (lcu->flags & NEED_UAC_UPDATE)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 661 | DBF_DEV_EVENT(DBF_WARNING, device, "could not update" |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 662 | " alias data in lcu (rc = %d), retry later", rc); |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 663 | if (!schedule_delayed_work(&lcu->ruac_data.dwork, 30*HZ)) |
| 664 | dasd_put_device(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 665 | } else { |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 666 | dasd_put_device(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 667 | lcu->ruac_data.device = NULL; |
| 668 | lcu->flags &= ~UPDATE_PENDING; |
| 669 | } |
| 670 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 671 | } |
| 672 | |
| 673 | static int _schedule_lcu_update(struct alias_lcu *lcu, |
| 674 | struct dasd_device *device) |
| 675 | { |
| 676 | struct dasd_device *usedev = NULL; |
| 677 | struct alias_pav_group *group; |
| 678 | |
| 679 | lcu->flags |= NEED_UAC_UPDATE; |
| 680 | if (lcu->ruac_data.device) { |
| 681 | /* already scheduled or running */ |
| 682 | return 0; |
| 683 | } |
| 684 | if (device && !list_empty(&device->alias_list)) |
| 685 | usedev = device; |
| 686 | |
| 687 | if (!usedev && !list_empty(&lcu->grouplist)) { |
| 688 | group = list_first_entry(&lcu->grouplist, |
| 689 | struct alias_pav_group, group); |
| 690 | if (!list_empty(&group->baselist)) |
| 691 | usedev = list_first_entry(&group->baselist, |
| 692 | struct dasd_device, |
| 693 | alias_list); |
| 694 | else if (!list_empty(&group->aliaslist)) |
| 695 | usedev = list_first_entry(&group->aliaslist, |
| 696 | struct dasd_device, |
| 697 | alias_list); |
| 698 | } |
| 699 | if (!usedev && !list_empty(&lcu->active_devices)) { |
| 700 | usedev = list_first_entry(&lcu->active_devices, |
| 701 | struct dasd_device, alias_list); |
| 702 | } |
| 703 | /* |
| 704 | * if we haven't found a proper device yet, give up for now, the next |
| 705 | * device that will be set active will trigger an lcu update |
| 706 | */ |
| 707 | if (!usedev) |
| 708 | return -EINVAL; |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 709 | dasd_get_device(usedev); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 710 | lcu->ruac_data.device = usedev; |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 711 | if (!schedule_delayed_work(&lcu->ruac_data.dwork, 0)) |
| 712 | dasd_put_device(usedev); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 713 | return 0; |
| 714 | } |
| 715 | |
| 716 | int dasd_alias_add_device(struct dasd_device *device) |
| 717 | { |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 718 | struct dasd_eckd_private *private = device->private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 719 | struct alias_lcu *lcu; |
| 720 | unsigned long flags; |
| 721 | int rc; |
| 722 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 723 | lcu = private->lcu; |
| 724 | rc = 0; |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 725 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 726 | spin_lock(&lcu->lock); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 727 | if (!(lcu->flags & UPDATE_PENDING)) { |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 728 | rc = _add_device_to_lcu(lcu, device, device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 729 | if (rc) |
| 730 | lcu->flags |= UPDATE_PENDING; |
| 731 | } |
| 732 | if (lcu->flags & UPDATE_PENDING) { |
| 733 | list_move(&device->alias_list, &lcu->active_devices); |
| 734 | _schedule_lcu_update(lcu, device); |
| 735 | } |
Stefan Haberland | 2dedf0d | 2010-05-17 10:00:11 +0200 | [diff] [blame] | 736 | spin_unlock(&lcu->lock); |
| 737 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 738 | return rc; |
| 739 | } |
| 740 | |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 741 | int dasd_alias_update_add_device(struct dasd_device *device) |
| 742 | { |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 743 | struct dasd_eckd_private *private = device->private; |
| 744 | |
Stefan Haberland | 501183f | 2010-05-17 10:00:10 +0200 | [diff] [blame] | 745 | private->lcu->flags |= UPDATE_PENDING; |
| 746 | return dasd_alias_add_device(device); |
| 747 | } |
| 748 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 749 | int dasd_alias_remove_device(struct dasd_device *device) |
| 750 | { |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 751 | struct dasd_eckd_private *private = device->private; |
| 752 | struct alias_lcu *lcu = private->lcu; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 753 | unsigned long flags; |
| 754 | |
Stefan Haberland | f602f6d6 | 2011-01-31 11:30:03 +0100 | [diff] [blame] | 755 | /* nothing to do if already removed */ |
| 756 | if (!lcu) |
| 757 | return 0; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 758 | spin_lock_irqsave(&lcu->lock, flags); |
| 759 | _remove_device_from_lcu(lcu, device); |
| 760 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | struct dasd_device *dasd_alias_get_start_dev(struct dasd_device *base_device) |
| 765 | { |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 766 | struct dasd_eckd_private *alias_priv, *private = base_device->private; |
| 767 | struct alias_pav_group *group = private->pavgroup; |
| 768 | struct alias_lcu *lcu = private->lcu; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 769 | struct dasd_device *alias_device; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 770 | unsigned long flags; |
| 771 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 772 | if (!group || !lcu) |
| 773 | return NULL; |
| 774 | if (lcu->pav == NO_PAV || |
| 775 | lcu->flags & (NEED_UAC_UPDATE | UPDATE_PENDING)) |
| 776 | return NULL; |
Stefan Haberland | b38f27e | 2011-12-27 11:27:28 +0100 | [diff] [blame] | 777 | if (unlikely(!(private->features.feature[8] & 0x01))) { |
| 778 | /* |
| 779 | * PAV enabled but prefix not, very unlikely |
| 780 | * seems to be a lost pathgroup |
| 781 | * use base device to do IO |
| 782 | */ |
| 783 | DBF_DEV_EVENT(DBF_ERR, base_device, "%s", |
| 784 | "Prefix not enabled with PAV enabled\n"); |
| 785 | return NULL; |
| 786 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 787 | |
| 788 | spin_lock_irqsave(&lcu->lock, flags); |
| 789 | alias_device = group->next; |
| 790 | if (!alias_device) { |
| 791 | if (list_empty(&group->aliaslist)) { |
| 792 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 793 | return NULL; |
| 794 | } else { |
| 795 | alias_device = list_first_entry(&group->aliaslist, |
| 796 | struct dasd_device, |
| 797 | alias_list); |
| 798 | } |
| 799 | } |
| 800 | if (list_is_last(&alias_device->alias_list, &group->aliaslist)) |
| 801 | group->next = list_first_entry(&group->aliaslist, |
| 802 | struct dasd_device, alias_list); |
| 803 | else |
| 804 | group->next = list_first_entry(&alias_device->alias_list, |
| 805 | struct dasd_device, alias_list); |
| 806 | spin_unlock_irqrestore(&lcu->lock, flags); |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 807 | alias_priv = alias_device->private; |
Stefan Haberland | f81a49d | 2015-07-10 10:47:09 +0200 | [diff] [blame] | 808 | if ((alias_priv->count < private->count) && !alias_device->stopped && |
| 809 | !test_bit(DASD_FLAG_OFFLINE, &alias_device->flags)) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 810 | return alias_device; |
| 811 | else |
| 812 | return NULL; |
| 813 | } |
| 814 | |
| 815 | /* |
| 816 | * Summary unit check handling depends on the way alias devices |
| 817 | * are handled so it is done here rather then in dasd_eckd.c |
| 818 | */ |
| 819 | static int reset_summary_unit_check(struct alias_lcu *lcu, |
| 820 | struct dasd_device *device, |
| 821 | char reason) |
| 822 | { |
| 823 | struct dasd_ccw_req *cqr; |
| 824 | int rc = 0; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 825 | struct ccw1 *ccw; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 826 | |
| 827 | cqr = lcu->rsu_cqr; |
| 828 | strncpy((char *) &cqr->magic, "ECKD", 4); |
| 829 | ASCEBC((char *) &cqr->magic, 4); |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 830 | ccw = cqr->cpaddr; |
| 831 | ccw->cmd_code = DASD_ECKD_CCW_RSCK; |
Stefan Haberland | 020bf04 | 2015-12-15 10:16:43 +0100 | [diff] [blame] | 832 | ccw->flags = CCW_FLAG_SLI; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 833 | ccw->count = 16; |
| 834 | ccw->cda = (__u32)(addr_t) cqr->data; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 835 | ((char *)cqr->data)[0] = reason; |
| 836 | |
| 837 | clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
| 838 | cqr->retries = 255; /* set retry counter to enable basic ERP */ |
| 839 | cqr->startdev = device; |
| 840 | cqr->memdev = device; |
| 841 | cqr->block = NULL; |
| 842 | cqr->expires = 5 * HZ; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 843 | cqr->buildclk = get_tod_clock(); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 844 | cqr->status = DASD_CQR_FILLED; |
| 845 | |
| 846 | rc = dasd_sleep_on_immediatly(cqr); |
| 847 | return rc; |
| 848 | } |
| 849 | |
| 850 | static void _restart_all_base_devices_on_lcu(struct alias_lcu *lcu) |
| 851 | { |
| 852 | struct alias_pav_group *pavgroup; |
| 853 | struct dasd_device *device; |
| 854 | struct dasd_eckd_private *private; |
| 855 | |
| 856 | /* active and inactive list can contain alias as well as base devices */ |
| 857 | list_for_each_entry(device, &lcu->active_devices, alias_list) { |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 858 | private = device->private; |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 859 | if (private->uid.type != UA_BASE_DEVICE) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 860 | continue; |
| 861 | dasd_schedule_block_bh(device->block); |
| 862 | dasd_schedule_device_bh(device); |
| 863 | } |
| 864 | list_for_each_entry(device, &lcu->inactive_devices, alias_list) { |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 865 | private = device->private; |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 866 | if (private->uid.type != UA_BASE_DEVICE) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 867 | continue; |
| 868 | dasd_schedule_block_bh(device->block); |
| 869 | dasd_schedule_device_bh(device); |
| 870 | } |
| 871 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { |
| 872 | list_for_each_entry(device, &pavgroup->baselist, alias_list) { |
| 873 | dasd_schedule_block_bh(device->block); |
| 874 | dasd_schedule_device_bh(device); |
| 875 | } |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | static void flush_all_alias_devices_on_lcu(struct alias_lcu *lcu) |
| 880 | { |
| 881 | struct alias_pav_group *pavgroup; |
| 882 | struct dasd_device *device, *temp; |
| 883 | struct dasd_eckd_private *private; |
| 884 | int rc; |
| 885 | unsigned long flags; |
| 886 | LIST_HEAD(active); |
| 887 | |
| 888 | /* |
| 889 | * Problem here ist that dasd_flush_device_queue may wait |
| 890 | * for termination of a request to complete. We can't keep |
| 891 | * the lcu lock during that time, so we must assume that |
| 892 | * the lists may have changed. |
| 893 | * Idea: first gather all active alias devices in a separate list, |
| 894 | * then flush the first element of this list unlocked, and afterwards |
| 895 | * check if it is still on the list before moving it to the |
| 896 | * active_devices list. |
| 897 | */ |
| 898 | |
| 899 | spin_lock_irqsave(&lcu->lock, flags); |
| 900 | list_for_each_entry_safe(device, temp, &lcu->active_devices, |
| 901 | alias_list) { |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 902 | private = device->private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 903 | if (private->uid.type == UA_BASE_DEVICE) |
| 904 | continue; |
| 905 | list_move(&device->alias_list, &active); |
| 906 | } |
| 907 | |
| 908 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { |
| 909 | list_splice_init(&pavgroup->aliaslist, &active); |
| 910 | } |
| 911 | while (!list_empty(&active)) { |
| 912 | device = list_first_entry(&active, struct dasd_device, |
| 913 | alias_list); |
| 914 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 915 | rc = dasd_flush_device_queue(device); |
| 916 | spin_lock_irqsave(&lcu->lock, flags); |
| 917 | /* |
| 918 | * only move device around if it wasn't moved away while we |
| 919 | * were waiting for the flush |
| 920 | */ |
| 921 | if (device == list_first_entry(&active, |
Stefan Haberland | 6933c35 | 2015-10-14 11:01:05 +0200 | [diff] [blame] | 922 | struct dasd_device, alias_list)) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 923 | list_move(&device->alias_list, &lcu->active_devices); |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 924 | private = device->private; |
Stefan Haberland | 6933c35 | 2015-10-14 11:01:05 +0200 | [diff] [blame] | 925 | private->pavgroup = NULL; |
| 926 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 927 | } |
| 928 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 929 | } |
| 930 | |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 931 | static void _stop_all_devices_on_lcu(struct alias_lcu *lcu) |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 932 | { |
| 933 | struct alias_pav_group *pavgroup; |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 934 | struct dasd_device *device; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 935 | |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 936 | list_for_each_entry(device, &lcu->active_devices, alias_list) |
| 937 | dasd_device_set_stop_bits(device, DASD_STOPPED_SU); |
| 938 | list_for_each_entry(device, &lcu->inactive_devices, alias_list) |
| 939 | dasd_device_set_stop_bits(device, DASD_STOPPED_SU); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 940 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 941 | list_for_each_entry(device, &pavgroup->baselist, alias_list) |
| 942 | dasd_device_set_stop_bits(device, DASD_STOPPED_SU); |
| 943 | list_for_each_entry(device, &pavgroup->aliaslist, alias_list) |
| 944 | dasd_device_set_stop_bits(device, DASD_STOPPED_SU); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | |
| 948 | static void _unstop_all_devices_on_lcu(struct alias_lcu *lcu) |
| 949 | { |
| 950 | struct alias_pav_group *pavgroup; |
| 951 | struct dasd_device *device; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 952 | |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 953 | list_for_each_entry(device, &lcu->active_devices, alias_list) |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 954 | dasd_device_remove_stop_bits(device, DASD_STOPPED_SU); |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 955 | list_for_each_entry(device, &lcu->inactive_devices, alias_list) |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 956 | dasd_device_remove_stop_bits(device, DASD_STOPPED_SU); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 957 | list_for_each_entry(pavgroup, &lcu->grouplist, group) { |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 958 | list_for_each_entry(device, &pavgroup->baselist, alias_list) |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 959 | dasd_device_remove_stop_bits(device, DASD_STOPPED_SU); |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 960 | list_for_each_entry(device, &pavgroup->aliaslist, alias_list) |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 961 | dasd_device_remove_stop_bits(device, DASD_STOPPED_SU); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 962 | } |
| 963 | } |
| 964 | |
| 965 | static void summary_unit_check_handling_work(struct work_struct *work) |
| 966 | { |
| 967 | struct alias_lcu *lcu; |
| 968 | struct summary_unit_check_work_data *suc_data; |
| 969 | unsigned long flags; |
| 970 | struct dasd_device *device; |
| 971 | |
| 972 | suc_data = container_of(work, struct summary_unit_check_work_data, |
| 973 | worker); |
| 974 | lcu = container_of(suc_data, struct alias_lcu, suc_data); |
| 975 | device = suc_data->device; |
| 976 | |
| 977 | /* 1. flush alias devices */ |
| 978 | flush_all_alias_devices_on_lcu(lcu); |
| 979 | |
| 980 | /* 2. reset summary unit check */ |
| 981 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 982 | dasd_device_remove_stop_bits(device, |
| 983 | (DASD_STOPPED_SU | DASD_STOPPED_PENDING)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 984 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 985 | reset_summary_unit_check(lcu, device, suc_data->reason); |
| 986 | |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 987 | _trylock_and_lock_lcu_irqsave(lcu, NULL, &flags); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 988 | _unstop_all_devices_on_lcu(lcu); |
| 989 | _restart_all_base_devices_on_lcu(lcu); |
| 990 | /* 3. read new alias configuration */ |
| 991 | _schedule_lcu_update(lcu, device); |
| 992 | lcu->suc_data.device = NULL; |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 993 | dasd_put_device(device); |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 994 | _unlock_all_devices_on_lcu(lcu, NULL, NULL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 995 | spin_unlock_irqrestore(&lcu->lock, flags); |
| 996 | } |
| 997 | |
| 998 | /* |
| 999 | * note: this will be called from int handler context (cdev locked) |
| 1000 | */ |
| 1001 | void dasd_alias_handle_summary_unit_check(struct dasd_device *device, |
| 1002 | struct irb *irb) |
| 1003 | { |
Sebastian Ott | 543691a4 | 2016-03-04 10:34:05 +0100 | [diff] [blame] | 1004 | struct dasd_eckd_private *private = device->private; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1005 | struct alias_lcu *lcu; |
| 1006 | char reason; |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1007 | char *sense; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1008 | |
Stefan Weinhuber | f3eb538 | 2009-03-26 15:23:48 +0100 | [diff] [blame] | 1009 | sense = dasd_get_sense(irb); |
| 1010 | if (sense) { |
| 1011 | reason = sense[8]; |
| 1012 | DBF_DEV_EVENT(DBF_NOTICE, device, "%s %x", |
| 1013 | "eckd handle summary unit check: reason", reason); |
| 1014 | } else { |
| 1015 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
| 1016 | "eckd handle summary unit check:" |
| 1017 | " no reason code available"); |
| 1018 | return; |
| 1019 | } |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1020 | |
| 1021 | lcu = private->lcu; |
| 1022 | if (!lcu) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1023 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1024 | "device not ready to handle summary" |
| 1025 | " unit check (no lcu structure)"); |
| 1026 | return; |
| 1027 | } |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 1028 | _trylock_and_lock_lcu(lcu, device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1029 | /* If this device is about to be removed just return and wait for |
| 1030 | * the next interrupt on a different device |
| 1031 | */ |
| 1032 | if (list_empty(&device->alias_list)) { |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1033 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1034 | "device is in offline processing," |
| 1035 | " don't do summary unit check handling"); |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 1036 | _unlock_all_devices_on_lcu(lcu, device, NULL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1037 | spin_unlock(&lcu->lock); |
| 1038 | return; |
| 1039 | } |
| 1040 | if (lcu->suc_data.device) { |
| 1041 | /* already scheduled or running */ |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 1042 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1043 | "previous instance of summary unit check worker" |
| 1044 | " still pending"); |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 1045 | _unlock_all_devices_on_lcu(lcu, device, NULL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1046 | spin_unlock(&lcu->lock); |
| 1047 | return ; |
| 1048 | } |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 1049 | _stop_all_devices_on_lcu(lcu); |
| 1050 | /* prepare for lcu_update */ |
| 1051 | private->lcu->flags |= NEED_UAC_UPDATE | UPDATE_PENDING; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1052 | lcu->suc_data.reason = reason; |
| 1053 | lcu->suc_data.device = device; |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 1054 | dasd_get_device(device); |
Stefan Haberland | 9bfefde | 2015-12-15 11:00:51 +0100 | [diff] [blame] | 1055 | _unlock_all_devices_on_lcu(lcu, device, NULL); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1056 | spin_unlock(&lcu->lock); |
Stefan Haberland | 9d862ab | 2015-12-15 10:45:05 +0100 | [diff] [blame] | 1057 | if (!schedule_work(&lcu->suc_data.worker)) |
| 1058 | dasd_put_device(device); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 1059 | }; |