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;
73 idset_sch_del(cb->set, sch->schid);
75 rc = cb->fn_known_sch(sch, cb->data);
79 static int call_fn_unknown_sch(struct subchannel_id schid, void *data)
81 struct cb_data *cb = data;
84 if (idset_sch_contains(cb->set, schid))
85 rc = cb->fn_unknown_sch(schid, cb->data);
89 static int call_fn_all_sch(struct subchannel_id schid, void *data)
91 struct cb_data *cb = data;
92 struct subchannel *sch;
95 sch = get_subchannel_by_schid(schid);
98 rc = cb->fn_known_sch(sch, cb->data);
99 put_device(&sch->dev);
101 if (cb->fn_unknown_sch)
102 rc = cb->fn_unknown_sch(schid, cb->data);
108 int for_each_subchannel_staged(int (*fn_known)(struct subchannel *, void *),
109 int (*fn_unknown)(struct subchannel_id,
116 cb.fn_known_sch = fn_known;
117 cb.fn_unknown_sch = fn_unknown;
119 if (fn_known && !fn_unknown) {
120 /* Skip idset allocation in case of known-only loop. */
122 return bus_for_each_dev(&css_bus_type, NULL, &cb,
126 cb.set = idset_sch_new();
128 /* fall back to brute force scanning in case of oom */
129 return for_each_subchannel(call_fn_all_sch, &cb);
133 /* Process registered subchannels. */
134 rc = bus_for_each_dev(&css_bus_type, NULL, &cb, call_fn_known_sch);
137 /* Process unregistered subchannels. */
139 rc = for_each_subchannel(call_fn_unknown_sch, &cb);
146 static void css_sch_todo(struct work_struct *work);
148 static int css_sch_create_locks(struct subchannel *sch)
150 sch->lock = kmalloc(sizeof(*sch->lock), GFP_KERNEL);
154 spin_lock_init(sch->lock);
155 mutex_init(&sch->reg_mutex);
160 static void css_subchannel_release(struct device *dev)
162 struct subchannel *sch = to_subchannel(dev);
164 sch->config.intparm = 0;
165 cio_commit_config(sch);
170 struct subchannel *css_alloc_subchannel(struct subchannel_id schid)
172 struct subchannel *sch;
175 sch = kzalloc(sizeof(*sch), GFP_KERNEL | GFP_DMA);
177 return ERR_PTR(-ENOMEM);
179 ret = cio_validate_subchannel(sch, schid);
183 ret = css_sch_create_locks(sch);
187 INIT_WORK(&sch->todo_work, css_sch_todo);
188 sch->dev.release = &css_subchannel_release;
189 device_initialize(&sch->dev);
197 static int css_sch_device_register(struct subchannel *sch)
201 mutex_lock(&sch->reg_mutex);
202 dev_set_name(&sch->dev, "0.%x.%04x", sch->schid.ssid,
204 ret = device_add(&sch->dev);
205 mutex_unlock(&sch->reg_mutex);
210 * css_sch_device_unregister - unregister a subchannel
211 * @sch: subchannel to be unregistered
213 void css_sch_device_unregister(struct subchannel *sch)
215 mutex_lock(&sch->reg_mutex);
216 if (device_is_registered(&sch->dev))
217 device_unregister(&sch->dev);
218 mutex_unlock(&sch->reg_mutex);
220 EXPORT_SYMBOL_GPL(css_sch_device_unregister);
222 static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw)
227 memset(ssd, 0, sizeof(struct chsc_ssd_info));
228 ssd->path_mask = pmcw->pim;
229 for (i = 0; i < 8; i++) {
231 if (pmcw->pim & mask) {
232 chp_id_init(&ssd->chpid[i]);
233 ssd->chpid[i].id = pmcw->chpid[i];
238 static void ssd_register_chpids(struct chsc_ssd_info *ssd)
243 for (i = 0; i < 8; i++) {
245 if (ssd->path_mask & mask)
246 if (!chp_is_registered(ssd->chpid[i]))
247 chp_new(ssd->chpid[i]);
251 void css_update_ssd_info(struct subchannel *sch)
255 ret = chsc_get_ssd_info(sch->schid, &sch->ssd_info);
257 ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
259 ssd_register_chpids(&sch->ssd_info);
262 static ssize_t type_show(struct device *dev, struct device_attribute *attr,
265 struct subchannel *sch = to_subchannel(dev);
267 return sprintf(buf, "%01x\n", sch->st);
270 static DEVICE_ATTR(type, 0444, type_show, NULL);
272 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
275 struct subchannel *sch = to_subchannel(dev);
277 return sprintf(buf, "css:t%01X\n", sch->st);
280 static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
282 static struct attribute *subch_attrs[] = {
284 &dev_attr_modalias.attr,
288 static struct attribute_group subch_attr_group = {
289 .attrs = subch_attrs,
292 static const struct attribute_group *default_subch_attr_groups[] = {
297 int css_register_subchannel(struct subchannel *sch)
301 /* Initialize the subchannel structure */
302 sch->dev.parent = &channel_subsystems[0]->device;
303 sch->dev.bus = &css_bus_type;
304 sch->dev.groups = default_subch_attr_groups;
306 * We don't want to generate uevents for I/O subchannels that don't
307 * have a working ccw device behind them since they will be
308 * unregistered before they can be used anyway, so we delay the add
309 * uevent until after device recognition was successful.
310 * Note that we suppress the uevent for all subchannel types;
311 * the subchannel driver can decide itself when it wants to inform
312 * userspace of its existence.
314 dev_set_uevent_suppress(&sch->dev, 1);
315 css_update_ssd_info(sch);
316 /* make it known to the system */
317 ret = css_sch_device_register(sch);
319 CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n",
320 sch->schid.ssid, sch->schid.sch_no, ret);
325 * No driver matched. Generate the uevent now so that
326 * a fitting driver module may be loaded based on the
329 dev_set_uevent_suppress(&sch->dev, 0);
330 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
335 static int css_probe_device(struct subchannel_id schid)
337 struct subchannel *sch;
340 sch = css_alloc_subchannel(schid);
344 ret = css_register_subchannel(sch);
346 put_device(&sch->dev);
352 check_subchannel(struct device * dev, void * data)
354 struct subchannel *sch;
355 struct subchannel_id *schid = data;
357 sch = to_subchannel(dev);
358 return schid_equal(&sch->schid, schid);
362 get_subchannel_by_schid(struct subchannel_id schid)
366 dev = bus_find_device(&css_bus_type, NULL,
367 &schid, check_subchannel);
369 return dev ? to_subchannel(dev) : NULL;
373 * css_sch_is_valid() - check if a subchannel is valid
374 * @schib: subchannel information block for the subchannel
376 int css_sch_is_valid(struct schib *schib)
378 if ((schib->pmcw.st == SUBCHANNEL_TYPE_IO) && !schib->pmcw.dnv)
380 if ((schib->pmcw.st == SUBCHANNEL_TYPE_MSG) && !schib->pmcw.w)
384 EXPORT_SYMBOL_GPL(css_sch_is_valid);
386 static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow)
391 /* Will be done on the slow path. */
394 if (stsch_err(schid, &schib)) {
395 /* Subchannel is not provided. */
398 if (!css_sch_is_valid(&schib)) {
399 /* Unusable - ignore. */
402 CIO_MSG_EVENT(4, "event: sch 0.%x.%04x, new\n", schid.ssid,
405 return css_probe_device(schid);
408 static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
413 if (sch->driver->sch_event)
414 ret = sch->driver->sch_event(sch, slow);
417 "Got subchannel machine check but "
418 "no sch_event handler provided.\n");
420 if (ret != 0 && ret != -EAGAIN) {
421 CIO_MSG_EVENT(2, "eval: sch 0.%x.%04x, rc=%d\n",
422 sch->schid.ssid, sch->schid.sch_no, ret);
427 static void css_evaluate_subchannel(struct subchannel_id schid, int slow)
429 struct subchannel *sch;
432 sch = get_subchannel_by_schid(schid);
434 ret = css_evaluate_known_subchannel(sch, slow);
435 put_device(&sch->dev);
437 ret = css_evaluate_new_subchannel(schid, slow);
439 css_schedule_eval(schid);
443 * css_sched_sch_todo - schedule a subchannel operation
447 * Schedule the operation identified by @todo to be performed on the slow path
448 * workqueue. Do nothing if another operation with higher priority is already
449 * scheduled. Needs to be called with subchannel lock held.
451 void css_sched_sch_todo(struct subchannel *sch, enum sch_todo todo)
453 CIO_MSG_EVENT(4, "sch_todo: sched sch=0.%x.%04x todo=%d\n",
454 sch->schid.ssid, sch->schid.sch_no, todo);
455 if (sch->todo >= todo)
457 /* Get workqueue ref. */
458 if (!get_device(&sch->dev))
461 if (!queue_work(cio_work_q, &sch->todo_work)) {
462 /* Already queued, release workqueue ref. */
463 put_device(&sch->dev);
466 EXPORT_SYMBOL_GPL(css_sched_sch_todo);
468 static void css_sch_todo(struct work_struct *work)
470 struct subchannel *sch;
474 sch = container_of(work, struct subchannel, todo_work);
476 spin_lock_irq(sch->lock);
478 CIO_MSG_EVENT(4, "sch_todo: sch=0.%x.%04x, todo=%d\n", sch->schid.ssid,
479 sch->schid.sch_no, todo);
480 sch->todo = SCH_TODO_NOTHING;
481 spin_unlock_irq(sch->lock);
484 case SCH_TODO_NOTHING:
487 ret = css_evaluate_known_subchannel(sch, 1);
488 if (ret == -EAGAIN) {
489 spin_lock_irq(sch->lock);
490 css_sched_sch_todo(sch, todo);
491 spin_unlock_irq(sch->lock);
495 css_sch_device_unregister(sch);
498 /* Release workqueue ref. */
499 put_device(&sch->dev);
502 static struct idset *slow_subchannel_set;
503 static spinlock_t slow_subchannel_lock;
504 static wait_queue_head_t css_eval_wq;
505 static atomic_t css_eval_scheduled;
507 static int __init slow_subchannel_init(void)
509 spin_lock_init(&slow_subchannel_lock);
510 atomic_set(&css_eval_scheduled, 0);
511 init_waitqueue_head(&css_eval_wq);
512 slow_subchannel_set = idset_sch_new();
513 if (!slow_subchannel_set) {
514 CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n");
520 static int slow_eval_known_fn(struct subchannel *sch, void *data)
525 spin_lock_irq(&slow_subchannel_lock);
526 eval = idset_sch_contains(slow_subchannel_set, sch->schid);
527 idset_sch_del(slow_subchannel_set, sch->schid);
528 spin_unlock_irq(&slow_subchannel_lock);
530 rc = css_evaluate_known_subchannel(sch, 1);
532 css_schedule_eval(sch->schid);
537 static int slow_eval_unknown_fn(struct subchannel_id schid, void *data)
542 spin_lock_irq(&slow_subchannel_lock);
543 eval = idset_sch_contains(slow_subchannel_set, schid);
544 idset_sch_del(slow_subchannel_set, schid);
545 spin_unlock_irq(&slow_subchannel_lock);
547 rc = css_evaluate_new_subchannel(schid, 1);
550 css_schedule_eval(schid);
556 /* These should abort looping */
557 spin_lock_irq(&slow_subchannel_lock);
558 idset_sch_del_subseq(slow_subchannel_set, schid);
559 spin_unlock_irq(&slow_subchannel_lock);
564 /* Allow scheduling here since the containing loop might
571 static void css_slow_path_func(struct work_struct *unused)
575 CIO_TRACE_EVENT(4, "slowpath");
576 for_each_subchannel_staged(slow_eval_known_fn, slow_eval_unknown_fn,
578 spin_lock_irqsave(&slow_subchannel_lock, flags);
579 if (idset_is_empty(slow_subchannel_set)) {
580 atomic_set(&css_eval_scheduled, 0);
581 wake_up(&css_eval_wq);
583 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
586 static DECLARE_DELAYED_WORK(slow_path_work, css_slow_path_func);
587 struct workqueue_struct *cio_work_q;
589 void css_schedule_eval(struct subchannel_id schid)
593 spin_lock_irqsave(&slow_subchannel_lock, flags);
594 idset_sch_add(slow_subchannel_set, schid);
595 atomic_set(&css_eval_scheduled, 1);
596 queue_delayed_work(cio_work_q, &slow_path_work, 0);
597 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
600 void css_schedule_eval_all(void)
604 spin_lock_irqsave(&slow_subchannel_lock, flags);
605 idset_fill(slow_subchannel_set);
606 atomic_set(&css_eval_scheduled, 1);
607 queue_delayed_work(cio_work_q, &slow_path_work, 0);
608 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
611 static int __unset_registered(struct device *dev, void *data)
613 struct idset *set = data;
614 struct subchannel *sch = to_subchannel(dev);
616 idset_sch_del(set, sch->schid);
620 void css_schedule_eval_all_unreg(unsigned long delay)
623 struct idset *unreg_set;
625 /* Find unregistered subchannels. */
626 unreg_set = idset_sch_new();
629 css_schedule_eval_all();
632 idset_fill(unreg_set);
633 bus_for_each_dev(&css_bus_type, NULL, unreg_set, __unset_registered);
634 /* Apply to slow_subchannel_set. */
635 spin_lock_irqsave(&slow_subchannel_lock, flags);
636 idset_add_set(slow_subchannel_set, unreg_set);
637 atomic_set(&css_eval_scheduled, 1);
638 queue_delayed_work(cio_work_q, &slow_path_work, delay);
639 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
640 idset_free(unreg_set);
643 void css_wait_for_slow_path(void)
645 flush_workqueue(cio_work_q);
648 /* Schedule reprobing of all unregistered subchannels. */
649 void css_schedule_reprobe(void)
651 /* Schedule with a delay to allow merging of subsequent calls. */
652 css_schedule_eval_all_unreg(1 * HZ);
654 EXPORT_SYMBOL_GPL(css_schedule_reprobe);
657 * Called from the machine check handler for subchannel report words.
659 static void css_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
661 struct subchannel_id mchk_schid;
662 struct subchannel *sch;
665 css_schedule_eval_all();
668 CIO_CRW_EVENT(2, "CRW0 reports slct=%d, oflw=%d, "
669 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
670 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
671 crw0->erc, crw0->rsid);
673 CIO_CRW_EVENT(2, "CRW1 reports slct=%d, oflw=%d, "
674 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
675 crw1->slct, crw1->oflw, crw1->chn, crw1->rsc,
676 crw1->anc, crw1->erc, crw1->rsid);
677 init_subchannel_id(&mchk_schid);
678 mchk_schid.sch_no = crw0->rsid;
680 mchk_schid.ssid = (crw1->rsid >> 4) & 3;
682 if (crw0->erc == CRW_ERC_PMOD) {
683 sch = get_subchannel_by_schid(mchk_schid);
685 css_update_ssd_info(sch);
686 put_device(&sch->dev);
690 * Since we are always presented with IPI in the CRW, we have to
691 * use stsch() to find out if the subchannel in question has come
694 css_evaluate_subchannel(mchk_schid, 0);
698 css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
702 if (css_general_characteristics.mcss) {
703 css->global_pgid.pgid_high.ext_cssid.version = 0x80;
704 css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid;
707 css->global_pgid.pgid_high.cpu_addr = stap();
709 css->global_pgid.pgid_high.cpu_addr = 0;
713 css->global_pgid.cpu_id = cpu_id.ident;
714 css->global_pgid.cpu_model = cpu_id.machine;
715 css->global_pgid.tod_high = tod_high;
720 channel_subsystem_release(struct device *dev)
722 struct channel_subsystem *css;
725 mutex_destroy(&css->mutex);
726 if (css->pseudo_subchannel) {
727 /* Implies that it has been generated but never registered. */
728 css_subchannel_release(&css->pseudo_subchannel->dev);
729 css->pseudo_subchannel = NULL;
735 css_cm_enable_show(struct device *dev, struct device_attribute *attr,
738 struct channel_subsystem *css = to_css(dev);
743 mutex_lock(&css->mutex);
744 ret = sprintf(buf, "%x\n", css->cm_enabled);
745 mutex_unlock(&css->mutex);
750 css_cm_enable_store(struct device *dev, struct device_attribute *attr,
751 const char *buf, size_t count)
753 struct channel_subsystem *css = to_css(dev);
757 ret = kstrtoul(buf, 16, &val);
760 mutex_lock(&css->mutex);
763 ret = css->cm_enabled ? chsc_secm(css, 0) : 0;
766 ret = css->cm_enabled ? 0 : chsc_secm(css, 1);
771 mutex_unlock(&css->mutex);
772 return ret < 0 ? ret : count;
775 static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store);
777 static int __init setup_css(int nr)
781 struct channel_subsystem *css;
783 css = channel_subsystems[nr];
784 memset(css, 0, sizeof(struct channel_subsystem));
785 css->pseudo_subchannel =
786 kzalloc(sizeof(*css->pseudo_subchannel), GFP_KERNEL);
787 if (!css->pseudo_subchannel)
789 css->pseudo_subchannel->dev.parent = &css->device;
790 css->pseudo_subchannel->dev.release = css_subchannel_release;
791 dev_set_name(&css->pseudo_subchannel->dev, "defunct");
792 mutex_init(&css->pseudo_subchannel->reg_mutex);
793 ret = css_sch_create_locks(css->pseudo_subchannel);
795 kfree(css->pseudo_subchannel);
798 mutex_init(&css->mutex);
801 dev_set_name(&css->device, "css%x", nr);
802 css->device.release = channel_subsystem_release;
803 tod_high = (u32) (get_tod_clock() >> 32);
804 css_generate_pgid(css, tod_high);
808 static int css_reboot_event(struct notifier_block *this,
815 for (i = 0; i <= __MAX_CSSID; i++) {
816 struct channel_subsystem *css;
818 css = channel_subsystems[i];
819 mutex_lock(&css->mutex);
821 if (chsc_secm(css, 0))
823 mutex_unlock(&css->mutex);
829 static struct notifier_block css_reboot_notifier = {
830 .notifier_call = css_reboot_event,
834 * Since the css devices are neither on a bus nor have a class
835 * nor have a special device type, we cannot stop/restart channel
836 * path measurements via the normal suspend/resume callbacks, but have
839 static int css_power_event(struct notifier_block *this, unsigned long event,
845 case PM_HIBERNATION_PREPARE:
846 case PM_SUSPEND_PREPARE:
848 for (i = 0; i <= __MAX_CSSID; i++) {
849 struct channel_subsystem *css;
851 css = channel_subsystems[i];
852 mutex_lock(&css->mutex);
853 if (!css->cm_enabled) {
854 mutex_unlock(&css->mutex);
857 ret = __chsc_do_secm(css, 0);
858 ret = notifier_from_errno(ret);
859 mutex_unlock(&css->mutex);
862 case PM_POST_HIBERNATION:
863 case PM_POST_SUSPEND:
865 for (i = 0; i <= __MAX_CSSID; i++) {
866 struct channel_subsystem *css;
868 css = channel_subsystems[i];
869 mutex_lock(&css->mutex);
870 if (!css->cm_enabled) {
871 mutex_unlock(&css->mutex);
874 ret = __chsc_do_secm(css, 1);
875 ret = notifier_from_errno(ret);
876 mutex_unlock(&css->mutex);
878 /* search for subchannels, which appeared during hibernation */
879 css_schedule_reprobe();
887 static struct notifier_block css_power_notifier = {
888 .notifier_call = css_power_event,
892 * Now that the driver core is running, we can setup our channel subsystem.
893 * The struct subchannel's are created during probing.
895 static int __init css_bus_init(void)
903 chsc_determine_css_characteristics();
904 /* Try to enable MSS. */
905 ret = chsc_enable_facility(CHSC_SDA_OC_MSS);
909 max_ssid = __MAX_SSID;
911 ret = slow_subchannel_init();
915 ret = crw_register_handler(CRW_RSC_SCH, css_process_crw);
919 if ((ret = bus_register(&css_bus_type)))
922 /* Setup css structure. */
923 for (i = 0; i <= __MAX_CSSID; i++) {
924 struct channel_subsystem *css;
926 css = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL);
931 channel_subsystems[i] = css;
934 kfree(channel_subsystems[i]);
937 ret = device_register(&css->device);
939 put_device(&css->device);
942 if (css_chsc_characteristics.secm) {
943 ret = device_create_file(&css->device,
944 &dev_attr_cm_enable);
948 ret = device_register(&css->pseudo_subchannel->dev);
950 put_device(&css->pseudo_subchannel->dev);
954 ret = register_reboot_notifier(&css_reboot_notifier);
957 ret = register_pm_notifier(&css_power_notifier);
959 unregister_reboot_notifier(&css_reboot_notifier);
964 /* Enable default isc for I/O subchannels. */
965 isc_register(IO_SCH_ISC);
969 if (css_chsc_characteristics.secm)
970 device_remove_file(&channel_subsystems[i]->device,
971 &dev_attr_cm_enable);
973 device_unregister(&channel_subsystems[i]->device);
976 struct channel_subsystem *css;
979 css = channel_subsystems[i];
980 device_unregister(&css->pseudo_subchannel->dev);
981 css->pseudo_subchannel = NULL;
982 if (css_chsc_characteristics.secm)
983 device_remove_file(&css->device,
984 &dev_attr_cm_enable);
985 device_unregister(&css->device);
987 bus_unregister(&css_bus_type);
989 crw_unregister_handler(CRW_RSC_SCH);
990 idset_free(slow_subchannel_set);
992 pr_alert("The CSS device driver initialization failed with "
997 static void __init css_bus_cleanup(void)
999 struct channel_subsystem *css;
1002 for (i = 0; i <= __MAX_CSSID; i++) {
1003 css = channel_subsystems[i];
1004 device_unregister(&css->pseudo_subchannel->dev);
1005 css->pseudo_subchannel = NULL;
1006 if (css_chsc_characteristics.secm)
1007 device_remove_file(&css->device, &dev_attr_cm_enable);
1008 device_unregister(&css->device);
1010 bus_unregister(&css_bus_type);
1011 crw_unregister_handler(CRW_RSC_SCH);
1012 idset_free(slow_subchannel_set);
1013 chsc_init_cleanup();
1014 isc_unregister(IO_SCH_ISC);
1017 static int __init channel_subsystem_init(void)
1021 ret = css_bus_init();
1024 cio_work_q = create_singlethread_workqueue("cio");
1029 ret = io_subchannel_init();
1035 destroy_workqueue(cio_work_q);
1040 subsys_initcall(channel_subsystem_init);
1042 static int css_settle(struct device_driver *drv, void *unused)
1044 struct css_driver *cssdrv = to_cssdriver(drv);
1047 return cssdrv->settle();
1051 int css_complete_work(void)
1055 /* Wait for the evaluation of subchannels to finish. */
1056 ret = wait_event_interruptible(css_eval_wq,
1057 atomic_read(&css_eval_scheduled) == 0);
1060 flush_workqueue(cio_work_q);
1061 /* Wait for the subchannel type specific initialization to finish */
1062 return bus_for_each_drv(&css_bus_type, NULL, NULL, css_settle);
1067 * Wait for the initialization of devices to finish, to make sure we are
1068 * done with our setup if the search for the root device starts.
1070 static int __init channel_subsystem_init_sync(void)
1072 /* Register subchannels which are already in use. */
1073 cio_register_early_subchannels();
1074 /* Start initial subchannel evaluation. */
1075 css_schedule_eval_all();
1076 css_complete_work();
1079 subsys_initcall_sync(channel_subsystem_init_sync);
1081 void channel_subsystem_reinit(void)
1083 struct channel_path *chp;
1084 struct chp_id chpid;
1086 chsc_enable_facility(CHSC_SDA_OC_MSS);
1087 chp_id_for_each(&chpid) {
1088 chp = chpid_to_chp(chpid);
1090 chp_update_desc(chp);
1094 #ifdef CONFIG_PROC_FS
1095 static ssize_t cio_settle_write(struct file *file, const char __user *buf,
1096 size_t count, loff_t *ppos)
1100 /* Handle pending CRW's. */
1101 crw_wait_for_channel_report();
1102 ret = css_complete_work();
1104 return ret ? ret : count;
1107 static const struct file_operations cio_settle_proc_fops = {
1108 .open = nonseekable_open,
1109 .write = cio_settle_write,
1110 .llseek = no_llseek,
1113 static int __init cio_settle_init(void)
1115 struct proc_dir_entry *entry;
1117 entry = proc_create("cio_settle", S_IWUSR, NULL,
1118 &cio_settle_proc_fops);
1123 device_initcall(cio_settle_init);
1124 #endif /*CONFIG_PROC_FS*/
1126 int sch_is_pseudo_sch(struct subchannel *sch)
1128 return sch == to_css(sch->dev.parent)->pseudo_subchannel;
1131 static int css_bus_match(struct device *dev, struct device_driver *drv)
1133 struct subchannel *sch = to_subchannel(dev);
1134 struct css_driver *driver = to_cssdriver(drv);
1135 struct css_device_id *id;
1137 for (id = driver->subchannel_type; id->match_flags; id++) {
1138 if (sch->st == id->type)
1145 static int css_probe(struct device *dev)
1147 struct subchannel *sch;
1150 sch = to_subchannel(dev);
1151 sch->driver = to_cssdriver(dev->driver);
1152 ret = sch->driver->probe ? sch->driver->probe(sch) : 0;
1158 static int css_remove(struct device *dev)
1160 struct subchannel *sch;
1163 sch = to_subchannel(dev);
1164 ret = sch->driver->remove ? sch->driver->remove(sch) : 0;
1169 static void css_shutdown(struct device *dev)
1171 struct subchannel *sch;
1173 sch = to_subchannel(dev);
1174 if (sch->driver && sch->driver->shutdown)
1175 sch->driver->shutdown(sch);
1178 static int css_uevent(struct device *dev, struct kobj_uevent_env *env)
1180 struct subchannel *sch = to_subchannel(dev);
1183 ret = add_uevent_var(env, "ST=%01X", sch->st);
1186 ret = add_uevent_var(env, "MODALIAS=css:t%01X", sch->st);
1190 static int css_pm_prepare(struct device *dev)
1192 struct subchannel *sch = to_subchannel(dev);
1193 struct css_driver *drv;
1195 if (mutex_is_locked(&sch->reg_mutex))
1197 if (!sch->dev.driver)
1199 drv = to_cssdriver(sch->dev.driver);
1200 /* Notify drivers that they may not register children. */
1201 return drv->prepare ? drv->prepare(sch) : 0;
1204 static void css_pm_complete(struct device *dev)
1206 struct subchannel *sch = to_subchannel(dev);
1207 struct css_driver *drv;
1209 if (!sch->dev.driver)
1211 drv = to_cssdriver(sch->dev.driver);
1216 static int css_pm_freeze(struct device *dev)
1218 struct subchannel *sch = to_subchannel(dev);
1219 struct css_driver *drv;
1221 if (!sch->dev.driver)
1223 drv = to_cssdriver(sch->dev.driver);
1224 return drv->freeze ? drv->freeze(sch) : 0;
1227 static int css_pm_thaw(struct device *dev)
1229 struct subchannel *sch = to_subchannel(dev);
1230 struct css_driver *drv;
1232 if (!sch->dev.driver)
1234 drv = to_cssdriver(sch->dev.driver);
1235 return drv->thaw ? drv->thaw(sch) : 0;
1238 static int css_pm_restore(struct device *dev)
1240 struct subchannel *sch = to_subchannel(dev);
1241 struct css_driver *drv;
1243 css_update_ssd_info(sch);
1244 if (!sch->dev.driver)
1246 drv = to_cssdriver(sch->dev.driver);
1247 return drv->restore ? drv->restore(sch) : 0;
1250 static const struct dev_pm_ops css_pm_ops = {
1251 .prepare = css_pm_prepare,
1252 .complete = css_pm_complete,
1253 .freeze = css_pm_freeze,
1254 .thaw = css_pm_thaw,
1255 .restore = css_pm_restore,
1258 static struct bus_type css_bus_type = {
1260 .match = css_bus_match,
1262 .remove = css_remove,
1263 .shutdown = css_shutdown,
1264 .uevent = css_uevent,
1269 * css_driver_register - register a css driver
1270 * @cdrv: css driver to register
1272 * This is mainly a wrapper around driver_register that sets name
1273 * and bus_type in the embedded struct device_driver correctly.
1275 int css_driver_register(struct css_driver *cdrv)
1277 cdrv->drv.bus = &css_bus_type;
1278 return driver_register(&cdrv->drv);
1280 EXPORT_SYMBOL_GPL(css_driver_register);
1283 * css_driver_unregister - unregister a css driver
1284 * @cdrv: css driver to unregister
1286 * This is a wrapper around driver_unregister.
1288 void css_driver_unregister(struct css_driver *cdrv)
1290 driver_unregister(&cdrv->drv);
1292 EXPORT_SYMBOL_GPL(css_driver_unregister);
1294 MODULE_LICENSE("GPL");