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 int css_sch_create_locks(struct subchannel *sch)
142 sch->lock = kmalloc(sizeof(*sch->lock), GFP_KERNEL);
146 spin_lock_init(sch->lock);
147 mutex_init(&sch->reg_mutex);
152 static void css_subchannel_release(struct device *dev)
154 struct subchannel *sch = to_subchannel(dev);
156 sch->config.intparm = 0;
157 cio_commit_config(sch);
162 struct subchannel *css_alloc_subchannel(struct subchannel_id schid)
164 struct subchannel *sch;
167 sch = kzalloc(sizeof(*sch), GFP_KERNEL | GFP_DMA);
169 return ERR_PTR(-ENOMEM);
171 ret = cio_validate_subchannel(sch, schid);
175 ret = css_sch_create_locks(sch);
179 INIT_WORK(&sch->todo_work, css_sch_todo);
180 sch->dev.release = &css_subchannel_release;
181 device_initialize(&sch->dev);
189 static int css_sch_device_register(struct subchannel *sch)
193 mutex_lock(&sch->reg_mutex);
194 dev_set_name(&sch->dev, "0.%x.%04x", sch->schid.ssid,
196 ret = device_add(&sch->dev);
197 mutex_unlock(&sch->reg_mutex);
202 * css_sch_device_unregister - unregister a subchannel
203 * @sch: subchannel to be unregistered
205 void css_sch_device_unregister(struct subchannel *sch)
207 mutex_lock(&sch->reg_mutex);
208 if (device_is_registered(&sch->dev))
209 device_unregister(&sch->dev);
210 mutex_unlock(&sch->reg_mutex);
212 EXPORT_SYMBOL_GPL(css_sch_device_unregister);
214 static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw)
219 memset(ssd, 0, sizeof(struct chsc_ssd_info));
220 ssd->path_mask = pmcw->pim;
221 for (i = 0; i < 8; i++) {
223 if (pmcw->pim & mask) {
224 chp_id_init(&ssd->chpid[i]);
225 ssd->chpid[i].id = pmcw->chpid[i];
230 static void ssd_register_chpids(struct chsc_ssd_info *ssd)
235 for (i = 0; i < 8; i++) {
237 if (ssd->path_mask & mask)
238 if (!chp_is_registered(ssd->chpid[i]))
239 chp_new(ssd->chpid[i]);
243 void css_update_ssd_info(struct subchannel *sch)
247 ret = chsc_get_ssd_info(sch->schid, &sch->ssd_info);
249 ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
251 ssd_register_chpids(&sch->ssd_info);
254 static ssize_t type_show(struct device *dev, struct device_attribute *attr,
257 struct subchannel *sch = to_subchannel(dev);
259 return sprintf(buf, "%01x\n", sch->st);
262 static DEVICE_ATTR(type, 0444, type_show, NULL);
264 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
267 struct subchannel *sch = to_subchannel(dev);
269 return sprintf(buf, "css:t%01X\n", sch->st);
272 static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
274 static struct attribute *subch_attrs[] = {
276 &dev_attr_modalias.attr,
280 static struct attribute_group subch_attr_group = {
281 .attrs = subch_attrs,
284 static const struct attribute_group *default_subch_attr_groups[] = {
289 int css_register_subchannel(struct subchannel *sch)
293 /* Initialize the subchannel structure */
294 sch->dev.parent = &channel_subsystems[0]->device;
295 sch->dev.bus = &css_bus_type;
296 sch->dev.groups = default_subch_attr_groups;
298 * We don't want to generate uevents for I/O subchannels that don't
299 * have a working ccw device behind them since they will be
300 * unregistered before they can be used anyway, so we delay the add
301 * uevent until after device recognition was successful.
302 * Note that we suppress the uevent for all subchannel types;
303 * the subchannel driver can decide itself when it wants to inform
304 * userspace of its existence.
306 dev_set_uevent_suppress(&sch->dev, 1);
307 css_update_ssd_info(sch);
308 /* make it known to the system */
309 ret = css_sch_device_register(sch);
311 CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n",
312 sch->schid.ssid, sch->schid.sch_no, ret);
317 * No driver matched. Generate the uevent now so that
318 * a fitting driver module may be loaded based on the
321 dev_set_uevent_suppress(&sch->dev, 0);
322 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
327 static int css_probe_device(struct subchannel_id schid)
329 struct subchannel *sch;
332 sch = css_alloc_subchannel(schid);
336 ret = css_register_subchannel(sch);
338 put_device(&sch->dev);
344 check_subchannel(struct device * dev, void * data)
346 struct subchannel *sch;
347 struct subchannel_id *schid = data;
349 sch = to_subchannel(dev);
350 return schid_equal(&sch->schid, schid);
354 get_subchannel_by_schid(struct subchannel_id schid)
358 dev = bus_find_device(&css_bus_type, NULL,
359 &schid, check_subchannel);
361 return dev ? to_subchannel(dev) : NULL;
365 * css_sch_is_valid() - check if a subchannel is valid
366 * @schib: subchannel information block for the subchannel
368 int css_sch_is_valid(struct schib *schib)
370 if ((schib->pmcw.st == SUBCHANNEL_TYPE_IO) && !schib->pmcw.dnv)
372 if ((schib->pmcw.st == SUBCHANNEL_TYPE_MSG) && !schib->pmcw.w)
376 EXPORT_SYMBOL_GPL(css_sch_is_valid);
378 static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow)
383 /* Will be done on the slow path. */
386 if (stsch_err(schid, &schib)) {
387 /* Subchannel is not provided. */
390 if (!css_sch_is_valid(&schib)) {
391 /* Unusable - ignore. */
394 CIO_MSG_EVENT(4, "event: sch 0.%x.%04x, new\n", schid.ssid,
397 return css_probe_device(schid);
400 static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
405 if (sch->driver->sch_event)
406 ret = sch->driver->sch_event(sch, slow);
409 "Got subchannel machine check but "
410 "no sch_event handler provided.\n");
412 if (ret != 0 && ret != -EAGAIN) {
413 CIO_MSG_EVENT(2, "eval: sch 0.%x.%04x, rc=%d\n",
414 sch->schid.ssid, sch->schid.sch_no, ret);
419 static void css_evaluate_subchannel(struct subchannel_id schid, int slow)
421 struct subchannel *sch;
424 sch = get_subchannel_by_schid(schid);
426 ret = css_evaluate_known_subchannel(sch, slow);
427 put_device(&sch->dev);
429 ret = css_evaluate_new_subchannel(schid, slow);
431 css_schedule_eval(schid);
435 * css_sched_sch_todo - schedule a subchannel operation
439 * Schedule the operation identified by @todo to be performed on the slow path
440 * workqueue. Do nothing if another operation with higher priority is already
441 * scheduled. Needs to be called with subchannel lock held.
443 void css_sched_sch_todo(struct subchannel *sch, enum sch_todo todo)
445 CIO_MSG_EVENT(4, "sch_todo: sched sch=0.%x.%04x todo=%d\n",
446 sch->schid.ssid, sch->schid.sch_no, todo);
447 if (sch->todo >= todo)
449 /* Get workqueue ref. */
450 if (!get_device(&sch->dev))
453 if (!queue_work(cio_work_q, &sch->todo_work)) {
454 /* Already queued, release workqueue ref. */
455 put_device(&sch->dev);
458 EXPORT_SYMBOL_GPL(css_sched_sch_todo);
460 static void css_sch_todo(struct work_struct *work)
462 struct subchannel *sch;
466 sch = container_of(work, struct subchannel, todo_work);
468 spin_lock_irq(sch->lock);
470 CIO_MSG_EVENT(4, "sch_todo: sch=0.%x.%04x, todo=%d\n", sch->schid.ssid,
471 sch->schid.sch_no, todo);
472 sch->todo = SCH_TODO_NOTHING;
473 spin_unlock_irq(sch->lock);
476 case SCH_TODO_NOTHING:
479 ret = css_evaluate_known_subchannel(sch, 1);
480 if (ret == -EAGAIN) {
481 spin_lock_irq(sch->lock);
482 css_sched_sch_todo(sch, todo);
483 spin_unlock_irq(sch->lock);
487 css_sch_device_unregister(sch);
490 /* Release workqueue ref. */
491 put_device(&sch->dev);
494 static struct idset *slow_subchannel_set;
495 static spinlock_t slow_subchannel_lock;
496 static wait_queue_head_t css_eval_wq;
497 static atomic_t css_eval_scheduled;
499 static int __init slow_subchannel_init(void)
501 spin_lock_init(&slow_subchannel_lock);
502 atomic_set(&css_eval_scheduled, 0);
503 init_waitqueue_head(&css_eval_wq);
504 slow_subchannel_set = idset_sch_new();
505 if (!slow_subchannel_set) {
506 CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n");
512 static int slow_eval_known_fn(struct subchannel *sch, void *data)
517 spin_lock_irq(&slow_subchannel_lock);
518 eval = idset_sch_contains(slow_subchannel_set, sch->schid);
519 idset_sch_del(slow_subchannel_set, sch->schid);
520 spin_unlock_irq(&slow_subchannel_lock);
522 rc = css_evaluate_known_subchannel(sch, 1);
524 css_schedule_eval(sch->schid);
529 static int slow_eval_unknown_fn(struct subchannel_id schid, void *data)
534 spin_lock_irq(&slow_subchannel_lock);
535 eval = idset_sch_contains(slow_subchannel_set, schid);
536 idset_sch_del(slow_subchannel_set, schid);
537 spin_unlock_irq(&slow_subchannel_lock);
539 rc = css_evaluate_new_subchannel(schid, 1);
542 css_schedule_eval(schid);
548 /* These should abort looping */
549 spin_lock_irq(&slow_subchannel_lock);
550 idset_sch_del_subseq(slow_subchannel_set, schid);
551 spin_unlock_irq(&slow_subchannel_lock);
560 static void css_slow_path_func(struct work_struct *unused)
564 CIO_TRACE_EVENT(4, "slowpath");
565 for_each_subchannel_staged(slow_eval_known_fn, slow_eval_unknown_fn,
567 spin_lock_irqsave(&slow_subchannel_lock, flags);
568 if (idset_is_empty(slow_subchannel_set)) {
569 atomic_set(&css_eval_scheduled, 0);
570 wake_up(&css_eval_wq);
572 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
575 static DECLARE_WORK(slow_path_work, css_slow_path_func);
576 struct workqueue_struct *cio_work_q;
578 void css_schedule_eval(struct subchannel_id schid)
582 spin_lock_irqsave(&slow_subchannel_lock, flags);
583 idset_sch_add(slow_subchannel_set, schid);
584 atomic_set(&css_eval_scheduled, 1);
585 queue_work(cio_work_q, &slow_path_work);
586 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
589 void css_schedule_eval_all(void)
593 spin_lock_irqsave(&slow_subchannel_lock, flags);
594 idset_fill(slow_subchannel_set);
595 atomic_set(&css_eval_scheduled, 1);
596 queue_work(cio_work_q, &slow_path_work);
597 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
600 static int __unset_registered(struct device *dev, void *data)
602 struct idset *set = data;
603 struct subchannel *sch = to_subchannel(dev);
605 idset_sch_del(set, sch->schid);
609 static void css_schedule_eval_all_unreg(void)
612 struct idset *unreg_set;
614 /* Find unregistered subchannels. */
615 unreg_set = idset_sch_new();
618 css_schedule_eval_all();
621 idset_fill(unreg_set);
622 bus_for_each_dev(&css_bus_type, NULL, unreg_set, __unset_registered);
623 /* Apply to slow_subchannel_set. */
624 spin_lock_irqsave(&slow_subchannel_lock, flags);
625 idset_add_set(slow_subchannel_set, unreg_set);
626 atomic_set(&css_eval_scheduled, 1);
627 queue_work(cio_work_q, &slow_path_work);
628 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
629 idset_free(unreg_set);
632 void css_wait_for_slow_path(void)
634 flush_workqueue(cio_work_q);
637 /* Schedule reprobing of all unregistered subchannels. */
638 void css_schedule_reprobe(void)
640 css_schedule_eval_all_unreg();
642 EXPORT_SYMBOL_GPL(css_schedule_reprobe);
645 * Called from the machine check handler for subchannel report words.
647 static void css_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
649 struct subchannel_id mchk_schid;
650 struct subchannel *sch;
653 css_schedule_eval_all();
656 CIO_CRW_EVENT(2, "CRW0 reports slct=%d, oflw=%d, "
657 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
658 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
659 crw0->erc, crw0->rsid);
661 CIO_CRW_EVENT(2, "CRW1 reports slct=%d, oflw=%d, "
662 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
663 crw1->slct, crw1->oflw, crw1->chn, crw1->rsc,
664 crw1->anc, crw1->erc, crw1->rsid);
665 init_subchannel_id(&mchk_schid);
666 mchk_schid.sch_no = crw0->rsid;
668 mchk_schid.ssid = (crw1->rsid >> 4) & 3;
670 if (crw0->erc == CRW_ERC_PMOD) {
671 sch = get_subchannel_by_schid(mchk_schid);
673 css_update_ssd_info(sch);
674 put_device(&sch->dev);
678 * Since we are always presented with IPI in the CRW, we have to
679 * use stsch() to find out if the subchannel in question has come
682 css_evaluate_subchannel(mchk_schid, 0);
686 css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
690 if (css_general_characteristics.mcss) {
691 css->global_pgid.pgid_high.ext_cssid.version = 0x80;
692 css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid;
695 css->global_pgid.pgid_high.cpu_addr = stap();
697 css->global_pgid.pgid_high.cpu_addr = 0;
701 css->global_pgid.cpu_id = cpu_id.ident;
702 css->global_pgid.cpu_model = cpu_id.machine;
703 css->global_pgid.tod_high = tod_high;
708 channel_subsystem_release(struct device *dev)
710 struct channel_subsystem *css;
713 mutex_destroy(&css->mutex);
714 if (css->pseudo_subchannel) {
715 /* Implies that it has been generated but never registered. */
716 css_subchannel_release(&css->pseudo_subchannel->dev);
717 css->pseudo_subchannel = NULL;
723 css_cm_enable_show(struct device *dev, struct device_attribute *attr,
726 struct channel_subsystem *css = to_css(dev);
731 mutex_lock(&css->mutex);
732 ret = sprintf(buf, "%x\n", css->cm_enabled);
733 mutex_unlock(&css->mutex);
738 css_cm_enable_store(struct device *dev, struct device_attribute *attr,
739 const char *buf, size_t count)
741 struct channel_subsystem *css = to_css(dev);
745 ret = kstrtoul(buf, 16, &val);
748 mutex_lock(&css->mutex);
751 ret = css->cm_enabled ? chsc_secm(css, 0) : 0;
754 ret = css->cm_enabled ? 0 : chsc_secm(css, 1);
759 mutex_unlock(&css->mutex);
760 return ret < 0 ? ret : count;
763 static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store);
765 static int __init setup_css(int nr)
769 struct channel_subsystem *css;
771 css = channel_subsystems[nr];
772 memset(css, 0, sizeof(struct channel_subsystem));
773 css->pseudo_subchannel =
774 kzalloc(sizeof(*css->pseudo_subchannel), GFP_KERNEL);
775 if (!css->pseudo_subchannel)
777 css->pseudo_subchannel->dev.parent = &css->device;
778 css->pseudo_subchannel->dev.release = css_subchannel_release;
779 dev_set_name(&css->pseudo_subchannel->dev, "defunct");
780 mutex_init(&css->pseudo_subchannel->reg_mutex);
781 ret = css_sch_create_locks(css->pseudo_subchannel);
783 kfree(css->pseudo_subchannel);
786 mutex_init(&css->mutex);
789 dev_set_name(&css->device, "css%x", nr);
790 css->device.release = channel_subsystem_release;
791 tod_high = (u32) (get_tod_clock() >> 32);
792 css_generate_pgid(css, tod_high);
796 static int css_reboot_event(struct notifier_block *this,
803 for (i = 0; i <= __MAX_CSSID; i++) {
804 struct channel_subsystem *css;
806 css = channel_subsystems[i];
807 mutex_lock(&css->mutex);
809 if (chsc_secm(css, 0))
811 mutex_unlock(&css->mutex);
817 static struct notifier_block css_reboot_notifier = {
818 .notifier_call = css_reboot_event,
822 * Since the css devices are neither on a bus nor have a class
823 * nor have a special device type, we cannot stop/restart channel
824 * path measurements via the normal suspend/resume callbacks, but have
827 static int css_power_event(struct notifier_block *this, unsigned long event,
833 case PM_HIBERNATION_PREPARE:
834 case PM_SUSPEND_PREPARE:
836 for (i = 0; i <= __MAX_CSSID; i++) {
837 struct channel_subsystem *css;
839 css = channel_subsystems[i];
840 mutex_lock(&css->mutex);
841 if (!css->cm_enabled) {
842 mutex_unlock(&css->mutex);
845 ret = __chsc_do_secm(css, 0);
846 ret = notifier_from_errno(ret);
847 mutex_unlock(&css->mutex);
850 case PM_POST_HIBERNATION:
851 case PM_POST_SUSPEND:
853 for (i = 0; i <= __MAX_CSSID; i++) {
854 struct channel_subsystem *css;
856 css = channel_subsystems[i];
857 mutex_lock(&css->mutex);
858 if (!css->cm_enabled) {
859 mutex_unlock(&css->mutex);
862 ret = __chsc_do_secm(css, 1);
863 ret = notifier_from_errno(ret);
864 mutex_unlock(&css->mutex);
866 /* search for subchannels, which appeared during hibernation */
867 css_schedule_reprobe();
875 static struct notifier_block css_power_notifier = {
876 .notifier_call = css_power_event,
880 * Now that the driver core is running, we can setup our channel subsystem.
881 * The struct subchannel's are created during probing.
883 static int __init css_bus_init(void)
891 chsc_determine_css_characteristics();
892 /* Try to enable MSS. */
893 ret = chsc_enable_facility(CHSC_SDA_OC_MSS);
897 max_ssid = __MAX_SSID;
899 ret = slow_subchannel_init();
903 ret = crw_register_handler(CRW_RSC_SCH, css_process_crw);
907 if ((ret = bus_register(&css_bus_type)))
910 /* Setup css structure. */
911 for (i = 0; i <= __MAX_CSSID; i++) {
912 struct channel_subsystem *css;
914 css = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL);
919 channel_subsystems[i] = css;
922 kfree(channel_subsystems[i]);
925 ret = device_register(&css->device);
927 put_device(&css->device);
930 if (css_chsc_characteristics.secm) {
931 ret = device_create_file(&css->device,
932 &dev_attr_cm_enable);
936 ret = device_register(&css->pseudo_subchannel->dev);
938 put_device(&css->pseudo_subchannel->dev);
942 ret = register_reboot_notifier(&css_reboot_notifier);
945 ret = register_pm_notifier(&css_power_notifier);
947 unregister_reboot_notifier(&css_reboot_notifier);
952 /* Enable default isc for I/O subchannels. */
953 isc_register(IO_SCH_ISC);
957 if (css_chsc_characteristics.secm)
958 device_remove_file(&channel_subsystems[i]->device,
959 &dev_attr_cm_enable);
961 device_unregister(&channel_subsystems[i]->device);
964 struct channel_subsystem *css;
967 css = channel_subsystems[i];
968 device_unregister(&css->pseudo_subchannel->dev);
969 css->pseudo_subchannel = NULL;
970 if (css_chsc_characteristics.secm)
971 device_remove_file(&css->device,
972 &dev_attr_cm_enable);
973 device_unregister(&css->device);
975 bus_unregister(&css_bus_type);
977 crw_unregister_handler(CRW_RSC_SCH);
978 idset_free(slow_subchannel_set);
980 pr_alert("The CSS device driver initialization failed with "
985 static void __init css_bus_cleanup(void)
987 struct channel_subsystem *css;
990 for (i = 0; i <= __MAX_CSSID; i++) {
991 css = channel_subsystems[i];
992 device_unregister(&css->pseudo_subchannel->dev);
993 css->pseudo_subchannel = NULL;
994 if (css_chsc_characteristics.secm)
995 device_remove_file(&css->device, &dev_attr_cm_enable);
996 device_unregister(&css->device);
998 bus_unregister(&css_bus_type);
999 crw_unregister_handler(CRW_RSC_SCH);
1000 idset_free(slow_subchannel_set);
1001 chsc_init_cleanup();
1002 isc_unregister(IO_SCH_ISC);
1005 static int __init channel_subsystem_init(void)
1009 ret = css_bus_init();
1012 cio_work_q = create_singlethread_workqueue("cio");
1017 ret = io_subchannel_init();
1023 destroy_workqueue(cio_work_q);
1028 subsys_initcall(channel_subsystem_init);
1030 static int css_settle(struct device_driver *drv, void *unused)
1032 struct css_driver *cssdrv = to_cssdriver(drv);
1035 return cssdrv->settle();
1039 int css_complete_work(void)
1043 /* Wait for the evaluation of subchannels to finish. */
1044 ret = wait_event_interruptible(css_eval_wq,
1045 atomic_read(&css_eval_scheduled) == 0);
1048 flush_workqueue(cio_work_q);
1049 /* Wait for the subchannel type specific initialization to finish */
1050 return bus_for_each_drv(&css_bus_type, NULL, NULL, css_settle);
1055 * Wait for the initialization of devices to finish, to make sure we are
1056 * done with our setup if the search for the root device starts.
1058 static int __init channel_subsystem_init_sync(void)
1060 /* Register subchannels which are already in use. */
1061 cio_register_early_subchannels();
1062 /* Start initial subchannel evaluation. */
1063 css_schedule_eval_all();
1064 css_complete_work();
1067 subsys_initcall_sync(channel_subsystem_init_sync);
1069 void channel_subsystem_reinit(void)
1071 struct channel_path *chp;
1072 struct chp_id chpid;
1074 chsc_enable_facility(CHSC_SDA_OC_MSS);
1075 chp_id_for_each(&chpid) {
1076 chp = chpid_to_chp(chpid);
1078 chp_update_desc(chp);
1082 #ifdef CONFIG_PROC_FS
1083 static ssize_t cio_settle_write(struct file *file, const char __user *buf,
1084 size_t count, loff_t *ppos)
1088 /* Handle pending CRW's. */
1089 crw_wait_for_channel_report();
1090 ret = css_complete_work();
1092 return ret ? ret : count;
1095 static const struct file_operations cio_settle_proc_fops = {
1096 .open = nonseekable_open,
1097 .write = cio_settle_write,
1098 .llseek = no_llseek,
1101 static int __init cio_settle_init(void)
1103 struct proc_dir_entry *entry;
1105 entry = proc_create("cio_settle", S_IWUSR, NULL,
1106 &cio_settle_proc_fops);
1111 device_initcall(cio_settle_init);
1112 #endif /*CONFIG_PROC_FS*/
1114 int sch_is_pseudo_sch(struct subchannel *sch)
1116 return sch == to_css(sch->dev.parent)->pseudo_subchannel;
1119 static int css_bus_match(struct device *dev, struct device_driver *drv)
1121 struct subchannel *sch = to_subchannel(dev);
1122 struct css_driver *driver = to_cssdriver(drv);
1123 struct css_device_id *id;
1125 for (id = driver->subchannel_type; id->match_flags; id++) {
1126 if (sch->st == id->type)
1133 static int css_probe(struct device *dev)
1135 struct subchannel *sch;
1138 sch = to_subchannel(dev);
1139 sch->driver = to_cssdriver(dev->driver);
1140 ret = sch->driver->probe ? sch->driver->probe(sch) : 0;
1146 static int css_remove(struct device *dev)
1148 struct subchannel *sch;
1151 sch = to_subchannel(dev);
1152 ret = sch->driver->remove ? sch->driver->remove(sch) : 0;
1157 static void css_shutdown(struct device *dev)
1159 struct subchannel *sch;
1161 sch = to_subchannel(dev);
1162 if (sch->driver && sch->driver->shutdown)
1163 sch->driver->shutdown(sch);
1166 static int css_uevent(struct device *dev, struct kobj_uevent_env *env)
1168 struct subchannel *sch = to_subchannel(dev);
1171 ret = add_uevent_var(env, "ST=%01X", sch->st);
1174 ret = add_uevent_var(env, "MODALIAS=css:t%01X", sch->st);
1178 static int css_pm_prepare(struct device *dev)
1180 struct subchannel *sch = to_subchannel(dev);
1181 struct css_driver *drv;
1183 if (mutex_is_locked(&sch->reg_mutex))
1185 if (!sch->dev.driver)
1187 drv = to_cssdriver(sch->dev.driver);
1188 /* Notify drivers that they may not register children. */
1189 return drv->prepare ? drv->prepare(sch) : 0;
1192 static void css_pm_complete(struct device *dev)
1194 struct subchannel *sch = to_subchannel(dev);
1195 struct css_driver *drv;
1197 if (!sch->dev.driver)
1199 drv = to_cssdriver(sch->dev.driver);
1204 static int css_pm_freeze(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);
1212 return drv->freeze ? drv->freeze(sch) : 0;
1215 static int css_pm_thaw(struct device *dev)
1217 struct subchannel *sch = to_subchannel(dev);
1218 struct css_driver *drv;
1220 if (!sch->dev.driver)
1222 drv = to_cssdriver(sch->dev.driver);
1223 return drv->thaw ? drv->thaw(sch) : 0;
1226 static int css_pm_restore(struct device *dev)
1228 struct subchannel *sch = to_subchannel(dev);
1229 struct css_driver *drv;
1231 css_update_ssd_info(sch);
1232 if (!sch->dev.driver)
1234 drv = to_cssdriver(sch->dev.driver);
1235 return drv->restore ? drv->restore(sch) : 0;
1238 static const struct dev_pm_ops css_pm_ops = {
1239 .prepare = css_pm_prepare,
1240 .complete = css_pm_complete,
1241 .freeze = css_pm_freeze,
1242 .thaw = css_pm_thaw,
1243 .restore = css_pm_restore,
1246 static struct bus_type css_bus_type = {
1248 .match = css_bus_match,
1250 .remove = css_remove,
1251 .shutdown = css_shutdown,
1252 .uevent = css_uevent,
1257 * css_driver_register - register a css driver
1258 * @cdrv: css driver to register
1260 * This is mainly a wrapper around driver_register that sets name
1261 * and bus_type in the embedded struct device_driver correctly.
1263 int css_driver_register(struct css_driver *cdrv)
1265 cdrv->drv.bus = &css_bus_type;
1266 return driver_register(&cdrv->drv);
1268 EXPORT_SYMBOL_GPL(css_driver_register);
1271 * css_driver_unregister - unregister a css driver
1272 * @cdrv: css driver to unregister
1274 * This is a wrapper around driver_unregister.
1276 void css_driver_unregister(struct css_driver *cdrv)
1278 driver_unregister(&cdrv->drv);
1280 EXPORT_SYMBOL_GPL(css_driver_unregister);
1282 MODULE_LICENSE("GPL");