/** * report_bad_packet() - Report bad packets * @hid_ishtp_cl: Client instance to get stats * @recv_buf: Raw received host interface message * @cur_pos: Current position index in payload * @payload_len: Length of payload expected * * Dumps error in case bad packet is received
*/ staticvoid report_bad_packet(struct ishtp_cl *hid_ishtp_cl, void *recv_buf,
size_t cur_pos, size_t payload_len)
{ struct hostif_msg *recv_msg = recv_buf; struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl);
/** * process_recv() - Received and parse incoming packet * @hid_ishtp_cl: Client instance to get stats * @recv_buf: Raw received host interface message * @data_len: length of the message * * Parse the incoming packet. If it is a response packet then it will update * per instance flags and wake up the caller waiting to for the response.
*/ staticvoid process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf,
size_t data_len)
{ struct hostif_msg *recv_msg; unsignedchar *payload; struct device_info *dev_info; int i, j;
size_t payload_len, total_len, cur_pos, raw_len, msg_len; int report_type; struct report_list *reports_list; struct report *report;
size_t report_len; struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); int curr_hid_dev = client_data->cur_hid_dev; struct ishtp_hid_data *hid_data = NULL; struct hid_device *hid = NULL;
do { if (cur_pos + sizeof(struct hostif_msg) > total_len) {
dev_err(cl_data_to_dev(client_data), "[hid-ish]: error, received %u which is less than data header %u\n",
(unsignedint)data_len,
(unsignedint)sizeof(struct hostif_msg_hdr));
++client_data->bad_recv_cnt;
ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl)); break;
}
case HOSTIF_GET_HID_DESCRIPTOR: if ((!(recv_msg->hdr.command & ~CMD_MASK) ||
client_data->init_done)) {
++client_data->bad_recv_cnt;
report_bad_packet(hid_ishtp_cl, recv_msg,
cur_pos,
payload_len);
ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl)); break;
} if (!client_data->hid_descr[curr_hid_dev])
client_data->hid_descr[curr_hid_dev] =
devm_kmalloc(cl_data_to_dev(client_data),
payload_len, GFP_KERNEL); if (client_data->hid_descr[curr_hid_dev]) {
memcpy(client_data->hid_descr[curr_hid_dev],
payload, payload_len);
client_data->hid_descr_size[curr_hid_dev] =
payload_len;
client_data->hid_descr_done = true;
}
wake_up_interruptible(&client_data->init_wait);
break;
case HOSTIF_GET_REPORT_DESCRIPTOR: if ((!(recv_msg->hdr.command & ~CMD_MASK) ||
client_data->init_done)) {
++client_data->bad_recv_cnt;
report_bad_packet(hid_ishtp_cl, recv_msg,
cur_pos,
payload_len);
ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl)); break;
} if (!client_data->report_descr[curr_hid_dev])
client_data->report_descr[curr_hid_dev] =
devm_kmalloc(cl_data_to_dev(client_data),
payload_len, GFP_KERNEL); if (client_data->report_descr[curr_hid_dev]) {
memcpy(client_data->report_descr[curr_hid_dev],
payload,
payload_len);
client_data->report_descr_size[curr_hid_dev] =
payload_len;
client_data->report_descr_done = true;
}
wake_up_interruptible(&client_data->init_wait);
break;
case HOSTIF_GET_FEATURE_REPORT:
report_type = HID_FEATURE_REPORT; goto do_get_report;
case HOSTIF_GET_INPUT_REPORT:
report_type = HID_INPUT_REPORT;
do_get_report: /* Get index of device that matches this id */ for (i = 0; i < client_data->num_hid_devices; ++i) { if (recv_msg->hdr.device_id ==
client_data->hid_devices[i].dev_id) {
hid = client_data->hid_sensor_hubs[i]; if (!hid) break;
case HOSTIF_SET_FEATURE_REPORT: /* Get index of device that matches this id */ for (i = 0; i < client_data->num_hid_devices; ++i) { if (recv_msg->hdr.device_id ==
client_data->hid_devices[i].dev_id) if (client_data->hid_sensor_hubs[i]) {
ishtp_hid_wakeup(
client_data->hid_sensor_hubs[
i]); break;
}
} break;
case HOSTIF_PUBLISH_INPUT_REPORT:
report_type = HID_INPUT_REPORT; for (i = 0; i < client_data->num_hid_devices; ++i) if (recv_msg->hdr.device_id ==
client_data->hid_devices[i].dev_id) if (client_data->hid_sensor_hubs[i])
hid_input_report(
client_data->hid_sensor_hubs[
i],
report_type, payload,
payload_len, 0); break;
/** * ish_cl_event_cb() - bus driver callback for incoming message/packet * @device: Pointer to the ishtp client device for which this message * is targeted * * Remove the packet from the list and process the message by calling * process_recv
*/ staticvoid ish_cl_event_cb(struct ishtp_cl_device *device)
{ struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(device); struct ishtp_cl_rb *rb_in_proc;
size_t r_length;
if (!hid_ishtp_cl) return;
while ((rb_in_proc = ishtp_cl_rx_get_rb(hid_ishtp_cl)) != NULL) { if (!rb_in_proc->buffer.data) return;
r_length = rb_in_proc->buf_idx;
/* decide what to do with received data */
process_recv(hid_ishtp_cl, rb_in_proc->buffer.data, r_length);
ishtp_cl_io_rb_recycle(rb_in_proc);
}
}
/** * hid_ishtp_set_feature() - send request to ISH FW to set a feature request * @hid: hid device instance for this request * @buf: feature buffer * @len: Length of feature buffer * @report_id: Report id for the feature set request * * This is called from hid core .request() callback. This function doesn't wait * for response.
*/ void hid_ishtp_set_feature(struct hid_device *hid, char *buf, unsignedint len, int report_id)
{ struct ishtp_hid_data *hid_data = hid->driver_data; struct ishtp_cl_data *client_data = hid_data->client_data; struct hostif_msg *msg = (struct hostif_msg *)buf; int rv; int i;
/** * hid_ishtp_get_report() - request to get feature/input report * @hid: hid device instance for this request * @report_id: Report id for the get request * @report_type: Report type for the this request * * This is called from hid core .request() callback. This function will send * request to FW and return without waiting for response.
*/ void hid_ishtp_get_report(struct hid_device *hid, int report_id, int report_type)
{ struct ishtp_hid_data *hid_data = hid->driver_data; struct ishtp_cl_data *client_data = hid_data->client_data; struct hostif_msg_to_sensor msg = {}; int rv; int i;
hid_ishtp_trace(client_data, "%s hid %p\n", __func__, hid);
rv = ishtp_hid_link_ready_wait(client_data); if (rv) {
hid_ishtp_trace(client_data, "%s hid %p link not ready\n",
__func__, hid); return;
}
msg.hdr.command = (report_type == HID_FEATURE_REPORT) ?
HOSTIF_GET_FEATURE_REPORT : HOSTIF_GET_INPUT_REPORT; for (i = 0; i < client_data->num_hid_devices; ++i) { if (hid == client_data->hid_sensor_hubs[i]) {
msg.hdr.device_id =
client_data->hid_devices[i].dev_id; break;
}
}
/** * ishtp_hid_link_ready_wait() - Wait for link ready * @client_data: client data instance * * If the transport link started suspend process, then wait, till either * resumed or timeout * * Return: 0 on success, non zero on error
*/ int ishtp_hid_link_ready_wait(struct ishtp_cl_data *client_data)
{ int rc;
if (client_data->suspended) {
hid_ishtp_trace(client_data, "wait for link ready\n");
rc = wait_event_interruptible_timeout(
client_data->ishtp_resume_wait,
!client_data->suspended,
5 * HZ);
if (rc == 0) {
hid_ishtp_trace(client_data, "link not ready\n"); return -EIO;
}
hid_ishtp_trace(client_data, "link ready\n");
}
return 0;
}
/** * ishtp_enum_enum_devices() - Enumerate hid devices * @hid_ishtp_cl: client instance * * Helper function to send request to firmware to enumerate HID devices * * Return: 0 on success, non zero on error
*/ staticint ishtp_enum_enum_devices(struct ishtp_cl *hid_ishtp_cl)
{ struct hostif_msg msg; struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); int retry_count; int rv;
/** * ishtp_get_hid_descriptor() - Get hid descriptor * @hid_ishtp_cl: client instance * @index: Index into the hid_descr array * * Helper function to send request to firmware get HID descriptor of a device * * Return: 0 on success, non zero on error
*/ staticint ishtp_get_hid_descriptor(struct ishtp_cl *hid_ishtp_cl, int index)
{ struct hostif_msg msg; struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); int rv;
if (!client_data->hid_descr_done) {
wait_event_interruptible_timeout(client_data->init_wait,
client_data->hid_descr_done,
3 * HZ); if (!client_data->hid_descr_done) {
dev_err(cl_data_to_dev(client_data), "[hid-ish]: timed out for hid_descr_done\n"); return -EIO;
}
/** * ishtp_get_report_descriptor() - Get report descriptor * @hid_ishtp_cl: client instance * @index: Index into the hid_descr array * * Helper function to send request to firmware get HID report descriptor of * a device * * Return: 0 on success, non zero on error
*/ staticint ishtp_get_report_descriptor(struct ishtp_cl *hid_ishtp_cl, int index)
{ struct hostif_msg msg; struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); int rv;
if (!client_data->report_descr_done)
wait_event_interruptible_timeout(client_data->init_wait,
client_data->report_descr_done,
3 * HZ); if (!client_data->report_descr_done) {
dev_err(cl_data_to_dev(client_data), "[hid-ish]: timed out for report descr\n"); return -EIO;
} if (!client_data->report_descr[index]) {
dev_err(cl_data_to_dev(client_data), "[hid-ish]: failed to alloc report descr\n"); return -ENOMEM;
}
return 0;
}
/** * hid_ishtp_cl_init() - Init function for ISHTP client * @hid_ishtp_cl: ISHTP client instance * @reset: true if called for init after reset * * This function complete the initializtion of the client. The summary of * processing: * - Send request to enumerate the hid clients * Get the HID descriptor for each enumearated device * Get report description of each device * Register each device wik hid core by calling ishtp_hid_probe * * Return: 0 on success, non zero on error
*/ staticint hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, bool reset)
{ struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); int i; int rv;
if (ishtp_wait_resume(ishtp_get_ishtp_device(hid_ishtp_cl))) {
client_data->suspended = false;
wake_up_interruptible(&client_data->ishtp_resume_wait);
} else {
hid_ishtp_trace(client_data, "hid client: wait for resume timed out");
dev_err(cl_data_to_dev(client_data), "wait for resume timed out");
}
}
ishtp_print_log ishtp_hid_print_trace;
/** * hid_ishtp_cl_probe() - ISHTP client driver probe * @cl_device: ISHTP client device instance * * This function gets called on device create on ISHTP bus * * Return: 0 on success, non zero on error
*/ staticint hid_ishtp_cl_probe(struct ishtp_cl_device *cl_device)
{ struct ishtp_cl *hid_ishtp_cl; struct ishtp_cl_data *client_data; int rv;
if (!cl_device) return -ENODEV;
client_data = devm_kzalloc(ishtp_device(cl_device), sizeof(*client_data),
GFP_KERNEL); if (!client_data) return -ENOMEM;
hid_ishtp_cl = ishtp_cl_allocate(cl_device); if (!hid_ishtp_cl) return -ENOMEM;
MODULE_DESCRIPTION("ISH ISHTP HID client driver"); /* Primary author */
MODULE_AUTHOR("Daniel Drubin "); /* * Several modification for multi instance support * suspend/resume and clean up
*/
MODULE_AUTHOR("Srinivas Pandruvada ");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.