blob: a0d274fe08f157e3ae0ad476d89c732428eda227 [file] [log] [blame]
Samuel Ortize5354102013-03-27 17:29:53 +02001#ifndef _LINUX_MEI_CL_BUS_H
2#define _LINUX_MEI_CL_BUS_H
3
4#include <linux/device.h>
5#include <linux/uuid.h>
Tomas Winkler1f180352014-09-29 16:31:46 +03006#include <linux/mod_devicetable.h>
Samuel Ortize5354102013-03-27 17:29:53 +02007
8struct mei_cl_device;
Tomas Winkler512f64d2015-07-23 15:08:41 +03009struct mei_device;
Samuel Ortize5354102013-03-27 17:29:53 +020010
Alexander Usyskin7c7a6072016-11-16 22:51:29 +020011typedef void (*mei_cldev_cb_t)(struct mei_cl_device *cldev);
Tomas Winklerdbac9932015-05-07 15:54:07 +030012
13/**
14 * struct mei_cl_device - MEI device handle
15 * An mei_cl_device pointer is returned from mei_add_device()
16 * and links MEI bus clients to their actual ME host client pointer.
17 * Drivers for MEI devices will get an mei_cl_device pointer
18 * when being probed and shall use it for doing ME bus I/O.
19 *
Tomas Winkler0ff0a8d2015-07-23 15:08:42 +030020 * @bus_list: device on the bus list
Tomas Winkler512f64d2015-07-23 15:08:41 +030021 * @bus: parent mei device
Tomas Winklerdbac9932015-05-07 15:54:07 +030022 * @dev: linux driver model device pointer
23 * @me_cl: me client
24 * @cl: mei client
25 * @name: device name
Alexander Usyskin7c7a6072016-11-16 22:51:29 +020026 * @rx_work: async work to execute Rx event callback
27 * @rx_cb: Drivers register this callback to get asynchronous ME
28 * Rx buffer pending notifications.
29 * @notif_work: async work to execute FW notif event callback
30 * @notif_cb: Drivers register this callback to get asynchronous ME
31 * FW notification pending notifications.
Tomas Winkler71ce7892015-07-23 15:08:43 +030032 *
33 * @do_match: wheather device can be matched with a driver
Tomas Winkler0ff0a8d2015-07-23 15:08:42 +030034 * @is_added: device is already scanned
Tomas Winklerdbac9932015-05-07 15:54:07 +030035 * @priv_data: client private data
36 */
37struct mei_cl_device {
Tomas Winkler0ff0a8d2015-07-23 15:08:42 +030038 struct list_head bus_list;
Tomas Winkler512f64d2015-07-23 15:08:41 +030039 struct mei_device *bus;
Tomas Winklerdbac9932015-05-07 15:54:07 +030040 struct device dev;
41
42 struct mei_me_client *me_cl;
43 struct mei_cl *cl;
44 char name[MEI_CL_NAME_SIZE];
45
Alexander Usyskin7c7a6072016-11-16 22:51:29 +020046 struct work_struct rx_work;
47 mei_cldev_cb_t rx_cb;
48 struct work_struct notif_work;
49 mei_cldev_cb_t notif_cb;
Tomas Winkler71ce7892015-07-23 15:08:43 +030050
51 unsigned int do_match:1;
Tomas Winkler0ff0a8d2015-07-23 15:08:42 +030052 unsigned int is_added:1;
Tomas Winklerdbac9932015-05-07 15:54:07 +030053
54 void *priv_data;
55};
56
Samuel Ortize5354102013-03-27 17:29:53 +020057struct mei_cl_driver {
58 struct device_driver driver;
59 const char *name;
60
61 const struct mei_cl_device_id *id_table;
62
Tomas Winkler89391382015-09-10 10:18:04 +030063 int (*probe)(struct mei_cl_device *cldev,
Samuel Ortize5354102013-03-27 17:29:53 +020064 const struct mei_cl_device_id *id);
Tomas Winkler89391382015-09-10 10:18:04 +030065 int (*remove)(struct mei_cl_device *cldev);
Samuel Ortize5354102013-03-27 17:29:53 +020066};
67
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030068int __mei_cldev_driver_register(struct mei_cl_driver *cldrv,
69 struct module *owner);
70#define mei_cldev_driver_register(cldrv) \
71 __mei_cldev_driver_register(cldrv, THIS_MODULE)
Samuel Ortiz333e4ee2013-03-27 17:29:54 +020072
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030073void mei_cldev_driver_unregister(struct mei_cl_driver *cldrv);
Samuel Ortiz333e4ee2013-03-27 17:29:54 +020074
Tomas Winkler5be149b2016-10-19 16:33:27 +030075/**
76 * module_mei_cl_driver - Helper macro for registering mei cl driver
77 *
Alexander Usyskin076802d2016-12-03 00:15:25 +020078 * @__mei_cldrv: mei_cl_driver structure
Tomas Winkler5be149b2016-10-19 16:33:27 +030079 *
80 * Helper macro for mei cl drivers which do not do anything special in module
81 * init/exit, for eliminating a boilerplate code.
82 */
83#define module_mei_cl_driver(__mei_cldrv) \
84 module_driver(__mei_cldrv, \
85 mei_cldev_driver_register,\
86 mei_cldev_driver_unregister)
87
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030088ssize_t mei_cldev_send(struct mei_cl_device *cldev, u8 *buf, size_t length);
Alexander Usyskin076802d2016-12-03 00:15:25 +020089ssize_t mei_cldev_recv(struct mei_cl_device *cldev, u8 *buf, size_t length);
90ssize_t mei_cldev_recv_nonblock(struct mei_cl_device *cldev, u8 *buf,
91 size_t length);
Samuel Ortiz3e833292013-03-27 17:29:55 +020092
Alexander Usyskin7c7a6072016-11-16 22:51:29 +020093int mei_cldev_register_rx_cb(struct mei_cl_device *cldev, mei_cldev_cb_t rx_cb);
94int mei_cldev_register_notif_cb(struct mei_cl_device *cldev,
95 mei_cldev_cb_t notif_cb);
Samuel Ortiz3e833292013-03-27 17:29:55 +020096
Tomas Winklerbaeacd02015-09-10 10:18:02 +030097const uuid_le *mei_cldev_uuid(const struct mei_cl_device *cldev);
98u8 mei_cldev_ver(const struct mei_cl_device *cldev);
99
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300100void *mei_cldev_get_drvdata(const struct mei_cl_device *cldev);
101void mei_cldev_set_drvdata(struct mei_cl_device *cldev, void *data);
Samuel Ortizaa6aef22013-03-27 17:29:59 +0200102
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300103int mei_cldev_enable(struct mei_cl_device *cldev);
104int mei_cldev_disable(struct mei_cl_device *cldev);
Tomas Winkler01a14ed2015-09-10 10:18:03 +0300105bool mei_cldev_enabled(struct mei_cl_device *cldev);
Samuel Ortize46980a2013-04-09 01:51:38 +0300106
Samuel Ortize5354102013-03-27 17:29:53 +0200107#endif /* _LINUX_MEI_CL_BUS_H */