Commit 7c7a6077 authored by Alexander Usyskin's avatar Alexander Usyskin Committed by Greg Kroah-Hartman

mei: bus: split RX and async notification callbacks

Split callbacks for RX and async notification events on mei bus to
eliminate synchronization problems and to open way for RX optimizations.
Signed-off-by: default avatarAlexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c110cdb1
...@@ -209,31 +209,40 @@ ssize_t mei_cldev_recv(struct mei_cl_device *cldev, u8 *buf, size_t length) ...@@ -209,31 +209,40 @@ ssize_t mei_cldev_recv(struct mei_cl_device *cldev, u8 *buf, size_t length)
EXPORT_SYMBOL_GPL(mei_cldev_recv); EXPORT_SYMBOL_GPL(mei_cldev_recv);
/** /**
* mei_cl_bus_event_work - dispatch rx event for a bus device * mei_cl_bus_rx_work - dispatch rx event for a bus device
* and schedule new work
* *
* @work: work * @work: work
*/ */
static void mei_cl_bus_event_work(struct work_struct *work) static void mei_cl_bus_rx_work(struct work_struct *work)
{ {
struct mei_cl_device *cldev; struct mei_cl_device *cldev;
struct mei_device *bus; struct mei_device *bus;
cldev = container_of(work, struct mei_cl_device, event_work); cldev = container_of(work, struct mei_cl_device, rx_work);
bus = cldev->bus; bus = cldev->bus;
if (cldev->event_cb) if (cldev->rx_cb)
cldev->event_cb(cldev, cldev->events); cldev->rx_cb(cldev);
cldev->events = 0;
/* Prepare for the next read */
if (cldev->events_mask & BIT(MEI_CL_EVENT_RX)) {
mutex_lock(&bus->device_lock); mutex_lock(&bus->device_lock);
mei_cl_read_start(cldev->cl, mei_cl_mtu(cldev->cl), NULL); mei_cl_read_start(cldev->cl, mei_cl_mtu(cldev->cl), NULL);
mutex_unlock(&bus->device_lock); mutex_unlock(&bus->device_lock);
} }
/**
* mei_cl_bus_notif_work - dispatch FW notif event for a bus device
*
* @work: work
*/
static void mei_cl_bus_notif_work(struct work_struct *work)
{
struct mei_cl_device *cldev;
cldev = container_of(work, struct mei_cl_device, notif_work);
if (cldev->notif_cb)
cldev->notif_cb(cldev);
} }
/** /**
...@@ -248,18 +257,13 @@ bool mei_cl_bus_notify_event(struct mei_cl *cl) ...@@ -248,18 +257,13 @@ bool mei_cl_bus_notify_event(struct mei_cl *cl)
{ {
struct mei_cl_device *cldev = cl->cldev; struct mei_cl_device *cldev = cl->cldev;
if (!cldev || !cldev->event_cb) if (!cldev || !cldev->notif_cb)
return false;
if (!(cldev->events_mask & BIT(MEI_CL_EVENT_NOTIF)))
return false; return false;
if (!cl->notify_ev) if (!cl->notify_ev)
return false; return false;
set_bit(MEI_CL_EVENT_NOTIF, &cldev->events); schedule_work(&cldev->notif_work);
schedule_work(&cldev->event_work);
cl->notify_ev = false; cl->notify_ev = false;
...@@ -278,64 +282,81 @@ bool mei_cl_bus_rx_event(struct mei_cl *cl) ...@@ -278,64 +282,81 @@ bool mei_cl_bus_rx_event(struct mei_cl *cl)
{ {
struct mei_cl_device *cldev = cl->cldev; struct mei_cl_device *cldev = cl->cldev;
if (!cldev || !cldev->event_cb) if (!cldev || !cldev->rx_cb)
return false;
if (!(cldev->events_mask & BIT(MEI_CL_EVENT_RX)))
return false; return false;
set_bit(MEI_CL_EVENT_RX, &cldev->events); schedule_work(&cldev->rx_work);
schedule_work(&cldev->event_work);
return true; return true;
} }
/** /**
* mei_cldev_register_event_cb - register event callback * mei_cldev_register_rx_cb - register Rx event callback
* *
* @cldev: me client devices * @cldev: me client devices
* @event_cb: callback function * @rx_cb: callback function
* @events_mask: requested events bitmask
* *
* Return: 0 on success * Return: 0 on success
* -EALREADY if an callback is already registered * -EALREADY if an callback is already registered
* <0 on other errors * <0 on other errors
*/ */
int mei_cldev_register_event_cb(struct mei_cl_device *cldev, int mei_cldev_register_rx_cb(struct mei_cl_device *cldev, mei_cldev_cb_t rx_cb)
unsigned long events_mask,
mei_cldev_event_cb_t event_cb)
{ {
struct mei_device *bus = cldev->bus; struct mei_device *bus = cldev->bus;
int ret; int ret;
if (cldev->event_cb) if (!rx_cb)
return -EINVAL;
if (cldev->rx_cb)
return -EALREADY; return -EALREADY;
cldev->events = 0; cldev->rx_cb = rx_cb;
cldev->events_mask = events_mask; INIT_WORK(&cldev->rx_work, mei_cl_bus_rx_work);
cldev->event_cb = event_cb;
INIT_WORK(&cldev->event_work, mei_cl_bus_event_work);
if (cldev->events_mask & BIT(MEI_CL_EVENT_RX)) {
mutex_lock(&bus->device_lock); mutex_lock(&bus->device_lock);
ret = mei_cl_read_start(cldev->cl, mei_cl_mtu(cldev->cl), NULL); ret = mei_cl_read_start(cldev->cl, mei_cl_mtu(cldev->cl), NULL);
mutex_unlock(&bus->device_lock); mutex_unlock(&bus->device_lock);
if (ret && ret != -EBUSY) if (ret && ret != -EBUSY)
return ret; return ret;
}
if (cldev->events_mask & BIT(MEI_CL_EVENT_NOTIF)) { return 0;
}
EXPORT_SYMBOL_GPL(mei_cldev_register_rx_cb);
/**
* mei_cldev_register_notif_cb - register FW notification event callback
*
* @cldev: me client devices
* @notif_cb: callback function
*
* Return: 0 on success
* -EALREADY if an callback is already registered
* <0 on other errors
*/
int mei_cldev_register_notif_cb(struct mei_cl_device *cldev,
mei_cldev_cb_t notif_cb)
{
struct mei_device *bus = cldev->bus;
int ret;
if (!notif_cb)
return -EINVAL;
if (cldev->notif_cb)
return -EALREADY;
cldev->notif_cb = notif_cb;
INIT_WORK(&cldev->notif_work, mei_cl_bus_notif_work);
mutex_lock(&bus->device_lock); mutex_lock(&bus->device_lock);
ret = mei_cl_notify_request(cldev->cl, NULL, event_cb ? 1 : 0); ret = mei_cl_notify_request(cldev->cl, NULL, 1);
mutex_unlock(&bus->device_lock); mutex_unlock(&bus->device_lock);
if (ret) if (ret)
return ret; return ret;
}
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(mei_cldev_register_event_cb); EXPORT_SYMBOL_GPL(mei_cldev_register_notif_cb);
/** /**
* mei_cldev_get_drvdata - driver data getter * mei_cldev_get_drvdata - driver data getter
...@@ -471,8 +492,6 @@ int mei_cldev_disable(struct mei_cl_device *cldev) ...@@ -471,8 +492,6 @@ int mei_cldev_disable(struct mei_cl_device *cldev)
bus = cldev->bus; bus = cldev->bus;
cldev->event_cb = NULL;
mutex_lock(&bus->device_lock); mutex_lock(&bus->device_lock);
if (!mei_cl_is_connected(cl)) { if (!mei_cl_is_connected(cl)) {
...@@ -619,9 +638,13 @@ static int mei_cl_device_remove(struct device *dev) ...@@ -619,9 +638,13 @@ static int mei_cl_device_remove(struct device *dev)
if (!cldev || !dev->driver) if (!cldev || !dev->driver)
return 0; return 0;
if (cldev->event_cb) { if (cldev->rx_cb) {
cldev->event_cb = NULL; cancel_work_sync(&cldev->rx_work);
cancel_work_sync(&cldev->event_work); cldev->rx_cb = NULL;
}
if (cldev->notif_cb) {
cancel_work_sync(&cldev->notif_work);
cldev->notif_cb = NULL;
} }
cldrv = to_mei_cl_driver(dev->driver); cldrv = to_mei_cl_driver(dev->driver);
......
...@@ -673,6 +673,11 @@ int mei_cl_unlink(struct mei_cl *cl) ...@@ -673,6 +673,11 @@ int mei_cl_unlink(struct mei_cl *cl)
list_del_init(&cl->link); list_del_init(&cl->link);
cl->state = MEI_FILE_UNINITIALIZED; cl->state = MEI_FILE_UNINITIALIZED;
cl->writing_state = MEI_IDLE;
WARN_ON(!list_empty(&cl->rd_completed) ||
!list_empty(&cl->rd_pending) ||
!list_empty(&cl->link));
return 0; return 0;
} }
......
...@@ -297,9 +297,11 @@ static int mei_nfc_recv(struct nfc_mei_phy *phy, u8 *buf, size_t length) ...@@ -297,9 +297,11 @@ static int mei_nfc_recv(struct nfc_mei_phy *phy, u8 *buf, size_t length)
} }
static void nfc_mei_event_cb(struct mei_cl_device *cldev, u32 events) static void nfc_mei_rx_cb(struct mei_cl_device *cldev)
{ {
struct nfc_mei_phy *phy = mei_cldev_get_drvdata(cldev); struct nfc_mei_phy *phy = mei_cldev_get_drvdata(cldev);
struct sk_buff *skb;
int reply_size;
if (!phy) if (!phy)
return; return;
...@@ -307,10 +309,6 @@ static void nfc_mei_event_cb(struct mei_cl_device *cldev, u32 events) ...@@ -307,10 +309,6 @@ static void nfc_mei_event_cb(struct mei_cl_device *cldev, u32 events)
if (phy->hard_fault != 0) if (phy->hard_fault != 0)
return; return;
if (events & BIT(MEI_CL_EVENT_RX)) {
struct sk_buff *skb;
int reply_size;
skb = alloc_skb(MEI_NFC_MAX_READ, GFP_KERNEL); skb = alloc_skb(MEI_NFC_MAX_READ, GFP_KERNEL);
if (!skb) if (!skb)
return; return;
...@@ -327,7 +325,6 @@ static void nfc_mei_event_cb(struct mei_cl_device *cldev, u32 events) ...@@ -327,7 +325,6 @@ static void nfc_mei_event_cb(struct mei_cl_device *cldev, u32 events)
MEI_DUMP_SKB_IN("mei frame read", skb); MEI_DUMP_SKB_IN("mei frame read", skb);
nfc_hci_recv_frame(phy->hdev, skb); nfc_hci_recv_frame(phy->hdev, skb);
}
} }
static int nfc_mei_phy_enable(void *phy_id) static int nfc_mei_phy_enable(void *phy_id)
...@@ -358,8 +355,7 @@ static int nfc_mei_phy_enable(void *phy_id) ...@@ -358,8 +355,7 @@ static int nfc_mei_phy_enable(void *phy_id)
goto err; goto err;
} }
r = mei_cldev_register_event_cb(phy->cldev, BIT(MEI_CL_EVENT_RX), r = mei_cldev_register_rx_cb(phy->cldev, nfc_mei_rx_cb);
nfc_mei_event_cb);
if (r) { if (r) {
pr_err("Event cb registration failed %d\n", r); pr_err("Event cb registration failed %d\n", r);
goto err; goto err;
......
...@@ -410,11 +410,11 @@ static void mei_wdt_unregister_work(struct work_struct *work) ...@@ -410,11 +410,11 @@ static void mei_wdt_unregister_work(struct work_struct *work)
} }
/** /**
* mei_wdt_event_rx - callback for data receive * mei_wdt_rx - callback for data receive
* *
* @cldev: bus device * @cldev: bus device
*/ */
static void mei_wdt_event_rx(struct mei_cl_device *cldev) static void mei_wdt_rx(struct mei_cl_device *cldev)
{ {
struct mei_wdt *wdt = mei_cldev_get_drvdata(cldev); struct mei_wdt *wdt = mei_cldev_get_drvdata(cldev);
struct mei_wdt_start_response res; struct mei_wdt_start_response res;
...@@ -482,11 +482,11 @@ static void mei_wdt_event_rx(struct mei_cl_device *cldev) ...@@ -482,11 +482,11 @@ static void mei_wdt_event_rx(struct mei_cl_device *cldev)
} }
/* /*
* mei_wdt_notify_event - callback for event notification * mei_wdt_notif - callback for event notification
* *
* @cldev: bus device * @cldev: bus device
*/ */
static void mei_wdt_notify_event(struct mei_cl_device *cldev) static void mei_wdt_notif(struct mei_cl_device *cldev)
{ {
struct mei_wdt *wdt = mei_cldev_get_drvdata(cldev); struct mei_wdt *wdt = mei_cldev_get_drvdata(cldev);
...@@ -496,21 +496,6 @@ static void mei_wdt_notify_event(struct mei_cl_device *cldev) ...@@ -496,21 +496,6 @@ static void mei_wdt_notify_event(struct mei_cl_device *cldev)
mei_wdt_register(wdt); mei_wdt_register(wdt);
} }
/**
* mei_wdt_event - callback for event receive
*
* @cldev: bus device
* @events: event mask
*/
static void mei_wdt_event(struct mei_cl_device *cldev, u32 events)
{
if (events & BIT(MEI_CL_EVENT_RX))
mei_wdt_event_rx(cldev);
if (events & BIT(MEI_CL_EVENT_NOTIF))
mei_wdt_notify_event(cldev);
}
#if IS_ENABLED(CONFIG_DEBUG_FS) #if IS_ENABLED(CONFIG_DEBUG_FS)
static ssize_t mei_dbgfs_read_activation(struct file *file, char __user *ubuf, static ssize_t mei_dbgfs_read_activation(struct file *file, char __user *ubuf,
...@@ -621,16 +606,17 @@ static int mei_wdt_probe(struct mei_cl_device *cldev, ...@@ -621,16 +606,17 @@ static int mei_wdt_probe(struct mei_cl_device *cldev,
goto err_out; goto err_out;
} }
ret = mei_cldev_register_event_cb(wdt->cldev, ret = mei_cldev_register_rx_cb(wdt->cldev, mei_wdt_rx);
BIT(MEI_CL_EVENT_RX) | if (ret) {
BIT(MEI_CL_EVENT_NOTIF), dev_err(&cldev->dev, "Could not reg rx event ret=%d\n", ret);
mei_wdt_event); goto err_disable;
}
ret = mei_cldev_register_notif_cb(wdt->cldev, mei_wdt_notif);
/* on legacy devices notification is not supported /* on legacy devices notification is not supported
* this doesn't fail the registration for RX event
*/ */
if (ret && ret != -EOPNOTSUPP) { if (ret && ret != -EOPNOTSUPP) {
dev_err(&cldev->dev, "Could not register event ret=%d\n", ret); dev_err(&cldev->dev, "Could not reg notif event ret=%d\n", ret);
goto err_disable; goto err_disable;
} }
......
...@@ -8,8 +8,7 @@ ...@@ -8,8 +8,7 @@
struct mei_cl_device; struct mei_cl_device;
struct mei_device; struct mei_device;
typedef void (*mei_cldev_event_cb_t)(struct mei_cl_device *cldev, typedef void (*mei_cldev_cb_t)(struct mei_cl_device *cldev);
u32 events);
/** /**
* struct mei_cl_device - MEI device handle * struct mei_cl_device - MEI device handle
...@@ -24,11 +23,12 @@ typedef void (*mei_cldev_event_cb_t)(struct mei_cl_device *cldev, ...@@ -24,11 +23,12 @@ typedef void (*mei_cldev_event_cb_t)(struct mei_cl_device *cldev,
* @me_cl: me client * @me_cl: me client
* @cl: mei client * @cl: mei client
* @name: device name * @name: device name
* @event_work: async work to execute event callback * @rx_work: async work to execute Rx event callback
* @event_cb: Drivers register this callback to get asynchronous ME * @rx_cb: Drivers register this callback to get asynchronous ME
* events (e.g. Rx buffer pending) notifications. * Rx buffer pending notifications.
* @events_mask: Events bit mask requested by driver. * @notif_work: async work to execute FW notif event callback
* @events: Events bitmask sent to the driver. * @notif_cb: Drivers register this callback to get asynchronous ME
* FW notification pending notifications.
* *
* @do_match: wheather device can be matched with a driver * @do_match: wheather device can be matched with a driver
* @is_added: device is already scanned * @is_added: device is already scanned
...@@ -43,10 +43,10 @@ struct mei_cl_device { ...@@ -43,10 +43,10 @@ struct mei_cl_device {
struct mei_cl *cl; struct mei_cl *cl;
char name[MEI_CL_NAME_SIZE]; char name[MEI_CL_NAME_SIZE];
struct work_struct event_work; struct work_struct rx_work;
mei_cldev_event_cb_t event_cb; mei_cldev_cb_t rx_cb;
unsigned long events_mask; struct work_struct notif_work;
unsigned long events; mei_cldev_cb_t notif_cb;
unsigned int do_match:1; unsigned int do_match:1;
unsigned int is_added:1; unsigned int is_added:1;
...@@ -88,13 +88,9 @@ void mei_cldev_driver_unregister(struct mei_cl_driver *cldrv); ...@@ -88,13 +88,9 @@ void mei_cldev_driver_unregister(struct mei_cl_driver *cldrv);
ssize_t mei_cldev_send(struct mei_cl_device *cldev, u8 *buf, size_t length); ssize_t mei_cldev_send(struct mei_cl_device *cldev, u8 *buf, size_t length);
ssize_t mei_cldev_recv(struct mei_cl_device *cldev, u8 *buf, size_t length); ssize_t mei_cldev_recv(struct mei_cl_device *cldev, u8 *buf, size_t length);
int mei_cldev_register_event_cb(struct mei_cl_device *cldev, int mei_cldev_register_rx_cb(struct mei_cl_device *cldev, mei_cldev_cb_t rx_cb);
unsigned long event_mask, int mei_cldev_register_notif_cb(struct mei_cl_device *cldev,
mei_cldev_event_cb_t read_cb); mei_cldev_cb_t notif_cb);
#define MEI_CL_EVENT_RX 0
#define MEI_CL_EVENT_TX 1
#define MEI_CL_EVENT_NOTIF 2
const uuid_le *mei_cldev_uuid(const struct mei_cl_device *cldev); const uuid_le *mei_cldev_uuid(const struct mei_cl_device *cldev);
u8 mei_cldev_ver(const struct mei_cl_device *cldev); u8 mei_cldev_ver(const struct mei_cl_device *cldev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment