10 #define KMSG_COMPONENT "cio"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/module.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>
46 init_subchannel_id(&schid);
50 ret =
fn(schid, data);
88 static int call_fn_all_sch(
struct subchannel_id schid,
void *data)
159 css_subchannel_release(
struct device *
dev)
173 static int css_sch_device_register(
struct subchannel *sch)
192 if (device_is_registered(&sch->
dev))
205 for (i = 0; i < 8; i++) {
207 if (pmcw->
pim & mask) {
208 chp_id_init(&ssd->
chpid[i]);
219 for (i = 0; i < 8; i++) {
239 ssd_register_chpids(&sch->
ssd_info);
258 return sprintf(buf,
"css:t%01X\n", sch->
st);
263 static struct attribute *subch_attrs[] = {
265 &dev_attr_modalias.attr,
270 .attrs = subch_attrs,
278 static int css_register_subchannel(
struct subchannel *sch)
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;
296 dev_set_uevent_suppress(&sch->
dev, 1);
299 ret = css_sch_device_register(sch);
311 dev_set_uevent_suppress(&sch->
dev, 0);
325 sch = css_alloc_subchannel(schid);
329 ret = css_register_subchannel(sch);
338 check_subchannel(
struct device * dev,
void * data)
344 return schid_equal(&sch->
schid, schid);
353 &schid, check_subchannel);
372 static int css_evaluate_new_subchannel(
struct subchannel_id schid,
int slow)
380 if (stsch_err(schid, &
schib)) {
394 static int css_evaluate_known_subchannel(
struct subchannel *sch,
int slow)
399 if (sch->
driver->sch_event)
400 ret = sch->
driver->sch_event(sch, slow);
403 "Got subchannel machine check but "
404 "no sch_event handler provided.\n");
406 if (ret != 0 && ret != -
EAGAIN) {
413 static void css_evaluate_subchannel(
struct subchannel_id schid,
int slow)
420 ret = css_evaluate_known_subchannel(sch, slow);
423 ret = css_evaluate_new_subchannel(schid, slow);
441 if (sch->
todo >= todo)
462 spin_lock_irq(sch->
lock);
465 sch->
schid.sch_no, todo);
467 spin_unlock_irq(sch->
lock);
473 ret = css_evaluate_known_subchannel(sch, 1);
475 spin_lock_irq(sch->
lock);
477 spin_unlock_irq(sch->
lock);
488 static struct idset *slow_subchannel_set;
493 static int __init slow_subchannel_init(
void)
499 if (!slow_subchannel_set) {
500 CIO_MSG_EVENT(0,
"could not allocate slow subchannel set\n");
506 static int slow_eval_known_fn(
struct subchannel *sch,
void *data)
511 spin_lock_irq(&slow_subchannel_lock);
514 spin_unlock_irq(&slow_subchannel_lock);
516 rc = css_evaluate_known_subchannel(sch, 1);
523 static int slow_eval_unknown_fn(
struct subchannel_id schid,
void *data)
528 spin_lock_irq(&slow_subchannel_lock);
531 spin_unlock_irq(&slow_subchannel_lock);
533 rc = css_evaluate_new_subchannel(schid, 1);
564 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
567 static DECLARE_WORK(slow_path_work, css_slow_path_func);
578 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
589 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
592 static int __unset_registered(
struct device *dev,
void *data)
601 static void css_schedule_eval_all_unreg(
void)
604 struct idset *unreg_set;
620 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
632 css_schedule_eval_all_unreg();
639 static void css_process_crw(
struct crw *crw0,
struct crw *crw1,
int overflow)
649 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
654 "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
657 init_subchannel_id(&mchk_schid);
658 mchk_schid.sch_no = crw0->
rsid;
660 mchk_schid.ssid = (crw1->
rsid >> 4) & 3;
674 css_evaluate_subchannel(mchk_schid, 0);
683 css->
global_pgid.pgid_high.ext_cssid.version = 0x80;
700 channel_subsystem_release(
struct device *dev)
731 const char *buf,
size_t count)
752 return ret < 0 ? ret :
count;
755 static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store);
763 css = channel_subsystems[
nr];
782 css->
device.release = channel_subsystem_release;
784 css_generate_pgid(css, tod_high);
798 css = channel_subsystems[
i];
810 .notifier_call = css_reboot_event,
819 static int css_power_event(
struct notifier_block *
this,
unsigned long event,
831 css = channel_subsystems[
i];
838 ret = notifier_from_errno(ret);
848 css = channel_subsystems[
i];
855 ret = notifier_from_errno(ret);
868 .notifier_call = css_power_event,
876 static int __init css_bus_init(
void)
892 ret = slow_subchannel_init();
912 channel_subsystems[
i] = css;
915 kfree(channel_subsystems[i]);
925 &dev_attr_cm_enable);
938 ret = register_pm_notifier(&css_power_notifier);
952 &dev_attr_cm_enable);
960 css = channel_subsystems[
i];
965 &dev_attr_cm_enable);
973 pr_alert(
"The CSS device driver initialization failed with "
978 static void __init css_bus_cleanup(
void)
984 css = channel_subsystems[
i];
998 static int __init channel_subsystem_init(
void)
1002 ret = css_bus_init();
1023 static int css_settle(
struct device_driver *drv,
void *unused)
1051 static int __init channel_subsystem_init_sync(
void)
1067 chp = chpid_to_chp(chpid);
1074 #ifdef CONFIG_PROC_FS
1075 static ssize_t cio_settle_write(
struct file *
file,
const char __user *buf,
1076 size_t count, loff_t *ppos)
1084 return ret ? ret :
count;
1089 .write = cio_settle_write,
1093 static int __init cio_settle_init(
void)
1098 &cio_settle_proc_fops);
1108 return sch ==
to_css(sch->
dev.parent)->pseudo_subchannel;
1125 static int css_probe(
struct device *dev)
1132 ret = sch->
driver->probe ? sch->
driver->probe(sch) : 0;
1138 static int css_remove(
struct device *dev)
1144 ret = sch->
driver->remove ? sch->
driver->remove(sch) : 0;
1149 static void css_shutdown(
struct device *dev)
1155 sch->
driver->shutdown(sch);
1170 static int css_pm_prepare(
struct device *dev)
1177 if (!sch->
dev.driver)
1184 static void css_pm_complete(
struct device *dev)
1189 if (!sch->
dev.driver)
1196 static int css_pm_freeze(
struct device *dev)
1201 if (!sch->
dev.driver)
1207 static int css_pm_thaw(
struct device *dev)
1212 if (!sch->
dev.driver)
1215 return drv->
thaw ? drv->
thaw(sch) : 0;
1218 static int css_pm_restore(
struct device *dev)
1224 if (!sch->
dev.driver)
1230 static const struct dev_pm_ops css_pm_ops = {
1231 .prepare = css_pm_prepare,
1232 .complete = css_pm_complete,
1233 .freeze = css_pm_freeze,
1234 .thaw = css_pm_thaw,
1235 .restore = css_pm_restore,
1238 static struct bus_type css_bus_type = {
1240 .match = css_bus_match,
1242 .remove = css_remove,
1243 .shutdown = css_shutdown,
1244 .uevent = css_uevent,
1257 cdrv->
drv.bus = &css_bus_type;