2 * PAV alias management for the DASD ECKD discipline
4 * Copyright IBM Corp. 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;
194 private = (struct dasd_eckd_private *) device->private;
196 device->discipline->get_uid(device, &uid);
197 spin_lock_irqsave(&aliastree.lock, flags);
198 server = _find_server(&uid);
200 spin_unlock_irqrestore(&aliastree.lock, flags);
201 newserver = _allocate_server(&uid);
202 if (IS_ERR(newserver))
203 return PTR_ERR(newserver);
204 spin_lock_irqsave(&aliastree.lock, flags);
205 server = _find_server(&uid);
207 list_add(&newserver->server, &aliastree.serverlist);
210 /* someone was faster */
211 _free_server(newserver);
215 lcu = _find_lcu(server, &uid);
217 spin_unlock_irqrestore(&aliastree.lock, flags);
218 newlcu = _allocate_lcu(&uid);
220 return PTR_ERR(newlcu);
221 spin_lock_irqsave(&aliastree.lock, flags);
222 lcu = _find_lcu(server, &uid);
224 list_add(&newlcu->lcu, &server->lculist);
227 /* someone was faster */
231 spin_lock(&lcu->lock);
232 list_add(&device->alias_list, &lcu->inactive_devices);
234 spin_unlock(&lcu->lock);
235 spin_unlock_irqrestore(&aliastree.lock, flags);
241 * This function removes a device from the scope of alias management.
242 * The complicated part is to make sure that it is not in use by
243 * any of the workers. If necessary cancel the work.
245 void dasd_alias_disconnect_device_from_lcu(struct dasd_device *device)
247 struct dasd_eckd_private *private;
249 struct alias_lcu *lcu;
250 struct alias_server *server;
254 private = (struct dasd_eckd_private *) device->private;
256 /* nothing to do if already disconnected */
259 device->discipline->get_uid(device, &uid);
260 spin_lock_irqsave(&lcu->lock, flags);
261 list_del_init(&device->alias_list);
262 /* make sure that the workers don't use this device */
263 if (device == lcu->suc_data.device) {
264 spin_unlock_irqrestore(&lcu->lock, flags);
265 cancel_work_sync(&lcu->suc_data.worker);
266 spin_lock_irqsave(&lcu->lock, flags);
267 if (device == lcu->suc_data.device) {
268 dasd_put_device(device);
269 lcu->suc_data.device = NULL;
273 if (device == lcu->ruac_data.device) {
274 spin_unlock_irqrestore(&lcu->lock, flags);
276 cancel_delayed_work_sync(&lcu->ruac_data.dwork);
277 spin_lock_irqsave(&lcu->lock, flags);
278 if (device == lcu->ruac_data.device) {
279 dasd_put_device(device);
280 lcu->ruac_data.device = NULL;
284 spin_unlock_irqrestore(&lcu->lock, flags);
286 spin_lock_irqsave(&aliastree.lock, flags);
287 spin_lock(&lcu->lock);
288 if (list_empty(&lcu->grouplist) &&
289 list_empty(&lcu->active_devices) &&
290 list_empty(&lcu->inactive_devices)) {
292 spin_unlock(&lcu->lock);
297 _schedule_lcu_update(lcu, NULL);
298 spin_unlock(&lcu->lock);
300 server = _find_server(&uid);
301 if (server && list_empty(&server->lculist)) {
302 list_del(&server->server);
303 _free_server(server);
305 spin_unlock_irqrestore(&aliastree.lock, flags);
309 * This function assumes that the unit address configuration stored
310 * in the lcu is up to date and will update the device uid before
311 * adding it to a pav group.
314 static int _add_device_to_lcu(struct alias_lcu *lcu,
315 struct dasd_device *device,
316 struct dasd_device *pos)
319 struct dasd_eckd_private *private;
320 struct alias_pav_group *group;
324 private = (struct dasd_eckd_private *) device->private;
326 /* only lock if not already locked */
328 spin_lock_irqsave_nested(get_ccwdev_lock(device->cdev), flags,
330 private->uid.type = lcu->uac->unit[private->uid.real_unit_addr].ua_type;
331 private->uid.base_unit_addr =
332 lcu->uac->unit[private->uid.real_unit_addr].base_ua;
336 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
338 /* if we have no PAV anyway, we don't need to bother with PAV groups */
339 if (lcu->pav == NO_PAV) {
340 list_move(&device->alias_list, &lcu->active_devices);
344 group = _find_group(lcu, &uid);
346 group = kzalloc(sizeof(*group), GFP_ATOMIC);
349 memcpy(group->uid.vendor, uid.vendor, sizeof(uid.vendor));
350 memcpy(group->uid.serial, uid.serial, sizeof(uid.serial));
351 group->uid.ssid = uid.ssid;
352 if (uid.type == UA_BASE_DEVICE)
353 group->uid.base_unit_addr = uid.real_unit_addr;
355 group->uid.base_unit_addr = uid.base_unit_addr;
356 memcpy(group->uid.vduit, uid.vduit, sizeof(uid.vduit));
357 INIT_LIST_HEAD(&group->group);
358 INIT_LIST_HEAD(&group->baselist);
359 INIT_LIST_HEAD(&group->aliaslist);
360 list_add(&group->group, &lcu->grouplist);
362 if (uid.type == UA_BASE_DEVICE)
363 list_move(&device->alias_list, &group->baselist);
365 list_move(&device->alias_list, &group->aliaslist);
366 private->pavgroup = group;
370 static void _remove_device_from_lcu(struct alias_lcu *lcu,
371 struct dasd_device *device)
373 struct dasd_eckd_private *private;
374 struct alias_pav_group *group;
376 private = (struct dasd_eckd_private *) device->private;
377 list_move(&device->alias_list, &lcu->inactive_devices);
378 group = private->pavgroup;
381 private->pavgroup = NULL;
382 if (list_empty(&group->baselist) && list_empty(&group->aliaslist)) {
383 list_del(&group->group);
387 if (group->next == device)
392 suborder_not_supported(struct dasd_ccw_req *cqr)
399 sense = dasd_get_sense(&cqr->irb);
404 msg_format = (sense[7] & 0xF0);
405 msg_no = (sense[7] & 0x0F);
407 /* command reject, Format 0 MSG 4 - invalid parameter */
408 if ((reason == 0x80) && (msg_format == 0x00) && (msg_no == 0x04))
414 static int read_unit_address_configuration(struct dasd_device *device,
415 struct alias_lcu *lcu)
417 struct dasd_psf_prssd_data *prssdp;
418 struct dasd_ccw_req *cqr;
423 cqr = dasd_kmalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
424 (sizeof(struct dasd_psf_prssd_data)),
428 cqr->startdev = device;
429 cqr->memdev = device;
430 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
432 cqr->expires = 20 * HZ;
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 */
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;
447 /* Read Subsystem Data - feature codes */
448 memset(lcu->uac, 0, sizeof(*(lcu->uac)));
451 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
452 ccw->count = sizeof(*(lcu->uac));
453 ccw->cda = (__u32)(addr_t) lcu->uac;
455 cqr->buildclk = get_tod_clock();
456 cqr->status = DASD_CQR_FILLED;
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);
464 rc = dasd_sleep_on(cqr);
465 if (rc && suborder_not_supported(cqr))
467 } while (rc && (cqr->retries > 0));
469 spin_lock_irqsave(&lcu->lock, flags);
470 lcu->flags |= NEED_UAC_UPDATE;
471 spin_unlock_irqrestore(&lcu->lock, flags);
473 dasd_kfree_request(cqr, cqr->memdev);
477 static int _lcu_update(struct dasd_device *refdev, struct alias_lcu *lcu)
480 struct alias_pav_group *pavgroup, *tempgroup;
481 struct dasd_device *device, *tempdev;
483 struct dasd_eckd_private *private;
485 spin_lock_irqsave(&lcu->lock, flags);
486 list_for_each_entry_safe(pavgroup, tempgroup, &lcu->grouplist, group) {
487 list_for_each_entry_safe(device, tempdev, &pavgroup->baselist,
489 list_move(&device->alias_list, &lcu->active_devices);
490 private = (struct dasd_eckd_private *) device->private;
491 private->pavgroup = NULL;
493 list_for_each_entry_safe(device, tempdev, &pavgroup->aliaslist,
495 list_move(&device->alias_list, &lcu->active_devices);
496 private = (struct dasd_eckd_private *) device->private;
497 private->pavgroup = NULL;
499 list_del(&pavgroup->group);
502 spin_unlock_irqrestore(&lcu->lock, flags);
504 rc = read_unit_address_configuration(refdev, lcu);
508 /* need to take cdev lock before lcu lock */
509 spin_lock_irqsave_nested(get_ccwdev_lock(refdev->cdev), flags,
511 spin_lock(&lcu->lock);
513 for (i = 0; i < MAX_DEVICES_PER_LCU; ++i) {
514 switch (lcu->uac->unit[i].ua_type) {
515 case UA_BASE_PAV_ALIAS:
518 case UA_HYPER_PAV_ALIAS:
519 lcu->pav = HYPER_PAV;
522 if (lcu->pav != NO_PAV)
526 list_for_each_entry_safe(device, tempdev, &lcu->active_devices,
528 _add_device_to_lcu(lcu, device, refdev);
530 spin_unlock(&lcu->lock);
531 spin_unlock_irqrestore(get_ccwdev_lock(refdev->cdev), flags);
535 static void lcu_update_work(struct work_struct *work)
537 struct alias_lcu *lcu;
538 struct read_uac_work_data *ruac_data;
539 struct dasd_device *device;
543 ruac_data = container_of(work, struct read_uac_work_data, dwork.work);
544 lcu = container_of(ruac_data, struct alias_lcu, ruac_data);
545 device = ruac_data->device;
546 rc = _lcu_update(device, lcu);
548 * Need to check flags again, as there could have been another
549 * prepare_update or a new device a new device while we were still
550 * processing the data
552 spin_lock_irqsave(&lcu->lock, flags);
553 if ((rc && (rc != -EOPNOTSUPP)) || (lcu->flags & NEED_UAC_UPDATE)) {
554 DBF_DEV_EVENT(DBF_WARNING, device, "could not update"
555 " alias data in lcu (rc = %d), retry later", rc);
556 if (!schedule_delayed_work(&lcu->ruac_data.dwork, 30*HZ))
557 dasd_put_device(device);
559 dasd_put_device(device);
560 lcu->ruac_data.device = NULL;
561 lcu->flags &= ~UPDATE_PENDING;
563 spin_unlock_irqrestore(&lcu->lock, flags);
566 static int _schedule_lcu_update(struct alias_lcu *lcu,
567 struct dasd_device *device)
569 struct dasd_device *usedev = NULL;
570 struct alias_pav_group *group;
572 lcu->flags |= NEED_UAC_UPDATE;
573 if (lcu->ruac_data.device) {
574 /* already scheduled or running */
577 if (device && !list_empty(&device->alias_list))
580 if (!usedev && !list_empty(&lcu->grouplist)) {
581 group = list_first_entry(&lcu->grouplist,
582 struct alias_pav_group, group);
583 if (!list_empty(&group->baselist))
584 usedev = list_first_entry(&group->baselist,
587 else if (!list_empty(&group->aliaslist))
588 usedev = list_first_entry(&group->aliaslist,
592 if (!usedev && !list_empty(&lcu->active_devices)) {
593 usedev = list_first_entry(&lcu->active_devices,
594 struct dasd_device, alias_list);
597 * if we haven't found a proper device yet, give up for now, the next
598 * device that will be set active will trigger an lcu update
602 dasd_get_device(usedev);
603 lcu->ruac_data.device = usedev;
604 if (!schedule_delayed_work(&lcu->ruac_data.dwork, 0))
605 dasd_put_device(usedev);
609 int dasd_alias_add_device(struct dasd_device *device)
611 struct dasd_eckd_private *private;
612 struct alias_lcu *lcu;
616 private = (struct dasd_eckd_private *) device->private;
620 /* need to take cdev lock before lcu lock */
621 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
622 spin_lock(&lcu->lock);
623 if (!(lcu->flags & UPDATE_PENDING)) {
624 rc = _add_device_to_lcu(lcu, device, device);
626 lcu->flags |= UPDATE_PENDING;
628 if (lcu->flags & UPDATE_PENDING) {
629 list_move(&device->alias_list, &lcu->active_devices);
630 _schedule_lcu_update(lcu, device);
632 spin_unlock(&lcu->lock);
633 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
637 int dasd_alias_update_add_device(struct dasd_device *device)
639 struct dasd_eckd_private *private;
640 private = (struct dasd_eckd_private *) device->private;
641 private->lcu->flags |= UPDATE_PENDING;
642 return dasd_alias_add_device(device);
645 int dasd_alias_remove_device(struct dasd_device *device)
647 struct dasd_eckd_private *private;
648 struct alias_lcu *lcu;
651 private = (struct dasd_eckd_private *) device->private;
653 /* nothing to do if already removed */
656 spin_lock_irqsave(&lcu->lock, flags);
657 _remove_device_from_lcu(lcu, device);
658 spin_unlock_irqrestore(&lcu->lock, flags);
662 struct dasd_device *dasd_alias_get_start_dev(struct dasd_device *base_device)
665 struct dasd_device *alias_device;
666 struct alias_pav_group *group;
667 struct alias_lcu *lcu;
668 struct dasd_eckd_private *private, *alias_priv;
671 private = (struct dasd_eckd_private *) base_device->private;
672 group = private->pavgroup;
676 if (lcu->pav == NO_PAV ||
677 lcu->flags & (NEED_UAC_UPDATE | UPDATE_PENDING))
679 if (unlikely(!(private->features.feature[8] & 0x01))) {
681 * PAV enabled but prefix not, very unlikely
682 * seems to be a lost pathgroup
683 * use base device to do IO
685 DBF_DEV_EVENT(DBF_ERR, base_device, "%s",
686 "Prefix not enabled with PAV enabled\n");
690 spin_lock_irqsave(&lcu->lock, flags);
691 alias_device = group->next;
693 if (list_empty(&group->aliaslist)) {
694 spin_unlock_irqrestore(&lcu->lock, flags);
697 alias_device = list_first_entry(&group->aliaslist,
702 if (list_is_last(&alias_device->alias_list, &group->aliaslist))
703 group->next = list_first_entry(&group->aliaslist,
704 struct dasd_device, alias_list);
706 group->next = list_first_entry(&alias_device->alias_list,
707 struct dasd_device, alias_list);
708 spin_unlock_irqrestore(&lcu->lock, flags);
709 alias_priv = (struct dasd_eckd_private *) alias_device->private;
710 if ((alias_priv->count < private->count) && !alias_device->stopped &&
711 !test_bit(DASD_FLAG_OFFLINE, &alias_device->flags))
718 * Summary unit check handling depends on the way alias devices
719 * are handled so it is done here rather then in dasd_eckd.c
721 static int reset_summary_unit_check(struct alias_lcu *lcu,
722 struct dasd_device *device,
725 struct dasd_ccw_req *cqr;
730 strncpy((char *) &cqr->magic, "ECKD", 4);
731 ASCEBC((char *) &cqr->magic, 4);
733 ccw->cmd_code = DASD_ECKD_CCW_RSCK;
734 ccw->flags = CCW_FLAG_SLI;
736 ccw->cda = (__u32)(addr_t) cqr->data;
737 ((char *)cqr->data)[0] = reason;
739 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
740 cqr->retries = 255; /* set retry counter to enable basic ERP */
741 cqr->startdev = device;
742 cqr->memdev = device;
744 cqr->expires = 5 * HZ;
745 cqr->buildclk = get_tod_clock();
746 cqr->status = DASD_CQR_FILLED;
748 rc = dasd_sleep_on_immediatly(cqr);
752 static void _restart_all_base_devices_on_lcu(struct alias_lcu *lcu)
754 struct alias_pav_group *pavgroup;
755 struct dasd_device *device;
756 struct dasd_eckd_private *private;
759 /* active and inactive list can contain alias as well as base devices */
760 list_for_each_entry(device, &lcu->active_devices, alias_list) {
761 private = (struct dasd_eckd_private *) device->private;
762 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
763 if (private->uid.type != UA_BASE_DEVICE) {
764 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
768 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
769 dasd_schedule_block_bh(device->block);
770 dasd_schedule_device_bh(device);
772 list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
773 private = (struct dasd_eckd_private *) device->private;
774 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
775 if (private->uid.type != UA_BASE_DEVICE) {
776 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
780 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
781 dasd_schedule_block_bh(device->block);
782 dasd_schedule_device_bh(device);
784 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
785 list_for_each_entry(device, &pavgroup->baselist, alias_list) {
786 dasd_schedule_block_bh(device->block);
787 dasd_schedule_device_bh(device);
792 static void flush_all_alias_devices_on_lcu(struct alias_lcu *lcu)
794 struct alias_pav_group *pavgroup;
795 struct dasd_device *device, *temp;
796 struct dasd_eckd_private *private;
802 * Problem here ist that dasd_flush_device_queue may wait
803 * for termination of a request to complete. We can't keep
804 * the lcu lock during that time, so we must assume that
805 * the lists may have changed.
806 * Idea: first gather all active alias devices in a separate list,
807 * then flush the first element of this list unlocked, and afterwards
808 * check if it is still on the list before moving it to the
809 * active_devices list.
812 spin_lock_irqsave(&lcu->lock, flags);
813 list_for_each_entry_safe(device, temp, &lcu->active_devices,
815 private = (struct dasd_eckd_private *) device->private;
816 if (private->uid.type == UA_BASE_DEVICE)
818 list_move(&device->alias_list, &active);
821 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
822 list_splice_init(&pavgroup->aliaslist, &active);
824 while (!list_empty(&active)) {
825 device = list_first_entry(&active, struct dasd_device,
827 spin_unlock_irqrestore(&lcu->lock, flags);
828 rc = dasd_flush_device_queue(device);
829 spin_lock_irqsave(&lcu->lock, flags);
831 * only move device around if it wasn't moved away while we
832 * were waiting for the flush
834 if (device == list_first_entry(&active,
835 struct dasd_device, alias_list)) {
836 list_move(&device->alias_list, &lcu->active_devices);
837 private = (struct dasd_eckd_private *) device->private;
838 private->pavgroup = NULL;
841 spin_unlock_irqrestore(&lcu->lock, flags);
844 static void __stop_device_on_lcu(struct dasd_device *device,
845 struct dasd_device *pos)
847 /* If pos == device then device is already locked! */
849 dasd_device_set_stop_bits(pos, DASD_STOPPED_SU);
852 spin_lock(get_ccwdev_lock(pos->cdev));
853 dasd_device_set_stop_bits(pos, DASD_STOPPED_SU);
854 spin_unlock(get_ccwdev_lock(pos->cdev));
858 * This function is called in interrupt context, so the
859 * cdev lock for device is already locked!
861 static void _stop_all_devices_on_lcu(struct alias_lcu *lcu,
862 struct dasd_device *device)
864 struct alias_pav_group *pavgroup;
865 struct dasd_device *pos;
867 list_for_each_entry(pos, &lcu->active_devices, alias_list)
868 __stop_device_on_lcu(device, pos);
869 list_for_each_entry(pos, &lcu->inactive_devices, alias_list)
870 __stop_device_on_lcu(device, pos);
871 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
872 list_for_each_entry(pos, &pavgroup->baselist, alias_list)
873 __stop_device_on_lcu(device, pos);
874 list_for_each_entry(pos, &pavgroup->aliaslist, alias_list)
875 __stop_device_on_lcu(device, pos);
879 static void _unstop_all_devices_on_lcu(struct alias_lcu *lcu)
881 struct alias_pav_group *pavgroup;
882 struct dasd_device *device;
885 list_for_each_entry(device, &lcu->active_devices, alias_list) {
886 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
887 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
888 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
891 list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
892 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
893 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
894 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
897 list_for_each_entry(pavgroup, &lcu->grouplist, group) {
898 list_for_each_entry(device, &pavgroup->baselist, alias_list) {
899 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
900 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
901 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
904 list_for_each_entry(device, &pavgroup->aliaslist, alias_list) {
905 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
906 dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
907 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
913 static void summary_unit_check_handling_work(struct work_struct *work)
915 struct alias_lcu *lcu;
916 struct summary_unit_check_work_data *suc_data;
918 struct dasd_device *device;
920 suc_data = container_of(work, struct summary_unit_check_work_data,
922 lcu = container_of(suc_data, struct alias_lcu, suc_data);
923 device = suc_data->device;
925 /* 1. flush alias devices */
926 flush_all_alias_devices_on_lcu(lcu);
928 /* 2. reset summary unit check */
929 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
930 dasd_device_remove_stop_bits(device,
931 (DASD_STOPPED_SU | DASD_STOPPED_PENDING));
932 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
933 reset_summary_unit_check(lcu, device, suc_data->reason);
935 spin_lock_irqsave(&lcu->lock, flags);
936 _unstop_all_devices_on_lcu(lcu);
937 _restart_all_base_devices_on_lcu(lcu);
938 /* 3. read new alias configuration */
939 _schedule_lcu_update(lcu, device);
940 lcu->suc_data.device = NULL;
941 dasd_put_device(device);
942 spin_unlock_irqrestore(&lcu->lock, flags);
946 * note: this will be called from int handler context (cdev locked)
948 void dasd_alias_handle_summary_unit_check(struct dasd_device *device,
951 struct alias_lcu *lcu;
953 struct dasd_eckd_private *private;
956 private = (struct dasd_eckd_private *) device->private;
958 sense = dasd_get_sense(irb);
961 DBF_DEV_EVENT(DBF_NOTICE, device, "%s %x",
962 "eckd handle summary unit check: reason", reason);
964 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
965 "eckd handle summary unit check:"
966 " no reason code available");
972 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
973 "device not ready to handle summary"
974 " unit check (no lcu structure)");
977 spin_lock(&lcu->lock);
978 _stop_all_devices_on_lcu(lcu, device);
979 /* prepare for lcu_update */
980 private->lcu->flags |= NEED_UAC_UPDATE | UPDATE_PENDING;
981 /* If this device is about to be removed just return and wait for
982 * the next interrupt on a different device
984 if (list_empty(&device->alias_list)) {
985 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
986 "device is in offline processing,"
987 " don't do summary unit check handling");
988 spin_unlock(&lcu->lock);
991 if (lcu->suc_data.device) {
992 /* already scheduled or running */
993 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
994 "previous instance of summary unit check worker"
996 spin_unlock(&lcu->lock);
999 lcu->suc_data.reason = reason;
1000 lcu->suc_data.device = device;
1001 dasd_get_device(device);
1002 spin_unlock(&lcu->lock);
1003 if (!schedule_work(&lcu->suc_data.worker))
1004 dasd_put_device(device);