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 ssd_from_pmcw(struct chsc_ssd_info
*ssd
, struct pmcw
*pmcw
)
203 memset(ssd
, 0, sizeof(struct chsc_ssd_info
));
204 ssd
->path_mask
= pmcw
->pim
;
205 for (i
= 0; i
< 8; i
++) {
207 if (pmcw
->pim
& mask
) {
208 chp_id_init(&ssd
->chpid
[i
]);
209 ssd
->chpid
[i
].id
= pmcw
->chpid
[i
];
214 static void ssd_register_chpids(struct chsc_ssd_info
*ssd
)
219 for (i
= 0; i
< 8; i
++) {
221 if (ssd
->path_mask
& mask
)
222 if (!chp_is_registered(ssd
->chpid
[i
]))
223 chp_new(ssd
->chpid
[i
]);
227 void css_update_ssd_info(struct subchannel
*sch
)
231 if (cio_is_console(sch
->schid
)) {
232 /* Console is initialized too early for functions requiring
233 * memory allocation. */
234 ssd_from_pmcw(&sch
->ssd_info
, &sch
->schib
.pmcw
);
236 ret
= chsc_get_ssd_info(sch
->schid
, &sch
->ssd_info
);
238 ssd_from_pmcw(&sch
->ssd_info
, &sch
->schib
.pmcw
);
239 ssd_register_chpids(&sch
->ssd_info
);
243 static ssize_t
type_show(struct device
*dev
, struct device_attribute
*attr
,
246 struct subchannel
*sch
= to_subchannel(dev
);
248 return sprintf(buf
, "%01x\n", sch
->st
);
251 static DEVICE_ATTR(type
, 0444, type_show
, NULL
);
253 static ssize_t
modalias_show(struct device
*dev
, struct device_attribute
*attr
,
256 struct subchannel
*sch
= to_subchannel(dev
);
258 return sprintf(buf
, "css:t%01X\n", sch
->st
);
261 static DEVICE_ATTR(modalias
, 0444, modalias_show
, NULL
);
263 static struct attribute
*subch_attrs
[] = {
265 &dev_attr_modalias
.attr
,
269 static struct attribute_group subch_attr_group
= {
270 .attrs
= subch_attrs
,
273 static const struct attribute_group
*default_subch_attr_groups
[] = {
278 static int css_register_subchannel(struct subchannel
*sch
)
282 /* Initialize the subchannel structure */
283 sch
->dev
.parent
= &channel_subsystems
[0]->device
;
284 sch
->dev
.bus
= &css_bus_type
;
285 sch
->dev
.release
= &css_subchannel_release
;
286 sch
->dev
.groups
= default_subch_attr_groups
;
288 * We don't want to generate uevents for I/O subchannels that don't
289 * have a working ccw device behind them since they will be
290 * unregistered before they can be used anyway, so we delay the add
291 * uevent until after device recognition was successful.
292 * Note that we suppress the uevent for all subchannel types;
293 * the subchannel driver can decide itself when it wants to inform
294 * userspace of its existence.
296 dev_set_uevent_suppress(&sch
->dev
, 1);
297 css_update_ssd_info(sch
);
298 /* make it known to the system */
299 ret
= css_sch_device_register(sch
);
301 CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n",
302 sch
->schid
.ssid
, sch
->schid
.sch_no
, ret
);
307 * No driver matched. Generate the uevent now so that
308 * a fitting driver module may be loaded based on the
311 dev_set_uevent_suppress(&sch
->dev
, 0);
312 kobject_uevent(&sch
->dev
.kobj
, KOBJ_ADD
);
317 int css_probe_device(struct subchannel_id schid
)
320 struct subchannel
*sch
;
322 if (cio_is_console(schid
))
323 sch
= cio_get_console_subchannel();
325 sch
= css_alloc_subchannel(schid
);
329 ret
= css_register_subchannel(sch
);
331 if (!cio_is_console(schid
))
332 put_device(&sch
->dev
);
338 check_subchannel(struct device
* dev
, void * data
)
340 struct subchannel
*sch
;
341 struct subchannel_id
*schid
= data
;
343 sch
= to_subchannel(dev
);
344 return schid_equal(&sch
->schid
, schid
);
348 get_subchannel_by_schid(struct subchannel_id schid
)
352 dev
= bus_find_device(&css_bus_type
, NULL
,
353 &schid
, check_subchannel
);
355 return dev
? to_subchannel(dev
) : NULL
;
359 * css_sch_is_valid() - check if a subchannel is valid
360 * @schib: subchannel information block for the subchannel
362 int css_sch_is_valid(struct schib
*schib
)
364 if ((schib
->pmcw
.st
== SUBCHANNEL_TYPE_IO
) && !schib
->pmcw
.dnv
)
366 if ((schib
->pmcw
.st
== SUBCHANNEL_TYPE_MSG
) && !schib
->pmcw
.w
)
370 EXPORT_SYMBOL_GPL(css_sch_is_valid
);
372 static int css_evaluate_new_subchannel(struct subchannel_id schid
, int slow
)
377 /* Will be done on the slow path. */
380 if (stsch_err(schid
, &schib
) || !css_sch_is_valid(&schib
)) {
381 /* Unusable - ignore. */
384 CIO_MSG_EVENT(4, "event: sch 0.%x.%04x, new\n", schid
.ssid
,
387 return css_probe_device(schid
);
390 static int css_evaluate_known_subchannel(struct subchannel
*sch
, int slow
)
395 if (sch
->driver
->sch_event
)
396 ret
= sch
->driver
->sch_event(sch
, slow
);
399 "Got subchannel machine check but "
400 "no sch_event handler provided.\n");
402 if (ret
!= 0 && ret
!= -EAGAIN
) {
403 CIO_MSG_EVENT(2, "eval: sch 0.%x.%04x, rc=%d\n",
404 sch
->schid
.ssid
, sch
->schid
.sch_no
, ret
);
409 static void css_evaluate_subchannel(struct subchannel_id schid
, int slow
)
411 struct subchannel
*sch
;
414 sch
= get_subchannel_by_schid(schid
);
416 ret
= css_evaluate_known_subchannel(sch
, slow
);
417 put_device(&sch
->dev
);
419 ret
= css_evaluate_new_subchannel(schid
, slow
);
421 css_schedule_eval(schid
);
425 * css_sched_sch_todo - schedule a subchannel operation
429 * Schedule the operation identified by @todo to be performed on the slow path
430 * workqueue. Do nothing if another operation with higher priority is already
431 * scheduled. Needs to be called with subchannel lock held.
433 void css_sched_sch_todo(struct subchannel
*sch
, enum sch_todo todo
)
435 CIO_MSG_EVENT(4, "sch_todo: sched sch=0.%x.%04x todo=%d\n",
436 sch
->schid
.ssid
, sch
->schid
.sch_no
, todo
);
437 if (sch
->todo
>= todo
)
439 /* Get workqueue ref. */
440 if (!get_device(&sch
->dev
))
443 if (!queue_work(cio_work_q
, &sch
->todo_work
)) {
444 /* Already queued, release workqueue ref. */
445 put_device(&sch
->dev
);
449 static void css_sch_todo(struct work_struct
*work
)
451 struct subchannel
*sch
;
455 sch
= container_of(work
, struct subchannel
, todo_work
);
457 spin_lock_irq(sch
->lock
);
459 CIO_MSG_EVENT(4, "sch_todo: sch=0.%x.%04x, todo=%d\n", sch
->schid
.ssid
,
460 sch
->schid
.sch_no
, todo
);
461 sch
->todo
= SCH_TODO_NOTHING
;
462 spin_unlock_irq(sch
->lock
);
465 case SCH_TODO_NOTHING
:
468 ret
= css_evaluate_known_subchannel(sch
, 1);
469 if (ret
== -EAGAIN
) {
470 spin_lock_irq(sch
->lock
);
471 css_sched_sch_todo(sch
, todo
);
472 spin_unlock_irq(sch
->lock
);
476 css_sch_device_unregister(sch
);
479 /* Release workqueue ref. */
480 put_device(&sch
->dev
);
483 static struct idset
*slow_subchannel_set
;
484 static spinlock_t slow_subchannel_lock
;
485 static wait_queue_head_t css_eval_wq
;
486 static atomic_t css_eval_scheduled
;
488 static int __init
slow_subchannel_init(void)
490 spin_lock_init(&slow_subchannel_lock
);
491 atomic_set(&css_eval_scheduled
, 0);
492 init_waitqueue_head(&css_eval_wq
);
493 slow_subchannel_set
= idset_sch_new();
494 if (!slow_subchannel_set
) {
495 CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n");
501 static int slow_eval_known_fn(struct subchannel
*sch
, void *data
)
506 spin_lock_irq(&slow_subchannel_lock
);
507 eval
= idset_sch_contains(slow_subchannel_set
, sch
->schid
);
508 idset_sch_del(slow_subchannel_set
, sch
->schid
);
509 spin_unlock_irq(&slow_subchannel_lock
);
511 rc
= css_evaluate_known_subchannel(sch
, 1);
513 css_schedule_eval(sch
->schid
);
518 static int slow_eval_unknown_fn(struct subchannel_id schid
, void *data
)
523 spin_lock_irq(&slow_subchannel_lock
);
524 eval
= idset_sch_contains(slow_subchannel_set
, schid
);
525 idset_sch_del(slow_subchannel_set
, schid
);
526 spin_unlock_irq(&slow_subchannel_lock
);
528 rc
= css_evaluate_new_subchannel(schid
, 1);
531 css_schedule_eval(schid
);
537 /* These should abort looping */
546 static void css_slow_path_func(struct work_struct
*unused
)
550 CIO_TRACE_EVENT(4, "slowpath");
551 for_each_subchannel_staged(slow_eval_known_fn
, slow_eval_unknown_fn
,
553 spin_lock_irqsave(&slow_subchannel_lock
, flags
);
554 if (idset_is_empty(slow_subchannel_set
)) {
555 atomic_set(&css_eval_scheduled
, 0);
556 wake_up(&css_eval_wq
);
558 spin_unlock_irqrestore(&slow_subchannel_lock
, flags
);
561 static DECLARE_WORK(slow_path_work
, css_slow_path_func
);
562 struct workqueue_struct
*cio_work_q
;
564 void css_schedule_eval(struct subchannel_id schid
)
568 spin_lock_irqsave(&slow_subchannel_lock
, flags
);
569 idset_sch_add(slow_subchannel_set
, schid
);
570 atomic_set(&css_eval_scheduled
, 1);
571 queue_work(cio_work_q
, &slow_path_work
);
572 spin_unlock_irqrestore(&slow_subchannel_lock
, flags
);
575 void css_schedule_eval_all(void)
579 spin_lock_irqsave(&slow_subchannel_lock
, flags
);
580 idset_fill(slow_subchannel_set
);
581 atomic_set(&css_eval_scheduled
, 1);
582 queue_work(cio_work_q
, &slow_path_work
);
583 spin_unlock_irqrestore(&slow_subchannel_lock
, flags
);
586 static int __unset_registered(struct device
*dev
, void *data
)
588 struct idset
*set
= data
;
589 struct subchannel
*sch
= to_subchannel(dev
);
591 idset_sch_del(set
, sch
->schid
);
595 static void css_schedule_eval_all_unreg(void)
598 struct idset
*unreg_set
;
600 /* Find unregistered subchannels. */
601 unreg_set
= idset_sch_new();
604 css_schedule_eval_all();
607 idset_fill(unreg_set
);
608 bus_for_each_dev(&css_bus_type
, NULL
, unreg_set
, __unset_registered
);
609 /* Apply to slow_subchannel_set. */
610 spin_lock_irqsave(&slow_subchannel_lock
, flags
);
611 idset_add_set(slow_subchannel_set
, unreg_set
);
612 atomic_set(&css_eval_scheduled
, 1);
613 queue_work(cio_work_q
, &slow_path_work
);
614 spin_unlock_irqrestore(&slow_subchannel_lock
, flags
);
615 idset_free(unreg_set
);
618 void css_wait_for_slow_path(void)
620 flush_workqueue(cio_work_q
);
623 /* Schedule reprobing of all unregistered subchannels. */
624 void css_schedule_reprobe(void)
626 css_schedule_eval_all_unreg();
628 EXPORT_SYMBOL_GPL(css_schedule_reprobe
);
631 * Called from the machine check handler for subchannel report words.
633 static void css_process_crw(struct crw
*crw0
, struct crw
*crw1
, int overflow
)
635 struct subchannel_id mchk_schid
;
636 struct subchannel
*sch
;
639 css_schedule_eval_all();
642 CIO_CRW_EVENT(2, "CRW0 reports slct=%d, oflw=%d, "
643 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
644 crw0
->slct
, crw0
->oflw
, crw0
->chn
, crw0
->rsc
, crw0
->anc
,
645 crw0
->erc
, crw0
->rsid
);
647 CIO_CRW_EVENT(2, "CRW1 reports slct=%d, oflw=%d, "
648 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
649 crw1
->slct
, crw1
->oflw
, crw1
->chn
, crw1
->rsc
,
650 crw1
->anc
, crw1
->erc
, crw1
->rsid
);
651 init_subchannel_id(&mchk_schid
);
652 mchk_schid
.sch_no
= crw0
->rsid
;
654 mchk_schid
.ssid
= (crw1
->rsid
>> 4) & 3;
656 if (crw0
->erc
== CRW_ERC_PMOD
) {
657 sch
= get_subchannel_by_schid(mchk_schid
);
659 css_update_ssd_info(sch
);
660 put_device(&sch
->dev
);
664 * Since we are always presented with IPI in the CRW, we have to
665 * use stsch() to find out if the subchannel in question has come
668 css_evaluate_subchannel(mchk_schid
, 0);
672 css_generate_pgid(struct channel_subsystem
*css
, u32 tod_high
)
676 if (css_general_characteristics
.mcss
) {
677 css
->global_pgid
.pgid_high
.ext_cssid
.version
= 0x80;
678 css
->global_pgid
.pgid_high
.ext_cssid
.cssid
= css
->cssid
;
681 css
->global_pgid
.pgid_high
.cpu_addr
= stap();
683 css
->global_pgid
.pgid_high
.cpu_addr
= 0;
687 css
->global_pgid
.cpu_id
= cpu_id
.ident
;
688 css
->global_pgid
.cpu_model
= cpu_id
.machine
;
689 css
->global_pgid
.tod_high
= tod_high
;
694 channel_subsystem_release(struct device
*dev
)
696 struct channel_subsystem
*css
;
699 mutex_destroy(&css
->mutex
);
700 if (css
->pseudo_subchannel
) {
701 /* Implies that it has been generated but never registered. */
702 css_subchannel_release(&css
->pseudo_subchannel
->dev
);
703 css
->pseudo_subchannel
= NULL
;
709 css_cm_enable_show(struct device
*dev
, struct device_attribute
*attr
,
712 struct channel_subsystem
*css
= to_css(dev
);
717 mutex_lock(&css
->mutex
);
718 ret
= sprintf(buf
, "%x\n", css
->cm_enabled
);
719 mutex_unlock(&css
->mutex
);
724 css_cm_enable_store(struct device
*dev
, struct device_attribute
*attr
,
725 const char *buf
, size_t count
)
727 struct channel_subsystem
*css
= to_css(dev
);
731 ret
= strict_strtoul(buf
, 16, &val
);
734 mutex_lock(&css
->mutex
);
737 ret
= css
->cm_enabled
? chsc_secm(css
, 0) : 0;
740 ret
= css
->cm_enabled
? 0 : chsc_secm(css
, 1);
745 mutex_unlock(&css
->mutex
);
746 return ret
< 0 ? ret
: count
;
749 static DEVICE_ATTR(cm_enable
, 0644, css_cm_enable_show
, css_cm_enable_store
);
751 static int __init
setup_css(int nr
)
755 struct channel_subsystem
*css
;
757 css
= channel_subsystems
[nr
];
758 memset(css
, 0, sizeof(struct channel_subsystem
));
759 css
->pseudo_subchannel
=
760 kzalloc(sizeof(*css
->pseudo_subchannel
), GFP_KERNEL
);
761 if (!css
->pseudo_subchannel
)
763 css
->pseudo_subchannel
->dev
.parent
= &css
->device
;
764 css
->pseudo_subchannel
->dev
.release
= css_subchannel_release
;
765 dev_set_name(&css
->pseudo_subchannel
->dev
, "defunct");
766 mutex_init(&css
->pseudo_subchannel
->reg_mutex
);
767 ret
= cio_create_sch_lock(css
->pseudo_subchannel
);
769 kfree(css
->pseudo_subchannel
);
772 mutex_init(&css
->mutex
);
775 dev_set_name(&css
->device
, "css%x", nr
);
776 css
->device
.release
= channel_subsystem_release
;
777 tod_high
= (u32
) (get_clock() >> 32);
778 css_generate_pgid(css
, tod_high
);
782 static int css_reboot_event(struct notifier_block
*this,
789 for (i
= 0; i
<= __MAX_CSSID
; i
++) {
790 struct channel_subsystem
*css
;
792 css
= channel_subsystems
[i
];
793 mutex_lock(&css
->mutex
);
795 if (chsc_secm(css
, 0))
797 mutex_unlock(&css
->mutex
);
803 static struct notifier_block css_reboot_notifier
= {
804 .notifier_call
= css_reboot_event
,
808 * Since the css devices are neither on a bus nor have a class
809 * nor have a special device type, we cannot stop/restart channel
810 * path measurements via the normal suspend/resume callbacks, but have
813 static int css_power_event(struct notifier_block
*this, unsigned long event
,
819 case PM_HIBERNATION_PREPARE
:
820 case PM_SUSPEND_PREPARE
:
822 for (i
= 0; i
<= __MAX_CSSID
; i
++) {
823 struct channel_subsystem
*css
;
825 css
= channel_subsystems
[i
];
826 mutex_lock(&css
->mutex
);
827 if (!css
->cm_enabled
) {
828 mutex_unlock(&css
->mutex
);
831 ret
= __chsc_do_secm(css
, 0);
832 ret
= notifier_from_errno(ret
);
833 mutex_unlock(&css
->mutex
);
836 case PM_POST_HIBERNATION
:
837 case PM_POST_SUSPEND
:
839 for (i
= 0; i
<= __MAX_CSSID
; i
++) {
840 struct channel_subsystem
*css
;
842 css
= channel_subsystems
[i
];
843 mutex_lock(&css
->mutex
);
844 if (!css
->cm_enabled
) {
845 mutex_unlock(&css
->mutex
);
848 ret
= __chsc_do_secm(css
, 1);
849 ret
= notifier_from_errno(ret
);
850 mutex_unlock(&css
->mutex
);
852 /* search for subchannels, which appeared during hibernation */
853 css_schedule_reprobe();
861 static struct notifier_block css_power_notifier
= {
862 .notifier_call
= css_power_event
,
866 * Now that the driver core is running, we can setup our channel subsystem.
867 * The struct subchannel's are created during probing (except for the
868 * static console subchannel).
870 static int __init
css_bus_init(void)
878 chsc_determine_css_characteristics();
879 /* Try to enable MSS. */
880 ret
= chsc_enable_facility(CHSC_SDA_OC_MSS
);
884 max_ssid
= __MAX_SSID
;
886 ret
= slow_subchannel_init();
890 ret
= crw_register_handler(CRW_RSC_SCH
, css_process_crw
);
894 if ((ret
= bus_register(&css_bus_type
)))
897 /* Setup css structure. */
898 for (i
= 0; i
<= __MAX_CSSID
; i
++) {
899 struct channel_subsystem
*css
;
901 css
= kmalloc(sizeof(struct channel_subsystem
), GFP_KERNEL
);
906 channel_subsystems
[i
] = css
;
909 kfree(channel_subsystems
[i
]);
912 ret
= device_register(&css
->device
);
914 put_device(&css
->device
);
917 if (css_chsc_characteristics
.secm
) {
918 ret
= device_create_file(&css
->device
,
919 &dev_attr_cm_enable
);
923 ret
= device_register(&css
->pseudo_subchannel
->dev
);
925 put_device(&css
->pseudo_subchannel
->dev
);
929 ret
= register_reboot_notifier(&css_reboot_notifier
);
932 ret
= register_pm_notifier(&css_power_notifier
);
934 unregister_reboot_notifier(&css_reboot_notifier
);
939 /* Enable default isc for I/O subchannels. */
940 isc_register(IO_SCH_ISC
);
944 if (css_chsc_characteristics
.secm
)
945 device_remove_file(&channel_subsystems
[i
]->device
,
946 &dev_attr_cm_enable
);
948 device_unregister(&channel_subsystems
[i
]->device
);
951 struct channel_subsystem
*css
;
954 css
= channel_subsystems
[i
];
955 device_unregister(&css
->pseudo_subchannel
->dev
);
956 css
->pseudo_subchannel
= NULL
;
957 if (css_chsc_characteristics
.secm
)
958 device_remove_file(&css
->device
,
959 &dev_attr_cm_enable
);
960 device_unregister(&css
->device
);
962 bus_unregister(&css_bus_type
);
964 crw_unregister_handler(CRW_RSC_SCH
);
965 idset_free(slow_subchannel_set
);
967 pr_alert("The CSS device driver initialization failed with "
972 static void __init
css_bus_cleanup(void)
974 struct channel_subsystem
*css
;
977 for (i
= 0; i
<= __MAX_CSSID
; i
++) {
978 css
= channel_subsystems
[i
];
979 device_unregister(&css
->pseudo_subchannel
->dev
);
980 css
->pseudo_subchannel
= NULL
;
981 if (css_chsc_characteristics
.secm
)
982 device_remove_file(&css
->device
, &dev_attr_cm_enable
);
983 device_unregister(&css
->device
);
985 bus_unregister(&css_bus_type
);
986 crw_unregister_handler(CRW_RSC_SCH
);
987 idset_free(slow_subchannel_set
);
989 isc_unregister(IO_SCH_ISC
);
992 static int __init
channel_subsystem_init(void)
996 ret
= css_bus_init();
999 cio_work_q
= create_singlethread_workqueue("cio");
1004 ret
= io_subchannel_init();
1010 destroy_workqueue(cio_work_q
);
1015 subsys_initcall(channel_subsystem_init
);
1017 static int css_settle(struct device_driver
*drv
, void *unused
)
1019 struct css_driver
*cssdrv
= to_cssdriver(drv
);
1022 return cssdrv
->settle();
1026 int css_complete_work(void)
1030 /* Wait for the evaluation of subchannels to finish. */
1031 ret
= wait_event_interruptible(css_eval_wq
,
1032 atomic_read(&css_eval_scheduled
) == 0);
1035 flush_workqueue(cio_work_q
);
1036 /* Wait for the subchannel type specific initialization to finish */
1037 return bus_for_each_drv(&css_bus_type
, NULL
, NULL
, css_settle
);
1042 * Wait for the initialization of devices to finish, to make sure we are
1043 * done with our setup if the search for the root device starts.
1045 static int __init
channel_subsystem_init_sync(void)
1047 /* Start initial subchannel evaluation. */
1048 css_schedule_eval_all();
1049 css_complete_work();
1052 subsys_initcall_sync(channel_subsystem_init_sync
);
1054 void channel_subsystem_reinit(void)
1056 struct channel_path
*chp
;
1057 struct chp_id chpid
;
1059 chsc_enable_facility(CHSC_SDA_OC_MSS
);
1060 chp_id_for_each(&chpid
) {
1061 chp
= chpid_to_chp(chpid
);
1064 chsc_determine_base_channel_path_desc(chpid
, &chp
->desc
);
1068 #ifdef CONFIG_PROC_FS
1069 static ssize_t
cio_settle_write(struct file
*file
, const char __user
*buf
,
1070 size_t count
, loff_t
*ppos
)
1074 /* Handle pending CRW's. */
1075 crw_wait_for_channel_report();
1076 ret
= css_complete_work();
1078 return ret
? ret
: count
;
1081 static const struct file_operations cio_settle_proc_fops
= {
1082 .open
= nonseekable_open
,
1083 .write
= cio_settle_write
,
1084 .llseek
= no_llseek
,
1087 static int __init
cio_settle_init(void)
1089 struct proc_dir_entry
*entry
;
1091 entry
= proc_create("cio_settle", S_IWUSR
, NULL
,
1092 &cio_settle_proc_fops
);
1097 device_initcall(cio_settle_init
);
1098 #endif /*CONFIG_PROC_FS*/
1100 int sch_is_pseudo_sch(struct subchannel
*sch
)
1102 return sch
== to_css(sch
->dev
.parent
)->pseudo_subchannel
;
1105 static int css_bus_match(struct device
*dev
, struct device_driver
*drv
)
1107 struct subchannel
*sch
= to_subchannel(dev
);
1108 struct css_driver
*driver
= to_cssdriver(drv
);
1109 struct css_device_id
*id
;
1111 for (id
= driver
->subchannel_type
; id
->match_flags
; id
++) {
1112 if (sch
->st
== id
->type
)
1119 static int css_probe(struct device
*dev
)
1121 struct subchannel
*sch
;
1124 sch
= to_subchannel(dev
);
1125 sch
->driver
= to_cssdriver(dev
->driver
);
1126 ret
= sch
->driver
->probe
? sch
->driver
->probe(sch
) : 0;
1132 static int css_remove(struct device
*dev
)
1134 struct subchannel
*sch
;
1137 sch
= to_subchannel(dev
);
1138 ret
= sch
->driver
->remove
? sch
->driver
->remove(sch
) : 0;
1143 static void css_shutdown(struct device
*dev
)
1145 struct subchannel
*sch
;
1147 sch
= to_subchannel(dev
);
1148 if (sch
->driver
&& sch
->driver
->shutdown
)
1149 sch
->driver
->shutdown(sch
);
1152 static int css_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
1154 struct subchannel
*sch
= to_subchannel(dev
);
1157 ret
= add_uevent_var(env
, "ST=%01X", sch
->st
);
1160 ret
= add_uevent_var(env
, "MODALIAS=css:t%01X", sch
->st
);
1164 static int css_pm_prepare(struct device
*dev
)
1166 struct subchannel
*sch
= to_subchannel(dev
);
1167 struct css_driver
*drv
;
1169 if (mutex_is_locked(&sch
->reg_mutex
))
1171 if (!sch
->dev
.driver
)
1173 drv
= to_cssdriver(sch
->dev
.driver
);
1174 /* Notify drivers that they may not register children. */
1175 return drv
->prepare
? drv
->prepare(sch
) : 0;
1178 static void css_pm_complete(struct device
*dev
)
1180 struct subchannel
*sch
= to_subchannel(dev
);
1181 struct css_driver
*drv
;
1183 if (!sch
->dev
.driver
)
1185 drv
= to_cssdriver(sch
->dev
.driver
);
1190 static int css_pm_freeze(struct device
*dev
)
1192 struct subchannel
*sch
= to_subchannel(dev
);
1193 struct css_driver
*drv
;
1195 if (!sch
->dev
.driver
)
1197 drv
= to_cssdriver(sch
->dev
.driver
);
1198 return drv
->freeze
? drv
->freeze(sch
) : 0;
1201 static int css_pm_thaw(struct device
*dev
)
1203 struct subchannel
*sch
= to_subchannel(dev
);
1204 struct css_driver
*drv
;
1206 if (!sch
->dev
.driver
)
1208 drv
= to_cssdriver(sch
->dev
.driver
);
1209 return drv
->thaw
? drv
->thaw(sch
) : 0;
1212 static int css_pm_restore(struct device
*dev
)
1214 struct subchannel
*sch
= to_subchannel(dev
);
1215 struct css_driver
*drv
;
1217 css_update_ssd_info(sch
);
1218 if (!sch
->dev
.driver
)
1220 drv
= to_cssdriver(sch
->dev
.driver
);
1221 return drv
->restore
? drv
->restore(sch
) : 0;
1224 static const struct dev_pm_ops css_pm_ops
= {
1225 .prepare
= css_pm_prepare
,
1226 .complete
= css_pm_complete
,
1227 .freeze
= css_pm_freeze
,
1228 .thaw
= css_pm_thaw
,
1229 .restore
= css_pm_restore
,
1232 static struct bus_type css_bus_type
= {
1234 .match
= css_bus_match
,
1236 .remove
= css_remove
,
1237 .shutdown
= css_shutdown
,
1238 .uevent
= css_uevent
,
1243 * css_driver_register - register a css driver
1244 * @cdrv: css driver to register
1246 * This is mainly a wrapper around driver_register that sets name
1247 * and bus_type in the embedded struct device_driver correctly.
1249 int css_driver_register(struct css_driver
*cdrv
)
1251 cdrv
->drv
.bus
= &css_bus_type
;
1252 return driver_register(&cdrv
->drv
);
1254 EXPORT_SYMBOL_GPL(css_driver_register
);
1257 * css_driver_unregister - unregister a css driver
1258 * @cdrv: css driver to unregister
1260 * This is a wrapper around driver_unregister.
1262 void css_driver_unregister(struct css_driver
*cdrv
)
1264 driver_unregister(&cdrv
->drv
);
1266 EXPORT_SYMBOL_GPL(css_driver_unregister
);
1268 MODULE_LICENSE("GPL");