1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Intel ISH client Interface definitions
4  *
5  * Copyright (c) 2019, Intel Corporation.
6  */
7 
8 #ifndef _INTEL_ISH_CLIENT_IF_H_
9 #define _INTEL_ISH_CLIENT_IF_H_
10 
11 #include <linux/device.h>
12 #include <linux/mod_devicetable.h>
13 
14 struct ishtp_cl_device;
15 struct ishtp_device;
16 struct ishtp_cl;
17 struct ishtp_fw_client;
18 
19 typedef __printf(2, 3) void (*ishtp_print_log)(struct ishtp_device *dev,
20 					       const char *format, ...);
21 
22 /* Client state */
23 enum cl_state {
24 	ISHTP_CL_INITIALIZING = 0,
25 	ISHTP_CL_CONNECTING,
26 	ISHTP_CL_CONNECTED,
27 	ISHTP_CL_DISCONNECTING,
28 	ISHTP_CL_DISCONNECTED
29 };
30 
31 /**
32  * struct ishtp_cl_device - ISHTP device handle
33  * @driver:	driver instance on a bus
34  * @name:	Name of the device for probe
35  * @probe:	driver callback for device probe
36  * @remove:	driver callback on device removal
37  *
38  * Client drivers defines to get probed/removed for ISHTP client device.
39  */
40 struct ishtp_cl_driver {
41 	struct device_driver driver;
42 	const char *name;
43 	const struct ishtp_device_id *id;
44 	int (*probe)(struct ishtp_cl_device *dev);
45 	void (*remove)(struct ishtp_cl_device *dev);
46 	int (*reset)(struct ishtp_cl_device *dev);
47 	const struct dev_pm_ops *pm;
48 };
49 
50 /**
51  * struct ishtp_msg_data - ISHTP message data struct
52  * @size:	Size of data in the *data
53  * @data:	Pointer to data
54  */
55 struct ishtp_msg_data {
56 	uint32_t size;
57 	unsigned char *data;
58 };
59 
60 /*
61  * struct ishtp_cl_rb - request block structure
62  * @list:	Link to list members
63  * @cl:		ISHTP client instance
64  * @buffer:	message header
65  * @buf_idx:	Index into buffer
66  * @read_time:	 unused at this time
67  */
68 struct ishtp_cl_rb {
69 	struct list_head list;
70 	struct ishtp_cl *cl;
71 	struct ishtp_msg_data buffer;
72 	unsigned long buf_idx;
73 	unsigned long read_time;
74 };
75 
76 int ishtp_cl_driver_register(struct ishtp_cl_driver *driver,
77 			     struct module *owner);
78 void ishtp_cl_driver_unregister(struct ishtp_cl_driver *driver);
79 int ishtp_register_event_cb(struct ishtp_cl_device *device,
80 			    void (*read_cb)(struct ishtp_cl_device *));
81 
82 /* Get the device * from ishtp device instance */
83 struct device *ishtp_device(struct ishtp_cl_device *cl_device);
84 /* wait for IPC resume */
85 bool ishtp_wait_resume(struct ishtp_device *dev);
86 /* Trace interface for clients */
87 ishtp_print_log ishtp_trace_callback(struct ishtp_cl_device *cl_device);
88 /* Get device pointer of PCI device for DMA acces */
89 struct device *ishtp_get_pci_device(struct ishtp_cl_device *cl_device);
90 
91 struct ishtp_cl *ishtp_cl_allocate(struct ishtp_cl_device *cl_device);
92 void ishtp_cl_free(struct ishtp_cl *cl);
93 int ishtp_cl_link(struct ishtp_cl *cl);
94 void ishtp_cl_unlink(struct ishtp_cl *cl);
95 int ishtp_cl_disconnect(struct ishtp_cl *cl);
96 int ishtp_cl_connect(struct ishtp_cl *cl);
97 int ishtp_cl_send(struct ishtp_cl *cl, uint8_t *buf, size_t length);
98 int ishtp_cl_flush_queues(struct ishtp_cl *cl);
99 int ishtp_cl_io_rb_recycle(struct ishtp_cl_rb *rb);
100 bool ishtp_cl_tx_empty(struct ishtp_cl *cl);
101 struct ishtp_cl_rb *ishtp_cl_rx_get_rb(struct ishtp_cl *cl);
102 void *ishtp_get_client_data(struct ishtp_cl *cl);
103 void ishtp_set_client_data(struct ishtp_cl *cl, void *data);
104 struct ishtp_device *ishtp_get_ishtp_device(struct ishtp_cl *cl);
105 void ishtp_set_tx_ring_size(struct ishtp_cl *cl, int size);
106 void ishtp_set_rx_ring_size(struct ishtp_cl *cl, int size);
107 void ishtp_set_connection_state(struct ishtp_cl *cl, int state);
108 void ishtp_cl_set_fw_client_id(struct ishtp_cl *cl, int fw_client_id);
109 
110 void ishtp_put_device(struct ishtp_cl_device *cl_dev);
111 void ishtp_get_device(struct ishtp_cl_device *cl_dev);
112 void ishtp_set_drvdata(struct ishtp_cl_device *cl_device, void *data);
113 void *ishtp_get_drvdata(struct ishtp_cl_device *cl_device);
114 struct ishtp_cl_device *ishtp_dev_to_cl_device(struct device *dev);
115 int ishtp_register_event_cb(struct ishtp_cl_device *device,
116 				void (*read_cb)(struct ishtp_cl_device *));
117 struct	ishtp_fw_client *ishtp_fw_cl_get_client(struct ishtp_device *dev,
118 						const guid_t *uuid);
119 int ishtp_get_fw_client_id(struct ishtp_fw_client *fw_client);
120 int ish_hw_reset(struct ishtp_device *dev);
121 #endif /* _INTEL_ISH_CLIENT_IF_H_ */
122