xref: /openbmc/linux/include/linux/mei_cl_bus.h (revision 2266e58a)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2013-2016, Intel Corporation. All rights reserved.
4  */
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>
10 #include <linux/mod_devicetable.h>
11 
12 struct mei_cl_device;
13 struct mei_device;
14 struct scatterlist;
15 
16 typedef void (*mei_cldev_cb_t)(struct mei_cl_device *cldev);
17 
18 /**
19  * struct mei_cl_device - MEI device handle
20  * An mei_cl_device pointer is returned from mei_add_device()
21  * and links MEI bus clients to their actual ME host client pointer.
22  * Drivers for MEI devices will get an mei_cl_device pointer
23  * when being probed and shall use it for doing ME bus I/O.
24  *
25  * @bus_list: device on the bus list
26  * @bus: parent mei device
27  * @dev: linux driver model device pointer
28  * @me_cl: me client
29  * @cl: mei client
30  * @name: device name
31  * @rx_work: async work to execute Rx event callback
32  * @rx_cb: Drivers register this callback to get asynchronous ME
33  *	Rx buffer pending notifications.
34  * @notif_work: async work to execute FW notif event callback
35  * @notif_cb: Drivers register this callback to get asynchronous ME
36  *	FW notification pending notifications.
37  *
38  * @do_match: wheather device can be matched with a driver
39  * @is_added: device is already scanned
40  * @priv_data: client private data
41  */
42 struct mei_cl_device {
43 	struct list_head bus_list;
44 	struct mei_device *bus;
45 	struct device dev;
46 
47 	struct mei_me_client *me_cl;
48 	struct mei_cl *cl;
49 	char name[MEI_CL_NAME_SIZE];
50 
51 	struct work_struct rx_work;
52 	mei_cldev_cb_t rx_cb;
53 	struct work_struct notif_work;
54 	mei_cldev_cb_t notif_cb;
55 
56 	unsigned int do_match:1;
57 	unsigned int is_added:1;
58 
59 	void *priv_data;
60 };
61 
62 #define to_mei_cl_device(d) container_of(d, struct mei_cl_device, dev)
63 
64 struct mei_cl_driver {
65 	struct device_driver driver;
66 	const char *name;
67 
68 	const struct mei_cl_device_id *id_table;
69 
70 	int (*probe)(struct mei_cl_device *cldev,
71 		     const struct mei_cl_device_id *id);
72 	void (*remove)(struct mei_cl_device *cldev);
73 };
74 
75 int __mei_cldev_driver_register(struct mei_cl_driver *cldrv,
76 				struct module *owner);
77 #define mei_cldev_driver_register(cldrv)             \
78 	__mei_cldev_driver_register(cldrv, THIS_MODULE)
79 
80 void mei_cldev_driver_unregister(struct mei_cl_driver *cldrv);
81 
82 /**
83  * module_mei_cl_driver - Helper macro for registering mei cl driver
84  *
85  * @__mei_cldrv: mei_cl_driver structure
86  *
87  *  Helper macro for mei cl drivers which do not do anything special in module
88  *  init/exit, for eliminating a boilerplate code.
89  */
90 #define module_mei_cl_driver(__mei_cldrv) \
91 	module_driver(__mei_cldrv, \
92 		      mei_cldev_driver_register,\
93 		      mei_cldev_driver_unregister)
94 
95 ssize_t mei_cldev_send(struct mei_cl_device *cldev, const u8 *buf,
96 		       size_t length);
97 ssize_t mei_cldev_recv(struct mei_cl_device *cldev, u8 *buf, size_t length);
98 ssize_t mei_cldev_recv_nonblock(struct mei_cl_device *cldev, u8 *buf,
99 				size_t length);
100 ssize_t mei_cldev_send_vtag(struct mei_cl_device *cldev, const u8 *buf,
101 			    size_t length, u8 vtag);
102 ssize_t mei_cldev_recv_vtag(struct mei_cl_device *cldev, u8 *buf, size_t length,
103 			    u8 *vtag);
104 ssize_t mei_cldev_recv_nonblock_vtag(struct mei_cl_device *cldev, u8 *buf,
105 				     size_t length, u8 *vtag);
106 
107 int mei_cldev_register_rx_cb(struct mei_cl_device *cldev, mei_cldev_cb_t rx_cb);
108 int mei_cldev_register_notif_cb(struct mei_cl_device *cldev,
109 				mei_cldev_cb_t notif_cb);
110 
111 const uuid_le *mei_cldev_uuid(const struct mei_cl_device *cldev);
112 u8 mei_cldev_ver(const struct mei_cl_device *cldev);
113 
114 void *mei_cldev_get_drvdata(const struct mei_cl_device *cldev);
115 void mei_cldev_set_drvdata(struct mei_cl_device *cldev, void *data);
116 
117 int mei_cldev_enable(struct mei_cl_device *cldev);
118 int mei_cldev_disable(struct mei_cl_device *cldev);
119 bool mei_cldev_enabled(const struct mei_cl_device *cldev);
120 ssize_t mei_cldev_send_gsc_command(struct mei_cl_device *cldev,
121 				   u8 client_id, u32 fence_id,
122 				   struct scatterlist *sg_in,
123 				   size_t total_in_len,
124 				   struct scatterlist *sg_out);
125 
126 void *mei_cldev_dma_map(struct mei_cl_device *cldev, u8 buffer_id, size_t size);
127 int mei_cldev_dma_unmap(struct mei_cl_device *cldev);
128 
129 #endif /* _LINUX_MEI_CL_BUS_H */
130