From 29fe7d59bdd8cea561187fca155dbf5cee918bb8 Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Fri, 20 Jan 2017 02:17:16 +0200 Subject: mei: make mei_io_list_flush static mei_io_list_flush is used only in client.c so make it local to the file and mark static. Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/client.c | 2 +- drivers/misc/mei/client.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/misc/mei') diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c index b0395601c6ae..3aaa86235fe0 100644 --- a/drivers/misc/mei/client.c +++ b/drivers/misc/mei/client.c @@ -404,7 +404,7 @@ static void __mei_io_list_flush(struct mei_cl_cb *list, * @list: An instance of our list structure * @cl: host client */ -void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl) +static inline void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl) { __mei_io_list_flush(list, cl, false); } diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h index f2545af9be7b..dc80ad5c9fa2 100644 --- a/drivers/misc/mei/client.h +++ b/drivers/misc/mei/client.h @@ -93,7 +93,6 @@ static inline void mei_io_list_init(struct mei_cl_cb *list) { INIT_LIST_HEAD(&list->list); } -void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl); /* * MEI Host Client Functions -- cgit v1.2.3 From 669c256cb9fb29a540ce4befb4328d88c665e523 Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Fri, 20 Jan 2017 02:17:17 +0200 Subject: mei: make mei_cl_set_disconnected static mei_cl_set_disconnected is used only in client.c, so make it local to the file and mark static. Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/client.c | 2 +- drivers/misc/mei/client.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/misc/mei') diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c index 3aaa86235fe0..da1c0703910a 100644 --- a/drivers/misc/mei/client.c +++ b/drivers/misc/mei/client.c @@ -756,7 +756,7 @@ static void mei_cl_wake_all(struct mei_cl *cl) * * @cl: host client */ -void mei_cl_set_disconnected(struct mei_cl *cl) +static void mei_cl_set_disconnected(struct mei_cl *cl) { struct mei_device *dev = cl->dev; diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h index dc80ad5c9fa2..ab92a542661b 100644 --- a/drivers/misc/mei/client.h +++ b/drivers/misc/mei/client.h @@ -208,7 +208,6 @@ static inline u8 mei_cl_host_addr(const struct mei_cl *cl) } int mei_cl_disconnect(struct mei_cl *cl); -void mei_cl_set_disconnected(struct mei_cl *cl); int mei_cl_irq_disconnect(struct mei_cl *cl, struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list); int mei_cl_connect(struct mei_cl *cl, struct mei_me_client *me_cl, -- cgit v1.2.3 From 9ecb839f16a353e71175981a098842fda4ddc7f1 Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Fri, 27 Jan 2017 16:32:38 +0200 Subject: mei: bus: cancel and disable callback after release call A driver on the mei bus may rely on the availability of the receive callback during driver remove() call, e.g. mei_wdt. Move callbacks dismantling after the remove() call to unblock that scenario. Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/bus.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/misc/mei') diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c index 2d9c5dd06e42..3bb1f1500f6b 100644 --- a/drivers/misc/mei/bus.c +++ b/drivers/misc/mei/bus.c @@ -665,6 +665,10 @@ static int mei_cl_device_remove(struct device *dev) if (!cldev || !dev->driver) return 0; + cldrv = to_mei_cl_driver(dev->driver); + if (cldrv->remove) + ret = cldrv->remove(cldev); + if (cldev->rx_cb) { cancel_work_sync(&cldev->rx_work); cldev->rx_cb = NULL; @@ -674,10 +678,6 @@ static int mei_cl_device_remove(struct device *dev) cldev->notif_cb = NULL; } - cldrv = to_mei_cl_driver(dev->driver); - if (cldrv->remove) - ret = cldrv->remove(cldev); - module_put(THIS_MODULE); dev->driver = NULL; return ret; -- cgit v1.2.3 From 5d88246090c5e9b178eb05bcfb52bbaad2ae48f3 Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Fri, 27 Jan 2017 16:32:39 +0200 Subject: mei: bus: prevent hardware module unload if device on bus is active The hardware module should not be unloaded if the bus has active devices. Get get_/put_ bus parent module upon client device connection/disconnection, to prevent the hardware managing module to disappear underneath. Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/bus.c | 31 +++++++++++++++++++++++++++++++ drivers/misc/mei/client.c | 10 ++++++++-- drivers/misc/mei/mei_dev.h | 2 ++ 3 files changed, 41 insertions(+), 2 deletions(-) (limited to 'drivers/misc/mei') diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c index 3bb1f1500f6b..b67f15b53067 100644 --- a/drivers/misc/mei/bus.c +++ b/drivers/misc/mei/bus.c @@ -541,6 +541,37 @@ out: } EXPORT_SYMBOL_GPL(mei_cldev_disable); +/** + * mei_cl_bus_module_get - acquire module of the underlying + * hw module. + * + * @cl: host client + * + * Return: true on success; false if the module was removed. + */ +bool mei_cl_bus_module_get(struct mei_cl *cl) +{ + struct mei_cl_device *cldev = cl->cldev; + + if (!cldev) + return true; + + return try_module_get(cldev->bus->dev->driver->owner); +} + +/** + * mei_cl_bus_module_put - release the underlying hw module. + * + * @cl: host client + */ +void mei_cl_bus_module_put(struct mei_cl *cl) +{ + struct mei_cl_device *cldev = cl->cldev; + + if (cldev) + module_put(cldev->bus->dev->driver->owner); +} + /** * mei_cl_device_find - find matching entry in the driver id table * diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c index da1c0703910a..619b4702347f 100644 --- a/drivers/misc/mei/client.c +++ b/drivers/misc/mei/client.c @@ -774,6 +774,8 @@ static void mei_cl_set_disconnected(struct mei_cl *cl) cl->tx_flow_ctrl_creds = 0; cl->timer_count = 0; + mei_cl_bus_module_put(cl); + if (!cl->me_cl) return; @@ -1077,13 +1079,17 @@ int mei_cl_connect(struct mei_cl *cl, struct mei_me_client *me_cl, dev = cl->dev; + if (!mei_cl_bus_module_get(cl)) + return -ENODEV; + rets = mei_cl_set_connecting(cl, me_cl); if (rets) - return rets; + goto nortpm; if (mei_cl_is_fixed_address(cl)) { cl->state = MEI_FILE_CONNECTED; - return 0; + rets = 0; + goto nortpm; } rets = pm_runtime_get(dev->dev); diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h index 8dadb98662a9..33ff4b7e356d 100644 --- a/drivers/misc/mei/mei_dev.h +++ b/drivers/misc/mei/mei_dev.h @@ -328,6 +328,8 @@ ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length, bool mei_cl_bus_rx_event(struct mei_cl *cl); bool mei_cl_bus_notify_event(struct mei_cl *cl); void mei_cl_bus_remove_devices(struct mei_device *bus); +bool mei_cl_bus_module_get(struct mei_cl *cl); +void mei_cl_bus_module_put(struct mei_cl *cl); int mei_cl_bus_init(void); void mei_cl_bus_exit(void); -- cgit v1.2.3 From 57080e88240a46c62cf7538de009545eb03d2568 Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Fri, 27 Jan 2017 16:32:40 +0200 Subject: mei: bus: unregister callbacks upon me client disable call Stop and unregister receive and notification callbacks from the disable function, to allow its later re-enablement. Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/bus.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'drivers/misc/mei') diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c index b67f15b53067..cb3e9e0ca049 100644 --- a/drivers/misc/mei/bus.c +++ b/drivers/misc/mei/bus.c @@ -498,6 +498,25 @@ out: } EXPORT_SYMBOL_GPL(mei_cldev_enable); +/** + * mei_cldev_unregister_callbacks - internal wrapper for unregistering + * callbacks. + * + * @cldev: client device + */ +static void mei_cldev_unregister_callbacks(struct mei_cl_device *cldev) +{ + if (cldev->rx_cb) { + cancel_work_sync(&cldev->rx_work); + cldev->rx_cb = NULL; + } + + if (cldev->notif_cb) { + cancel_work_sync(&cldev->notif_work); + cldev->notif_cb = NULL; + } +} + /** * mei_cldev_disable - disable me client device * disconnect form the me client @@ -519,6 +538,8 @@ int mei_cldev_disable(struct mei_cl_device *cldev) bus = cldev->bus; + mei_cldev_unregister_callbacks(cldev); + mutex_lock(&bus->device_lock); if (!mei_cl_is_connected(cl)) { @@ -700,14 +721,7 @@ static int mei_cl_device_remove(struct device *dev) if (cldrv->remove) ret = cldrv->remove(cldev); - if (cldev->rx_cb) { - cancel_work_sync(&cldev->rx_work); - cldev->rx_cb = NULL; - } - if (cldev->notif_cb) { - cancel_work_sync(&cldev->notif_work); - cldev->notif_cb = NULL; - } + mei_cldev_unregister_callbacks(cldev); module_put(THIS_MODULE); dev->driver = NULL; -- cgit v1.2.3 From 7c47d2ca0feca767479329da23523ed798acb854 Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Fri, 27 Jan 2017 16:32:41 +0200 Subject: mei: return error on notification request to a disconnected client Request for a notification from a disconnected client will be ignored silently by the FW but the caller should know that the operation hasn't succeeded. Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/client.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/misc/mei') diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c index 619b4702347f..ecfaef93457d 100644 --- a/drivers/misc/mei/client.c +++ b/drivers/misc/mei/client.c @@ -1331,6 +1331,9 @@ int mei_cl_notify_request(struct mei_cl *cl, return -EOPNOTSUPP; } + if (!mei_cl_is_connected(cl)) + return -ENODEV; + rets = pm_runtime_get(dev->dev); if (rets < 0 && rets != -EINPROGRESS) { pm_runtime_put_noidle(dev->dev); -- cgit v1.2.3 From 6c0d6701a551ac344e63935535db0494110c5f4e Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Fri, 27 Jan 2017 16:32:42 +0200 Subject: mei: abort waiting for notification on unsupported HW On legacy HW, pre Skylake, the notifications are not supported, return -EOPNOTSUPP in mei_cl_notify_get and prevent waiting indefinitely. Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/client.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'drivers/misc/mei') diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c index ecfaef93457d..923fad39535c 100644 --- a/drivers/misc/mei/client.c +++ b/drivers/misc/mei/client.c @@ -1428,6 +1428,11 @@ int mei_cl_notify_get(struct mei_cl *cl, bool block, bool *notify_ev) dev = cl->dev; + if (!dev->hbm_f_ev_supported) { + cl_dbg(dev, cl, "notifications not supported\n"); + return -EOPNOTSUPP; + } + if (!mei_cl_is_connected(cl)) return -ENODEV; -- cgit v1.2.3 From 6537ae2f20412dd1c7464272dfff77d5afb50d25 Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Fri, 27 Jan 2017 16:32:43 +0200 Subject: mei: amthif: clean command queue upon disconnection In order to prevent memory leak clean up the amthif command queue upon disconnection. The issue may happen only on error path as the command queue is cleaned upon file descriptor close. And remove the cleanup from mei_cl_flush_queues as this code is never reached for amthif client. Signed-off-by: Tomas Winkler Signed-off-by: Alexander Usyskin Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/misc/mei') diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c index 923fad39535c..d9e3e68bab89 100644 --- a/drivers/misc/mei/client.c +++ b/drivers/misc/mei/client.c @@ -546,7 +546,6 @@ int mei_cl_flush_queues(struct mei_cl *cl, const struct file *fp) mei_io_list_free(&cl->dev->write_waiting_list, cl); mei_io_list_flush(&cl->dev->ctrl_wr_list, cl); mei_io_list_flush(&cl->dev->ctrl_rd_list, cl); - mei_io_list_flush(&cl->dev->amthif_cmd_list, cl); mei_cl_read_cb_flush(cl, fp); @@ -769,6 +768,7 @@ static void mei_cl_set_disconnected(struct mei_cl *cl) mei_io_list_free(&dev->write_waiting_list, cl); mei_io_list_flush(&dev->ctrl_rd_list, cl); mei_io_list_flush(&dev->ctrl_wr_list, cl); + mei_io_list_free(&dev->amthif_cmd_list, cl); mei_cl_wake_all(cl); cl->rx_flow_ctrl_creds = 0; cl->tx_flow_ctrl_creds = 0; -- cgit v1.2.3 From 9ecdbc58f96bd145669510822bc44eafde3c7351 Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Fri, 27 Jan 2017 16:32:44 +0200 Subject: mei: amthif: allow the read completion after close The amthif client connection is shared over multiple file descriptors. In case a file descriptor was closed immediately after a write, the read credits should be still available so the pending reads can be cleaned from the queue, hence we cannot drop the control read list, this is done only upon connection close. Signed-off-by: Tomas Winkler Signed-off-by: Alexander Usyskin Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/amthif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/misc/mei') diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c index 466afb2611c6..2d553cd6d4d0 100644 --- a/drivers/misc/mei/amthif.c +++ b/drivers/misc/mei/amthif.c @@ -353,9 +353,9 @@ int mei_amthif_release(struct mei_device *dev, struct file *file) dev->iamthif_canceled = true; } + /* Don't clean ctrl_rd_list here, the reads has to be completed */ mei_clear_list(file, &dev->amthif_cmd_list.list); mei_clear_list(file, &cl->rd_completed); - mei_clear_list(file, &dev->ctrl_rd_list.list); return 0; } -- cgit v1.2.3 From 962ff7bcec243dc5ff6dd3cbad6ed585e3177556 Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Fri, 27 Jan 2017 16:32:45 +0200 Subject: mei: replace callback structures used as list head by list_head mei_dev structure used struct mei_cl_cb type variables as for holding callbacks list heads. Replace them by the actual struct list_head as there is no other info that is handled. This slims down the mei_dev structure and mostly streamline the code. Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/amthif.c | 11 +++++----- drivers/misc/mei/client.c | 52 ++++++++++++++++++++++---------------------- drivers/misc/mei/client.h | 20 +++++------------ drivers/misc/mei/hbm.c | 2 +- drivers/misc/mei/hw-me.c | 10 ++++----- drivers/misc/mei/hw-txe.c | 10 ++++----- drivers/misc/mei/init.c | 22 +++++++++---------- drivers/misc/mei/interrupt.c | 36 +++++++++++++++--------------- drivers/misc/mei/mei_dev.h | 20 ++++++++--------- 9 files changed, 85 insertions(+), 98 deletions(-) (limited to 'drivers/misc/mei') diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c index 2d553cd6d4d0..366ef1fe9b90 100644 --- a/drivers/misc/mei/amthif.c +++ b/drivers/misc/mei/amthif.c @@ -132,8 +132,7 @@ int mei_amthif_run_next_cmd(struct mei_device *dev) dev_dbg(dev->dev, "complete amthif cmd_list cb.\n"); - cb = list_first_entry_or_null(&dev->amthif_cmd_list.list, - typeof(*cb), list); + cb = list_first_entry_or_null(&dev->amthif_cmd_list, typeof(*cb), list); if (!cb) { dev->iamthif_state = MEI_IAMTHIF_IDLE; cl->fp = NULL; @@ -167,7 +166,7 @@ int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb) struct mei_device *dev = cl->dev; - list_add_tail(&cb->list, &dev->amthif_cmd_list.list); + list_add_tail(&cb->list, &dev->amthif_cmd_list); /* * The previous request is still in processing, queue this one. @@ -211,7 +210,7 @@ unsigned int mei_amthif_poll(struct file *file, poll_table *wait) * Return: 0, OK; otherwise, error. */ int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, - struct mei_cl_cb *cmpl_list) + struct list_head *cmpl_list) { int ret; @@ -237,7 +236,7 @@ int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, */ int mei_amthif_irq_read_msg(struct mei_cl *cl, struct mei_msg_hdr *mei_hdr, - struct mei_cl_cb *cmpl_list) + struct list_head *cmpl_list) { struct mei_device *dev; int ret; @@ -354,7 +353,7 @@ int mei_amthif_release(struct mei_device *dev, struct file *file) } /* Don't clean ctrl_rd_list here, the reads has to be completed */ - mei_clear_list(file, &dev->amthif_cmd_list.list); + mei_clear_list(file, &dev->amthif_cmd_list); mei_clear_list(file, &cl->rd_completed); return 0; diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c index d9e3e68bab89..838a4a349f9e 100644 --- a/drivers/misc/mei/client.c +++ b/drivers/misc/mei/client.c @@ -379,17 +379,17 @@ static struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, /** * __mei_io_list_flush - removes and frees cbs belonging to cl. * - * @list: an instance of our list structure + * @head: an instance of our list structure * @cl: host client, can be NULL for flushing the whole list * @free: whether to free the cbs */ -static void __mei_io_list_flush(struct mei_cl_cb *list, +static void __mei_io_list_flush(struct list_head *head, struct mei_cl *cl, bool free) { struct mei_cl_cb *cb, *next; /* enable removing everything if no cl is specified */ - list_for_each_entry_safe(cb, next, &list->list, list) { + list_for_each_entry_safe(cb, next, head, list) { if (!cl || mei_cl_cmp_id(cl, cb->cl)) { list_del_init(&cb->list); if (free) @@ -401,23 +401,23 @@ static void __mei_io_list_flush(struct mei_cl_cb *list, /** * mei_io_list_flush - removes list entry belonging to cl. * - * @list: An instance of our list structure + * @head: An instance of our list structure * @cl: host client */ -static inline void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl) +static inline void mei_io_list_flush(struct list_head *head, struct mei_cl *cl) { - __mei_io_list_flush(list, cl, false); + __mei_io_list_flush(head, cl, false); } /** * mei_io_list_free - removes cb belonging to cl and free them * - * @list: An instance of our list structure + * @head: An instance of our list structure * @cl: host client */ -static inline void mei_io_list_free(struct mei_cl_cb *list, struct mei_cl *cl) +static inline void mei_io_list_free(struct list_head *head, struct mei_cl *cl) { - __mei_io_list_flush(list, cl, true); + __mei_io_list_flush(head, cl, true); } /** @@ -479,7 +479,7 @@ struct mei_cl_cb *mei_cl_enqueue_ctrl_wr_cb(struct mei_cl *cl, size_t length, if (!cb) return NULL; - list_add_tail(&cb->list, &cl->dev->ctrl_wr_list.list); + list_add_tail(&cb->list, &cl->dev->ctrl_wr_list); return cb; } @@ -831,7 +831,7 @@ static int mei_cl_send_disconnect(struct mei_cl *cl, struct mei_cl_cb *cb) return ret; } - list_move_tail(&cb->list, &dev->ctrl_rd_list.list); + list_move_tail(&cb->list, &dev->ctrl_rd_list); cl->timer_count = MEI_CONNECT_TIMEOUT; mei_schedule_stall_timer(dev); @@ -849,7 +849,7 @@ static int mei_cl_send_disconnect(struct mei_cl *cl, struct mei_cl_cb *cb) * Return: 0, OK; otherwise, error. */ int mei_cl_irq_disconnect(struct mei_cl *cl, struct mei_cl_cb *cb, - struct mei_cl_cb *cmpl_list) + struct list_head *cmpl_list) { struct mei_device *dev = cl->dev; u32 msg_slots; @@ -864,7 +864,7 @@ int mei_cl_irq_disconnect(struct mei_cl *cl, struct mei_cl_cb *cb, ret = mei_cl_send_disconnect(cl, cb); if (ret) - list_move_tail(&cb->list, &cmpl_list->list); + list_move_tail(&cb->list, cmpl_list); return ret; } @@ -986,7 +986,7 @@ static bool mei_cl_is_other_connecting(struct mei_cl *cl) dev = cl->dev; - list_for_each_entry(cb, &dev->ctrl_rd_list.list, list) { + list_for_each_entry(cb, &dev->ctrl_rd_list, list) { if (cb->fop_type == MEI_FOP_CONNECT && mei_cl_me_id(cl) == mei_cl_me_id(cb->cl)) return true; @@ -1017,7 +1017,7 @@ static int mei_cl_send_connect(struct mei_cl *cl, struct mei_cl_cb *cb) return ret; } - list_move_tail(&cb->list, &dev->ctrl_rd_list.list); + list_move_tail(&cb->list, &dev->ctrl_rd_list); cl->timer_count = MEI_CONNECT_TIMEOUT; mei_schedule_stall_timer(dev); return 0; @@ -1033,7 +1033,7 @@ static int mei_cl_send_connect(struct mei_cl *cl, struct mei_cl_cb *cb) * Return: 0, OK; otherwise, error. */ int mei_cl_irq_connect(struct mei_cl *cl, struct mei_cl_cb *cb, - struct mei_cl_cb *cmpl_list) + struct list_head *cmpl_list) { struct mei_device *dev = cl->dev; u32 msg_slots; @@ -1051,7 +1051,7 @@ int mei_cl_irq_connect(struct mei_cl *cl, struct mei_cl_cb *cb, rets = mei_cl_send_connect(cl, cb); if (rets) - list_move_tail(&cb->list, &cmpl_list->list); + list_move_tail(&cb->list, cmpl_list); return rets; } @@ -1276,7 +1276,7 @@ enum mei_cb_file_ops mei_cl_notify_req2fop(u8 req) * Return: 0 on such and error otherwise. */ int mei_cl_irq_notify(struct mei_cl *cl, struct mei_cl_cb *cb, - struct mei_cl_cb *cmpl_list) + struct list_head *cmpl_list) { struct mei_device *dev = cl->dev; u32 msg_slots; @@ -1294,11 +1294,11 @@ int mei_cl_irq_notify(struct mei_cl *cl, struct mei_cl_cb *cb, ret = mei_hbm_cl_notify_req(dev, cl, request); if (ret) { cl->status = ret; - list_move_tail(&cb->list, &cmpl_list->list); + list_move_tail(&cb->list, cmpl_list); return ret; } - list_move_tail(&cb->list, &dev->ctrl_rd_list.list); + list_move_tail(&cb->list, &dev->ctrl_rd_list); return 0; } @@ -1353,7 +1353,7 @@ int mei_cl_notify_request(struct mei_cl *cl, rets = -ENODEV; goto out; } - list_move_tail(&cb->list, &dev->ctrl_rd_list.list); + list_move_tail(&cb->list, &dev->ctrl_rd_list); } mutex_unlock(&dev->device_lock); @@ -1533,7 +1533,7 @@ nortpm: * Return: 0, OK; otherwise error. */ int mei_cl_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, - struct mei_cl_cb *cmpl_list) + struct list_head *cmpl_list) { struct mei_device *dev; struct mei_msg_data *buf; @@ -1605,13 +1605,13 @@ int mei_cl_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, } if (mei_hdr.msg_complete) - list_move_tail(&cb->list, &dev->write_waiting_list.list); + list_move_tail(&cb->list, &dev->write_waiting_list); return 0; err: cl->status = rets; - list_move_tail(&cb->list, &cmpl_list->list); + list_move_tail(&cb->list, cmpl_list); return rets; } @@ -1701,9 +1701,9 @@ int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb) out: if (mei_hdr.msg_complete) - list_add_tail(&cb->list, &dev->write_waiting_list.list); + list_add_tail(&cb->list, &dev->write_waiting_list); else - list_add_tail(&cb->list, &dev->write_list.list); + list_add_tail(&cb->list, &dev->write_list); cb = NULL; if (blocking && cl->writing_state != MEI_WRITE_COMPLETE) { diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h index ab92a542661b..f48cfa026268 100644 --- a/drivers/misc/mei/client.h +++ b/drivers/misc/mei/client.h @@ -84,16 +84,6 @@ static inline u8 mei_me_cl_ver(const struct mei_me_client *me_cl) */ void mei_io_cb_free(struct mei_cl_cb *priv_cb); -/** - * mei_io_list_init - Sets up a queue list. - * - * @list: An instance cl callback structure - */ -static inline void mei_io_list_init(struct mei_cl_cb *list) -{ - INIT_LIST_HEAD(&list->list); -} - /* * MEI Host Client Functions */ @@ -209,17 +199,17 @@ static inline u8 mei_cl_host_addr(const struct mei_cl *cl) int mei_cl_disconnect(struct mei_cl *cl); int mei_cl_irq_disconnect(struct mei_cl *cl, struct mei_cl_cb *cb, - struct mei_cl_cb *cmpl_list); + struct list_head *cmpl_list); int mei_cl_connect(struct mei_cl *cl, struct mei_me_client *me_cl, const struct file *file); int mei_cl_irq_connect(struct mei_cl *cl, struct mei_cl_cb *cb, - struct mei_cl_cb *cmpl_list); + struct list_head *cmpl_list); int mei_cl_read_start(struct mei_cl *cl, size_t length, const struct file *fp); int mei_cl_irq_read_msg(struct mei_cl *cl, struct mei_msg_hdr *hdr, - struct mei_cl_cb *cmpl_list); + struct list_head *cmpl_list); int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb); int mei_cl_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, - struct mei_cl_cb *cmpl_list); + struct list_head *cmpl_list); void mei_cl_complete(struct mei_cl *cl, struct mei_cl_cb *cb); @@ -230,7 +220,7 @@ enum mei_cb_file_ops mei_cl_notify_req2fop(u8 request); int mei_cl_notify_request(struct mei_cl *cl, const struct file *file, u8 request); int mei_cl_irq_notify(struct mei_cl *cl, struct mei_cl_cb *cb, - struct mei_cl_cb *cmpl_list); + struct list_head *cmpl_list); int mei_cl_notify_get(struct mei_cl *cl, bool block, bool *notify_ev); void mei_cl_notify(struct mei_cl *cl); diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c index 25b4a1ba522d..ba3a774c8d71 100644 --- a/drivers/misc/mei/hbm.c +++ b/drivers/misc/mei/hbm.c @@ -815,7 +815,7 @@ static void mei_hbm_cl_res(struct mei_device *dev, struct mei_cl_cb *cb, *next; cl = NULL; - list_for_each_entry_safe(cb, next, &dev->ctrl_rd_list.list, list) { + list_for_each_entry_safe(cb, next, &dev->ctrl_rd_list, list) { cl = cb->cl; diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c index a05375a3338a..06a579952e3f 100644 --- a/drivers/misc/mei/hw-me.c +++ b/drivers/misc/mei/hw-me.c @@ -1189,7 +1189,7 @@ irqreturn_t mei_me_irq_quick_handler(int irq, void *dev_id) irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id) { struct mei_device *dev = (struct mei_device *) dev_id; - struct mei_cl_cb complete_list; + struct list_head cmpl_list; s32 slots; u32 hcsr; int rets = 0; @@ -1201,7 +1201,7 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id) hcsr = mei_hcsr_read(dev); me_intr_clear(dev, hcsr); - mei_io_list_init(&complete_list); + INIT_LIST_HEAD(&cmpl_list); /* check if ME wants a reset */ if (!mei_hw_is_ready(dev) && dev->dev_state != MEI_DEV_RESETTING) { @@ -1227,7 +1227,7 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id) slots = mei_count_full_read_slots(dev); while (slots > 0) { dev_dbg(dev->dev, "slots to read = %08x\n", slots); - rets = mei_irq_read_handler(dev, &complete_list, &slots); + rets = mei_irq_read_handler(dev, &cmpl_list, &slots); /* There is a race between ME write and interrupt delivery: * Not all data is always available immediately after the * interrupt, so try to read again on the next interrupt. @@ -1252,11 +1252,11 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id) */ if (dev->pg_event != MEI_PG_EVENT_WAIT && dev->pg_event != MEI_PG_EVENT_RECEIVED) { - rets = mei_irq_write_handler(dev, &complete_list); + rets = mei_irq_write_handler(dev, &cmpl_list); dev->hbuf_is_ready = mei_hbuf_is_ready(dev); } - mei_irq_compl_handler(dev, &complete_list); + mei_irq_compl_handler(dev, &cmpl_list); end: dev_dbg(dev->dev, "interrupt thread end ret = %d\n", rets); diff --git a/drivers/misc/mei/hw-txe.c b/drivers/misc/mei/hw-txe.c index e9f8c0aeec13..6259b11d440c 100644 --- a/drivers/misc/mei/hw-txe.c +++ b/drivers/misc/mei/hw-txe.c @@ -1057,7 +1057,7 @@ irqreturn_t mei_txe_irq_thread_handler(int irq, void *dev_id) { struct mei_device *dev = (struct mei_device *) dev_id; struct mei_txe_hw *hw = to_txe_hw(dev); - struct mei_cl_cb complete_list; + struct list_head cmpl_list; s32 slots; int rets = 0; @@ -1069,7 +1069,7 @@ irqreturn_t mei_txe_irq_thread_handler(int irq, void *dev_id) /* initialize our complete list */ mutex_lock(&dev->device_lock); - mei_io_list_init(&complete_list); + INIT_LIST_HEAD(&cmpl_list); if (pci_dev_msi_enabled(to_pci_dev(dev->dev))) mei_txe_check_and_ack_intrs(dev, true); @@ -1126,7 +1126,7 @@ irqreturn_t mei_txe_irq_thread_handler(int irq, void *dev_id) slots = mei_count_full_read_slots(dev); if (test_and_clear_bit(TXE_INTR_OUT_DB_BIT, &hw->intr_cause)) { /* Read from TXE */ - rets = mei_irq_read_handler(dev, &complete_list, &slots); + rets = mei_irq_read_handler(dev, &cmpl_list, &slots); if (rets && dev->dev_state != MEI_DEV_RESETTING) { dev_err(dev->dev, "mei_irq_read_handler ret = %d.\n", rets); @@ -1144,14 +1144,14 @@ irqreturn_t mei_txe_irq_thread_handler(int irq, void *dev_id) if (hw->aliveness && dev->hbuf_is_ready) { /* get the real register value */ dev->hbuf_is_ready = mei_hbuf_is_ready(dev); - rets = mei_irq_write_handler(dev, &complete_list); + rets = mei_irq_write_handler(dev, &cmpl_list); if (rets && rets != -EMSGSIZE) dev_err(dev->dev, "mei_irq_write_handler ret = %d.\n", rets); dev->hbuf_is_ready = mei_hbuf_is_ready(dev); } - mei_irq_compl_handler(dev, &complete_list); + mei_irq_compl_handler(dev, &cmpl_list); end: dev_dbg(dev->dev, "interrupt thread end ret = %d\n", rets); diff --git a/drivers/misc/mei/init.c b/drivers/misc/mei/init.c index 41e5760a6886..cfb1cdf176fa 100644 --- a/drivers/misc/mei/init.c +++ b/drivers/misc/mei/init.c @@ -349,16 +349,16 @@ EXPORT_SYMBOL_GPL(mei_stop); bool mei_write_is_idle(struct mei_device *dev) { bool idle = (dev->dev_state == MEI_DEV_ENABLED && - list_empty(&dev->ctrl_wr_list.list) && - list_empty(&dev->write_list.list) && - list_empty(&dev->write_waiting_list.list)); + list_empty(&dev->ctrl_wr_list) && + list_empty(&dev->write_list) && + list_empty(&dev->write_waiting_list)); dev_dbg(dev->dev, "write pg: is idle[%d] state=%s ctrl=%01d write=%01d wwait=%01d\n", idle, mei_dev_state_str(dev->dev_state), - list_empty(&dev->ctrl_wr_list.list), - list_empty(&dev->write_list.list), - list_empty(&dev->write_waiting_list.list)); + list_empty(&dev->ctrl_wr_list), + list_empty(&dev->write_list), + list_empty(&dev->write_waiting_list)); return idle; } @@ -388,17 +388,17 @@ void mei_device_init(struct mei_device *dev, dev->dev_state = MEI_DEV_INITIALIZING; dev->reset_count = 0; - mei_io_list_init(&dev->write_list); - mei_io_list_init(&dev->write_waiting_list); - mei_io_list_init(&dev->ctrl_wr_list); - mei_io_list_init(&dev->ctrl_rd_list); + INIT_LIST_HEAD(&dev->write_list); + INIT_LIST_HEAD(&dev->write_waiting_list); + INIT_LIST_HEAD(&dev->ctrl_wr_list); + INIT_LIST_HEAD(&dev->ctrl_rd_list); INIT_DELAYED_WORK(&dev->timer_work, mei_timer); INIT_WORK(&dev->reset_work, mei_reset_work); INIT_WORK(&dev->bus_rescan_work, mei_cl_bus_rescan_work); INIT_LIST_HEAD(&dev->iamthif_cl.link); - mei_io_list_init(&dev->amthif_cmd_list); + INIT_LIST_HEAD(&dev->amthif_cmd_list); bitmap_zero(dev->host_clients_map, MEI_CLIENTS_MAX); dev->open_handle_count = 0; diff --git a/drivers/misc/mei/interrupt.c b/drivers/misc/mei/interrupt.c index b584749bcc4a..406e9e2b2fff 100644 --- a/drivers/misc/mei/interrupt.c +++ b/drivers/misc/mei/interrupt.c @@ -35,14 +35,14 @@ * for the completed callbacks * * @dev: mei device - * @compl_list: list of completed cbs + * @cmpl_list: list of completed cbs */ -void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *compl_list) +void mei_irq_compl_handler(struct mei_device *dev, struct list_head *cmpl_list) { struct mei_cl_cb *cb, *next; struct mei_cl *cl; - list_for_each_entry_safe(cb, next, &compl_list->list, list) { + list_for_each_entry_safe(cb, next, cmpl_list, list) { cl = cb->cl; list_del_init(&cb->list); @@ -92,13 +92,13 @@ void mei_irq_discard_msg(struct mei_device *dev, struct mei_msg_hdr *hdr) * * @cl: reading client * @mei_hdr: header of mei client message - * @complete_list: completion list + * @cmpl_list: completion list * * Return: always 0 */ int mei_cl_irq_read_msg(struct mei_cl *cl, struct mei_msg_hdr *mei_hdr, - struct mei_cl_cb *complete_list) + struct list_head *cmpl_list) { struct mei_device *dev = cl->dev; struct mei_cl_cb *cb; @@ -144,7 +144,7 @@ int mei_cl_irq_read_msg(struct mei_cl *cl, if (mei_hdr->msg_complete) { cl_dbg(dev, cl, "completed read length = %zu\n", cb->buf_idx); - list_move_tail(&cb->list, &complete_list->list); + list_move_tail(&cb->list, cmpl_list); } else { pm_runtime_mark_last_busy(dev->dev); pm_request_autosuspend(dev->dev); @@ -154,7 +154,7 @@ int mei_cl_irq_read_msg(struct mei_cl *cl, discard: if (cb) - list_move_tail(&cb->list, &complete_list->list); + list_move_tail(&cb->list, cmpl_list); mei_irq_discard_msg(dev, mei_hdr); return 0; } @@ -169,7 +169,7 @@ discard: * Return: 0, OK; otherwise, error. */ static int mei_cl_irq_disconnect_rsp(struct mei_cl *cl, struct mei_cl_cb *cb, - struct mei_cl_cb *cmpl_list) + struct list_head *cmpl_list) { struct mei_device *dev = cl->dev; u32 msg_slots; @@ -183,7 +183,7 @@ static int mei_cl_irq_disconnect_rsp(struct mei_cl *cl, struct mei_cl_cb *cb, return -EMSGSIZE; ret = mei_hbm_cl_disconnect_rsp(dev, cl); - list_move_tail(&cb->list, &cmpl_list->list); + list_move_tail(&cb->list, cmpl_list); return ret; } @@ -199,7 +199,7 @@ static int mei_cl_irq_disconnect_rsp(struct mei_cl *cl, struct mei_cl_cb *cb, * Return: 0, OK; otherwise, error. */ static int mei_cl_irq_read(struct mei_cl *cl, struct mei_cl_cb *cb, - struct mei_cl_cb *cmpl_list) + struct list_head *cmpl_list) { struct mei_device *dev = cl->dev; u32 msg_slots; @@ -219,7 +219,7 @@ static int mei_cl_irq_read(struct mei_cl *cl, struct mei_cl_cb *cb, if (ret) { cl->status = ret; cb->buf_idx = 0; - list_move_tail(&cb->list, &cmpl_list->list); + list_move_tail(&cb->list, cmpl_list); return ret; } @@ -249,7 +249,7 @@ static inline bool hdr_is_fixed(struct mei_msg_hdr *mei_hdr) * Return: 0 on success, <0 on failure. */ int mei_irq_read_handler(struct mei_device *dev, - struct mei_cl_cb *cmpl_list, s32 *slots) + struct list_head *cmpl_list, s32 *slots) { struct mei_msg_hdr *mei_hdr; struct mei_cl *cl; @@ -347,12 +347,11 @@ EXPORT_SYMBOL_GPL(mei_irq_read_handler); * * Return: 0 on success, <0 on failure. */ -int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list) +int mei_irq_write_handler(struct mei_device *dev, struct list_head *cmpl_list) { struct mei_cl *cl; struct mei_cl_cb *cb, *next; - struct mei_cl_cb *list; s32 slots; int ret; @@ -367,19 +366,18 @@ int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list) /* complete all waiting for write CB */ dev_dbg(dev->dev, "complete all waiting for write cb.\n"); - list = &dev->write_waiting_list; - list_for_each_entry_safe(cb, next, &list->list, list) { + list_for_each_entry_safe(cb, next, &dev->write_waiting_list, list) { cl = cb->cl; cl->status = 0; cl_dbg(dev, cl, "MEI WRITE COMPLETE\n"); cl->writing_state = MEI_WRITE_COMPLETE; - list_move_tail(&cb->list, &cmpl_list->list); + list_move_tail(&cb->list, cmpl_list); } /* complete control write list CB */ dev_dbg(dev->dev, "complete control write list cb.\n"); - list_for_each_entry_safe(cb, next, &dev->ctrl_wr_list.list, list) { + list_for_each_entry_safe(cb, next, &dev->ctrl_wr_list, list) { cl = cb->cl; switch (cb->fop_type) { case MEI_FOP_DISCONNECT: @@ -423,7 +421,7 @@ int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list) } /* complete write list CB */ dev_dbg(dev->dev, "complete write list cb.\n"); - list_for_each_entry_safe(cb, next, &dev->write_list.list, list) { + list_for_each_entry_safe(cb, next, &dev->write_list, list) { cl = cb->cl; if (cl == &dev->iamthif_cl) ret = mei_amthif_irq_write(cl, cb, cmpl_list); diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h index 33ff4b7e356d..d41aac53a2ac 100644 --- a/drivers/misc/mei/mei_dev.h +++ b/drivers/misc/mei/mei_dev.h @@ -441,10 +441,10 @@ struct mei_device { struct cdev cdev; int minor; - struct mei_cl_cb write_list; - struct mei_cl_cb write_waiting_list; - struct mei_cl_cb ctrl_wr_list; - struct mei_cl_cb ctrl_rd_list; + struct list_head write_list; + struct list_head write_waiting_list; + struct list_head ctrl_wr_list; + struct list_head ctrl_rd_list; struct list_head file_list; long open_handle_count; @@ -501,7 +501,7 @@ struct mei_device { bool override_fixed_address; /* amthif list for cmd waiting */ - struct mei_cl_cb amthif_cmd_list; + struct list_head amthif_cmd_list; struct mei_cl iamthif_cl; long iamthif_open_count; u32 iamthif_stall_timer; @@ -573,10 +573,10 @@ void mei_cancel_work(struct mei_device *dev); void mei_timer(struct work_struct *work); void mei_schedule_stall_timer(struct mei_device *dev); int mei_irq_read_handler(struct mei_device *dev, - struct mei_cl_cb *cmpl_list, s32 *slots); + struct list_head *cmpl_list, s32 *slots); -int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list); -void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list); +int mei_irq_write_handler(struct mei_device *dev, struct list_head *cmpl_list); +void mei_irq_compl_handler(struct mei_device *dev, struct list_head *cmpl_list); /* * AMTHIF - AMT Host Interface Functions @@ -592,12 +592,12 @@ int mei_amthif_release(struct mei_device *dev, struct file *file); int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb); int mei_amthif_run_next_cmd(struct mei_device *dev); int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, - struct mei_cl_cb *cmpl_list); + struct list_head *cmpl_list); void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb); int mei_amthif_irq_read_msg(struct mei_cl *cl, struct mei_msg_hdr *mei_hdr, - struct mei_cl_cb *complete_list); + struct list_head *cmpl_list); int mei_amthif_irq_read(struct mei_device *dev, s32 *slots); /* -- cgit v1.2.3 From f046192d98c9a929c3eefdd65b885000d341d969 Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Fri, 27 Jan 2017 16:32:46 +0200 Subject: mei: revamp io list cleanup function. Specify in function names by which object is the io list filtered: cl for a client and fp for file descriptor. In that course a code duplication is resolved by dropping mei_cl_read_cb_flush and mei_clear_list and using mei_io_list_free_fp function. Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/amthif.c | 34 ++++--------------- drivers/misc/mei/client.c | 83 ++++++++++++++++++++++------------------------- drivers/misc/mei/client.h | 2 +- 3 files changed, 47 insertions(+), 72 deletions(-) (limited to 'drivers/misc/mei') diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c index 366ef1fe9b90..0e7406ccb6dd 100644 --- a/drivers/misc/mei/amthif.c +++ b/drivers/misc/mei/amthif.c @@ -310,51 +310,31 @@ void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb) } } -/** - * mei_clear_list - removes all callbacks associated with file - * from mei_cb_list - * - * @file: file structure - * @mei_cb_list: callbacks list - * - * mei_clear_list is called to clear resources associated with file - * when application calls close function or Ctrl-C was pressed - */ -static void mei_clear_list(const struct file *file, - struct list_head *mei_cb_list) -{ - struct mei_cl_cb *cb, *next; - - list_for_each_entry_safe(cb, next, mei_cb_list, list) - if (file == cb->fp) - mei_io_cb_free(cb); -} - /** * mei_amthif_release - the release function * * @dev: device structure -* @file: pointer to file structure +* @fp: pointer to file structure * * Return: 0 on success, <0 on error */ -int mei_amthif_release(struct mei_device *dev, struct file *file) +int mei_amthif_release(struct mei_device *dev, struct file *fp) { - struct mei_cl *cl = file->private_data; + struct mei_cl *cl = fp->private_data; if (dev->iamthif_open_count > 0) dev->iamthif_open_count--; - if (cl->fp == file && dev->iamthif_state != MEI_IAMTHIF_IDLE) { + if (cl->fp == fp && dev->iamthif_state != MEI_IAMTHIF_IDLE) { dev_dbg(dev->dev, "amthif canceled iamthif state %d\n", - dev->iamthif_state); + dev->iamthif_state); dev->iamthif_canceled = true; } /* Don't clean ctrl_rd_list here, the reads has to be completed */ - mei_clear_list(file, &dev->amthif_cmd_list); - mei_clear_list(file, &cl->rd_completed); + mei_io_list_free_fp(&dev->amthif_cmd_list, fp); + mei_io_list_free_fp(&cl->rd_completed, fp); return 0; } diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c index 838a4a349f9e..68fe37b5bc52 100644 --- a/drivers/misc/mei/client.c +++ b/drivers/misc/mei/client.c @@ -377,14 +377,14 @@ static struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, } /** - * __mei_io_list_flush - removes and frees cbs belonging to cl. + * __mei_io_list_flush_cl - removes and frees cbs belonging to cl. * * @head: an instance of our list structure * @cl: host client, can be NULL for flushing the whole list * @free: whether to free the cbs */ -static void __mei_io_list_flush(struct list_head *head, - struct mei_cl *cl, bool free) +static void __mei_io_list_flush_cl(struct list_head *head, + const struct mei_cl *cl, bool free) { struct mei_cl_cb *cb, *next; @@ -399,25 +399,42 @@ static void __mei_io_list_flush(struct list_head *head, } /** - * mei_io_list_flush - removes list entry belonging to cl. + * mei_io_list_flush_cl - removes list entry belonging to cl. * * @head: An instance of our list structure * @cl: host client */ -static inline void mei_io_list_flush(struct list_head *head, struct mei_cl *cl) +static inline void mei_io_list_flush_cl(struct list_head *head, + const struct mei_cl *cl) { - __mei_io_list_flush(head, cl, false); + __mei_io_list_flush_cl(head, cl, false); } /** - * mei_io_list_free - removes cb belonging to cl and free them + * mei_io_list_free_cl - removes cb belonging to cl and free them * * @head: An instance of our list structure * @cl: host client */ -static inline void mei_io_list_free(struct list_head *head, struct mei_cl *cl) +static inline void mei_io_list_free_cl(struct list_head *head, + const struct mei_cl *cl) { - __mei_io_list_flush(head, cl, true); + __mei_io_list_flush_cl(head, cl, true); +} + +/** + * mei_io_list_free_fp - free cb from a list that matches file pointer + * + * @head: io list + * @fp: file pointer (matching cb file object), may be NULL + */ +void mei_io_list_free_fp(struct list_head *head, const struct file *fp) +{ + struct mei_cl_cb *cb, *next; + + list_for_each_entry_safe(cb, next, head, list) + if (!fp || fp == cb->fp) + mei_io_cb_free(cb); } /** @@ -503,27 +520,6 @@ struct mei_cl_cb *mei_cl_read_cb(const struct mei_cl *cl, const struct file *fp) return NULL; } -/** - * mei_cl_read_cb_flush - free client's read pending and completed cbs - * for a specific file - * - * @cl: host client - * @fp: file pointer (matching cb file object), may be NULL - */ -void mei_cl_read_cb_flush(const struct mei_cl *cl, const struct file *fp) -{ - struct mei_cl_cb *cb, *next; - - list_for_each_entry_safe(cb, next, &cl->rd_completed, list) - if (!fp || fp == cb->fp) - mei_io_cb_free(cb); - - - list_for_each_entry_safe(cb, next, &cl->rd_pending, list) - if (!fp || fp == cb->fp) - mei_io_cb_free(cb); -} - /** * mei_cl_flush_queues - flushes queue lists belonging to cl. * @@ -542,17 +538,16 @@ int mei_cl_flush_queues(struct mei_cl *cl, const struct file *fp) dev = cl->dev; cl_dbg(dev, cl, "remove list entry belonging to cl\n"); - mei_io_list_free(&cl->dev->write_list, cl); - mei_io_list_free(&cl->dev->write_waiting_list, cl); - mei_io_list_flush(&cl->dev->ctrl_wr_list, cl); - mei_io_list_flush(&cl->dev->ctrl_rd_list, cl); - - mei_cl_read_cb_flush(cl, fp); + mei_io_list_free_cl(&cl->dev->write_list, cl); + mei_io_list_free_cl(&cl->dev->write_waiting_list, cl); + mei_io_list_flush_cl(&cl->dev->ctrl_wr_list, cl); + mei_io_list_flush_cl(&cl->dev->ctrl_rd_list, cl); + mei_io_list_free_fp(&cl->rd_pending, fp); + mei_io_list_free_fp(&cl->rd_completed, fp); return 0; } - /** * mei_cl_init - initializes cl. * @@ -764,11 +759,11 @@ static void mei_cl_set_disconnected(struct mei_cl *cl) return; cl->state = MEI_FILE_DISCONNECTED; - mei_io_list_free(&dev->write_list, cl); - mei_io_list_free(&dev->write_waiting_list, cl); - mei_io_list_flush(&dev->ctrl_rd_list, cl); - mei_io_list_flush(&dev->ctrl_wr_list, cl); - mei_io_list_free(&dev->amthif_cmd_list, cl); + mei_io_list_free_cl(&dev->write_list, cl); + mei_io_list_free_cl(&dev->write_waiting_list, cl); + mei_io_list_flush_cl(&dev->ctrl_rd_list, cl); + mei_io_list_flush_cl(&dev->ctrl_wr_list, cl); + mei_io_list_free_cl(&dev->amthif_cmd_list, cl); mei_cl_wake_all(cl); cl->rx_flow_ctrl_creds = 0; cl->tx_flow_ctrl_creds = 0; @@ -1123,8 +1118,8 @@ int mei_cl_connect(struct mei_cl *cl, struct mei_me_client *me_cl, if (!mei_cl_is_connected(cl)) { if (cl->state == MEI_FILE_DISCONNECT_REQUIRED) { - mei_io_list_flush(&dev->ctrl_rd_list, cl); - mei_io_list_flush(&dev->ctrl_wr_list, cl); + mei_io_list_flush_cl(&dev->ctrl_rd_list, cl); + mei_io_list_flush_cl(&dev->ctrl_wr_list, cl); /* ignore disconnect return valuue; * in case of failure reset will be invoked */ diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h index f48cfa026268..545ae319ba90 100644 --- a/drivers/misc/mei/client.h +++ b/drivers/misc/mei/client.h @@ -83,6 +83,7 @@ static inline u8 mei_me_cl_ver(const struct mei_me_client *me_cl) * MEI IO Functions */ void mei_io_cb_free(struct mei_cl_cb *priv_cb); +void mei_io_list_free_fp(struct list_head *head, const struct file *fp); /* * MEI Host Client Functions @@ -99,7 +100,6 @@ struct mei_cl *mei_cl_alloc_linked(struct mei_device *dev); struct mei_cl_cb *mei_cl_read_cb(const struct mei_cl *cl, const struct file *fp); -void mei_cl_read_cb_flush(const struct mei_cl *cl, const struct file *fp); struct mei_cl_cb *mei_cl_alloc_cb(struct mei_cl *cl, size_t length, enum mei_cb_file_ops type, const struct file *fp); -- cgit v1.2.3 From f8a096059fc5f719301d314e5d7451f1bab5032a Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Thu, 26 Jan 2017 17:16:26 +0200 Subject: mei: simplify error handling via devres function. Use devm_ and pcim_ functions to make error handling simpler and code smaller and tidier. Based on original patch by mei: me: use managed functions pcim_* and devm_* https://lkml.org/lkml/2016/2/1/339 Signed-off-by: Tomas Winkler Signed-off-by: Alexander Usyskin Signed-off-by: Andy Shevchenko Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/hw-me.c | 6 ++-- drivers/misc/mei/hw-txe.c | 4 +-- drivers/misc/mei/hw-txe.h | 2 +- drivers/misc/mei/pci-me.c | 50 +++++++-------------------------- drivers/misc/mei/pci-txe.c | 69 +++++++--------------------------------------- 5 files changed, 26 insertions(+), 105 deletions(-) (limited to 'drivers/misc/mei') diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c index 06a579952e3f..befeac52c349 100644 --- a/drivers/misc/mei/hw-me.c +++ b/drivers/misc/mei/hw-me.c @@ -1389,7 +1389,7 @@ const struct mei_cfg mei_me_pch8_sps_cfg = { * @pdev: The pci device structure * @cfg: per device generation config * - * Return: The mei_device_device pointer on success, NULL on failure. + * Return: The mei_device pointer on success, NULL on failure. */ struct mei_device *mei_me_dev_init(struct pci_dev *pdev, const struct mei_cfg *cfg) @@ -1397,8 +1397,8 @@ struct mei_device *mei_me_dev_init(struct pci_dev *pdev, struct mei_device *dev; struct mei_me_hw *hw; - dev = kzalloc(sizeof(struct mei_device) + - sizeof(struct mei_me_hw), GFP_KERNEL); + dev = devm_kzalloc(&pdev->dev, sizeof(struct mei_device) + + sizeof(struct mei_me_hw), GFP_KERNEL); if (!dev) return NULL; hw = to_me_hw(dev); diff --git a/drivers/misc/mei/hw-txe.c b/drivers/misc/mei/hw-txe.c index 6259b11d440c..24e4a4c96606 100644 --- a/drivers/misc/mei/hw-txe.c +++ b/drivers/misc/mei/hw-txe.c @@ -1207,8 +1207,8 @@ struct mei_device *mei_txe_dev_init(struct pci_dev *pdev) struct mei_device *dev; struct mei_txe_hw *hw; - dev = kzalloc(sizeof(struct mei_device) + - sizeof(struct mei_txe_hw), GFP_KERNEL); + dev = devm_kzalloc(&pdev->dev, sizeof(struct mei_device) + + sizeof(struct mei_txe_hw), GFP_KERNEL); if (!dev) return NULL; diff --git a/drivers/misc/mei/hw-txe.h b/drivers/misc/mei/hw-txe.h index ce3ed0b88b0c..e1e8b66d7648 100644 --- a/drivers/misc/mei/hw-txe.h +++ b/drivers/misc/mei/hw-txe.h @@ -45,7 +45,7 @@ * @intr_cause: translated interrupt cause */ struct mei_txe_hw { - void __iomem *mem_addr[NUM_OF_MEM_BARS]; + void __iomem * const *mem_addr; u32 aliveness; u32 readiness; u32 slots; diff --git a/drivers/misc/mei/pci-me.c b/drivers/misc/mei/pci-me.c index f9c6ec4b98ab..0a668fdfbbe9 100644 --- a/drivers/misc/mei/pci-me.c +++ b/drivers/misc/mei/pci-me.c @@ -149,18 +149,18 @@ static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent) return -ENODEV; /* enable pci dev */ - err = pci_enable_device(pdev); + err = pcim_enable_device(pdev); if (err) { dev_err(&pdev->dev, "failed to enable pci device.\n"); goto end; } /* set PCI host mastering */ pci_set_master(pdev); - /* pci request regions for mei driver */ - err = pci_request_regions(pdev, KBUILD_MODNAME); + /* pci request regions and mapping IO device memory for mei driver */ + err = pcim_iomap_regions(pdev, BIT(0), KBUILD_MODNAME); if (err) { dev_err(&pdev->dev, "failed to get pci regions.\n"); - goto disable_device; + goto end; } if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) || @@ -173,24 +173,18 @@ static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent) } if (err) { dev_err(&pdev->dev, "No usable DMA configuration, aborting\n"); - goto release_regions; + goto end; } - /* allocates and initializes the mei dev structure */ dev = mei_me_dev_init(pdev, cfg); if (!dev) { err = -ENOMEM; - goto release_regions; + goto end; } hw = to_me_hw(dev); - /* mapping IO device memory */ - hw->mem_addr = pci_iomap(pdev, 0, 0); - if (!hw->mem_addr) { - dev_err(&pdev->dev, "mapping I/O device memory failure.\n"); - err = -ENOMEM; - goto free_device; - } + hw->mem_addr = pcim_iomap_table(pdev)[0]; + pci_enable_msi(pdev); /* request and enable interrupt */ @@ -203,7 +197,7 @@ static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (err) { dev_err(&pdev->dev, "request_threaded_irq failure. irq = %d\n", pdev->irq); - goto disable_msi; + goto end; } if (mei_start(dev)) { @@ -242,15 +236,6 @@ release_irq: mei_cancel_work(dev); mei_disable_interrupts(dev); free_irq(pdev->irq, dev); -disable_msi: - pci_disable_msi(pdev); - pci_iounmap(pdev, hw->mem_addr); -free_device: - kfree(dev); -release_regions: - pci_release_regions(pdev); -disable_device: - pci_disable_device(pdev); end: dev_err(&pdev->dev, "initialization failed.\n"); return err; @@ -267,7 +252,6 @@ end: static void mei_me_remove(struct pci_dev *pdev) { struct mei_device *dev; - struct mei_me_hw *hw; dev = pci_get_drvdata(pdev); if (!dev) @@ -276,33 +260,19 @@ static void mei_me_remove(struct pci_dev *pdev) if (mei_pg_is_enabled(dev)) pm_runtime_get_noresume(&pdev->dev); - hw = to_me_hw(dev); - - dev_dbg(&pdev->dev, "stop\n"); mei_stop(dev); if (!pci_dev_run_wake(pdev)) mei_me_unset_pm_domain(dev); - /* disable interrupts */ mei_disable_interrupts(dev); free_irq(pdev->irq, dev); - pci_disable_msi(pdev); - - if (hw->mem_addr) - pci_iounmap(pdev, hw->mem_addr); mei_deregister(dev); - - kfree(dev); - - pci_release_regions(pdev); - pci_disable_device(pdev); - - } + #ifdef CONFIG_PM_SLEEP static int mei_me_pci_suspend(struct device *device) { diff --git a/drivers/misc/mei/pci-txe.c b/drivers/misc/mei/pci-txe.c index 58ffd30dcc91..fe088b40daf9 100644 --- a/drivers/misc/mei/pci-txe.c +++ b/drivers/misc/mei/pci-txe.c @@ -52,17 +52,6 @@ static inline void mei_txe_set_pm_domain(struct mei_device *dev) {} static inline void mei_txe_unset_pm_domain(struct mei_device *dev) {} #endif /* CONFIG_PM */ -static void mei_txe_pci_iounmap(struct pci_dev *pdev, struct mei_txe_hw *hw) -{ - int i; - - for (i = SEC_BAR; i < NUM_OF_MEM_BARS; i++) { - if (hw->mem_addr[i]) { - pci_iounmap(pdev, hw->mem_addr[i]); - hw->mem_addr[i] = NULL; - } - } -} /** * mei_txe_probe - Device Initialization Routine * @@ -75,22 +64,22 @@ static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct mei_device *dev; struct mei_txe_hw *hw; + const int mask = BIT(SEC_BAR) | BIT(BRIDGE_BAR); int err; - int i; /* enable pci dev */ - err = pci_enable_device(pdev); + err = pcim_enable_device(pdev); if (err) { dev_err(&pdev->dev, "failed to enable pci device.\n"); goto end; } /* set PCI host mastering */ pci_set_master(pdev); - /* pci request regions for mei driver */ - err = pci_request_regions(pdev, KBUILD_MODNAME); + /* pci request regions and mapping IO device memory for mei driver */ + err = pcim_iomap_regions(pdev, mask, KBUILD_MODNAME); if (err) { dev_err(&pdev->dev, "failed to get pci regions.\n"); - goto disable_device; + goto end; } err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36)); @@ -98,7 +87,7 @@ static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); if (err) { dev_err(&pdev->dev, "No suitable DMA available.\n"); - goto release_regions; + goto end; } } @@ -106,20 +95,10 @@ static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) dev = mei_txe_dev_init(pdev); if (!dev) { err = -ENOMEM; - goto release_regions; + goto end; } hw = to_txe_hw(dev); - - /* mapping IO device memory */ - for (i = SEC_BAR; i < NUM_OF_MEM_BARS; i++) { - hw->mem_addr[i] = pci_iomap(pdev, i, 0); - if (!hw->mem_addr[i]) { - dev_err(&pdev->dev, "mapping I/O device memory failure.\n"); - err = -ENOMEM; - goto free_device; - } - } - + hw->mem_addr = pcim_iomap_table(pdev); pci_enable_msi(pdev); @@ -140,7 +119,7 @@ static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (err) { dev_err(&pdev->dev, "mei: request_threaded_irq failure. irq = %d\n", pdev->irq); - goto free_device; + goto end; } if (mei_start(dev)) { @@ -173,23 +152,9 @@ static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) stop: mei_stop(dev); release_irq: - mei_cancel_work(dev); - - /* disable interrupts */ mei_disable_interrupts(dev); - free_irq(pdev->irq, dev); - pci_disable_msi(pdev); - -free_device: - mei_txe_pci_iounmap(pdev, hw); - - kfree(dev); -release_regions: - pci_release_regions(pdev); -disable_device: - pci_disable_device(pdev); end: dev_err(&pdev->dev, "initialization failed.\n"); return err; @@ -206,38 +171,24 @@ end: static void mei_txe_remove(struct pci_dev *pdev) { struct mei_device *dev; - struct mei_txe_hw *hw; dev = pci_get_drvdata(pdev); if (!dev) { - dev_err(&pdev->dev, "mei: dev =NULL\n"); + dev_err(&pdev->dev, "mei: dev == NULL\n"); return; } pm_runtime_get_noresume(&pdev->dev); - hw = to_txe_hw(dev); - mei_stop(dev); if (!pci_dev_run_wake(pdev)) mei_txe_unset_pm_domain(dev); - /* disable interrupts */ mei_disable_interrupts(dev); free_irq(pdev->irq, dev); - pci_disable_msi(pdev); - - pci_set_drvdata(pdev, NULL); - - mei_txe_pci_iounmap(pdev, hw); mei_deregister(dev); - - kfree(dev); - - pci_release_regions(pdev); - pci_disable_device(pdev); } -- cgit v1.2.3 From 9c7daa61d91647fba3b986a9941d3fb531b9b9ff Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Thu, 2 Feb 2017 11:26:53 +0200 Subject: mei: me: add a wrapper to set host generated data interrupt Consolidate setting H_IG, an interrupt from host towards hw, into a wrapper to eliminate code duplication. Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/hw-me.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'drivers/misc/mei') diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c index befeac52c349..23294b845c42 100644 --- a/drivers/misc/mei/hw-me.c +++ b/drivers/misc/mei/hw-me.c @@ -139,6 +139,19 @@ static inline void mei_hcsr_set(struct mei_device *dev, u32 reg) mei_hcsr_write(dev, reg); } +/** + * mei_hcsr_set_hig - set host interrupt (set H_IG) + * + * @dev: the device structure + */ +static inline void mei_hcsr_set_hig(struct mei_device *dev) +{ + u32 hcsr; + + hcsr = mei_hcsr_read(dev) | H_IG; + mei_hcsr_set(dev, hcsr); +} + /** * mei_me_d0i3c_read - Reads 32bit data from the D0I3C register * @@ -505,7 +518,6 @@ static int mei_me_hbuf_write(struct mei_device *dev, unsigned long rem; unsigned long length = header->length; u32 *reg_buf = (u32 *)buf; - u32 hcsr; u32 dw_cnt; int i; int empty_slots; @@ -532,8 +544,7 @@ static int mei_me_hbuf_write(struct mei_device *dev, mei_me_hcbww_write(dev, reg); } - hcsr = mei_hcsr_read(dev) | H_IG; - mei_hcsr_set(dev, hcsr); + mei_hcsr_set_hig(dev); if (!mei_me_hw_is_ready(dev)) return -EIO; @@ -580,7 +591,6 @@ static int mei_me_read_slots(struct mei_device *dev, unsigned char *buffer, unsigned long buffer_length) { u32 *reg_buf = (u32 *)buffer; - u32 hcsr; for (; buffer_length >= sizeof(u32); buffer_length -= sizeof(u32)) *reg_buf++ = mei_me_mecbrw_read(dev); @@ -591,8 +601,7 @@ static int mei_me_read_slots(struct mei_device *dev, unsigned char *buffer, memcpy(reg_buf, ®, buffer_length); } - hcsr = mei_hcsr_read(dev) | H_IG; - mei_hcsr_set(dev, hcsr); + mei_hcsr_set_hig(dev); return 0; } -- cgit v1.2.3 From 47f60a017169d1d3c6cb086ece272f272f110845 Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Thu, 2 Feb 2017 11:26:54 +0200 Subject: mei: me: generate an interrupt if the hw indicates reset. In rare case the driver may lose connection with the device after device reset due to a missed interrupt. The driver will unlock the flow by generating an interrupt towards the firmware (HIG) when the device is in the resetting state. The FW is able to ignore the interrupt during orderly flow. The effected platforms are skylake and newer. Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/hw-me.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'drivers/misc/mei') diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c index 23294b845c42..71216affcab1 100644 --- a/drivers/misc/mei/hw-me.c +++ b/drivers/misc/mei/hw-me.c @@ -393,6 +393,19 @@ static bool mei_me_hw_is_ready(struct mei_device *dev) return (mecsr & ME_RDY_HRA) == ME_RDY_HRA; } +/** + * mei_me_hw_is_resetting - check whether the me(hw) is in reset + * + * @dev: mei device + * Return: bool + */ +static bool mei_me_hw_is_resetting(struct mei_device *dev) +{ + u32 mecsr = mei_me_mecsr_read(dev); + + return (mecsr & ME_RST_HRA) == ME_RST_HRA; +} + /** * mei_me_hw_ready_wait - wait until the me(hw) has turned ready * or timeout is reached @@ -1219,6 +1232,9 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id) goto end; } + if (mei_me_hw_is_resetting(dev)) + mei_hcsr_set_hig(dev); + mei_me_pg_intr(dev, me_intr_src(hcsr)); /* check if we need to start the dev */ -- cgit v1.2.3 From cb97fbbcac15982406e0c74cd5512a8b6fcf10b3 Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Wed, 8 Feb 2017 00:41:45 +0200 Subject: mei: remove support for broken parallel read Parallel reads from multiple threads on a file descriptor are not well defined and racy. It is safer to return to original behavior and simply fail the additional read. The solution is to remove request for next read credit. Cc: #4.9 Fixes: ff1586a7ea57 ("mei: enqueue consecutive reads") Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/main.c | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'drivers/misc/mei') diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c index e1bf54481fd6..9d0b7050c79a 100644 --- a/drivers/misc/mei/main.c +++ b/drivers/misc/mei/main.c @@ -182,32 +182,36 @@ static ssize_t mei_read(struct file *file, char __user *ubuf, goto out; } - if (rets == -EBUSY && - !mei_cl_enqueue_ctrl_wr_cb(cl, length, MEI_FOP_READ, file)) { - rets = -ENOMEM; - goto out; - } - do { - mutex_unlock(&dev->device_lock); - - if (wait_event_interruptible(cl->rx_wait, - (!list_empty(&cl->rd_completed)) || - (!mei_cl_is_connected(cl)))) { +again: + mutex_unlock(&dev->device_lock); + if (wait_event_interruptible(cl->rx_wait, + !list_empty(&cl->rd_completed) || + !mei_cl_is_connected(cl))) { + if (signal_pending(current)) + return -EINTR; + return -ERESTARTSYS; + } + mutex_lock(&dev->device_lock); - if (signal_pending(current)) - return -EINTR; - return -ERESTARTSYS; - } + if (!mei_cl_is_connected(cl)) { + rets = -ENODEV; + goto out; + } - mutex_lock(&dev->device_lock); - if (!mei_cl_is_connected(cl)) { - rets = -ENODEV; - goto out; - } + cb = mei_cl_read_cb(cl, file); + if (!cb) { + /* + * For amthif all the waiters are woken up, + * but only fp with matching cb->fp get the cb, + * the others have to return to wait on read. + */ + if (cl == &dev->iamthif_cl) + goto again; - cb = mei_cl_read_cb(cl, file); - } while (!cb); + rets = 0; + goto out; + } copy_buffer: /* now copy the data to user space */ -- cgit v1.2.3