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
;
193 struct dasd_uid
*uid
;
195 private = (struct dasd_eckd_private
*) device
->private;
197 spin_lock_irqsave(&aliastree
.lock
, flags
);
199 server
= _find_server(uid
);
201 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
202 newserver
= _allocate_server(uid
);
203 if (IS_ERR(newserver
))
204 return PTR_ERR(newserver
);
205 spin_lock_irqsave(&aliastree
.lock
, flags
);
206 server
= _find_server(uid
);
208 list_add(&newserver
->server
, &aliastree
.serverlist
);
212 /* someone was faster */
213 _free_server(newserver
);
217 lcu
= _find_lcu(server
, uid
);
219 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
220 newlcu
= _allocate_lcu(uid
);
222 return PTR_ERR(newlcu
);
223 spin_lock_irqsave(&aliastree
.lock
, flags
);
224 lcu
= _find_lcu(server
, uid
);
226 list_add(&newlcu
->lcu
, &server
->lculist
);
230 /* someone was faster */
235 spin_lock(&lcu
->lock
);
236 list_add(&device
->alias_list
, &lcu
->inactive_devices
);
238 spin_unlock(&lcu
->lock
);
239 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
245 * The first device to be registered on an LCU will have to do
246 * some additional setup steps to configure that LCU on the
247 * storage server. All further devices should wait with their
248 * initialization until the first device is done.
249 * To synchronize this work, the first device will call
250 * dasd_alias_lcu_setup_complete when it is done, and all
251 * other devices will wait for it with dasd_alias_wait_for_lcu_setup.
253 void dasd_alias_lcu_setup_complete(struct dasd_device
*device
)
255 struct dasd_eckd_private
*private;
257 struct alias_server
*server
;
258 struct alias_lcu
*lcu
;
259 struct dasd_uid
*uid
;
261 private = (struct dasd_eckd_private
*) device
->private;
264 spin_lock_irqsave(&aliastree
.lock
, flags
);
265 server
= _find_server(uid
);
267 lcu
= _find_lcu(server
, uid
);
268 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
270 DBF_EVENT_DEVID(DBF_ERR
, device
->cdev
,
271 "could not find lcu for %04x %02x",
272 uid
->ssid
, uid
->real_unit_addr
);
276 complete_all(&lcu
->lcu_setup
);
279 void dasd_alias_wait_for_lcu_setup(struct dasd_device
*device
)
281 struct dasd_eckd_private
*private;
283 struct alias_server
*server
;
284 struct alias_lcu
*lcu
;
285 struct dasd_uid
*uid
;
287 private = (struct dasd_eckd_private
*) device
->private;
290 spin_lock_irqsave(&aliastree
.lock
, flags
);
291 server
= _find_server(uid
);
293 lcu
= _find_lcu(server
, uid
);
294 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
296 DBF_EVENT_DEVID(DBF_ERR
, device
->cdev
,
297 "could not find lcu for %04x %02x",
298 uid
->ssid
, uid
->real_unit_addr
);
302 wait_for_completion(&lcu
->lcu_setup
);
306 * This function removes a device from the scope of alias management.
307 * The complicated part is to make sure that it is not in use by
308 * any of the workers. If necessary cancel the work.
310 void dasd_alias_disconnect_device_from_lcu(struct dasd_device
*device
)
312 struct dasd_eckd_private
*private;
314 struct alias_lcu
*lcu
;
315 struct alias_server
*server
;
318 private = (struct dasd_eckd_private
*) device
->private;
320 spin_lock_irqsave(&lcu
->lock
, flags
);
321 list_del_init(&device
->alias_list
);
322 /* make sure that the workers don't use this device */
323 if (device
== lcu
->suc_data
.device
) {
324 spin_unlock_irqrestore(&lcu
->lock
, flags
);
325 cancel_work_sync(&lcu
->suc_data
.worker
);
326 spin_lock_irqsave(&lcu
->lock
, flags
);
327 if (device
== lcu
->suc_data
.device
)
328 lcu
->suc_data
.device
= NULL
;
331 if (device
== lcu
->ruac_data
.device
) {
332 spin_unlock_irqrestore(&lcu
->lock
, flags
);
334 cancel_delayed_work_sync(&lcu
->ruac_data
.dwork
);
335 spin_lock_irqsave(&lcu
->lock
, flags
);
336 if (device
== lcu
->ruac_data
.device
)
337 lcu
->ruac_data
.device
= NULL
;
340 spin_unlock_irqrestore(&lcu
->lock
, flags
);
342 spin_lock_irqsave(&aliastree
.lock
, flags
);
343 spin_lock(&lcu
->lock
);
344 if (list_empty(&lcu
->grouplist
) &&
345 list_empty(&lcu
->active_devices
) &&
346 list_empty(&lcu
->inactive_devices
)) {
348 spin_unlock(&lcu
->lock
);
353 _schedule_lcu_update(lcu
, NULL
);
354 spin_unlock(&lcu
->lock
);
356 server
= _find_server(&private->uid
);
357 if (server
&& list_empty(&server
->lculist
)) {
358 list_del(&server
->server
);
359 _free_server(server
);
361 spin_unlock_irqrestore(&aliastree
.lock
, flags
);
365 * This function assumes that the unit address configuration stored
366 * in the lcu is up to date and will update the device uid before
367 * adding it to a pav group.
369 static int _add_device_to_lcu(struct alias_lcu
*lcu
,
370 struct dasd_device
*device
)
373 struct dasd_eckd_private
*private;
374 struct alias_pav_group
*group
;
375 struct dasd_uid
*uid
;
377 private = (struct dasd_eckd_private
*) device
->private;
379 uid
->type
= lcu
->uac
->unit
[uid
->real_unit_addr
].ua_type
;
380 uid
->base_unit_addr
= lcu
->uac
->unit
[uid
->real_unit_addr
].base_ua
;
381 dasd_set_uid(device
->cdev
, &private->uid
);
383 /* if we have no PAV anyway, we don't need to bother with PAV groups */
384 if (lcu
->pav
== NO_PAV
) {
385 list_move(&device
->alias_list
, &lcu
->active_devices
);
389 group
= _find_group(lcu
, uid
);
391 group
= kzalloc(sizeof(*group
), GFP_ATOMIC
);
394 memcpy(group
->uid
.vendor
, uid
->vendor
, sizeof(uid
->vendor
));
395 memcpy(group
->uid
.serial
, uid
->serial
, sizeof(uid
->serial
));
396 group
->uid
.ssid
= uid
->ssid
;
397 if (uid
->type
== UA_BASE_DEVICE
)
398 group
->uid
.base_unit_addr
= uid
->real_unit_addr
;
400 group
->uid
.base_unit_addr
= uid
->base_unit_addr
;
401 memcpy(group
->uid
.vduit
, uid
->vduit
, sizeof(uid
->vduit
));
402 INIT_LIST_HEAD(&group
->group
);
403 INIT_LIST_HEAD(&group
->baselist
);
404 INIT_LIST_HEAD(&group
->aliaslist
);
405 list_add(&group
->group
, &lcu
->grouplist
);
407 if (uid
->type
== UA_BASE_DEVICE
)
408 list_move(&device
->alias_list
, &group
->baselist
);
410 list_move(&device
->alias_list
, &group
->aliaslist
);
411 private->pavgroup
= group
;
415 static void _remove_device_from_lcu(struct alias_lcu
*lcu
,
416 struct dasd_device
*device
)
418 struct dasd_eckd_private
*private;
419 struct alias_pav_group
*group
;
421 private = (struct dasd_eckd_private
*) device
->private;
422 list_move(&device
->alias_list
, &lcu
->inactive_devices
);
423 group
= private->pavgroup
;
426 private->pavgroup
= NULL
;
427 if (list_empty(&group
->baselist
) && list_empty(&group
->aliaslist
)) {
428 list_del(&group
->group
);
432 if (group
->next
== device
)
436 static int read_unit_address_configuration(struct dasd_device
*device
,
437 struct alias_lcu
*lcu
)
439 struct dasd_psf_prssd_data
*prssdp
;
440 struct dasd_ccw_req
*cqr
;
445 cqr
= dasd_kmalloc_request(DASD_ECKD_MAGIC
, 1 /* PSF */ + 1 /* RSSD */,
446 (sizeof(struct dasd_psf_prssd_data
)),
450 cqr
->startdev
= device
;
451 cqr
->memdev
= device
;
452 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
454 cqr
->expires
= 20 * HZ
;
456 /* Prepare for Read Subsystem Data */
457 prssdp
= (struct dasd_psf_prssd_data
*) cqr
->data
;
458 memset(prssdp
, 0, sizeof(struct dasd_psf_prssd_data
));
459 prssdp
->order
= PSF_ORDER_PRSSD
;
460 prssdp
->suborder
= 0x0e; /* Read unit address configuration */
461 /* all other bytes of prssdp must be zero */
464 ccw
->cmd_code
= DASD_ECKD_CCW_PSF
;
465 ccw
->count
= sizeof(struct dasd_psf_prssd_data
);
466 ccw
->flags
|= CCW_FLAG_CC
;
467 ccw
->cda
= (__u32
)(addr_t
) prssdp
;
469 /* Read Subsystem Data - feature codes */
470 memset(lcu
->uac
, 0, sizeof(*(lcu
->uac
)));
473 ccw
->cmd_code
= DASD_ECKD_CCW_RSSD
;
474 ccw
->count
= sizeof(*(lcu
->uac
));
475 ccw
->cda
= (__u32
)(addr_t
) lcu
->uac
;
477 cqr
->buildclk
= get_clock();
478 cqr
->status
= DASD_CQR_FILLED
;
480 /* need to unset flag here to detect race with summary unit check */
481 spin_lock_irqsave(&lcu
->lock
, flags
);
482 lcu
->flags
&= ~NEED_UAC_UPDATE
;
483 spin_unlock_irqrestore(&lcu
->lock
, flags
);
486 rc
= dasd_sleep_on(cqr
);
487 } while (rc
&& (cqr
->retries
> 0));
489 spin_lock_irqsave(&lcu
->lock
, flags
);
490 lcu
->flags
|= NEED_UAC_UPDATE
;
491 spin_unlock_irqrestore(&lcu
->lock
, flags
);
493 dasd_kfree_request(cqr
, cqr
->memdev
);
497 static int _lcu_update(struct dasd_device
*refdev
, struct alias_lcu
*lcu
)
500 struct alias_pav_group
*pavgroup
, *tempgroup
;
501 struct dasd_device
*device
, *tempdev
;
503 struct dasd_eckd_private
*private;
505 spin_lock_irqsave(&lcu
->lock
, flags
);
506 list_for_each_entry_safe(pavgroup
, tempgroup
, &lcu
->grouplist
, group
) {
507 list_for_each_entry_safe(device
, tempdev
, &pavgroup
->baselist
,
509 list_move(&device
->alias_list
, &lcu
->active_devices
);
510 private = (struct dasd_eckd_private
*) device
->private;
511 private->pavgroup
= NULL
;
513 list_for_each_entry_safe(device
, tempdev
, &pavgroup
->aliaslist
,
515 list_move(&device
->alias_list
, &lcu
->active_devices
);
516 private = (struct dasd_eckd_private
*) device
->private;
517 private->pavgroup
= NULL
;
519 list_del(&pavgroup
->group
);
522 spin_unlock_irqrestore(&lcu
->lock
, flags
);
524 rc
= read_unit_address_configuration(refdev
, lcu
);
528 spin_lock_irqsave(&lcu
->lock
, flags
);
530 for (i
= 0; i
< MAX_DEVICES_PER_LCU
; ++i
) {
531 switch (lcu
->uac
->unit
[i
].ua_type
) {
532 case UA_BASE_PAV_ALIAS
:
535 case UA_HYPER_PAV_ALIAS
:
536 lcu
->pav
= HYPER_PAV
;
539 if (lcu
->pav
!= NO_PAV
)
543 list_for_each_entry_safe(device
, tempdev
, &lcu
->active_devices
,
545 _add_device_to_lcu(lcu
, device
);
547 spin_unlock_irqrestore(&lcu
->lock
, flags
);
551 static void lcu_update_work(struct work_struct
*work
)
553 struct alias_lcu
*lcu
;
554 struct read_uac_work_data
*ruac_data
;
555 struct dasd_device
*device
;
559 ruac_data
= container_of(work
, struct read_uac_work_data
, dwork
.work
);
560 lcu
= container_of(ruac_data
, struct alias_lcu
, ruac_data
);
561 device
= ruac_data
->device
;
562 rc
= _lcu_update(device
, lcu
);
564 * Need to check flags again, as there could have been another
565 * prepare_update or a new device a new device while we were still
566 * processing the data
568 spin_lock_irqsave(&lcu
->lock
, flags
);
569 if (rc
|| (lcu
->flags
& NEED_UAC_UPDATE
)) {
570 DBF_DEV_EVENT(DBF_WARNING
, device
, "could not update"
571 " alias data in lcu (rc = %d), retry later", rc
);
572 schedule_delayed_work(&lcu
->ruac_data
.dwork
, 30*HZ
);
574 lcu
->ruac_data
.device
= NULL
;
575 lcu
->flags
&= ~UPDATE_PENDING
;
577 spin_unlock_irqrestore(&lcu
->lock
, flags
);
580 static int _schedule_lcu_update(struct alias_lcu
*lcu
,
581 struct dasd_device
*device
)
583 struct dasd_device
*usedev
= NULL
;
584 struct alias_pav_group
*group
;
586 lcu
->flags
|= NEED_UAC_UPDATE
;
587 if (lcu
->ruac_data
.device
) {
588 /* already scheduled or running */
591 if (device
&& !list_empty(&device
->alias_list
))
594 if (!usedev
&& !list_empty(&lcu
->grouplist
)) {
595 group
= list_first_entry(&lcu
->grouplist
,
596 struct alias_pav_group
, group
);
597 if (!list_empty(&group
->baselist
))
598 usedev
= list_first_entry(&group
->baselist
,
601 else if (!list_empty(&group
->aliaslist
))
602 usedev
= list_first_entry(&group
->aliaslist
,
606 if (!usedev
&& !list_empty(&lcu
->active_devices
)) {
607 usedev
= list_first_entry(&lcu
->active_devices
,
608 struct dasd_device
, alias_list
);
611 * if we haven't found a proper device yet, give up for now, the next
612 * device that will be set active will trigger an lcu update
616 lcu
->ruac_data
.device
= usedev
;
617 schedule_delayed_work(&lcu
->ruac_data
.dwork
, 0);
621 int dasd_alias_add_device(struct dasd_device
*device
)
623 struct dasd_eckd_private
*private;
624 struct alias_lcu
*lcu
;
628 private = (struct dasd_eckd_private
*) device
->private;
631 spin_lock_irqsave(&lcu
->lock
, flags
);
632 if (!(lcu
->flags
& UPDATE_PENDING
)) {
633 rc
= _add_device_to_lcu(lcu
, device
);
635 lcu
->flags
|= UPDATE_PENDING
;
637 if (lcu
->flags
& UPDATE_PENDING
) {
638 list_move(&device
->alias_list
, &lcu
->active_devices
);
639 _schedule_lcu_update(lcu
, device
);
641 spin_unlock_irqrestore(&lcu
->lock
, flags
);
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 spin_lock_irqsave(&lcu
->lock
, flags
);
654 _remove_device_from_lcu(lcu
, device
);
655 spin_unlock_irqrestore(&lcu
->lock
, flags
);
659 struct dasd_device
*dasd_alias_get_start_dev(struct dasd_device
*base_device
)
662 struct dasd_device
*alias_device
;
663 struct alias_pav_group
*group
;
664 struct alias_lcu
*lcu
;
665 struct dasd_eckd_private
*private, *alias_priv
;
668 private = (struct dasd_eckd_private
*) base_device
->private;
669 group
= private->pavgroup
;
673 if (lcu
->pav
== NO_PAV
||
674 lcu
->flags
& (NEED_UAC_UPDATE
| UPDATE_PENDING
))
677 spin_lock_irqsave(&lcu
->lock
, flags
);
678 alias_device
= group
->next
;
680 if (list_empty(&group
->aliaslist
)) {
681 spin_unlock_irqrestore(&lcu
->lock
, flags
);
684 alias_device
= list_first_entry(&group
->aliaslist
,
689 if (list_is_last(&alias_device
->alias_list
, &group
->aliaslist
))
690 group
->next
= list_first_entry(&group
->aliaslist
,
691 struct dasd_device
, alias_list
);
693 group
->next
= list_first_entry(&alias_device
->alias_list
,
694 struct dasd_device
, alias_list
);
695 spin_unlock_irqrestore(&lcu
->lock
, flags
);
696 alias_priv
= (struct dasd_eckd_private
*) alias_device
->private;
697 if ((alias_priv
->count
< private->count
) && !alias_device
->stopped
)
704 * Summary unit check handling depends on the way alias devices
705 * are handled so it is done here rather then in dasd_eckd.c
707 static int reset_summary_unit_check(struct alias_lcu
*lcu
,
708 struct dasd_device
*device
,
711 struct dasd_ccw_req
*cqr
;
716 strncpy((char *) &cqr
->magic
, "ECKD", 4);
717 ASCEBC((char *) &cqr
->magic
, 4);
719 ccw
->cmd_code
= DASD_ECKD_CCW_RSCK
;
722 ccw
->cda
= (__u32
)(addr_t
) cqr
->data
;
723 ((char *)cqr
->data
)[0] = reason
;
725 clear_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
726 cqr
->retries
= 255; /* set retry counter to enable basic ERP */
727 cqr
->startdev
= device
;
728 cqr
->memdev
= device
;
730 cqr
->expires
= 5 * HZ
;
731 cqr
->buildclk
= get_clock();
732 cqr
->status
= DASD_CQR_FILLED
;
734 rc
= dasd_sleep_on_immediatly(cqr
);
738 static void _restart_all_base_devices_on_lcu(struct alias_lcu
*lcu
)
740 struct alias_pav_group
*pavgroup
;
741 struct dasd_device
*device
;
742 struct dasd_eckd_private
*private;
744 /* active and inactive list can contain alias as well as base devices */
745 list_for_each_entry(device
, &lcu
->active_devices
, alias_list
) {
746 private = (struct dasd_eckd_private
*) device
->private;
747 if (private->uid
.type
!= UA_BASE_DEVICE
)
749 dasd_schedule_block_bh(device
->block
);
750 dasd_schedule_device_bh(device
);
752 list_for_each_entry(device
, &lcu
->inactive_devices
, alias_list
) {
753 private = (struct dasd_eckd_private
*) device
->private;
754 if (private->uid
.type
!= UA_BASE_DEVICE
)
756 dasd_schedule_block_bh(device
->block
);
757 dasd_schedule_device_bh(device
);
759 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
760 list_for_each_entry(device
, &pavgroup
->baselist
, alias_list
) {
761 dasd_schedule_block_bh(device
->block
);
762 dasd_schedule_device_bh(device
);
767 static void flush_all_alias_devices_on_lcu(struct alias_lcu
*lcu
)
769 struct alias_pav_group
*pavgroup
;
770 struct dasd_device
*device
, *temp
;
771 struct dasd_eckd_private
*private;
777 * Problem here ist that dasd_flush_device_queue may wait
778 * for termination of a request to complete. We can't keep
779 * the lcu lock during that time, so we must assume that
780 * the lists may have changed.
781 * Idea: first gather all active alias devices in a separate list,
782 * then flush the first element of this list unlocked, and afterwards
783 * check if it is still on the list before moving it to the
784 * active_devices list.
787 spin_lock_irqsave(&lcu
->lock
, flags
);
788 list_for_each_entry_safe(device
, temp
, &lcu
->active_devices
,
790 private = (struct dasd_eckd_private
*) device
->private;
791 if (private->uid
.type
== UA_BASE_DEVICE
)
793 list_move(&device
->alias_list
, &active
);
796 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
797 list_splice_init(&pavgroup
->aliaslist
, &active
);
799 while (!list_empty(&active
)) {
800 device
= list_first_entry(&active
, struct dasd_device
,
802 spin_unlock_irqrestore(&lcu
->lock
, flags
);
803 rc
= dasd_flush_device_queue(device
);
804 spin_lock_irqsave(&lcu
->lock
, flags
);
806 * only move device around if it wasn't moved away while we
807 * were waiting for the flush
809 if (device
== list_first_entry(&active
,
810 struct dasd_device
, alias_list
))
811 list_move(&device
->alias_list
, &lcu
->active_devices
);
813 spin_unlock_irqrestore(&lcu
->lock
, flags
);
816 static void __stop_device_on_lcu(struct dasd_device
*device
,
817 struct dasd_device
*pos
)
819 /* If pos == device then device is already locked! */
821 dasd_device_set_stop_bits(pos
, DASD_STOPPED_SU
);
824 spin_lock(get_ccwdev_lock(pos
->cdev
));
825 dasd_device_set_stop_bits(pos
, DASD_STOPPED_SU
);
826 spin_unlock(get_ccwdev_lock(pos
->cdev
));
830 * This function is called in interrupt context, so the
831 * cdev lock for device is already locked!
833 static void _stop_all_devices_on_lcu(struct alias_lcu
*lcu
,
834 struct dasd_device
*device
)
836 struct alias_pav_group
*pavgroup
;
837 struct dasd_device
*pos
;
839 list_for_each_entry(pos
, &lcu
->active_devices
, alias_list
)
840 __stop_device_on_lcu(device
, pos
);
841 list_for_each_entry(pos
, &lcu
->inactive_devices
, alias_list
)
842 __stop_device_on_lcu(device
, pos
);
843 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
844 list_for_each_entry(pos
, &pavgroup
->baselist
, alias_list
)
845 __stop_device_on_lcu(device
, pos
);
846 list_for_each_entry(pos
, &pavgroup
->aliaslist
, alias_list
)
847 __stop_device_on_lcu(device
, pos
);
851 static void _unstop_all_devices_on_lcu(struct alias_lcu
*lcu
)
853 struct alias_pav_group
*pavgroup
;
854 struct dasd_device
*device
;
857 list_for_each_entry(device
, &lcu
->active_devices
, alias_list
) {
858 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
859 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
860 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
863 list_for_each_entry(device
, &lcu
->inactive_devices
, alias_list
) {
864 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
865 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
866 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
869 list_for_each_entry(pavgroup
, &lcu
->grouplist
, group
) {
870 list_for_each_entry(device
, &pavgroup
->baselist
, alias_list
) {
871 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
872 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
873 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
),
876 list_for_each_entry(device
, &pavgroup
->aliaslist
, alias_list
) {
877 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
878 dasd_device_remove_stop_bits(device
, DASD_STOPPED_SU
);
879 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
),
885 static void summary_unit_check_handling_work(struct work_struct
*work
)
887 struct alias_lcu
*lcu
;
888 struct summary_unit_check_work_data
*suc_data
;
890 struct dasd_device
*device
;
892 suc_data
= container_of(work
, struct summary_unit_check_work_data
,
894 lcu
= container_of(suc_data
, struct alias_lcu
, suc_data
);
895 device
= suc_data
->device
;
897 /* 1. flush alias devices */
898 flush_all_alias_devices_on_lcu(lcu
);
900 /* 2. reset summary unit check */
901 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
902 dasd_device_remove_stop_bits(device
,
903 (DASD_STOPPED_SU
| DASD_STOPPED_PENDING
));
904 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
905 reset_summary_unit_check(lcu
, device
, suc_data
->reason
);
907 spin_lock_irqsave(&lcu
->lock
, flags
);
908 _unstop_all_devices_on_lcu(lcu
);
909 _restart_all_base_devices_on_lcu(lcu
);
910 /* 3. read new alias configuration */
911 _schedule_lcu_update(lcu
, device
);
912 lcu
->suc_data
.device
= NULL
;
913 spin_unlock_irqrestore(&lcu
->lock
, flags
);
917 * note: this will be called from int handler context (cdev locked)
919 void dasd_alias_handle_summary_unit_check(struct dasd_device
*device
,
922 struct alias_lcu
*lcu
;
924 struct dasd_eckd_private
*private;
927 private = (struct dasd_eckd_private
*) device
->private;
929 sense
= dasd_get_sense(irb
);
932 DBF_DEV_EVENT(DBF_NOTICE
, device
, "%s %x",
933 "eckd handle summary unit check: reason", reason
);
935 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
936 "eckd handle summary unit check:"
937 " no reason code available");
943 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
944 "device not ready to handle summary"
945 " unit check (no lcu structure)");
948 spin_lock(&lcu
->lock
);
949 _stop_all_devices_on_lcu(lcu
, device
);
950 /* prepare for lcu_update */
951 private->lcu
->flags
|= NEED_UAC_UPDATE
| UPDATE_PENDING
;
952 /* If this device is about to be removed just return and wait for
953 * the next interrupt on a different device
955 if (list_empty(&device
->alias_list
)) {
956 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
957 "device is in offline processing,"
958 " don't do summary unit check handling");
959 spin_unlock(&lcu
->lock
);
962 if (lcu
->suc_data
.device
) {
963 /* already scheduled or running */
964 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
965 "previous instance of summary unit check worker"
967 spin_unlock(&lcu
->lock
);
970 lcu
->suc_data
.reason
= reason
;
971 lcu
->suc_data
.device
= device
;
972 spin_unlock(&lcu
->lock
);
973 schedule_work(&lcu
->suc_data
.worker
);