Skip to content

Commit

Permalink
HID: intel-ish-hid: use async resume function
Browse files Browse the repository at this point in the history
ISH IPC driver uses asynchronous workqueue to do resume now, but there is
a potential timing issue: when child devices resume before bus driver, it
will cause child devices resume failed and cannot be recovered until
reboot. The current implementation in this case do wait for IPC to resume
but fail to accommodate for a case when there is no ISH reboot and soft
resume is taking time. This issue is apparent on Tiger Lake platform with
5.11.13 kernel when doing suspend to idle then resume(s0ix) test. To
resolve this issue, we change ISHTP HID client to use asynchronous resume
callback too. In the asynchronous resume callback, it waits for the ISHTP
resume done event, and then notify ISHTP HID client link ready.

Signed-off-by: Ye Xiang <[email protected]>
Acked-by: Srinivas Pandruvada <[email protected]>
Signed-off-by: Jiri Kosina <[email protected]>
  • Loading branch information
yeapa authored and Jiri Kosina committed Jul 15, 2021
1 parent df04fbe commit e48bf29
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
15 changes: 14 additions & 1 deletion drivers/hid/intel-ish-hid/ishtp-hid-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,17 @@ static void hid_ishtp_cl_reset_handler(struct work_struct *work)
}
}

static void hid_ishtp_cl_resume_handler(struct work_struct *work)
{
struct ishtp_cl_data *client_data = container_of(work, struct ishtp_cl_data, resume_work);
struct ishtp_cl *hid_ishtp_cl = client_data->hid_ishtp_cl;

if (ishtp_wait_resume(ishtp_get_ishtp_device(hid_ishtp_cl))) {
client_data->suspended = false;
wake_up_interruptible(&client_data->ishtp_resume_wait);
}
}

ishtp_print_log ishtp_hid_print_trace;

/**
Expand Down Expand Up @@ -822,6 +833,8 @@ static int hid_ishtp_cl_probe(struct ishtp_cl_device *cl_device)
init_waitqueue_head(&client_data->ishtp_resume_wait);

INIT_WORK(&client_data->work, hid_ishtp_cl_reset_handler);
INIT_WORK(&client_data->resume_work, hid_ishtp_cl_resume_handler);


ishtp_hid_print_trace = ishtp_trace_callback(cl_device);

Expand Down Expand Up @@ -921,7 +934,7 @@ static int hid_ishtp_cl_resume(struct device *device)

hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__,
hid_ishtp_cl);
client_data->suspended = false;
schedule_work(&client_data->resume_work);
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions drivers/hid/intel-ish-hid/ishtp-hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ struct ishtp_cl_data {
int multi_packet_cnt;

struct work_struct work;
struct work_struct resume_work;
struct ishtp_cl_device *cl_device;
};

Expand Down
29 changes: 22 additions & 7 deletions drivers/hid/intel-ish-hid/ishtp/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,6 @@ static int ishtp_cl_device_resume(struct device *dev)
if (!device)
return 0;

/*
* When ISH needs hard reset, it is done asynchrnously, hence bus
* resume will be called before full ISH resume
*/
if (device->ishtp_dev->resume_flag)
return 0;

driver = to_ishtp_cl_driver(dev->driver);
if (driver && driver->driver.pm) {
if (driver->driver.pm->resume)
Expand Down Expand Up @@ -849,6 +842,28 @@ struct device *ishtp_device(struct ishtp_cl_device *device)
}
EXPORT_SYMBOL(ishtp_device);

/**
* ishtp_wait_resume() - Wait for IPC resume
*
* Wait for IPC resume
*
* Return: resume complete or not
*/
bool ishtp_wait_resume(struct ishtp_device *dev)
{
/* 50ms to get resume response */
#define WAIT_FOR_RESUME_ACK_MS 50

/* Waiting to get resume response */
if (dev->resume_flag)
wait_event_interruptible_timeout(dev->resume_wait,
!dev->resume_flag,
msecs_to_jiffies(WAIT_FOR_RESUME_ACK_MS));

return (!dev->resume_flag);
}
EXPORT_SYMBOL_GPL(ishtp_wait_resume);

/**
* ishtp_get_pci_device() - Return PCI device dev pointer
* This interface is used to return PCI device pointer
Expand Down
2 changes: 2 additions & 0 deletions include/linux/intel-ish-client-if.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ int ishtp_register_event_cb(struct ishtp_cl_device *device,

/* Get the device * from ishtp device instance */
struct device *ishtp_device(struct ishtp_cl_device *cl_device);
/* wait for IPC resume */
bool ishtp_wait_resume(struct ishtp_device *dev);
/* Trace interface for clients */
ishtp_print_log ishtp_trace_callback(struct ishtp_cl_device *cl_device);
/* Get device pointer of PCI device for DMA acces */
Expand Down

0 comments on commit e48bf29

Please sign in to comment.