Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Tomas Winkler | 1e55b60 | 2019-03-12 00:10:44 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013-2016, Intel Corporation. All rights reserved. |
| 4 | */ |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 5 | #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 Winkler | 1f18035 | 2014-09-29 16:31:46 +0300 | [diff] [blame] | 10 | #include <linux/mod_devicetable.h> |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 11 | |
| 12 | struct mei_cl_device; |
Tomas Winkler | 512f64d | 2015-07-23 15:08:41 +0300 | [diff] [blame] | 13 | struct mei_device; |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 14 | |
Alexander Usyskin | 7c7a607 | 2016-11-16 22:51:29 +0200 | [diff] [blame] | 15 | typedef void (*mei_cldev_cb_t)(struct mei_cl_device *cldev); |
Tomas Winkler | dbac993 | 2015-05-07 15:54:07 +0300 | [diff] [blame] | 16 | |
| 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 Winkler | 0ff0a8d | 2015-07-23 15:08:42 +0300 | [diff] [blame] | 24 | * @bus_list: device on the bus list |
Tomas Winkler | 512f64d | 2015-07-23 15:08:41 +0300 | [diff] [blame] | 25 | * @bus: parent mei device |
Tomas Winkler | dbac993 | 2015-05-07 15:54:07 +0300 | [diff] [blame] | 26 | * @dev: linux driver model device pointer |
| 27 | * @me_cl: me client |
| 28 | * @cl: mei client |
| 29 | * @name: device name |
Alexander Usyskin | 7c7a607 | 2016-11-16 22:51:29 +0200 | [diff] [blame] | 30 | * @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 Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 36 | * |
| 37 | * @do_match: wheather device can be matched with a driver |
Tomas Winkler | 0ff0a8d | 2015-07-23 15:08:42 +0300 | [diff] [blame] | 38 | * @is_added: device is already scanned |
Tomas Winkler | dbac993 | 2015-05-07 15:54:07 +0300 | [diff] [blame] | 39 | * @priv_data: client private data |
| 40 | */ |
| 41 | struct mei_cl_device { |
Tomas Winkler | 0ff0a8d | 2015-07-23 15:08:42 +0300 | [diff] [blame] | 42 | struct list_head bus_list; |
Tomas Winkler | 512f64d | 2015-07-23 15:08:41 +0300 | [diff] [blame] | 43 | struct mei_device *bus; |
Tomas Winkler | dbac993 | 2015-05-07 15:54:07 +0300 | [diff] [blame] | 44 | 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 Usyskin | 7c7a607 | 2016-11-16 22:51:29 +0200 | [diff] [blame] | 50 | 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 Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 54 | |
| 55 | unsigned int do_match:1; |
Tomas Winkler | 0ff0a8d | 2015-07-23 15:08:42 +0300 | [diff] [blame] | 56 | unsigned int is_added:1; |
Tomas Winkler | dbac993 | 2015-05-07 15:54:07 +0300 | [diff] [blame] | 57 | |
| 58 | void *priv_data; |
| 59 | }; |
| 60 | |
Tomas Winkler | 32ea33a | 2019-02-09 18:42:05 +0200 | [diff] [blame] | 61 | #define to_mei_cl_device(d) container_of(d, struct mei_cl_device, dev) |
| 62 | |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 63 | struct mei_cl_driver { |
| 64 | struct device_driver driver; |
| 65 | const char *name; |
| 66 | |
| 67 | const struct mei_cl_device_id *id_table; |
| 68 | |
Tomas Winkler | 8939138 | 2015-09-10 10:18:04 +0300 | [diff] [blame] | 69 | int (*probe)(struct mei_cl_device *cldev, |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 70 | const struct mei_cl_device_id *id); |
Tomas Winkler | 8939138 | 2015-09-10 10:18:04 +0300 | [diff] [blame] | 71 | int (*remove)(struct mei_cl_device *cldev); |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 72 | }; |
| 73 | |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 74 | int __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 Ortiz | 333e4ee | 2013-03-27 17:29:54 +0200 | [diff] [blame] | 78 | |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 79 | void mei_cldev_driver_unregister(struct mei_cl_driver *cldrv); |
Samuel Ortiz | 333e4ee | 2013-03-27 17:29:54 +0200 | [diff] [blame] | 80 | |
Tomas Winkler | 5be149b | 2016-10-19 16:33:27 +0300 | [diff] [blame] | 81 | /** |
| 82 | * module_mei_cl_driver - Helper macro for registering mei cl driver |
| 83 | * |
Alexander Usyskin | 076802d | 2016-12-03 00:15:25 +0200 | [diff] [blame] | 84 | * @__mei_cldrv: mei_cl_driver structure |
Tomas Winkler | 5be149b | 2016-10-19 16:33:27 +0300 | [diff] [blame] | 85 | * |
| 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 Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 94 | ssize_t mei_cldev_send(struct mei_cl_device *cldev, u8 *buf, size_t length); |
Alexander Usyskin | 076802d | 2016-12-03 00:15:25 +0200 | [diff] [blame] | 95 | ssize_t mei_cldev_recv(struct mei_cl_device *cldev, u8 *buf, size_t length); |
| 96 | ssize_t mei_cldev_recv_nonblock(struct mei_cl_device *cldev, u8 *buf, |
| 97 | size_t length); |
Samuel Ortiz | 3e83329 | 2013-03-27 17:29:55 +0200 | [diff] [blame] | 98 | |
Alexander Usyskin | 7c7a607 | 2016-11-16 22:51:29 +0200 | [diff] [blame] | 99 | int mei_cldev_register_rx_cb(struct mei_cl_device *cldev, mei_cldev_cb_t rx_cb); |
| 100 | int mei_cldev_register_notif_cb(struct mei_cl_device *cldev, |
| 101 | mei_cldev_cb_t notif_cb); |
Samuel Ortiz | 3e83329 | 2013-03-27 17:29:55 +0200 | [diff] [blame] | 102 | |
Tomas Winkler | baeacd0 | 2015-09-10 10:18:02 +0300 | [diff] [blame] | 103 | const uuid_le *mei_cldev_uuid(const struct mei_cl_device *cldev); |
| 104 | u8 mei_cldev_ver(const struct mei_cl_device *cldev); |
| 105 | |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 106 | void *mei_cldev_get_drvdata(const struct mei_cl_device *cldev); |
| 107 | void mei_cldev_set_drvdata(struct mei_cl_device *cldev, void *data); |
Samuel Ortiz | aa6aef2 | 2013-03-27 17:29:59 +0200 | [diff] [blame] | 108 | |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 109 | int mei_cldev_enable(struct mei_cl_device *cldev); |
| 110 | int mei_cldev_disable(struct mei_cl_device *cldev); |
Tomas Winkler | 01a14ed | 2015-09-10 10:18:03 +0300 | [diff] [blame] | 111 | bool mei_cldev_enabled(struct mei_cl_device *cldev); |
Samuel Ortiz | e46980a | 2013-04-09 01:51:38 +0300 | [diff] [blame] | 112 | |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 113 | #endif /* _LINUX_MEI_CL_BUS_H */ |