blob: f40d606f86c987dd4b971cbb12e7774b6b8a1e93 [file] [log] [blame]
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01001/*
2 * PAV alias management for the DASD ECKD discipline
3 *
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02004 * Copyright IBM Corp. 2007
Stefan Weinhuber8e09f212008-01-26 14:11:23 +01005 * Author(s): Stefan Weinhuber <wein@de.ibm.com>
6 */
7
Stefan Haberlandca99dab2009-09-11 10:28:30 +02008#define KMSG_COMPONENT "dasd-eckd"
Stefan Haberlandfc19f382009-03-26 15:23:49 +01009
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010010#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010012#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
43static void summary_unit_check_handling_work(struct work_struct *);
44static void lcu_update_work(struct work_struct *);
45static int _schedule_lcu_update(struct alias_lcu *, struct dasd_device *);
46
47static struct alias_root aliastree = {
48 .serverlist = LIST_HEAD_INIT(aliastree.serverlist),
49 .lock = __SPIN_LOCK_UNLOCKED(aliastree.lock),
50};
51
52static 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 Tschudin3b974872015-08-04 17:11:15 +020061 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010062 return NULL;
63}
64
65static 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 Tschudin3b974872015-08-04 17:11:15 +020072 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010073 return NULL;
74}
75
76static 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 Weinhuber4abb08c2008-08-01 16:39:09 +020097 if (pos->uid.base_unit_addr == search_unit_addr &&
98 !strncmp(pos->uid.vduit, uid->vduit, sizeof(uid->vduit)))
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010099 return pos;
Peter Senna Tschudin3b974872015-08-04 17:11:15 +0200100 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100101 return NULL;
102}
103
104static 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
118static void _free_server(struct alias_server *server)
119{
120 kfree(server);
121}
122
123static 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 Weinhuberf4ac1d02009-12-07 12:51:53 +0100156 init_completion(&lcu->lcu_setup);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100157 return lcu;
158
159out_err4:
160 kfree(lcu->rsu_cqr->cpaddr);
161out_err3:
162 kfree(lcu->rsu_cqr);
163out_err2:
164 kfree(lcu->uac);
165out_err1:
166 kfree(lcu);
167 return ERR_PTR(-ENOMEM);
168}
169
170static 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 */
186int dasd_alias_make_device_known_to_lcu(struct dasd_device *device)
187{
Sebastian Ott543691a42016-03-04 10:34:05 +0100188 struct dasd_eckd_private *private = device->private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100189 unsigned long flags;
190 struct alias_server *server, *newserver;
191 struct alias_lcu *lcu, *newlcu;
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200192 struct dasd_uid uid;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100193
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200194 device->discipline->get_uid(device, &uid);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100195 spin_lock_irqsave(&aliastree.lock, flags);
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200196 server = _find_server(&uid);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100197 if (!server) {
198 spin_unlock_irqrestore(&aliastree.lock, flags);
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200199 newserver = _allocate_server(&uid);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100200 if (IS_ERR(newserver))
201 return PTR_ERR(newserver);
202 spin_lock_irqsave(&aliastree.lock, flags);
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200203 server = _find_server(&uid);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100204 if (!server) {
205 list_add(&newserver->server, &aliastree.serverlist);
206 server = newserver;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100207 } else {
208 /* someone was faster */
209 _free_server(newserver);
210 }
211 }
212
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200213 lcu = _find_lcu(server, &uid);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100214 if (!lcu) {
215 spin_unlock_irqrestore(&aliastree.lock, flags);
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200216 newlcu = _allocate_lcu(&uid);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100217 if (IS_ERR(newlcu))
Roel Kluin6d53cfe2009-12-18 17:43:17 +0100218 return PTR_ERR(newlcu);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100219 spin_lock_irqsave(&aliastree.lock, flags);
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200220 lcu = _find_lcu(server, &uid);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100221 if (!lcu) {
222 list_add(&newlcu->lcu, &server->lculist);
223 lcu = newlcu;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100224 } else {
225 /* someone was faster */
226 _free_lcu(newlcu);
227 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100228 }
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 Haberlandf9f8d022012-01-18 18:03:40 +0100235 return 0;
Stefan Weinhuberf4ac1d02009-12-07 12:51:53 +0100236}
237
238/*
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100239 * 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 */
243void dasd_alias_disconnect_device_from_lcu(struct dasd_device *device)
244{
Sebastian Ott543691a42016-03-04 10:34:05 +0100245 struct dasd_eckd_private *private = device->private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100246 unsigned long flags;
247 struct alias_lcu *lcu;
248 struct alias_server *server;
249 int was_pending;
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200250 struct dasd_uid uid;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100251
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100252 lcu = private->lcu;
Stefan Haberlandf602f6d62011-01-31 11:30:03 +0100253 /* nothing to do if already disconnected */
254 if (!lcu)
255 return;
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200256 device->discipline->get_uid(device, &uid);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100257 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 Haberland9d862ab2015-12-15 10:45:05 +0100264 if (device == lcu->suc_data.device) {
265 dasd_put_device(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100266 lcu->suc_data.device = NULL;
Stefan Haberland9d862ab2015-12-15 10:45:05 +0100267 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100268 }
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 Haberland9d862ab2015-12-15 10:45:05 +0100275 if (device == lcu->ruac_data.device) {
276 dasd_put_device(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100277 lcu->ruac_data.device = NULL;
Stefan Haberland9d862ab2015-12-15 10:45:05 +0100278 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100279 }
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 Haberland2dedf0d2010-05-17 10:00:11 +0200297 server = _find_server(&uid);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100298 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 Haberland2dedf0d2010-05-17 10:00:11 +0200310
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100311static int _add_device_to_lcu(struct alias_lcu *lcu,
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200312 struct dasd_device *device,
313 struct dasd_device *pos)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100314{
315
Sebastian Ott543691a42016-03-04 10:34:05 +0100316 struct dasd_eckd_private *private = device->private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100317 struct alias_pav_group *group;
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200318 struct dasd_uid uid;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100319
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100320 spin_lock(get_ccwdev_lock(device->cdev));
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200321 private->uid.type = lcu->uac->unit[private->uid.real_unit_addr].ua_type;
322 private->uid.base_unit_addr =
323 lcu->uac->unit[private->uid.real_unit_addr].base_ua;
324 uid = private->uid;
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100325 spin_unlock(get_ccwdev_lock(device->cdev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100326 /* if we have no PAV anyway, we don't need to bother with PAV groups */
327 if (lcu->pav == NO_PAV) {
328 list_move(&device->alias_list, &lcu->active_devices);
329 return 0;
330 }
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200331 group = _find_group(lcu, &uid);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100332 if (!group) {
333 group = kzalloc(sizeof(*group), GFP_ATOMIC);
334 if (!group)
335 return -ENOMEM;
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200336 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 Weinhuber8e09f212008-01-26 14:11:23 +0100341 else
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200342 group->uid.base_unit_addr = uid.base_unit_addr;
343 memcpy(group->uid.vduit, uid.vduit, sizeof(uid.vduit));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100344 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 Haberland2dedf0d2010-05-17 10:00:11 +0200349 if (uid.type == UA_BASE_DEVICE)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100350 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
357static void _remove_device_from_lcu(struct alias_lcu *lcu,
358 struct dasd_device *device)
359{
Sebastian Ott543691a42016-03-04 10:34:05 +0100360 struct dasd_eckd_private *private = device->private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100361 struct alias_pav_group *group;
362
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100363 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 Haberland03429f32012-09-11 17:19:12 +0200377static int
378suborder_not_supported(struct dasd_ccw_req *cqr)
379{
380 char *sense;
381 char reason;
382 char msg_format;
383 char msg_no;
384
Stefan Haberland0a878192019-08-01 13:06:30 +0200385 /*
386 * intrc values ENODEV, ENOLINK and EPERM
387 * will be optained from sleep_on to indicate that no
388 * IO operation can be started
389 */
390 if (cqr->intrc == -ENODEV)
391 return 1;
392
393 if (cqr->intrc == -ENOLINK)
394 return 1;
395
396 if (cqr->intrc == -EPERM)
397 return 1;
398
Stefan Haberland03429f32012-09-11 17:19:12 +0200399 sense = dasd_get_sense(&cqr->irb);
400 if (!sense)
401 return 0;
402
403 reason = sense[0];
404 msg_format = (sense[7] & 0xF0);
405 msg_no = (sense[7] & 0x0F);
406
407 /* command reject, Format 0 MSG 4 - invalid parameter */
408 if ((reason == 0x80) && (msg_format == 0x00) && (msg_no == 0x04))
409 return 1;
410
411 return 0;
412}
413
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100414static int read_unit_address_configuration(struct dasd_device *device,
415 struct alias_lcu *lcu)
416{
417 struct dasd_psf_prssd_data *prssdp;
418 struct dasd_ccw_req *cqr;
419 struct ccw1 *ccw;
420 int rc;
421 unsigned long flags;
422
Stefan Haberland68b781f2009-09-11 10:28:29 +0200423 cqr = dasd_kmalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100424 (sizeof(struct dasd_psf_prssd_data)),
425 device);
426 if (IS_ERR(cqr))
427 return PTR_ERR(cqr);
428 cqr->startdev = device;
429 cqr->memdev = device;
430 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
431 cqr->retries = 10;
432 cqr->expires = 20 * HZ;
433
434 /* Prepare for Read Subsystem Data */
435 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
436 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
437 prssdp->order = PSF_ORDER_PRSSD;
438 prssdp->suborder = 0x0e; /* Read unit address configuration */
439 /* all other bytes of prssdp must be zero */
440
441 ccw = cqr->cpaddr;
442 ccw->cmd_code = DASD_ECKD_CCW_PSF;
443 ccw->count = sizeof(struct dasd_psf_prssd_data);
444 ccw->flags |= CCW_FLAG_CC;
445 ccw->cda = (__u32)(addr_t) prssdp;
446
447 /* Read Subsystem Data - feature codes */
448 memset(lcu->uac, 0, sizeof(*(lcu->uac)));
449
450 ccw++;
451 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
452 ccw->count = sizeof(*(lcu->uac));
453 ccw->cda = (__u32)(addr_t) lcu->uac;
454
Heiko Carstens1aae0562013-01-30 09:49:40 +0100455 cqr->buildclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100456 cqr->status = DASD_CQR_FILLED;
457
458 /* need to unset flag here to detect race with summary unit check */
459 spin_lock_irqsave(&lcu->lock, flags);
460 lcu->flags &= ~NEED_UAC_UPDATE;
461 spin_unlock_irqrestore(&lcu->lock, flags);
462
Stefan Haberland0a878192019-08-01 13:06:30 +0200463 rc = dasd_sleep_on(cqr);
464 if (rc && !suborder_not_supported(cqr)) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100465 spin_lock_irqsave(&lcu->lock, flags);
466 lcu->flags |= NEED_UAC_UPDATE;
467 spin_unlock_irqrestore(&lcu->lock, flags);
468 }
469 dasd_kfree_request(cqr, cqr->memdev);
470 return rc;
471}
472
473static int _lcu_update(struct dasd_device *refdev, struct alias_lcu *lcu)
474{
475 unsigned long flags;
476 struct alias_pav_group *pavgroup, *tempgroup;
477 struct dasd_device *device, *tempdev;
478 int i, rc;
479 struct dasd_eckd_private *private;
480
481 spin_lock_irqsave(&lcu->lock, flags);
482 list_for_each_entry_safe(pavgroup, tempgroup, &lcu->grouplist, group) {
483 list_for_each_entry_safe(device, tempdev, &pavgroup->baselist,
484 alias_list) {
485 list_move(&device->alias_list, &lcu->active_devices);
Sebastian Ott543691a42016-03-04 10:34:05 +0100486 private = device->private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100487 private->pavgroup = NULL;
488 }
489 list_for_each_entry_safe(device, tempdev, &pavgroup->aliaslist,
490 alias_list) {
491 list_move(&device->alias_list, &lcu->active_devices);
Sebastian Ott543691a42016-03-04 10:34:05 +0100492 private = device->private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100493 private->pavgroup = NULL;
494 }
495 list_del(&pavgroup->group);
496 kfree(pavgroup);
497 }
498 spin_unlock_irqrestore(&lcu->lock, flags);
499
500 rc = read_unit_address_configuration(refdev, lcu);
501 if (rc)
502 return rc;
503
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100504 spin_lock_irqsave(&lcu->lock, flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100505 lcu->pav = NO_PAV;
506 for (i = 0; i < MAX_DEVICES_PER_LCU; ++i) {
507 switch (lcu->uac->unit[i].ua_type) {
508 case UA_BASE_PAV_ALIAS:
509 lcu->pav = BASE_PAV;
510 break;
511 case UA_HYPER_PAV_ALIAS:
512 lcu->pav = HYPER_PAV;
513 break;
514 }
515 if (lcu->pav != NO_PAV)
516 break;
517 }
518
519 list_for_each_entry_safe(device, tempdev, &lcu->active_devices,
520 alias_list) {
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200521 _add_device_to_lcu(lcu, device, refdev);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100522 }
Stefan Haberland9bfefde2015-12-15 11:00:51 +0100523 spin_unlock_irqrestore(&lcu->lock, flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100524 return 0;
525}
526
527static void lcu_update_work(struct work_struct *work)
528{
529 struct alias_lcu *lcu;
530 struct read_uac_work_data *ruac_data;
531 struct dasd_device *device;
532 unsigned long flags;
533 int rc;
534
535 ruac_data = container_of(work, struct read_uac_work_data, dwork.work);
536 lcu = container_of(ruac_data, struct alias_lcu, ruac_data);
537 device = ruac_data->device;
538 rc = _lcu_update(device, lcu);
539 /*
540 * Need to check flags again, as there could have been another
541 * prepare_update or a new device a new device while we were still
542 * processing the data
543 */
544 spin_lock_irqsave(&lcu->lock, flags);
Stefan Haberland03429f32012-09-11 17:19:12 +0200545 if ((rc && (rc != -EOPNOTSUPP)) || (lcu->flags & NEED_UAC_UPDATE)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100546 DBF_DEV_EVENT(DBF_WARNING, device, "could not update"
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100547 " alias data in lcu (rc = %d), retry later", rc);
Stefan Haberland9d862ab2015-12-15 10:45:05 +0100548 if (!schedule_delayed_work(&lcu->ruac_data.dwork, 30*HZ))
549 dasd_put_device(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100550 } else {
Stefan Haberland9d862ab2015-12-15 10:45:05 +0100551 dasd_put_device(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100552 lcu->ruac_data.device = NULL;
553 lcu->flags &= ~UPDATE_PENDING;
554 }
555 spin_unlock_irqrestore(&lcu->lock, flags);
556}
557
558static int _schedule_lcu_update(struct alias_lcu *lcu,
559 struct dasd_device *device)
560{
561 struct dasd_device *usedev = NULL;
562 struct alias_pav_group *group;
563
564 lcu->flags |= NEED_UAC_UPDATE;
565 if (lcu->ruac_data.device) {
566 /* already scheduled or running */
567 return 0;
568 }
569 if (device && !list_empty(&device->alias_list))
570 usedev = device;
571
572 if (!usedev && !list_empty(&lcu->grouplist)) {
573 group = list_first_entry(&lcu->grouplist,
574 struct alias_pav_group, group);
575 if (!list_empty(&group->baselist))
576 usedev = list_first_entry(&group->baselist,
577 struct dasd_device,
578 alias_list);
579 else if (!list_empty(&group->aliaslist))
580 usedev = list_first_entry(&group->aliaslist,
581 struct dasd_device,
582 alias_list);
583 }
584 if (!usedev && !list_empty(&lcu->active_devices)) {
585 usedev = list_first_entry(&lcu->active_devices,
586 struct dasd_device, alias_list);
587 }
588 /*
589 * if we haven't found a proper device yet, give up for now, the next
590 * device that will be set active will trigger an lcu update
591 */
592 if (!usedev)
593 return -EINVAL;
Stefan Haberland9d862ab2015-12-15 10:45:05 +0100594 dasd_get_device(usedev);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100595 lcu->ruac_data.device = usedev;
Stefan Haberland9d862ab2015-12-15 10:45:05 +0100596 if (!schedule_delayed_work(&lcu->ruac_data.dwork, 0))
597 dasd_put_device(usedev);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100598 return 0;
599}
600
601int dasd_alias_add_device(struct dasd_device *device)
602{
Sebastian Ott543691a42016-03-04 10:34:05 +0100603 struct dasd_eckd_private *private = device->private;
Stefan Haberlanda714a5f2018-04-12 13:38:22 +0200604 __u8 uaddr = private->uid.real_unit_addr;
605 struct alias_lcu *lcu = private->lcu;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100606 unsigned long flags;
607 int rc;
608
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100609 rc = 0;
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100610 spin_lock_irqsave(&lcu->lock, flags);
Stefan Haberlanda714a5f2018-04-12 13:38:22 +0200611 /*
612 * Check if device and lcu type differ. If so, the uac data may be
613 * outdated and needs to be updated.
614 */
615 if (private->uid.type != lcu->uac->unit[uaddr].ua_type) {
616 lcu->flags |= UPDATE_PENDING;
617 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
618 "uid type mismatch - trigger rescan");
619 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100620 if (!(lcu->flags & UPDATE_PENDING)) {
Stefan Haberland2dedf0d2010-05-17 10:00:11 +0200621 rc = _add_device_to_lcu(lcu, device, device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100622 if (rc)
623 lcu->flags |= UPDATE_PENDING;
624 }
625 if (lcu->flags & UPDATE_PENDING) {
626 list_move(&device->alias_list, &lcu->active_devices);
627 _schedule_lcu_update(lcu, device);
628 }
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100629 spin_unlock_irqrestore(&lcu->lock, flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100630 return rc;
631}
632
Stefan Haberland501183f2010-05-17 10:00:10 +0200633int dasd_alias_update_add_device(struct dasd_device *device)
634{
Sebastian Ott543691a42016-03-04 10:34:05 +0100635 struct dasd_eckd_private *private = device->private;
636
Stefan Haberland501183f2010-05-17 10:00:10 +0200637 private->lcu->flags |= UPDATE_PENDING;
638 return dasd_alias_add_device(device);
639}
640
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100641int dasd_alias_remove_device(struct dasd_device *device)
642{
Sebastian Ott543691a42016-03-04 10:34:05 +0100643 struct dasd_eckd_private *private = device->private;
644 struct alias_lcu *lcu = private->lcu;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100645 unsigned long flags;
646
Stefan Haberlandf602f6d62011-01-31 11:30:03 +0100647 /* nothing to do if already removed */
648 if (!lcu)
649 return 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100650 spin_lock_irqsave(&lcu->lock, flags);
651 _remove_device_from_lcu(lcu, device);
652 spin_unlock_irqrestore(&lcu->lock, flags);
653 return 0;
654}
655
656struct dasd_device *dasd_alias_get_start_dev(struct dasd_device *base_device)
657{
Sebastian Ott543691a42016-03-04 10:34:05 +0100658 struct dasd_eckd_private *alias_priv, *private = base_device->private;
659 struct alias_pav_group *group = private->pavgroup;
660 struct alias_lcu *lcu = private->lcu;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100661 struct dasd_device *alias_device;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100662 unsigned long flags;
663
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100664 if (!group || !lcu)
665 return NULL;
666 if (lcu->pav == NO_PAV ||
667 lcu->flags & (NEED_UAC_UPDATE | UPDATE_PENDING))
668 return NULL;
Stefan Haberlandb38f27e2011-12-27 11:27:28 +0100669 if (unlikely(!(private->features.feature[8] & 0x01))) {
670 /*
671 * PAV enabled but prefix not, very unlikely
672 * seems to be a lost pathgroup
673 * use base device to do IO
674 */
675 DBF_DEV_EVENT(DBF_ERR, base_device, "%s",
676 "Prefix not enabled with PAV enabled\n");
677 return NULL;
678 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100679
680 spin_lock_irqsave(&lcu->lock, flags);
681 alias_device = group->next;
682 if (!alias_device) {
683 if (list_empty(&group->aliaslist)) {
684 spin_unlock_irqrestore(&lcu->lock, flags);
685 return NULL;
686 } else {
687 alias_device = list_first_entry(&group->aliaslist,
688 struct dasd_device,
689 alias_list);
690 }
691 }
692 if (list_is_last(&alias_device->alias_list, &group->aliaslist))
693 group->next = list_first_entry(&group->aliaslist,
694 struct dasd_device, alias_list);
695 else
696 group->next = list_first_entry(&alias_device->alias_list,
697 struct dasd_device, alias_list);
698 spin_unlock_irqrestore(&lcu->lock, flags);
Sebastian Ott543691a42016-03-04 10:34:05 +0100699 alias_priv = alias_device->private;
Stefan Haberlandf81a49d2015-07-10 10:47:09 +0200700 if ((alias_priv->count < private->count) && !alias_device->stopped &&
701 !test_bit(DASD_FLAG_OFFLINE, &alias_device->flags))
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100702 return alias_device;
703 else
704 return NULL;
705}
706
707/*
708 * Summary unit check handling depends on the way alias devices
709 * are handled so it is done here rather then in dasd_eckd.c
710 */
711static int reset_summary_unit_check(struct alias_lcu *lcu,
712 struct dasd_device *device,
713 char reason)
714{
715 struct dasd_ccw_req *cqr;
716 int rc = 0;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100717 struct ccw1 *ccw;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100718
719 cqr = lcu->rsu_cqr;
720 strncpy((char *) &cqr->magic, "ECKD", 4);
721 ASCEBC((char *) &cqr->magic, 4);
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100722 ccw = cqr->cpaddr;
723 ccw->cmd_code = DASD_ECKD_CCW_RSCK;
Stefan Haberland020bf042015-12-15 10:16:43 +0100724 ccw->flags = CCW_FLAG_SLI;
Stefan Weinhuberf3eb5382009-03-26 15:23:48 +0100725 ccw->count = 16;
726 ccw->cda = (__u32)(addr_t) cqr->data;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100727 ((char *)cqr->data)[0] = reason;
728
729 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
730 cqr->retries = 255; /* set retry counter to enable basic ERP */
731 cqr->startdev = device;
732 cqr->memdev = device;
733 cqr->block = NULL;
734 cqr->expires = 5 * HZ;
Heiko Carstens1aae0562013-01-30 09:49:40 +0100735 cqr->buildclk = get_tod_clock();
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100736 cqr->status = DASD_CQR_FILLED;
737
738 rc = dasd_sleep_on_immediatly(cqr);
739 return rc;
740}
741
742static void _restart_all_base_devices_on_lcu(struct alias_lcu *lcu)
743{
744 struct alias_pav_group *pavgroup;
745 struct dasd_device *device;
746 struct dasd_eckd_private *private;
747
748 /* active and inactive list can contain alias as well as base devices */
749 list_for_each_entry(device, &lcu->active_devices, alias_list) {
Sebastian Ott543691a42016-03-04 10:34:05 +0100750 private = device->private;
Stefan Haberland9bfefde2015-12-15 11:00:51 +0100751 if (private->uid.type != UA_BASE_DEVICE)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100752 continue;
753 dasd_schedule_block_bh(device->block);
754 dasd_schedule_device_bh(device);
755 }
756 list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
Sebastian Ott543691a42016-03-04 10:34:05 +0100757 private = device->private;
Stefan Haberland9bfefde2015-12-15 11:00:51 +0100758 if (private->uid.type != UA_BASE_DEVICE)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100759 continue;
760 dasd_schedule_block_bh(device->block);
761 dasd_schedule_device_bh(device);
762 }
763 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
764 list_for_each_entry(device, &pavgroup->baselist, alias_list) {
765 dasd_schedule_block_bh(device->block);
766 dasd_schedule_device_bh(device);
767 }
768 }
769}
770
771static void flush_all_alias_devices_on_lcu(struct alias_lcu *lcu)
772{
773 struct alias_pav_group *pavgroup;
774 struct dasd_device *device, *temp;
775 struct dasd_eckd_private *private;
776 int rc;
777 unsigned long flags;
778 LIST_HEAD(active);
779
780 /*
781 * Problem here ist that dasd_flush_device_queue may wait
782 * for termination of a request to complete. We can't keep
783 * the lcu lock during that time, so we must assume that
784 * the lists may have changed.
785 * Idea: first gather all active alias devices in a separate list,
786 * then flush the first element of this list unlocked, and afterwards
787 * check if it is still on the list before moving it to the
788 * active_devices list.
789 */
790
791 spin_lock_irqsave(&lcu->lock, flags);
792 list_for_each_entry_safe(device, temp, &lcu->active_devices,
793 alias_list) {
Sebastian Ott543691a42016-03-04 10:34:05 +0100794 private = device->private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100795 if (private->uid.type == UA_BASE_DEVICE)
796 continue;
797 list_move(&device->alias_list, &active);
798 }
799
800 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
801 list_splice_init(&pavgroup->aliaslist, &active);
802 }
803 while (!list_empty(&active)) {
804 device = list_first_entry(&active, struct dasd_device,
805 alias_list);
806 spin_unlock_irqrestore(&lcu->lock, flags);
807 rc = dasd_flush_device_queue(device);
808 spin_lock_irqsave(&lcu->lock, flags);
809 /*
810 * only move device around if it wasn't moved away while we
811 * were waiting for the flush
812 */
813 if (device == list_first_entry(&active,
Stefan Haberland6933c352015-10-14 11:01:05 +0200814 struct dasd_device, alias_list)) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100815 list_move(&device->alias_list, &lcu->active_devices);
Sebastian Ott543691a42016-03-04 10:34:05 +0100816 private = device->private;
Stefan Haberland6933c352015-10-14 11:01:05 +0200817 private->pavgroup = NULL;
818 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100819 }
820 spin_unlock_irqrestore(&lcu->lock, flags);
821}
822
Stefan Haberland9bfefde2015-12-15 11:00:51 +0100823static void _stop_all_devices_on_lcu(struct alias_lcu *lcu)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100824{
825 struct alias_pav_group *pavgroup;
Stefan Haberland9bfefde2015-12-15 11:00:51 +0100826 struct dasd_device *device;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100827
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100828 list_for_each_entry(device, &lcu->active_devices, alias_list) {
829 spin_lock(get_ccwdev_lock(device->cdev));
Stefan Haberland9bfefde2015-12-15 11:00:51 +0100830 dasd_device_set_stop_bits(device, DASD_STOPPED_SU);
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100831 spin_unlock(get_ccwdev_lock(device->cdev));
832 }
833 list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
834 spin_lock(get_ccwdev_lock(device->cdev));
Stefan Haberland9bfefde2015-12-15 11:00:51 +0100835 dasd_device_set_stop_bits(device, DASD_STOPPED_SU);
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100836 spin_unlock(get_ccwdev_lock(device->cdev));
837 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100838 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100839 list_for_each_entry(device, &pavgroup->baselist, alias_list) {
840 spin_lock(get_ccwdev_lock(device->cdev));
Stefan Haberland9bfefde2015-12-15 11:00:51 +0100841 dasd_device_set_stop_bits(device, DASD_STOPPED_SU);
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100842 spin_unlock(get_ccwdev_lock(device->cdev));
843 }
844 list_for_each_entry(device, &pavgroup->aliaslist, alias_list) {
845 spin_lock(get_ccwdev_lock(device->cdev));
Stefan Haberland9bfefde2015-12-15 11:00:51 +0100846 dasd_device_set_stop_bits(device, DASD_STOPPED_SU);
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100847 spin_unlock(get_ccwdev_lock(device->cdev));
848 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100849 }
850}
851
852static void _unstop_all_devices_on_lcu(struct alias_lcu *lcu)
853{
854 struct alias_pav_group *pavgroup;
855 struct dasd_device *device;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100856
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100857 list_for_each_entry(device, &lcu->active_devices, alias_list) {
858 spin_lock(get_ccwdev_lock(device->cdev));
Stefan Weinhubereb6e1992009-12-07 12:51:51 +0100859 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100860 spin_unlock(get_ccwdev_lock(device->cdev));
861 }
862 list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
863 spin_lock(get_ccwdev_lock(device->cdev));
Stefan Weinhubereb6e1992009-12-07 12:51:51 +0100864 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100865 spin_unlock(get_ccwdev_lock(device->cdev));
866 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100867 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100868 list_for_each_entry(device, &pavgroup->baselist, alias_list) {
869 spin_lock(get_ccwdev_lock(device->cdev));
Stefan Weinhubereb6e1992009-12-07 12:51:51 +0100870 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100871 spin_unlock(get_ccwdev_lock(device->cdev));
872 }
873 list_for_each_entry(device, &pavgroup->aliaslist, alias_list) {
874 spin_lock(get_ccwdev_lock(device->cdev));
Stefan Weinhubereb6e1992009-12-07 12:51:51 +0100875 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100876 spin_unlock(get_ccwdev_lock(device->cdev));
877 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100878 }
879}
880
881static void summary_unit_check_handling_work(struct work_struct *work)
882{
883 struct alias_lcu *lcu;
884 struct summary_unit_check_work_data *suc_data;
885 unsigned long flags;
886 struct dasd_device *device;
887
888 suc_data = container_of(work, struct summary_unit_check_work_data,
889 worker);
890 lcu = container_of(suc_data, struct alias_lcu, suc_data);
891 device = suc_data->device;
892
893 /* 1. flush alias devices */
894 flush_all_alias_devices_on_lcu(lcu);
895
896 /* 2. reset summary unit check */
897 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +0100898 dasd_device_remove_stop_bits(device,
899 (DASD_STOPPED_SU | DASD_STOPPED_PENDING));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100900 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
901 reset_summary_unit_check(lcu, device, suc_data->reason);
902
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100903 spin_lock_irqsave(&lcu->lock, flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100904 _unstop_all_devices_on_lcu(lcu);
905 _restart_all_base_devices_on_lcu(lcu);
906 /* 3. read new alias configuration */
907 _schedule_lcu_update(lcu, device);
908 lcu->suc_data.device = NULL;
Stefan Haberland9d862ab2015-12-15 10:45:05 +0100909 dasd_put_device(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100910 spin_unlock_irqrestore(&lcu->lock, flags);
911}
912
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100913void dasd_alias_handle_summary_unit_check(struct work_struct *work)
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100914{
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100915 struct dasd_device *device = container_of(work, struct dasd_device,
916 suc_work);
Sebastian Ott543691a42016-03-04 10:34:05 +0100917 struct dasd_eckd_private *private = device->private;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100918 struct alias_lcu *lcu;
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100919 unsigned long flags;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100920
921 lcu = private->lcu;
922 if (!lcu) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100923 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100924 "device not ready to handle summary"
925 " unit check (no lcu structure)");
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100926 goto out;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100927 }
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100928 spin_lock_irqsave(&lcu->lock, flags);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100929 /* If this device is about to be removed just return and wait for
930 * the next interrupt on a different device
931 */
932 if (list_empty(&device->alias_list)) {
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100933 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100934 "device is in offline processing,"
935 " don't do summary unit check handling");
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100936 goto out_unlock;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100937 }
938 if (lcu->suc_data.device) {
939 /* already scheduled or running */
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100940 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100941 "previous instance of summary unit check worker"
942 " still pending");
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100943 goto out_unlock;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100944 }
Stefan Haberland9bfefde2015-12-15 11:00:51 +0100945 _stop_all_devices_on_lcu(lcu);
946 /* prepare for lcu_update */
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100947 lcu->flags |= NEED_UAC_UPDATE | UPDATE_PENDING;
948 lcu->suc_data.reason = private->suc_reason;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100949 lcu->suc_data.device = device;
Stefan Haberland9d862ab2015-12-15 10:45:05 +0100950 dasd_get_device(device);
Stefan Haberland9d862ab2015-12-15 10:45:05 +0100951 if (!schedule_work(&lcu->suc_data.worker))
952 dasd_put_device(device);
Stefan Haberland59a9ed52016-02-23 10:15:27 +0100953out_unlock:
954 spin_unlock_irqrestore(&lcu->lock, flags);
955out:
956 clear_bit(DASD_FLAG_SUC, &device->flags);
957 dasd_put_device(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100958};