2 * driver for channel subsystem
4 * Copyright IBM Corp. 2002, 2010
6 * Author(s): Arnd Bergmann (arndb@de.ibm.com)
7 * Cornelia Huck (cornelia.huck@de.ibm.com)
10 #define KMSG_COMPONENT "cio"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/device.h>
16 #include <linux/slab.h>
17 #include <linux/errno.h>
18 #include <linux/list.h>
19 #include <linux/reboot.h>
20 #include <linux/suspend.h>
21 #include <linux/proc_fs.h>
27 #include "cio_debug.h"
34 int css_init_done
= 0;
37 struct channel_subsystem
*channel_subsystems
[__MAX_CSSID
+ 1];
38 static struct bus_type css_bus_type
;
41 for_each_subchannel(int(*fn
)(struct subchannel_id
, void *), void *data
)
43 struct subchannel_id schid
;
46 init_subchannel_id(&schid
);
49 ret
= fn(schid
, data
);
52 } while (schid
.sch_no
++ < __MAX_SUBCHANNEL
);
54 } while (schid
.ssid
++ < max_ssid
);
61 int (*fn_known_sch
)(struct subchannel
*, void *);
62 int (*fn_unknown_sch
)(struct subchannel_id
, void *);
65 static int call_fn_known_sch(struct device
*dev
, void *data
)
67 struct subchannel
*sch
= to_subchannel(dev
);
68 struct cb_data
*cb
= data
;
72 idset_sch_del(cb
->set
, sch
->schid
);
74 rc
= cb
->fn_known_sch(sch
, cb
->data
);
78 static int call_fn_unknown_sch(struct subchannel_id schid
, void *data
)
80 struct cb_data
*cb
= data
;
83 if (idset_sch_contains(cb
->set
, schid
))
84 rc
= cb
->fn_unknown_sch(schid
, cb
->data
);
88 static int call_fn_all_sch(struct subchannel_id schid
, void *data
)
90 struct cb_data
*cb
= data
;
91 struct subchannel
*sch
;
94 sch
= get_subchannel_by_schid(schid
);
97 rc
= cb
->fn_known_sch(sch
, cb
->data
);
98 put_device(&sch
->dev
);
100 if (cb
->fn_unknown_sch
)
101 rc
= cb
->fn_unknown_sch(schid
, cb
->data
);
107 int for_each_subchannel_staged(int (*fn_known
)(struct subchannel
*, void *),
108 int (*fn_unknown
)(struct subchannel_id
,
115 cb
.fn_known_sch
= fn_known
;
116 cb
.fn_unknown_sch
= fn_unknown
;
118 if (fn_known
&& !fn_unknown
) {
119 /* Skip idset allocation in case of known-only loop. */
121 return bus_for_each_dev(&css_bus_type
, NULL
, &cb
,
125 cb
.set
= idset_sch_new();
127 /* fall back to brute force scanning in case of oom */
128 return for_each_subchannel(call_fn_all_sch
, &cb
);
132 /* Process registered subchannels. */
133 rc
= bus_for_each_dev(&css_bus_type
, NULL
, &cb
, call_fn_known_sch
);
136 /* Process unregistered subchannels. */
138 rc
= for_each_subchannel(call_fn_unknown_sch
, &cb
);
145 static void css_sch_todo(struct work_struct
*work
);
147 static int css_sch_create_locks(struct subchannel
*sch
)
149 sch
->lock
= kmalloc(sizeof(*sch
->lock
), GFP_KERNEL
);
153 spin_lock_init(sch
->lock
);
154 mutex_init(&sch
->reg_mutex
);
159 static void css_subchannel_release(struct device
*dev
)
161 struct subchannel
*sch
= to_subchannel(dev
);
163 sch
->config
.intparm
= 0;
164 cio_commit_config(sch
);
169 struct subchannel
*css_alloc_subchannel(struct subchannel_id schid
)
171 struct subchannel
*sch
;
174 sch
= kzalloc(sizeof(*sch
), GFP_KERNEL
| GFP_DMA
);
176 return ERR_PTR(-ENOMEM
);
178 ret
= cio_validate_subchannel(sch
, schid
);
182 ret
= css_sch_create_locks(sch
);
186 INIT_WORK(&sch
->todo_work
, css_sch_todo
);
187 sch
->dev
.release
= &css_subchannel_release
;
188 device_initialize(&sch
->dev
);
196 static int css_sch_device_register(struct subchannel
*sch
)
200 mutex_lock(&sch
->reg_mutex
);
201 dev_set_name(&sch
->dev
, "0.%x.%04x", sch
->schid
.ssid
,
203 ret
= device_add(&sch
->dev
);
204 mutex_unlock(&sch
->reg_mutex
);
209 * css_sch_device_unregister - unregister a subchannel
210 * @sch: subchannel to be unregistered
212 void css_sch_device_unregister(struct subchannel
*sch
)
214 mutex_lock(&sch
->reg_mutex
);
215 if (device_is_registered(&sch
->dev
))
216 device_unregister(&sch
->dev
);
217 mutex_unlock(&sch
->reg_mutex
);
219 EXPORT_SYMBOL_GPL(css_sch_device_unregister
);
221 static void ssd_from_pmcw(struct chsc_ssd_info
*ssd
, struct pmcw
*pmcw
)
226 memset(ssd
, 0, sizeof(struct chsc_ssd_info
));
227 ssd
->path_mask
= pmcw
->pim
;
228 for (i
= 0; i
< 8; i
++) {
230 if (pmcw
->pim
& mask
) {
231 chp_id_init(&ssd
->chpid
[i
]);
232 ssd
->chpid
[i
].id
= pmcw
->chpid
[i
];
237 static void ssd_register_chpids(struct chsc_ssd_info
*ssd
)
242 for (i
= 0; i
< 8; i
++) {
244 if (ssd
->path_mask
& mask
)
245 if (!chp_is_registered(ssd
->chpid
[i
]))
246 chp_new(ssd
->chpid
[i
]);
250 void css_update_ssd_info(struct subchannel
*sch
)
254 ret
= chsc_get_ssd_info(sch
->schid
, &sch
->ssd_info
);
256 ssd_from_pmcw(&sch
->ssd_info
, &sch
->schib
.pmcw
);
258 ssd_register_chpids(&sch
->ssd_info
);
261 static ssize_t
type_show(struct device
*dev
, struct device_attribute
*attr
,
264 struct subchannel
*sch
= to_subchannel(dev
);
266 return sprintf(buf
, "%01x\n", sch
->st
);
269 static DEVICE_ATTR(type
, 0444, type_show
, NULL
);
271 static ssize_t
modalias_show(struct device
*dev
, struct device_attribute
*attr
,
274 struct subchannel
*sch
= to_subchannel(dev
);
276 return sprintf(buf
, "css:t%01X\n", sch
->st
);
279 static DEVICE_ATTR(modalias
, 0444, modalias_show
, NULL
);
281 static struct attribute
*subch_attrs
[] = {
283 &dev_attr_modalias
.attr
,
287 static struct attribute_group subch_attr_group
= {
288 .attrs
= subch_attrs
,
291 static const struct attribute_group
*default_subch_attr_groups
[] = {
296 int css_register_subchannel(struct subchannel
*sch
)
300 /* Initialize the subchannel structure */
301 sch
->dev
.parent
= &channel_subsystems
[0]->device
;
302 sch
->dev
.bus
= &css_bus_type
;
303 sch
->dev
.groups
= default_subch_attr_groups
;
305 * We don't want to generate uevents for I/O subchannels that don't
306 * have a working ccw device behind them since they will be
307 * unregistered before they can be used anyway, so we delay the add
308 * uevent until after device recognition was successful.
309 * Note that we suppress the uevent for all subchannel types;
310 * the subchannel driver can decide itself when it wants to inform
311 * userspace of its existence.
313 dev_set_uevent_suppress(&sch
->dev
, 1);
314 css_update_ssd_info(sch
);
315 /* make it known to the system */
316 ret
= css_sch_device_register(sch
);
318 CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n",
319 sch
->schid
.ssid
, sch
->schid
.sch_no
, ret
);
324 * No driver matched. Generate the uevent now so that
325 * a fitting driver module may be loaded based on the
328 dev_set_uevent_suppress(&sch
->dev
, 0);
329 kobject_uevent(&sch
->dev
.kobj
, KOBJ_ADD
);
334 static int css_probe_device(struct subchannel_id schid
)
336 struct subchannel
*sch
;
339 sch
= css_alloc_subchannel(schid
);
343 ret
= css_register_subchannel(sch
);
345 put_device(&sch
->dev
);
351 check_subchannel(struct device
* dev
, void * data
)
353 struct subchannel
*sch
;
354 struct subchannel_id
*schid
= data
;
356 sch
= to_subchannel(dev
);
357 return schid_equal(&sch
->schid
, schid
);
361 get_subchannel_by_schid(struct subchannel_id schid
)
365 dev
= bus_find_device(&css_bus_type
, NULL
,
366 &schid
, check_subchannel
);
368 return dev
? to_subchannel(dev
) : NULL
;
372 * css_sch_is_valid() - check if a subchannel is valid
373 * @schib: subchannel information block for the subchannel
375 int css_sch_is_valid(struct schib
*schib
)
377 if ((schib
->pmcw
.st
== SUBCHANNEL_TYPE_IO
) && !schib
->pmcw
.dnv
)
379 if ((schib
->pmcw
.st
== SUBCHANNEL_TYPE_MSG
) && !schib
->pmcw
.w
)
383 EXPORT_SYMBOL_GPL(css_sch_is_valid
);
385 static int css_evaluate_new_subchannel(struct subchannel_id schid
, int slow
)
390 /* Will be done on the slow path. */
393 if (stsch(schid
, &schib
)) {
394 /* Subchannel is not provided. */
397 if (!css_sch_is_valid(&schib
)) {
398 /* Unusable - ignore. */
401 CIO_MSG_EVENT(4, "event: sch 0.%x.%04x, new\n", schid
.ssid
,
404 return css_probe_device(schid
);
407 static int css_evaluate_known_subchannel(struct subchannel
*sch
, int slow
)
412 if (sch
->driver
->sch_event
)
413 ret
= sch
->driver
->sch_event(sch
, slow
);
416 "Got subchannel machine check but "
417 "no sch_event handler provided.\n");
419 if (ret
!= 0 && ret
!= -EAGAIN
) {
420 CIO_MSG_EVENT(2, "eval: sch 0.%x.%04x, rc=%d\n",
421 sch
->schid
.ssid
, sch
->schid
.sch_no
, ret
);
426 static void css_evaluate_subchannel(struct subchannel_id schid
, int slow
)
428 struct subchannel
*sch
;
431 sch
= get_subchannel_by_schid(schid
);
433 ret
= css_evaluate_known_subchannel(sch
, slow
);
434 put_device(&sch
->dev
);
436 ret
= css_evaluate_new_subchannel(schid
, slow
);
438 css_schedule_eval(schid
);
442 * css_sched_sch_todo - schedule a subchannel operation
446 * Schedule the operation identified by @todo to be performed on the slow path
447 * workqueue. Do nothing if another operation with higher priority is already
448 * scheduled. Needs to be called with subchannel lock held.
450 void css_sched_sch_todo(struct subchannel
*sch
, enum sch_todo todo
)
452 CIO_MSG_EVENT(4, "sch_todo: sched sch=0.%x.%04x todo=%d\n",
453 sch
->schid
.ssid
, sch
->schid
.sch_no
, todo
);
454 if (sch
->todo
>= todo
)
456 /* Get workqueue ref. */
457 if (!get_device(&sch
->dev
))
460 if (!queue_work(cio_work_q
, &sch
->todo_work
)) {
461 /* Already queued, release workqueue ref. */
462 put_device(&sch
->dev
);
465 EXPORT_SYMBOL_GPL(css_sched_sch_todo
);
467 static void css_sch_todo(struct work_struct
*work
)
469 struct subchannel
*sch
;
473 sch
= container_of(work
, struct subchannel
, todo_work
);
475 spin_lock_irq(sch
->lock
);
477 CIO_MSG_EVENT(4, "sch_todo: sch=0.%x.%04x, todo=%d\n", sch
->schid
.ssid
,
478 sch
->schid
.sch_no
, todo
);
479 sch
->todo
= SCH_TODO_NOTHING
;
480 spin_unlock_irq(sch
->lock
);
483 case SCH_TODO_NOTHING
:
486 ret
= css_evaluate_known_subchannel(sch
, 1);
487 if (ret
== -EAGAIN
) {
488 spin_lock_irq(sch
->lock
);
489 css_sched_sch_todo(sch
, todo
);
490 spin_unlock_irq(sch
->lock
);
494 css_sch_device_unregister(sch
);
497 /* Release workqueue ref. */
498 put_device(&sch
->dev
);
501 static struct idset
*slow_subchannel_set
;
502 static spinlock_t slow_subchannel_lock
;
503 static wait_queue_head_t css_eval_wq
;
504 static atomic_t css_eval_scheduled
;
506 static int __init
slow_subchannel_init(void)
508 spin_lock_init(&slow_subchannel_lock
);
509 atomic_set(&css_eval_scheduled
, 0);
510 init_waitqueue_head(&css_eval_wq
);
511 slow_subchannel_set
= idset_sch_new();
512 if (!slow_subchannel_set
) {
513 CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n");
519 static int slow_eval_known_fn(struct subchannel
*sch
, void *data
)
524 spin_lock_irq(&slow_subchannel_lock
);
525 eval
= idset_sch_contains(slow_subchannel_set
, sch
->schid
);
526 idset_sch_del(slow_subchannel_set
, sch
->schid
);
527 spin_unlock_irq(&slow_subchannel_lock
);
529 rc
= css_evaluate_known_subchannel(sch
, 1);
531 css_schedule_eval(sch
->schid
);
536 static int slow_eval_unknown_fn(struct subchannel_id schid
, void *data
)
541 spin_lock_irq(&slow_subchannel_lock
);
542 eval
= idset_sch_contains(slow_subchannel_set
, schid
);
543 idset_sch_del(slow_subchannel_set
, schid
);
544 spin_unlock_irq(&slow_subchannel_lock
);
546 rc
= css_evaluate_new_subchannel(schid
, 1);
549 css_schedule_eval(schid
);
555 /* These should abort looping */
556 spin_lock_irq(&slow_subchannel_lock
);
557 idset_sch_del_subseq(slow_subchannel_set
, schid
);
558 spin_unlock_irq(&slow_subchannel_lock
);
563 /* Allow scheduling here since the containing loop might
570 static void css_slow_path_func(struct work_struct
*unused
)
574 CIO_TRACE_EVENT(4, "slowpath");
575 for_each_subchannel_staged(slow_eval_known_fn
, slow_eval_unknown_fn
,
577 spin_lock_irqsave(&slow_subchannel_lock
, flags
);
578 if (idset_is_empty(slow_subchannel_set
)) {
579 atomic_set(&css_eval_scheduled
, 0);
580 wake_up(&css_eval_wq
);
582 spin_unlock_irqrestore(&slow_subchannel_lock
, flags
);
585 static DECLARE_DELAYED_WORK(slow_path_work
, css_slow_path_func
);
586 struct workqueue_struct
*cio_work_q
;
588 void css_schedule_eval(struct subchannel_id schid
)
592 spin_lock_irqsave(&slow_subchannel_lock
, flags
);
593 idset_sch_add(slow_subchannel_set
, schid
);
594 atomic_set(&css_eval_scheduled
, 1);
595 queue_delayed_work(cio_work_q
, &slow_path_work
, 0);
596 spin_unlock_irqrestore(&slow_subchannel_lock
, flags
);
599 void css_schedule_eval_all(void)
603 spin_lock_irqsave(&slow_subchannel_lock
, flags
);
604 idset_fill(slow_subchannel_set
);
605 atomic_set(&css_eval_scheduled
, 1);
606 queue_delayed_work(cio_work_q
, &slow_path_work
, 0);
607 spin_unlock_irqrestore(&slow_subchannel_lock
, flags
);
610 static int __unset_registered(struct device
*dev
, void *data
)
612 struct idset
*set
= data
;
613 struct subchannel
*sch
= to_subchannel(dev
);
615 idset_sch_del(set
, sch
->schid
);
619 void css_schedule_eval_all_unreg(unsigned long delay
)
622 struct idset
*unreg_set
;
624 /* Find unregistered subchannels. */
625 unreg_set
= idset_sch_new();
628 css_schedule_eval_all();
631 idset_fill(unreg_set
);
632 bus_for_each_dev(&css_bus_type
, NULL
, unreg_set
, __unset_registered
);
633 /* Apply to slow_subchannel_set. */
634 spin_lock_irqsave(&slow_subchannel_lock
, flags
);
635 idset_add_set(slow_subchannel_set
, unreg_set
);
636 atomic_set(&css_eval_scheduled
, 1);
637 queue_delayed_work(cio_work_q
, &slow_path_work
, delay
);
638 spin_unlock_irqrestore(&slow_subchannel_lock
, flags
);
639 idset_free(unreg_set
);
642 void css_wait_for_slow_path(void)
644 flush_workqueue(cio_work_q
);
647 /* Schedule reprobing of all unregistered subchannels. */
648 void css_schedule_reprobe(void)
650 /* Schedule with a delay to allow merging of subsequent calls. */
651 css_schedule_eval_all_unreg(1 * HZ
);
653 EXPORT_SYMBOL_GPL(css_schedule_reprobe
);
656 * Called from the machine check handler for subchannel report words.
658 static void css_process_crw(struct crw
*crw0
, struct crw
*crw1
, int overflow
)
660 struct subchannel_id mchk_schid
;
661 struct subchannel
*sch
;
664 css_schedule_eval_all();
667 CIO_CRW_EVENT(2, "CRW0 reports slct=%d, oflw=%d, "
668 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
669 crw0
->slct
, crw0
->oflw
, crw0
->chn
, crw0
->rsc
, crw0
->anc
,
670 crw0
->erc
, crw0
->rsid
);
672 CIO_CRW_EVENT(2, "CRW1 reports slct=%d, oflw=%d, "
673 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
674 crw1
->slct
, crw1
->oflw
, crw1
->chn
, crw1
->rsc
,
675 crw1
->anc
, crw1
->erc
, crw1
->rsid
);
676 init_subchannel_id(&mchk_schid
);
677 mchk_schid
.sch_no
= crw0
->rsid
;
679 mchk_schid
.ssid
= (crw1
->rsid
>> 4) & 3;
681 if (crw0
->erc
== CRW_ERC_PMOD
) {
682 sch
= get_subchannel_by_schid(mchk_schid
);
684 css_update_ssd_info(sch
);
685 put_device(&sch
->dev
);
689 * Since we are always presented with IPI in the CRW, we have to
690 * use stsch() to find out if the subchannel in question has come
693 css_evaluate_subchannel(mchk_schid
, 0);
697 css_generate_pgid(struct channel_subsystem
*css
, u32 tod_high
)
701 if (css_general_characteristics
.mcss
) {
702 css
->global_pgid
.pgid_high
.ext_cssid
.version
= 0x80;
703 css
->global_pgid
.pgid_high
.ext_cssid
.cssid
= css
->cssid
;
705 css
->global_pgid
.pgid_high
.cpu_addr
= stap();
708 css
->global_pgid
.cpu_id
= cpu_id
.ident
;
709 css
->global_pgid
.cpu_model
= cpu_id
.machine
;
710 css
->global_pgid
.tod_high
= tod_high
;
714 channel_subsystem_release(struct device
*dev
)
716 struct channel_subsystem
*css
;
719 mutex_destroy(&css
->mutex
);
720 if (css
->pseudo_subchannel
) {
721 /* Implies that it has been generated but never registered. */
722 css_subchannel_release(&css
->pseudo_subchannel
->dev
);
723 css
->pseudo_subchannel
= NULL
;
729 css_cm_enable_show(struct device
*dev
, struct device_attribute
*attr
,
732 struct channel_subsystem
*css
= to_css(dev
);
737 mutex_lock(&css
->mutex
);
738 ret
= sprintf(buf
, "%x\n", css
->cm_enabled
);
739 mutex_unlock(&css
->mutex
);
744 css_cm_enable_store(struct device
*dev
, struct device_attribute
*attr
,
745 const char *buf
, size_t count
)
747 struct channel_subsystem
*css
= to_css(dev
);
751 ret
= kstrtoul(buf
, 16, &val
);
754 mutex_lock(&css
->mutex
);
757 ret
= css
->cm_enabled
? chsc_secm(css
, 0) : 0;
760 ret
= css
->cm_enabled
? 0 : chsc_secm(css
, 1);
765 mutex_unlock(&css
->mutex
);
766 return ret
< 0 ? ret
: count
;
769 static DEVICE_ATTR(cm_enable
, 0644, css_cm_enable_show
, css_cm_enable_store
);
771 static int __init
setup_css(int nr
)
775 struct channel_subsystem
*css
;
777 css
= channel_subsystems
[nr
];
778 memset(css
, 0, sizeof(struct channel_subsystem
));
779 css
->pseudo_subchannel
=
780 kzalloc(sizeof(*css
->pseudo_subchannel
), GFP_KERNEL
);
781 if (!css
->pseudo_subchannel
)
783 css
->pseudo_subchannel
->dev
.parent
= &css
->device
;
784 css
->pseudo_subchannel
->dev
.release
= css_subchannel_release
;
785 dev_set_name(&css
->pseudo_subchannel
->dev
, "defunct");
786 mutex_init(&css
->pseudo_subchannel
->reg_mutex
);
787 ret
= css_sch_create_locks(css
->pseudo_subchannel
);
789 kfree(css
->pseudo_subchannel
);
792 mutex_init(&css
->mutex
);
795 dev_set_name(&css
->device
, "css%x", nr
);
796 css
->device
.release
= channel_subsystem_release
;
797 tod_high
= (u32
) (get_tod_clock() >> 32);
798 css_generate_pgid(css
, tod_high
);
802 static int css_reboot_event(struct notifier_block
*this,
809 for (i
= 0; i
<= __MAX_CSSID
; i
++) {
810 struct channel_subsystem
*css
;
812 css
= channel_subsystems
[i
];
813 mutex_lock(&css
->mutex
);
815 if (chsc_secm(css
, 0))
817 mutex_unlock(&css
->mutex
);
823 static struct notifier_block css_reboot_notifier
= {
824 .notifier_call
= css_reboot_event
,
828 * Since the css devices are neither on a bus nor have a class
829 * nor have a special device type, we cannot stop/restart channel
830 * path measurements via the normal suspend/resume callbacks, but have
833 static int css_power_event(struct notifier_block
*this, unsigned long event
,
839 case PM_HIBERNATION_PREPARE
:
840 case PM_SUSPEND_PREPARE
:
842 for (i
= 0; i
<= __MAX_CSSID
; i
++) {
843 struct channel_subsystem
*css
;
845 css
= channel_subsystems
[i
];
846 mutex_lock(&css
->mutex
);
847 if (!css
->cm_enabled
) {
848 mutex_unlock(&css
->mutex
);
851 ret
= __chsc_do_secm(css
, 0);
852 ret
= notifier_from_errno(ret
);
853 mutex_unlock(&css
->mutex
);
856 case PM_POST_HIBERNATION
:
857 case PM_POST_SUSPEND
:
859 for (i
= 0; i
<= __MAX_CSSID
; i
++) {
860 struct channel_subsystem
*css
;
862 css
= channel_subsystems
[i
];
863 mutex_lock(&css
->mutex
);
864 if (!css
->cm_enabled
) {
865 mutex_unlock(&css
->mutex
);
868 ret
= __chsc_do_secm(css
, 1);
869 ret
= notifier_from_errno(ret
);
870 mutex_unlock(&css
->mutex
);
872 /* search for subchannels, which appeared during hibernation */
873 css_schedule_reprobe();
881 static struct notifier_block css_power_notifier
= {
882 .notifier_call
= css_power_event
,
886 * Now that the driver core is running, we can setup our channel subsystem.
887 * The struct subchannel's are created during probing.
889 static int __init
css_bus_init(void)
897 chsc_determine_css_characteristics();
898 /* Try to enable MSS. */
899 ret
= chsc_enable_facility(CHSC_SDA_OC_MSS
);
903 max_ssid
= __MAX_SSID
;
905 ret
= slow_subchannel_init();
909 ret
= crw_register_handler(CRW_RSC_SCH
, css_process_crw
);
913 if ((ret
= bus_register(&css_bus_type
)))
916 /* Setup css structure. */
917 for (i
= 0; i
<= __MAX_CSSID
; i
++) {
918 struct channel_subsystem
*css
;
920 css
= kmalloc(sizeof(struct channel_subsystem
), GFP_KERNEL
);
925 channel_subsystems
[i
] = css
;
928 kfree(channel_subsystems
[i
]);
931 ret
= device_register(&css
->device
);
933 put_device(&css
->device
);
936 if (css_chsc_characteristics
.secm
) {
937 ret
= device_create_file(&css
->device
,
938 &dev_attr_cm_enable
);
942 ret
= device_register(&css
->pseudo_subchannel
->dev
);
944 put_device(&css
->pseudo_subchannel
->dev
);
948 ret
= register_reboot_notifier(&css_reboot_notifier
);
951 ret
= register_pm_notifier(&css_power_notifier
);
953 unregister_reboot_notifier(&css_reboot_notifier
);
958 /* Enable default isc for I/O subchannels. */
959 isc_register(IO_SCH_ISC
);
963 if (css_chsc_characteristics
.secm
)
964 device_remove_file(&channel_subsystems
[i
]->device
,
965 &dev_attr_cm_enable
);
967 device_unregister(&channel_subsystems
[i
]->device
);
970 struct channel_subsystem
*css
;
973 css
= channel_subsystems
[i
];
974 device_unregister(&css
->pseudo_subchannel
->dev
);
975 css
->pseudo_subchannel
= NULL
;
976 if (css_chsc_characteristics
.secm
)
977 device_remove_file(&css
->device
,
978 &dev_attr_cm_enable
);
979 device_unregister(&css
->device
);
981 bus_unregister(&css_bus_type
);
983 crw_unregister_handler(CRW_RSC_SCH
);
984 idset_free(slow_subchannel_set
);
986 pr_alert("The CSS device driver initialization failed with "
991 static void __init
css_bus_cleanup(void)
993 struct channel_subsystem
*css
;
996 for (i
= 0; i
<= __MAX_CSSID
; i
++) {
997 css
= channel_subsystems
[i
];
998 device_unregister(&css
->pseudo_subchannel
->dev
);
999 css
->pseudo_subchannel
= NULL
;
1000 if (css_chsc_characteristics
.secm
)
1001 device_remove_file(&css
->device
, &dev_attr_cm_enable
);
1002 device_unregister(&css
->device
);
1004 bus_unregister(&css_bus_type
);
1005 crw_unregister_handler(CRW_RSC_SCH
);
1006 idset_free(slow_subchannel_set
);
1007 chsc_init_cleanup();
1008 isc_unregister(IO_SCH_ISC
);
1011 static int __init
channel_subsystem_init(void)
1015 ret
= css_bus_init();
1018 cio_work_q
= create_singlethread_workqueue("cio");
1023 ret
= io_subchannel_init();
1029 destroy_workqueue(cio_work_q
);
1034 subsys_initcall(channel_subsystem_init
);
1036 static int css_settle(struct device_driver
*drv
, void *unused
)
1038 struct css_driver
*cssdrv
= to_cssdriver(drv
);
1041 return cssdrv
->settle();
1045 int css_complete_work(void)
1049 /* Wait for the evaluation of subchannels to finish. */
1050 ret
= wait_event_interruptible(css_eval_wq
,
1051 atomic_read(&css_eval_scheduled
) == 0);
1054 flush_workqueue(cio_work_q
);
1055 /* Wait for the subchannel type specific initialization to finish */
1056 return bus_for_each_drv(&css_bus_type
, NULL
, NULL
, css_settle
);
1061 * Wait for the initialization of devices to finish, to make sure we are
1062 * done with our setup if the search for the root device starts.
1064 static int __init
channel_subsystem_init_sync(void)
1066 /* Register subchannels which are already in use. */
1067 cio_register_early_subchannels();
1068 /* Start initial subchannel evaluation. */
1069 css_schedule_eval_all();
1070 css_complete_work();
1073 subsys_initcall_sync(channel_subsystem_init_sync
);
1075 void channel_subsystem_reinit(void)
1077 struct channel_path
*chp
;
1078 struct chp_id chpid
;
1080 chsc_enable_facility(CHSC_SDA_OC_MSS
);
1081 chp_id_for_each(&chpid
) {
1082 chp
= chpid_to_chp(chpid
);
1084 chp_update_desc(chp
);
1089 #ifdef CONFIG_PROC_FS
1090 static ssize_t
cio_settle_write(struct file
*file
, const char __user
*buf
,
1091 size_t count
, loff_t
*ppos
)
1095 /* Handle pending CRW's. */
1096 crw_wait_for_channel_report();
1097 ret
= css_complete_work();
1099 return ret
? ret
: count
;
1102 static const struct file_operations cio_settle_proc_fops
= {
1103 .open
= nonseekable_open
,
1104 .write
= cio_settle_write
,
1105 .llseek
= no_llseek
,
1108 static int __init
cio_settle_init(void)
1110 struct proc_dir_entry
*entry
;
1112 entry
= proc_create("cio_settle", S_IWUSR
, NULL
,
1113 &cio_settle_proc_fops
);
1118 device_initcall(cio_settle_init
);
1119 #endif /*CONFIG_PROC_FS*/
1121 int sch_is_pseudo_sch(struct subchannel
*sch
)
1123 return sch
== to_css(sch
->dev
.parent
)->pseudo_subchannel
;
1126 static int css_bus_match(struct device
*dev
, struct device_driver
*drv
)
1128 struct subchannel
*sch
= to_subchannel(dev
);
1129 struct css_driver
*driver
= to_cssdriver(drv
);
1130 struct css_device_id
*id
;
1132 for (id
= driver
->subchannel_type
; id
->match_flags
; id
++) {
1133 if (sch
->st
== id
->type
)
1140 static int css_probe(struct device
*dev
)
1142 struct subchannel
*sch
;
1145 sch
= to_subchannel(dev
);
1146 sch
->driver
= to_cssdriver(dev
->driver
);
1147 ret
= sch
->driver
->probe
? sch
->driver
->probe(sch
) : 0;
1153 static int css_remove(struct device
*dev
)
1155 struct subchannel
*sch
;
1158 sch
= to_subchannel(dev
);
1159 ret
= sch
->driver
->remove
? sch
->driver
->remove(sch
) : 0;
1164 static void css_shutdown(struct device
*dev
)
1166 struct subchannel
*sch
;
1168 sch
= to_subchannel(dev
);
1169 if (sch
->driver
&& sch
->driver
->shutdown
)
1170 sch
->driver
->shutdown(sch
);
1173 static int css_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
1175 struct subchannel
*sch
= to_subchannel(dev
);
1178 ret
= add_uevent_var(env
, "ST=%01X", sch
->st
);
1181 ret
= add_uevent_var(env
, "MODALIAS=css:t%01X", sch
->st
);
1185 static int css_pm_prepare(struct device
*dev
)
1187 struct subchannel
*sch
= to_subchannel(dev
);
1188 struct css_driver
*drv
;
1190 if (mutex_is_locked(&sch
->reg_mutex
))
1192 if (!sch
->dev
.driver
)
1194 drv
= to_cssdriver(sch
->dev
.driver
);
1195 /* Notify drivers that they may not register children. */
1196 return drv
->prepare
? drv
->prepare(sch
) : 0;
1199 static void css_pm_complete(struct device
*dev
)
1201 struct subchannel
*sch
= to_subchannel(dev
);
1202 struct css_driver
*drv
;
1204 if (!sch
->dev
.driver
)
1206 drv
= to_cssdriver(sch
->dev
.driver
);
1211 static int css_pm_freeze(struct device
*dev
)
1213 struct subchannel
*sch
= to_subchannel(dev
);
1214 struct css_driver
*drv
;
1216 if (!sch
->dev
.driver
)
1218 drv
= to_cssdriver(sch
->dev
.driver
);
1219 return drv
->freeze
? drv
->freeze(sch
) : 0;
1222 static int css_pm_thaw(struct device
*dev
)
1224 struct subchannel
*sch
= to_subchannel(dev
);
1225 struct css_driver
*drv
;
1227 if (!sch
->dev
.driver
)
1229 drv
= to_cssdriver(sch
->dev
.driver
);
1230 return drv
->thaw
? drv
->thaw(sch
) : 0;
1233 static int css_pm_restore(struct device
*dev
)
1235 struct subchannel
*sch
= to_subchannel(dev
);
1236 struct css_driver
*drv
;
1238 css_update_ssd_info(sch
);
1239 if (!sch
->dev
.driver
)
1241 drv
= to_cssdriver(sch
->dev
.driver
);
1242 return drv
->restore
? drv
->restore(sch
) : 0;
1245 static const struct dev_pm_ops css_pm_ops
= {
1246 .prepare
= css_pm_prepare
,
1247 .complete
= css_pm_complete
,
1248 .freeze
= css_pm_freeze
,
1249 .thaw
= css_pm_thaw
,
1250 .restore
= css_pm_restore
,
1253 static struct bus_type css_bus_type
= {
1255 .match
= css_bus_match
,
1257 .remove
= css_remove
,
1258 .shutdown
= css_shutdown
,
1259 .uevent
= css_uevent
,
1264 * css_driver_register - register a css driver
1265 * @cdrv: css driver to register
1267 * This is mainly a wrapper around driver_register that sets name
1268 * and bus_type in the embedded struct device_driver correctly.
1270 int css_driver_register(struct css_driver
*cdrv
)
1272 cdrv
->drv
.bus
= &css_bus_type
;
1273 return driver_register(&cdrv
->drv
);
1275 EXPORT_SYMBOL_GPL(css_driver_register
);
1278 * css_driver_unregister - unregister a css driver
1279 * @cdrv: css driver to unregister
1281 * This is a wrapper around driver_unregister.
1283 void css_driver_unregister(struct css_driver
*cdrv
)
1285 driver_unregister(&cdrv
->drv
);
1287 EXPORT_SYMBOL_GPL(css_driver_unregister
);
1289 MODULE_LICENSE("GPL");