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 lcu
->suc_data
.device
= NULL
;
271 if (device
== lcu
->ruac_data
.device
) {
272 spin_unlock_irqrestore(&lcu
->lock
, flags
);
274 cancel_delayed_work_sync(&lcu
->ruac_data
.dwork
);
275 spin_lock_irqsave(&lcu
->lock
, flags
);
276 if (device
== lcu
->ruac_data
.device
)
277 lcu
->ruac_data
.device
= NULL
;
280 spin_unlock_irqrestore(&lcu
->lock
, flags
);
282 spin_lock_irqsave(&aliastree
.lock
, flags
);
283 spin_lock(&lcu
->lock
);
284 if (list_empty(&lcu
->grouplist
) &&
285 list_empty(&lcu
->active_devices
) &&
286 list_empty(&lcu
->inactive_devices
)) {
288 spin_unlock(&lcu
->lock
);
293 _schedule_lcu_update(lcu
, NULL
);
294 spin_unlock(&lcu
->lock
);
296 server
= _find_server(&uid
);
297 if (server
&& list_empty(&server
->lculist
)) {
298 list_del(&server
->server
);
299 _free_server(server
);
301 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
305 * This function assumes that the unit address configuration stored
306 * in the lcu is up to date and will update the device uid before
307 * adding it to a pav group.
310 static int _add_device_to_lcu(struct alias_lcu
*lcu
,
311 struct dasd_device
*device
,
312 struct dasd_device
*pos
)
315 struct dasd_eckd_private
*private;
316 struct alias_pav_group
*group
;
320 private = (struct dasd_eckd_private
*) device
->private;
322 /* only lock if not already locked */
324 spin_lock_irqsave_nested(get_ccwdev_lock(device
->cdev
), flags
,
326 private->uid
.type
= lcu
->uac
->unit
[private->uid
.real_unit_addr
].ua_type
;
327 private->uid
.base_unit_addr
=
328 lcu
->uac
->unit
[private->uid
.real_unit_addr
].base_ua
;
332 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
334 /* if we have no PAV anyway, we don't need to bother with PAV groups */
335 if (lcu
->pav
== NO_PAV
) {
336 list_move(&device
->alias_list
, &lcu
->active_devices
);
340 group
= _find_group(lcu
, &uid
);
342 group
= kzalloc(sizeof(*group
), GFP_ATOMIC
);
345 memcpy(group
->uid
.vendor
, uid
.vendor
, sizeof(uid
.vendor
));
346 memcpy(group
->uid
.serial
, uid
.serial
, sizeof(uid
.serial
));
347 group
->uid
.ssid
= uid
.ssid
;
348 if (uid
.type
== UA_BASE_DEVICE
)
349 group
->uid
.base_unit_addr
= uid
.real_unit_addr
;
351 group
->uid
.base_unit_addr
= uid
.base_unit_addr
;
352 memcpy(group
->uid
.vduit
, uid
.vduit
, sizeof(uid
.vduit
));
353 INIT_LIST_HEAD(&group
->group
);
354 INIT_LIST_HEAD(&group
->baselist
);
355 INIT_LIST_HEAD(&group
->aliaslist
);
356 list_add(&group
->group
, &lcu
->grouplist
);
358 if (uid
.type
== UA_BASE_DEVICE
)
359 list_move(&device
->alias_list
, &group
->baselist
);
361 list_move(&device
->alias_list
, &group
->aliaslist
);
362 private->pavgroup
= group
;
366 static void _remove_device_from_lcu(struct alias_lcu
*lcu
,
367 struct dasd_device
*device
)
369 struct dasd_eckd_private
*private;
370 struct alias_pav_group
*group
;
372 private = (struct dasd_eckd_private
*) device
->private;
373 list_move(&device
->alias_list
, &lcu
->inactive_devices
);
374 group
= private->pavgroup
;
377 private->pavgroup
= NULL
;
378 if (list_empty(&group
->baselist
) && list_empty(&group
->aliaslist
)) {
379 list_del(&group
->group
);
383 if (group
->next
== device
)
388 suborder_not_supported(struct dasd_ccw_req
*cqr
)
395 sense
= dasd_get_sense(&cqr
->irb
);
400 msg_format
= (sense
[7] & 0xF0);
401 msg_no
= (sense
[7] & 0x0F);
403 /* command reject, Format 0 MSG 4 - invalid parameter */
404 if ((reason
== 0x80) && (msg_format
== 0x00) && (msg_no
== 0x04))
410 static int read_unit_address_configuration(struct dasd_device
*device
,
411 struct alias_lcu
*lcu
)
413 struct dasd_psf_prssd_data
*prssdp
;
414 struct dasd_ccw_req
*cqr
;
419 cqr
= dasd_kmalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
420 (sizeof(struct dasd_psf_prssd_data
)),
424 cqr
->startdev
= device
;
425 cqr
->memdev
= device
;
426 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
428 cqr
->expires
= 20 * HZ
;
430 /* Prepare for Read Subsystem Data */
431 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
432 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
433 prssdp
->order
= PSF_ORDER_PRSSD
;
434 prssdp
->suborder
= 0x0e; /* Read unit address configuration */
435 /* all other bytes of prssdp must be zero */
438 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
439 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
440 ccw
->flags
|= CCW_FLAG_CC
;
441 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
443 /* Read Subsystem Data - feature codes */
444 memset(lcu
->uac
, 0, sizeof(*(lcu
->uac
)));
447 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
448 ccw
->count
= sizeof(*(lcu
->uac
));
449 ccw
->cda
= (__u32
)(addr_t
) lcu
->uac
;
451 cqr
->buildclk
= get_tod_clock();
452 cqr
->status
= DASD_CQR_FILLED
;
454 /* need to unset flag here to detect race with summary unit check */
455 spin_lock_irqsave(&lcu
->lock
, flags
);
456 lcu
->flags
&= ~NEED_UAC_UPDATE
;
457 spin_unlock_irqrestore(&lcu
->lock
, flags
);
460 rc
= dasd_sleep_on(cqr
);
461 if (rc
&& suborder_not_supported(cqr
))
463 } while (rc
&& (cqr
->retries
> 0));
465 spin_lock_irqsave(&lcu
->lock
, flags
);
466 lcu
->flags
|= NEED_UAC_UPDATE
;
467 spin_unlock_irqrestore(&lcu
->lock
, flags
);
469 dasd_kfree_request(cqr
, cqr
->memdev
);
473 static int _lcu_update(struct dasd_device
*refdev
, struct alias_lcu
*lcu
)
476 struct alias_pav_group
*pavgroup
, *tempgroup
;
477 struct dasd_device
*device
, *tempdev
;
479 struct dasd_eckd_private
*private;
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
,
485 list_move(&device
->alias_list
, &lcu
->active_devices
);
486 private = (struct dasd_eckd_private
*) device
->private;
487 private->pavgroup
= NULL
;
489 list_for_each_entry_safe(device
, tempdev
, &pavgroup
->aliaslist
,
491 list_move(&device
->alias_list
, &lcu
->active_devices
);
492 private = (struct dasd_eckd_private
*) device
->private;
493 private->pavgroup
= NULL
;
495 list_del(&pavgroup
->group
);
498 spin_unlock_irqrestore(&lcu
->lock
, flags
);
500 rc
= read_unit_address_configuration(refdev
, lcu
);
504 /* need to take cdev lock before lcu lock */
505 spin_lock_irqsave_nested(get_ccwdev_lock(refdev
->cdev
), flags
,
507 spin_lock(&lcu
->lock
);
509 for (i
= 0; i
< MAX_DEVICES_PER_LCU
; ++i
) {
510 switch (lcu
->uac
->unit
[i
].ua_type
) {
511 case UA_BASE_PAV_ALIAS
:
514 case UA_HYPER_PAV_ALIAS
:
515 lcu
->pav
= HYPER_PAV
;
518 if (lcu
->pav
!= NO_PAV
)
522 list_for_each_entry_safe(device
, tempdev
, &lcu
->active_devices
,
524 _add_device_to_lcu(lcu
, device
, refdev
);
526 spin_unlock(&lcu
->lock
);
527 spin_unlock_irqrestore(get_ccwdev_lock(refdev
->cdev
), flags
);
531 static void lcu_update_work(struct work_struct
*work
)
533 struct alias_lcu
*lcu
;
534 struct read_uac_work_data
*ruac_data
;
535 struct dasd_device
*device
;
539 ruac_data
= container_of(work
, struct read_uac_work_data
, dwork
.work
);
540 lcu
= container_of(ruac_data
, struct alias_lcu
, ruac_data
);
541 device
= ruac_data
->device
;
542 rc
= _lcu_update(device
, lcu
);
544 * Need to check flags again, as there could have been another
545 * prepare_update or a new device a new device while we were still
546 * processing the data
548 spin_lock_irqsave(&lcu
->lock
, flags
);
549 if ((rc
&& (rc
!= -EOPNOTSUPP
)) || (lcu
->flags
& NEED_UAC_UPDATE
)) {
550 DBF_DEV_EVENT(DBF_WARNING
, device
, "could not update"
551 " alias data in lcu (rc = %d), retry later", rc
);
552 schedule_delayed_work(&lcu
->ruac_data
.dwork
, 30*HZ
);
554 lcu
->ruac_data
.device
= NULL
;
555 lcu
->flags
&= ~UPDATE_PENDING
;
557 spin_unlock_irqrestore(&lcu
->lock
, flags
);
560 static int _schedule_lcu_update(struct alias_lcu
*lcu
,
561 struct dasd_device
*device
)
563 struct dasd_device
*usedev
= NULL
;
564 struct alias_pav_group
*group
;
566 lcu
->flags
|= NEED_UAC_UPDATE
;
567 if (lcu
->ruac_data
.device
) {
568 /* already scheduled or running */
571 if (device
&& !list_empty(&device
->alias_list
))
574 if (!usedev
&& !list_empty(&lcu
->grouplist
)) {
575 group
= list_first_entry(&lcu
->grouplist
,
576 struct alias_pav_group
, group
);
577 if (!list_empty(&group
->baselist
))
578 usedev
= list_first_entry(&group
->baselist
,
581 else if (!list_empty(&group
->aliaslist
))
582 usedev
= list_first_entry(&group
->aliaslist
,
586 if (!usedev
&& !list_empty(&lcu
->active_devices
)) {
587 usedev
= list_first_entry(&lcu
->active_devices
,
588 struct dasd_device
, alias_list
);
591 * if we haven't found a proper device yet, give up for now, the next
592 * device that will be set active will trigger an lcu update
596 lcu
->ruac_data
.device
= usedev
;
597 schedule_delayed_work(&lcu
->ruac_data
.dwork
, 0);
601 int dasd_alias_add_device(struct dasd_device
*device
)
603 struct dasd_eckd_private
*private;
604 struct alias_lcu
*lcu
;
608 private = (struct dasd_eckd_private
*) device
->private;
612 /* need to take cdev lock before lcu lock */
613 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
614 spin_lock(&lcu
->lock
);
615 if (!(lcu
->flags
& UPDATE_PENDING
)) {
616 rc
= _add_device_to_lcu(lcu
, device
, device
);
618 lcu
->flags
|= UPDATE_PENDING
;
620 if (lcu
->flags
& UPDATE_PENDING
) {
621 list_move(&device
->alias_list
, &lcu
->active_devices
);
622 _schedule_lcu_update(lcu
, device
);
624 spin_unlock(&lcu
->lock
);
625 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
629 int dasd_alias_update_add_device(struct dasd_device
*device
)
631 struct dasd_eckd_private
*private;
632 private = (struct dasd_eckd_private
*) device
->private;
633 private->lcu
->flags
|= UPDATE_PENDING
;
634 return dasd_alias_add_device(device
);
637 int dasd_alias_remove_device(struct dasd_device
*device
)
639 struct dasd_eckd_private
*private;
640 struct alias_lcu
*lcu
;
643 private = (struct dasd_eckd_private
*) device
->private;
645 /* nothing to do if already removed */
648 spin_lock_irqsave(&lcu
->lock
, flags
);
649 _remove_device_from_lcu(lcu
, device
);
650 spin_unlock_irqrestore(&lcu
->lock
, flags
);
654 struct dasd_device
*dasd_alias_get_start_dev(struct dasd_device
*base_device
)
657 struct dasd_device
*alias_device
;
658 struct alias_pav_group
*group
;
659 struct alias_lcu
*lcu
;
660 struct dasd_eckd_private
*private, *alias_priv
;
663 private = (struct dasd_eckd_private
*) base_device
->private;
664 group
= private->pavgroup
;
668 if (lcu
->pav
== NO_PAV
||
669 lcu
->flags
& (NEED_UAC_UPDATE
| UPDATE_PENDING
))
671 if (unlikely(!(private->features
.feature
[8] & 0x01))) {
673 * PAV enabled but prefix not, very unlikely
674 * seems to be a lost pathgroup
675 * use base device to do IO
677 DBF_DEV_EVENT(DBF_ERR
, base_device
, "%s",
678 "Prefix not enabled with PAV enabled\n");
682 spin_lock_irqsave(&lcu
->lock
, flags
);
683 alias_device
= group
->next
;
685 if (list_empty(&group
->aliaslist
)) {
686 spin_unlock_irqrestore(&lcu
->lock
, flags
);
689 alias_device
= list_first_entry(&group
->aliaslist
,
694 if (list_is_last(&alias_device
->alias_list
, &group
->aliaslist
))
695 group
->next
= list_first_entry(&group
->aliaslist
,
696 struct dasd_device
, alias_list
);
698 group
->next
= list_first_entry(&alias_device
->alias_list
,
699 struct dasd_device
, alias_list
);
700 spin_unlock_irqrestore(&lcu
->lock
, flags
);
701 alias_priv
= (struct dasd_eckd_private
*) alias_device
->private;
702 if ((alias_priv
->count
< private->count
) && !alias_device
->stopped
)
709 * Summary unit check handling depends on the way alias devices
710 * are handled so it is done here rather then in dasd_eckd.c
712 static int reset_summary_unit_check(struct alias_lcu
*lcu
,
713 struct dasd_device
*device
,
716 struct dasd_ccw_req
*cqr
;
721 strncpy((char *) &cqr
->magic
, "ECKD", 4);
722 ASCEBC((char *) &cqr
->magic
, 4);
724 ccw
->cmd_code
= DASD_ECKD_CCW_RSCK
;
727 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
728 ((char *)cqr
->data
)[0] = reason
;
730 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
731 cqr
->retries
= 255; /* set retry counter to enable basic ERP */
732 cqr
->startdev
= device
;
733 cqr
->memdev
= device
;
735 cqr
->expires
= 5 * HZ
;
736 cqr
->buildclk
= get_tod_clock();
737 cqr
->status
= DASD_CQR_FILLED
;
739 rc
= dasd_sleep_on_immediatly(cqr
);
743 static void _restart_all_base_devices_on_lcu(struct alias_lcu
*lcu
)
745 struct alias_pav_group
*pavgroup
;
746 struct dasd_device
*device
;
747 struct dasd_eckd_private
*private;
750 /* active and inactive list can contain alias as well as base devices */
751 list_for_each_entry(device
, &lcu
->active_devices
, alias_list
) {
752 private = (struct dasd_eckd_private
*) device
->private;
753 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
754 if (private->uid
.type
!= UA_BASE_DEVICE
) {
755 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
),
759 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
760 dasd_schedule_block_bh(device
->block
);
761 dasd_schedule_device_bh(device
);
763 list_for_each_entry(device
, &lcu
->inactive_devices
, alias_list
) {
764 private = (struct dasd_eckd_private
*) device
->private;
765 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
766 if (private->uid
.type
!= UA_BASE_DEVICE
) {
767 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
),
771 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
772 dasd_schedule_block_bh(device
->block
);
773 dasd_schedule_device_bh(device
);
775 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
776 list_for_each_entry(device
, &pavgroup
->baselist
, alias_list
) {
777 dasd_schedule_block_bh(device
->block
);
778 dasd_schedule_device_bh(device
);
783 static void flush_all_alias_devices_on_lcu(struct alias_lcu
*lcu
)
785 struct alias_pav_group
*pavgroup
;
786 struct dasd_device
*device
, *temp
;
787 struct dasd_eckd_private
*private;
793 * Problem here ist that dasd_flush_device_queue may wait
794 * for termination of a request to complete. We can't keep
795 * the lcu lock during that time, so we must assume that
796 * the lists may have changed.
797 * Idea: first gather all active alias devices in a separate list,
798 * then flush the first element of this list unlocked, and afterwards
799 * check if it is still on the list before moving it to the
800 * active_devices list.
803 spin_lock_irqsave(&lcu
->lock
, flags
);
804 list_for_each_entry_safe(device
, temp
, &lcu
->active_devices
,
806 private = (struct dasd_eckd_private
*) device
->private;
807 if (private->uid
.type
== UA_BASE_DEVICE
)
809 list_move(&device
->alias_list
, &active
);
812 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
813 list_splice_init(&pavgroup
->aliaslist
, &active
);
815 while (!list_empty(&active
)) {
816 device
= list_first_entry(&active
, struct dasd_device
,
818 spin_unlock_irqrestore(&lcu
->lock
, flags
);
819 rc
= dasd_flush_device_queue(device
);
820 spin_lock_irqsave(&lcu
->lock
, flags
);
822 * only move device around if it wasn't moved away while we
823 * were waiting for the flush
825 if (device
== list_first_entry(&active
,
826 struct dasd_device
, alias_list
))
827 list_move(&device
->alias_list
, &lcu
->active_devices
);
829 spin_unlock_irqrestore(&lcu
->lock
, flags
);
832 static void __stop_device_on_lcu(struct dasd_device
*device
,
833 struct dasd_device
*pos
)
835 /* If pos == device then device is already locked! */
837 dasd_device_set_stop_bits(pos
, DASD_STOPPED_SU
);
840 spin_lock(get_ccwdev_lock(pos
->cdev
));
841 dasd_device_set_stop_bits(pos
, DASD_STOPPED_SU
);
842 spin_unlock(get_ccwdev_lock(pos
->cdev
));
846 * This function is called in interrupt context, so the
847 * cdev lock for device is already locked!
849 static void _stop_all_devices_on_lcu(struct alias_lcu
*lcu
,
850 struct dasd_device
*device
)
852 struct alias_pav_group
*pavgroup
;
853 struct dasd_device
*pos
;
855 list_for_each_entry(pos
, &lcu
->active_devices
, alias_list
)
856 __stop_device_on_lcu(device
, pos
);
857 list_for_each_entry(pos
, &lcu
->inactive_devices
, alias_list
)
858 __stop_device_on_lcu(device
, pos
);
859 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
860 list_for_each_entry(pos
, &pavgroup
->baselist
, alias_list
)
861 __stop_device_on_lcu(device
, pos
);
862 list_for_each_entry(pos
, &pavgroup
->aliaslist
, alias_list
)
863 __stop_device_on_lcu(device
, pos
);
867 static void _unstop_all_devices_on_lcu(struct alias_lcu
*lcu
)
869 struct alias_pav_group
*pavgroup
;
870 struct dasd_device
*device
;
873 list_for_each_entry(device
, &lcu
->active_devices
, alias_list
) {
874 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
875 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
876 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
879 list_for_each_entry(device
, &lcu
->inactive_devices
, alias_list
) {
880 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
881 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
882 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
885 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
886 list_for_each_entry(device
, &pavgroup
->baselist
, alias_list
) {
887 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
888 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
889 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
),
892 list_for_each_entry(device
, &pavgroup
->aliaslist
, alias_list
) {
893 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
894 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
895 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
),
901 static void summary_unit_check_handling_work(struct work_struct
*work
)
903 struct alias_lcu
*lcu
;
904 struct summary_unit_check_work_data
*suc_data
;
906 struct dasd_device
*device
;
908 suc_data
= container_of(work
, struct summary_unit_check_work_data
,
910 lcu
= container_of(suc_data
, struct alias_lcu
, suc_data
);
911 device
= suc_data
->device
;
913 /* 1. flush alias devices */
914 flush_all_alias_devices_on_lcu(lcu
);
916 /* 2. reset summary unit check */
917 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
918 dasd_device_remove_stop_bits(device
,
919 (DASD_STOPPED_SU
| DASD_STOPPED_PENDING
));
920 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
921 reset_summary_unit_check(lcu
, device
, suc_data
->reason
);
923 spin_lock_irqsave(&lcu
->lock
, flags
);
924 _unstop_all_devices_on_lcu(lcu
);
925 _restart_all_base_devices_on_lcu(lcu
);
926 /* 3. read new alias configuration */
927 _schedule_lcu_update(lcu
, device
);
928 lcu
->suc_data
.device
= NULL
;
929 spin_unlock_irqrestore(&lcu
->lock
, flags
);
933 * note: this will be called from int handler context (cdev locked)
935 void dasd_alias_handle_summary_unit_check(struct dasd_device
*device
,
938 struct alias_lcu
*lcu
;
940 struct dasd_eckd_private
*private;
943 private = (struct dasd_eckd_private
*) device
->private;
945 sense
= dasd_get_sense(irb
);
948 DBF_DEV_EVENT(DBF_NOTICE
, device
, "%s %x",
949 "eckd handle summary unit check: reason", reason
);
951 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
952 "eckd handle summary unit check:"
953 " no reason code available");
959 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
960 "device not ready to handle summary"
961 " unit check (no lcu structure)");
964 spin_lock(&lcu
->lock
);
965 _stop_all_devices_on_lcu(lcu
, device
);
966 /* prepare for lcu_update */
967 private->lcu
->flags
|= NEED_UAC_UPDATE
| UPDATE_PENDING
;
968 /* If this device is about to be removed just return and wait for
969 * the next interrupt on a different device
971 if (list_empty(&device
->alias_list
)) {
972 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
973 "device is in offline processing,"
974 " don't do summary unit check handling");
975 spin_unlock(&lcu
->lock
);
978 if (lcu
->suc_data
.device
) {
979 /* already scheduled or running */
980 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
981 "previous instance of summary unit check worker"
983 spin_unlock(&lcu
->lock
);
986 lcu
->suc_data
.reason
= reason
;
987 lcu
->suc_data
.device
= device
;
988 spin_unlock(&lcu
->lock
);
989 schedule_work(&lcu
->suc_data
.worker
);