From e19595fcabb5d09071b9ddb302be98715b77b1b9 Mon Sep 17 00:00:00 2001 From: Hyungwoo Yang Date: Mon, 4 Mar 2019 12:48:54 -0800 Subject: HID: intel-ish: enable raw interface to HID devices on ISH Raw interface is often used to update firmwares in HID devices. We are enabling the interface to support in-field firmware update for the HID devices attached to ISH. Signed-off-by: Hyungwoo Yang Acked-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina --- drivers/hid/intel-ish-hid/ishtp-hid-client.c | 37 +++++++++++++++++------- drivers/hid/intel-ish-hid/ishtp-hid.c | 43 ++++++++++++++++++++++++++-- drivers/hid/intel-ish-hid/ishtp-hid.h | 8 ++++++ 3 files changed, 74 insertions(+), 14 deletions(-) (limited to 'drivers/hid/intel-ish-hid') diff --git a/drivers/hid/intel-ish-hid/ishtp-hid-client.c b/drivers/hid/intel-ish-hid/ishtp-hid-client.c index 30fe0c5e6fad..58773a3b5150 100644 --- a/drivers/hid/intel-ish-hid/ishtp-hid-client.c +++ b/drivers/hid/intel-ish-hid/ishtp-hid-client.c @@ -69,13 +69,15 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, unsigned char *payload; struct device_info *dev_info; int i, j; - size_t payload_len, total_len, cur_pos; + size_t payload_len, total_len, cur_pos, raw_len; int report_type; struct report_list *reports_list; char *reports; size_t report_len; struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data; int curr_hid_dev = client_data->cur_hid_dev; + struct ishtp_hid_data *hid_data = NULL; + struct hid_device *hid = NULL; payload = recv_buf + sizeof(struct hostif_msg_hdr); total_len = data_len; @@ -219,18 +221,31 @@ 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) - if (client_data->hid_sensor_hubs[i]) { - hid_input_report( - client_data->hid_sensor_hubs[ - i], - report_type, payload, - payload_len, 0); - ishtp_hid_wakeup( - client_data->hid_sensor_hubs[ - i]); + client_data->hid_devices[i].dev_id) { + hid = client_data->hid_sensor_hubs[i]; + if (!hid) break; + + hid_data = hid->driver_data; + if (hid_data->raw_get_req) { + raw_len = + (hid_data->raw_buf_size < + payload_len) ? + hid_data->raw_buf_size : + payload_len; + + memcpy(hid_data->raw_buf, + payload, raw_len); + } else { + hid_input_report + (hid, report_type, + payload, payload_len, + 0); } + + ishtp_hid_wakeup(hid); + break; + } } break; diff --git a/drivers/hid/intel-ish-hid/ishtp-hid.c b/drivers/hid/intel-ish-hid/ishtp-hid.c index bc4c536f3c0d..5c7e127b0483 100644 --- a/drivers/hid/intel-ish-hid/ishtp-hid.c +++ b/drivers/hid/intel-ish-hid/ishtp-hid.c @@ -59,10 +59,46 @@ static void ishtp_hid_close(struct hid_device *hid) { } -static int ishtp_raw_request(struct hid_device *hdev, unsigned char reportnum, - __u8 *buf, size_t len, unsigned char rtype, int reqtype) +static int ishtp_raw_request(struct hid_device *hid, unsigned char reportnum, + __u8 *buf, size_t len, unsigned char rtype, + int reqtype) { - return 0; + struct ishtp_hid_data *hid_data = hid->driver_data; + char *ishtp_buf = NULL; + size_t ishtp_buf_len; + unsigned int header_size = sizeof(struct hostif_msg); + + if (rtype == HID_OUTPUT_REPORT) + return -EINVAL; + + hid_data->request_done = false; + switch (reqtype) { + case HID_REQ_GET_REPORT: + hid_data->raw_buf = buf; + hid_data->raw_buf_size = len; + hid_data->raw_get_req = true; + + hid_ishtp_get_report(hid, reportnum, rtype); + break; + case HID_REQ_SET_REPORT: + /* + * Spare 7 bytes for 64b accesses through + * get/put_unaligned_le64() + */ + ishtp_buf_len = len + header_size; + ishtp_buf = kzalloc(ishtp_buf_len + 7, GFP_KERNEL); + if (!ishtp_buf) + return -ENOMEM; + + memcpy(ishtp_buf + header_size, buf, len); + hid_ishtp_set_feature(hid, ishtp_buf, ishtp_buf_len, reportnum); + kfree(ishtp_buf); + break; + } + + hid_hw_wait(hid); + + return len; } /** @@ -87,6 +123,7 @@ static void ishtp_hid_request(struct hid_device *hid, struct hid_report *rep, hid_data->request_done = false; switch (reqtype) { case HID_REQ_GET_REPORT: + hid_data->raw_get_req = false; hid_ishtp_get_report(hid, rep->id, rep->type); break; case HID_REQ_SET_REPORT: diff --git a/drivers/hid/intel-ish-hid/ishtp-hid.h b/drivers/hid/intel-ish-hid/ishtp-hid.h index 1cd07a441cd4..40663639e43b 100644 --- a/drivers/hid/intel-ish-hid/ishtp-hid.h +++ b/drivers/hid/intel-ish-hid/ishtp-hid.h @@ -159,6 +159,9 @@ struct ishtp_cl_data { * @client_data: Link to the client instance * @hid_wait: Completion waitq * + * @raw_get_req: Flag indicating raw get request ongoing + * @raw_buf: raw request buffer filled on receiving get report + * @raw_buf_size: raw request buffer size * Used to tie hid hid->driver data to driver client instance */ struct ishtp_hid_data { @@ -166,6 +169,11 @@ struct ishtp_hid_data { bool request_done; struct ishtp_cl_data *client_data; wait_queue_head_t hid_wait; + + /* raw request */ + bool raw_get_req; + u8 *raw_buf; + size_t raw_buf_size; }; /* Interface functions between HID LL driver and ISH TP client */ -- cgit v1.2.3 From 6b3f75f75fdd225f8c5927b938c29bd24c21fc1b Mon Sep 17 00:00:00 2001 From: Hong Liu Date: Mon, 18 Mar 2019 12:14:19 -0700 Subject: HID: intel-ish-hid: Add match callback to ishtp bus type Currently we depend on the guid check in ishtp_cl_driver.probe to match the device and driver. However Linux device core first calls the match() callback to decide the matching of driver and device, and then does some preparation before calling the driver probe function. If we return error in the driver probe, it needs to tear down all the preparation work and retry with next driver. Adding the match callback can avoid the unnecessary entry into unmatched driver probe function for ishtp clients reported by FW. Signed-off-by: Hong Liu Signed-off-by: Jiri Kosina --- drivers/hid/intel-ish-hid/ishtp-hid-client.c | 5 +---- drivers/hid/intel-ish-hid/ishtp/bus.c | 21 +++++++++++++++++++++ drivers/hid/intel-ish-hid/ishtp/bus.h | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) (limited to 'drivers/hid/intel-ish-hid') diff --git a/drivers/hid/intel-ish-hid/ishtp-hid-client.c b/drivers/hid/intel-ish-hid/ishtp-hid-client.c index 58773a3b5150..b86290611a5f 100644 --- a/drivers/hid/intel-ish-hid/ishtp-hid-client.c +++ b/drivers/hid/intel-ish-hid/ishtp-hid-client.c @@ -803,10 +803,6 @@ static int hid_ishtp_cl_probe(struct ishtp_cl_device *cl_device) if (!cl_device) return -ENODEV; - if (!guid_equal(&hid_ishtp_guid, - &cl_device->fw_client->props.protocol_name)) - return -ENODEV; - client_data = devm_kzalloc(&cl_device->dev, sizeof(*client_data), GFP_KERNEL); if (!client_data) @@ -937,6 +933,7 @@ static const struct dev_pm_ops hid_ishtp_pm_ops = { static struct ishtp_cl_driver hid_ishtp_cl_driver = { .name = "ish-hid", + .guid = &hid_ishtp_guid, .probe = hid_ishtp_cl_probe, .remove = hid_ishtp_cl_remove, .reset = hid_ishtp_cl_reset, diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c b/drivers/hid/intel-ish-hid/ishtp/bus.c index d5f4b6438d86..6348fee8aadc 100644 --- a/drivers/hid/intel-ish-hid/ishtp/bus.c +++ b/drivers/hid/intel-ish-hid/ishtp/bus.c @@ -219,6 +219,26 @@ static int ishtp_cl_device_probe(struct device *dev) return driver->probe(device); } +/** + * ishtp_cl_bus_match() - Bus match() callback + * @dev: the device structure + * @drv: the driver structure + * + * This is a bus match callback, called when a new ishtp_cl_device is + * registered during ishtp bus client enumeration. Use the guid_t in + * drv and dev to decide whether they match or not. + * + * Return: 1 if dev & drv matches, 0 otherwise. + */ +static int ishtp_cl_bus_match(struct device *dev, struct device_driver *drv) +{ + struct ishtp_cl_device *device = to_ishtp_cl_device(dev); + struct ishtp_cl_driver *driver = to_ishtp_cl_driver(drv); + + return guid_equal(driver->guid, + &device->fw_client->props.protocol_name); +} + /** * ishtp_cl_device_remove() - Bus remove() callback * @dev: the device structure @@ -372,6 +392,7 @@ static struct bus_type ishtp_cl_bus_type = { .name = "ishtp", .dev_groups = ishtp_cl_dev_groups, .probe = ishtp_cl_device_probe, + .match = ishtp_cl_bus_match, .remove = ishtp_cl_device_remove, .pm = &ishtp_cl_bus_dev_pm_ops, .uevent = ishtp_cl_uevent, diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.h b/drivers/hid/intel-ish-hid/ishtp/bus.h index 4cf7ad586c37..c96e7fb42f01 100644 --- a/drivers/hid/intel-ish-hid/ishtp/bus.h +++ b/drivers/hid/intel-ish-hid/ishtp/bus.h @@ -64,6 +64,7 @@ struct ishtp_cl_device { struct ishtp_cl_driver { struct device_driver driver; const char *name; + const guid_t *guid; int (*probe)(struct ishtp_cl_device *dev); int (*remove)(struct ishtp_cl_device *dev); int (*reset)(struct ishtp_cl_device *dev); -- cgit v1.2.3 From 7ab2184246bd0b32e427ff60bfa07a2435011ce2 Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Mon, 18 Mar 2019 12:14:20 -0700 Subject: HID: intel-ish-hid: Hide members of struct ishtp_cl_device ISH clients don't need to access any field of struct ishtp_cl_device. To avoid this create an interface functions instead where it is required. In the case of ishtp_cl_allocate(), modify the parameters so that the clients don't have to dereference. Clients can also use tracing, here a new interface is added to get the common trace function pointer, instead of direct call. The new interface functions defined in one external header file, named intel-ish-client-if.h. This is the only header files all ISHTP clients must include. Signed-off-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina --- drivers/hid/intel-ish-hid/ishtp-hid-client.c | 56 ++++++++++++++++------------ drivers/hid/intel-ish-hid/ishtp-hid.c | 4 +- drivers/hid/intel-ish-hid/ishtp-hid.h | 2 +- drivers/hid/intel-ish-hid/ishtp/bus.c | 27 ++++++++++++++ drivers/hid/intel-ish-hid/ishtp/client.c | 4 +- drivers/hid/intel-ish-hid/ishtp/client.h | 2 +- include/linux/intel-ish-client-if.h | 18 +++++++++ 7 files changed, 84 insertions(+), 29 deletions(-) create mode 100644 include/linux/intel-ish-client-if.h (limited to 'drivers/hid/intel-ish-hid') diff --git a/drivers/hid/intel-ish-hid/ishtp-hid-client.c b/drivers/hid/intel-ish-hid/ishtp-hid-client.c index b86290611a5f..17d5bd4f52c1 100644 --- a/drivers/hid/intel-ish-hid/ishtp-hid-client.c +++ b/drivers/hid/intel-ish-hid/ishtp-hid-client.c @@ -15,6 +15,7 @@ #include #include +#include #include #include "ishtp/ishtp-dev.h" #include "ishtp/client.h" @@ -24,6 +25,8 @@ #define HID_CL_RX_RING_SIZE 32 #define HID_CL_TX_RING_SIZE 16 +#define cl_data_to_dev(client_data) ishtp_device(client_data->cl_device) + /** * report_bad_packets() - Report bad packets * @hid_ishtp_cl: Client instance to get stats @@ -39,7 +42,7 @@ static void report_bad_packet(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, struct hostif_msg *recv_msg = recv_buf; struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data; - dev_err(&client_data->cl_device->dev, "[hid-ish]: BAD packet %02X\n" + dev_err(cl_data_to_dev(client_data), "[hid-ish]: BAD packet %02X\n" "total_bad=%u cur_pos=%u\n" "[%02X %02X %02X %02X]\n" "payload_len=%u\n" @@ -85,7 +88,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, do { if (cur_pos + sizeof(struct hostif_msg) > total_len) { - dev_err(&client_data->cl_device->dev, + dev_err(cl_data_to_dev(client_data), "[hid-ish]: error, received %u which is less than data header %u\n", (unsigned int)data_len, (unsigned int)sizeof(struct hostif_msg_hdr)); @@ -124,12 +127,12 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, client_data->hid_dev_count = (unsigned int)*payload; if (!client_data->hid_devices) client_data->hid_devices = devm_kcalloc( - &client_data->cl_device->dev, + cl_data_to_dev(client_data), client_data->hid_dev_count, sizeof(struct device_info), GFP_KERNEL); if (!client_data->hid_devices) { - dev_err(&client_data->cl_device->dev, + dev_err(cl_data_to_dev(client_data), "Mem alloc failed for hid device info\n"); wake_up_interruptible(&client_data->init_wait); break; @@ -137,7 +140,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, for (i = 0; i < client_data->hid_dev_count; ++i) { if (1 + sizeof(struct device_info) * i >= payload_len) { - dev_err(&client_data->cl_device->dev, + dev_err(cl_data_to_dev(client_data), "[hid-ish]: [ENUM_DEVICES]: content size %zu is bigger than payload_len %zu\n", 1 + sizeof(struct device_info) * i, payload_len); @@ -172,7 +175,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, } if (!client_data->hid_descr[curr_hid_dev]) client_data->hid_descr[curr_hid_dev] = - devm_kmalloc(&client_data->cl_device->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], @@ -197,7 +200,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, } if (!client_data->report_descr[curr_hid_dev]) client_data->report_descr[curr_hid_dev] = - devm_kmalloc(&client_data->cl_device->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], @@ -516,12 +519,12 @@ static int ishtp_enum_enum_devices(struct ishtp_cl *hid_ishtp_cl) sizeof(struct hostif_msg)); } if (!client_data->enum_devices_done) { - dev_err(&client_data->cl_device->dev, + dev_err(cl_data_to_dev(client_data), "[hid-ish]: timed out waiting for enum_devices\n"); return -ETIMEDOUT; } if (!client_data->hid_devices) { - dev_err(&client_data->cl_device->dev, + dev_err(cl_data_to_dev(client_data), "[hid-ish]: failed to allocate HID dev structures\n"); return -ENOMEM; } @@ -564,13 +567,13 @@ static int ishtp_get_hid_descriptor(struct ishtp_cl *hid_ishtp_cl, int index) client_data->hid_descr_done, 3 * HZ); if (!client_data->hid_descr_done) { - dev_err(&client_data->cl_device->dev, + dev_err(cl_data_to_dev(client_data), "[hid-ish]: timed out for hid_descr_done\n"); return -EIO; } if (!client_data->hid_descr[index]) { - dev_err(&client_data->cl_device->dev, + dev_err(cl_data_to_dev(client_data), "[hid-ish]: allocation HID desc fail\n"); return -ENOMEM; } @@ -611,12 +614,12 @@ static int ishtp_get_report_descriptor(struct ishtp_cl *hid_ishtp_cl, client_data->report_descr_done, 3 * HZ); if (!client_data->report_descr_done) { - dev_err(&client_data->cl_device->dev, + 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(&client_data->cl_device->dev, + dev_err(cl_data_to_dev(client_data), "[hid-ish]: failed to alloc report descr\n"); return -ENOMEM; } @@ -646,12 +649,12 @@ static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset) int i; int rv; - dev_dbg(&client_data->cl_device->dev, "%s\n", __func__); + dev_dbg(cl_data_to_dev(client_data), "%s\n", __func__); hid_ishtp_trace(client_data, "%s reset flag: %d\n", __func__, reset); rv = ishtp_cl_link(hid_ishtp_cl, ISHTP_HOST_CLIENT_ID_ANY); if (rv) { - dev_err(&client_data->cl_device->dev, + dev_err(cl_data_to_dev(client_data), "ishtp_cl_link failed\n"); return -ENOMEM; } @@ -666,7 +669,7 @@ static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset) fw_client = ishtp_fw_cl_get_client(dev, &hid_ishtp_guid); if (!fw_client) { - dev_err(&client_data->cl_device->dev, + dev_err(cl_data_to_dev(client_data), "ish client uuid not found\n"); return -ENOENT; } @@ -676,7 +679,7 @@ static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset) rv = ishtp_cl_connect(hid_ishtp_cl); if (rv) { - dev_err(&client_data->cl_device->dev, + dev_err(cl_data_to_dev(client_data), "client connect fail\n"); goto err_cl_unlink; } @@ -707,7 +710,7 @@ static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset) if (!reset) { rv = ishtp_hid_probe(i, client_data); if (rv) { - dev_err(&client_data->cl_device->dev, + dev_err(cl_data_to_dev(client_data), "[hid-ish]: HID probe for #%u failed: %d\n", i, rv); goto err_cl_disconnect; @@ -763,7 +766,7 @@ static void hid_ishtp_cl_reset_handler(struct work_struct *work) hid_ishtp_cl_deinit(hid_ishtp_cl); - hid_ishtp_cl = ishtp_cl_allocate(cl_device->ishtp_dev); + hid_ishtp_cl = ishtp_cl_allocate(cl_device); if (!hid_ishtp_cl) return; @@ -777,15 +780,17 @@ static void hid_ishtp_cl_reset_handler(struct work_struct *work) rv = hid_ishtp_cl_init(hid_ishtp_cl, 1); if (!rv) break; - dev_err(&client_data->cl_device->dev, "Retry reset init\n"); + dev_err(cl_data_to_dev(client_data), "Retry reset init\n"); } if (rv) { - dev_err(&client_data->cl_device->dev, "Reset Failed\n"); + dev_err(cl_data_to_dev(client_data), "Reset Failed\n"); hid_ishtp_trace(client_data, "%s Failed hid_ishtp_cl %p\n", __func__, hid_ishtp_cl); } } +void (*hid_print_trace)(void *dev, const char *format, ...); + /** * hid_ishtp_cl_probe() - ISHTP client driver probe * @cl_device: ISHTP client device instance @@ -803,12 +808,13 @@ static int hid_ishtp_cl_probe(struct ishtp_cl_device *cl_device) if (!cl_device) return -ENODEV; - client_data = devm_kzalloc(&cl_device->dev, sizeof(*client_data), + 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->ishtp_dev); + hid_ishtp_cl = ishtp_cl_allocate(cl_device); if (!hid_ishtp_cl) return -ENOMEM; @@ -822,6 +828,8 @@ static int hid_ishtp_cl_probe(struct ishtp_cl_device *cl_device) INIT_WORK(&client_data->work, hid_ishtp_cl_reset_handler); + hid_print_trace = ishtp_trace_callback(cl_device); + rv = hid_ishtp_cl_init(hid_ishtp_cl, 0); if (rv) { ishtp_cl_free(hid_ishtp_cl); @@ -848,7 +856,7 @@ static int hid_ishtp_cl_remove(struct ishtp_cl_device *cl_device) hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__, hid_ishtp_cl); - dev_dbg(&cl_device->dev, "%s\n", __func__); + dev_dbg(ishtp_device(cl_device), "%s\n", __func__); hid_ishtp_cl->state = ISHTP_CL_DISCONNECTING; ishtp_cl_disconnect(hid_ishtp_cl); ishtp_put_device(cl_device); diff --git a/drivers/hid/intel-ish-hid/ishtp-hid.c b/drivers/hid/intel-ish-hid/ishtp-hid.c index 5c7e127b0483..95a5b87d9105 100644 --- a/drivers/hid/intel-ish-hid/ishtp-hid.c +++ b/drivers/hid/intel-ish-hid/ishtp-hid.c @@ -14,6 +14,7 @@ */ #include +#include #include #include "ishtp/client.h" #include "ishtp-hid.h" @@ -241,7 +242,8 @@ int ishtp_hid_probe(unsigned int cur_hid_dev, hid->ll_driver = &ishtp_hid_ll_driver; hid->bus = BUS_INTEL_ISHTP; - hid->dev.parent = &client_data->cl_device->dev; + hid->dev.parent = ishtp_device(client_data->cl_device); + hid->version = le16_to_cpu(ISH_HID_VERSION); hid->vendor = le16_to_cpu(client_data->hid_devices[cur_hid_dev].vid); hid->product = le16_to_cpu(client_data->hid_devices[cur_hid_dev].pid); diff --git a/drivers/hid/intel-ish-hid/ishtp-hid.h b/drivers/hid/intel-ish-hid/ishtp-hid.h index 40663639e43b..8af44e855a49 100644 --- a/drivers/hid/intel-ish-hid/ishtp-hid.h +++ b/drivers/hid/intel-ish-hid/ishtp-hid.h @@ -24,7 +24,7 @@ #define IS_RESPONSE 0x80 /* Used to dump to Linux trace buffer, if enabled */ -#define hid_ishtp_trace(client, ...) \ +#define hid_ishtp_trace(client, ...) \ client->cl_device->ishtp_dev->print_log(\ client->cl_device->ishtp_dev, __VA_ARGS__) diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c b/drivers/hid/intel-ish-hid/ishtp/bus.c index 6348fee8aadc..308853eab91c 100644 --- a/drivers/hid/intel-ish-hid/ishtp/bus.c +++ b/drivers/hid/intel-ish-hid/ishtp/bus.c @@ -827,6 +827,33 @@ int ishtp_use_dma_transfer(void) return ishtp_use_dma; } +/** + * ishtp_device() - Return device pointer + * + * This interface is used to return device pointer from ishtp_cl_device + * instance. + * + * Return: device *. + */ +struct device *ishtp_device(struct ishtp_cl_device *device) +{ + return &device->dev; +} +EXPORT_SYMBOL(ishtp_device); + +/** + * ishtp_trace_callback() - Return trace callback + * + * This interface is used to return trace callback function pointer. + * + * Return: void *. + */ +void *ishtp_trace_callback(struct ishtp_cl_device *cl_device) +{ + return cl_device->ishtp_dev->print_log; +} +EXPORT_SYMBOL(ishtp_trace_callback); + /** * ishtp_bus_register() - Function to register bus * diff --git a/drivers/hid/intel-ish-hid/ishtp/client.c b/drivers/hid/intel-ish-hid/ishtp/client.c index faeccdb1475b..760e48a368a8 100644 --- a/drivers/hid/intel-ish-hid/ishtp/client.c +++ b/drivers/hid/intel-ish-hid/ishtp/client.c @@ -126,7 +126,7 @@ static void ishtp_cl_init(struct ishtp_cl *cl, struct ishtp_device *dev) * * Return: The allocated client instance or NULL on failure */ -struct ishtp_cl *ishtp_cl_allocate(struct ishtp_device *dev) +struct ishtp_cl *ishtp_cl_allocate(struct ishtp_cl_device *cl_device) { struct ishtp_cl *cl; @@ -134,7 +134,7 @@ struct ishtp_cl *ishtp_cl_allocate(struct ishtp_device *dev) if (!cl) return NULL; - ishtp_cl_init(cl, dev); + ishtp_cl_init(cl, cl_device->ishtp_dev); return cl; } EXPORT_SYMBOL(ishtp_cl_allocate); diff --git a/drivers/hid/intel-ish-hid/ishtp/client.h b/drivers/hid/intel-ish-hid/ishtp/client.h index e0df3eb611e6..992625891a6c 100644 --- a/drivers/hid/intel-ish-hid/ishtp/client.h +++ b/drivers/hid/intel-ish-hid/ishtp/client.h @@ -170,7 +170,7 @@ static inline bool ishtp_cl_cmp_id(const struct ishtp_cl *cl1, } /* exported functions from ISHTP under client management scope */ -struct ishtp_cl *ishtp_cl_allocate(struct ishtp_device *dev); +struct ishtp_cl *ishtp_cl_allocate(struct ishtp_cl_device *cl_device); void ishtp_cl_free(struct ishtp_cl *cl); int ishtp_cl_link(struct ishtp_cl *cl, int id); void ishtp_cl_unlink(struct ishtp_cl *cl); diff --git a/include/linux/intel-ish-client-if.h b/include/linux/intel-ish-client-if.h new file mode 100644 index 000000000000..11e285172735 --- /dev/null +++ b/include/linux/intel-ish-client-if.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Intel ISH client Interface definitions + * + * Copyright (c) 2019, Intel Corporation. + */ + +#ifndef _INTEL_ISH_CLIENT_IF_H_ +#define _INTEL_ISH_CLIENT_IF_H_ + +struct ishtp_cl_device; + +/* Get the device * from ishtp device instance */ +struct device *ishtp_device(struct ishtp_cl_device *cl_device); +/* Trace interface for clients */ +void *ishtp_trace_callback(struct ishtp_cl_device *cl_device); + +#endif /* _INTEL_ISH_CLIENT_IF_H_ */ -- cgit v1.2.3 From c2012ec06204b1c92c7ed683ac36d53472a37be4 Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Mon, 18 Mar 2019 12:14:21 -0700 Subject: HID: intel-ish-hid: Simplify ishtp_cl_link() All callers will only use ISHTP_HOST_CLIENT_ID_ANY, so get rid of option to pass this additional id. Signed-off-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina --- drivers/hid/intel-ish-hid/ishtp-hid-client.c | 2 +- drivers/hid/intel-ish-hid/ishtp/client.c | 14 ++++---------- drivers/hid/intel-ish-hid/ishtp/client.h | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) (limited to 'drivers/hid/intel-ish-hid') diff --git a/drivers/hid/intel-ish-hid/ishtp-hid-client.c b/drivers/hid/intel-ish-hid/ishtp-hid-client.c index 17d5bd4f52c1..94a00ffeb09b 100644 --- a/drivers/hid/intel-ish-hid/ishtp-hid-client.c +++ b/drivers/hid/intel-ish-hid/ishtp-hid-client.c @@ -652,7 +652,7 @@ static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset) dev_dbg(cl_data_to_dev(client_data), "%s\n", __func__); hid_ishtp_trace(client_data, "%s reset flag: %d\n", __func__, reset); - rv = ishtp_cl_link(hid_ishtp_cl, ISHTP_HOST_CLIENT_ID_ANY); + rv = ishtp_cl_link(hid_ishtp_cl); if (rv) { dev_err(cl_data_to_dev(client_data), "ishtp_cl_link failed\n"); diff --git a/drivers/hid/intel-ish-hid/ishtp/client.c b/drivers/hid/intel-ish-hid/ishtp/client.c index 760e48a368a8..657b46dcefa6 100644 --- a/drivers/hid/intel-ish-hid/ishtp/client.c +++ b/drivers/hid/intel-ish-hid/ishtp/client.c @@ -168,9 +168,6 @@ EXPORT_SYMBOL(ishtp_cl_free); /** * ishtp_cl_link() - Reserve a host id and link the client instance * @cl: client device instance - * @id: host client id to use. It can be ISHTP_HOST_CLIENT_ID_ANY if any - * id from the available can be used - * * * This allocates a single bit in the hostmap. This function will make sure * that not many client sessions are opened at the same time. Once allocated @@ -179,11 +176,11 @@ EXPORT_SYMBOL(ishtp_cl_free); * * Return: 0 or error code on failure */ -int ishtp_cl_link(struct ishtp_cl *cl, int id) +int ishtp_cl_link(struct ishtp_cl *cl) { struct ishtp_device *dev; - unsigned long flags, flags_cl; - int ret = 0; + unsigned long flags, flags_cl; + int id, ret = 0; if (WARN_ON(!cl || !cl->dev)) return -EINVAL; @@ -197,10 +194,7 @@ int ishtp_cl_link(struct ishtp_cl *cl, int id) goto unlock_dev; } - /* If Id is not assigned get one*/ - if (id == ISHTP_HOST_CLIENT_ID_ANY) - id = find_first_zero_bit(dev->host_clients_map, - ISHTP_CLIENTS_MAX); + id = find_first_zero_bit(dev->host_clients_map, ISHTP_CLIENTS_MAX); if (id >= ISHTP_CLIENTS_MAX) { spin_unlock_irqrestore(&dev->device_lock, flags); diff --git a/drivers/hid/intel-ish-hid/ishtp/client.h b/drivers/hid/intel-ish-hid/ishtp/client.h index 992625891a6c..afa8b1f521d0 100644 --- a/drivers/hid/intel-ish-hid/ishtp/client.h +++ b/drivers/hid/intel-ish-hid/ishtp/client.h @@ -172,7 +172,7 @@ static inline bool ishtp_cl_cmp_id(const struct ishtp_cl *cl1, /* exported functions from ISHTP under client management scope */ struct ishtp_cl *ishtp_cl_allocate(struct ishtp_cl_device *cl_device); void ishtp_cl_free(struct ishtp_cl *cl); -int ishtp_cl_link(struct ishtp_cl *cl, int id); +int ishtp_cl_link(struct ishtp_cl *cl); void ishtp_cl_unlink(struct ishtp_cl *cl); int ishtp_cl_disconnect(struct ishtp_cl *cl); int ishtp_cl_connect(struct ishtp_cl *cl); -- cgit v1.2.3 From e00a864f976ab2646929ae82aa65ccd05a4f7539 Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Mon, 18 Mar 2019 12:14:22 -0700 Subject: HID: intel-ish-hid: Move driver registry functions Move the driver registry with the ishtp bus to the common interface file, which clients can include. Also rename __ishtp_cl_driver_register() to ishtp_cl_driver_register() and removed define for ishtp_cl_driver_register. Signed-off-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina --- drivers/hid/intel-ish-hid/ishtp-hid-client.c | 2 +- drivers/hid/intel-ish-hid/ishtp/bus.c | 8 ++++---- drivers/hid/intel-ish-hid/ishtp/bus.h | 27 +-------------------------- include/linux/intel-ish-client-if.h | 25 +++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 31 deletions(-) (limited to 'drivers/hid/intel-ish-hid') diff --git a/drivers/hid/intel-ish-hid/ishtp-hid-client.c b/drivers/hid/intel-ish-hid/ishtp-hid-client.c index 94a00ffeb09b..4afb39713213 100644 --- a/drivers/hid/intel-ish-hid/ishtp-hid-client.c +++ b/drivers/hid/intel-ish-hid/ishtp-hid-client.c @@ -953,7 +953,7 @@ static int __init ish_hid_init(void) int rv; /* Register ISHTP client device driver with ISHTP Bus */ - rv = ishtp_cl_driver_register(&hid_ishtp_cl_driver); + rv = ishtp_cl_driver_register(&hid_ishtp_cl_driver, THIS_MODULE); return rv; diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c b/drivers/hid/intel-ish-hid/ishtp/bus.c index 308853eab91c..95a97534fcda 100644 --- a/drivers/hid/intel-ish-hid/ishtp/bus.c +++ b/drivers/hid/intel-ish-hid/ishtp/bus.c @@ -485,7 +485,7 @@ static void ishtp_bus_remove_device(struct ishtp_cl_device *device) } /** - * __ishtp_cl_driver_register() - Client driver register + * ishtp_cl_driver_register() - Client driver register * @driver: the client driver instance * @owner: Owner of this driver module * @@ -494,8 +494,8 @@ static void ishtp_bus_remove_device(struct ishtp_cl_device *device) * * Return: Return value of driver_register or -ENODEV if not ready */ -int __ishtp_cl_driver_register(struct ishtp_cl_driver *driver, - struct module *owner) +int ishtp_cl_driver_register(struct ishtp_cl_driver *driver, + struct module *owner) { int err; @@ -512,7 +512,7 @@ int __ishtp_cl_driver_register(struct ishtp_cl_driver *driver, return 0; } -EXPORT_SYMBOL(__ishtp_cl_driver_register); +EXPORT_SYMBOL(ishtp_cl_driver_register); /** * ishtp_cl_driver_unregister() - Client driver unregister diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.h b/drivers/hid/intel-ish-hid/ishtp/bus.h index c96e7fb42f01..4aed195719de 100644 --- a/drivers/hid/intel-ish-hid/ishtp/bus.h +++ b/drivers/hid/intel-ish-hid/ishtp/bus.h @@ -17,6 +17,7 @@ #include #include +#include struct ishtp_cl; struct ishtp_cl_device; @@ -52,26 +53,6 @@ struct ishtp_cl_device { void (*event_cb)(struct ishtp_cl_device *device); }; -/** - * struct ishtp_cl_device - ISHTP device handle - * @driver: driver instance on a bus - * @name: Name of the device for probe - * @probe: driver callback for device probe - * @remove: driver callback on device removal - * - * Client drivers defines to get probed/removed for ISHTP client device. - */ -struct ishtp_cl_driver { - struct device_driver driver; - const char *name; - const guid_t *guid; - int (*probe)(struct ishtp_cl_device *dev); - int (*remove)(struct ishtp_cl_device *dev); - int (*reset)(struct ishtp_cl_device *dev); - const struct dev_pm_ops *pm; -}; - - int ishtp_bus_new_client(struct ishtp_device *dev); void ishtp_remove_all_clients(struct ishtp_device *dev); int ishtp_cl_device_bind(struct ishtp_cl *cl); @@ -105,12 +86,6 @@ void ishtp_get_device(struct ishtp_cl_device *); void ishtp_set_drvdata(struct ishtp_cl_device *cl_device, void *data); void *ishtp_get_drvdata(struct ishtp_cl_device *cl_device); -int __ishtp_cl_driver_register(struct ishtp_cl_driver *driver, - struct module *owner); -#define ishtp_cl_driver_register(driver) \ - __ishtp_cl_driver_register(driver, THIS_MODULE) -void ishtp_cl_driver_unregister(struct ishtp_cl_driver *driver); - int ishtp_register_event_cb(struct ishtp_cl_device *device, void (*read_cb)(struct ishtp_cl_device *)); int ishtp_fw_cl_by_uuid(struct ishtp_device *dev, const guid_t *cuuid); diff --git a/include/linux/intel-ish-client-if.h b/include/linux/intel-ish-client-if.h index 11e285172735..abc0b8122f07 100644 --- a/include/linux/intel-ish-client-if.h +++ b/include/linux/intel-ish-client-if.h @@ -10,6 +10,31 @@ struct ishtp_cl_device; +/** + * struct ishtp_cl_device - ISHTP device handle + * @driver: driver instance on a bus + * @name: Name of the device for probe + * @probe: driver callback for device probe + * @remove: driver callback on device removal + * + * Client drivers defines to get probed/removed for ISHTP client device. + */ +struct ishtp_cl_driver { + struct device_driver driver; + const char *name; + const guid_t *guid; + int (*probe)(struct ishtp_cl_device *dev); + int (*remove)(struct ishtp_cl_device *dev); + int (*reset)(struct ishtp_cl_device *dev); + const struct dev_pm_ops *pm; +}; + +int ishtp_cl_driver_register(struct ishtp_cl_driver *driver, + struct module *owner); +void ishtp_cl_driver_unregister(struct ishtp_cl_driver *driver); +int ishtp_register_event_cb(struct ishtp_cl_device *device, + void (*read_cb)(struct ishtp_cl_device *)); + /* Get the device * from ishtp device instance */ struct device *ishtp_device(struct ishtp_cl_device *cl_device); /* Trace interface for clients */ -- cgit v1.2.3 From 9a0bc1a63780baedcefb8c84ab436d3d8fde37e5 Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Mon, 18 Mar 2019 12:14:23 -0700 Subject: HID: intel-ish-hid: Store ishtp_cl_device instance in device Store ishtp_cl_device pointer in device struct private data. In this way we can get ishtp_cl_device * from device struct pointer. Signed-off-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina --- drivers/hid/intel-ish-hid/ishtp/bus.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/hid/intel-ish-hid') diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c b/drivers/hid/intel-ish-hid/ishtp/bus.c index 95a97534fcda..2ca65864192f 100644 --- a/drivers/hid/intel-ish-hid/ishtp/bus.c +++ b/drivers/hid/intel-ish-hid/ishtp/bus.c @@ -466,6 +466,7 @@ static struct ishtp_cl_device *ishtp_bus_add_device(struct ishtp_device *dev, } ishtp_device_ready = true; + dev_set_drvdata(&device->dev, device); return device; } -- cgit v1.2.3 From 8991eb309e1faa04ce1ca950d89dd36e3c8584cd Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Mon, 18 Mar 2019 12:14:24 -0700 Subject: HID: intel-ish-hid: Move the common functions from client.h Move the interface functions in client.h to common include. These are already abstracted well to use as is. Also move any associated structures used by these functions. Signed-off-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina --- drivers/hid/intel-ish-hid/ishtp/client.h | 24 --------------- drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h | 26 ---------------- include/linux/intel-ish-client-if.h | 48 +++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 50 deletions(-) (limited to 'drivers/hid/intel-ish-hid') diff --git a/drivers/hid/intel-ish-hid/ishtp/client.h b/drivers/hid/intel-ish-hid/ishtp/client.h index afa8b1f521d0..6ed00947d6bc 100644 --- a/drivers/hid/intel-ish-hid/ishtp/client.h +++ b/drivers/hid/intel-ish-hid/ishtp/client.h @@ -19,15 +19,6 @@ #include #include "ishtp-dev.h" -/* Client state */ -enum cl_state { - ISHTP_CL_INITIALIZING = 0, - ISHTP_CL_CONNECTING, - ISHTP_CL_CONNECTED, - ISHTP_CL_DISCONNECTING, - ISHTP_CL_DISCONNECTED -}; - /* Tx and Rx ring size */ #define CL_DEF_RX_RING_SIZE 2 #define CL_DEF_TX_RING_SIZE 2 @@ -169,19 +160,4 @@ static inline bool ishtp_cl_cmp_id(const struct ishtp_cl *cl1, (cl1->fw_client_id == cl2->fw_client_id); } -/* exported functions from ISHTP under client management scope */ -struct ishtp_cl *ishtp_cl_allocate(struct ishtp_cl_device *cl_device); -void ishtp_cl_free(struct ishtp_cl *cl); -int ishtp_cl_link(struct ishtp_cl *cl); -void ishtp_cl_unlink(struct ishtp_cl *cl); -int ishtp_cl_disconnect(struct ishtp_cl *cl); -int ishtp_cl_connect(struct ishtp_cl *cl); -int ishtp_cl_send(struct ishtp_cl *cl, uint8_t *buf, size_t length); -int ishtp_cl_flush_queues(struct ishtp_cl *cl); - -/* exported functions from ISHTP client buffer management scope */ -int ishtp_cl_io_rb_recycle(struct ishtp_cl_rb *rb); -bool ishtp_cl_tx_empty(struct ishtp_cl *cl); -struct ishtp_cl_rb *ishtp_cl_rx_get_rb(struct ishtp_cl *cl); - #endif /* _ISHTP_CLIENT_H_ */ diff --git a/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h b/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h index e54ce1ef27dd..e0a320e67a41 100644 --- a/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h +++ b/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h @@ -79,32 +79,6 @@ struct ishtp_fw_client { uint8_t client_id; }; -/** - * struct ishtp_msg_data - ISHTP message data struct - * @size: Size of data in the *data - * @data: Pointer to data - */ -struct ishtp_msg_data { - uint32_t size; - unsigned char *data; -}; - -/* - * struct ishtp_cl_rb - request block structure - * @list: Link to list members - * @cl: ISHTP client instance - * @buffer: message header - * @buf_idx: Index into buffer - * @read_time: unused at this time - */ -struct ishtp_cl_rb { - struct list_head list; - struct ishtp_cl *cl; - struct ishtp_msg_data buffer; - unsigned long buf_idx; - unsigned long read_time; -}; - /* * Control info for IPC messages ISHTP/IPC sending FIFO - * list with inline data buffer diff --git a/include/linux/intel-ish-client-if.h b/include/linux/intel-ish-client-if.h index abc0b8122f07..7ce172f656f8 100644 --- a/include/linux/intel-ish-client-if.h +++ b/include/linux/intel-ish-client-if.h @@ -9,6 +9,16 @@ #define _INTEL_ISH_CLIENT_IF_H_ struct ishtp_cl_device; +struct ishtp_cl; + +/* Client state */ +enum cl_state { + ISHTP_CL_INITIALIZING = 0, + ISHTP_CL_CONNECTING, + ISHTP_CL_CONNECTED, + ISHTP_CL_DISCONNECTING, + ISHTP_CL_DISCONNECTED +}; /** * struct ishtp_cl_device - ISHTP device handle @@ -29,6 +39,32 @@ struct ishtp_cl_driver { const struct dev_pm_ops *pm; }; +/** + * struct ishtp_msg_data - ISHTP message data struct + * @size: Size of data in the *data + * @data: Pointer to data + */ +struct ishtp_msg_data { + uint32_t size; + unsigned char *data; +}; + +/* + * struct ishtp_cl_rb - request block structure + * @list: Link to list members + * @cl: ISHTP client instance + * @buffer: message header + * @buf_idx: Index into buffer + * @read_time: unused at this time + */ +struct ishtp_cl_rb { + struct list_head list; + struct ishtp_cl *cl; + struct ishtp_msg_data buffer; + unsigned long buf_idx; + unsigned long read_time; +}; + int ishtp_cl_driver_register(struct ishtp_cl_driver *driver, struct module *owner); void ishtp_cl_driver_unregister(struct ishtp_cl_driver *driver); @@ -40,4 +76,16 @@ struct device *ishtp_device(struct ishtp_cl_device *cl_device); /* Trace interface for clients */ void *ishtp_trace_callback(struct ishtp_cl_device *cl_device); +struct ishtp_cl *ishtp_cl_allocate(struct ishtp_cl_device *cl_device); +void ishtp_cl_free(struct ishtp_cl *cl); +int ishtp_cl_link(struct ishtp_cl *cl); +void ishtp_cl_unlink(struct ishtp_cl *cl); +int ishtp_cl_disconnect(struct ishtp_cl *cl); +int ishtp_cl_connect(struct ishtp_cl *cl); +int ishtp_cl_send(struct ishtp_cl *cl, uint8_t *buf, size_t length); +int ishtp_cl_flush_queues(struct ishtp_cl *cl); +int ishtp_cl_io_rb_recycle(struct ishtp_cl_rb *rb); +bool ishtp_cl_tx_empty(struct ishtp_cl *cl); +struct ishtp_cl_rb *ishtp_cl_rx_get_rb(struct ishtp_cl *cl); + #endif /* _INTEL_ISH_CLIENT_IF_H_ */ -- cgit v1.2.3 From 51cbc7079ecae545be93c137edeb7453d28b9ec9 Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Mon, 18 Mar 2019 12:14:25 -0700 Subject: HID: intel-ish-hid: Add interface functions for struct ishtp_cl Instead of directly accessing members of struct ishtp_cl, create interface functions to access them. Signed-off-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina --- drivers/hid/intel-ish-hid/ishtp/client.c | 42 ++++++++++++++++++++++++++++++++ include/linux/intel-ish-client-if.h | 7 ++++++ 2 files changed, 49 insertions(+) (limited to 'drivers/hid/intel-ish-hid') diff --git a/drivers/hid/intel-ish-hid/ishtp/client.c b/drivers/hid/intel-ish-hid/ishtp/client.c index 657b46dcefa6..b7ac5e3b1e82 100644 --- a/drivers/hid/intel-ish-hid/ishtp/client.c +++ b/drivers/hid/intel-ish-hid/ishtp/client.c @@ -1063,3 +1063,45 @@ void recv_ishtp_cl_msg_dma(struct ishtp_device *dev, void *msg, eoi: return; } + +void *ishtp_get_client_data(struct ishtp_cl *cl) +{ + return cl->client_data; +} +EXPORT_SYMBOL(ishtp_get_client_data); + +void ishtp_set_client_data(struct ishtp_cl *cl, void *data) +{ + cl->client_data = data; +} +EXPORT_SYMBOL(ishtp_set_client_data); + +struct ishtp_device *ishtp_get_ishtp_device(struct ishtp_cl *cl) +{ + return cl->dev; +} +EXPORT_SYMBOL(ishtp_get_ishtp_device); + +void ishtp_set_tx_ring_size(struct ishtp_cl *cl, int size) +{ + cl->tx_ring_size = size; +} +EXPORT_SYMBOL(ishtp_set_tx_ring_size); + +void ishtp_set_rx_ring_size(struct ishtp_cl *cl, int size) +{ + cl->rx_ring_size = size; +} +EXPORT_SYMBOL(ishtp_set_rx_ring_size); + +void ishtp_set_connection_state(struct ishtp_cl *cl, int state) +{ + cl->state = state; +} +EXPORT_SYMBOL(ishtp_set_connection_state); + +void ishtp_cl_set_fw_client_id(struct ishtp_cl *cl, int fw_client_id) +{ + cl->fw_client_id = fw_client_id; +} +EXPORT_SYMBOL(ishtp_cl_set_fw_client_id); diff --git a/include/linux/intel-ish-client-if.h b/include/linux/intel-ish-client-if.h index 7ce172f656f8..526e3048e09f 100644 --- a/include/linux/intel-ish-client-if.h +++ b/include/linux/intel-ish-client-if.h @@ -87,5 +87,12 @@ int ishtp_cl_flush_queues(struct ishtp_cl *cl); int ishtp_cl_io_rb_recycle(struct ishtp_cl_rb *rb); bool ishtp_cl_tx_empty(struct ishtp_cl *cl); struct ishtp_cl_rb *ishtp_cl_rx_get_rb(struct ishtp_cl *cl); +void *ishtp_get_client_data(struct ishtp_cl *cl); +void ishtp_set_client_data(struct ishtp_cl *cl, void *data); +struct ishtp_device *ishtp_get_ishtp_device(struct ishtp_cl *cl); +void ishtp_set_tx_ring_size(struct ishtp_cl *cl, int size); +void ishtp_set_rx_ring_size(struct ishtp_cl *cl, int size); +void ishtp_set_connection_state(struct ishtp_cl *cl, int state); +void ishtp_cl_set_fw_client_id(struct ishtp_cl *cl, int fw_client_id); #endif /* _INTEL_ISH_CLIENT_IF_H_ */ -- cgit v1.2.3 From 5f7224cf418511b9d3c40d35b098d15f9e4e7404 Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Mon, 18 Mar 2019 12:14:26 -0700 Subject: HID: intel-ish-hid: Move functions related to bus and device Move function idefinitions related to bus and device to common header file. Also create new function to get fw client id and move ish_hw_reset() from inline to exported function. Signed-off-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina --- drivers/hid/intel-ish-hid/ishtp/bus.c | 26 ++++++++++++++++++++++++++ drivers/hid/intel-ish-hid/ishtp/bus.h | 11 ----------- drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h | 5 ----- include/linux/intel-ish-client-if.h | 12 ++++++++++++ 4 files changed, 38 insertions(+), 16 deletions(-) (limited to 'drivers/hid/intel-ish-hid') diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c b/drivers/hid/intel-ish-hid/ishtp/bus.c index 2ca65864192f..66a485a41481 100644 --- a/drivers/hid/intel-ish-hid/ishtp/bus.c +++ b/drivers/hid/intel-ish-hid/ishtp/bus.c @@ -170,6 +170,19 @@ struct ishtp_fw_client *ishtp_fw_cl_get_client(struct ishtp_device *dev, } EXPORT_SYMBOL(ishtp_fw_cl_get_client); +/** + * ishtp_get_fw_client_id() - Get fw client id + * + * This interface is used to reset HW get FW client id. + * + * Return: firmware client id. + */ +int ishtp_get_fw_client_id(struct ishtp_fw_client *fw_client) +{ + return fw_client->client_id; +} +EXPORT_SYMBOL(ishtp_get_fw_client_id); + /** * ishtp_fw_cl_by_id() - return index to fw_clients for client_id * @dev: the ishtp device structure @@ -855,6 +868,19 @@ void *ishtp_trace_callback(struct ishtp_cl_device *cl_device) } EXPORT_SYMBOL(ishtp_trace_callback); +/** + * ish_hw_reset() - Call HW reset IPC callback + * + * This interface is used to reset HW in case of error. + * + * Return: value from IPC hw_reset callback + */ +int ish_hw_reset(struct ishtp_device *dev) +{ + return dev->ops->hw_reset(dev); +} +EXPORT_SYMBOL(ish_hw_reset); + /** * ishtp_bus_register() - Function to register bus * diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.h b/drivers/hid/intel-ish-hid/ishtp/bus.h index 4aed195719de..93d516f5a853 100644 --- a/drivers/hid/intel-ish-hid/ishtp/bus.h +++ b/drivers/hid/intel-ish-hid/ishtp/bus.h @@ -80,16 +80,5 @@ void ishtp_recv(struct ishtp_device *dev); void ishtp_reset_handler(struct ishtp_device *dev); void ishtp_reset_compl_handler(struct ishtp_device *dev); -void ishtp_put_device(struct ishtp_cl_device *); -void ishtp_get_device(struct ishtp_cl_device *); - -void ishtp_set_drvdata(struct ishtp_cl_device *cl_device, void *data); -void *ishtp_get_drvdata(struct ishtp_cl_device *cl_device); - -int ishtp_register_event_cb(struct ishtp_cl_device *device, - void (*read_cb)(struct ishtp_cl_device *)); int ishtp_fw_cl_by_uuid(struct ishtp_device *dev, const guid_t *cuuid); -struct ishtp_fw_client *ishtp_fw_cl_get_client(struct ishtp_device *dev, - const guid_t *uuid); - #endif /* _LINUX_ISHTP_CL_BUS_H */ diff --git a/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h b/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h index e0a320e67a41..3cfef084b9fc 100644 --- a/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h +++ b/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h @@ -238,11 +238,6 @@ static inline int ish_ipc_reset(struct ishtp_device *dev) return dev->ops->ipc_reset(dev); } -static inline int ish_hw_reset(struct ishtp_device *dev) -{ - return dev->ops->hw_reset(dev); -} - /* Exported function */ void ishtp_device_init(struct ishtp_device *dev); int ishtp_start(struct ishtp_device *dev); diff --git a/include/linux/intel-ish-client-if.h b/include/linux/intel-ish-client-if.h index 526e3048e09f..e98bfbb1e07e 100644 --- a/include/linux/intel-ish-client-if.h +++ b/include/linux/intel-ish-client-if.h @@ -9,7 +9,9 @@ #define _INTEL_ISH_CLIENT_IF_H_ struct ishtp_cl_device; +struct ishtp_device; struct ishtp_cl; +struct ishtp_fw_client; /* Client state */ enum cl_state { @@ -95,4 +97,14 @@ void ishtp_set_rx_ring_size(struct ishtp_cl *cl, int size); void ishtp_set_connection_state(struct ishtp_cl *cl, int state); void ishtp_cl_set_fw_client_id(struct ishtp_cl *cl, int fw_client_id); +void ishtp_put_device(struct ishtp_cl_device *cl_dev); +void ishtp_get_device(struct ishtp_cl_device *cl_dev); +void ishtp_set_drvdata(struct ishtp_cl_device *cl_device, void *data); +void *ishtp_get_drvdata(struct ishtp_cl_device *cl_device); +int ishtp_register_event_cb(struct ishtp_cl_device *device, + void (*read_cb)(struct ishtp_cl_device *)); +struct ishtp_fw_client *ishtp_fw_cl_get_client(struct ishtp_device *dev, + const guid_t *uuid); +int ishtp_get_fw_client_id(struct ishtp_fw_client *fw_client); +int ish_hw_reset(struct ishtp_device *dev); #endif /* _INTEL_ISH_CLIENT_IF_H_ */ -- cgit v1.2.3 From 29b06d12ba796a4c3e7bdfd8a26230eefb261261 Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Mon, 18 Mar 2019 12:14:27 -0700 Subject: HID: intel-ish-hid: Use the new interface functions in HID ish client Only include intel-ish-client-if.h, which has all interfaces required to implment ISHTP client. There is no longer any direct field access from core ISHTP only include files. Signed-off-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina --- drivers/hid/intel-ish-hid/ishtp-hid-client.c | 68 +++++++++++++--------------- drivers/hid/intel-ish-hid/ishtp-hid.c | 2 - drivers/hid/intel-ish-hid/ishtp-hid.h | 6 +-- 3 files changed, 35 insertions(+), 41 deletions(-) (limited to 'drivers/hid/intel-ish-hid') diff --git a/drivers/hid/intel-ish-hid/ishtp-hid-client.c b/drivers/hid/intel-ish-hid/ishtp-hid-client.c index 4afb39713213..56777a43e69c 100644 --- a/drivers/hid/intel-ish-hid/ishtp-hid-client.c +++ b/drivers/hid/intel-ish-hid/ishtp-hid-client.c @@ -17,8 +17,6 @@ #include #include #include -#include "ishtp/ishtp-dev.h" -#include "ishtp/client.h" #include "ishtp-hid.h" /* Rx ring buffer pool size */ @@ -40,7 +38,7 @@ static void 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 = hid_ishtp_cl->client_data; + struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); dev_err(cl_data_to_dev(client_data), "[hid-ish]: BAD packet %02X\n" "total_bad=%u cur_pos=%u\n" @@ -77,7 +75,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, struct report_list *reports_list; char *reports; size_t report_len; - struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data; + 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; @@ -93,7 +91,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, (unsigned int)data_len, (unsigned int)sizeof(struct hostif_msg_hdr)); ++client_data->bad_recv_cnt; - ish_hw_reset(hid_ishtp_cl->dev); + ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl)); break; } @@ -106,7 +104,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, ++client_data->bad_recv_cnt; report_bad_packet(hid_ishtp_cl, recv_msg, cur_pos, payload_len); - ish_hw_reset(hid_ishtp_cl->dev); + ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl)); break; } @@ -121,7 +119,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, report_bad_packet(hid_ishtp_cl, recv_msg, cur_pos, payload_len); - ish_hw_reset(hid_ishtp_cl->dev); + ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl)); break; } client_data->hid_dev_count = (unsigned int)*payload; @@ -170,7 +168,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, report_bad_packet(hid_ishtp_cl, recv_msg, cur_pos, payload_len); - ish_hw_reset(hid_ishtp_cl->dev); + ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl)); break; } if (!client_data->hid_descr[curr_hid_dev]) @@ -195,7 +193,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, report_bad_packet(hid_ishtp_cl, recv_msg, cur_pos, payload_len); - ish_hw_reset(hid_ishtp_cl->dev); + ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl)); break; } if (!client_data->report_descr[curr_hid_dev]) @@ -313,7 +311,7 @@ do_get_report: ++client_data->bad_recv_cnt; report_bad_packet(hid_ishtp_cl, recv_msg, cur_pos, payload_len); - ish_hw_reset(hid_ishtp_cl->dev); + ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl)); break; } @@ -493,7 +491,7 @@ int ishtp_hid_link_ready_wait(struct ishtp_cl_data *client_data) static int ishtp_enum_enum_devices(struct ishtp_cl *hid_ishtp_cl) { struct hostif_msg msg; - struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data; + struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); int retry_count; int rv; @@ -530,7 +528,7 @@ static int ishtp_enum_enum_devices(struct ishtp_cl *hid_ishtp_cl) } client_data->num_hid_devices = client_data->hid_dev_count; - dev_info(&hid_ishtp_cl->device->dev, + dev_info(ishtp_device(client_data->cl_device), "[hid-ish]: enum_devices_done OK, num_hid_devices=%d\n", client_data->num_hid_devices); @@ -549,7 +547,7 @@ static int ishtp_enum_enum_devices(struct ishtp_cl *hid_ishtp_cl) static int ishtp_get_hid_descriptor(struct ishtp_cl *hid_ishtp_cl, int index) { struct hostif_msg msg; - struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data; + struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); int rv; /* Get HID descriptor */ @@ -596,7 +594,7 @@ static int ishtp_get_report_descriptor(struct ishtp_cl *hid_ishtp_cl, int index) { struct hostif_msg msg; - struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data; + struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); int rv; /* Get report descriptor */ @@ -644,7 +642,7 @@ static int ishtp_get_report_descriptor(struct ishtp_cl *hid_ishtp_cl, static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset) { struct ishtp_device *dev; - struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data; + struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); struct ishtp_fw_client *fw_client; int i; int rv; @@ -661,11 +659,11 @@ static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset) client_data->init_done = 0; - dev = hid_ishtp_cl->dev; + dev = ishtp_get_ishtp_device(hid_ishtp_cl); /* Connect to FW client */ - hid_ishtp_cl->rx_ring_size = HID_CL_RX_RING_SIZE; - hid_ishtp_cl->tx_ring_size = HID_CL_TX_RING_SIZE; + ishtp_set_tx_ring_size(hid_ishtp_cl, HID_CL_TX_RING_SIZE); + ishtp_set_rx_ring_size(hid_ishtp_cl, HID_CL_RX_RING_SIZE); fw_client = ishtp_fw_cl_get_client(dev, &hid_ishtp_guid); if (!fw_client) { @@ -673,9 +671,9 @@ static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset) "ish client uuid not found\n"); return -ENOENT; } - - hid_ishtp_cl->fw_client_id = fw_client->client_id; - hid_ishtp_cl->state = ISHTP_CL_CONNECTING; + ishtp_cl_set_fw_client_id(hid_ishtp_cl, + ishtp_get_fw_client_id(fw_client)); + ishtp_set_connection_state(hid_ishtp_cl, ISHTP_CL_CONNECTING); rv = ishtp_cl_connect(hid_ishtp_cl); if (rv) { @@ -687,7 +685,7 @@ static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset) hid_ishtp_trace(client_data, "%s client connected\n", __func__); /* Register read callback */ - ishtp_register_event_cb(hid_ishtp_cl->device, ish_cl_event_cb); + ishtp_register_event_cb(client_data->cl_device, ish_cl_event_cb); rv = ishtp_enum_enum_devices(hid_ishtp_cl); if (rv) @@ -725,7 +723,7 @@ static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset) return 0; err_cl_disconnect: - hid_ishtp_cl->state = ISHTP_CL_DISCONNECTING; + ishtp_set_connection_state(hid_ishtp_cl, ISHTP_CL_DISCONNECTING); ishtp_cl_disconnect(hid_ishtp_cl); err_cl_unlink: ishtp_cl_unlink(hid_ishtp_cl); @@ -762,7 +760,7 @@ static void hid_ishtp_cl_reset_handler(struct work_struct *work) hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__, hid_ishtp_cl); - dev_dbg(&cl_device->dev, "%s\n", __func__); + dev_dbg(ishtp_device(client_data->cl_device), "%s\n", __func__); hid_ishtp_cl_deinit(hid_ishtp_cl); @@ -771,7 +769,7 @@ static void hid_ishtp_cl_reset_handler(struct work_struct *work) return; ishtp_set_drvdata(cl_device, hid_ishtp_cl); - hid_ishtp_cl->client_data = client_data; + ishtp_set_client_data(hid_ishtp_cl, client_data); client_data->hid_ishtp_cl = hid_ishtp_cl; client_data->num_hid_devices = 0; @@ -789,7 +787,7 @@ static void hid_ishtp_cl_reset_handler(struct work_struct *work) } } -void (*hid_print_trace)(void *dev, const char *format, ...); +void (*hid_print_trace)(void *unused, const char *format, ...); /** * hid_ishtp_cl_probe() - ISHTP client driver probe @@ -819,7 +817,7 @@ static int hid_ishtp_cl_probe(struct ishtp_cl_device *cl_device) return -ENOMEM; ishtp_set_drvdata(cl_device, hid_ishtp_cl); - hid_ishtp_cl->client_data = client_data; + ishtp_set_client_data(hid_ishtp_cl, client_data); client_data->hid_ishtp_cl = hid_ishtp_cl; client_data->cl_device = cl_device; @@ -851,13 +849,13 @@ static int hid_ishtp_cl_probe(struct ishtp_cl_device *cl_device) static int hid_ishtp_cl_remove(struct ishtp_cl_device *cl_device) { struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device); - struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data; + struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__, hid_ishtp_cl); dev_dbg(ishtp_device(cl_device), "%s\n", __func__); - hid_ishtp_cl->state = ISHTP_CL_DISCONNECTING; + ishtp_set_connection_state(hid_ishtp_cl, ISHTP_CL_DISCONNECTING); ishtp_cl_disconnect(hid_ishtp_cl); ishtp_put_device(cl_device); ishtp_hid_remove(client_data); @@ -881,7 +879,7 @@ static int hid_ishtp_cl_remove(struct ishtp_cl_device *cl_device) static int hid_ishtp_cl_reset(struct ishtp_cl_device *cl_device) { struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device); - struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data; + struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__, hid_ishtp_cl); @@ -891,8 +889,6 @@ static int hid_ishtp_cl_reset(struct ishtp_cl_device *cl_device) return 0; } -#define to_ishtp_cl_device(d) container_of(d, struct ishtp_cl_device, dev) - /** * hid_ishtp_cl_suspend() - ISHTP client driver suspend * @device: device instance @@ -903,9 +899,9 @@ static int hid_ishtp_cl_reset(struct ishtp_cl_device *cl_device) */ static int hid_ishtp_cl_suspend(struct device *device) { - struct ishtp_cl_device *cl_device = to_ishtp_cl_device(device); + struct ishtp_cl_device *cl_device = dev_get_drvdata(device); struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device); - struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data; + struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__, hid_ishtp_cl); @@ -924,9 +920,9 @@ static int hid_ishtp_cl_suspend(struct device *device) */ static int hid_ishtp_cl_resume(struct device *device) { - struct ishtp_cl_device *cl_device = to_ishtp_cl_device(device); + struct ishtp_cl_device *cl_device = dev_get_drvdata(device); struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device); - struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data; + struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__, hid_ishtp_cl); diff --git a/drivers/hid/intel-ish-hid/ishtp-hid.c b/drivers/hid/intel-ish-hid/ishtp-hid.c index 95a5b87d9105..62c03561adaa 100644 --- a/drivers/hid/intel-ish-hid/ishtp-hid.c +++ b/drivers/hid/intel-ish-hid/ishtp-hid.c @@ -16,7 +16,6 @@ #include #include #include -#include "ishtp/client.h" #include "ishtp-hid.h" /** @@ -154,7 +153,6 @@ static void ishtp_hid_request(struct hid_device *hid, struct hid_report *rep, static int ishtp_wait_for_response(struct hid_device *hid) { struct ishtp_hid_data *hid_data = hid->driver_data; - struct ishtp_cl_data *client_data = hid_data->client_data; int rv; hid_ishtp_trace(client_data, "%s hid %p\n", __func__, hid); diff --git a/drivers/hid/intel-ish-hid/ishtp-hid.h b/drivers/hid/intel-ish-hid/ishtp-hid.h index 8af44e855a49..e27d3d6c1920 100644 --- a/drivers/hid/intel-ish-hid/ishtp-hid.h +++ b/drivers/hid/intel-ish-hid/ishtp-hid.h @@ -24,9 +24,9 @@ #define IS_RESPONSE 0x80 /* Used to dump to Linux trace buffer, if enabled */ -#define hid_ishtp_trace(client, ...) \ - client->cl_device->ishtp_dev->print_log(\ - client->cl_device->ishtp_dev, __VA_ARGS__) +extern void (*hid_print_trace)(void *unused, const char *format, ...); +#define hid_ishtp_trace(client, ...) \ + (hid_print_trace)(NULL, __VA_ARGS__) /* ISH Transport protocol (ISHTP in short) GUID */ static const guid_t hid_ishtp_guid = -- cgit v1.2.3 From 0e568a16af403263f8e421f1f10b91f9f15b52c3 Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Mon, 18 Mar 2019 12:14:28 -0700 Subject: HID: intel-ish-hid: Add interface function for PCI device pointer Instead of directly accessing PCI device poitner via struct ishtp_cl, create interface function for same. This is required for DMA transfer. Signed-off-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina --- drivers/hid/intel-ish-hid/ishtp/bus.c | 13 +++++++++++++ include/linux/intel-ish-client-if.h | 2 ++ 2 files changed, 15 insertions(+) (limited to 'drivers/hid/intel-ish-hid') diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c b/drivers/hid/intel-ish-hid/ishtp/bus.c index 66a485a41481..fb8ca12955b4 100644 --- a/drivers/hid/intel-ish-hid/ishtp/bus.c +++ b/drivers/hid/intel-ish-hid/ishtp/bus.c @@ -855,6 +855,19 @@ struct device *ishtp_device(struct ishtp_cl_device *device) } EXPORT_SYMBOL(ishtp_device); +/** + * ishtp_get_pci_device() - Return PCI device dev pointer + * This interface is used to return PCI device pointer + * from ishtp_cl_device instance. + * + * Return: device *. + */ +struct device *ishtp_get_pci_device(struct ishtp_cl_device *device) +{ + return device->ishtp_dev->devc; +} +EXPORT_SYMBOL(ishtp_get_pci_device); + /** * ishtp_trace_callback() - Return trace callback * diff --git a/include/linux/intel-ish-client-if.h b/include/linux/intel-ish-client-if.h index e98bfbb1e07e..16255c2ca2f4 100644 --- a/include/linux/intel-ish-client-if.h +++ b/include/linux/intel-ish-client-if.h @@ -77,6 +77,8 @@ int ishtp_register_event_cb(struct ishtp_cl_device *device, struct device *ishtp_device(struct ishtp_cl_device *cl_device); /* Trace interface for clients */ void *ishtp_trace_callback(struct ishtp_cl_device *cl_device); +/* Get device pointer of PCI device for DMA acces */ +struct device *ishtp_get_pci_device(struct ishtp_cl_device *cl_device); struct ishtp_cl *ishtp_cl_allocate(struct ishtp_cl_device *cl_device); void ishtp_cl_free(struct ishtp_cl *cl); -- cgit v1.2.3 From 91b228107da3e41558449a62cd93816b47b3b4b5 Mon Sep 17 00:00:00 2001 From: Rushikesh S Kadam Date: Tue, 2 Apr 2019 11:17:41 +0530 Subject: HID: intel-ish-hid: ISH firmware loader client driver This driver adds support for loading Intel Integrated Sensor Hub (ISH) firmware from host file system to ISH SRAM and start execution. At power-on, the ISH subsystem shall boot to an interim Shim loader-firmware, which shall expose an ISHTP loader device. The driver implements an ISHTP client that communicates with the Shim ISHTP loader device over the intel-ish-hid stack, to download the main ISH firmware. Signed-off-by: Rushikesh S Kadam Acked-by: Srinivas Pandruvada Acked-by: Nick Crews Tested-by: Jett Rink Signed-off-by: Jiri Kosina --- drivers/hid/Makefile | 1 + drivers/hid/intel-ish-hid/Kconfig | 15 + drivers/hid/intel-ish-hid/Makefile | 3 + drivers/hid/intel-ish-hid/ishtp-fw-loader.c | 1085 +++++++++++++++++++++++++++ 4 files changed, 1104 insertions(+) create mode 100644 drivers/hid/intel-ish-hid/ishtp-fw-loader.c (limited to 'drivers/hid/intel-ish-hid') diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 170163b41303..d8d393e7a1f9 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -134,3 +134,4 @@ obj-$(CONFIG_USB_KBD) += usbhid/ obj-$(CONFIG_I2C_HID) += i2c-hid/ obj-$(CONFIG_INTEL_ISH_HID) += intel-ish-hid/ +obj-$(INTEL_ISH_FIRMWARE_DOWNLOADER) += intel-ish-hid/ diff --git a/drivers/hid/intel-ish-hid/Kconfig b/drivers/hid/intel-ish-hid/Kconfig index 519e4c8b53c4..786adbc97ac5 100644 --- a/drivers/hid/intel-ish-hid/Kconfig +++ b/drivers/hid/intel-ish-hid/Kconfig @@ -14,4 +14,19 @@ config INTEL_ISH_HID Broxton and Kaby Lake. Say Y here if you want to support Intel ISH. If unsure, say N. + +config INTEL_ISH_FIRMWARE_DOWNLOADER + tristate "Host Firmware Load feature for Intel ISH" + depends on INTEL_ISH_HID + depends on X86 + help + The Integrated Sensor Hub (ISH) enables the kernel to offload + sensor polling and algorithm processing to a dedicated low power + processor in the chipset. + + The Host Firmware Load feature adds support to load the ISH + firmware from host file system at boot. + + Say M here if you want to support Host Firmware Loading feature + for Intel ISH. If unsure, say N. endmenu diff --git a/drivers/hid/intel-ish-hid/Makefile b/drivers/hid/intel-ish-hid/Makefile index 825b70af672f..2de97e4b7740 100644 --- a/drivers/hid/intel-ish-hid/Makefile +++ b/drivers/hid/intel-ish-hid/Makefile @@ -20,4 +20,7 @@ obj-$(CONFIG_INTEL_ISH_HID) += intel-ishtp-hid.o intel-ishtp-hid-objs := ishtp-hid.o intel-ishtp-hid-objs += ishtp-hid-client.o +obj-$(CONFIG_INTEL_ISH_FIRMWARE_DOWNLOADER) += intel-ishtp-loader.o +intel-ishtp-loader-objs += ishtp-fw-loader.o + ccflags-y += -Idrivers/hid/intel-ish-hid/ishtp diff --git a/drivers/hid/intel-ish-hid/ishtp-fw-loader.c b/drivers/hid/intel-ish-hid/ishtp-fw-loader.c new file mode 100644 index 000000000000..e770e220bd73 --- /dev/null +++ b/drivers/hid/intel-ish-hid/ishtp-fw-loader.c @@ -0,0 +1,1085 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ISH-TP client driver for ISH firmware loading + * + * Copyright (c) 2019, Intel Corporation. + */ + +#include +#include +#include +#include +#include +#include + +/* Number of times we attempt to load the firmware before giving up */ +#define MAX_LOAD_ATTEMPTS 3 + +/* ISH TX/RX ring buffer pool size */ +#define LOADER_CL_RX_RING_SIZE 1 +#define LOADER_CL_TX_RING_SIZE 1 + +/* + * ISH Shim firmware loader reserves 4 Kb buffer in SRAM. The buffer is + * used to temporarily hold the data transferred from host to Shim + * firmware loader. Reason for the odd size of 3968 bytes? Each IPC + * transfer is 128 bytes (= 4 bytes header + 124 bytes payload). So the + * 4 Kb buffer can hold maximum of 32 IPC transfers, which means we can + * have a max payload of 3968 bytes (= 32 x 124 payload). + */ +#define LOADER_SHIM_IPC_BUF_SIZE 3968 + +/** + * enum ish_loader_commands - ISH loader host commands. + * LOADER_CMD_XFER_QUERY Query the Shim firmware loader for + * capabilities + * LOADER_CMD_XFER_FRAGMENT Transfer one firmware image fragment at a + * time. The command may be executed + * multiple times until the entire firmware + * image is downloaded to SRAM. + * LOADER_CMD_START Start executing the main firmware. + */ +enum ish_loader_commands { + LOADER_CMD_XFER_QUERY = 0, + LOADER_CMD_XFER_FRAGMENT, + LOADER_CMD_START, +}; + +/* Command bit mask */ +#define CMD_MASK GENMASK(6, 0) +#define IS_RESPONSE BIT(7) + +/* + * ISH firmware max delay for one transmit failure is 1 Hz, + * and firmware will retry 2 times, so 3 Hz is used for timeout. + */ +#define ISHTP_SEND_TIMEOUT (3 * HZ) + +/* + * Loader transfer modes: + * + * LOADER_XFER_MODE_ISHTP mode uses the existing ISH-TP mechanism to + * transfer data. This may use IPC or DMA if supported in firmware. + * The buffer size is limited to 4 Kb by the IPC/ISH-TP protocol for + * both IPC & DMA (legacy). + * + * LOADER_XFER_MODE_DIRECT_DMA - firmware loading is a bit different + * from the sensor data streaming. Here we download a large (300+ Kb) + * image directly to ISH SRAM memory. There is limited benefit of + * DMA'ing 300 Kb image in 4 Kb chucks limit. Hence, we introduce + * this "direct dma" mode, where we do not use ISH-TP for DMA, but + * instead manage the DMA directly in kernel driver and Shim firmware + * loader (allocate buffer, break in chucks and transfer). This allows + * to overcome 4 Kb limit, and optimize the data flow path in firmware. + */ +#define LOADER_XFER_MODE_DIRECT_DMA BIT(0) +#define LOADER_XFER_MODE_ISHTP BIT(1) + +/* ISH Transport Loader client unique GUID */ +static const guid_t loader_ishtp_guid = + GUID_INIT(0xc804d06a, 0x55bd, 0x4ea7, + 0xad, 0xed, 0x1e, 0x31, 0x22, 0x8c, 0x76, 0xdc); + +#define FILENAME_SIZE 256 + +/* + * The firmware loading latency will be minimum if we can DMA the + * entire ISH firmware image in one go. This requires that we allocate + * a large DMA buffer in kernel, which could be problematic on some + * platforms. So here we limit the DMA buffer size via a module_param. + * We default to 4 pages, but a customer can set it to higher limit if + * deemed appropriate for his platform. + */ +static int dma_buf_size_limit = 4 * PAGE_SIZE; + +/** + * struct loader_msg_hdr - Header for ISH Loader commands. + * @command: LOADER_CMD* commands. Bit 7 is the response. + * @status: Command response status. Non 0, is error + * condition. + * + * This structure is used as header for every command/data sent/received + * between Host driver and ISH Shim firmware loader. + */ +struct loader_msg_hdr { + u8 command; + u8 reserved[2]; + u8 status; +} __packed; + +struct loader_xfer_query { + struct loader_msg_hdr hdr; + u32 image_size; +} __packed; + +struct ish_fw_version { + u16 major; + u16 minor; + u16 hotfix; + u16 build; +} __packed; + +union loader_version { + u32 value; + struct { + u8 major; + u8 minor; + u8 hotfix; + u8 build; + }; +} __packed; + +struct loader_capability { + u32 max_fw_image_size; + u32 xfer_mode; + u32 max_dma_buf_size; /* only for dma mode, multiples of cacheline */ +} __packed; + +struct shim_fw_info { + struct ish_fw_version ish_fw_version; + u32 protocol_version; + union loader_version ldr_version; + struct loader_capability ldr_capability; +} __packed; + +struct loader_xfer_query_response { + struct loader_msg_hdr hdr; + struct shim_fw_info fw_info; +} __packed; + +struct loader_xfer_fragment { + struct loader_msg_hdr hdr; + u32 xfer_mode; + u32 offset; + u32 size; + u32 is_last; +} __packed; + +struct loader_xfer_ipc_fragment { + struct loader_xfer_fragment fragment; + u8 data[] ____cacheline_aligned; /* variable length payload here */ +} __packed; + +struct loader_xfer_dma_fragment { + struct loader_xfer_fragment fragment; + u64 ddr_phys_addr; +} __packed; + +struct loader_start { + struct loader_msg_hdr hdr; +} __packed; + +/** + * struct response_info - Encapsulate firmware response related + * information for passing between function + * loader_cl_send() and process_recv() callback. + * @data Copy the data received from firmware here. + * @max_size Max size allocated for the @data buffer. If the + * received data exceeds this value, we log an + * error. + * @size Actual size of data received from firmware. + * @error Returns 0 for success, negative error code for a + * failure in function process_recv(). + * @received Set to true on receiving a valid firmware + * response to host command + * @wait_queue Wait queue for Host firmware loading where the + * client sends message to ISH firmware and waits + * for response + */ +struct response_info { + void *data; + size_t max_size; + size_t size; + int error; + bool received; + wait_queue_head_t wait_queue; +}; + +/** + * struct ishtp_cl_data - Encapsulate per ISH-TP Client Data. + * @work_ishtp_reset: Work queue for reset handling. + * @work_fw_load: Work queue for host firmware loading. + * @flag_retry Flag for indicating host firmware loading should + * be retried. + * @retry_count Count the number of retries. + * + * This structure is used to store data per client. + */ +struct ishtp_cl_data { + struct ishtp_cl *loader_ishtp_cl; + struct ishtp_cl_device *cl_device; + + /* + * Used for passing firmware response information between + * loader_cl_send() and process_recv() callback. + */ + struct response_info response; + + struct work_struct work_ishtp_reset; + struct work_struct work_fw_load; + + /* + * In certain failure scenrios, it makes sense to reset the ISH + * subsystem and retry Host firmware loading (e.g. bad message + * packet, ENOMEM, etc.). On the other hand, failures due to + * protocol mismatch, etc., are not recoverable. We do not + * retry them. + * + * If set, the flag indicates that we should re-try the + * particular failure. + */ + bool flag_retry; + int retry_count; +}; + +#define IPC_FRAGMENT_DATA_PREAMBLE \ + offsetof(struct loader_xfer_ipc_fragment, data) + +#define cl_data_to_dev(client_data) ishtp_device((client_data)->cl_device) + +/** + * get_firmware_variant() - Gets the filename of firmware image to be + * loaded based on platform variant. + * @client_data Client data instance. + * @filename Returns firmware filename. + * + * Queries the firmware-name device property string. + * + * Return: 0 for success, negative error code for failure. + */ +static int get_firmware_variant(struct ishtp_cl_data *client_data, + char *filename) +{ + int rv; + const char *val; + struct device *devc = ishtp_get_pci_device(client_data->cl_device); + + rv = device_property_read_string(devc, "firmware-name", &val); + if (rv < 0) { + dev_err(devc, + "Error: ISH firmware-name device property required\n"); + return rv; + } + return snprintf(filename, FILENAME_SIZE, "intel/%s", val); +} + +/** + * loader_cl_send() Send message from host to firmware + * @client_data: Client data instance + * @out_msg Message buffer to be sent to firmware + * @out_size Size of out going message + * @in_msg Message buffer where the incoming data copied. + * This buffer is allocated by calling + * @in_size Max size of incoming message + * + * Return: Number of bytes copied in the in_msg on success, negative + * error code on failure. + */ +static int loader_cl_send(struct ishtp_cl_data *client_data, + u8 *out_msg, size_t out_size, + u8 *in_msg, size_t in_size) +{ + int rv; + struct loader_msg_hdr *out_hdr = (struct loader_msg_hdr *)out_msg; + struct ishtp_cl *loader_ishtp_cl = client_data->loader_ishtp_cl; + + dev_dbg(cl_data_to_dev(client_data), + "%s: command=%02lx is_response=%u status=%02x\n", + __func__, + out_hdr->command & CMD_MASK, + out_hdr->command & IS_RESPONSE ? 1 : 0, + out_hdr->status); + + /* Setup in coming buffer & size */ + client_data->response.data = in_msg; + client_data->response.max_size = in_size; + client_data->response.error = 0; + client_data->response.received = false; + + rv = ishtp_cl_send(loader_ishtp_cl, out_msg, out_size); + if (rv < 0) { + dev_err(cl_data_to_dev(client_data), + "ishtp_cl_send error %d\n", rv); + return rv; + } + + wait_event_interruptible_timeout(client_data->response.wait_queue, + client_data->response.received, + ISHTP_SEND_TIMEOUT); + if (!client_data->response.received) { + dev_err(cl_data_to_dev(client_data), + "Timed out for response to command=%02lx", + out_hdr->command & CMD_MASK); + return -ETIMEDOUT; + } + + if (client_data->response.error < 0) + return client_data->response.error; + + return client_data->response.size; +} + +/** + * process_recv() - Receive and parse incoming packet + * @loader_ishtp_cl: Client instance to get stats + * @rb_in_proc: ISH received message buffer + * + * Parse the incoming packet. If it is a response packet then it will + * update received and wake up the caller waiting to for the response. + */ +static void process_recv(struct ishtp_cl *loader_ishtp_cl, + struct ishtp_cl_rb *rb_in_proc) +{ + struct loader_msg_hdr *hdr; + size_t data_len = rb_in_proc->buf_idx; + struct ishtp_cl_data *client_data = + ishtp_get_client_data(loader_ishtp_cl); + + /* Sanity check */ + if (!client_data->response.data) { + dev_err(cl_data_to_dev(client_data), + "Receiving buffer is null. Should be allocated by calling function\n"); + client_data->response.error = -EINVAL; + goto end; + } + + if (client_data->response.received) { + dev_err(cl_data_to_dev(client_data), + "Previous firmware message not yet processed\n"); + client_data->response.error = -EINVAL; + goto end; + } + /* + * All firmware messages have a header. Check buffer size + * before accessing elements inside. + */ + if (!rb_in_proc->buffer.data) { + dev_warn(cl_data_to_dev(client_data), + "rb_in_proc->buffer.data returned null"); + client_data->response.error = -EBADMSG; + goto end; + } + + if (data_len < sizeof(struct loader_msg_hdr)) { + dev_err(cl_data_to_dev(client_data), + "data size %zu is less than header %zu\n", + data_len, sizeof(struct loader_msg_hdr)); + client_data->response.error = -EMSGSIZE; + goto end; + } + + hdr = (struct loader_msg_hdr *)rb_in_proc->buffer.data; + + dev_dbg(cl_data_to_dev(client_data), + "%s: command=%02lx is_response=%u status=%02x\n", + __func__, + hdr->command & CMD_MASK, + hdr->command & IS_RESPONSE ? 1 : 0, + hdr->status); + + if (((hdr->command & CMD_MASK) != LOADER_CMD_XFER_QUERY) && + ((hdr->command & CMD_MASK) != LOADER_CMD_XFER_FRAGMENT) && + ((hdr->command & CMD_MASK) != LOADER_CMD_START)) { + dev_err(cl_data_to_dev(client_data), + "Invalid command=%02lx\n", + hdr->command & CMD_MASK); + client_data->response.error = -EPROTO; + goto end; + } + + if (data_len > client_data->response.max_size) { + dev_err(cl_data_to_dev(client_data), + "Received buffer size %zu is larger than allocated buffer %zu\n", + data_len, client_data->response.max_size); + client_data->response.error = -EMSGSIZE; + goto end; + } + + /* We expect only "response" messages from firmware */ + if (!(hdr->command & IS_RESPONSE)) { + dev_err(cl_data_to_dev(client_data), + "Invalid response to command\n"); + client_data->response.error = -EIO; + goto end; + } + + if (hdr->status) { + dev_err(cl_data_to_dev(client_data), + "Loader returned status %d\n", + hdr->status); + client_data->response.error = -EIO; + goto end; + } + + /* Update the actual received buffer size */ + client_data->response.size = data_len; + + /* + * Copy the buffer received in firmware response for the + * calling thread. + */ + memcpy(client_data->response.data, + rb_in_proc->buffer.data, data_len); + + /* Set flag before waking up the caller */ + client_data->response.received = true; + +end: + /* Free the buffer */ + ishtp_cl_io_rb_recycle(rb_in_proc); + rb_in_proc = NULL; + + /* Wake the calling thread */ + wake_up_interruptible(&client_data->response.wait_queue); +} + +/** + * loader_cl_event_cb() - bus driver callback for incoming message + * @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 + */ +static void loader_cl_event_cb(struct ishtp_cl_device *cl_device) +{ + struct ishtp_cl_rb *rb_in_proc; + struct ishtp_cl *loader_ishtp_cl = ishtp_get_drvdata(cl_device); + + while ((rb_in_proc = ishtp_cl_rx_get_rb(loader_ishtp_cl)) != NULL) { + /* Process the data packet from firmware */ + process_recv(loader_ishtp_cl, rb_in_proc); + } +} + +/** + * ish_query_loader_prop() - Query ISH Shim firmware loader + * @client_data: Client data instance + * @fw: Poiner to firmware data struct in host memory + * @fw_info: Loader firmware properties + * + * This function queries the ISH Shim firmware loader for capabilities. + * + * Return: 0 for success, negative error code for failure. + */ +static int ish_query_loader_prop(struct ishtp_cl_data *client_data, + const struct firmware *fw, + struct shim_fw_info *fw_info) +{ + int rv; + struct loader_xfer_query ldr_xfer_query; + struct loader_xfer_query_response ldr_xfer_query_resp; + + memset(&ldr_xfer_query, 0, sizeof(ldr_xfer_query)); + ldr_xfer_query.hdr.command = LOADER_CMD_XFER_QUERY; + ldr_xfer_query.image_size = fw->size; + rv = loader_cl_send(client_data, + (u8 *)&ldr_xfer_query, + sizeof(ldr_xfer_query), + (u8 *)&ldr_xfer_query_resp, + sizeof(ldr_xfer_query_resp)); + if (rv < 0) { + client_data->flag_retry = true; + return rv; + } + + /* On success, the return value is the received buffer size */ + if (rv != sizeof(struct loader_xfer_query_response)) { + dev_err(cl_data_to_dev(client_data), + "data size %d is not equal to size of loader_xfer_query_response %zu\n", + rv, sizeof(struct loader_xfer_query_response)); + client_data->flag_retry = true; + return -EMSGSIZE; + } + + /* Save fw_info for use outside this function */ + *fw_info = ldr_xfer_query_resp.fw_info; + + /* Loader firmware properties */ + dev_dbg(cl_data_to_dev(client_data), + "ish_fw_version: major=%d minor=%d hotfix=%d build=%d protocol_version=0x%x loader_version=%d\n", + fw_info->ish_fw_version.major, + fw_info->ish_fw_version.minor, + fw_info->ish_fw_version.hotfix, + fw_info->ish_fw_version.build, + fw_info->protocol_version, + fw_info->ldr_version.value); + + dev_dbg(cl_data_to_dev(client_data), + "loader_capability: max_fw_image_size=0x%x xfer_mode=%d max_dma_buf_size=0x%x dma_buf_size_limit=0x%x\n", + fw_info->ldr_capability.max_fw_image_size, + fw_info->ldr_capability.xfer_mode, + fw_info->ldr_capability.max_dma_buf_size, + dma_buf_size_limit); + + /* Sanity checks */ + if (fw_info->ldr_capability.max_fw_image_size < fw->size) { + dev_err(cl_data_to_dev(client_data), + "ISH firmware size %zu is greater than Shim firmware loader max supported %d\n", + fw->size, + fw_info->ldr_capability.max_fw_image_size); + return -ENOSPC; + } + + /* For DMA the buffer size should be multiple of cacheline size */ + if ((fw_info->ldr_capability.xfer_mode & LOADER_XFER_MODE_DIRECT_DMA) && + (fw_info->ldr_capability.max_dma_buf_size % L1_CACHE_BYTES)) { + dev_err(cl_data_to_dev(client_data), + "Shim firmware loader buffer size %d should be multipe of cacheline\n", + fw_info->ldr_capability.max_dma_buf_size); + return -EINVAL; + } + + return 0; +} + +/** + * ish_fw_xfer_ishtp() Loads ISH firmware using ishtp interface + * @client_data: Client data instance + * @fw: Pointer to firmware data struct in host memory + * + * This function uses ISH-TP to transfer ISH firmware from host to + * ISH SRAM. Lower layers may use IPC or DMA depending on firmware + * support. + * + * Return: 0 for success, negative error code for failure. + */ +static int ish_fw_xfer_ishtp(struct ishtp_cl_data *client_data, + const struct firmware *fw) +{ + int rv; + u32 fragment_offset, fragment_size, payload_max_size; + struct loader_xfer_ipc_fragment *ldr_xfer_ipc_frag; + struct loader_msg_hdr ldr_xfer_ipc_ack; + + payload_max_size = + LOADER_SHIM_IPC_BUF_SIZE - IPC_FRAGMENT_DATA_PREAMBLE; + + ldr_xfer_ipc_frag = kzalloc(LOADER_SHIM_IPC_BUF_SIZE, GFP_KERNEL); + if (!ldr_xfer_ipc_frag) { + client_data->flag_retry = true; + return -ENOMEM; + } + + ldr_xfer_ipc_frag->fragment.hdr.command = LOADER_CMD_XFER_FRAGMENT; + ldr_xfer_ipc_frag->fragment.xfer_mode = LOADER_XFER_MODE_ISHTP; + + /* Break the firmware image into fragments and send as ISH-TP payload */ + fragment_offset = 0; + while (fragment_offset < fw->size) { + if (fragment_offset + payload_max_size < fw->size) { + fragment_size = payload_max_size; + ldr_xfer_ipc_frag->fragment.is_last = 0; + } else { + fragment_size = fw->size - fragment_offset; + ldr_xfer_ipc_frag->fragment.is_last = 1; + } + + ldr_xfer_ipc_frag->fragment.offset = fragment_offset; + ldr_xfer_ipc_frag->fragment.size = fragment_size; + memcpy(ldr_xfer_ipc_frag->data, + &fw->data[fragment_offset], + fragment_size); + + dev_dbg(cl_data_to_dev(client_data), + "xfer_mode=ipc offset=0x%08x size=0x%08x is_last=%d\n", + ldr_xfer_ipc_frag->fragment.offset, + ldr_xfer_ipc_frag->fragment.size, + ldr_xfer_ipc_frag->fragment.is_last); + + rv = loader_cl_send(client_data, + (u8 *)ldr_xfer_ipc_frag, + IPC_FRAGMENT_DATA_PREAMBLE + fragment_size, + (u8 *)&ldr_xfer_ipc_ack, + sizeof(ldr_xfer_ipc_ack)); + if (rv < 0) { + client_data->flag_retry = true; + goto end_err_resp_buf_release; + } + + fragment_offset += fragment_size; + } + + kfree(ldr_xfer_ipc_frag); + return 0; + +end_err_resp_buf_release: + /* Free ISH buffer if not done already, in error case */ + kfree(ldr_xfer_ipc_frag); + return rv; +} + +/** + * ish_fw_xfer_direct_dma() - Loads ISH firmware using direct dma + * @client_data: Client data instance + * @fw: Pointer to firmware data struct in host memory + * @fw_info: Loader firmware properties + * + * Host firmware load is a unique case where we need to download + * a large firmware image (200+ Kb). This function implements + * direct DMA transfer in kernel and ISH firmware. This allows + * us to overcome the ISH-TP 4 Kb limit, and allows us to DMA + * directly to ISH UMA at location of choice. + * Function depends on corresponding support in ISH firmware. + * + * Return: 0 for success, negative error code for failure. + */ +static int ish_fw_xfer_direct_dma(struct ishtp_cl_data *client_data, + const struct firmware *fw, + const struct shim_fw_info fw_info) +{ + int rv; + void *dma_buf; + dma_addr_t dma_buf_phy; + u32 fragment_offset, fragment_size, payload_max_size; + struct loader_msg_hdr ldr_xfer_dma_frag_ack; + struct loader_xfer_dma_fragment ldr_xfer_dma_frag; + struct device *devc = ishtp_get_pci_device(client_data->cl_device); + u32 shim_fw_buf_size = + fw_info.ldr_capability.max_dma_buf_size; + + /* + * payload_max_size should be set to minimum of + * (1) Size of firmware to be loaded, + * (2) Max DMA buffer size supported by Shim firmware, + * (3) DMA buffer size limit set by boot_param dma_buf_size_limit. + */ + payload_max_size = min3(fw->size, + (size_t)shim_fw_buf_size, + (size_t)dma_buf_size_limit); + + /* + * Buffer size should be multiple of cacheline size + * if it's not, select the previous cacheline boundary. + */ + payload_max_size &= ~(L1_CACHE_BYTES - 1); + + dma_buf = kmalloc(payload_max_size, GFP_KERNEL | GFP_DMA32); + if (!dma_buf) { + client_data->flag_retry = true; + return -ENOMEM; + } + + dma_buf_phy = dma_map_single(devc, dma_buf, payload_max_size, + DMA_TO_DEVICE); + if (dma_mapping_error(devc, dma_buf_phy)) { + dev_err(cl_data_to_dev(client_data), "DMA map failed\n"); + client_data->flag_retry = true; + rv = -ENOMEM; + goto end_err_dma_buf_release; + } + + ldr_xfer_dma_frag.fragment.hdr.command = LOADER_CMD_XFER_FRAGMENT; + ldr_xfer_dma_frag.fragment.xfer_mode = LOADER_XFER_MODE_DIRECT_DMA; + ldr_xfer_dma_frag.ddr_phys_addr = (u64)dma_buf_phy; + + /* Send the firmware image in chucks of payload_max_size */ + fragment_offset = 0; + while (fragment_offset < fw->size) { + if (fragment_offset + payload_max_size < fw->size) { + fragment_size = payload_max_size; + ldr_xfer_dma_frag.fragment.is_last = 0; + } else { + fragment_size = fw->size - fragment_offset; + ldr_xfer_dma_frag.fragment.is_last = 1; + } + + ldr_xfer_dma_frag.fragment.offset = fragment_offset; + ldr_xfer_dma_frag.fragment.size = fragment_size; + memcpy(dma_buf, &fw->data[fragment_offset], fragment_size); + + dma_sync_single_for_device(devc, dma_buf_phy, + payload_max_size, + DMA_TO_DEVICE); + + /* + * Flush cache here because the dma_sync_single_for_device() + * does not do for x86. + */ + clflush_cache_range(dma_buf, payload_max_size); + + dev_dbg(cl_data_to_dev(client_data), + "xfer_mode=dma offset=0x%08x size=0x%x is_last=%d ddr_phys_addr=0x%016llx\n", + ldr_xfer_dma_frag.fragment.offset, + ldr_xfer_dma_frag.fragment.size, + ldr_xfer_dma_frag.fragment.is_last, + ldr_xfer_dma_frag.ddr_phys_addr); + + rv = loader_cl_send(client_data, + (u8 *)&ldr_xfer_dma_frag, + sizeof(ldr_xfer_dma_frag), + (u8 *)&ldr_xfer_dma_frag_ack, + sizeof(ldr_xfer_dma_frag_ack)); + if (rv < 0) { + client_data->flag_retry = true; + goto end_err_resp_buf_release; + } + + fragment_offset += fragment_size; + } + + dma_unmap_single(devc, dma_buf_phy, payload_max_size, DMA_TO_DEVICE); + kfree(dma_buf); + return 0; + +end_err_resp_buf_release: + /* Free ISH buffer if not done already, in error case */ + dma_unmap_single(devc, dma_buf_phy, payload_max_size, DMA_TO_DEVICE); +end_err_dma_buf_release: + kfree(dma_buf); + return rv; +} + +/** + * ish_fw_start() Start executing ISH main firmware + * @client_data: client data instance + * + * This function sends message to Shim firmware loader to start + * the execution of ISH main firmware. + * + * Return: 0 for success, negative error code for failure. + */ +static int ish_fw_start(struct ishtp_cl_data *client_data) +{ + struct loader_start ldr_start; + struct loader_msg_hdr ldr_start_ack; + + memset(&ldr_start, 0, sizeof(ldr_start)); + ldr_start.hdr.command = LOADER_CMD_START; + return loader_cl_send(client_data, + (u8 *)&ldr_start, + sizeof(ldr_start), + (u8 *)&ldr_start_ack, + sizeof(ldr_start_ack)); +} + +/** + * load_fw_from_host() Loads ISH firmware from host + * @client_data: Client data instance + * + * This function loads the ISH firmware to ISH SRAM and starts execution + * + * Return: 0 for success, negative error code for failure. + */ +static int load_fw_from_host(struct ishtp_cl_data *client_data) +{ + int rv; + u32 xfer_mode; + char *filename; + const struct firmware *fw; + struct shim_fw_info fw_info; + struct ishtp_cl *loader_ishtp_cl = client_data->loader_ishtp_cl; + + client_data->flag_retry = false; + + filename = kzalloc(FILENAME_SIZE, GFP_KERNEL); + if (!filename) { + client_data->flag_retry = true; + rv = -ENOMEM; + goto end_error; + } + + /* Get filename of the ISH firmware to be loaded */ + rv = get_firmware_variant(client_data, filename); + if (rv < 0) + goto end_err_filename_buf_release; + + rv = request_firmware(&fw, filename, cl_data_to_dev(client_data)); + if (rv < 0) + goto end_err_filename_buf_release; + + /* Step 1: Query Shim firmware loader properties */ + + rv = ish_query_loader_prop(client_data, fw, &fw_info); + if (rv < 0) + goto end_err_fw_release; + + /* Step 2: Send the main firmware image to be loaded, to ISH SRAM */ + + xfer_mode = fw_info.ldr_capability.xfer_mode; + if (xfer_mode & LOADER_XFER_MODE_DIRECT_DMA) { + rv = ish_fw_xfer_direct_dma(client_data, fw, fw_info); + } else if (xfer_mode & LOADER_XFER_MODE_ISHTP) { + rv = ish_fw_xfer_ishtp(client_data, fw); + } else { + dev_err(cl_data_to_dev(client_data), + "No transfer mode selected in firmware\n"); + rv = -EINVAL; + } + if (rv < 0) + goto end_err_fw_release; + + /* Step 3: Start ISH main firmware exeuction */ + + rv = ish_fw_start(client_data); + if (rv < 0) + goto end_err_fw_release; + + release_firmware(fw); + kfree(filename); + dev_info(cl_data_to_dev(client_data), "ISH firmware %s loaded\n", + filename); + return 0; + +end_err_fw_release: + release_firmware(fw); +end_err_filename_buf_release: + kfree(filename); +end_error: + /* Keep a count of retries, and give up after 3 attempts */ + if (client_data->flag_retry && + client_data->retry_count++ < MAX_LOAD_ATTEMPTS) { + dev_warn(cl_data_to_dev(client_data), + "ISH host firmware load failed %d. Resetting ISH, and trying again..\n", + rv); + ish_hw_reset(ishtp_get_ishtp_device(loader_ishtp_cl)); + } else { + dev_err(cl_data_to_dev(client_data), + "ISH host firmware load failed %d\n", rv); + } + return rv; +} + +static void load_fw_from_host_handler(struct work_struct *work) +{ + struct ishtp_cl_data *client_data; + + client_data = container_of(work, struct ishtp_cl_data, + work_fw_load); + load_fw_from_host(client_data); +} + +/** + * loader_init() - Init function for ISH-TP client + * @loader_ishtp_cl: ISH-TP client instance + * @reset: true if called for init after reset + * + * Return: 0 for success, negative error code for failure + */ +static int loader_init(struct ishtp_cl *loader_ishtp_cl, int reset) +{ + int rv; + struct ishtp_fw_client *fw_client; + struct ishtp_cl_data *client_data = + ishtp_get_client_data(loader_ishtp_cl); + + dev_dbg(cl_data_to_dev(client_data), "reset flag: %d\n", reset); + + rv = ishtp_cl_link(loader_ishtp_cl); + if (rv < 0) { + dev_err(cl_data_to_dev(client_data), "ishtp_cl_link failed\n"); + return rv; + } + + /* Connect to firmware client */ + ishtp_set_tx_ring_size(loader_ishtp_cl, LOADER_CL_TX_RING_SIZE); + ishtp_set_rx_ring_size(loader_ishtp_cl, LOADER_CL_RX_RING_SIZE); + + fw_client = + ishtp_fw_cl_get_client(ishtp_get_ishtp_device(loader_ishtp_cl), + &loader_ishtp_guid); + if (!fw_client) { + dev_err(cl_data_to_dev(client_data), + "ISH client uuid not found\n"); + rv = -ENOENT; + goto err_cl_unlink; + } + + ishtp_cl_set_fw_client_id(loader_ishtp_cl, + ishtp_get_fw_client_id(fw_client)); + ishtp_set_connection_state(loader_ishtp_cl, ISHTP_CL_CONNECTING); + + rv = ishtp_cl_connect(loader_ishtp_cl); + if (rv < 0) { + dev_err(cl_data_to_dev(client_data), "Client connect fail\n"); + goto err_cl_unlink; + } + + dev_dbg(cl_data_to_dev(client_data), "Client connected\n"); + + ishtp_register_event_cb(client_data->cl_device, loader_cl_event_cb); + + return 0; + +err_cl_unlink: + ishtp_cl_unlink(loader_ishtp_cl); + return rv; +} + +static void loader_deinit(struct ishtp_cl *loader_ishtp_cl) +{ + ishtp_set_connection_state(loader_ishtp_cl, ISHTP_CL_DISCONNECTING); + ishtp_cl_disconnect(loader_ishtp_cl); + ishtp_cl_unlink(loader_ishtp_cl); + ishtp_cl_flush_queues(loader_ishtp_cl); + + /* Disband and free all Tx and Rx client-level rings */ + ishtp_cl_free(loader_ishtp_cl); +} + +static void reset_handler(struct work_struct *work) +{ + int rv; + struct ishtp_cl_data *client_data; + struct ishtp_cl *loader_ishtp_cl; + struct ishtp_cl_device *cl_device; + + client_data = container_of(work, struct ishtp_cl_data, + work_ishtp_reset); + + loader_ishtp_cl = client_data->loader_ishtp_cl; + cl_device = client_data->cl_device; + + /* Unlink, flush queues & start again */ + ishtp_cl_unlink(loader_ishtp_cl); + ishtp_cl_flush_queues(loader_ishtp_cl); + ishtp_cl_free(loader_ishtp_cl); + + loader_ishtp_cl = ishtp_cl_allocate(cl_device); + if (!loader_ishtp_cl) + return; + + ishtp_set_drvdata(cl_device, loader_ishtp_cl); + ishtp_set_client_data(loader_ishtp_cl, client_data); + client_data->loader_ishtp_cl = loader_ishtp_cl; + client_data->cl_device = cl_device; + + rv = loader_init(loader_ishtp_cl, 1); + if (rv < 0) { + dev_err(ishtp_device(cl_device), "Reset Failed\n"); + return; + } + + /* ISH firmware loading from host */ + load_fw_from_host(client_data); +} + +/** + * loader_ishtp_cl_probe() - ISH-TP client driver probe + * @cl_device: ISH-TP client device instance + * + * This function gets called on device create on ISH-TP bus + * + * Return: 0 for success, negative error code for failure + */ +static int loader_ishtp_cl_probe(struct ishtp_cl_device *cl_device) +{ + struct ishtp_cl *loader_ishtp_cl; + struct ishtp_cl_data *client_data; + int rv; + + client_data = devm_kzalloc(ishtp_device(cl_device), + sizeof(*client_data), + GFP_KERNEL); + if (!client_data) + return -ENOMEM; + + loader_ishtp_cl = ishtp_cl_allocate(cl_device); + if (!loader_ishtp_cl) + return -ENOMEM; + + ishtp_set_drvdata(cl_device, loader_ishtp_cl); + ishtp_set_client_data(loader_ishtp_cl, client_data); + client_data->loader_ishtp_cl = loader_ishtp_cl; + client_data->cl_device = cl_device; + + init_waitqueue_head(&client_data->response.wait_queue); + + INIT_WORK(&client_data->work_ishtp_reset, + reset_handler); + INIT_WORK(&client_data->work_fw_load, + load_fw_from_host_handler); + + rv = loader_init(loader_ishtp_cl, 0); + if (rv < 0) { + ishtp_cl_free(loader_ishtp_cl); + return rv; + } + ishtp_get_device(cl_device); + + client_data->retry_count = 0; + + /* ISH firmware loading from host */ + schedule_work(&client_data->work_fw_load); + + return 0; +} + +/** + * loader_ishtp_cl_remove() - ISH-TP client driver remove + * @cl_device: ISH-TP client device instance + * + * This function gets called on device remove on ISH-TP bus + * + * Return: 0 + */ +static int loader_ishtp_cl_remove(struct ishtp_cl_device *cl_device) +{ + struct ishtp_cl_data *client_data; + struct ishtp_cl *loader_ishtp_cl = ishtp_get_drvdata(cl_device); + + client_data = ishtp_get_client_data(loader_ishtp_cl); + + /* + * The sequence of the following two cancel_work_sync() is + * important. The work_fw_load can in turn schedue + * work_ishtp_reset, so first cancel work_fw_load then + * cancel work_ishtp_reset. + */ + cancel_work_sync(&client_data->work_fw_load); + cancel_work_sync(&client_data->work_ishtp_reset); + loader_deinit(loader_ishtp_cl); + ishtp_put_device(cl_device); + + return 0; +} + +/** + * loader_ishtp_cl_reset() - ISH-TP client driver reset + * @cl_device: ISH-TP client device instance + * + * This function gets called on device reset on ISH-TP bus + * + * Return: 0 + */ +static int loader_ishtp_cl_reset(struct ishtp_cl_device *cl_device) +{ + struct ishtp_cl_data *client_data; + struct ishtp_cl *loader_ishtp_cl = ishtp_get_drvdata(cl_device); + + client_data = ishtp_get_client_data(loader_ishtp_cl); + + schedule_work(&client_data->work_ishtp_reset); + + return 0; +} + +static struct ishtp_cl_driver loader_ishtp_cl_driver = { + .name = "ish-loader", + .guid = &loader_ishtp_guid, + .probe = loader_ishtp_cl_probe, + .remove = loader_ishtp_cl_remove, + .reset = loader_ishtp_cl_reset, +}; + +static int __init ish_loader_init(void) +{ + return ishtp_cl_driver_register(&loader_ishtp_cl_driver, THIS_MODULE); +} + +static void __exit ish_loader_exit(void) +{ + ishtp_cl_driver_unregister(&loader_ishtp_cl_driver); +} + +late_initcall(ish_loader_init); +module_exit(ish_loader_exit); + +module_param(dma_buf_size_limit, int, 0644); +MODULE_PARM_DESC(dma_buf_size_limit, "Limit the DMA buf size to this value in bytes"); + +MODULE_DESCRIPTION("ISH ISH-TP Host firmware Loader Client Driver"); +MODULE_AUTHOR("Rushikesh S Kadam "); + +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("ishtp:*"); -- cgit v1.2.3 From 2eb3c3e6eafb8f3c243b7640335b24da0f340821 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Thu, 4 Apr 2019 08:58:57 +0100 Subject: HID: intel-ish-hid: fix spelling mistake "multipe" -> "multiple" There is a spelling mistake in a dev_err message, fix it. Signed-off-by: Colin Ian King Reviewed-by: Mukesh Ojha Signed-off-by: Benjamin Tissoires --- drivers/hid/intel-ish-hid/ishtp-fw-loader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/hid/intel-ish-hid') diff --git a/drivers/hid/intel-ish-hid/ishtp-fw-loader.c b/drivers/hid/intel-ish-hid/ishtp-fw-loader.c index e770e220bd73..22ba21457035 100644 --- a/drivers/hid/intel-ish-hid/ishtp-fw-loader.c +++ b/drivers/hid/intel-ish-hid/ishtp-fw-loader.c @@ -525,7 +525,7 @@ static int ish_query_loader_prop(struct ishtp_cl_data *client_data, if ((fw_info->ldr_capability.xfer_mode & LOADER_XFER_MODE_DIRECT_DMA) && (fw_info->ldr_capability.max_dma_buf_size % L1_CACHE_BYTES)) { dev_err(cl_data_to_dev(client_data), - "Shim firmware loader buffer size %d should be multipe of cacheline\n", + "Shim firmware loader buffer size %d should be multiple of cacheline\n", fw_info->ldr_capability.max_dma_buf_size); return -EINVAL; } -- cgit v1.2.3