Skip to content

Commit 3dc196e

Browse files
ausyskingregkh
authored andcommitted
mei: me: wait for power gating exit confirmation
Fix the hbm power gating state machine so it will wait till it receives confirmation interrupt for the PG_ISOLATION_EXIT message. In process of the suspend flow the devices first have to exit from the power gating state (runtime pm resume). If we do not handle the confirmation interrupt after sending PG_ISOLATION_EXIT message, we may receive it already after the suspend flow has changed the device state and interrupt will be interpreted as a spurious event, consequently link reset will be invoked which will prevent the device from completing the suspend flow kernel: [6603] mei_reset:136: mei_me 0000:00:16.0: powering down: end of reset kernel: [476] mei_me_irq_thread_handler:643: mei_me 0000:00:16.0: function called after ISR to handle the interrupt processing. kernel: mei_me 0000:00:16.0: FW not ready: resetting Cc: <stable@vger.kernel.org> raspberrypi#3.18+ Cc: Gabriele Mazzotta <gabriele.mzt@gmail.com> Link: https://bugzilla.kernel.org/show_bug.cgi?id=86241 Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=770397 Tested-by: Gabriele Mazzotta <gabriele.mzt@gmail.com> Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c241e9b commit 3dc196e

4 files changed

Lines changed: 80 additions & 5 deletions

File tree

‎drivers/misc/mei/client.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ void mei_host_client_init(struct work_struct *work)
714714
bool mei_hbuf_acquire(struct mei_device *dev)
715715
{
716716
if (mei_pg_state(dev) == MEI_PG_ON ||
717-
dev->pg_event == MEI_PG_EVENT_WAIT) {
717+
mei_pg_in_transition(dev)) {
718718
dev_dbg(dev->dev, "device is in pg\n");
719719
return false;
720720
}

‎drivers/misc/mei/hw-me.c‎

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,17 +663,46 @@ int mei_me_pg_exit_sync(struct mei_device *dev)
663663
mutex_lock(&dev->device_lock);
664664

665665
reply:
666-
if (dev->pg_event == MEI_PG_EVENT_RECEIVED)
667-
ret = mei_hbm_pg(dev, MEI_PG_ISOLATION_EXIT_RES_CMD);
666+
if (dev->pg_event != MEI_PG_EVENT_RECEIVED) {
667+
ret = -ETIME;
668+
goto out;
669+
}
670+
671+
dev->pg_event = MEI_PG_EVENT_INTR_WAIT;
672+
ret = mei_hbm_pg(dev, MEI_PG_ISOLATION_EXIT_RES_CMD);
673+
if (ret)
674+
return ret;
675+
676+
mutex_unlock(&dev->device_lock);
677+
wait_event_timeout(dev->wait_pg,
678+
dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED, timeout);
679+
mutex_lock(&dev->device_lock);
680+
681+
if (dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED)
682+
ret = 0;
668683
else
669684
ret = -ETIME;
670685

686+
out:
671687
dev->pg_event = MEI_PG_EVENT_IDLE;
672688
hw->pg_state = MEI_PG_OFF;
673689

674690
return ret;
675691
}
676692

