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
);
50 ret
= fn(schid
, data
);
53 } while (schid
.sch_no
++ < __MAX_SUBCHANNEL
);
55 } while (schid
.ssid
++ < max_ssid
);
62 int (*fn_known_sch
)(struct subchannel
*, void *);
63 int (*fn_unknown_sch
)(struct subchannel_id
, void *);
66 static int call_fn_known_sch(struct device
*dev
, void *data
)
68 struct subchannel
*sch
= to_subchannel(dev
);
69 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 cb
.set
= idset_sch_new();
120 /* fall back to brute force scanning in case of oom */
121 return for_each_subchannel(call_fn_all_sch
, &cb
);
125 /* Process registered subchannels. */
126 rc
= bus_for_each_dev(&css_bus_type
, NULL
, &cb
, call_fn_known_sch
);
129 /* Process unregistered subchannels. */
131 rc
= for_each_subchannel(call_fn_unknown_sch
, &cb
);
138 static void css_sch_todo(struct work_struct
*work
);
140 static struct subchannel
*
141 css_alloc_subchannel(struct subchannel_id schid
)
143 struct subchannel
*sch
;
146 sch
= kmalloc (sizeof (*sch
), GFP_KERNEL
| GFP_DMA
);
148 return ERR_PTR(-ENOMEM
);
149 ret
= cio_validate_subchannel (sch
, schid
);
154 INIT_WORK(&sch
->todo_work
, css_sch_todo
);
159 css_subchannel_release(struct device
*dev
)
161 struct subchannel
*sch
;
163 sch
= to_subchannel(dev
);
164 if (!cio_is_console(sch
->schid
)) {
165 /* Reset intparm to zeroes. */
166 sch
->config
.intparm
= 0;
167 cio_commit_config(sch
);
173 static int css_sch_device_register(struct subchannel
*sch
)
177 mutex_lock(&sch
->reg_mutex
);
178 dev_set_name(&sch
->dev
, "0.%x.%04x", sch
->schid
.ssid
,
180 ret
= device_register(&sch
->dev
);
181 mutex_unlock(&sch
->reg_mutex
);
186 * css_sch_device_unregister - unregister a subchannel
187 * @sch: subchannel to be unregistered
189 void css_sch_device_unregister(struct subchannel
*sch
)
191 mutex_lock(&sch
->reg_mutex
);
192 if (device_is_registered(&sch
->dev
))
193 device_unregister(&sch
->dev
);
194 mutex_unlock(&sch
->reg_mutex
);
196 EXPORT_SYMBOL_GPL(css_sch_device_unregister
);
198 static void css_sch_todo(struct work_struct
*work
)
200 struct subchannel
*sch
;
203 sch
= container_of(work
, struct subchannel
, todo_work
);
205 spin_lock_irq(sch
->lock
);
207 CIO_MSG_EVENT(4, "sch_todo: sch=0.%x.%04x, todo=%d\n", sch
->schid
.ssid
,
208 sch
->schid
.sch_no
, todo
);
209 sch
->todo
= SCH_TODO_NOTHING
;
210 spin_unlock_irq(sch
->lock
);
212 if (todo
== SCH_TODO_UNREG
)
213 css_sch_device_unregister(sch
);
214 /* Release workqueue ref. */
215 put_device(&sch
->dev
);
219 * css_sched_sch_todo - schedule a subchannel operation
223 * Schedule the operation identified by @todo to be performed on the slow path
224 * workqueue. Do nothing if another operation with higher priority is already
225 * scheduled. Needs to be called with subchannel lock held.
227 void css_sched_sch_todo(struct subchannel
*sch
, enum sch_todo todo
)
229 CIO_MSG_EVENT(4, "sch_todo: sched sch=0.%x.%04x todo=%d\n",
230 sch
->schid
.ssid
, sch
->schid
.sch_no
, todo
);
231 if (sch
->todo
>= todo
)
233 /* Get workqueue ref. */
234 if (!get_device(&sch
->dev
))
237 if (!queue_work(cio_work_q
, &sch
->todo_work
)) {
238 /* Already queued, release workqueue ref. */
239 put_device(&sch
->dev
);
243 static void ssd_from_pmcw(struct chsc_ssd_info
*ssd
, struct pmcw
*pmcw
)
248 memset(ssd
, 0, sizeof(struct chsc_ssd_info
));
249 ssd
->path_mask
= pmcw
->pim
;
250 for (i
= 0; i
< 8; i
++) {
252 if (pmcw
->pim
& mask
) {
253 chp_id_init(&ssd
->chpid
[i
]);
254 ssd
->chpid
[i
].id
= pmcw
->chpid
[i
];
259 static void ssd_register_chpids(struct chsc_ssd_info
*ssd
)
264 for (i
= 0; i
< 8; i
++) {
266 if (ssd
->path_mask
& mask
)
267 if (!chp_is_registered(ssd
->chpid
[i
]))
268 chp_new(ssd
->chpid
[i
]);
272 void css_update_ssd_info(struct subchannel
*sch
)
276 if (cio_is_console(sch
->schid
)) {
277 /* Console is initialized too early for functions requiring
278 * memory allocation. */
279 ssd_from_pmcw(&sch
->ssd_info
, &sch
->schib
.pmcw
);
281 ret
= chsc_get_ssd_info(sch
->schid
, &sch
->ssd_info
);
283 ssd_from_pmcw(&sch
->ssd_info
, &sch
->schib
.pmcw
);
284 ssd_register_chpids(&sch
->ssd_info
);
288 static ssize_t
type_show(struct device
*dev
, struct device_attribute
*attr
,
291 struct subchannel
*sch
= to_subchannel(dev
);
293 return sprintf(buf
, "%01x\n", sch
->st
);
296 static DEVICE_ATTR(type
, 0444, type_show
, NULL
);
298 static ssize_t
modalias_show(struct device
*dev
, struct device_attribute
*attr
,
301 struct subchannel
*sch
= to_subchannel(dev
);
303 return sprintf(buf
, "css:t%01X\n", sch
->st
);
306 static DEVICE_ATTR(modalias
, 0444, modalias_show
, NULL
);
308 static struct attribute
*subch_attrs
[] = {
310 &dev_attr_modalias
.attr
,
314 static struct attribute_group subch_attr_group
= {
315 .attrs
= subch_attrs
,
318 static const struct attribute_group
*default_subch_attr_groups
[] = {
323 static int css_register_subchannel(struct subchannel
*sch
)
327 /* Initialize the subchannel structure */
328 sch
->dev
.parent
= &channel_subsystems
[0]->device
;
329 sch
->dev
.bus
= &css_bus_type
;
330 sch
->dev
.release
= &css_subchannel_release
;
331 sch
->dev
.groups
= default_subch_attr_groups
;
333 * We don't want to generate uevents for I/O subchannels that don't
334 * have a working ccw device behind them since they will be
335 * unregistered before they can be used anyway, so we delay the add
336 * uevent until after device recognition was successful.
337 * Note that we suppress the uevent for all subchannel types;
338 * the subchannel driver can decide itself when it wants to inform
339 * userspace of its existence.
341 dev_set_uevent_suppress(&sch
->dev
, 1);
342 css_update_ssd_info(sch
);
343 /* make it known to the system */
344 ret
= css_sch_device_register(sch
);
346 CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n",
347 sch
->schid
.ssid
, sch
->schid
.sch_no
, ret
);
352 * No driver matched. Generate the uevent now so that
353 * a fitting driver module may be loaded based on the
356 dev_set_uevent_suppress(&sch
->dev
, 0);
357 kobject_uevent(&sch
->dev
.kobj
, KOBJ_ADD
);
362 int css_probe_device(struct subchannel_id schid
)
365 struct subchannel
*sch
;
367 if (cio_is_console(schid
))
368 sch
= cio_get_console_subchannel();
370 sch
= css_alloc_subchannel(schid
);
374 ret
= css_register_subchannel(sch
);
376 if (!cio_is_console(schid
))
377 put_device(&sch
->dev
);
383 check_subchannel(struct device
* dev
, void * data
)
385 struct subchannel
*sch
;
386 struct subchannel_id
*schid
= data
;
388 sch
= to_subchannel(dev
);
389 return schid_equal(&sch
->schid
, schid
);
393 get_subchannel_by_schid(struct subchannel_id schid
)
397 dev
= bus_find_device(&css_bus_type
, NULL
,
398 &schid
, check_subchannel
);
400 return dev
? to_subchannel(dev
) : NULL
;
404 * css_sch_is_valid() - check if a subchannel is valid
405 * @schib: subchannel information block for the subchannel
407 int css_sch_is_valid(struct schib
*schib
)
409 if ((schib
->pmcw
.st
== SUBCHANNEL_TYPE_IO
) && !schib
->pmcw
.dnv
)
411 if ((schib
->pmcw
.st
== SUBCHANNEL_TYPE_MSG
) && !schib
->pmcw
.w
)
415 EXPORT_SYMBOL_GPL(css_sch_is_valid
);
417 static int css_evaluate_new_subchannel(struct subchannel_id schid
, int slow
)
422 /* Will be done on the slow path. */
425 if (stsch_err(schid
, &schib
) || !css_sch_is_valid(&schib
)) {
426 /* Unusable - ignore. */
429 CIO_MSG_EVENT(4, "event: sch 0.%x.%04x, new\n", schid
.ssid
,
432 return css_probe_device(schid
);
435 static int css_evaluate_known_subchannel(struct subchannel
*sch
, int slow
)
440 if (sch
->driver
->sch_event
)
441 ret
= sch
->driver
->sch_event(sch
, slow
);
444 "Got subchannel machine check but "
445 "no sch_event handler provided.\n");
447 if (ret
!= 0 && ret
!= -EAGAIN
) {
448 CIO_MSG_EVENT(2, "eval: sch 0.%x.%04x, rc=%d\n",
449 sch
->schid
.ssid
, sch
->schid
.sch_no
, ret
);
454 static void css_evaluate_subchannel(struct subchannel_id schid
, int slow
)
456 struct subchannel
*sch
;
459 sch
= get_subchannel_by_schid(schid
);
461 ret
= css_evaluate_known_subchannel(sch
, slow
);
462 put_device(&sch
->dev
);
464 ret
= css_evaluate_new_subchannel(schid
, slow
);
466 css_schedule_eval(schid
);
469 static struct idset
*slow_subchannel_set
;
470 static spinlock_t slow_subchannel_lock
;
471 static wait_queue_head_t css_eval_wq
;
472 static atomic_t css_eval_scheduled
;
474 static int __init
slow_subchannel_init(void)
476 spin_lock_init(&slow_subchannel_lock
);
477 atomic_set(&css_eval_scheduled
, 0);
478 init_waitqueue_head(&css_eval_wq
);
479 slow_subchannel_set
= idset_sch_new();
480 if (!slow_subchannel_set
) {
481 CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n");
487 static int slow_eval_known_fn(struct subchannel
*sch
, void *data
)
492 spin_lock_irq(&slow_subchannel_lock
);
493 eval
= idset_sch_contains(slow_subchannel_set
, sch
->schid
);
494 idset_sch_del(slow_subchannel_set
, sch
->schid
);
495 spin_unlock_irq(&slow_subchannel_lock
);
497 rc
= css_evaluate_known_subchannel(sch
, 1);
499 css_schedule_eval(sch
->schid
);
504 static int slow_eval_unknown_fn(struct subchannel_id schid
, void *data
)
509 spin_lock_irq(&slow_subchannel_lock
);
510 eval
= idset_sch_contains(slow_subchannel_set
, schid
);
511 idset_sch_del(slow_subchannel_set
, schid
);
512 spin_unlock_irq(&slow_subchannel_lock
);
514 rc
= css_evaluate_new_subchannel(schid
, 1);
517 css_schedule_eval(schid
);
523 /* These should abort looping */
532 static void css_slow_path_func(struct work_struct
*unused
)
536 CIO_TRACE_EVENT(4, "slowpath");
537 for_each_subchannel_staged(slow_eval_known_fn
, slow_eval_unknown_fn
,
539 spin_lock_irqsave(&slow_subchannel_lock
, flags
);
540 if (idset_is_empty(slow_subchannel_set
)) {
541 atomic_set(&css_eval_scheduled
, 0);
542 wake_up(&css_eval_wq
);
544 spin_unlock_irqrestore(&slow_subchannel_lock
, flags
);
547 static DECLARE_WORK(slow_path_work
, css_slow_path_func
);
548 struct workqueue_struct
*cio_work_q
;
550 void css_schedule_eval(struct subchannel_id schid
)
554 spin_lock_irqsave(&slow_subchannel_lock
, flags
);
555 idset_sch_add(slow_subchannel_set
, schid
);
556 atomic_set(&css_eval_scheduled
, 1);
557 queue_work(cio_work_q
, &slow_path_work
);
558 spin_unlock_irqrestore(&slow_subchannel_lock
, flags
);
561 void css_schedule_eval_all(void)
565 spin_lock_irqsave(&slow_subchannel_lock
, flags
);
566 idset_fill(slow_subchannel_set
);
567 atomic_set(&css_eval_scheduled
, 1);
568 queue_work(cio_work_q
, &slow_path_work
);
569 spin_unlock_irqrestore(&slow_subchannel_lock
, flags
);
572 static int __unset_registered(struct device
*dev
, void *data
)
574 struct idset
*set
= data
;
575 struct subchannel
*sch
= to_subchannel(dev
);
577 idset_sch_del(set
, sch
->schid
);
581 static void css_schedule_eval_all_unreg(void)
584 struct idset
*unreg_set
;
586 /* Find unregistered subchannels. */
587 unreg_set
= idset_sch_new();
590 css_schedule_eval_all();
593 idset_fill(unreg_set
);
594 bus_for_each_dev(&css_bus_type
, NULL
, unreg_set
, __unset_registered
);
595 /* Apply to slow_subchannel_set. */
596 spin_lock_irqsave(&slow_subchannel_lock
, flags
);
597 idset_add_set(slow_subchannel_set
, unreg_set
);
598 atomic_set(&css_eval_scheduled
, 1);
599 queue_work(cio_work_q
, &slow_path_work
);
600 spin_unlock_irqrestore(&slow_subchannel_lock
, flags
);
601 idset_free(unreg_set
);
604 void css_wait_for_slow_path(void)
606 flush_workqueue(cio_work_q
);
609 /* Schedule reprobing of all unregistered subchannels. */
610 void css_schedule_reprobe(void)
612 css_schedule_eval_all_unreg();
614 EXPORT_SYMBOL_GPL(css_schedule_reprobe
);
617 * Called from the machine check handler for subchannel report words.
619 static void css_process_crw(struct crw
*crw0
, struct crw
*crw1
, int overflow
)
621 struct subchannel_id mchk_schid
;
622 struct subchannel
*sch
;
625 css_schedule_eval_all();
628 CIO_CRW_EVENT(2, "CRW0 reports slct=%d, oflw=%d, "
629 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
630 crw0
->slct
, crw0
->oflw
, crw0
->chn
, crw0
->rsc
, crw0
->anc
,
631 crw0
->erc
, crw0
->rsid
);
633 CIO_CRW_EVENT(2, "CRW1 reports slct=%d, oflw=%d, "
634 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
635 crw1
->slct
, crw1
->oflw
, crw1
->chn
, crw1
->rsc
,
636 crw1
->anc
, crw1
->erc
, crw1
->rsid
);
637 init_subchannel_id(&mchk_schid
);
638 mchk_schid
.sch_no
= crw0
->rsid
;
640 mchk_schid
.ssid
= (crw1
->rsid
>> 4) & 3;
642 if (crw0
->erc
== CRW_ERC_PMOD
) {
643 sch
= get_subchannel_by_schid(mchk_schid
);
645 css_update_ssd_info(sch
);
646 put_device(&sch
->dev
);
650 * Since we are always presented with IPI in the CRW, we have to
651 * use stsch() to find out if the subchannel in question has come
654 css_evaluate_subchannel(mchk_schid
, 0);
658 css_generate_pgid(struct channel_subsystem
*css
, u32 tod_high
)
662 if (css_general_characteristics
.mcss
) {
663 css
->global_pgid
.pgid_high
.ext_cssid
.version
= 0x80;
664 css
->global_pgid
.pgid_high
.ext_cssid
.cssid
= css
->cssid
;
667 css
->global_pgid
.pgid_high
.cpu_addr
= stap();
669 css
->global_pgid
.pgid_high
.cpu_addr
= 0;
673 css
->global_pgid
.cpu_id
= cpu_id
.ident
;
674 css
->global_pgid
.cpu_model
= cpu_id
.machine
;
675 css
->global_pgid
.tod_high
= tod_high
;
680 channel_subsystem_release(struct device
*dev
)
682 struct channel_subsystem
*css
;
685 mutex_destroy(&css
->mutex
);
686 if (css
->pseudo_subchannel
) {
687 /* Implies that it has been generated but never registered. */
688 css_subchannel_release(&css
->pseudo_subchannel
->dev
);
689 css
->pseudo_subchannel
= NULL
;
695 css_cm_enable_show(struct device
*dev
, struct device_attribute
*attr
,
698 struct channel_subsystem
*css
= to_css(dev
);
703 mutex_lock(&css
->mutex
);
704 ret
= sprintf(buf
, "%x\n", css
->cm_enabled
);
705 mutex_unlock(&css
->mutex
);
710 css_cm_enable_store(struct device
*dev
, struct device_attribute
*attr
,
711 const char *buf
, size_t count
)
713 struct channel_subsystem
*css
= to_css(dev
);
717 ret
= strict_strtoul(buf
, 16, &val
);
720 mutex_lock(&css
->mutex
);
723 ret
= css
->cm_enabled
? chsc_secm(css
, 0) : 0;
726 ret
= css
->cm_enabled
? 0 : chsc_secm(css
, 1);
731 mutex_unlock(&css
->mutex
);
732 return ret
< 0 ? ret
: count
;
735 static DEVICE_ATTR(cm_enable
, 0644, css_cm_enable_show
, css_cm_enable_store
);
737 static int __init
setup_css(int nr
)
741 struct channel_subsystem
*css
;
743 css
= channel_subsystems
[nr
];
744 memset(css
, 0, sizeof(struct channel_subsystem
));
745 css
->pseudo_subchannel
=
746 kzalloc(sizeof(*css
->pseudo_subchannel
), GFP_KERNEL
);
747 if (!css
->pseudo_subchannel
)
749 css
->pseudo_subchannel
->dev
.parent
= &css
->device
;
750 css
->pseudo_subchannel
->dev
.release
= css_subchannel_release
;
751 dev_set_name(&css
->pseudo_subchannel
->dev
, "defunct");
752 mutex_init(&css
->pseudo_subchannel
->reg_mutex
);
753 ret
= cio_create_sch_lock(css
->pseudo_subchannel
);
755 kfree(css
->pseudo_subchannel
);
758 mutex_init(&css
->mutex
);
761 dev_set_name(&css
->device
, "css%x", nr
);
762 css
->device
.release
= channel_subsystem_release
;
763 tod_high
= (u32
) (get_clock() >> 32);
764 css_generate_pgid(css
, tod_high
);
768 static int css_reboot_event(struct notifier_block
*this,
775 for (i
= 0; i
<= __MAX_CSSID
; i
++) {
776 struct channel_subsystem
*css
;
778 css
= channel_subsystems
[i
];
779 mutex_lock(&css
->mutex
);
781 if (chsc_secm(css
, 0))
783 mutex_unlock(&css
->mutex
);
789 static struct notifier_block css_reboot_notifier
= {
790 .notifier_call
= css_reboot_event
,
794 * Since the css devices are neither on a bus nor have a class
795 * nor have a special device type, we cannot stop/restart channel
796 * path measurements via the normal suspend/resume callbacks, but have
799 static int css_power_event(struct notifier_block
*this, unsigned long event
,
805 case PM_HIBERNATION_PREPARE
:
806 case PM_SUSPEND_PREPARE
:
808 for (i
= 0; i
<= __MAX_CSSID
; i
++) {
809 struct channel_subsystem
*css
;
811 css
= channel_subsystems
[i
];
812 mutex_lock(&css
->mutex
);
813 if (!css
->cm_enabled
) {
814 mutex_unlock(&css
->mutex
);
817 ret
= __chsc_do_secm(css
, 0);
818 ret
= notifier_from_errno(ret
);
819 mutex_unlock(&css
->mutex
);
822 case PM_POST_HIBERNATION
:
823 case PM_POST_SUSPEND
:
825 for (i
= 0; i
<= __MAX_CSSID
; i
++) {
826 struct channel_subsystem
*css
;
828 css
= channel_subsystems
[i
];
829 mutex_lock(&css
->mutex
);
830 if (!css
->cm_enabled
) {
831 mutex_unlock(&css
->mutex
);
834 ret
= __chsc_do_secm(css
, 1);
835 ret
= notifier_from_errno(ret
);
836 mutex_unlock(&css
->mutex
);
838 /* search for subchannels, which appeared during hibernation */
839 css_schedule_reprobe();
847 static struct notifier_block css_power_notifier
= {
848 .notifier_call
= css_power_event
,
852 * Now that the driver core is running, we can setup our channel subsystem.
853 * The struct subchannel's are created during probing (except for the
854 * static console subchannel).
856 static int __init
css_bus_init(void)
864 chsc_determine_css_characteristics();
865 /* Try to enable MSS. */
866 ret
= chsc_enable_facility(CHSC_SDA_OC_MSS
);
870 max_ssid
= __MAX_SSID
;
872 ret
= slow_subchannel_init();
876 ret
= crw_register_handler(CRW_RSC_SCH
, css_process_crw
);
880 if ((ret
= bus_register(&css_bus_type
)))
883 /* Setup css structure. */
884 for (i
= 0; i
<= __MAX_CSSID
; i
++) {
885 struct channel_subsystem
*css
;
887 css
= kmalloc(sizeof(struct channel_subsystem
), GFP_KERNEL
);
892 channel_subsystems
[i
] = css
;
895 kfree(channel_subsystems
[i
]);
898 ret
= device_register(&css
->device
);
900 put_device(&css
->device
);
903 if (css_chsc_characteristics
.secm
) {
904 ret
= device_create_file(&css
->device
,
905 &dev_attr_cm_enable
);
909 ret
= device_register(&css
->pseudo_subchannel
->dev
);
911 put_device(&css
->pseudo_subchannel
->dev
);
915 ret
= register_reboot_notifier(&css_reboot_notifier
);
918 ret
= register_pm_notifier(&css_power_notifier
);
920 unregister_reboot_notifier(&css_reboot_notifier
);
925 /* Enable default isc for I/O subchannels. */
926 isc_register(IO_SCH_ISC
);
930 if (css_chsc_characteristics
.secm
)
931 device_remove_file(&channel_subsystems
[i
]->device
,
932 &dev_attr_cm_enable
);
934 device_unregister(&channel_subsystems
[i
]->device
);
937 struct channel_subsystem
*css
;
940 css
= channel_subsystems
[i
];
941 device_unregister(&css
->pseudo_subchannel
->dev
);
942 css
->pseudo_subchannel
= NULL
;
943 if (css_chsc_characteristics
.secm
)
944 device_remove_file(&css
->device
,
945 &dev_attr_cm_enable
);
946 device_unregister(&css
->device
);
948 bus_unregister(&css_bus_type
);
950 crw_unregister_handler(CRW_RSC_SCH
);
951 idset_free(slow_subchannel_set
);
953 pr_alert("The CSS device driver initialization failed with "
958 static void __init
css_bus_cleanup(void)
960 struct channel_subsystem
*css
;
963 for (i
= 0; i
<= __MAX_CSSID
; i
++) {
964 css
= channel_subsystems
[i
];
965 device_unregister(&css
->pseudo_subchannel
->dev
);
966 css
->pseudo_subchannel
= NULL
;
967 if (css_chsc_characteristics
.secm
)
968 device_remove_file(&css
->device
, &dev_attr_cm_enable
);
969 device_unregister(&css
->device
);
971 bus_unregister(&css_bus_type
);
972 crw_unregister_handler(CRW_RSC_SCH
);
973 idset_free(slow_subchannel_set
);
975 isc_unregister(IO_SCH_ISC
);
978 static int __init
channel_subsystem_init(void)
982 ret
= css_bus_init();
985 cio_work_q
= create_singlethread_workqueue("cio");
990 ret
= io_subchannel_init();
996 destroy_workqueue(cio_work_q
);
1001 subsys_initcall(channel_subsystem_init
);
1003 static int css_settle(struct device_driver
*drv
, void *unused
)
1005 struct css_driver
*cssdrv
= to_cssdriver(drv
);
1008 return cssdrv
->settle();
1012 int css_complete_work(void)
1016 /* Wait for the evaluation of subchannels to finish. */
1017 ret
= wait_event_interruptible(css_eval_wq
,
1018 atomic_read(&css_eval_scheduled
) == 0);
1021 flush_workqueue(cio_work_q
);
1022 /* Wait for the subchannel type specific initialization to finish */
1023 return bus_for_each_drv(&css_bus_type
, NULL
, NULL
, css_settle
);
1028 * Wait for the initialization of devices to finish, to make sure we are
1029 * done with our setup if the search for the root device starts.
1031 static int __init
channel_subsystem_init_sync(void)
1033 /* Start initial subchannel evaluation. */
1034 css_schedule_eval_all();
1035 css_complete_work();
1038 subsys_initcall_sync(channel_subsystem_init_sync
);
1040 void channel_subsystem_reinit(void)
1042 struct channel_path
*chp
;
1043 struct chp_id chpid
;
1045 chsc_enable_facility(CHSC_SDA_OC_MSS
);
1046 chp_id_for_each(&chpid
) {
1047 chp
= chpid_to_chp(chpid
);
1050 chsc_determine_base_channel_path_desc(chpid
, &chp
->desc
);
1054 #ifdef CONFIG_PROC_FS
1055 static ssize_t
cio_settle_write(struct file
*file
, const char __user
*buf
,
1056 size_t count
, loff_t
*ppos
)
1060 /* Handle pending CRW's. */
1061 crw_wait_for_channel_report();
1062 ret
= css_complete_work();
1064 return ret
? ret
: count
;
1067 static const struct file_operations cio_settle_proc_fops
= {
1068 .open
= nonseekable_open
,
1069 .write
= cio_settle_write
,
1070 .llseek
= no_llseek
,
1073 static int __init
cio_settle_init(void)
1075 struct proc_dir_entry
*entry
;
1077 entry
= proc_create("cio_settle", S_IWUSR
, NULL
,
1078 &cio_settle_proc_fops
);
1083 device_initcall(cio_settle_init
);
1084 #endif /*CONFIG_PROC_FS*/
1086 int sch_is_pseudo_sch(struct subchannel
*sch
)
1088 return sch
== to_css(sch
->dev
.parent
)->pseudo_subchannel
;
1091 static int css_bus_match(struct device
*dev
, struct device_driver
*drv
)
1093 struct subchannel
*sch
= to_subchannel(dev
);
1094 struct css_driver
*driver
= to_cssdriver(drv
);
1095 struct css_device_id
*id
;
1097 for (id
= driver
->subchannel_type
; id
->match_flags
; id
++) {
1098 if (sch
->st
== id
->type
)
1105 static int css_probe(struct device
*dev
)
1107 struct subchannel
*sch
;
1110 sch
= to_subchannel(dev
);
1111 sch
->driver
= to_cssdriver(dev
->driver
);
1112 ret
= sch
->driver
->probe
? sch
->driver
->probe(sch
) : 0;
1118 static int css_remove(struct device
*dev
)
1120 struct subchannel
*sch
;
1123 sch
= to_subchannel(dev
);
1124 ret
= sch
->driver
->remove
? sch
->driver
->remove(sch
) : 0;
1129 static void css_shutdown(struct device
*dev
)
1131 struct subchannel
*sch
;
1133 sch
= to_subchannel(dev
);
1134 if (sch
->driver
&& sch
->driver
->shutdown
)
1135 sch
->driver
->shutdown(sch
);
1138 static int css_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
1140 struct subchannel
*sch
= to_subchannel(dev
);
1143 ret
= add_uevent_var(env
, "ST=%01X", sch
->st
);
1146 ret
= add_uevent_var(env
, "MODALIAS=css:t%01X", sch
->st
);
1150 static int css_pm_prepare(struct device
*dev
)
1152 struct subchannel
*sch
= to_subchannel(dev
);
1153 struct css_driver
*drv
;
1155 if (mutex_is_locked(&sch
->reg_mutex
))
1157 if (!sch
->dev
.driver
)
1159 drv
= to_cssdriver(sch
->dev
.driver
);
1160 /* Notify drivers that they may not register children. */
1161 return drv
->prepare
? drv
->prepare(sch
) : 0;
1164 static void css_pm_complete(struct device
*dev
)
1166 struct subchannel
*sch
= to_subchannel(dev
);
1167 struct css_driver
*drv
;
1169 if (!sch
->dev
.driver
)
1171 drv
= to_cssdriver(sch
->dev
.driver
);
1176 static int css_pm_freeze(struct device
*dev
)
1178 struct subchannel
*sch
= to_subchannel(dev
);
1179 struct css_driver
*drv
;
1181 if (!sch
->dev
.driver
)
1183 drv
= to_cssdriver(sch
->dev
.driver
);
1184 return drv
->freeze
? drv
->freeze(sch
) : 0;
1187 static int css_pm_thaw(struct device
*dev
)
1189 struct subchannel
*sch
= to_subchannel(dev
);
1190 struct css_driver
*drv
;
1192 if (!sch
->dev
.driver
)
1194 drv
= to_cssdriver(sch
->dev
.driver
);
1195 return drv
->thaw
? drv
->thaw(sch
) : 0;
1198 static int css_pm_restore(struct device
*dev
)
1200 struct subchannel
*sch
= to_subchannel(dev
);
1201 struct css_driver
*drv
;
1203 css_update_ssd_info(sch
);
1204 if (!sch
->dev
.driver
)
1206 drv
= to_cssdriver(sch
->dev
.driver
);
1207 return drv
->restore
? drv
->restore(sch
) : 0;
1210 static const struct dev_pm_ops css_pm_ops
= {
1211 .prepare
= css_pm_prepare
,
1212 .complete
= css_pm_complete
,
1213 .freeze
= css_pm_freeze
,
1214 .thaw
= css_pm_thaw
,
1215 .restore
= css_pm_restore
,
1218 static struct bus_type css_bus_type
= {
1220 .match
= css_bus_match
,
1222 .remove
= css_remove
,
1223 .shutdown
= css_shutdown
,
1224 .uevent
= css_uevent
,
1229 * css_driver_register - register a css driver
1230 * @cdrv: css driver to register
1232 * This is mainly a wrapper around driver_register that sets name
1233 * and bus_type in the embedded struct device_driver correctly.
1235 int css_driver_register(struct css_driver
*cdrv
)
1237 cdrv
->drv
.bus
= &css_bus_type
;
1238 return driver_register(&cdrv
->drv
);
1240 EXPORT_SYMBOL_GPL(css_driver_register
);
1243 * css_driver_unregister - unregister a css driver
1244 * @cdrv: css driver to unregister
1246 * This is a wrapper around driver_unregister.
1248 void css_driver_unregister(struct css_driver
*cdrv
)
1250 driver_unregister(&cdrv
->drv
);
1252 EXPORT_SYMBOL_GPL(css_driver_unregister
);
1254 MODULE_LICENSE("GPL");