Commit b950ac1d authored by Tomas Winkler's avatar Tomas Winkler Committed by Greg Kroah-Hartman

mei: don't get stuck in select during reset

Clear pending connection after hw reset but before hw start
and wake up the waiting task in poll. Signal POLLERR in select
when device went through reset.

Add wrapper mei_cl_is_connected for checking if
the device and client are connected.
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 20138d6c
...@@ -418,15 +418,23 @@ unsigned int mei_amthif_poll(struct mei_device *dev, ...@@ -418,15 +418,23 @@ unsigned int mei_amthif_poll(struct mei_device *dev,
struct file *file, poll_table *wait) struct file *file, poll_table *wait)
{ {
unsigned int mask = 0; unsigned int mask = 0;
mutex_unlock(&dev->device_lock);
poll_wait(file, &dev->iamthif_cl.wait, wait); poll_wait(file, &dev->iamthif_cl.wait, wait);
mutex_lock(&dev->device_lock); mutex_lock(&dev->device_lock);
if (dev->iamthif_state == MEI_IAMTHIF_READ_COMPLETE && if (!mei_cl_is_connected(&dev->iamthif_cl)) {
dev->iamthif_file_object == file) {
mask = POLLERR;
} else if (dev->iamthif_state == MEI_IAMTHIF_READ_COMPLETE &&
dev->iamthif_file_object == file) {
mask |= (POLLIN | POLLRDNORM); mask |= (POLLIN | POLLRDNORM);
dev_dbg(&dev->pdev->dev, "run next amthif cb\n"); dev_dbg(&dev->pdev->dev, "run next amthif cb\n");
mei_amthif_run_next_cmd(dev); mei_amthif_run_next_cmd(dev);
} }
mutex_unlock(&dev->device_lock);
return mask; return mask;
} }
......
...@@ -635,10 +635,7 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length) ...@@ -635,10 +635,7 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length)
dev = cl->dev; dev = cl->dev;
if (cl->state != MEI_FILE_CONNECTED) if (!mei_cl_is_connected(cl))
return -ENODEV;
if (dev->dev_state != MEI_DEV_ENABLED)
return -ENODEV; return -ENODEV;
if (cl->read_cb) { if (cl->read_cb) {
......
...@@ -84,6 +84,13 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl); ...@@ -84,6 +84,13 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl);
/* /*
* MEI input output function prototype * MEI input output function prototype
*/ */
static inline bool mei_cl_is_connected(struct mei_cl *cl)
{
return (cl->dev &&
cl->dev->dev_state == MEI_DEV_ENABLED &&
cl->state == MEI_FILE_CONNECTED);
}
bool mei_cl_is_other_connecting(struct mei_cl *cl); bool mei_cl_is_other_connecting(struct mei_cl *cl);
int mei_cl_disconnect(struct mei_cl *cl); int mei_cl_disconnect(struct mei_cl *cl);
int mei_cl_connect(struct mei_cl *cl, struct file *file); int mei_cl_connect(struct mei_cl *cl, struct file *file);
......
...@@ -149,12 +149,20 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled) ...@@ -149,12 +149,20 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
dev->hbm_state = MEI_HBM_IDLE; dev->hbm_state = MEI_HBM_IDLE;
if (dev->dev_state != MEI_DEV_INITIALIZING) { if (dev->dev_state != MEI_DEV_INITIALIZING) {
if (dev->dev_state != MEI_DEV_DISABLED && if (dev->dev_state != MEI_DEV_DISABLED &&
dev->dev_state != MEI_DEV_POWER_DOWN) dev->dev_state != MEI_DEV_POWER_DOWN)
dev->dev_state = MEI_DEV_RESETTING; dev->dev_state = MEI_DEV_RESETTING;
/* remove all waiting requests */
mei_cl_all_write_clear(dev);
mei_cl_all_disconnect(dev); mei_cl_all_disconnect(dev);
/* wake up all readings so they can be interrupted */
mei_cl_all_wakeup(dev);
/* remove entry if already in list */ /* remove entry if already in list */
dev_dbg(&dev->pdev->dev, "remove iamthif and wd from the file list.\n"); dev_dbg(&dev->pdev->dev, "remove iamthif and wd from the file list.\n");
mei_cl_unlink(&dev->wd_cl); mei_cl_unlink(&dev->wd_cl);
...@@ -195,11 +203,6 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled) ...@@ -195,11 +203,6 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
mei_hbm_start_req(dev); mei_hbm_start_req(dev);
/* wake up all readings so they can be interrupted */
mei_cl_all_wakeup(dev);
/* remove all waiting requests */
mei_cl_all_write_clear(dev);
} }
EXPORT_SYMBOL_GPL(mei_reset); EXPORT_SYMBOL_GPL(mei_reset);
......
...@@ -625,24 +625,32 @@ static unsigned int mei_poll(struct file *file, poll_table *wait) ...@@ -625,24 +625,32 @@ static unsigned int mei_poll(struct file *file, poll_table *wait)
unsigned int mask = 0; unsigned int mask = 0;
if (WARN_ON(!cl || !cl->dev)) if (WARN_ON(!cl || !cl->dev))
return mask; return POLLERR;
dev = cl->dev; dev = cl->dev;
mutex_lock(&dev->device_lock); mutex_lock(&dev->device_lock);
if (dev->dev_state != MEI_DEV_ENABLED) if (!mei_cl_is_connected(cl)) {
goto out; mask = POLLERR;
if (cl == &dev->iamthif_cl) {
mask = mei_amthif_poll(dev, file, wait);
goto out; goto out;
} }
mutex_unlock(&dev->device_lock); mutex_unlock(&dev->device_lock);
if (cl == &dev->iamthif_cl)
return mei_amthif_poll(dev, file, wait);
poll_wait(file, &cl->tx_wait, wait); poll_wait(file, &cl->tx_wait, wait);
mutex_lock(&dev->device_lock); mutex_lock(&dev->device_lock);
if (!mei_cl_is_connected(cl)) {
mask = POLLERR;
goto out;
}
if (MEI_WRITE_COMPLETE == cl->writing_state) if (MEI_WRITE_COMPLETE == cl->writing_state)
mask |= (POLLIN | POLLRDNORM); mask |= (POLLIN | POLLRDNORM);
......
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