2 * PAV alias management for the DASD ECKD discipline
4 * Copyright IBM Corporation, 2007
5 * Author(s): Stefan Weinhuber <wein@de.ibm.com>
8 #define KMSG_COMPONENT "dasd-eckd"
10 #include <linux/list.h>
11 #include <linux/slab.h>
12 #include <asm/ebcdic.h>
14 #include "dasd_eckd.h"
18 #endif /* PRINTK_HEADER */
19 #define PRINTK_HEADER "dasd(eckd):"
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
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 *);
47 static struct alias_root aliastree = {
48 .serverlist = LIST_HEAD_INIT(aliastree.serverlist),
49 .lock = __SPIN_LOCK_UNLOCKED(aliastree.lock),
52 static struct alias_server *_find_server(struct dasd_uid *uid)
54 struct alias_server *pos;
55 list_for_each_entry(pos, &aliastree.serverlist, server) {
56 if (!strncmp(pos->uid.vendor, uid->vendor,
58 && !strncmp(pos->uid.serial, uid->serial,
65 static struct alias_lcu *_find_lcu(struct alias_server *server,
68 struct alias_lcu *pos;
69 list_for_each_entry(pos, &server->lculist, lcu) {
70 if (pos->uid.ssid == uid->ssid)
76 static struct alias_pav_group *_find_group(struct alias_lcu *lcu,
79 struct alias_pav_group *pos;
80 __u8 search_unit_addr;
82 /* for hyper pav there is only one group */
83 if (lcu->pav == HYPER_PAV) {
84 if (list_empty(&lcu->grouplist))
87 return list_first_entry(&lcu->grouplist,
88 struct alias_pav_group, group);
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;
95 search_unit_addr = uid->base_unit_addr;
96 list_for_each_entry(pos, &lcu->grouplist, group) {
97 if (pos->uid.base_unit_addr == search_unit_addr &&
98 !strncmp(pos->uid.vduit, uid->vduit, sizeof(uid->vduit)))
104 static struct alias_server *_allocate_server(struct dasd_uid *uid)
106 struct alias_server *server;
108 server = kzalloc(sizeof(*server), GFP_KERNEL);
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);
118 static void _free_server(struct alias_server *server)
123 static struct alias_lcu *_allocate_lcu(struct dasd_uid *uid)
125 struct alias_lcu *lcu;
127 lcu = kzalloc(sizeof(*lcu), GFP_KERNEL);
129 return ERR_PTR(-ENOMEM);
130 lcu->uac = kzalloc(sizeof(*(lcu->uac)), GFP_KERNEL | GFP_DMA);
133 lcu->rsu_cqr = kzalloc(sizeof(*lcu->rsu_cqr), GFP_KERNEL | GFP_DMA);
136 lcu->rsu_cqr->cpaddr = kzalloc(sizeof(struct ccw1),
137 GFP_KERNEL | GFP_DMA);
138 if (!lcu->rsu_cqr->cpaddr)
140 lcu->rsu_cqr->data = kzalloc(16, GFP_KERNEL | GFP_DMA);
141 if (!lcu->rsu_cqr->data)
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;
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);
156 init_completion(&lcu->lcu_setup);
160 kfree(lcu->rsu_cqr->cpaddr);
167 return ERR_PTR(-ENOMEM);
170 static void _free_lcu(struct alias_lcu *lcu)
172 kfree(lcu->rsu_cqr->data);
173 kfree(lcu->rsu_cqr->cpaddr);
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)
186 int dasd_alias_make_device_known_to_lcu(struct dasd_device *device)
188 struct dasd_eckd_private *private;
190 struct alias_server *server, *newserver;
191 struct alias_lcu *lcu, *newlcu;
195 private = (struct dasd_eckd_private *) device->private;
197 device->discipline->get_uid(device, &uid);
198 spin_lock_irqsave(&aliastree.lock, flags);
200 server = _find_server(&uid);
202 spin_unlock_irqrestore(&aliastree.lock, flags);
203 newserver = _allocate_server(&uid);
204 if (IS_ERR(newserver))
205 return PTR_ERR(newserver);
206 spin_lock_irqsave(&aliastree.lock, flags);
207 server = _find_server(&uid);
209 list_add(&newserver->server, &aliastree.serverlist);
213 /* someone was faster */
214 _free_server(newserver);
218 lcu = _find_lcu(server, &uid);
220 spin_unlock_irqrestore(&aliastree.lock, flags);
221 newlcu = _allocate_lcu(&uid);
223 return PTR_ERR(newlcu);
224 spin_lock_irqsave(&aliastree.lock, flags);
225 lcu = _find_lcu(server, &uid);
227 list_add(&newlcu->lcu, &server->lculist);
231 /* someone was faster */
236 spin_lock(&lcu->lock);
237 list_add(&device->alias_list, &lcu->inactive_devices);
239 spin_unlock(&lcu->lock);
240 spin_unlock_irqrestore(&aliastree.lock, flags);
246 * The first device to be registered on an LCU will have to do
247 * some additional setup steps to configure that LCU on the
248 * storage server. All further devices should wait with their
249 * initialization until the first device is done.
250 * To synchronize this work, the first device will call
251 * dasd_alias_lcu_setup_complete when it is done, and all
252 * other devices will wait for it with dasd_alias_wait_for_lcu_setup.
254 void dasd_alias_lcu_setup_complete(struct dasd_device *device)
257 struct alias_server *server;
258 struct alias_lcu *lcu;
261 device->discipline->get_uid(device, &uid);
263 spin_lock_irqsave(&aliastree.lock, flags);
264 server = _find_server(&uid);
266 lcu = _find_lcu(server, &uid);
267 spin_unlock_irqrestore(&aliastree.lock, flags);
269 DBF_EVENT_DEVID(DBF_ERR, device->cdev,
270 "could not find lcu for %04x %02x",
271 uid.ssid, uid.real_unit_addr);
275 complete_all(&lcu->lcu_setup);
278 void dasd_alias_wait_for_lcu_setup(struct dasd_device *device)
281 struct alias_server *server;
282 struct alias_lcu *lcu;
285 device->discipline->get_uid(device, &uid);
287 spin_lock_irqsave(&aliastree.lock, flags);
288 server = _find_server(&uid);
290 lcu = _find_lcu(server, &uid);
291 spin_unlock_irqrestore(&aliastree.lock, flags);
293 DBF_EVENT_DEVID(DBF_ERR, device->cdev,
294 "could not find lcu for %04x %02x",
295 uid.ssid, uid.real_unit_addr);
299 wait_for_completion(&lcu->lcu_setup);
303 * This function removes a device from the scope of alias management.
304 * The complicated part is to make sure that it is not in use by
305 * any of the workers. If necessary cancel the work.
307 void dasd_alias_disconnect_device_from_lcu(struct dasd_device *device)
309 struct dasd_eckd_private *private;
311 struct alias_lcu *lcu;
312 struct alias_server *server;
316 private = (struct dasd_eckd_private *) device->private;
318 /* nothing to do if already disconnected */
321 device->discipline->get_uid(device, &uid);
322 spin_lock_irqsave(&lcu->lock, flags);
323 list_del_init(&device->alias_list);
324 /* make sure that the workers don't use this device */
325 if (device == lcu->suc_data.device) {
326 spin_unlock_irqrestore(&lcu->lock, flags);
327 cancel_work_sync(&lcu->suc_data.worker);
328 spin_lock_irqsave(&lcu->lock, flags);
329 if (device == lcu->suc_data.device)
330 lcu->suc_data.device = NULL;
333 if (device == lcu->ruac_data.device) {
334 spin_unlock_irqrestore(&lcu->lock, flags);
336 cancel_delayed_work_sync(&lcu->ruac_data.dwork);
337 spin_lock_irqsave(&lcu->lock, flags);
338 if (device == lcu->ruac_data.device)
339 lcu->ruac_data.device = NULL;
342 spin_unlock_irqrestore(&lcu->lock, flags);
344 spin_lock_irqsave(&aliastree.lock, flags);
345 spin_lock(&lcu->lock);
346 if (list_empty(&lcu->grouplist) &&
347 list_empty(&lcu->active_devices) &&
348 list_empty(&lcu->inactive_devices)) {
350 spin_unlock(&lcu->lock);
355 _schedule_lcu_update(lcu, NULL);
356 spin_unlock(&lcu->lock);
358 server = _find_server(&uid);
359 if (server && list_empty(&server->lculist)) {
360 list_del(&server->server);
361 _free_server(server);
363 spin_unlock_irqrestore(&aliastree.lock, flags);
367 * This function assumes that the unit address configuration stored
368 * in the lcu is up to date and will update the device uid before
369 * adding it to a pav group.
372 static int _add_device_to_lcu(struct alias_lcu *lcu,
373 struct dasd_device *device,
374 struct dasd_device *pos)
377 struct dasd_eckd_private *private;
378 struct alias_pav_group *group;
382 private = (struct dasd_eckd_private *) device->private;
384 /* only lock if not already locked */
386 spin_lock_irqsave_nested(get_ccwdev_lock(device->cdev), flags,
388 private->uid.type = lcu->uac->unit[private->uid.real_unit_addr].ua_type;
389 private->uid.base_unit_addr =
390 lcu->uac->unit[private->uid.real_unit_addr].base_ua;
394 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
396 /* if we have no PAV anyway, we don't need to bother with PAV groups */
397 if (lcu->pav == NO_PAV) {
398 list_move(&device->alias_list, &lcu->active_devices);
402 group = _find_group(lcu, &uid);
404 group = kzalloc(sizeof(*group), GFP_ATOMIC);
407 memcpy(group->uid.vendor, uid.vendor, sizeof(uid.vendor));
408 memcpy(group->uid.serial, uid.serial, sizeof(uid.serial));
409 group->uid.ssid = uid.ssid;
410 if (uid.type == UA_BASE_DEVICE)
411 group->uid.base_unit_addr = uid.real_unit_addr;
413 group->uid.base_unit_addr = uid.base_unit_addr;
414 memcpy(group->uid.vduit, uid.vduit, sizeof(uid.vduit));
415 INIT_LIST_HEAD(&group->group);
416 INIT_LIST_HEAD(&group->baselist);
417 INIT_LIST_HEAD(&group->aliaslist);
418 list_add(&group->group, &lcu->grouplist);
420 if (uid.type == UA_BASE_DEVICE)
421 list_move(&device->alias_list, &group->baselist);
423 list_move(&device->alias_list, &group->aliaslist);
424 private->pavgroup = group;
428 static void _remove_device_from_lcu(struct alias_lcu *lcu,
429 struct dasd_device *device)
431 struct dasd_eckd_private *private;
432 struct alias_pav_group *group;
434 private = (struct dasd_eckd_private *) device->private;
435 list_move(&device->alias_list, &lcu->inactive_devices);
436 group = private->pavgroup;
439 private->pavgroup = NULL;
440 if (list_empty(&group->baselist) && list_empty(&group->aliaslist)) {
441 list_del(&group->group);
445 if (group->next == device)
449 static int read_unit_address_configuration(struct dasd_device *device,
450 struct alias_lcu *lcu)
452 struct dasd_psf_prssd_data *prssdp;
453 struct dasd_ccw_req *cqr;
458 cqr = dasd_kmalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
459 (sizeof(struct dasd_psf_prssd_data)),
463 cqr->startdev = device;
464 cqr->memdev = device;
465 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
467 cqr->expires = 20 * HZ;
469 /* Prepare for Read Subsystem Data */
470 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
471 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
472 prssdp->order = PSF_ORDER_PRSSD;
473 prssdp->suborder = 0x0e; /* Read unit address configuration */
474 /* all other bytes of prssdp must be zero */
477 ccw->cmd_code = DASD_ECKD_CCW_PSF;
478 ccw->count = sizeof(struct dasd_psf_prssd_data);
479 ccw->flags |= CCW_FLAG_CC;
480 ccw->cda = (__u32)(addr_t) prssdp;
482 /* Read Subsystem Data - feature codes */
483 memset(lcu->uac, 0, sizeof(*(lcu->uac)));
486 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
487 ccw->count = sizeof(*(lcu->uac));
488 ccw->cda = (__u32)(addr_t) lcu->uac;
490 cqr->buildclk = get_clock();
491 cqr->status = DASD_CQR_FILLED;
493 /* need to unset flag here to detect race with summary unit check */
494 spin_lock_irqsave(&lcu->lock, flags);
495 lcu->flags &= ~NEED_UAC_UPDATE;
496 spin_unlock_irqrestore(&lcu->lock, flags);
499 rc = dasd_sleep_on(cqr);
500 } while (rc && (cqr->retries > 0));
502 spin_lock_irqsave(&lcu->lock, flags);
503 lcu->flags |= NEED_UAC_UPDATE;
504 spin_unlock_irqrestore(&lcu->lock, flags);
506 dasd_kfree_request(cqr, cqr->memdev);
510 static int _lcu_update(struct dasd_device *refdev, struct alias_lcu *lcu)
513 struct alias_pav_group *pavgroup, *tempgroup;
514 struct dasd_device *device, *tempdev;
516 struct dasd_eckd_private *private;
518 spin_lock_irqsave(&lcu->lock, flags);
519 list_for_each_entry_safe(pavgroup, tempgroup, &lcu->grouplist, group) {
520 list_for_each_entry_safe(device, tempdev, &pavgroup->baselist,
522 list_move(&device->alias_list, &lcu->active_devices);
523 private = (struct dasd_eckd_private *) device->private;
524 private->pavgroup = NULL;
526 list_for_each_entry_safe(device, tempdev, &pavgroup->aliaslist,
528 list_move(&device->alias_list, &lcu->active_devices);
529 private = (struct dasd_eckd_private *) device->private;
530 private->pavgroup = NULL;
532 list_del(&pavgroup->group);
535 spin_unlock_irqrestore(&lcu->lock, flags);
537 rc = read_unit_address_configuration(refdev, lcu);
541 /* need to take cdev lock before lcu lock */
542 spin_lock_irqsave_nested(get_ccwdev_lock(refdev->cdev), flags,
544 spin_lock(&lcu->lock);
546 for (i = 0; i < MAX_DEVICES_PER_LCU; ++i) {
547 switch (lcu->uac->unit[i].ua_type) {
548 case UA_BASE_PAV_ALIAS:
551 case UA_HYPER_PAV_ALIAS:
552 lcu->pav = HYPER_PAV;
555 if (lcu->pav != NO_PAV)
559 list_for_each_entry_safe(device, tempdev, &lcu->active_devices,
561 _add_device_to_lcu(lcu, device, refdev);
563 spin_unlock(&lcu->lock);
564 spin_unlock_irqrestore(get_ccwdev_lock(refdev->cdev), flags);
568 static void lcu_update_work(struct work_struct *work)
570 struct alias_lcu *lcu;
571 struct read_uac_work_data *ruac_data;
572 struct dasd_device *device;
576 ruac_data = container_of(work, struct read_uac_work_data, dwork.work);
577 lcu = container_of(ruac_data, struct alias_lcu, ruac_data);
578 device = ruac_data->device;
579 rc = _lcu_update(device, lcu);
581 * Need to check flags again, as there could have been another
582 * prepare_update or a new device a new device while we were still
583 * processing the data
585 spin_lock_irqsave(&lcu->lock, flags);
586 if (rc || (lcu->flags & NEED_UAC_UPDATE)) {
587 DBF_DEV_EVENT(DBF_WARNING, device, "could not update"
588 " alias data in lcu (rc = %d), retry later", rc);
589 schedule_delayed_work(&lcu->ruac_data.dwork, 30*HZ);
591 lcu->ruac_data.device = NULL;
592 lcu->flags &= ~UPDATE_PENDING;
594 spin_unlock_irqrestore(&lcu->lock, flags);
597 static int _schedule_lcu_update(struct alias_lcu *lcu,
598 struct dasd_device *device)
600 struct dasd_device *usedev = NULL;
601 struct alias_pav_group *group;
603 lcu->flags |= NEED_UAC_UPDATE;
604 if (lcu->ruac_data.device) {
605 /* already scheduled or running */
608 if (device && !list_empty(&device->alias_list))
611 if (!usedev && !list_empty(&lcu->grouplist)) {
612 group = list_first_entry(&lcu->grouplist,
613 struct alias_pav_group, group);
614 if (!list_empty(&group->baselist))
615 usedev = list_first_entry(&group->baselist,
618 else if (!list_empty(&group->aliaslist))
619 usedev = list_first_entry(&group->aliaslist,
623 if (!usedev && !list_empty(&lcu->active_devices)) {
624 usedev = list_first_entry(&lcu->active_devices,
625 struct dasd_device, alias_list);
628 * if we haven't found a proper device yet, give up for now, the next
629 * device that will be set active will trigger an lcu update
633 lcu->ruac_data.device = usedev;
634 schedule_delayed_work(&lcu->ruac_data.dwork, 0);
638 int dasd_alias_add_device(struct dasd_device *device)
640 struct dasd_eckd_private *private;
641 struct alias_lcu *lcu;
645 private = (struct dasd_eckd_private *) device->private;
649 /* need to take cdev lock before lcu lock */
650 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
651 spin_lock(&lcu->lock);
652 if (!(lcu->flags & UPDATE_PENDING)) {
653 rc = _add_device_to_lcu(lcu, device, device);
655 lcu->flags |= UPDATE_PENDING;
657 if (lcu->flags & UPDATE_PENDING) {
658 list_move(&device->alias_list, &lcu->active_devices);
659 _schedule_lcu_update(lcu, device);
661 spin_unlock(&lcu->lock);
662 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
666 int dasd_alias_update_add_device(struct dasd_device *device)
668 struct dasd_eckd_private *private;
669 private = (struct dasd_eckd_private *) device->private;
670 private->lcu->flags |= UPDATE_PENDING;
671 return dasd_alias_add_device(device);
674 int dasd_alias_remove_device(struct dasd_device *device)
676 struct dasd_eckd_private *private;
677 struct alias_lcu *lcu;
680 private = (struct dasd_eckd_private *) device->private;
682 /* nothing to do if already removed */
685 spin_lock_irqsave(&lcu->lock, flags);
686 _remove_device_from_lcu(lcu, device);
687 spin_unlock_irqrestore(&lcu->lock, flags);
691 struct dasd_device *dasd_alias_get_start_dev(struct dasd_device *base_device)
694 struct dasd_device *alias_device;
695 struct alias_pav_group *group;
696 struct alias_lcu *lcu;
697 struct dasd_eckd_private *private, *alias_priv;
700 private = (struct dasd_eckd_private *) base_device->private;
701 group = private->pavgroup;
705 if (lcu->pav == NO_PAV ||
706 lcu->flags & (NEED_UAC_UPDATE | UPDATE_PENDING))
709 spin_lock_irqsave(&lcu->lock, flags);
710 alias_device = group->next;
712 if (list_empty(&group->aliaslist)) {
713 spin_unlock_irqrestore(&lcu->lock, flags);
716 alias_device = list_first_entry(&group->aliaslist,
721 if (list_is_last(&alias_device->alias_list, &group->aliaslist))
722 group->next = list_first_entry(&group->aliaslist,
723 struct dasd_device, alias_list);
725 group->next = list_first_entry(&alias_device->alias_list,
726 struct dasd_device, alias_list);
727 spin_unlock_irqrestore(&lcu->lock, flags);
728 alias_priv = (struct dasd_eckd_private *) alias_device->private;
729 if ((alias_priv->count < private->count) && !alias_device->stopped)
736 * Summary unit check handling depends on the way alias devices
737 * are handled so it is done here rather then in dasd_eckd.c
739 static int reset_summary_unit_check(struct alias_lcu *lcu,
740 struct dasd_device *device,
743 struct dasd_ccw_req *cqr;
748 strncpy((char *) &cqr->magic, "ECKD", 4);
749 ASCEBC((char *) &cqr->magic, 4);
751 ccw->cmd_code = DASD_ECKD_CCW_RSCK;
754 ccw->cda = (__u32)(addr_t) cqr->data;
755 ((char *)cqr->data)[0] = reason;
757 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
758 cqr->retries = 255; /* set retry counter to enable basic ERP */
759 cqr->startdev = device;
760 cqr->memdev = device;
762 cqr->expires = 5 * HZ;
763 cqr->buildclk = get_clock();
764 cqr->status = DASD_CQR_FILLED;
766 rc = dasd_sleep_on_immediatly(cqr);
770 static void _restart_all_base_devices_on_lcu(struct alias_lcu *lcu)
772 struct alias_pav_group *pavgroup;
773 struct dasd_device *device;
774 struct dasd_eckd_private *private;
777 /* active and inactive list can contain alias as well as base devices */
778 list_for_each_entry(device, &lcu->active_devices, alias_list) {
779 private = (struct dasd_eckd_private *) device->private;
780 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
781 if (private->uid.type != UA_BASE_DEVICE) {
782 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
786 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
787 dasd_schedule_block_bh(device->block);
788 dasd_schedule_device_bh(device);
790 list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
791 private = (struct dasd_eckd_private *) device->private;
792 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
793 if (private->uid.type != UA_BASE_DEVICE) {
794 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
798 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
799 dasd_schedule_block_bh(device->block);
800 dasd_schedule_device_bh(device);
802 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
803 list_for_each_entry(device, &pavgroup->baselist, alias_list) {
804 dasd_schedule_block_bh(device->block);
805 dasd_schedule_device_bh(device);
810 static void flush_all_alias_devices_on_lcu(struct alias_lcu *lcu)
812 struct alias_pav_group *pavgroup;
813 struct dasd_device *device, *temp;
814 struct dasd_eckd_private *private;
820 * Problem here ist that dasd_flush_device_queue may wait
821 * for termination of a request to complete. We can't keep
822 * the lcu lock during that time, so we must assume that
823 * the lists may have changed.
824 * Idea: first gather all active alias devices in a separate list,
825 * then flush the first element of this list unlocked, and afterwards
826 * check if it is still on the list before moving it to the
827 * active_devices list.
830 spin_lock_irqsave(&lcu->lock, flags);
831 list_for_each_entry_safe(device, temp, &lcu->active_devices,
833 private = (struct dasd_eckd_private *) device->private;
834 if (private->uid.type == UA_BASE_DEVICE)
836 list_move(&device->alias_list, &active);
839 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
840 list_splice_init(&pavgroup->aliaslist, &active);
842 while (!list_empty(&active)) {
843 device = list_first_entry(&active, struct dasd_device,
845 spin_unlock_irqrestore(&lcu->lock, flags);
846 rc = dasd_flush_device_queue(device);
847 spin_lock_irqsave(&lcu->lock, flags);
849 * only move device around if it wasn't moved away while we
850 * were waiting for the flush
852 if (device == list_first_entry(&active,
853 struct dasd_device, alias_list))
854 list_move(&device->alias_list, &lcu->active_devices);
856 spin_unlock_irqrestore(&lcu->lock, flags);
859 static void __stop_device_on_lcu(struct dasd_device *device,
860 struct dasd_device *pos)
862 /* If pos == device then device is already locked! */
864 dasd_device_set_stop_bits(pos, DASD_STOPPED_SU);
867 spin_lock(get_ccwdev_lock(pos->cdev));
868 dasd_device_set_stop_bits(pos, DASD_STOPPED_SU);
869 spin_unlock(get_ccwdev_lock(pos->cdev));
873 * This function is called in interrupt context, so the
874 * cdev lock for device is already locked!
876 static void _stop_all_devices_on_lcu(struct alias_lcu *lcu,
877 struct dasd_device *device)
879 struct alias_pav_group *pavgroup;
880 struct dasd_device *pos;
882 list_for_each_entry(pos, &lcu->active_devices, alias_list)
883 __stop_device_on_lcu(device, pos);
884 list_for_each_entry(pos, &lcu->inactive_devices, alias_list)
885 __stop_device_on_lcu(device, pos);
886 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
887 list_for_each_entry(pos, &pavgroup->baselist, alias_list)
888 __stop_device_on_lcu(device, pos);
889 list_for_each_entry(pos, &pavgroup->aliaslist, alias_list)
890 __stop_device_on_lcu(device, pos);
894 static void _unstop_all_devices_on_lcu(struct alias_lcu *lcu)
896 struct alias_pav_group *pavgroup;
897 struct dasd_device *device;
900 list_for_each_entry(device, &lcu->active_devices, alias_list) {
901 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
902 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
903 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
906 list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
907 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
908 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
909 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
912 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
913 list_for_each_entry(device, &pavgroup->baselist, alias_list) {
914 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
915 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
916 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
919 list_for_each_entry(device, &pavgroup->aliaslist, alias_list) {
920 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
921 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
922 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
928 static void summary_unit_check_handling_work(struct work_struct *work)
930 struct alias_lcu *lcu;
931 struct summary_unit_check_work_data *suc_data;
933 struct dasd_device *device;
935 suc_data = container_of(work, struct summary_unit_check_work_data,
937 lcu = container_of(suc_data, struct alias_lcu, suc_data);
938 device = suc_data->device;
940 /* 1. flush alias devices */
941 flush_all_alias_devices_on_lcu(lcu);
943 /* 2. reset summary unit check */
944 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
945 dasd_device_remove_stop_bits(device,
946 (DASD_STOPPED_SU | DASD_STOPPED_PENDING));
947 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
948 reset_summary_unit_check(lcu, device, suc_data->reason);
950 spin_lock_irqsave(&lcu->lock, flags);
951 _unstop_all_devices_on_lcu(lcu);
952 _restart_all_base_devices_on_lcu(lcu);
953 /* 3. read new alias configuration */
954 _schedule_lcu_update(lcu, device);
955 lcu->suc_data.device = NULL;
956 spin_unlock_irqrestore(&lcu->lock, flags);
960 * note: this will be called from int handler context (cdev locked)
962 void dasd_alias_handle_summary_unit_check(struct dasd_device *device,
965 struct alias_lcu *lcu;
967 struct dasd_eckd_private *private;
970 private = (struct dasd_eckd_private *) device->private;
972 sense = dasd_get_sense(irb);
975 DBF_DEV_EVENT(DBF_NOTICE, device, "%s %x",
976 "eckd handle summary unit check: reason", reason);
978 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
979 "eckd handle summary unit check:"
980 " no reason code available");
986 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
987 "device not ready to handle summary"
988 " unit check (no lcu structure)");
991 spin_lock(&lcu->lock);
992 _stop_all_devices_on_lcu(lcu, device);
993 /* prepare for lcu_update */
994 private->lcu->flags |= NEED_UAC_UPDATE | UPDATE_PENDING;
995 /* If this device is about to be removed just return and wait for
996 * the next interrupt on a different device
998 if (list_empty(&device->alias_list)) {
999 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1000 "device is in offline processing,"
1001 " don't do summary unit check handling");
1002 spin_unlock(&lcu->lock);
1005 if (lcu->suc_data.device) {
1006 /* already scheduled or running */
1007 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1008 "previous instance of summary unit check worker"
1010 spin_unlock(&lcu->lock);
1013 lcu->suc_data.reason = reason;
1014 lcu->suc_data.device = device;
1015 spin_unlock(&lcu->lock);
1016 schedule_work(&lcu->suc_data.worker);