mei: allow clients on bus to communicate in remove callback
authorAlexander Usyskin <alexander.usyskin@intel.com>
Sat, 6 Feb 2021 14:43:21 +0000 (16:43 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 6 Feb 2021 14:48:11 +0000 (15:48 +0100)
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 <alexander.usyskin@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Link: https://lore.kernel.org/r/20210206144325.25682-2-tomas.winkler@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/mei/bus.c
drivers/misc/mei/client.c
drivers/misc/mei/init.c
drivers/misc/mei/mei_dev.h

index 2907db260fba5ead002155992ac513e0fca3104a..34fb5e541fe5fb1a3969f08814d60a31e1a58a71 100644 (file)
@@ -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;
        }
@@ -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;
        }
index beb6cdff20fb35c5f53ec014b01fc5ed5906aa36..d3f060dce4a6013b7168df28a79231d3be7e21bf 100644 (file)
@@ -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;
index bcee77768b91762566ff238e6a5c6308dd9994aa..5c8cb679b997629e9913112391d2e57673df4bc3 100644 (file)
@@ -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);
 
index 8c395bfdf6f37404f00b6d250d510f24b3301684..585a6f615bf83f79cc27426d6190df274fee98f0 100644 (file)
@@ -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
 };