2 * driver for channel subsystem
4 * Copyright IBM Corp. 2002, 2009
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>
26 #include "cio_debug.h"
33 int css_init_done = 0;
34 static int need_reprobe = 0;
35 static int max_ssid = 0;
37 struct channel_subsystem *channel_subsystems[__MAX_CSSID + 1];
40 for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data)
42 struct subchannel_id schid;
45 init_subchannel_id(&schid);
49 ret = fn(schid, data);
52 } while (schid.sch_no++ < __MAX_SUBCHANNEL);
54 } while (schid.ssid++ < max_ssid);
61 int (*fn_known_sch)(struct subchannel *, void *);
62 int (*fn_unknown_sch)(struct subchannel_id, void *);
65 static int call_fn_known_sch(struct device *dev, void *data)
67 struct subchannel *sch = to_subchannel(dev);
68 struct cb_data *cb = data;
71 idset_sch_del(cb->set, sch->schid);
73 rc = cb->fn_known_sch(sch, cb->data);
77 static int call_fn_unknown_sch(struct subchannel_id schid, void *data)
79 struct cb_data *cb = data;
82 if (idset_sch_contains(cb->set, schid))
83 rc = cb->fn_unknown_sch(schid, cb->data);
87 static int call_fn_all_sch(struct subchannel_id schid, void *data)
89 struct cb_data *cb = data;
90 struct subchannel *sch;
93 sch = get_subchannel_by_schid(schid);
96 rc = cb->fn_known_sch(sch, cb->data);
97 put_device(&sch->dev);
99 if (cb->fn_unknown_sch)
100 rc = cb->fn_unknown_sch(schid, cb->data);
106 int for_each_subchannel_staged(int (*fn_known)(struct subchannel *, void *),
107 int (*fn_unknown)(struct subchannel_id,
114 cb.fn_known_sch = fn_known;
115 cb.fn_unknown_sch = fn_unknown;
117 cb.set = idset_sch_new();
119 /* fall back to brute force scanning in case of oom */
120 return for_each_subchannel(call_fn_all_sch, &cb);
124 /* Process registered subchannels. */
125 rc = bus_for_each_dev(&css_bus_type, NULL, &cb, call_fn_known_sch);
128 /* Process unregistered subchannels. */
130 rc = for_each_subchannel(call_fn_unknown_sch, &cb);
137 static struct subchannel *
138 css_alloc_subchannel(struct subchannel_id schid)
140 struct subchannel *sch;
143 sch = kmalloc (sizeof (*sch), GFP_KERNEL | GFP_DMA);
145 return ERR_PTR(-ENOMEM);
146 ret = cio_validate_subchannel (sch, schid);
155 css_subchannel_release(struct device *dev)
157 struct subchannel *sch;
159 sch = to_subchannel(dev);
160 if (!cio_is_console(sch->schid)) {
161 /* Reset intparm to zeroes. */
162 sch->config.intparm = 0;
163 cio_commit_config(sch);
169 static int css_sch_device_register(struct subchannel *sch)
173 mutex_lock(&sch->reg_mutex);
174 dev_set_name(&sch->dev, "0.%x.%04x", sch->schid.ssid,
176 ret = device_register(&sch->dev);
177 mutex_unlock(&sch->reg_mutex);
182 * css_sch_device_unregister - unregister a subchannel
183 * @sch: subchannel to be unregistered
185 void css_sch_device_unregister(struct subchannel *sch)
187 mutex_lock(&sch->reg_mutex);
188 if (device_is_registered(&sch->dev))
189 device_unregister(&sch->dev);
190 mutex_unlock(&sch->reg_mutex);
192 EXPORT_SYMBOL_GPL(css_sch_device_unregister);
194 static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw)
199 memset(ssd, 0, sizeof(struct chsc_ssd_info));
200 ssd->path_mask = pmcw->pim;
201 for (i = 0; i < 8; i++) {
203 if (pmcw->pim & mask) {
204 chp_id_init(&ssd->chpid[i]);
205 ssd->chpid[i].id = pmcw->chpid[i];
210 static void ssd_register_chpids(struct chsc_ssd_info *ssd)
215 for (i = 0; i < 8; i++) {
217 if (ssd->path_mask & mask)
218 if (!chp_is_registered(ssd->chpid[i]))
219 chp_new(ssd->chpid[i]);
223 void css_update_ssd_info(struct subchannel *sch)
227 if (cio_is_console(sch->schid)) {
228 /* Console is initialized too early for functions requiring
229 * memory allocation. */
230 ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
232 ret = chsc_get_ssd_info(sch->schid, &sch->ssd_info);
234 ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
235 ssd_register_chpids(&sch->ssd_info);
239 static ssize_t type_show(struct device *dev, struct device_attribute *attr,
242 struct subchannel *sch = to_subchannel(dev);
244 return sprintf(buf, "%01x\n", sch->st);
247 static DEVICE_ATTR(type, 0444, type_show, NULL);
249 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
252 struct subchannel *sch = to_subchannel(dev);
254 return sprintf(buf, "css:t%01X\n", sch->st);
257 static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
259 static struct attribute *subch_attrs[] = {
261 &dev_attr_modalias.attr,
265 static struct attribute_group subch_attr_group = {
266 .attrs = subch_attrs,
269 static const struct attribute_group *default_subch_attr_groups[] = {
274 static int css_register_subchannel(struct subchannel *sch)
278 /* Initialize the subchannel structure */
279 sch->dev.parent = &channel_subsystems[0]->device;
280 sch->dev.bus = &css_bus_type;
281 sch->dev.release = &css_subchannel_release;
282 sch->dev.groups = default_subch_attr_groups;
284 * We don't want to generate uevents for I/O subchannels that don't
285 * have a working ccw device behind them since they will be
286 * unregistered before they can be used anyway, so we delay the add
287 * uevent until after device recognition was successful.
288 * Note that we suppress the uevent for all subchannel types;
289 * the subchannel driver can decide itself when it wants to inform
290 * userspace of its existence.
292 dev_set_uevent_suppress(&sch->dev, 1);
293 css_update_ssd_info(sch);
294 /* make it known to the system */
295 ret = css_sch_device_register(sch);
297 CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n",
298 sch->schid.ssid, sch->schid.sch_no, ret);
303 * No driver matched. Generate the uevent now so that
304 * a fitting driver module may be loaded based on the
307 dev_set_uevent_suppress(&sch->dev, 0);
308 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
313 int css_probe_device(struct subchannel_id schid)
316 struct subchannel *sch;
318 sch = css_alloc_subchannel(schid);
321 ret = css_register_subchannel(sch);
323 put_device(&sch->dev);
328 check_subchannel(struct device * dev, void * data)
330 struct subchannel *sch;
331 struct subchannel_id *schid = data;
333 sch = to_subchannel(dev);
334 return schid_equal(&sch->schid, schid);
338 get_subchannel_by_schid(struct subchannel_id schid)
342 dev = bus_find_device(&css_bus_type, NULL,
343 &schid, check_subchannel);
345 return dev ? to_subchannel(dev) : NULL;
349 * css_sch_is_valid() - check if a subchannel is valid
350 * @schib: subchannel information block for the subchannel
352 int css_sch_is_valid(struct schib *schib)
354 if ((schib->pmcw.st == SUBCHANNEL_TYPE_IO) && !schib->pmcw.dnv)
356 if ((schib->pmcw.st == SUBCHANNEL_TYPE_MSG) && !schib->pmcw.w)
360 EXPORT_SYMBOL_GPL(css_sch_is_valid);
362 static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow)
367 /* Will be done on the slow path. */
370 if (stsch_err(schid, &schib) || !css_sch_is_valid(&schib)) {
371 /* Unusable - ignore. */
374 CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, unknown, "
375 "slow path.\n", schid.ssid, schid.sch_no, CIO_OPER);
377 return css_probe_device(schid);
380 static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
385 if (sch->driver->sch_event)
386 ret = sch->driver->sch_event(sch, slow);
389 "Got subchannel machine check but "
390 "no sch_event handler provided.\n");
395 static void css_evaluate_subchannel(struct subchannel_id schid, int slow)
397 struct subchannel *sch;
400 sch = get_subchannel_by_schid(schid);
402 ret = css_evaluate_known_subchannel(sch, slow);
403 put_device(&sch->dev);
405 ret = css_evaluate_new_subchannel(schid, slow);
407 css_schedule_eval(schid);
410 static struct idset *slow_subchannel_set;
411 static spinlock_t slow_subchannel_lock;
412 static wait_queue_head_t css_eval_wq;
413 static atomic_t css_eval_scheduled;
415 static int __init slow_subchannel_init(void)
417 spin_lock_init(&slow_subchannel_lock);
418 atomic_set(&css_eval_scheduled, 0);
419 init_waitqueue_head(&css_eval_wq);
420 slow_subchannel_set = idset_sch_new();
421 if (!slow_subchannel_set) {
422 CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n");
428 static int slow_eval_known_fn(struct subchannel *sch, void *data)
433 spin_lock_irq(&slow_subchannel_lock);
434 eval = idset_sch_contains(slow_subchannel_set, sch->schid);
435 idset_sch_del(slow_subchannel_set, sch->schid);
436 spin_unlock_irq(&slow_subchannel_lock);
438 rc = css_evaluate_known_subchannel(sch, 1);
440 css_schedule_eval(sch->schid);
445 static int slow_eval_unknown_fn(struct subchannel_id schid, void *data)
450 spin_lock_irq(&slow_subchannel_lock);
451 eval = idset_sch_contains(slow_subchannel_set, schid);
452 idset_sch_del(slow_subchannel_set, schid);
453 spin_unlock_irq(&slow_subchannel_lock);
455 rc = css_evaluate_new_subchannel(schid, 1);
458 css_schedule_eval(schid);
464 /* These should abort looping */
473 static void css_slow_path_func(struct work_struct *unused)
477 CIO_TRACE_EVENT(4, "slowpath");
478 for_each_subchannel_staged(slow_eval_known_fn, slow_eval_unknown_fn,
480 spin_lock_irqsave(&slow_subchannel_lock, flags);
481 if (idset_is_empty(slow_subchannel_set)) {
482 atomic_set(&css_eval_scheduled, 0);
483 wake_up(&css_eval_wq);
485 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
488 static DECLARE_WORK(slow_path_work, css_slow_path_func);
489 struct workqueue_struct *slow_path_wq;
491 void css_schedule_eval(struct subchannel_id schid)
495 spin_lock_irqsave(&slow_subchannel_lock, flags);
496 idset_sch_add(slow_subchannel_set, schid);
497 atomic_set(&css_eval_scheduled, 1);
498 queue_work(slow_path_wq, &slow_path_work);
499 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
502 void css_schedule_eval_all(void)
506 spin_lock_irqsave(&slow_subchannel_lock, flags);
507 idset_fill(slow_subchannel_set);
508 atomic_set(&css_eval_scheduled, 1);
509 queue_work(slow_path_wq, &slow_path_work);
510 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
513 void css_wait_for_slow_path(void)
515 flush_workqueue(slow_path_wq);
518 /* Reprobe subchannel if unregistered. */
519 static int reprobe_subchannel(struct subchannel_id schid, void *data)
523 CIO_MSG_EVENT(6, "cio: reprobe 0.%x.%04x\n",
524 schid.ssid, schid.sch_no);
528 ret = css_probe_device(schid);
535 /* These should abort looping */
544 static void reprobe_after_idle(struct work_struct *unused)
546 /* Make sure initial subchannel scan is done. */
547 wait_event(ccw_device_init_wq,
548 atomic_read(&ccw_device_init_count) == 0);
550 css_schedule_reprobe();
553 static DECLARE_WORK(reprobe_idle_work, reprobe_after_idle);
555 /* Work function used to reprobe all unregistered subchannels. */
556 static void reprobe_all(struct work_struct *unused)
560 CIO_MSG_EVENT(4, "reprobe start\n");
562 /* Make sure initial subchannel scan is done. */
563 if (atomic_read(&ccw_device_init_count) != 0) {
564 queue_work(ccw_device_work, &reprobe_idle_work);
568 ret = for_each_subchannel_staged(NULL, reprobe_subchannel, NULL);
570 CIO_MSG_EVENT(4, "reprobe done (rc=%d, need_reprobe=%d)\n", ret,
574 static DECLARE_WORK(css_reprobe_work, reprobe_all);
576 /* Schedule reprobing of all unregistered subchannels. */
577 void css_schedule_reprobe(void)
580 queue_work(slow_path_wq, &css_reprobe_work);
583 EXPORT_SYMBOL_GPL(css_schedule_reprobe);
586 * Called from the machine check handler for subchannel report words.
588 static void css_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
590 struct subchannel_id mchk_schid;
593 css_schedule_eval_all();
596 CIO_CRW_EVENT(2, "CRW0 reports slct=%d, oflw=%d, "
597 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
598 crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
599 crw0->erc, crw0->rsid);
601 CIO_CRW_EVENT(2, "CRW1 reports slct=%d, oflw=%d, "
602 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
603 crw1->slct, crw1->oflw, crw1->chn, crw1->rsc,
604 crw1->anc, crw1->erc, crw1->rsid);
605 init_subchannel_id(&mchk_schid);
606 mchk_schid.sch_no = crw0->rsid;
608 mchk_schid.ssid = (crw1->rsid >> 8) & 3;
611 * Since we are always presented with IPI in the CRW, we have to
612 * use stsch() to find out if the subchannel in question has come
615 css_evaluate_subchannel(mchk_schid, 0);
618 static int __init setup_subchannel(struct subchannel_id schid, void *data)
620 struct subchannel *sch;
623 if (cio_is_console(schid))
624 sch = cio_get_console_subchannel();
626 sch = css_alloc_subchannel(schid);
635 panic("Out of memory in init_channel_subsystem\n");
636 /* -ENXIO: no more subchannels. */
639 /* -EIO: this subchannel set not supported. */
647 * We register ALL valid subchannels in ioinfo, even those
648 * that have been present before init_channel_subsystem.
649 * These subchannels can't have been registered yet (kmalloc
650 * not working) so we do it now. This is true e.g. for the
651 * console subchannel.
653 if (css_register_subchannel(sch)) {
654 if (!cio_is_console(schid))
655 put_device(&sch->dev);
661 css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
663 if (css_general_characteristics.mcss) {
664 css->global_pgid.pgid_high.ext_cssid.version = 0x80;
665 css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid;
668 css->global_pgid.pgid_high.cpu_addr = stap();
670 css->global_pgid.pgid_high.cpu_addr = 0;
673 css->global_pgid.cpu_id = S390_lowcore.cpu_id.ident;
674 css->global_pgid.cpu_model = S390_lowcore.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 ret = cio_create_sch_lock(css->pseudo_subchannel);
754 kfree(css->pseudo_subchannel);
757 mutex_init(&css->mutex);
760 dev_set_name(&css->device, "css%x", nr);
761 css->device.release = channel_subsystem_release;
762 tod_high = (u32) (get_clock() >> 32);
763 css_generate_pgid(css, tod_high);
767 static int css_reboot_event(struct notifier_block *this,
774 for (i = 0; i <= __MAX_CSSID; i++) {
775 struct channel_subsystem *css;
777 css = channel_subsystems[i];
778 mutex_lock(&css->mutex);
780 if (chsc_secm(css, 0))
782 mutex_unlock(&css->mutex);
788 static struct notifier_block css_reboot_notifier = {
789 .notifier_call = css_reboot_event,
793 * Since the css devices are neither on a bus nor have a class
794 * nor have a special device type, we cannot stop/restart channel
795 * path measurements via the normal suspend/resume callbacks, but have
798 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 secm_area = (void *)get_zeroed_page(GFP_KERNEL |
820 if (__chsc_do_secm(css, 0, secm_area))
822 free_page((unsigned long)secm_area);
826 mutex_unlock(&css->mutex);
829 case PM_POST_HIBERNATION:
830 case PM_POST_SUSPEND:
832 for (i = 0; i <= __MAX_CSSID; i++) {
833 struct channel_subsystem *css;
835 css = channel_subsystems[i];
836 mutex_lock(&css->mutex);
837 if (!css->cm_enabled) {
838 mutex_unlock(&css->mutex);
841 secm_area = (void *)get_zeroed_page(GFP_KERNEL |
844 if (__chsc_do_secm(css, 1, secm_area))
846 free_page((unsigned long)secm_area);
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)
874 ret = chsc_determine_css_characteristics();
878 ret = chsc_alloc_sei_area();
882 ret = slow_subchannel_init();
886 ret = crw_register_handler(CRW_RSC_SCH, css_process_crw);
890 if ((ret = bus_register(&css_bus_type)))
893 /* Try to enable MSS. */
894 ret = chsc_enable_facility(CHSC_SDA_OC_MSS);
896 case 0: /* Success. */
897 max_ssid = __MAX_SSID;
904 /* Setup css structure. */
905 for (i = 0; i <= __MAX_CSSID; i++) {
906 struct channel_subsystem *css;
908 css = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL);
913 channel_subsystems[i] = css;
916 kfree(channel_subsystems[i]);
919 ret = device_register(&css->device);
921 put_device(&css->device);
924 if (css_chsc_characteristics.secm) {
925 ret = device_create_file(&css->device,
926 &dev_attr_cm_enable);
930 ret = device_register(&css->pseudo_subchannel->dev);
932 put_device(&css->pseudo_subchannel->dev);
936 ret = register_reboot_notifier(&css_reboot_notifier);
939 ret = register_pm_notifier(&css_power_notifier);
941 unregister_reboot_notifier(&css_reboot_notifier);
946 /* Enable default isc for I/O subchannels. */
947 isc_register(IO_SCH_ISC);
951 if (css_chsc_characteristics.secm)
952 device_remove_file(&channel_subsystems[i]->device,
953 &dev_attr_cm_enable);
955 device_unregister(&channel_subsystems[i]->device);
958 struct channel_subsystem *css;
961 css = channel_subsystems[i];
962 device_unregister(&css->pseudo_subchannel->dev);
963 css->pseudo_subchannel = NULL;
964 if (css_chsc_characteristics.secm)
965 device_remove_file(&css->device,
966 &dev_attr_cm_enable);
967 device_unregister(&css->device);
970 bus_unregister(&css_bus_type);
972 crw_unregister_handler(CRW_RSC_CSS);
973 chsc_free_sei_area();
974 kfree(slow_subchannel_set);
975 pr_alert("The CSS device driver initialization failed with "
980 static void __init css_bus_cleanup(void)
982 struct channel_subsystem *css;
985 for (i = 0; i <= __MAX_CSSID; i++) {
986 css = channel_subsystems[i];
987 device_unregister(&css->pseudo_subchannel->dev);
988 css->pseudo_subchannel = NULL;
989 if (css_chsc_characteristics.secm)
990 device_remove_file(&css->device, &dev_attr_cm_enable);
991 device_unregister(&css->device);
993 bus_unregister(&css_bus_type);
994 crw_unregister_handler(CRW_RSC_CSS);
995 chsc_free_sei_area();
996 kfree(slow_subchannel_set);
997 isc_unregister(IO_SCH_ISC);
1000 static int __init channel_subsystem_init(void)
1004 ret = css_bus_init();
1008 ret = io_subchannel_init();
1014 subsys_initcall(channel_subsystem_init);
1016 static int css_settle(struct device_driver *drv, void *unused)
1018 struct css_driver *cssdrv = to_cssdriver(drv);
1026 * Wait for the initialization of devices to finish, to make sure we are
1027 * done with our setup if the search for the root device starts.
1029 static int __init channel_subsystem_init_sync(void)
1031 /* Allocate and register subchannels. */
1032 for_each_subchannel(setup_subchannel, NULL);
1033 /* Wait for the evaluation of subchannels to finish. */
1034 wait_event(css_eval_wq, atomic_read(&css_eval_scheduled) == 0);
1036 /* Wait for the subchannel type specific initialization to finish */
1037 return bus_for_each_drv(&css_bus_type, NULL, NULL, css_settle);
1039 subsys_initcall_sync(channel_subsystem_init_sync);
1041 int sch_is_pseudo_sch(struct subchannel *sch)
1043 return sch == to_css(sch->dev.parent)->pseudo_subchannel;
1046 static int css_bus_match(struct device *dev, struct device_driver *drv)
1048 struct subchannel *sch = to_subchannel(dev);
1049 struct css_driver *driver = to_cssdriver(drv);
1050 struct css_device_id *id;
1052 for (id = driver->subchannel_type; id->match_flags; id++) {
1053 if (sch->st == id->type)
1060 static int css_probe(struct device *dev)
1062 struct subchannel *sch;
1065 sch = to_subchannel(dev);
1066 sch->driver = to_cssdriver(dev->driver);
1067 ret = sch->driver->probe ? sch->driver->probe(sch) : 0;
1073 static int css_remove(struct device *dev)
1075 struct subchannel *sch;
1078 sch = to_subchannel(dev);
1079 ret = sch->driver->remove ? sch->driver->remove(sch) : 0;
1084 static void css_shutdown(struct device *dev)
1086 struct subchannel *sch;
1088 sch = to_subchannel(dev);
1089 if (sch->driver && sch->driver->shutdown)
1090 sch->driver->shutdown(sch);
1093 static int css_uevent(struct device *dev, struct kobj_uevent_env *env)
1095 struct subchannel *sch = to_subchannel(dev);
1098 ret = add_uevent_var(env, "ST=%01X", sch->st);
1101 ret = add_uevent_var(env, "MODALIAS=css:t%01X", sch->st);
1105 static int css_pm_prepare(struct device *dev)
1107 struct subchannel *sch = to_subchannel(dev);
1108 struct css_driver *drv;
1110 if (mutex_is_locked(&sch->reg_mutex))
1112 if (!sch->dev.driver)
1114 drv = to_cssdriver(sch->dev.driver);
1115 /* Notify drivers that they may not register children. */
1116 return drv->prepare ? drv->prepare(sch) : 0;
1119 static void css_pm_complete(struct device *dev)
1121 struct subchannel *sch = to_subchannel(dev);
1122 struct css_driver *drv;
1124 if (!sch->dev.driver)
1126 drv = to_cssdriver(sch->dev.driver);
1131 static int css_pm_freeze(struct device *dev)
1133 struct subchannel *sch = to_subchannel(dev);
1134 struct css_driver *drv;
1136 if (!sch->dev.driver)
1138 drv = to_cssdriver(sch->dev.driver);
1139 return drv->freeze ? drv->freeze(sch) : 0;
1142 static int css_pm_thaw(struct device *dev)
1144 struct subchannel *sch = to_subchannel(dev);
1145 struct css_driver *drv;
1147 if (!sch->dev.driver)
1149 drv = to_cssdriver(sch->dev.driver);
1150 return drv->thaw ? drv->thaw(sch) : 0;
1153 static int css_pm_restore(struct device *dev)
1155 struct subchannel *sch = to_subchannel(dev);
1156 struct css_driver *drv;
1158 if (!sch->dev.driver)
1160 drv = to_cssdriver(sch->dev.driver);
1161 return drv->restore ? drv->restore(sch) : 0;
1164 static struct dev_pm_ops css_pm_ops = {
1165 .prepare = css_pm_prepare,
1166 .complete = css_pm_complete,
1167 .freeze = css_pm_freeze,
1168 .thaw = css_pm_thaw,
1169 .restore = css_pm_restore,
1172 struct bus_type css_bus_type = {
1174 .match = css_bus_match,
1176 .remove = css_remove,
1177 .shutdown = css_shutdown,
1178 .uevent = css_uevent,
1183 * css_driver_register - register a css driver
1184 * @cdrv: css driver to register
1186 * This is mainly a wrapper around driver_register that sets name
1187 * and bus_type in the embedded struct device_driver correctly.
1189 int css_driver_register(struct css_driver *cdrv)
1191 cdrv->drv.name = cdrv->name;
1192 cdrv->drv.bus = &css_bus_type;
1193 cdrv->drv.owner = cdrv->owner;
1194 return driver_register(&cdrv->drv);
1196 EXPORT_SYMBOL_GPL(css_driver_register);
1199 * css_driver_unregister - unregister a css driver
1200 * @cdrv: css driver to unregister
1202 * This is a wrapper around driver_unregister.
1204 void css_driver_unregister(struct css_driver *cdrv)
1206 driver_unregister(&cdrv->drv);
1208 EXPORT_SYMBOL_GPL(css_driver_unregister);
1210 MODULE_LICENSE("GPL");
1211 EXPORT_SYMBOL(css_bus_type);