diff options
author | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
---|---|---|
committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
commit | ada47b5fe13d89735805b566185f4885f5a3f750 (patch) | |
tree | 644b88f8a71896307d71438e9b3af49126ffb22b /drivers/s390/cio/device.c | |
parent | 43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff) | |
parent | 3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff) |
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'drivers/s390/cio/device.c')
-rw-r--r-- | drivers/s390/cio/device.c | 1160 |
1 files changed, 495 insertions, 665 deletions
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c index 2490b741e16a..6d229f3523a0 100644 --- a/drivers/s390/cio/device.c +++ b/drivers/s390/cio/device.c | |||
@@ -7,6 +7,10 @@ | |||
7 | * Cornelia Huck (cornelia.huck@de.ibm.com) | 7 | * Cornelia Huck (cornelia.huck@de.ibm.com) |
8 | * Martin Schwidefsky (schwidefsky@de.ibm.com) | 8 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
9 | */ | 9 | */ |
10 | |||
11 | #define KMSG_COMPONENT "cio" | ||
12 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | ||
13 | |||
10 | #include <linux/module.h> | 14 | #include <linux/module.h> |
11 | #include <linux/init.h> | 15 | #include <linux/init.h> |
12 | #include <linux/spinlock.h> | 16 | #include <linux/spinlock.h> |
@@ -132,7 +136,6 @@ static int io_subchannel_sch_event(struct subchannel *, int); | |||
132 | static int io_subchannel_chp_event(struct subchannel *, struct chp_link *, | 136 | static int io_subchannel_chp_event(struct subchannel *, struct chp_link *, |
133 | int); | 137 | int); |
134 | static void recovery_func(unsigned long data); | 138 | static void recovery_func(unsigned long data); |
135 | struct workqueue_struct *ccw_device_work; | ||
136 | wait_queue_head_t ccw_device_init_wq; | 139 | wait_queue_head_t ccw_device_init_wq; |
137 | atomic_t ccw_device_init_count; | 140 | atomic_t ccw_device_init_count; |
138 | 141 | ||
@@ -155,11 +158,16 @@ static int io_subchannel_prepare(struct subchannel *sch) | |||
155 | return 0; | 158 | return 0; |
156 | } | 159 | } |
157 | 160 | ||
158 | static void io_subchannel_settle(void) | 161 | static int io_subchannel_settle(void) |
159 | { | 162 | { |
160 | wait_event(ccw_device_init_wq, | 163 | int ret; |
161 | atomic_read(&ccw_device_init_count) == 0); | 164 | |
162 | flush_workqueue(ccw_device_work); | 165 | ret = wait_event_interruptible(ccw_device_init_wq, |
166 | atomic_read(&ccw_device_init_count) == 0); | ||
167 | if (ret) | ||
168 | return -EINTR; | ||
169 | flush_workqueue(cio_work_q); | ||
170 | return 0; | ||
163 | } | 171 | } |
164 | 172 | ||
165 | static struct css_driver io_subchannel_driver = { | 173 | static struct css_driver io_subchannel_driver = { |
@@ -184,27 +192,13 @@ int __init io_subchannel_init(void) | |||
184 | atomic_set(&ccw_device_init_count, 0); | 192 | atomic_set(&ccw_device_init_count, 0); |
185 | setup_timer(&recovery_timer, recovery_func, 0); | 193 | setup_timer(&recovery_timer, recovery_func, 0); |
186 | 194 | ||
187 | ccw_device_work = create_singlethread_workqueue("cio"); | 195 | ret = bus_register(&ccw_bus_type); |
188 | if (!ccw_device_work) | 196 | if (ret) |
189 | return -ENOMEM; | 197 | return ret; |
190 | slow_path_wq = create_singlethread_workqueue("kslowcrw"); | ||
191 | if (!slow_path_wq) { | ||
192 | ret = -ENOMEM; | ||
193 | goto out_err; | ||
194 | } | ||
195 | if ((ret = bus_register (&ccw_bus_type))) | ||
196 | goto out_err; | ||
197 | |||
198 | ret = css_driver_register(&io_subchannel_driver); | 198 | ret = css_driver_register(&io_subchannel_driver); |
199 | if (ret) | 199 | if (ret) |
200 | goto out_err; | 200 | bus_unregister(&ccw_bus_type); |
201 | 201 | ||
202 | return 0; | ||
203 | out_err: | ||
204 | if (ccw_device_work) | ||
205 | destroy_workqueue(ccw_device_work); | ||
206 | if (slow_path_wq) | ||
207 | destroy_workqueue(slow_path_wq); | ||
208 | return ret; | 202 | return ret; |
209 | } | 203 | } |
210 | 204 | ||
@@ -299,53 +293,18 @@ int ccw_device_is_orphan(struct ccw_device *cdev) | |||
299 | 293 | ||
300 | static void ccw_device_unregister(struct ccw_device *cdev) | 294 | static void ccw_device_unregister(struct ccw_device *cdev) |
301 | { | 295 | { |
302 | if (test_and_clear_bit(1, &cdev->private->registered)) { | 296 | if (device_is_registered(&cdev->dev)) { |
297 | /* Undo device_add(). */ | ||
303 | device_del(&cdev->dev); | 298 | device_del(&cdev->dev); |
299 | } | ||
300 | if (cdev->private->flags.initialized) { | ||
301 | cdev->private->flags.initialized = 0; | ||
304 | /* Release reference from device_initialize(). */ | 302 | /* Release reference from device_initialize(). */ |
305 | put_device(&cdev->dev); | 303 | put_device(&cdev->dev); |
306 | } | 304 | } |
307 | } | 305 | } |
308 | 306 | ||
309 | static void ccw_device_remove_orphan_cb(struct work_struct *work) | 307 | static void io_subchannel_quiesce(struct subchannel *); |
310 | { | ||
311 | struct ccw_device_private *priv; | ||
312 | struct ccw_device *cdev; | ||
313 | |||
314 | priv = container_of(work, struct ccw_device_private, kick_work); | ||
315 | cdev = priv->cdev; | ||
316 | ccw_device_unregister(cdev); | ||
317 | /* Release cdev reference for workqueue processing. */ | ||
318 | put_device(&cdev->dev); | ||
319 | } | ||
320 | |||
321 | static void | ||
322 | ccw_device_remove_disconnected(struct ccw_device *cdev) | ||
323 | { | ||
324 | unsigned long flags; | ||
325 | |||
326 | /* | ||
327 | * Forced offline in disconnected state means | ||
328 | * 'throw away device'. | ||
329 | */ | ||
330 | if (ccw_device_is_orphan(cdev)) { | ||
331 | /* | ||
332 | * Deregister ccw device. | ||
333 | * Unfortunately, we cannot do this directly from the | ||
334 | * attribute method. | ||
335 | */ | ||
336 | /* Get cdev reference for workqueue processing. */ | ||
337 | if (!get_device(&cdev->dev)) | ||
338 | return; | ||
339 | spin_lock_irqsave(cdev->ccwlock, flags); | ||
340 | cdev->private->state = DEV_STATE_NOT_OPER; | ||
341 | spin_unlock_irqrestore(cdev->ccwlock, flags); | ||
342 | PREPARE_WORK(&cdev->private->kick_work, | ||
343 | ccw_device_remove_orphan_cb); | ||
344 | queue_work(slow_path_wq, &cdev->private->kick_work); | ||
345 | } else | ||
346 | /* Deregister subchannel, which will kill the ccw device. */ | ||
347 | ccw_device_schedule_sch_unregister(cdev); | ||
348 | } | ||
349 | 308 | ||
350 | /** | 309 | /** |
351 | * ccw_device_set_offline() - disable a ccw device for I/O | 310 | * ccw_device_set_offline() - disable a ccw device for I/O |
@@ -360,7 +319,8 @@ ccw_device_remove_disconnected(struct ccw_device *cdev) | |||
360 | */ | 319 | */ |
361 | int ccw_device_set_offline(struct ccw_device *cdev) | 320 | int ccw_device_set_offline(struct ccw_device *cdev) |
362 | { | 321 | { |
363 | int ret; | 322 | struct subchannel *sch; |
323 | int ret, state; | ||
364 | 324 | ||
365 | if (!cdev) | 325 | if (!cdev) |
366 | return -ENODEV; | 326 | return -ENODEV; |
@@ -374,6 +334,7 @@ int ccw_device_set_offline(struct ccw_device *cdev) | |||
374 | } | 334 | } |
375 | cdev->online = 0; | 335 | cdev->online = 0; |
376 | spin_lock_irq(cdev->ccwlock); | 336 | spin_lock_irq(cdev->ccwlock); |
337 | sch = to_subchannel(cdev->dev.parent); | ||
377 | /* Wait until a final state or DISCONNECTED is reached */ | 338 | /* Wait until a final state or DISCONNECTED is reached */ |
378 | while (!dev_fsm_final_state(cdev) && | 339 | while (!dev_fsm_final_state(cdev) && |
379 | cdev->private->state != DEV_STATE_DISCONNECTED) { | 340 | cdev->private->state != DEV_STATE_DISCONNECTED) { |
@@ -382,20 +343,37 @@ int ccw_device_set_offline(struct ccw_device *cdev) | |||
382 | cdev->private->state == DEV_STATE_DISCONNECTED)); | 343 | cdev->private->state == DEV_STATE_DISCONNECTED)); |
383 | spin_lock_irq(cdev->ccwlock); | 344 | spin_lock_irq(cdev->ccwlock); |
384 | } | 345 | } |
385 | ret = ccw_device_offline(cdev); | 346 | do { |
386 | if (ret) | 347 | ret = ccw_device_offline(cdev); |
387 | goto error; | 348 | if (!ret) |
349 | break; | ||
350 | CIO_MSG_EVENT(0, "ccw_device_offline returned %d, device " | ||
351 | "0.%x.%04x\n", ret, cdev->private->dev_id.ssid, | ||
352 | cdev->private->dev_id.devno); | ||
353 | if (ret != -EBUSY) | ||
354 | goto error; | ||
355 | state = cdev->private->state; | ||
356 | spin_unlock_irq(cdev->ccwlock); | ||
357 | io_subchannel_quiesce(sch); | ||
358 | spin_lock_irq(cdev->ccwlock); | ||
359 | cdev->private->state = state; | ||
360 | } while (ret == -EBUSY); | ||
388 | spin_unlock_irq(cdev->ccwlock); | 361 | spin_unlock_irq(cdev->ccwlock); |
389 | wait_event(cdev->private->wait_q, (dev_fsm_final_state(cdev) || | 362 | wait_event(cdev->private->wait_q, (dev_fsm_final_state(cdev) || |
390 | cdev->private->state == DEV_STATE_DISCONNECTED)); | 363 | cdev->private->state == DEV_STATE_DISCONNECTED)); |
364 | /* Inform the user if set offline failed. */ | ||
365 | if (cdev->private->state == DEV_STATE_BOXED) { | ||
366 | pr_warning("%s: The device entered boxed state while " | ||
367 | "being set offline\n", dev_name(&cdev->dev)); | ||
368 | } else if (cdev->private->state == DEV_STATE_NOT_OPER) { | ||
369 | pr_warning("%s: The device stopped operating while " | ||
370 | "being set offline\n", dev_name(&cdev->dev)); | ||
371 | } | ||
391 | /* Give up reference from ccw_device_set_online(). */ | 372 | /* Give up reference from ccw_device_set_online(). */ |
392 | put_device(&cdev->dev); | 373 | put_device(&cdev->dev); |
393 | return 0; | 374 | return 0; |
394 | 375 | ||
395 | error: | 376 | error: |
396 | CIO_MSG_EVENT(0, "ccw_device_offline returned %d, device 0.%x.%04x\n", | ||
397 | ret, cdev->private->dev_id.ssid, | ||
398 | cdev->private->dev_id.devno); | ||
399 | cdev->private->state = DEV_STATE_OFFLINE; | 377 | cdev->private->state = DEV_STATE_OFFLINE; |
400 | dev_fsm_event(cdev, DEV_EVENT_NOTOPER); | 378 | dev_fsm_event(cdev, DEV_EVENT_NOTOPER); |
401 | spin_unlock_irq(cdev->ccwlock); | 379 | spin_unlock_irq(cdev->ccwlock); |
@@ -448,6 +426,16 @@ int ccw_device_set_online(struct ccw_device *cdev) | |||
448 | if ((cdev->private->state != DEV_STATE_ONLINE) && | 426 | if ((cdev->private->state != DEV_STATE_ONLINE) && |
449 | (cdev->private->state != DEV_STATE_W4SENSE)) { | 427 | (cdev->private->state != DEV_STATE_W4SENSE)) { |
450 | spin_unlock_irq(cdev->ccwlock); | 428 | spin_unlock_irq(cdev->ccwlock); |
429 | /* Inform the user that set online failed. */ | ||
430 | if (cdev->private->state == DEV_STATE_BOXED) { | ||
431 | pr_warning("%s: Setting the device online failed " | ||
432 | "because it is boxed\n", | ||
433 | dev_name(&cdev->dev)); | ||
434 | } else if (cdev->private->state == DEV_STATE_NOT_OPER) { | ||
435 | pr_warning("%s: Setting the device online failed " | ||
436 | "because it is not operational\n", | ||
437 | dev_name(&cdev->dev)); | ||
438 | } | ||
451 | /* Give up online reference since onlining failed. */ | 439 | /* Give up online reference since onlining failed. */ |
452 | put_device(&cdev->dev); | 440 | put_device(&cdev->dev); |
453 | return -ENODEV; | 441 | return -ENODEV; |
@@ -494,27 +482,22 @@ error: | |||
494 | 482 | ||
495 | static int online_store_handle_offline(struct ccw_device *cdev) | 483 | static int online_store_handle_offline(struct ccw_device *cdev) |
496 | { | 484 | { |
497 | if (cdev->private->state == DEV_STATE_DISCONNECTED) | 485 | if (cdev->private->state == DEV_STATE_DISCONNECTED) { |
498 | ccw_device_remove_disconnected(cdev); | 486 | spin_lock_irq(cdev->ccwlock); |
499 | else if (cdev->online && cdev->drv && cdev->drv->set_offline) | 487 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG_EVAL); |
488 | spin_unlock_irq(cdev->ccwlock); | ||
489 | } else if (cdev->online && cdev->drv && cdev->drv->set_offline) | ||
500 | return ccw_device_set_offline(cdev); | 490 | return ccw_device_set_offline(cdev); |
501 | return 0; | 491 | return 0; |
502 | } | 492 | } |
503 | 493 | ||
504 | static int online_store_recog_and_online(struct ccw_device *cdev) | 494 | static int online_store_recog_and_online(struct ccw_device *cdev) |
505 | { | 495 | { |
506 | int ret; | ||
507 | |||
508 | /* Do device recognition, if needed. */ | 496 | /* Do device recognition, if needed. */ |
509 | if (cdev->private->state == DEV_STATE_BOXED) { | 497 | if (cdev->private->state == DEV_STATE_BOXED) { |
510 | ret = ccw_device_recognition(cdev); | 498 | spin_lock_irq(cdev->ccwlock); |
511 | if (ret) { | 499 | ccw_device_recognition(cdev); |
512 | CIO_MSG_EVENT(0, "Couldn't start recognition " | 500 | spin_unlock_irq(cdev->ccwlock); |
513 | "for device 0.%x.%04x (ret=%d)\n", | ||
514 | cdev->private->dev_id.ssid, | ||
515 | cdev->private->dev_id.devno, ret); | ||
516 | return ret; | ||
517 | } | ||
518 | wait_event(cdev->private->wait_q, | 501 | wait_event(cdev->private->wait_q, |
519 | cdev->private->flags.recog_done); | 502 | cdev->private->flags.recog_done); |
520 | if (cdev->private->state != DEV_STATE_OFFLINE) | 503 | if (cdev->private->state != DEV_STATE_OFFLINE) |
@@ -553,11 +536,10 @@ static ssize_t online_store (struct device *dev, struct device_attribute *attr, | |||
553 | int force, ret; | 536 | int force, ret; |
554 | unsigned long i; | 537 | unsigned long i; |
555 | 538 | ||
556 | if ((cdev->private->state != DEV_STATE_OFFLINE && | 539 | if (!dev_fsm_final_state(cdev) && |
557 | cdev->private->state != DEV_STATE_ONLINE && | 540 | cdev->private->state != DEV_STATE_DISCONNECTED) |
558 | cdev->private->state != DEV_STATE_BOXED && | 541 | return -EAGAIN; |
559 | cdev->private->state != DEV_STATE_DISCONNECTED) || | 542 | if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0) |
560 | atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0) | ||
561 | return -EAGAIN; | 543 | return -EAGAIN; |
562 | 544 | ||
563 | if (cdev->drv && !try_module_get(cdev->drv->owner)) { | 545 | if (cdev->drv && !try_module_get(cdev->drv->owner)) { |
@@ -665,81 +647,31 @@ static int ccw_device_register(struct ccw_device *cdev) | |||
665 | cdev->private->dev_id.devno); | 647 | cdev->private->dev_id.devno); |
666 | if (ret) | 648 | if (ret) |
667 | return ret; | 649 | return ret; |
668 | ret = device_add(dev); | 650 | return device_add(dev); |
669 | if (ret) | ||
670 | return ret; | ||
671 | |||
672 | set_bit(1, &cdev->private->registered); | ||
673 | return ret; | ||
674 | } | ||
675 | |||
676 | struct match_data { | ||
677 | struct ccw_dev_id dev_id; | ||
678 | struct ccw_device * sibling; | ||
679 | }; | ||
680 | |||
681 | static int | ||
682 | match_devno(struct device * dev, void * data) | ||
683 | { | ||
684 | struct match_data * d = data; | ||
685 | struct ccw_device * cdev; | ||
686 | |||
687 | cdev = to_ccwdev(dev); | ||
688 | if ((cdev->private->state == DEV_STATE_DISCONNECTED) && | ||
689 | !ccw_device_is_orphan(cdev) && | ||
690 | ccw_dev_id_is_equal(&cdev->private->dev_id, &d->dev_id) && | ||
691 | (cdev != d->sibling)) | ||
692 | return 1; | ||
693 | return 0; | ||
694 | } | 651 | } |
695 | 652 | ||
696 | static struct ccw_device * get_disc_ccwdev_by_dev_id(struct ccw_dev_id *dev_id, | 653 | static int match_dev_id(struct device *dev, void *data) |
697 | struct ccw_device *sibling) | ||
698 | { | 654 | { |
699 | struct device *dev; | 655 | struct ccw_device *cdev = to_ccwdev(dev); |
700 | struct match_data data; | 656 | struct ccw_dev_id *dev_id = data; |
701 | |||
702 | data.dev_id = *dev_id; | ||
703 | data.sibling = sibling; | ||
704 | dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno); | ||
705 | |||
706 | return dev ? to_ccwdev(dev) : NULL; | ||
707 | } | ||
708 | |||
709 | static int match_orphan(struct device *dev, void *data) | ||
710 | { | ||
711 | struct ccw_dev_id *dev_id; | ||
712 | struct ccw_device *cdev; | ||
713 | 657 | ||
714 | dev_id = data; | ||
715 | cdev = to_ccwdev(dev); | ||
716 | return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id); | 658 | return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id); |
717 | } | 659 | } |
718 | 660 | ||
719 | static struct ccw_device * | 661 | static struct ccw_device *get_ccwdev_by_dev_id(struct ccw_dev_id *dev_id) |
720 | get_orphaned_ccwdev_by_dev_id(struct channel_subsystem *css, | ||
721 | struct ccw_dev_id *dev_id) | ||
722 | { | 662 | { |
723 | struct device *dev; | 663 | struct device *dev; |
724 | 664 | ||
725 | dev = device_find_child(&css->pseudo_subchannel->dev, dev_id, | 665 | dev = bus_find_device(&ccw_bus_type, NULL, dev_id, match_dev_id); |
726 | match_orphan); | ||
727 | 666 | ||
728 | return dev ? to_ccwdev(dev) : NULL; | 667 | return dev ? to_ccwdev(dev) : NULL; |
729 | } | 668 | } |
730 | 669 | ||
731 | void ccw_device_do_unbind_bind(struct work_struct *work) | 670 | static void ccw_device_do_unbind_bind(struct ccw_device *cdev) |
732 | { | 671 | { |
733 | struct ccw_device_private *priv; | ||
734 | struct ccw_device *cdev; | ||
735 | struct subchannel *sch; | ||
736 | int ret; | 672 | int ret; |
737 | 673 | ||
738 | priv = container_of(work, struct ccw_device_private, kick_work); | 674 | if (device_is_registered(&cdev->dev)) { |
739 | cdev = priv->cdev; | ||
740 | sch = to_subchannel(cdev->dev.parent); | ||
741 | |||
742 | if (test_bit(1, &cdev->private->registered)) { | ||
743 | device_release_driver(&cdev->dev); | 675 | device_release_driver(&cdev->dev); |
744 | ret = device_attach(&cdev->dev); | 676 | ret = device_attach(&cdev->dev); |
745 | WARN_ON(ret == -ENODEV); | 677 | WARN_ON(ret == -ENODEV); |
@@ -773,6 +705,8 @@ static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch) | |||
773 | return ERR_PTR(-ENOMEM); | 705 | return ERR_PTR(-ENOMEM); |
774 | } | 706 | } |
775 | 707 | ||
708 | static void ccw_device_todo(struct work_struct *work); | ||
709 | |||
776 | static int io_subchannel_initialize_dev(struct subchannel *sch, | 710 | static int io_subchannel_initialize_dev(struct subchannel *sch, |
777 | struct ccw_device *cdev) | 711 | struct ccw_device *cdev) |
778 | { | 712 | { |
@@ -780,7 +714,7 @@ static int io_subchannel_initialize_dev(struct subchannel *sch, | |||
780 | atomic_set(&cdev->private->onoff, 0); | 714 | atomic_set(&cdev->private->onoff, 0); |
781 | cdev->dev.parent = &sch->dev; | 715 | cdev->dev.parent = &sch->dev; |
782 | cdev->dev.release = ccw_device_release; | 716 | cdev->dev.release = ccw_device_release; |
783 | INIT_WORK(&cdev->private->kick_work, NULL); | 717 | INIT_WORK(&cdev->private->todo_work, ccw_device_todo); |
784 | cdev->dev.groups = ccwdev_attr_groups; | 718 | cdev->dev.groups = ccwdev_attr_groups; |
785 | /* Do first half of device_register. */ | 719 | /* Do first half of device_register. */ |
786 | device_initialize(&cdev->dev); | 720 | device_initialize(&cdev->dev); |
@@ -789,6 +723,7 @@ static int io_subchannel_initialize_dev(struct subchannel *sch, | |||
789 | put_device(&cdev->dev); | 723 | put_device(&cdev->dev); |
790 | return -ENODEV; | 724 | return -ENODEV; |
791 | } | 725 | } |
726 | cdev->private->flags.initialized = 1; | ||
792 | return 0; | 727 | return 0; |
793 | } | 728 | } |
794 | 729 | ||
@@ -806,76 +741,7 @@ static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch) | |||
806 | return cdev; | 741 | return cdev; |
807 | } | 742 | } |
808 | 743 | ||
809 | static int io_subchannel_recog(struct ccw_device *, struct subchannel *); | 744 | static void io_subchannel_recog(struct ccw_device *, struct subchannel *); |
810 | |||
811 | static void sch_attach_device(struct subchannel *sch, | ||
812 | struct ccw_device *cdev) | ||
813 | { | ||
814 | css_update_ssd_info(sch); | ||
815 | spin_lock_irq(sch->lock); | ||
816 | sch_set_cdev(sch, cdev); | ||
817 | cdev->private->schid = sch->schid; | ||
818 | cdev->ccwlock = sch->lock; | ||
819 | ccw_device_trigger_reprobe(cdev); | ||
820 | spin_unlock_irq(sch->lock); | ||
821 | } | ||
822 | |||
823 | static void sch_attach_disconnected_device(struct subchannel *sch, | ||
824 | struct ccw_device *cdev) | ||
825 | { | ||
826 | struct subchannel *other_sch; | ||
827 | int ret; | ||
828 | |||
829 | /* Get reference for new parent. */ | ||
830 | if (!get_device(&sch->dev)) | ||
831 | return; | ||
832 | other_sch = to_subchannel(cdev->dev.parent); | ||
833 | /* Note: device_move() changes cdev->dev.parent */ | ||
834 | ret = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV); | ||
835 | if (ret) { | ||
836 | CIO_MSG_EVENT(0, "Moving disconnected device 0.%x.%04x failed " | ||
837 | "(ret=%d)!\n", cdev->private->dev_id.ssid, | ||
838 | cdev->private->dev_id.devno, ret); | ||
839 | /* Put reference for new parent. */ | ||
840 | put_device(&sch->dev); | ||
841 | return; | ||
842 | } | ||
843 | sch_set_cdev(other_sch, NULL); | ||
844 | /* No need to keep a subchannel without ccw device around. */ | ||
845 | css_sch_device_unregister(other_sch); | ||
846 | sch_attach_device(sch, cdev); | ||
847 | /* Put reference for old parent. */ | ||
848 | put_device(&other_sch->dev); | ||
849 | } | ||
850 | |||
851 | static void sch_attach_orphaned_device(struct subchannel *sch, | ||
852 | struct ccw_device *cdev) | ||
853 | { | ||
854 | int ret; | ||
855 | struct subchannel *pseudo_sch; | ||
856 | |||
857 | /* Get reference for new parent. */ | ||
858 | if (!get_device(&sch->dev)) | ||
859 | return; | ||
860 | pseudo_sch = to_subchannel(cdev->dev.parent); | ||
861 | /* | ||
862 | * Try to move the ccw device to its new subchannel. | ||
863 | * Note: device_move() changes cdev->dev.parent | ||
864 | */ | ||
865 | ret = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV); | ||
866 | if (ret) { | ||
867 | CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage " | ||
868 | "failed (ret=%d)!\n", | ||
869 | cdev->private->dev_id.ssid, | ||
870 | cdev->private->dev_id.devno, ret); | ||
871 | /* Put reference for new parent. */ | ||
872 | put_device(&sch->dev); | ||
873 | return; | ||
874 | } | ||
875 | sch_attach_device(sch, cdev); | ||
876 | /* Put reference on pseudo subchannel. */ | ||
877 | put_device(&pseudo_sch->dev); | ||
878 | } | ||
879 | 745 | ||
880 | static void sch_create_and_recog_new_device(struct subchannel *sch) | 746 | static void sch_create_and_recog_new_device(struct subchannel *sch) |
881 | { | 747 | { |
@@ -888,100 +754,19 @@ static void sch_create_and_recog_new_device(struct subchannel *sch) | |||
888 | css_sch_device_unregister(sch); | 754 | css_sch_device_unregister(sch); |
889 | return; | 755 | return; |
890 | } | 756 | } |
891 | spin_lock_irq(sch->lock); | ||
892 | sch_set_cdev(sch, cdev); | ||
893 | spin_unlock_irq(sch->lock); | ||
894 | /* Start recognition for the new ccw device. */ | 757 | /* Start recognition for the new ccw device. */ |
895 | if (io_subchannel_recog(cdev, sch)) { | 758 | io_subchannel_recog(cdev, sch); |
896 | spin_lock_irq(sch->lock); | ||
897 | sch_set_cdev(sch, NULL); | ||
898 | spin_unlock_irq(sch->lock); | ||
899 | css_sch_device_unregister(sch); | ||
900 | /* Put reference from io_subchannel_create_ccwdev(). */ | ||
901 | put_device(&sch->dev); | ||
902 | /* Give up initial reference. */ | ||
903 | put_device(&cdev->dev); | ||
904 | } | ||
905 | } | ||
906 | |||
907 | |||
908 | void ccw_device_move_to_orphanage(struct work_struct *work) | ||
909 | { | ||
910 | struct ccw_device_private *priv; | ||
911 | struct ccw_device *cdev; | ||
912 | struct ccw_device *replacing_cdev; | ||
913 | struct subchannel *sch; | ||
914 | int ret; | ||
915 | struct channel_subsystem *css; | ||
916 | struct ccw_dev_id dev_id; | ||
917 | |||
918 | priv = container_of(work, struct ccw_device_private, kick_work); | ||
919 | cdev = priv->cdev; | ||
920 | sch = to_subchannel(cdev->dev.parent); | ||
921 | css = to_css(sch->dev.parent); | ||
922 | dev_id.devno = sch->schib.pmcw.dev; | ||
923 | dev_id.ssid = sch->schid.ssid; | ||
924 | |||
925 | /* Increase refcount for pseudo subchannel. */ | ||
926 | get_device(&css->pseudo_subchannel->dev); | ||
927 | /* | ||
928 | * Move the orphaned ccw device to the orphanage so the replacing | ||
929 | * ccw device can take its place on the subchannel. | ||
930 | * Note: device_move() changes cdev->dev.parent | ||
931 | */ | ||
932 | ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev, | ||
933 | DPM_ORDER_NONE); | ||
934 | if (ret) { | ||
935 | CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed " | ||
936 | "(ret=%d)!\n", cdev->private->dev_id.ssid, | ||
937 | cdev->private->dev_id.devno, ret); | ||
938 | /* Decrease refcount for pseudo subchannel again. */ | ||
939 | put_device(&css->pseudo_subchannel->dev); | ||
940 | return; | ||
941 | } | ||
942 | cdev->ccwlock = css->pseudo_subchannel->lock; | ||
943 | /* | ||
944 | * Search for the replacing ccw device | ||
945 | * - among the disconnected devices | ||
946 | * - in the orphanage | ||
947 | */ | ||
948 | replacing_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev); | ||
949 | if (replacing_cdev) { | ||
950 | sch_attach_disconnected_device(sch, replacing_cdev); | ||
951 | /* Release reference from get_disc_ccwdev_by_dev_id() */ | ||
952 | put_device(&replacing_cdev->dev); | ||
953 | /* Release reference of subchannel from old cdev. */ | ||
954 | put_device(&sch->dev); | ||
955 | return; | ||
956 | } | ||
957 | replacing_cdev = get_orphaned_ccwdev_by_dev_id(css, &dev_id); | ||
958 | if (replacing_cdev) { | ||
959 | sch_attach_orphaned_device(sch, replacing_cdev); | ||
960 | /* Release reference from get_orphaned_ccwdev_by_dev_id() */ | ||
961 | put_device(&replacing_cdev->dev); | ||
962 | /* Release reference of subchannel from old cdev. */ | ||
963 | put_device(&sch->dev); | ||
964 | return; | ||
965 | } | ||
966 | sch_create_and_recog_new_device(sch); | ||
967 | /* Release reference of subchannel from old cdev. */ | ||
968 | put_device(&sch->dev); | ||
969 | } | 759 | } |
970 | 760 | ||
971 | /* | 761 | /* |
972 | * Register recognized device. | 762 | * Register recognized device. |
973 | */ | 763 | */ |
974 | static void | 764 | static void io_subchannel_register(struct ccw_device *cdev) |
975 | io_subchannel_register(struct work_struct *work) | ||
976 | { | 765 | { |
977 | struct ccw_device_private *priv; | ||
978 | struct ccw_device *cdev; | ||
979 | struct subchannel *sch; | 766 | struct subchannel *sch; |
980 | int ret; | 767 | int ret, adjust_init_count = 1; |
981 | unsigned long flags; | 768 | unsigned long flags; |
982 | 769 | ||
983 | priv = container_of(work, struct ccw_device_private, kick_work); | ||
984 | cdev = priv->cdev; | ||
985 | sch = to_subchannel(cdev->dev.parent); | 770 | sch = to_subchannel(cdev->dev.parent); |
986 | /* | 771 | /* |
987 | * Check if subchannel is still registered. It may have become | 772 | * Check if subchannel is still registered. It may have become |
@@ -1008,6 +793,7 @@ io_subchannel_register(struct work_struct *work) | |||
1008 | cdev->private->dev_id.ssid, | 793 | cdev->private->dev_id.ssid, |
1009 | cdev->private->dev_id.devno); | 794 | cdev->private->dev_id.devno); |
1010 | } | 795 | } |
796 | adjust_init_count = 0; | ||
1011 | goto out; | 797 | goto out; |
1012 | } | 798 | } |
1013 | /* | 799 | /* |
@@ -1033,41 +819,23 @@ out: | |||
1033 | cdev->private->flags.recog_done = 1; | 819 | cdev->private->flags.recog_done = 1; |
1034 | wake_up(&cdev->private->wait_q); | 820 | wake_up(&cdev->private->wait_q); |
1035 | out_err: | 821 | out_err: |
1036 | /* Release reference for workqueue processing. */ | 822 | if (adjust_init_count && atomic_dec_and_test(&ccw_device_init_count)) |
1037 | put_device(&cdev->dev); | ||
1038 | if (atomic_dec_and_test(&ccw_device_init_count)) | ||
1039 | wake_up(&ccw_device_init_wq); | 823 | wake_up(&ccw_device_init_wq); |
1040 | } | 824 | } |
1041 | 825 | ||
1042 | static void ccw_device_call_sch_unregister(struct work_struct *work) | 826 | static void ccw_device_call_sch_unregister(struct ccw_device *cdev) |
1043 | { | 827 | { |
1044 | struct ccw_device_private *priv; | ||
1045 | struct ccw_device *cdev; | ||
1046 | struct subchannel *sch; | 828 | struct subchannel *sch; |
1047 | 829 | ||
1048 | priv = container_of(work, struct ccw_device_private, kick_work); | ||
1049 | cdev = priv->cdev; | ||
1050 | /* Get subchannel reference for local processing. */ | 830 | /* Get subchannel reference for local processing. */ |
1051 | if (!get_device(cdev->dev.parent)) | 831 | if (!get_device(cdev->dev.parent)) |
1052 | return; | 832 | return; |
1053 | sch = to_subchannel(cdev->dev.parent); | 833 | sch = to_subchannel(cdev->dev.parent); |
1054 | css_sch_device_unregister(sch); | 834 | css_sch_device_unregister(sch); |
1055 | /* Release cdev reference for workqueue processing.*/ | ||
1056 | put_device(&cdev->dev); | ||
1057 | /* Release subchannel reference for local processing. */ | 835 | /* Release subchannel reference for local processing. */ |
1058 | put_device(&sch->dev); | 836 | put_device(&sch->dev); |
1059 | } | 837 | } |
1060 | 838 | ||
1061 | void ccw_device_schedule_sch_unregister(struct ccw_device *cdev) | ||
1062 | { | ||
1063 | /* Get cdev reference for workqueue processing. */ | ||
1064 | if (!get_device(&cdev->dev)) | ||
1065 | return; | ||
1066 | PREPARE_WORK(&cdev->private->kick_work, | ||
1067 | ccw_device_call_sch_unregister); | ||
1068 | queue_work(slow_path_wq, &cdev->private->kick_work); | ||
1069 | } | ||
1070 | |||
1071 | /* | 839 | /* |
1072 | * subchannel recognition done. Called from the state machine. | 840 | * subchannel recognition done. Called from the state machine. |
1073 | */ | 841 | */ |
@@ -1083,7 +851,8 @@ io_subchannel_recog_done(struct ccw_device *cdev) | |||
1083 | /* Device did not respond in time. */ | 851 | /* Device did not respond in time. */ |
1084 | case DEV_STATE_NOT_OPER: | 852 | case DEV_STATE_NOT_OPER: |
1085 | cdev->private->flags.recog_done = 1; | 853 | cdev->private->flags.recog_done = 1; |
1086 | ccw_device_schedule_sch_unregister(cdev); | 854 | /* Remove device found not operational. */ |
855 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); | ||
1087 | if (atomic_dec_and_test(&ccw_device_init_count)) | 856 | if (atomic_dec_and_test(&ccw_device_init_count)) |
1088 | wake_up(&ccw_device_init_wq); | 857 | wake_up(&ccw_device_init_wq); |
1089 | break; | 858 | break; |
@@ -1092,22 +861,15 @@ io_subchannel_recog_done(struct ccw_device *cdev) | |||
1092 | * We can't register the device in interrupt context so | 861 | * We can't register the device in interrupt context so |
1093 | * we schedule a work item. | 862 | * we schedule a work item. |
1094 | */ | 863 | */ |
1095 | if (!get_device(&cdev->dev)) | 864 | ccw_device_sched_todo(cdev, CDEV_TODO_REGISTER); |
1096 | break; | ||
1097 | PREPARE_WORK(&cdev->private->kick_work, | ||
1098 | io_subchannel_register); | ||
1099 | queue_work(slow_path_wq, &cdev->private->kick_work); | ||
1100 | break; | 865 | break; |
1101 | } | 866 | } |
1102 | } | 867 | } |
1103 | 868 | ||
1104 | static int | 869 | static void io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch) |
1105 | io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch) | ||
1106 | { | 870 | { |
1107 | int rc; | ||
1108 | struct ccw_device_private *priv; | 871 | struct ccw_device_private *priv; |
1109 | 872 | ||
1110 | sch_set_cdev(sch, cdev); | ||
1111 | cdev->ccwlock = sch->lock; | 873 | cdev->ccwlock = sch->lock; |
1112 | 874 | ||
1113 | /* Init private data. */ | 875 | /* Init private data. */ |
@@ -1125,62 +887,81 @@ io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch) | |||
1125 | 887 | ||
1126 | /* Start async. device sensing. */ | 888 | /* Start async. device sensing. */ |
1127 | spin_lock_irq(sch->lock); | 889 | spin_lock_irq(sch->lock); |
1128 | rc = ccw_device_recognition(cdev); | 890 | sch_set_cdev(sch, cdev); |
891 | ccw_device_recognition(cdev); | ||
1129 | spin_unlock_irq(sch->lock); | 892 | spin_unlock_irq(sch->lock); |
1130 | if (rc) { | ||
1131 | if (atomic_dec_and_test(&ccw_device_init_count)) | ||
1132 | wake_up(&ccw_device_init_wq); | ||
1133 | } | ||
1134 | return rc; | ||
1135 | } | 893 | } |
1136 | 894 | ||
1137 | static void ccw_device_move_to_sch(struct work_struct *work) | 895 | static int ccw_device_move_to_sch(struct ccw_device *cdev, |
896 | struct subchannel *sch) | ||
1138 | { | 897 | { |
1139 | struct ccw_device_private *priv; | 898 | struct subchannel *old_sch; |
1140 | int rc; | 899 | int rc, old_enabled = 0; |
1141 | struct subchannel *sch; | ||
1142 | struct ccw_device *cdev; | ||
1143 | struct subchannel *former_parent; | ||
1144 | 900 | ||
1145 | priv = container_of(work, struct ccw_device_private, kick_work); | 901 | old_sch = to_subchannel(cdev->dev.parent); |
1146 | sch = priv->sch; | 902 | /* Obtain child reference for new parent. */ |
1147 | cdev = priv->cdev; | ||
1148 | former_parent = to_subchannel(cdev->dev.parent); | ||
1149 | /* Get reference for new parent. */ | ||
1150 | if (!get_device(&sch->dev)) | 903 | if (!get_device(&sch->dev)) |
1151 | return; | 904 | return -ENODEV; |
905 | |||
906 | if (!sch_is_pseudo_sch(old_sch)) { | ||
907 | spin_lock_irq(old_sch->lock); | ||
908 | old_enabled = old_sch->schib.pmcw.ena; | ||
909 | rc = 0; | ||
910 | if (old_enabled) | ||
911 | rc = cio_disable_subchannel(old_sch); | ||
912 | spin_unlock_irq(old_sch->lock); | ||
913 | if (rc == -EBUSY) { | ||
914 | /* Release child reference for new parent. */ | ||
915 | put_device(&sch->dev); | ||
916 | return rc; | ||
917 | } | ||
918 | } | ||
919 | |||
1152 | mutex_lock(&sch->reg_mutex); | 920 | mutex_lock(&sch->reg_mutex); |
1153 | /* | ||
1154 | * Try to move the ccw device to its new subchannel. | ||
1155 | * Note: device_move() changes cdev->dev.parent | ||
1156 | */ | ||
1157 | rc = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV); | 921 | rc = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV); |
1158 | mutex_unlock(&sch->reg_mutex); | 922 | mutex_unlock(&sch->reg_mutex); |
1159 | if (rc) { | 923 | if (rc) { |
1160 | CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to subchannel " | 924 | CIO_MSG_EVENT(0, "device_move(0.%x.%04x,0.%x.%04x)=%d\n", |
1161 | "0.%x.%04x failed (ret=%d)!\n", | ||
1162 | cdev->private->dev_id.ssid, | 925 | cdev->private->dev_id.ssid, |
1163 | cdev->private->dev_id.devno, sch->schid.ssid, | 926 | cdev->private->dev_id.devno, sch->schid.ssid, |
1164 | sch->schid.sch_no, rc); | 927 | sch->schib.pmcw.dev, rc); |
1165 | css_sch_device_unregister(sch); | 928 | if (old_enabled) { |
1166 | /* Put reference for new parent again. */ | 929 | /* Try to reenable the old subchannel. */ |
930 | spin_lock_irq(old_sch->lock); | ||
931 | cio_enable_subchannel(old_sch, (u32)(addr_t)old_sch); | ||
932 | spin_unlock_irq(old_sch->lock); | ||
933 | } | ||
934 | /* Release child reference for new parent. */ | ||
1167 | put_device(&sch->dev); | 935 | put_device(&sch->dev); |
1168 | goto out; | 936 | return rc; |
1169 | } | 937 | } |
1170 | if (!sch_is_pseudo_sch(former_parent)) { | 938 | /* Clean up old subchannel. */ |
1171 | spin_lock_irq(former_parent->lock); | 939 | if (!sch_is_pseudo_sch(old_sch)) { |
1172 | sch_set_cdev(former_parent, NULL); | 940 | spin_lock_irq(old_sch->lock); |
1173 | spin_unlock_irq(former_parent->lock); | 941 | sch_set_cdev(old_sch, NULL); |
1174 | css_sch_device_unregister(former_parent); | 942 | spin_unlock_irq(old_sch->lock); |
1175 | /* Reset intparm to zeroes. */ | 943 | css_schedule_eval(old_sch->schid); |
1176 | former_parent->config.intparm = 0; | ||
1177 | cio_commit_config(former_parent); | ||
1178 | } | 944 | } |
1179 | sch_attach_device(sch, cdev); | 945 | /* Release child reference for old parent. */ |
1180 | out: | 946 | put_device(&old_sch->dev); |
1181 | /* Put reference for old parent. */ | 947 | /* Initialize new subchannel. */ |
1182 | put_device(&former_parent->dev); | 948 | spin_lock_irq(sch->lock); |
1183 | put_device(&cdev->dev); | 949 | cdev->private->schid = sch->schid; |
950 | cdev->ccwlock = sch->lock; | ||
951 | if (!sch_is_pseudo_sch(sch)) | ||
952 | sch_set_cdev(sch, cdev); | ||
953 | spin_unlock_irq(sch->lock); | ||
954 | if (!sch_is_pseudo_sch(sch)) | ||
955 | css_update_ssd_info(sch); | ||
956 | return 0; | ||
957 | } | ||
958 | |||
959 | static int ccw_device_move_to_orph(struct ccw_device *cdev) | ||
960 | { | ||
961 | struct subchannel *sch = to_subchannel(cdev->dev.parent); | ||
962 | struct channel_subsystem *css = to_css(sch->dev.parent); | ||
963 | |||
964 | return ccw_device_move_to_sch(cdev, css->pseudo_subchannel); | ||
1184 | } | 965 | } |
1185 | 966 | ||
1186 | static void io_subchannel_irq(struct subchannel *sch) | 967 | static void io_subchannel_irq(struct subchannel *sch) |
@@ -1199,9 +980,6 @@ void io_subchannel_init_config(struct subchannel *sch) | |||
1199 | { | 980 | { |
1200 | memset(&sch->config, 0, sizeof(sch->config)); | 981 | memset(&sch->config, 0, sizeof(sch->config)); |
1201 | sch->config.csense = 1; | 982 | sch->config.csense = 1; |
1202 | /* Use subchannel mp mode when there is more than 1 installed CHPID. */ | ||
1203 | if ((sch->schib.pmcw.pim & (sch->schib.pmcw.pim - 1)) != 0) | ||
1204 | sch->config.mp = 1; | ||
1205 | } | 983 | } |
1206 | 984 | ||
1207 | static void io_subchannel_init_fields(struct subchannel *sch) | 985 | static void io_subchannel_init_fields(struct subchannel *sch) |
@@ -1222,23 +1000,6 @@ static void io_subchannel_init_fields(struct subchannel *sch) | |||
1222 | io_subchannel_init_config(sch); | 1000 | io_subchannel_init_config(sch); |
1223 | } | 1001 | } |
1224 | 1002 | ||
1225 | static void io_subchannel_do_unreg(struct work_struct *work) | ||
1226 | { | ||
1227 | struct subchannel *sch; | ||
1228 | |||
1229 | sch = container_of(work, struct subchannel, work); | ||
1230 | css_sch_device_unregister(sch); | ||
1231 | put_device(&sch->dev); | ||
1232 | } | ||
1233 | |||
1234 | /* Schedule unregister if we have no cdev. */ | ||
1235 | static void io_subchannel_schedule_removal(struct subchannel *sch) | ||
1236 | { | ||
1237 | get_device(&sch->dev); | ||
1238 | INIT_WORK(&sch->work, io_subchannel_do_unreg); | ||
1239 | queue_work(slow_path_wq, &sch->work); | ||
1240 | } | ||
1241 | |||
1242 | /* | 1003 | /* |
1243 | * Note: We always return 0 so that we bind to the device even on error. | 1004 | * Note: We always return 0 so that we bind to the device even on error. |
1244 | * This is needed so that our remove function is called on unregister. | 1005 | * This is needed so that our remove function is called on unregister. |
@@ -1247,8 +1008,6 @@ static int io_subchannel_probe(struct subchannel *sch) | |||
1247 | { | 1008 | { |
1248 | struct ccw_device *cdev; | 1009 | struct ccw_device *cdev; |
1249 | int rc; | 1010 | int rc; |
1250 | unsigned long flags; | ||
1251 | struct ccw_dev_id dev_id; | ||
1252 | 1011 | ||
1253 | if (cio_is_console(sch->schid)) { | 1012 | if (cio_is_console(sch->schid)) { |
1254 | rc = sysfs_create_group(&sch->dev.kobj, | 1013 | rc = sysfs_create_group(&sch->dev.kobj, |
@@ -1268,6 +1027,7 @@ static int io_subchannel_probe(struct subchannel *sch) | |||
1268 | cdev = sch_get_cdev(sch); | 1027 | cdev = sch_get_cdev(sch); |
1269 | cdev->dev.groups = ccwdev_attr_groups; | 1028 | cdev->dev.groups = ccwdev_attr_groups; |
1270 | device_initialize(&cdev->dev); | 1029 | device_initialize(&cdev->dev); |
1030 | cdev->private->flags.initialized = 1; | ||
1271 | ccw_device_register(cdev); | 1031 | ccw_device_register(cdev); |
1272 | /* | 1032 | /* |
1273 | * Check if the device is already online. If it is | 1033 | * Check if the device is already online. If it is |
@@ -1292,44 +1052,14 @@ static int io_subchannel_probe(struct subchannel *sch) | |||
1292 | sch->private = kzalloc(sizeof(struct io_subchannel_private), | 1052 | sch->private = kzalloc(sizeof(struct io_subchannel_private), |
1293 | GFP_KERNEL | GFP_DMA); | 1053 | GFP_KERNEL | GFP_DMA); |
1294 | if (!sch->private) | 1054 | if (!sch->private) |
1295 | goto out_err; | 1055 | goto out_schedule; |
1296 | /* | 1056 | css_schedule_eval(sch->schid); |
1297 | * First check if a fitting device may be found amongst the | ||
1298 | * disconnected devices or in the orphanage. | ||
1299 | */ | ||
1300 | dev_id.devno = sch->schib.pmcw.dev; | ||
1301 | dev_id.ssid = sch->schid.ssid; | ||
1302 | cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL); | ||
1303 | if (!cdev) | ||
1304 | cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent), | ||
1305 | &dev_id); | ||
1306 | if (cdev) { | ||
1307 | /* | ||
1308 | * Schedule moving the device until when we have a registered | ||
1309 | * subchannel to move to and succeed the probe. We can | ||
1310 | * unregister later again, when the probe is through. | ||
1311 | */ | ||
1312 | cdev->private->sch = sch; | ||
1313 | PREPARE_WORK(&cdev->private->kick_work, | ||
1314 | ccw_device_move_to_sch); | ||
1315 | queue_work(slow_path_wq, &cdev->private->kick_work); | ||
1316 | return 0; | ||
1317 | } | ||
1318 | cdev = io_subchannel_create_ccwdev(sch); | ||
1319 | if (IS_ERR(cdev)) | ||
1320 | goto out_err; | ||
1321 | rc = io_subchannel_recog(cdev, sch); | ||
1322 | if (rc) { | ||
1323 | spin_lock_irqsave(sch->lock, flags); | ||
1324 | io_subchannel_recog_done(cdev); | ||
1325 | spin_unlock_irqrestore(sch->lock, flags); | ||
1326 | } | ||
1327 | return 0; | 1057 | return 0; |
1328 | out_err: | 1058 | |
1329 | kfree(sch->private); | ||
1330 | sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group); | ||
1331 | out_schedule: | 1059 | out_schedule: |
1332 | io_subchannel_schedule_removal(sch); | 1060 | spin_lock_irq(sch->lock); |
1061 | css_sched_sch_todo(sch, SCH_TODO_UNREG); | ||
1062 | spin_unlock_irq(sch->lock); | ||
1333 | return 0; | 1063 | return 0; |
1334 | } | 1064 | } |
1335 | 1065 | ||
@@ -1337,32 +1067,23 @@ static int | |||
1337 | io_subchannel_remove (struct subchannel *sch) | 1067 | io_subchannel_remove (struct subchannel *sch) |
1338 | { | 1068 | { |
1339 | struct ccw_device *cdev; | 1069 | struct ccw_device *cdev; |
1340 | unsigned long flags; | ||
1341 | 1070 | ||
1342 | cdev = sch_get_cdev(sch); | 1071 | cdev = sch_get_cdev(sch); |
1343 | if (!cdev) | 1072 | if (!cdev) |
1344 | return 0; | 1073 | goto out_free; |
1074 | io_subchannel_quiesce(sch); | ||
1345 | /* Set ccw device to not operational and drop reference. */ | 1075 | /* Set ccw device to not operational and drop reference. */ |
1346 | spin_lock_irqsave(cdev->ccwlock, flags); | 1076 | spin_lock_irq(cdev->ccwlock); |
1347 | sch_set_cdev(sch, NULL); | 1077 | sch_set_cdev(sch, NULL); |
1348 | cdev->private->state = DEV_STATE_NOT_OPER; | 1078 | cdev->private->state = DEV_STATE_NOT_OPER; |
1349 | spin_unlock_irqrestore(cdev->ccwlock, flags); | 1079 | spin_unlock_irq(cdev->ccwlock); |
1350 | ccw_device_unregister(cdev); | 1080 | ccw_device_unregister(cdev); |
1081 | out_free: | ||
1351 | kfree(sch->private); | 1082 | kfree(sch->private); |
1352 | sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group); | 1083 | sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group); |
1353 | return 0; | 1084 | return 0; |
1354 | } | 1085 | } |
1355 | 1086 | ||
1356 | static int io_subchannel_notify(struct subchannel *sch, int event) | ||
1357 | { | ||
1358 | struct ccw_device *cdev; | ||
1359 | |||
1360 | cdev = sch_get_cdev(sch); | ||
1361 | if (!cdev) | ||
1362 | return 0; | ||
1363 | return ccw_device_notify(cdev, event); | ||
1364 | } | ||
1365 | |||
1366 | static void io_subchannel_verify(struct subchannel *sch) | 1087 | static void io_subchannel_verify(struct subchannel *sch) |
1367 | { | 1088 | { |
1368 | struct ccw_device *cdev; | 1089 | struct ccw_device *cdev; |
@@ -1372,36 +1093,6 @@ static void io_subchannel_verify(struct subchannel *sch) | |||
1372 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); | 1093 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
1373 | } | 1094 | } |
1374 | 1095 | ||
1375 | static int check_for_io_on_path(struct subchannel *sch, int mask) | ||
1376 | { | ||
1377 | if (cio_update_schib(sch)) | ||
1378 | return 0; | ||
1379 | if (scsw_actl(&sch->schib.scsw) && sch->schib.pmcw.lpum == mask) | ||
1380 | return 1; | ||
1381 | return 0; | ||
1382 | } | ||
1383 | |||
1384 | static void terminate_internal_io(struct subchannel *sch, | ||
1385 | struct ccw_device *cdev) | ||
1386 | { | ||
1387 | if (cio_clear(sch)) { | ||
1388 | /* Recheck device in case clear failed. */ | ||
1389 | sch->lpm = 0; | ||
1390 | if (cdev->online) | ||
1391 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); | ||
1392 | else | ||
1393 | css_schedule_eval(sch->schid); | ||
1394 | return; | ||
1395 | } | ||
1396 | cdev->private->state = DEV_STATE_CLEAR_VERIFY; | ||
1397 | /* Request retry of internal operation. */ | ||
1398 | cdev->private->flags.intretry = 1; | ||
1399 | /* Call handler. */ | ||
1400 | if (cdev->handler) | ||
1401 | cdev->handler(cdev, cdev->private->intparm, | ||
1402 | ERR_PTR(-EIO)); | ||
1403 | } | ||
1404 | |||
1405 | static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask) | 1096 | static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask) |
1406 | { | 1097 | { |
1407 | struct ccw_device *cdev; | 1098 | struct ccw_device *cdev; |
@@ -1409,18 +1100,24 @@ static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask) | |||
1409 | cdev = sch_get_cdev(sch); | 1100 | cdev = sch_get_cdev(sch); |
1410 | if (!cdev) | 1101 | if (!cdev) |
1411 | return; | 1102 | return; |
1412 | if (check_for_io_on_path(sch, mask)) { | 1103 | if (cio_update_schib(sch)) |
1413 | if (cdev->private->state == DEV_STATE_ONLINE) | 1104 | goto err; |
1414 | ccw_device_kill_io(cdev); | 1105 | /* Check for I/O on path. */ |
1415 | else { | 1106 | if (scsw_actl(&sch->schib.scsw) == 0 || sch->schib.pmcw.lpum != mask) |
1416 | terminate_internal_io(sch, cdev); | 1107 | goto out; |
1417 | /* Re-start path verification. */ | 1108 | if (cdev->private->state == DEV_STATE_ONLINE) { |
1418 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); | 1109 | ccw_device_kill_io(cdev); |
1419 | } | 1110 | goto out; |
1420 | } else | 1111 | } |
1421 | /* trigger path verification. */ | 1112 | if (cio_clear(sch)) |
1422 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); | 1113 | goto err; |
1114 | out: | ||
1115 | /* Trigger path verification. */ | ||
1116 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); | ||
1117 | return; | ||
1423 | 1118 | ||
1119 | err: | ||
1120 | dev_fsm_event(cdev, DEV_EVENT_NOTOPER); | ||
1424 | } | 1121 | } |
1425 | 1122 | ||
1426 | static int io_subchannel_chp_event(struct subchannel *sch, | 1123 | static int io_subchannel_chp_event(struct subchannel *sch, |
@@ -1457,46 +1154,41 @@ static int io_subchannel_chp_event(struct subchannel *sch, | |||
1457 | return 0; | 1154 | return 0; |
1458 | } | 1155 | } |
1459 | 1156 | ||
1460 | static void | 1157 | static void io_subchannel_quiesce(struct subchannel *sch) |
1461 | io_subchannel_shutdown(struct subchannel *sch) | ||
1462 | { | 1158 | { |
1463 | struct ccw_device *cdev; | 1159 | struct ccw_device *cdev; |
1464 | int ret; | 1160 | int ret; |
1465 | 1161 | ||
1162 | spin_lock_irq(sch->lock); | ||
1466 | cdev = sch_get_cdev(sch); | 1163 | cdev = sch_get_cdev(sch); |
1467 | |||
1468 | if (cio_is_console(sch->schid)) | 1164 | if (cio_is_console(sch->schid)) |
1469 | return; | 1165 | goto out_unlock; |
1470 | if (!sch->schib.pmcw.ena) | 1166 | if (!sch->schib.pmcw.ena) |
1471 | /* Nothing to do. */ | 1167 | goto out_unlock; |
1472 | return; | ||
1473 | ret = cio_disable_subchannel(sch); | 1168 | ret = cio_disable_subchannel(sch); |
1474 | if (ret != -EBUSY) | 1169 | if (ret != -EBUSY) |
1475 | /* Subchannel is disabled, we're done. */ | 1170 | goto out_unlock; |
1476 | return; | ||
1477 | cdev->private->state = DEV_STATE_QUIESCE; | ||
1478 | if (cdev->handler) | 1171 | if (cdev->handler) |
1479 | cdev->handler(cdev, cdev->private->intparm, | 1172 | cdev->handler(cdev, cdev->private->intparm, ERR_PTR(-EIO)); |
1480 | ERR_PTR(-EIO)); | 1173 | while (ret == -EBUSY) { |
1481 | ret = ccw_device_cancel_halt_clear(cdev); | 1174 | cdev->private->state = DEV_STATE_QUIESCE; |
1482 | if (ret == -EBUSY) { | 1175 | ret = ccw_device_cancel_halt_clear(cdev); |
1483 | ccw_device_set_timeout(cdev, HZ/10); | 1176 | if (ret == -EBUSY) { |
1484 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); | 1177 | ccw_device_set_timeout(cdev, HZ/10); |
1178 | spin_unlock_irq(sch->lock); | ||
1179 | wait_event(cdev->private->wait_q, | ||
1180 | cdev->private->state != DEV_STATE_QUIESCE); | ||
1181 | spin_lock_irq(sch->lock); | ||
1182 | } | ||
1183 | ret = cio_disable_subchannel(sch); | ||
1485 | } | 1184 | } |
1486 | cio_disable_subchannel(sch); | 1185 | out_unlock: |
1186 | spin_unlock_irq(sch->lock); | ||
1487 | } | 1187 | } |
1488 | 1188 | ||
1489 | static int io_subchannel_get_status(struct subchannel *sch) | 1189 | static void io_subchannel_shutdown(struct subchannel *sch) |
1490 | { | 1190 | { |
1491 | struct schib schib; | 1191 | io_subchannel_quiesce(sch); |
1492 | |||
1493 | if (stsch(sch->schid, &schib) || !schib.pmcw.dnv) | ||
1494 | return CIO_GONE; | ||
1495 | if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev)) | ||
1496 | return CIO_REVALIDATE; | ||
1497 | if (!sch->lpm) | ||
1498 | return CIO_NO_PATH; | ||
1499 | return CIO_OPER; | ||
1500 | } | 1192 | } |
1501 | 1193 | ||
1502 | static int device_is_disconnected(struct ccw_device *cdev) | 1194 | static int device_is_disconnected(struct ccw_device *cdev) |
@@ -1575,20 +1267,16 @@ static void ccw_device_schedule_recovery(void) | |||
1575 | static int purge_fn(struct device *dev, void *data) | 1267 | static int purge_fn(struct device *dev, void *data) |
1576 | { | 1268 | { |
1577 | struct ccw_device *cdev = to_ccwdev(dev); | 1269 | struct ccw_device *cdev = to_ccwdev(dev); |
1578 | struct ccw_device_private *priv = cdev->private; | 1270 | struct ccw_dev_id *id = &cdev->private->dev_id; |
1579 | int unreg; | ||
1580 | 1271 | ||
1581 | spin_lock_irq(cdev->ccwlock); | 1272 | spin_lock_irq(cdev->ccwlock); |
1582 | unreg = is_blacklisted(priv->dev_id.ssid, priv->dev_id.devno) && | 1273 | if (is_blacklisted(id->ssid, id->devno) && |
1583 | (priv->state == DEV_STATE_OFFLINE); | 1274 | (cdev->private->state == DEV_STATE_OFFLINE)) { |
1275 | CIO_MSG_EVENT(3, "ccw: purging 0.%x.%04x\n", id->ssid, | ||
1276 | id->devno); | ||
1277 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); | ||
1278 | } | ||
1584 | spin_unlock_irq(cdev->ccwlock); | 1279 | spin_unlock_irq(cdev->ccwlock); |
1585 | if (!unreg) | ||
1586 | goto out; | ||
1587 | CIO_MSG_EVENT(3, "ccw: purging 0.%x.%04x\n", priv->dev_id.ssid, | ||
1588 | priv->dev_id.devno); | ||
1589 | ccw_device_schedule_sch_unregister(cdev); | ||
1590 | |||
1591 | out: | ||
1592 | /* Abort loop in case of pending signal. */ | 1280 | /* Abort loop in case of pending signal. */ |
1593 | if (signal_pending(current)) | 1281 | if (signal_pending(current)) |
1594 | return -EINTR; | 1282 | return -EINTR; |
@@ -1630,91 +1318,177 @@ void ccw_device_set_notoper(struct ccw_device *cdev) | |||
1630 | cdev->private->state = DEV_STATE_NOT_OPER; | 1318 | cdev->private->state = DEV_STATE_NOT_OPER; |
1631 | } | 1319 | } |
1632 | 1320 | ||
1633 | static int io_subchannel_sch_event(struct subchannel *sch, int slow) | 1321 | enum io_sch_action { |
1322 | IO_SCH_UNREG, | ||
1323 | IO_SCH_ORPH_UNREG, | ||
1324 | IO_SCH_ATTACH, | ||
1325 | IO_SCH_UNREG_ATTACH, | ||
1326 | IO_SCH_ORPH_ATTACH, | ||
1327 | IO_SCH_REPROBE, | ||
1328 | IO_SCH_VERIFY, | ||
1329 | IO_SCH_DISC, | ||
1330 | IO_SCH_NOP, | ||
1331 | }; | ||
1332 | |||
1333 | static enum io_sch_action sch_get_action(struct subchannel *sch) | ||
1634 | { | 1334 | { |
1635 | int event, ret, disc; | ||
1636 | unsigned long flags; | ||
1637 | enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE, DISC } action; | ||
1638 | struct ccw_device *cdev; | 1335 | struct ccw_device *cdev; |
1639 | 1336 | ||
1640 | spin_lock_irqsave(sch->lock, flags); | ||
1641 | cdev = sch_get_cdev(sch); | 1337 | cdev = sch_get_cdev(sch); |
1642 | disc = device_is_disconnected(cdev); | 1338 | if (cio_update_schib(sch)) { |
1643 | if (disc && slow) { | 1339 | /* Not operational. */ |
1644 | /* Disconnected devices are evaluated directly only.*/ | 1340 | if (!cdev) |
1645 | spin_unlock_irqrestore(sch->lock, flags); | 1341 | return IO_SCH_UNREG; |
1646 | return 0; | 1342 | if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK) |
1343 | return IO_SCH_UNREG; | ||
1344 | return IO_SCH_ORPH_UNREG; | ||
1647 | } | 1345 | } |
1648 | /* No interrupt after machine check - kill pending timers. */ | 1346 | /* Operational. */ |
1649 | if (cdev) | 1347 | if (!cdev) |
1650 | ccw_device_set_timeout(cdev, 0); | 1348 | return IO_SCH_ATTACH; |
1651 | if (!disc && !slow) { | 1349 | if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) { |
1652 | /* Non-disconnected devices are evaluated on the slow path. */ | 1350 | if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK) |
1653 | spin_unlock_irqrestore(sch->lock, flags); | 1351 | return IO_SCH_UNREG_ATTACH; |
1654 | return -EAGAIN; | 1352 | return IO_SCH_ORPH_ATTACH; |
1655 | } | 1353 | } |
1656 | event = io_subchannel_get_status(sch); | 1354 | if ((sch->schib.pmcw.pam & sch->opm) == 0) { |
1657 | CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n", | 1355 | if (ccw_device_notify(cdev, CIO_NO_PATH) != NOTIFY_OK) |
1658 | sch->schid.ssid, sch->schid.sch_no, event, | 1356 | return IO_SCH_UNREG; |
1659 | disc ? "disconnected" : "normal", | 1357 | return IO_SCH_DISC; |
1660 | slow ? "slow" : "fast"); | 1358 | } |
1661 | /* Analyze subchannel status. */ | 1359 | if (device_is_disconnected(cdev)) |
1662 | action = NONE; | 1360 | return IO_SCH_REPROBE; |
1663 | switch (event) { | 1361 | if (cdev->online) |
1664 | case CIO_NO_PATH: | 1362 | return IO_SCH_VERIFY; |
1665 | if (disc) { | 1363 | return IO_SCH_NOP; |
1666 | /* Check if paths have become available. */ | 1364 | } |
1667 | action = REPROBE; | 1365 | |
1668 | break; | 1366 | /** |
1367 | * io_subchannel_sch_event - process subchannel event | ||
1368 | * @sch: subchannel | ||
1369 | * @process: non-zero if function is called in process context | ||
1370 | * | ||
1371 | * An unspecified event occurred for this subchannel. Adjust data according | ||
1372 | * to the current operational state of the subchannel and device. Return | ||
1373 | * zero when the event has been handled sufficiently or -EAGAIN when this | ||
1374 | * function should be called again in process context. | ||
1375 | */ | ||
1376 | static int io_subchannel_sch_event(struct subchannel *sch, int process) | ||
1377 | { | ||
1378 | unsigned long flags; | ||
1379 | struct ccw_device *cdev; | ||
1380 | struct ccw_dev_id dev_id; | ||
1381 | enum io_sch_action action; | ||
1382 | int rc = -EAGAIN; | ||
1383 | |||
1384 | spin_lock_irqsave(sch->lock, flags); | ||
1385 | if (!device_is_registered(&sch->dev)) | ||
1386 | goto out_unlock; | ||
1387 | if (work_pending(&sch->todo_work)) | ||
1388 | goto out_unlock; | ||
1389 | cdev = sch_get_cdev(sch); | ||
1390 | if (cdev && work_pending(&cdev->private->todo_work)) | ||
1391 | goto out_unlock; | ||
1392 | action = sch_get_action(sch); | ||
1393 | CIO_MSG_EVENT(2, "event: sch 0.%x.%04x, process=%d, action=%d\n", | ||
1394 | sch->schid.ssid, sch->schid.sch_no, process, | ||
1395 | action); | ||
1396 | /* Perform immediate actions while holding the lock. */ | ||
1397 | switch (action) { | ||
1398 | case IO_SCH_REPROBE: | ||
1399 | /* Trigger device recognition. */ | ||
1400 | ccw_device_trigger_reprobe(cdev); | ||
1401 | rc = 0; | ||
1402 | goto out_unlock; | ||
1403 | case IO_SCH_VERIFY: | ||
1404 | if (cdev->private->flags.resuming == 1) { | ||
1405 | if (cio_enable_subchannel(sch, (u32)(addr_t)sch)) { | ||
1406 | ccw_device_set_notoper(cdev); | ||
1407 | break; | ||
1408 | } | ||
1669 | } | 1409 | } |
1670 | /* fall through */ | 1410 | /* Trigger path verification. */ |
1671 | case CIO_GONE: | 1411 | io_subchannel_verify(sch); |
1672 | /* Ask driver what to do with device. */ | 1412 | rc = 0; |
1673 | if (io_subchannel_notify(sch, event)) | 1413 | goto out_unlock; |
1674 | action = DISC; | 1414 | case IO_SCH_DISC: |
1675 | else | 1415 | ccw_device_set_disconnected(cdev); |
1676 | action = UNREGISTER; | 1416 | rc = 0; |
1417 | goto out_unlock; | ||
1418 | case IO_SCH_ORPH_UNREG: | ||
1419 | case IO_SCH_ORPH_ATTACH: | ||
1420 | ccw_device_set_disconnected(cdev); | ||
1677 | break; | 1421 | break; |
1678 | case CIO_REVALIDATE: | 1422 | case IO_SCH_UNREG_ATTACH: |
1679 | /* Device will be removed, so no notify necessary. */ | 1423 | case IO_SCH_UNREG: |
1680 | if (disc) | 1424 | if (cdev) |
1681 | /* Reprobe because immediate unregister might block. */ | 1425 | ccw_device_set_notoper(cdev); |
1682 | action = REPROBE; | ||
1683 | else | ||
1684 | action = UNREGISTER_PROBE; | ||
1685 | break; | 1426 | break; |
1686 | case CIO_OPER: | 1427 | case IO_SCH_NOP: |
1687 | if (disc) | 1428 | rc = 0; |
1688 | /* Get device operational again. */ | 1429 | goto out_unlock; |
1689 | action = REPROBE; | 1430 | default: |
1690 | break; | 1431 | break; |
1691 | } | 1432 | } |
1692 | /* Perform action. */ | 1433 | spin_unlock_irqrestore(sch->lock, flags); |
1693 | ret = 0; | 1434 | /* All other actions require process context. */ |
1435 | if (!process) | ||
1436 | goto out; | ||
1437 | /* Handle attached ccw device. */ | ||
1694 | switch (action) { | 1438 | switch (action) { |
1695 | case UNREGISTER: | 1439 | case IO_SCH_ORPH_UNREG: |
1696 | case UNREGISTER_PROBE: | 1440 | case IO_SCH_ORPH_ATTACH: |
1697 | ccw_device_set_notoper(cdev); | 1441 | /* Move ccw device to orphanage. */ |
1698 | /* Unregister device (will use subchannel lock). */ | 1442 | rc = ccw_device_move_to_orph(cdev); |
1699 | spin_unlock_irqrestore(sch->lock, flags); | 1443 | if (rc) |
1700 | css_sch_device_unregister(sch); | 1444 | goto out; |
1701 | spin_lock_irqsave(sch->lock, flags); | ||
1702 | break; | 1445 | break; |
1703 | case REPROBE: | 1446 | case IO_SCH_UNREG_ATTACH: |
1704 | ccw_device_trigger_reprobe(cdev); | 1447 | /* Unregister ccw device. */ |
1448 | if (!cdev->private->flags.resuming) | ||
1449 | ccw_device_unregister(cdev); | ||
1705 | break; | 1450 | break; |
1706 | case DISC: | 1451 | default: |
1707 | ccw_device_set_disconnected(cdev); | 1452 | break; |
1453 | } | ||
1454 | /* Handle subchannel. */ | ||
1455 | switch (action) { | ||
1456 | case IO_SCH_ORPH_UNREG: | ||
1457 | case IO_SCH_UNREG: | ||
1458 | if (!cdev || !cdev->private->flags.resuming) | ||
1459 | css_sch_device_unregister(sch); | ||
1460 | break; | ||
1461 | case IO_SCH_ORPH_ATTACH: | ||
1462 | case IO_SCH_UNREG_ATTACH: | ||
1463 | case IO_SCH_ATTACH: | ||
1464 | dev_id.ssid = sch->schid.ssid; | ||
1465 | dev_id.devno = sch->schib.pmcw.dev; | ||
1466 | cdev = get_ccwdev_by_dev_id(&dev_id); | ||
1467 | if (!cdev) { | ||
1468 | sch_create_and_recog_new_device(sch); | ||
1469 | break; | ||
1470 | } | ||
1471 | rc = ccw_device_move_to_sch(cdev, sch); | ||
1472 | if (rc) { | ||
1473 | /* Release reference from get_ccwdev_by_dev_id() */ | ||
1474 | put_device(&cdev->dev); | ||
1475 | goto out; | ||
1476 | } | ||
1477 | spin_lock_irqsave(sch->lock, flags); | ||
1478 | ccw_device_trigger_reprobe(cdev); | ||
1479 | spin_unlock_irqrestore(sch->lock, flags); | ||
1480 | /* Release reference from get_ccwdev_by_dev_id() */ | ||
1481 | put_device(&cdev->dev); | ||
1708 | break; | 1482 | break; |
1709 | default: | 1483 | default: |
1710 | break; | 1484 | break; |
1711 | } | 1485 | } |
1712 | spin_unlock_irqrestore(sch->lock, flags); | 1486 | return 0; |
1713 | /* Probe if necessary. */ | ||
1714 | if (action == UNREGISTER_PROBE) | ||
1715 | ret = css_probe_device(sch->schid); | ||
1716 | 1487 | ||
1717 | return ret; | 1488 | out_unlock: |
1489 | spin_unlock_irqrestore(sch->lock, flags); | ||
1490 | out: | ||
1491 | return rc; | ||
1718 | } | 1492 | } |
1719 | 1493 | ||
1720 | #ifdef CONFIG_CCW_CONSOLE | 1494 | #ifdef CONFIG_CCW_CONSOLE |
@@ -1744,10 +1518,8 @@ static int ccw_device_console_enable(struct ccw_device *cdev, | |||
1744 | sch->driver = &io_subchannel_driver; | 1518 | sch->driver = &io_subchannel_driver; |
1745 | /* Initialize the ccw_device structure. */ | 1519 | /* Initialize the ccw_device structure. */ |
1746 | cdev->dev.parent= &sch->dev; | 1520 | cdev->dev.parent= &sch->dev; |
1747 | rc = io_subchannel_recog(cdev, sch); | 1521 | sch_set_cdev(sch, cdev); |
1748 | if (rc) | 1522 | io_subchannel_recog(cdev, sch); |
1749 | return rc; | ||
1750 | |||
1751 | /* Now wait for the async. recognition to come to an end. */ | 1523 | /* Now wait for the async. recognition to come to an end. */ |
1752 | spin_lock_irq(cdev->ccwlock); | 1524 | spin_lock_irq(cdev->ccwlock); |
1753 | while (!dev_fsm_final_state(cdev)) | 1525 | while (!dev_fsm_final_state(cdev)) |
@@ -1763,7 +1535,7 @@ static int ccw_device_console_enable(struct ccw_device *cdev, | |||
1763 | rc = 0; | 1535 | rc = 0; |
1764 | out_unlock: | 1536 | out_unlock: |
1765 | spin_unlock_irq(cdev->ccwlock); | 1537 | spin_unlock_irq(cdev->ccwlock); |
1766 | return 0; | 1538 | return rc; |
1767 | } | 1539 | } |
1768 | 1540 | ||
1769 | struct ccw_device * | 1541 | struct ccw_device * |
@@ -1919,7 +1691,7 @@ static int ccw_device_pm_prepare(struct device *dev) | |||
1919 | { | 1691 | { |
1920 | struct ccw_device *cdev = to_ccwdev(dev); | 1692 | struct ccw_device *cdev = to_ccwdev(dev); |
1921 | 1693 | ||
1922 | if (work_pending(&cdev->private->kick_work)) | 1694 | if (work_pending(&cdev->private->todo_work)) |
1923 | return -EAGAIN; | 1695 | return -EAGAIN; |
1924 | /* Fail while device is being set online/offline. */ | 1696 | /* Fail while device is being set online/offline. */ |
1925 | if (atomic_read(&cdev->private->onoff)) | 1697 | if (atomic_read(&cdev->private->onoff)) |
@@ -2005,119 +1777,117 @@ static int ccw_device_pm_thaw(struct device *dev) | |||
2005 | static void __ccw_device_pm_restore(struct ccw_device *cdev) | 1777 | static void __ccw_device_pm_restore(struct ccw_device *cdev) |
2006 | { | 1778 | { |
2007 | struct subchannel *sch = to_subchannel(cdev->dev.parent); | 1779 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
2008 | int ret; | ||
2009 | 1780 | ||
2010 | if (cio_is_console(sch->schid)) | 1781 | spin_lock_irq(sch->lock); |
2011 | goto out; | 1782 | if (cio_is_console(sch->schid)) { |
1783 | cio_enable_subchannel(sch, (u32)(addr_t)sch); | ||
1784 | goto out_unlock; | ||
1785 | } | ||
2012 | /* | 1786 | /* |
2013 | * While we were sleeping, devices may have gone or become | 1787 | * While we were sleeping, devices may have gone or become |
2014 | * available again. Kick re-detection. | 1788 | * available again. Kick re-detection. |
2015 | */ | 1789 | */ |
2016 | spin_lock_irq(sch->lock); | ||
2017 | cdev->private->flags.resuming = 1; | 1790 | cdev->private->flags.resuming = 1; |
2018 | ret = ccw_device_recognition(cdev); | 1791 | css_schedule_eval(sch->schid); |
1792 | spin_unlock_irq(sch->lock); | ||
1793 | css_complete_work(); | ||
1794 | |||
1795 | /* cdev may have been moved to a different subchannel. */ | ||
1796 | sch = to_subchannel(cdev->dev.parent); | ||
1797 | spin_lock_irq(sch->lock); | ||
1798 | if (cdev->private->state != DEV_STATE_ONLINE && | ||
1799 | cdev->private->state != DEV_STATE_OFFLINE) | ||
1800 | goto out_unlock; | ||
1801 | |||
1802 | ccw_device_recognition(cdev); | ||
2019 | spin_unlock_irq(sch->lock); | 1803 | spin_unlock_irq(sch->lock); |
2020 | if (ret) { | ||
2021 | CIO_MSG_EVENT(0, "Couldn't start recognition for device " | ||
2022 | "0.%x.%04x (ret=%d)\n", | ||
2023 | cdev->private->dev_id.ssid, | ||
2024 | cdev->private->dev_id.devno, ret); | ||
2025 | spin_lock_irq(sch->lock); | ||
2026 | cdev->private->state = DEV_STATE_DISCONNECTED; | ||
2027 | spin_unlock_irq(sch->lock); | ||
2028 | /* notify driver after the resume cb */ | ||
2029 | goto out; | ||
2030 | } | ||
2031 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev) || | 1804 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev) || |
2032 | cdev->private->state == DEV_STATE_DISCONNECTED); | 1805 | cdev->private->state == DEV_STATE_DISCONNECTED); |
1806 | spin_lock_irq(sch->lock); | ||
2033 | 1807 | ||
2034 | out: | 1808 | out_unlock: |
2035 | cdev->private->flags.resuming = 0; | 1809 | cdev->private->flags.resuming = 0; |
1810 | spin_unlock_irq(sch->lock); | ||
2036 | } | 1811 | } |
2037 | 1812 | ||
2038 | static int resume_handle_boxed(struct ccw_device *cdev) | 1813 | static int resume_handle_boxed(struct ccw_device *cdev) |
2039 | { | 1814 | { |
2040 | cdev->private->state = DEV_STATE_BOXED; | 1815 | cdev->private->state = DEV_STATE_BOXED; |
2041 | if (ccw_device_notify(cdev, CIO_BOXED)) | 1816 | if (ccw_device_notify(cdev, CIO_BOXED) == NOTIFY_OK) |
2042 | return 0; | 1817 | return 0; |
2043 | ccw_device_schedule_sch_unregister(cdev); | 1818 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); |
2044 | return -ENODEV; | 1819 | return -ENODEV; |
2045 | } | 1820 | } |
2046 | 1821 | ||
2047 | static int resume_handle_disc(struct ccw_device *cdev) | 1822 | static int resume_handle_disc(struct ccw_device *cdev) |
2048 | { | 1823 | { |
2049 | cdev->private->state = DEV_STATE_DISCONNECTED; | 1824 | cdev->private->state = DEV_STATE_DISCONNECTED; |
2050 | if (ccw_device_notify(cdev, CIO_GONE)) | 1825 | if (ccw_device_notify(cdev, CIO_GONE) == NOTIFY_OK) |
2051 | return 0; | 1826 | return 0; |
2052 | ccw_device_schedule_sch_unregister(cdev); | 1827 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); |
2053 | return -ENODEV; | 1828 | return -ENODEV; |
2054 | } | 1829 | } |
2055 | 1830 | ||
2056 | static int ccw_device_pm_restore(struct device *dev) | 1831 | static int ccw_device_pm_restore(struct device *dev) |
2057 | { | 1832 | { |
2058 | struct ccw_device *cdev = to_ccwdev(dev); | 1833 | struct ccw_device *cdev = to_ccwdev(dev); |
2059 | struct subchannel *sch = to_subchannel(cdev->dev.parent); | 1834 | struct subchannel *sch; |
2060 | int ret = 0, cm_enabled; | 1835 | int ret = 0; |
2061 | 1836 | ||
2062 | __ccw_device_pm_restore(cdev); | 1837 | __ccw_device_pm_restore(cdev); |
1838 | sch = to_subchannel(cdev->dev.parent); | ||
2063 | spin_lock_irq(sch->lock); | 1839 | spin_lock_irq(sch->lock); |
2064 | if (cio_is_console(sch->schid)) { | 1840 | if (cio_is_console(sch->schid)) |
2065 | cio_enable_subchannel(sch, (u32)(addr_t)sch); | ||
2066 | spin_unlock_irq(sch->lock); | ||
2067 | goto out_restore; | 1841 | goto out_restore; |
2068 | } | 1842 | |
2069 | cdev->private->flags.donotify = 0; | ||
2070 | /* check recognition results */ | 1843 | /* check recognition results */ |
2071 | switch (cdev->private->state) { | 1844 | switch (cdev->private->state) { |
2072 | case DEV_STATE_OFFLINE: | 1845 | case DEV_STATE_OFFLINE: |
1846 | case DEV_STATE_ONLINE: | ||
1847 | cdev->private->flags.donotify = 0; | ||
2073 | break; | 1848 | break; |
2074 | case DEV_STATE_BOXED: | 1849 | case DEV_STATE_BOXED: |
2075 | ret = resume_handle_boxed(cdev); | 1850 | ret = resume_handle_boxed(cdev); |
2076 | spin_unlock_irq(sch->lock); | ||
2077 | if (ret) | 1851 | if (ret) |
2078 | goto out; | 1852 | goto out_unlock; |
2079 | goto out_restore; | 1853 | goto out_restore; |
2080 | case DEV_STATE_DISCONNECTED: | ||
2081 | goto out_disc_unlock; | ||
2082 | default: | 1854 | default: |
2083 | goto out_unreg_unlock; | 1855 | ret = resume_handle_disc(cdev); |
2084 | } | 1856 | if (ret) |
2085 | /* check if the device id has changed */ | 1857 | goto out_unlock; |
2086 | if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) { | 1858 | goto out_restore; |
2087 | CIO_MSG_EVENT(0, "resume: sch 0.%x.%04x: failed (devno " | ||
2088 | "changed from %04x to %04x)\n", | ||
2089 | sch->schid.ssid, sch->schid.sch_no, | ||
2090 | cdev->private->dev_id.devno, | ||
2091 | sch->schib.pmcw.dev); | ||
2092 | goto out_unreg_unlock; | ||
2093 | } | 1859 | } |
2094 | /* check if the device type has changed */ | 1860 | /* check if the device type has changed */ |
2095 | if (!ccw_device_test_sense_data(cdev)) { | 1861 | if (!ccw_device_test_sense_data(cdev)) { |
2096 | ccw_device_update_sense_data(cdev); | 1862 | ccw_device_update_sense_data(cdev); |
2097 | PREPARE_WORK(&cdev->private->kick_work, | 1863 | ccw_device_sched_todo(cdev, CDEV_TODO_REBIND); |
2098 | ccw_device_do_unbind_bind); | ||
2099 | queue_work(ccw_device_work, &cdev->private->kick_work); | ||
2100 | ret = -ENODEV; | 1864 | ret = -ENODEV; |
2101 | goto out_unlock; | 1865 | goto out_unlock; |
2102 | } | 1866 | } |
2103 | if (!cdev->online) { | 1867 | if (!cdev->online) |
2104 | ret = 0; | ||
2105 | goto out_unlock; | 1868 | goto out_unlock; |
2106 | } | ||
2107 | ret = ccw_device_online(cdev); | ||
2108 | if (ret) | ||
2109 | goto out_disc_unlock; | ||
2110 | 1869 | ||
2111 | cm_enabled = cdev->private->cmb != NULL; | 1870 | if (ccw_device_online(cdev)) { |
1871 | ret = resume_handle_disc(cdev); | ||
1872 | if (ret) | ||
1873 | goto out_unlock; | ||
1874 | goto out_restore; | ||
1875 | } | ||
2112 | spin_unlock_irq(sch->lock); | 1876 | spin_unlock_irq(sch->lock); |
2113 | |||
2114 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); | 1877 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); |
2115 | if (cdev->private->state != DEV_STATE_ONLINE) { | 1878 | spin_lock_irq(sch->lock); |
2116 | spin_lock_irq(sch->lock); | 1879 | |
2117 | goto out_disc_unlock; | 1880 | if (ccw_device_notify(cdev, CIO_OPER) == NOTIFY_BAD) { |
1881 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); | ||
1882 | ret = -ENODEV; | ||
1883 | goto out_unlock; | ||
2118 | } | 1884 | } |
2119 | if (cm_enabled) { | 1885 | |
1886 | /* reenable cmf, if needed */ | ||
1887 | if (cdev->private->cmb) { | ||
1888 | spin_unlock_irq(sch->lock); | ||
2120 | ret = ccw_set_cmf(cdev, 1); | 1889 | ret = ccw_set_cmf(cdev, 1); |
1890 | spin_lock_irq(sch->lock); | ||
2121 | if (ret) { | 1891 | if (ret) { |
2122 | CIO_MSG_EVENT(2, "resume: cdev 0.%x.%04x: cmf failed " | 1892 | CIO_MSG_EVENT(2, "resume: cdev 0.%x.%04x: cmf failed " |
2123 | "(rc=%d)\n", cdev->private->dev_id.ssid, | 1893 | "(rc=%d)\n", cdev->private->dev_id.ssid, |
@@ -2127,27 +1897,17 @@ static int ccw_device_pm_restore(struct device *dev) | |||
2127 | } | 1897 | } |
2128 | 1898 | ||
2129 | out_restore: | 1899 | out_restore: |
1900 | spin_unlock_irq(sch->lock); | ||
2130 | if (cdev->online && cdev->drv && cdev->drv->restore) | 1901 | if (cdev->online && cdev->drv && cdev->drv->restore) |
2131 | ret = cdev->drv->restore(cdev); | 1902 | ret = cdev->drv->restore(cdev); |
2132 | out: | ||
2133 | return ret; | 1903 | return ret; |
2134 | 1904 | ||
2135 | out_disc_unlock: | ||
2136 | ret = resume_handle_disc(cdev); | ||
2137 | spin_unlock_irq(sch->lock); | ||
2138 | if (ret) | ||
2139 | return ret; | ||
2140 | goto out_restore; | ||
2141 | |||
2142 | out_unreg_unlock: | ||
2143 | ccw_device_schedule_sch_unregister(cdev); | ||
2144 | ret = -ENODEV; | ||
2145 | out_unlock: | 1905 | out_unlock: |
2146 | spin_unlock_irq(sch->lock); | 1906 | spin_unlock_irq(sch->lock); |
2147 | return ret; | 1907 | return ret; |
2148 | } | 1908 | } |
2149 | 1909 | ||
2150 | static struct dev_pm_ops ccw_pm_ops = { | 1910 | static const struct dev_pm_ops ccw_pm_ops = { |
2151 | .prepare = ccw_device_pm_prepare, | 1911 | .prepare = ccw_device_pm_prepare, |
2152 | .complete = ccw_device_pm_complete, | 1912 | .complete = ccw_device_pm_complete, |
2153 | .freeze = ccw_device_pm_freeze, | 1913 | .freeze = ccw_device_pm_freeze, |
@@ -2205,6 +1965,77 @@ ccw_device_get_subchannel_id(struct ccw_device *cdev) | |||
2205 | return sch->schid; | 1965 | return sch->schid; |
2206 | } | 1966 | } |
2207 | 1967 | ||
1968 | static void ccw_device_todo(struct work_struct *work) | ||
1969 | { | ||
1970 | struct ccw_device_private *priv; | ||
1971 | struct ccw_device *cdev; | ||
1972 | struct subchannel *sch; | ||
1973 | enum cdev_todo todo; | ||
1974 | |||
1975 | priv = container_of(work, struct ccw_device_private, todo_work); | ||
1976 | cdev = priv->cdev; | ||
1977 | sch = to_subchannel(cdev->dev.parent); | ||
1978 | /* Find out todo. */ | ||
1979 | spin_lock_irq(cdev->ccwlock); | ||
1980 | todo = priv->todo; | ||
1981 | priv->todo = CDEV_TODO_NOTHING; | ||
1982 | CIO_MSG_EVENT(4, "cdev_todo: cdev=0.%x.%04x todo=%d\n", | ||
1983 | priv->dev_id.ssid, priv->dev_id.devno, todo); | ||
1984 | spin_unlock_irq(cdev->ccwlock); | ||
1985 | /* Perform todo. */ | ||
1986 | switch (todo) { | ||
1987 | case CDEV_TODO_ENABLE_CMF: | ||
1988 | cmf_reenable(cdev); | ||
1989 | break; | ||
1990 | case CDEV_TODO_REBIND: | ||
1991 | ccw_device_do_unbind_bind(cdev); | ||
1992 | break; | ||
1993 | case CDEV_TODO_REGISTER: | ||
1994 | io_subchannel_register(cdev); | ||
1995 | break; | ||
1996 | case CDEV_TODO_UNREG_EVAL: | ||
1997 | if (!sch_is_pseudo_sch(sch)) | ||
1998 | css_schedule_eval(sch->schid); | ||
1999 | /* fall-through */ | ||
2000 | case CDEV_TODO_UNREG: | ||
2001 | if (sch_is_pseudo_sch(sch)) | ||
2002 | ccw_device_unregister(cdev); | ||
2003 | else | ||
2004 | ccw_device_call_sch_unregister(cdev); | ||
2005 | break; | ||
2006 | default: | ||
2007 | break; | ||
2008 | } | ||
2009 | /* Release workqueue ref. */ | ||
2010 | put_device(&cdev->dev); | ||
2011 | } | ||
2012 | |||
2013 | /** | ||
2014 | * ccw_device_sched_todo - schedule ccw device operation | ||
2015 | * @cdev: ccw device | ||
2016 | * @todo: todo | ||
2017 | * | ||
2018 | * Schedule the operation identified by @todo to be performed on the slow path | ||
2019 | * workqueue. Do nothing if another operation with higher priority is already | ||
2020 | * scheduled. Needs to be called with ccwdev lock held. | ||
2021 | */ | ||
2022 | void ccw_device_sched_todo(struct ccw_device *cdev, enum cdev_todo todo) | ||
2023 | { | ||
2024 | CIO_MSG_EVENT(4, "cdev_todo: sched cdev=0.%x.%04x todo=%d\n", | ||
2025 | cdev->private->dev_id.ssid, cdev->private->dev_id.devno, | ||
2026 | todo); | ||
2027 | if (cdev->private->todo >= todo) | ||
2028 | return; | ||
2029 | cdev->private->todo = todo; | ||
2030 | /* Get workqueue ref. */ | ||
2031 | if (!get_device(&cdev->dev)) | ||
2032 | return; | ||
2033 | if (!queue_work(cio_work_q, &cdev->private->todo_work)) { | ||
2034 | /* Already queued, release workqueue ref. */ | ||
2035 | put_device(&cdev->dev); | ||
2036 | } | ||
2037 | } | ||
2038 | |||
2208 | MODULE_LICENSE("GPL"); | 2039 | MODULE_LICENSE("GPL"); |
2209 | EXPORT_SYMBOL(ccw_device_set_online); | 2040 | EXPORT_SYMBOL(ccw_device_set_online); |
2210 | EXPORT_SYMBOL(ccw_device_set_offline); | 2041 | EXPORT_SYMBOL(ccw_device_set_offline); |
@@ -2212,5 +2043,4 @@ EXPORT_SYMBOL(ccw_driver_register); | |||
2212 | EXPORT_SYMBOL(ccw_driver_unregister); | 2043 | EXPORT_SYMBOL(ccw_driver_unregister); |
2213 | EXPORT_SYMBOL(get_ccwdev_by_busid); | 2044 | EXPORT_SYMBOL(get_ccwdev_by_busid); |
2214 | EXPORT_SYMBOL(ccw_bus_type); | 2045 | EXPORT_SYMBOL(ccw_bus_type); |
2215 | EXPORT_SYMBOL(ccw_device_work); | ||
2216 | EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id); | 2046 | EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id); |