Skip to content

Commit

Permalink
mei: allow clients on bus to communicate in remove callback
Browse files Browse the repository at this point in the history
Introduce new intermediate state to allow the clients on the bus
to communicate with the firmware from the remove handler.
This is to enable to perform a clean shutdown.

Signed-off-by: Alexander Usyskin <[email protected]>
Signed-off-by: Tomas Winkler <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
ausyskin authored and gregkh committed Feb 6, 2021
1 parent 37f1cda commit 36edb14
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions drivers/misc/mei/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, u8 vtag,
bus = cl->dev;

mutex_lock(&bus->device_lock);
if (bus->dev_state != MEI_DEV_ENABLED) {
if (bus->dev_state != MEI_DEV_ENABLED &&
bus->dev_state != MEI_DEV_POWERING_DOWN) {
rets = -ENODEV;
goto out;
}
Expand Down Expand Up @@ -128,7 +129,8 @@ ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length, u8 *vtag,
bus = cl->dev;

mutex_lock(&bus->device_lock);
if (bus->dev_state != MEI_DEV_ENABLED) {
if (bus->dev_state != MEI_DEV_ENABLED &&
bus->dev_state != MEI_DEV_POWERING_DOWN) {
rets = -ENODEV;
goto out;
}
Expand Down
3 changes: 2 additions & 1 deletion drivers/misc/mei/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,8 @@ int mei_cl_disconnect(struct mei_cl *cl)
return 0;
}

if (dev->dev_state == MEI_DEV_POWER_DOWN) {
if (dev->dev_state == MEI_DEV_POWERING_DOWN ||
dev->dev_state == MEI_DEV_POWER_DOWN) {
cl_dbg(dev, cl, "Device is powering down, don't bother with disconnection\n");
mei_cl_set_disconnected(cl);
return 0;
Expand Down
5 changes: 4 additions & 1 deletion drivers/misc/mei/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,12 @@ void mei_stop(struct mei_device *dev)
dev_dbg(dev->dev, "stopping the device.\n");

mutex_lock(&dev->device_lock);
mei_set_devstate(dev, MEI_DEV_POWER_DOWN);
mei_set_devstate(dev, MEI_DEV_POWERING_DOWN);
mutex_unlock(&dev->device_lock);
mei_cl_bus_remove_devices(dev);
mutex_lock(&dev->device_lock);
mei_set_devstate(dev, MEI_DEV_POWER_DOWN);
mutex_unlock(&dev->device_lock);

mei_cancel_work(dev);

Expand Down
1 change: 1 addition & 0 deletions drivers/misc/mei/mei_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ enum mei_dev_state {
MEI_DEV_ENABLED,
MEI_DEV_RESETTING,
MEI_DEV_DISABLED,
MEI_DEV_POWERING_DOWN,
MEI_DEV_POWER_DOWN,
MEI_DEV_POWER_UP
};
Expand Down

0 comments on commit 36edb14

Please sign in to comment.