693+
/**
694+
* mei_me_pg_in_transition - is device now in pg transition
695+
*
696+
* @dev: the device structure
697+
*
698+
* Return: true if in pg transition, false otherwise
699+
*/
700+
static bool mei_me_pg_in_transition(struct mei_device *dev)
701+
{
702+
return dev->pg_event >= MEI_PG_EVENT_WAIT &&
703+
dev->pg_event <= MEI_PG_EVENT_INTR_WAIT;
704+
}
705+
677706
/**
678707
* mei_me_pg_is_enabled - detect if PG is supported by HW
679708
*
@@ -704,6 +733,24 @@ static bool mei_me_pg_is_enabled(struct mei_device *dev)
704733
return false;
705734
}
706735

736+
/**
737+
* mei_me_pg_intr - perform pg processing in interrupt thread handler
738+
*
739+
* @dev: the device structure
740+
*/
741+
static void mei_me_pg_intr(struct mei_device *dev)
742+
{
743+
struct mei_me_hw *hw = to_me_hw(dev);
744+
745+
if (dev->pg_event != MEI_PG_EVENT_INTR_WAIT)
746+
return;
747+
748+
dev->pg_event = MEI_PG_EVENT_INTR_RECEIVED;
749+
hw->pg_state = MEI_PG_OFF;
750+
if (waitqueue_active(&dev->wait_pg))
751+
wake_up(&dev->wait_pg);
752+
}
753+
707754
/**
708755
* mei_me_irq_quick_handler - The ISR of the MEI device
709756
*
@@ -761,6 +808,8 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
761808
goto end;
762809
}
763810

811+
mei_me_pg_intr(dev);
812+
764813
/* check if we need to start the dev */
765814
if (!mei_host_is_ready(dev)) {
766815
if (mei_hw_is_ready(dev)) {
@@ -797,9 +846,10 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
797846
/*
798847
* During PG handshake only allowed write is the replay to the
799848
* PG exit message, so block calling write function
800-
* if the pg state is not idle
849+
* if the pg event is in PG handshake
801850
*/
802-
if (dev->pg_event == MEI_PG_EVENT_IDLE) {
851+
if (dev->pg_event != MEI_PG_EVENT_WAIT &&
852+
dev->pg_event != MEI_PG_EVENT_RECEIVED) {
803853
rets = mei_irq_write_handler(dev, &complete_list);
804854
dev->hbuf_is_ready = mei_hbuf_is_ready(dev);
805855
}
@@ -824,6 +874,7 @@ static const struct mei_hw_ops mei_me_hw_ops = {
824874
.hw_config = mei_me_hw_config,
825875
.hw_start = mei_me_hw_start,
826876

877+
.pg_in_transition = mei_me_pg_in_transition,
827878
.pg_is_enabled = mei_me_pg_is_enabled,
828879

829880
.intr_clear = mei_me_intr_clear,

‎drivers/misc/mei/hw-txe.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,18 @@ int mei_txe_aliveness_set_sync(struct mei_device *dev, u32 req)
301301
return 0;
302302
}
303303

304+
/**
305+
* mei_txe_pg_in_transition - is device now in pg transition
306+
*
307+
* @dev: the device structure
308+
*
309+
* Return: true if in pg transition, false otherwise
310+
*/
311+
static bool mei_txe_pg_in_transition(struct mei_device *dev)
312+
{
313+
return dev->pg_event == MEI_PG_EVENT_WAIT;
314+
}
315+
304316
/**
305317
* mei_txe_pg_is_enabled - detect if PG is supported by HW
306318
*
@@ -1138,6 +1150,7 @@ static const struct mei_hw_ops mei_txe_hw_ops = {
11381150
.hw_config = mei_txe_hw_config,
11391151
.hw_start = mei_txe_hw_start,
11401152

1153+
.pg_in_transition = mei_txe_pg_in_transition,
11411154
.pg_is_enabled = mei_txe_pg_is_enabled,
11421155

11431156
.intr_clear = mei_txe_intr_clear,

‎drivers/misc/mei/mei_dev.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ struct mei_cl {
276276
277277
* @fw_status : get fw status registers
278278
* @pg_state : power gating state of the device
279+
* @pg_in_transition : is device now in pg transition
279280
* @pg_is_enabled : is power gating enabled
280281
281282
* @intr_clear : clear pending interrupts
@@ -305,6 +306,7 @@ struct mei_hw_ops {
305306

306307
int (*fw_status)(struct mei_device *dev, struct mei_fw_status *fw_sts);
307308
enum mei_pg_state (*pg_state)(struct mei_device *dev);
309+
bool (*pg_in_transition)(struct mei_device *dev);
308310
bool (*pg_is_enabled)(struct mei_device *dev);
309311

310312
void (*intr_clear)(struct mei_device *dev);
@@ -349,11 +351,15 @@ struct mei_cl *mei_cl_bus_find_cl_by_uuid(struct mei_device *dev, uuid_le uuid);
349351
* @MEI_PG_EVENT_IDLE: the driver is not in power gating transition
350352
* @MEI_PG_EVENT_WAIT: the driver is waiting for a pg event to complete
351353
* @MEI_PG_EVENT_RECEIVED: the driver received pg event
354+
* @MEI_PG_EVENT_INTR_WAIT: the driver is waiting for a pg event interrupt
355+
* @MEI_PG_EVENT_INTR_RECEIVED: the driver received pg event interrupt
352356
*/
353357
enum mei_pg_event {
354358
MEI_PG_EVENT_IDLE,
355359
MEI_PG_EVENT_WAIT,
356360
MEI_PG_EVENT_RECEIVED,
361+
MEI_PG_EVENT_INTR_WAIT,
362+
MEI_PG_EVENT_INTR_RECEIVED,
357363
};
358364

359365
/**
@@ -670,6 +676,11 @@ static inline enum mei_pg_state mei_pg_state(struct mei_device *dev)
670676
return dev->ops->pg_state(dev);
671677
}
672678

679+
static inline bool mei_pg_in_transition(struct mei_device *dev)
680+
{
681+
return dev->ops->pg_in_transition(dev);
682+
}
683+
673684
static inline bool mei_pg_is_enabled(struct mei_device *dev)
674685
{
675686
return dev->ops->pg_is_enabled(dev);

0 commit comments

Comments
 (0)