From be5d3823f29c09676abd2eeea4f9767bc4a1a531 Mon Sep 17 00:00:00 2001 From: Sebastian Ott Date: Fri, 26 Feb 2010 22:37:24 +0100 Subject: [S390] cio: consolidate workqueues We used to maintain 2 singlethreaded workqueues for synchronization and to trigger work from interrupt context. Since our latest cio changes we only use one of these workqueues. So get rid of the unused workqueue, rename the remaining one to "cio_work_q" and move its ownership to the channel subsystem driver. Signed-off-by: Sebastian Ott Signed-off-by: Martin Schwidefsky --- drivers/s390/cio/css.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'drivers/s390/cio/css.c') diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c index 7679aee6fa14..99fcf9d0ea14 100644 --- a/drivers/s390/cio/css.c +++ b/drivers/s390/cio/css.c @@ -232,7 +232,7 @@ void css_sched_sch_todo(struct subchannel *sch, enum sch_todo todo) if (!get_device(&sch->dev)) return; sch->todo = todo; - if (!queue_work(slow_path_wq, &sch->todo_work)) { + if (!queue_work(cio_work_q, &sch->todo_work)) { /* Already queued, release workqueue ref. */ put_device(&sch->dev); } @@ -543,7 +543,7 @@ static void css_slow_path_func(struct work_struct *unused) } static DECLARE_WORK(slow_path_work, css_slow_path_func); -struct workqueue_struct *slow_path_wq; +struct workqueue_struct *cio_work_q; void css_schedule_eval(struct subchannel_id schid) { @@ -552,7 +552,7 @@ void css_schedule_eval(struct subchannel_id schid) spin_lock_irqsave(&slow_subchannel_lock, flags); idset_sch_add(slow_subchannel_set, schid); atomic_set(&css_eval_scheduled, 1); - queue_work(slow_path_wq, &slow_path_work); + queue_work(cio_work_q, &slow_path_work); spin_unlock_irqrestore(&slow_subchannel_lock, flags); } @@ -563,7 +563,7 @@ void css_schedule_eval_all(void) spin_lock_irqsave(&slow_subchannel_lock, flags); idset_fill(slow_subchannel_set); atomic_set(&css_eval_scheduled, 1); - queue_work(slow_path_wq, &slow_path_work); + queue_work(cio_work_q, &slow_path_work); spin_unlock_irqrestore(&slow_subchannel_lock, flags); } @@ -594,14 +594,14 @@ void css_schedule_eval_all_unreg(void) spin_lock_irqsave(&slow_subchannel_lock, flags); idset_add_set(slow_subchannel_set, unreg_set); atomic_set(&css_eval_scheduled, 1); - queue_work(slow_path_wq, &slow_path_work); + queue_work(cio_work_q, &slow_path_work); spin_unlock_irqrestore(&slow_subchannel_lock, flags); idset_free(unreg_set); } void css_wait_for_slow_path(void) { - flush_workqueue(slow_path_wq); + flush_workqueue(cio_work_q); } /* Schedule reprobing of all unregistered subchannels. */ @@ -992,12 +992,21 @@ static int __init channel_subsystem_init(void) ret = css_bus_init(); if (ret) return ret; - + cio_work_q = create_singlethread_workqueue("cio"); + if (!cio_work_q) { + ret = -ENOMEM; + goto out_bus; + } ret = io_subchannel_init(); if (ret) - css_bus_cleanup(); + goto out_wq; return ret; +out_wq: + destroy_workqueue(cio_work_q); +out_bus: + css_bus_cleanup(); + return ret; } subsys_initcall(channel_subsystem_init); @@ -1020,6 +1029,7 @@ static int __init channel_subsystem_init_sync(void) css_schedule_eval_all(); /* Wait for the evaluation of subchannels to finish. */ wait_event(css_eval_wq, atomic_read(&css_eval_scheduled) == 0); + flush_workqueue(cio_work_q); /* Wait for the subchannel type specific initialization to finish */ return bus_for_each_drv(&css_bus_type, NULL, NULL, css_settle); } -- cgit v1.2.3 From 879acca58a904c25487c89ab11e23eb556fb13d3 Mon Sep 17 00:00:00 2001 From: Sebastian Ott Date: Fri, 26 Feb 2010 22:37:25 +0100 Subject: [S390] cio: introduce cio_settle This patch introduces a proc file cio_settle. A write request to this file is blocked until all queued cio actions are handled. This will allow userspace to wait for pending work affecting device availability after changing cio_ignore or the hardware configuration. Signed-off-by: Sebastian Ott Signed-off-by: Martin Schwidefsky --- Documentation/s390/CommonIO | 6 ++++++ drivers/s390/cio/css.c | 47 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 5 deletions(-) (limited to 'drivers/s390/cio/css.c') diff --git a/Documentation/s390/CommonIO b/Documentation/s390/CommonIO index 339207d11d95..d378cba66456 100644 --- a/Documentation/s390/CommonIO +++ b/Documentation/s390/CommonIO @@ -87,6 +87,12 @@ Command line parameters compatibility, by the device number in hexadecimal (0xabcd or abcd). Device numbers given as 0xabcd will be interpreted as 0.0.abcd. +* /proc/cio_settle + + A write request to this file is blocked until all queued cio actions are + handled. This will allow userspace to wait for pending work affecting + device availability after changing cio_ignore or the hardware configuration. + * For some of the information present in the /proc filesystem in 2.4 (namely, /proc/subchannels and /proc/chpids), see driver-model.txt. Information formerly in /proc/irq_count is now in /proc/interrupts. diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c index 99fcf9d0ea14..366affcd9bbf 100644 --- a/drivers/s390/cio/css.c +++ b/drivers/s390/cio/css.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -1019,6 +1020,18 @@ static int css_settle(struct device_driver *drv, void *unused) return 0; } +static inline void css_complete_work(void) +{ + int ret; + + /* Wait for the evaluation of subchannels to finish. */ + wait_event(css_eval_wq, atomic_read(&css_eval_scheduled) == 0); + flush_workqueue(cio_work_q); + /* Wait for the subchannel type specific initialization to finish */ + ret = bus_for_each_drv(&css_bus_type, NULL, NULL, css_settle); +} + + /* * Wait for the initialization of devices to finish, to make sure we are * done with our setup if the search for the root device starts. @@ -1027,14 +1040,38 @@ static int __init channel_subsystem_init_sync(void) { /* Start initial subchannel evaluation. */ css_schedule_eval_all(); - /* Wait for the evaluation of subchannels to finish. */ - wait_event(css_eval_wq, atomic_read(&css_eval_scheduled) == 0); - flush_workqueue(cio_work_q); - /* Wait for the subchannel type specific initialization to finish */ - return bus_for_each_drv(&css_bus_type, NULL, NULL, css_settle); + css_complete_work(); + return 0; } subsys_initcall_sync(channel_subsystem_init_sync); +#ifdef CONFIG_PROC_FS +static ssize_t cio_settle_write(struct file *file, const char __user *buf, + size_t count, loff_t *ppos) +{ + /* Handle pending CRW's. */ + crw_wait_for_channel_report(); + css_complete_work(); + return count; +} + +static const struct file_operations cio_settle_proc_fops = { + .write = cio_settle_write, +}; + +static int __init cio_settle_init(void) +{ + struct proc_dir_entry *entry; + + entry = proc_create("cio_settle", S_IWUSR, NULL, + &cio_settle_proc_fops); + if (!entry) + return -ENOMEM; + return 0; +} +device_initcall(cio_settle_init); +#endif /*CONFIG_PROC_FS*/ + int sch_is_pseudo_sch(struct subchannel *sch) { return sch == to_css(sch->dev.parent)->pseudo_subchannel; -- cgit v1.2.3 From b4c707214c987da021d4d5c4ed54612cf73d80d6 Mon Sep 17 00:00:00 2001 From: Sebastian Ott Date: Fri, 26 Feb 2010 22:37:27 +0100 Subject: [S390] cio: make wait_events interruptible Make the potentially long blocking wait_event's used by the cio settle mechanism interruptible. Signed-off-by: Sebastian Ott Signed-off-by: Martin Schwidefsky --- drivers/s390/cio/css.c | 18 ++++++++++++------ drivers/s390/cio/css.h | 2 +- drivers/s390/cio/device.c | 11 ++++++++--- 3 files changed, 21 insertions(+), 10 deletions(-) (limited to 'drivers/s390/cio/css.c') diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c index 366affcd9bbf..169a27723c4f 100644 --- a/drivers/s390/cio/css.c +++ b/drivers/s390/cio/css.c @@ -1016,19 +1016,22 @@ static int css_settle(struct device_driver *drv, void *unused) struct css_driver *cssdrv = to_cssdriver(drv); if (cssdrv->settle) - cssdrv->settle(); + return cssdrv->settle(); return 0; } -static inline void css_complete_work(void) +static inline int css_complete_work(void) { int ret; /* Wait for the evaluation of subchannels to finish. */ - wait_event(css_eval_wq, atomic_read(&css_eval_scheduled) == 0); + ret = wait_event_interruptible(css_eval_wq, + atomic_read(&css_eval_scheduled) == 0); + if (ret) + return -EINTR; flush_workqueue(cio_work_q); /* Wait for the subchannel type specific initialization to finish */ - ret = bus_for_each_drv(&css_bus_type, NULL, NULL, css_settle); + return bus_for_each_drv(&css_bus_type, NULL, NULL, css_settle); } @@ -1049,10 +1052,13 @@ subsys_initcall_sync(channel_subsystem_init_sync); static ssize_t cio_settle_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { + int ret; + /* Handle pending CRW's. */ crw_wait_for_channel_report(); - css_complete_work(); - return count; + ret = css_complete_work(); + + return ret ? ret : count; } static const struct file_operations cio_settle_proc_fops = { diff --git a/drivers/s390/cio/css.h b/drivers/s390/cio/css.h index e05525d53ea5..325d813bb8e0 100644 --- a/drivers/s390/cio/css.h +++ b/drivers/s390/cio/css.h @@ -95,7 +95,7 @@ struct css_driver { int (*freeze)(struct subchannel *); int (*thaw) (struct subchannel *); int (*restore)(struct subchannel *); - void (*settle)(void); + int (*settle)(void); const char *name; }; diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c index 9c9ea45141af..6aa2f069c6be 100644 --- a/drivers/s390/cio/device.c +++ b/drivers/s390/cio/device.c @@ -158,11 +158,16 @@ static int io_subchannel_prepare(struct subchannel *sch) return 0; } -static void io_subchannel_settle(void) +static int io_subchannel_settle(void) { - wait_event(ccw_device_init_wq, - atomic_read(&ccw_device_init_count) == 0); + int ret; + + ret = wait_event_interruptible(ccw_device_init_wq, + atomic_read(&ccw_device_init_count) == 0); + if (ret) + return -EINTR; flush_workqueue(cio_work_q); + return 0; } static struct css_driver io_subchannel_driver = { -- cgit v1.2.3 From 0d01bb89220490763d89571d27e7ee3f13f9b372 Mon Sep 17 00:00:00 2001 From: Sebastian Ott Date: Fri, 26 Feb 2010 22:37:29 +0100 Subject: [S390] cio: trigger subchannel event at resume time ccw_device_pm_restore: trigger subchannel event to better handle changes to the subchannel device. Signed-off-by: Sebastian Ott Signed-off-by: Martin Schwidefsky --- drivers/s390/cio/css.c | 2 +- drivers/s390/cio/css.h | 1 + drivers/s390/cio/device.c | 111 +++++++++++++++++++++++++--------------------- 3 files changed, 63 insertions(+), 51 deletions(-) (limited to 'drivers/s390/cio/css.c') diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c index 169a27723c4f..2769da54f2b9 100644 --- a/drivers/s390/cio/css.c +++ b/drivers/s390/cio/css.c @@ -1020,7 +1020,7 @@ static int css_settle(struct device_driver *drv, void *unused) return 0; } -static inline int css_complete_work(void) +int css_complete_work(void) { int ret; diff --git a/drivers/s390/cio/css.h b/drivers/s390/cio/css.h index 325d813bb8e0..7e37886de231 100644 --- a/drivers/s390/cio/css.h +++ b/drivers/s390/cio/css.h @@ -146,6 +146,7 @@ extern struct channel_subsystem *channel_subsystems[]; /* Helper functions to build lists for the slow path. */ void css_schedule_eval(struct subchannel_id schid); void css_schedule_eval_all(void); +int css_complete_work(void); int sch_is_pseudo_sch(struct subchannel *); struct schib; diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c index c7b2b7b26b8b..c6abb75c4615 100644 --- a/drivers/s390/cio/device.c +++ b/drivers/s390/cio/device.c @@ -1400,6 +1400,12 @@ static int io_subchannel_sch_event(struct subchannel *sch, int process) rc = 0; goto out_unlock; case IO_SCH_VERIFY: + if (cdev->private->flags.resuming == 1) { + if (cio_enable_subchannel(sch, (u32)(addr_t)sch)) { + ccw_device_set_notoper(cdev); + break; + } + } /* Trigger path verification. */ io_subchannel_verify(sch); rc = 0; @@ -1438,7 +1444,8 @@ static int io_subchannel_sch_event(struct subchannel *sch, int process) break; case IO_SCH_UNREG_ATTACH: /* Unregister ccw device. */ - ccw_device_unregister(cdev); + if (!cdev->private->flags.resuming) + ccw_device_unregister(cdev); break; default: break; @@ -1447,7 +1454,8 @@ static int io_subchannel_sch_event(struct subchannel *sch, int process) switch (action) { case IO_SCH_ORPH_UNREG: case IO_SCH_UNREG: - css_sch_device_unregister(sch); + if (!cdev || !cdev->private->flags.resuming) + css_sch_device_unregister(sch); break; case IO_SCH_ORPH_ATTACH: case IO_SCH_UNREG_ATTACH: @@ -1769,20 +1777,36 @@ static void __ccw_device_pm_restore(struct ccw_device *cdev) { struct subchannel *sch = to_subchannel(cdev->dev.parent); - if (cio_is_console(sch->schid)) - goto out; + spin_lock_irq(sch->lock); + if (cio_is_console(sch->schid)) { + cio_enable_subchannel(sch, (u32)(addr_t)sch); + goto out_unlock; + } /* * While we were sleeping, devices may have gone or become * available again. Kick re-detection. */ - spin_lock_irq(sch->lock); cdev->private->flags.resuming = 1; + css_schedule_eval(sch->schid); + spin_unlock_irq(sch->lock); + css_complete_work(); + + /* cdev may have been moved to a different subchannel. */ + sch = to_subchannel(cdev->dev.parent); + spin_lock_irq(sch->lock); + if (cdev->private->state != DEV_STATE_ONLINE && + cdev->private->state != DEV_STATE_OFFLINE) + goto out_unlock; + ccw_device_recognition(cdev); spin_unlock_irq(sch->lock); wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev) || cdev->private->state == DEV_STATE_DISCONNECTED); -out: + spin_lock_irq(sch->lock); + +out_unlock: cdev->private->flags.resuming = 0; + spin_unlock_irq(sch->lock); } static int resume_handle_boxed(struct ccw_device *cdev) @@ -1806,40 +1830,31 @@ static int resume_handle_disc(struct ccw_device *cdev) static int ccw_device_pm_restore(struct device *dev) { struct ccw_device *cdev = to_ccwdev(dev); - struct subchannel *sch = to_subchannel(cdev->dev.parent); - int ret = 0, cm_enabled; + struct subchannel *sch; + int ret = 0; __ccw_device_pm_restore(cdev); + sch = to_subchannel(cdev->dev.parent); spin_lock_irq(sch->lock); - if (cio_is_console(sch->schid)) { - cio_enable_subchannel(sch, (u32)(addr_t)sch); - spin_unlock_irq(sch->lock); + if (cio_is_console(sch->schid)) goto out_restore; - } - cdev->private->flags.donotify = 0; + /* check recognition results */ switch (cdev->private->state) { case DEV_STATE_OFFLINE: + case DEV_STATE_ONLINE: + cdev->private->flags.donotify = 0; break; case DEV_STATE_BOXED: ret = resume_handle_boxed(cdev); - spin_unlock_irq(sch->lock); if (ret) - goto out; + goto out_unlock; goto out_restore; - case DEV_STATE_DISCONNECTED: - goto out_disc_unlock; default: - goto out_unreg_unlock; - } - /* check if the device id has changed */ - if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) { - CIO_MSG_EVENT(0, "resume: sch 0.%x.%04x: failed (devno " - "changed from %04x to %04x)\n", - sch->schid.ssid, sch->schid.sch_no, - cdev->private->dev_id.devno, - sch->schib.pmcw.dev); - goto out_unreg_unlock; + ret = resume_handle_disc(cdev); + if (ret) + goto out_unlock; + goto out_restore; } /* check if the device type has changed */ if (!ccw_device_test_sense_data(cdev)) { @@ -1848,24 +1863,30 @@ static int ccw_device_pm_restore(struct device *dev) ret = -ENODEV; goto out_unlock; } - if (!cdev->online) { - ret = 0; + if (!cdev->online) goto out_unlock; - } - ret = ccw_device_online(cdev); - if (ret) - goto out_disc_unlock; - cm_enabled = cdev->private->cmb != NULL; + if (ccw_device_online(cdev)) { + ret = resume_handle_disc(cdev); + if (ret) + goto out_unlock; + goto out_restore; + } spin_unlock_irq(sch->lock); - wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); - if (cdev->private->state != DEV_STATE_ONLINE) { - spin_lock_irq(sch->lock); - goto out_disc_unlock; + spin_lock_irq(sch->lock); + + if (ccw_device_notify(cdev, CIO_OPER) == NOTIFY_BAD) { + ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); + ret = -ENODEV; + goto out_unlock; } - if (cm_enabled) { + + /* reenable cmf, if needed */ + if (cdev->private->cmb) { + spin_unlock_irq(sch->lock); ret = ccw_set_cmf(cdev, 1); + spin_lock_irq(sch->lock); if (ret) { CIO_MSG_EVENT(2, "resume: cdev 0.%x.%04x: cmf failed " "(rc=%d)\n", cdev->private->dev_id.ssid, @@ -1875,21 +1896,11 @@ static int ccw_device_pm_restore(struct device *dev) } out_restore: + spin_unlock_irq(sch->lock); if (cdev->online && cdev->drv && cdev->drv->restore) ret = cdev->drv->restore(cdev); -out: return ret; -out_disc_unlock: - ret = resume_handle_disc(cdev); - spin_unlock_irq(sch->lock); - if (ret) - return ret; - goto out_restore; - -out_unreg_unlock: - ccw_device_sched_todo(cdev, CDEV_TODO_UNREG_EVAL); - ret = -ENODEV; out_unlock: spin_unlock_irq(sch->lock); return ret; -- cgit v1.2.3