blob: 52aa4821093aa9db56273c51fb32bbce79f16754 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Tomas Winkler1e55b602019-03-12 00:10:44 +02002/*
3 * Copyright (c) 2013-2016, Intel Corporation. All rights reserved.
4 */
Samuel Ortize5354102013-03-27 17:29:53 +02005#ifndef _LINUX_MEI_CL_BUS_H
6#define _LINUX_MEI_CL_BUS_H
7
8#include <linux/device.h>
9#include <linux/uuid.h>
Tomas Winkler1f180352014-09-29 16:31:46 +030010#include <linux/mod_devicetable.h>
Samuel Ortize5354102013-03-27 17:29:53 +020011
12struct mei_cl_device;
Tomas Winkler512f64d2015-07-23 15:08:41 +030013struct mei_device;
Samuel Ortize5354102013-03-27 17:29:53 +020014
Alexander Usyskin7c7a6072016-11-16 22:51:29 +020015typedef void (*mei_cldev_cb_t)(struct mei_cl_device *cldev);
Tomas Winklerdbac9932015-05-07 15:54:07 +030016
17/**
18 * struct mei_cl_device - MEI device handle
19 * An mei_cl_device pointer is returned from mei_add_device()
20 * and links MEI bus clients to their actual ME host client pointer.
21 * Drivers for MEI devices will get an mei_cl_device pointer
22 * when being probed and shall use it for doing ME bus I/O.
23 *
Tomas Winkler0ff0a8d2015-07-23 15:08:42 +030024 * @bus_list: device on the bus list
Tomas Winkler512f64d2015-07-23 15:08:41 +030025 * @bus: parent mei device
Tomas Winklerdbac9932015-05-07 15:54:07 +030026 * @dev: linux driver model device pointer
27 * @me_cl: me client
28 * @cl: mei client
29 * @name: device name
Alexander Usyskin7c7a6072016-11-16 22:51:29 +020030 * @rx_work: async work to execute Rx event callback
31 * @rx_cb: Drivers register this callback to get asynchronous ME
32 * Rx buffer pending notifications.
33 * @notif_work: async work to execute FW notif event callback
34 * @notif_cb: Drivers register this callback to get asynchronous ME
35 * FW notification pending notifications.
Tomas Winkler71ce7892015-07-23 15:08:43 +030036 *
37 * @do_match: wheather device can be matched with a driver
Tomas Winkler0ff0a8d2015-07-23 15:08:42 +030038 * @is_added: device is already scanned
Tomas Winklerdbac9932015-05-07 15:54:07 +030039 * @priv_data: client private data
40 */
41struct mei_cl_device {
Tomas Winkler0ff0a8d2015-07-23 15:08:42 +030042 struct list_head bus_list;
Tomas Winkler512f64d2015-07-23 15:08:41 +030043 struct mei_device *bus;
Tomas Winklerdbac9932015-05-07 15:54:07 +030044 struct device dev;
45
46 struct mei_me_client *me_cl;
47 struct mei_cl *cl;
48 char name[MEI_CL_NAME_SIZE];
49
Alexander Usyskin7c7a6072016-11-16 22:51:29 +020050 struct work_struct rx_work;
51 mei_cldev_cb_t rx_cb;
52 struct work_struct notif_work;
53 mei_cldev_cb_t notif_cb;
Tomas Winkler71ce7892015-07-23 15:08:43 +030054
55 unsigned int do_match:1;
Tomas Winkler0ff0a8d2015-07-23 15:08:42 +030056 unsigned int is_added:1;
Tomas Winklerdbac9932015-05-07 15:54:07 +030057
58 void *priv_data;
59};
60
Tomas Winkler32ea33a2019-02-09 18:42:05 +020061#define to_mei_cl_device(d) container_of(d, struct mei_cl_device, dev)
62
Samuel Ortize5354102013-03-27 17:29:53 +020063struct mei_cl_driver {
64 struct device_driver driver;
65 const char *name;
66
67 const struct mei_cl_device_id *id_table;
68
Tomas Winkler89391382015-09-10 10:18:04 +030069 int (*probe)(struct mei_cl_device *cldev,
Samuel Ortize5354102013-03-27 17:29:53 +020070 const struct mei_cl_device_id *id);
Tomas Winkler89391382015-09-10 10:18:04 +030071 int (*remove)(struct mei_cl_device *cldev);
Samuel Ortize5354102013-03-27 17:29:53 +020072};
73
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030074int __mei_cldev_driver_register(struct mei_cl_driver *cldrv,
75 struct module *owner);
76#define mei_cldev_driver_register(cldrv) \
77 __mei_cldev_driver_register(cldrv, THIS_MODULE)
Samuel Ortiz333e4ee2013-03-27 17:29:54 +020078
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030079void mei_cldev_driver_unregister(struct mei_cl_driver *cldrv);
Samuel Ortiz333e4ee2013-03-27 17:29:54 +020080
Tomas Winkler5be149b2016-10-19 16:33:27 +030081/**
82 * module_mei_cl_driver - Helper macro for registering mei cl driver
83 *
Alexander Usyskin076802d2016-12-03 00:15:25 +020084 * @__mei_cldrv: mei_cl_driver structure
Tomas Winkler5be149b2016-10-19 16:33:27 +030085 *
86 * Helper macro for mei cl drivers which do not do anything special in module
87 * init/exit, for eliminating a boilerplate code.
88 */
89#define module_mei_cl_driver(__mei_cldrv) \
90 module_driver(__mei_cldrv, \
91 mei_cldev_driver_register,\
92 mei_cldev_driver_unregister)
93
Tomas Winklerd49dc5e2015-09-10 10:18:05 +030094ssize_t mei_cldev_send(struct mei_cl_device *cldev, u8 *buf, size_t length);
Alexander Usyskin076802d2016-12-03 00:15:25 +020095ssize_t mei_cldev_recv(struct mei_cl_device *cldev, u8 *buf, size_t length);
96ssize_t mei_cldev_recv_nonblock(struct mei_cl_device *cldev, u8 *buf,
97 size_t length);
Samuel Ortiz3e833292013-03-27 17:29:55 +020098
Alexander Usyskin7c7a6072016-11-16 22:51:29 +020099int mei_cldev_register_rx_cb(struct mei_cl_device *cldev, mei_cldev_cb_t rx_cb);
100int mei_cldev_register_notif_cb(struct mei_cl_device *cldev,
101 mei_cldev_cb_t notif_cb);
Samuel Ortiz3e833292013-03-27 17:29:55 +0200102
Tomas Winklerbaeacd02015-09-10 10:18:02 +0300103const uuid_le *mei_cldev_uuid(const struct mei_cl_device *cldev);
104u8 mei_cldev_ver(const struct mei_cl_device *cldev);
105
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300106void *mei_cldev_get_drvdata(const struct mei_cl_device *cldev);
107void mei_cldev_set_drvdata(struct mei_cl_device *cldev, void *data);
Samuel Ortizaa6aef22013-03-27 17:29:59 +0200108
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300109int mei_cldev_enable(struct mei_cl_device *cldev);
110int mei_cldev_disable(struct mei_cl_device *cldev);
Tomas Winkler01a14ed2015-09-10 10:18:03 +0300111bool mei_cldev_enabled(struct mei_cl_device *cldev);
Samuel Ortize46980a2013-04-09 01:51:38 +0300112
Samuel Ortize5354102013-03-27 17:29:53 +0200113#endif /* _LINUX_MEI_CL_BUS_H */