1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 /* Copyright (c) 2018, The Linux Foundation. All rights reserved.
4  * Copyright (C) 2018-2020 Linaro Ltd.
5  */
6 #ifndef _IPA_QMI_MSG_H_
7 #define _IPA_QMI_MSG_H_
8 
9 /* === Only "ipa_qmi" and "ipa_qmi_msg.c" should include this file === */
10 
11 #include <linux/types.h>
12 #include <linux/soc/qcom/qmi.h>
13 
14 /* Request/response/indication QMI message ids used for IPA.  Receiving
15  * end issues a response for requests; indications require no response.
16  */
17 #define IPA_QMI_INDICATION_REGISTER	0x20	/* modem -> AP request */
18 #define IPA_QMI_INIT_DRIVER		0x21	/* AP -> modem request */
19 #define IPA_QMI_INIT_COMPLETE		0x22	/* AP -> modem indication */
20 #define IPA_QMI_DRIVER_INIT_COMPLETE	0x35	/* modem -> AP request */
21 
22 /* The maximum size required for message types.  These sizes include
23  * the message data, along with type (1 byte) and length (2 byte)
24  * information for each field.  The qmi_send_*() interfaces require
25  * the message size to be provided.
26  */
27 #define IPA_QMI_INDICATION_REGISTER_REQ_SZ	12	/* -> server handle */
28 #define IPA_QMI_INDICATION_REGISTER_RSP_SZ	7	/* <- server handle */
29 #define IPA_QMI_INIT_DRIVER_REQ_SZ		162	/* client handle -> */
30 #define IPA_QMI_INIT_DRIVER_RSP_SZ		25	/* client handle <- */
31 #define IPA_QMI_INIT_COMPLETE_IND_SZ		7	/* <- server handle */
32 #define IPA_QMI_DRIVER_INIT_COMPLETE_REQ_SZ	4	/* -> server handle */
33 #define IPA_QMI_DRIVER_INIT_COMPLETE_RSP_SZ	7	/* <- server handle */
34 
35 /* Maximum size of messages we expect the AP to receive (max of above) */
36 #define IPA_QMI_SERVER_MAX_RCV_SZ		8
37 #define IPA_QMI_CLIENT_MAX_RCV_SZ		25
38 
39 /* Request message for the IPA_QMI_INDICATION_REGISTER request */
40 struct ipa_indication_register_req {
41 	u8 master_driver_init_complete_valid;
42 	u8 master_driver_init_complete;
43 	u8 data_usage_quota_reached_valid;
44 	u8 data_usage_quota_reached;
45 	u8 ipa_mhi_ready_ind_valid;
46 	u8 ipa_mhi_ready_ind;
47 };
48 
49 /* The response to a IPA_QMI_INDICATION_REGISTER request consists only of
50  * a standard QMI response.
51  */
52 struct ipa_indication_register_rsp {
53 	struct qmi_response_type_v01 rsp;
54 };
55 
56 /* Request message for the IPA_QMI_DRIVER_INIT_COMPLETE request */
57 struct ipa_driver_init_complete_req {
58 	u8 status;
59 };
60 
61 /* The response to a IPA_QMI_DRIVER_INIT_COMPLETE request consists only
62  * of a standard QMI response.
63  */
64 struct ipa_driver_init_complete_rsp {
65 	struct qmi_response_type_v01 rsp;
66 };
67 
68 /* The message for the IPA_QMI_INIT_COMPLETE_IND indication consists
69  * only of a standard QMI response.
70  */
71 struct ipa_init_complete_ind {
72 	struct qmi_response_type_v01 status;
73 };
74 
75 /* The AP tells the modem its platform type.  We assume Android. */
76 enum ipa_platform_type {
77 	IPA_QMI_PLATFORM_TYPE_INVALID		= 0,	/* Invalid */
78 	IPA_QMI_PLATFORM_TYPE_TN		= 1,	/* Data card */
79 	IPA_QMI_PLATFORM_TYPE_LE		= 2,	/* Data router */
80 	IPA_QMI_PLATFORM_TYPE_MSM_ANDROID	= 3,	/* Android MSM */
81 	IPA_QMI_PLATFORM_TYPE_MSM_WINDOWS	= 4,	/* Windows MSM */
82 	IPA_QMI_PLATFORM_TYPE_MSM_QNX_V01	= 5,	/* QNX MSM */
83 };
84 
85 /* This defines the start and end offset of a range of memory.  Both
86  * fields are offsets relative to the start of IPA shared memory.
87  * The end value is the last addressable byte *within* the range.
88  */
89 struct ipa_mem_bounds {
90 	u32 start;
91 	u32 end;
92 };
93 
94 /* This defines the location and size of an array.  The start value
95  * is an offset relative to the start of IPA shared memory.  The
96  * size of the array is implied by the number of entries (the entry
97  * size is assumed to be known).
98  */
99 struct ipa_mem_array {
100 	u32 start;
101 	u32 count;
102 };
103 
104 /* This defines the location and size of a range of memory.  The
105  * start is an offset relative to the start of IPA shared memory.
106  * This differs from the ipa_mem_bounds structure in that the size
107  * (in bytes) of the memory region is specified rather than the
108  * offset of its last byte.
109  */
110 struct ipa_mem_range {
111 	u32 start;
112 	u32 size;
113 };
114 
115 /* The message for the IPA_QMI_INIT_DRIVER request contains information
116  * from the AP that affects modem initialization.
117  */
118 struct ipa_init_modem_driver_req {
119 	u8			platform_type_valid;
120 	u32			platform_type;	/* enum ipa_platform_type */
121 
122 	/* Modem header table information.  This defines the IPA shared
123 	 * memory in which the modem may insert header table entries.
124 	 */
125 	u8			hdr_tbl_info_valid;
126 	struct ipa_mem_bounds	hdr_tbl_info;
127 
128 	/* Routing table information.  These define the location and size of
129 	 * non-hashable IPv4 and IPv6 filter tables.  The start values are
130 	 * offsets relative to the start of IPA shared memory.
131 	 */
132 	u8			v4_route_tbl_info_valid;
133 	struct ipa_mem_array	v4_route_tbl_info;
134 	u8			v6_route_tbl_info_valid;
135 	struct ipa_mem_array	v6_route_tbl_info;
136 
137 	/* Filter table information.  These define the location of the
138 	 * non-hashable IPv4 and IPv6 filter tables.  The start values are
139 	 * offsets relative to the start of IPA shared memory.
140 	 */
141 	u8			v4_filter_tbl_start_valid;
142 	u32			v4_filter_tbl_start;
143 	u8			v6_filter_tbl_start_valid;
144 	u32			v6_filter_tbl_start;
145 
146 	/* Modem memory information.  This defines the location and
147 	 * size of memory available for the modem to use.
148 	 */
149 	u8			modem_mem_info_valid;
150 	struct ipa_mem_range	modem_mem_info;
151 
152 	/* This defines the destination endpoint on the AP to which
153 	 * the modem driver can send control commands.  Must be less
154 	 * than ipa_endpoint_max().
155 	 */
156 	u8			ctrl_comm_dest_end_pt_valid;
157 	u32			ctrl_comm_dest_end_pt;
158 
159 	/* This defines whether the modem should load the microcontroller
160 	 * or not.  It is unnecessary to reload it if the modem is being
161 	 * restarted.
162 	 *
163 	 * NOTE: this field is named "is_ssr_bootup" elsewhere.
164 	 */
165 	u8			skip_uc_load_valid;
166 	u8			skip_uc_load;
167 
168 	/* Processing context memory information.  This defines the memory in
169 	 * which the modem may insert header processing context table entries.
170 	 */
171 	u8			hdr_proc_ctx_tbl_info_valid;
172 	struct ipa_mem_bounds	hdr_proc_ctx_tbl_info;
173 
174 	/* Compression command memory information.  This defines the memory
175 	 * in which the modem may insert compression/decompression commands.
176 	 */
177 	u8			zip_tbl_info_valid;
178 	struct ipa_mem_bounds	zip_tbl_info;
179 
180 	/* Routing table information.  These define the location and size
181 	 * of hashable IPv4 and IPv6 filter tables.  The start values are
182 	 * offsets relative to the start of IPA shared memory.
183 	 */
184 	u8			v4_hash_route_tbl_info_valid;
185 	struct ipa_mem_array	v4_hash_route_tbl_info;
186 	u8			v6_hash_route_tbl_info_valid;
187 	struct ipa_mem_array	v6_hash_route_tbl_info;
188 
189 	/* Filter table information.  These define the location and size
190 	 * of hashable IPv4 and IPv6 filter tables.  The start values are
191 	 * offsets relative to the start of IPA shared memory.
192 	 */
193 	u8			v4_hash_filter_tbl_start_valid;
194 	u32			v4_hash_filter_tbl_start;
195 	u8			v6_hash_filter_tbl_start_valid;
196 	u32			v6_hash_filter_tbl_start;
197 
198 	/* Statistics information.  These define the locations of the
199 	 * first and last statistics sub-regions.  (IPA v4.0 and above)
200 	 */
201 	u8			hw_stats_quota_base_addr_valid;
202 	u32			hw_stats_quota_base_addr;
203 	u8			hw_stats_quota_size_valid;
204 	u32			hw_stats_quota_size;
205 	u8			hw_stats_drop_base_addr_valid;
206 	u32			hw_stats_drop_base_addr;
207 	u8			hw_stats_drop_size_valid;
208 	u32			hw_stats_drop_size;
209 };
210 
211 /* The response to a IPA_QMI_INIT_DRIVER request begins with a standard
212  * QMI response, but contains other information as well.  Currently we
213  * simply wait for the the INIT_DRIVER transaction to complete and
214  * ignore any other data that might be returned.
215  */
216 struct ipa_init_modem_driver_rsp {
217 	struct qmi_response_type_v01	rsp;
218 
219 	/* This defines the destination endpoint on the modem to which
220 	 * the AP driver can send control commands.  Must be less than
221 	 * ipa_endpoint_max().
222 	 */
223 	u8				ctrl_comm_dest_end_pt_valid;
224 	u32				ctrl_comm_dest_end_pt;
225 
226 	/* This defines the default endpoint.  The AP driver is not
227 	 * required to configure the hardware with this value.  Must
228 	 * be less than ipa_endpoint_max().
229 	 */
230 	u8				default_end_pt_valid;
231 	u32				default_end_pt;
232 
233 	/* This defines whether a second handshake is required to complete
234 	 * initialization.
235 	 */
236 	u8				modem_driver_init_pending_valid;
237 	u8				modem_driver_init_pending;
238 };
239 
240 /* Message structure definitions defined in "ipa_qmi_msg.c" */
241 extern struct qmi_elem_info ipa_indication_register_req_ei[];
242 extern struct qmi_elem_info ipa_indication_register_rsp_ei[];
243 extern struct qmi_elem_info ipa_driver_init_complete_req_ei[];
244 extern struct qmi_elem_info ipa_driver_init_complete_rsp_ei[];
245 extern struct qmi_elem_info ipa_init_complete_ind_ei[];
246 extern struct qmi_elem_info ipa_mem_bounds_ei[];
247 extern struct qmi_elem_info ipa_mem_array_ei[];
248 extern struct qmi_elem_info ipa_mem_range_ei[];
249 extern struct qmi_elem_info ipa_init_modem_driver_req_ei[];
250 extern struct qmi_elem_info ipa_init_modem_driver_rsp_ei[];
251 
252 #endif /* !_IPA_QMI_MSG_H_ */
253