Commit 7b942b4b authored by Julian Wiedmann's avatar Julian Wiedmann Committed by Vasily Gorbik

s390/qdio: consistently restore the IRQ handler

For rolling back after an error, qdio_establish() calls qdio_shutdown().
If the error occurs early enough, then the qdio_irq's state still is
QDIO_IRQ_STATE_INACTIVE and qdio_shutdown() does nothing.

But at _any_ point where qdio_establish() bails out in this way,
qdio_setup_irq() will have already replaced the IRQ handler. This then
won't be restored after an early error, and the device can end up being
returned to the device driver with qdio's IRQ handler still installed.

Slightly reorder qdio_setup_irq() so we can be 100% sure that the IRQ
handler was replaced. Then fix the bug in qdio_establish() by calling a
helper that rolls back only the IRQ handler modification.

Also use the new helper in qdio_shutdown() to keep things in sync, and
slightly clean up the locking while doing so.
This makes minor semantical changes, but holding setup_mutex gives us
sufficient leeway to eg. pull qdio_shutdown_thinint() outside of the
ccwdev lock's scope.

Fixes: 779e6e1c ("[S390] qdio: new qdio driver.")
Signed-off-by: default avatarJulian Wiedmann <jwi@linux.ibm.com>
Reviewed-by: default avatarBenjamin Block <bblock@linux.ibm.com>
Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
parent de267a7c
...@@ -389,6 +389,7 @@ int qdio_setup_get_ssqd(struct qdio_irq *irq_ptr, ...@@ -389,6 +389,7 @@ int qdio_setup_get_ssqd(struct qdio_irq *irq_ptr,
struct subchannel_id *schid, struct subchannel_id *schid,
struct qdio_ssqd_desc *data); struct qdio_ssqd_desc *data);
int qdio_setup_irq(struct qdio_irq *irq_ptr, struct qdio_initialize *init_data); int qdio_setup_irq(struct qdio_irq *irq_ptr, struct qdio_initialize *init_data);
void qdio_shutdown_irq(struct qdio_irq *irq);
void qdio_print_subchannel_info(struct qdio_irq *irq_ptr); void qdio_print_subchannel_info(struct qdio_irq *irq_ptr);
void qdio_release_memory(struct qdio_irq *irq_ptr); void qdio_release_memory(struct qdio_irq *irq_ptr);
int qdio_setup_init(void); int qdio_setup_init(void);
......
...@@ -1154,35 +1154,27 @@ int qdio_shutdown(struct ccw_device *cdev, int how) ...@@ -1154,35 +1154,27 @@ int qdio_shutdown(struct ccw_device *cdev, int how)
/* cleanup subchannel */ /* cleanup subchannel */
spin_lock_irq(get_ccwdev_lock(cdev)); spin_lock_irq(get_ccwdev_lock(cdev));
qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
if (how & QDIO_FLAG_CLEANUP_USING_CLEAR) if (how & QDIO_FLAG_CLEANUP_USING_CLEAR)
rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP); rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
else else
/* default behaviour is halt */ /* default behaviour is halt */
rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP); rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
spin_unlock_irq(get_ccwdev_lock(cdev));
if (rc) { if (rc) {
DBF_ERROR("%4x SHUTD ERR", irq_ptr->schid.sch_no); DBF_ERROR("%4x SHUTD ERR", irq_ptr->schid.sch_no);
DBF_ERROR("rc:%4d", rc); DBF_ERROR("rc:%4d", rc);
goto no_cleanup; goto no_cleanup;
} }
qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
spin_unlock_irq(get_ccwdev_lock(cdev));
wait_event_interruptible_timeout(cdev->private->wait_q, wait_event_interruptible_timeout(cdev->private->wait_q,
irq_ptr->state == QDIO_IRQ_STATE_INACTIVE || irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
irq_ptr->state == QDIO_IRQ_STATE_ERR, irq_ptr->state == QDIO_IRQ_STATE_ERR,
10 * HZ); 10 * HZ);
spin_lock_irq(get_ccwdev_lock(cdev));
no_cleanup: no_cleanup:
qdio_shutdown_thinint(irq_ptr); qdio_shutdown_thinint(irq_ptr);
qdio_shutdown_irq(irq_ptr);
/* restore interrupt handler */
if ((void *)cdev->handler == (void *)qdio_int_handler) {
cdev->handler = irq_ptr->orig_handler;
cdev->private->intparm = 0;
}
spin_unlock_irq(get_ccwdev_lock(cdev));
qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE); qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
mutex_unlock(&irq_ptr->setup_mutex); mutex_unlock(&irq_ptr->setup_mutex);
...@@ -1352,8 +1344,8 @@ int qdio_establish(struct ccw_device *cdev, ...@@ -1352,8 +1344,8 @@ int qdio_establish(struct ccw_device *cdev,
rc = qdio_establish_thinint(irq_ptr); rc = qdio_establish_thinint(irq_ptr);
if (rc) { if (rc) {
qdio_shutdown_irq(irq_ptr);
mutex_unlock(&irq_ptr->setup_mutex); mutex_unlock(&irq_ptr->setup_mutex);
qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
return rc; return rc;
} }
...@@ -1371,8 +1363,8 @@ int qdio_establish(struct ccw_device *cdev, ...@@ -1371,8 +1363,8 @@ int qdio_establish(struct ccw_device *cdev,
if (rc) { if (rc) {
DBF_ERROR("%4x est IO ERR", irq_ptr->schid.sch_no); DBF_ERROR("%4x est IO ERR", irq_ptr->schid.sch_no);
DBF_ERROR("rc:%4x", rc); DBF_ERROR("rc:%4x", rc);
qdio_shutdown_irq(irq_ptr);
mutex_unlock(&irq_ptr->setup_mutex); mutex_unlock(&irq_ptr->setup_mutex);
qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
return rc; return rc;
} }
......
...@@ -491,6 +491,12 @@ int qdio_setup_irq(struct qdio_irq *irq_ptr, struct qdio_initialize *init_data) ...@@ -491,6 +491,12 @@ int qdio_setup_irq(struct qdio_irq *irq_ptr, struct qdio_initialize *init_data)
/* qdr, qib, sls, slsbs, slibs, sbales are filled now */ /* qdr, qib, sls, slsbs, slibs, sbales are filled now */
/* set our IRQ handler */
spin_lock_irq(get_ccwdev_lock(cdev));
irq_ptr->orig_handler = cdev->handler;
cdev->handler = qdio_int_handler;
spin_unlock_irq(get_ccwdev_lock(cdev));
/* get qdio commands */ /* get qdio commands */
ciw = ccw_device_get_ciw(cdev, CIW_TYPE_EQUEUE); ciw = ccw_device_get_ciw(cdev, CIW_TYPE_EQUEUE);
if (!ciw) { if (!ciw) {
...@@ -506,12 +512,18 @@ int qdio_setup_irq(struct qdio_irq *irq_ptr, struct qdio_initialize *init_data) ...@@ -506,12 +512,18 @@ int qdio_setup_irq(struct qdio_irq *irq_ptr, struct qdio_initialize *init_data)
} }
irq_ptr->aqueue = *ciw; irq_ptr->aqueue = *ciw;
/* set new interrupt handler */ return 0;
}
void qdio_shutdown_irq(struct qdio_irq *irq)
{
struct ccw_device *cdev = irq->cdev;
/* restore IRQ handler */
spin_lock_irq(get_ccwdev_lock(cdev)); spin_lock_irq(get_ccwdev_lock(cdev));
irq_ptr->orig_handler = cdev->handler; cdev->handler = irq->orig_handler;
cdev->handler = qdio_int_handler; cdev->private->intparm = 0;
spin_unlock_irq(get_ccwdev_lock(cdev)); spin_unlock_irq(get_ccwdev_lock(cdev));
return 0;
} }
void qdio_print_subchannel_info(struct qdio_irq *irq_ptr) void qdio_print_subchannel_info(struct qdio_irq *irq_ptr)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment