blob: fcddc484cd6738f724f7d2891bcb78f9a553be02 [file] [log] [blame]
Puja Gupta4f27f592017-02-24 17:19:38 -08001/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
Karthikeyan Ramasubramanianfafd67f12016-09-16 17:15:13 -06002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _MSM_QMI_INTERFACE_H_
14#define _MSM_QMI_INTERFACE_H_
15
16#include <linux/types.h>
17#include <linux/errno.h>
18#include <linux/mm.h>
19#include <linux/list.h>
20#include <linux/socket.h>
21#include <linux/gfp.h>
22#include <linux/qmi_encdec.h>
23#include <linux/workqueue.h>
24
25#define QMI_COMMON_TLV_TYPE 0
26
27enum qmi_event_type {
28 QMI_RECV_MSG = 1,
29 QMI_SERVER_ARRIVE,
30 QMI_SERVER_EXIT,
31};
32
33/**
34 * struct qmi_handle - QMI Handle Data Structure
35 * @handle_hash: Hash Table Node in which this handle is present.
36 * @src_port: Pointer to port used for message exchange.
37 * @ctl_port: Pointer to port used for out-of-band event exchange.
38 * @handle_type: Type of handle(Service/Client).
39 * @next_txn_id: Transaction ID of the next outgoing request.
40 * @handle_wq: Workqueue to handle any handle-specific events.
41 * @handle_lock: Lock to protect access to elements in the handle.
42 * @notify_lock: Lock to protect and generate notification atomically.
43 * @notify: Function to notify the handle owner of an event.
44 * @notify_priv: Private info to be passed during the notifcation.
45 * @handle_reset: Flag to hold the reset state of the handle.
46 * @reset_waitq: Wait queue to wait for any reset events.
47 * @ctl_work: Work to handle the out-of-band events for this handle.
48 * @dest_info: Destination to which this handle is connected to.
49 * @dest_service_id: service id of the service that client connected to.
50 * @txn_list: List of transactions waiting for the response.
51 * @ind_cb: Function to notify the handle owner of an indication message.
52 * @ind_cb_priv: Private info to be passed during an indication notification.
53 * @resume_tx_work: Work to resume the tx when the transport is not busy.
54 * @pending_txn_list: List of requests pending tx due to busy transport.
55 * @conn_list: List of connections handled by the service.
56 * @svc_ops_options: Service specific operations and options.
57 */
58struct qmi_handle {
59 struct hlist_node handle_hash;
60 void *src_port;
61 void *ctl_port;
62 unsigned int handle_type;
63 uint16_t next_txn_id;
64 struct workqueue_struct *handle_wq;
65 struct mutex handle_lock;
66 spinlock_t notify_lock;
67 void (*notify)(struct qmi_handle *handle, enum qmi_event_type event,
68 void *notify_priv);
69 void *notify_priv;
70 int handle_reset;
71 wait_queue_head_t reset_waitq;
72 struct delayed_work ctl_work;
73
74 /* Client specific elements */
75 void *dest_info;
76 uint32_t dest_service_id;
77 struct list_head txn_list;
78 void (*ind_cb)(struct qmi_handle *handle,
79 unsigned int msg_id, void *msg,
80 unsigned int msg_len, void *ind_cb_priv);
81 void *ind_cb_priv;
82 struct delayed_work resume_tx_work;
83 struct list_head pending_txn_list;
84
85 /* Service specific elements */
86 struct list_head conn_list;
87 struct qmi_svc_ops_options *svc_ops_options;
88};
89
90enum qmi_result_type_v01 {
91 /* To force a 32 bit signed enum. Do not change or use*/
92 QMI_RESULT_TYPE_MIN_ENUM_VAL_V01 = INT_MIN,
93 QMI_RESULT_SUCCESS_V01 = 0,
94 QMI_RESULT_FAILURE_V01 = 1,
Karthikeyan Ramasubramanianfafd67f12016-09-16 17:15:13 -060095 QMI_RESULT_TYPE_MAX_ENUM_VAL_V01 = INT_MAX,
96};
97
98enum qmi_error_type_v01 {
99 /* To force a 32 bit signed enum. Do not change or use*/
100 QMI_ERR_TYPE_MIN_ENUM_VAL_V01 = INT_MIN,
101 QMI_ERR_NONE_V01 = 0x0000,
102 QMI_ERR_MALFORMED_MSG_V01 = 0x0001,
103 QMI_ERR_NO_MEMORY_V01 = 0x0002,
104 QMI_ERR_INTERNAL_V01 = 0x0003,
105 QMI_ERR_CLIENT_IDS_EXHAUSTED_V01 = 0x0005,
106 QMI_ERR_INVALID_ID_V01 = 0x0029,
107 QMI_ERR_ENCODING_V01 = 0x003A,
Puja Gupta1c4c1f02017-05-15 11:15:07 -0700108 QMI_ERR_DISABLED_V01 = 0x0045,
Karthikeyan Ramasubramanianfafd67f12016-09-16 17:15:13 -0600109 QMI_ERR_INCOMPATIBLE_STATE_V01 = 0x005A,
110 QMI_ERR_NOT_SUPPORTED_V01 = 0x005E,
111 QMI_ERR_TYPE_MAX_ENUM_VAL_V01 = INT_MAX,
112};
113
114struct qmi_response_type_v01 {
115 enum qmi_result_type_v01 result;
116 enum qmi_error_type_v01 error;
117};
118
119/**
120 * qmi_svc_ops_options - Operations and options to be specified when
121 * a service registers.
122 * @version: Version field to identify the ops_options structure.
123 * @service_id: Service ID of the service.
124 * @service_vers: Version to identify the client-service compatibility.
125 * @service_ins: Instance ID registered by the service.
126 * @connect_cb: Callback when a new client connects with the service.
127 * @disconnect_cb: Callback when the client exits the connection.
128 * @req_desc_cb: Callback to get request structure and its descriptor
129 * for a message id.
130 * @req_cb: Callback to process the request.
131 */
132struct qmi_svc_ops_options {
133 unsigned int version;
134 uint32_t service_id;
135 uint32_t service_vers;
136 uint32_t service_ins;
137 int (*connect_cb)(struct qmi_handle *handle,
138 void *conn_handle);
139 int (*disconnect_cb)(struct qmi_handle *handle,
140 void *conn_handle);
141 int (*req_desc_cb)(unsigned int msg_id,
142 struct msg_desc **req_desc);
143 int (*req_cb)(struct qmi_handle *handle,
144 void *conn_handle,
145 void *req_handle,
146 unsigned int msg_id,
147 void *req);
148};
149
150#ifdef CONFIG_MSM_QMI_INTERFACE
151
152/* Element info array describing common qmi response structure */
153extern struct elem_info qmi_response_type_v01_ei[];
154#define get_qmi_response_type_v01_ei() qmi_response_type_v01_ei
155
156/**
157 * qmi_handle_create() - Create a QMI handle
158 * @notify: Callback to notify events on the handle created.
159 * @notify_priv: Private information to be passed along with the notification.
160 *
161 * @return: Valid QMI handle on success, NULL on error.
162 */
163struct qmi_handle *qmi_handle_create(
164 void (*notify)(struct qmi_handle *handle,
165 enum qmi_event_type event, void *notify_priv),
166 void *notify_priv);
167
168/**
169 * qmi_handle_destroy() - Destroy the QMI handle
170 * @handle: QMI handle to be destroyed.
171 *
172 * @return: 0 on success, < 0 on error.
173 */
174int qmi_handle_destroy(struct qmi_handle *handle);
175
176/**
177 * qmi_register_ind_cb() - Register the indication callback function
178 * @handle: QMI handle with which the function is registered.
179 * @ind_cb: Callback function to be registered.
180 * @ind_cb_priv: Private data to be passed with the indication callback.
181 *
182 * @return: 0 on success, < 0 on error.
183 */
184int qmi_register_ind_cb(struct qmi_handle *handle,
185 void (*ind_cb)(struct qmi_handle *handle,
186 unsigned int msg_id, void *msg,
187 unsigned int msg_len, void *ind_cb_priv),
188 void *ind_cb_priv);
189
190/**
191 * qmi_send_req_wait() - Send a synchronous QMI request
192 * @handle: QMI handle through which the QMI request is sent.
193 * @request_desc: Structure describing the request data structure.
194 * @req: Buffer containing the request data structure.
195 * @req_len: Length of the request data structure.
196 * @resp_desc: Structure describing the response data structure.
197 * @resp: Buffer to hold the response data structure.
198 * @resp_len: Length of the response data structure.
199 * @timeout_ms: Timeout before a response is received.
200 *
201 * @return: 0 on success, < 0 on error.
202 */
203int qmi_send_req_wait(struct qmi_handle *handle,
204 struct msg_desc *req_desc,
205 void *req, unsigned int req_len,
206 struct msg_desc *resp_desc,
207 void *resp, unsigned int resp_len,
208 unsigned long timeout_ms);
209
210/**
211 * qmi_send_req_nowait() - Send an asynchronous QMI request
212 * @handle: QMI handle through which the QMI request is sent.
213 * @request_desc: Structure describing the request data structure.
214 * @req: Buffer containing the request data structure.
215 * @req_len: Length of the request data structure.
216 * @resp_desc: Structure describing the response data structure.
217 * @resp: Buffer to hold the response data structure.
218 * @resp_len: Length of the response data structure.
219 * @resp_cb: Callback function to be invoked when the response arrives.
220 * @resp_cb_data: Private information to be passed along with the callback.
221 *
222 * @return: 0 on success, < 0 on error.
223 */
224int qmi_send_req_nowait(struct qmi_handle *handle,
225 struct msg_desc *req_desc,
226 void *req, unsigned int req_len,
227 struct msg_desc *resp_desc,
228 void *resp, unsigned int resp_len,
229 void (*resp_cb)(struct qmi_handle *handle,
230 unsigned int msg_id, void *msg,
231 void *resp_cb_data,
232 int stat),
233 void *resp_cb_data);
234
235/**
236 * qmi_recv_msg() - Receive the QMI message
237 * @handle: Handle for which the QMI message has to be received.
238 *
239 * @return: 0 on success, < 0 on error.
240 */
241int qmi_recv_msg(struct qmi_handle *handle);
242
243/**
244 * qmi_connect_to_service() - Connect the QMI handle with a QMI service
245 * @handle: QMI handle to be connected with the QMI service.
246 * @service_id: Service id to identify the QMI service.
247 * @service_vers: Version to identify the compatibility.
248 * @service_ins: Instance id to identify the instance of the QMI service.
249 *
250 * @return: 0 on success, < 0 on error.
251 */
252int qmi_connect_to_service(struct qmi_handle *handle,
253 uint32_t service_id,
254 uint32_t service_vers,
255 uint32_t service_ins);
256
257/**
258 * qmi_svc_event_notifier_register() - Register a notifier block to receive
259 * events regarding a QMI service
260 * @service_id: Service ID to identify the QMI service.
261 * @service_vers: Version to identify the compatibility.
262 * @service_ins: Instance ID to identify the instance of the QMI service.
263 * @nb: Notifier block used to receive the event.
264 *
265 * @return: 0 if successfully registered, < 0 on error.
266 */
267int qmi_svc_event_notifier_register(uint32_t service_id,
268 uint32_t service_vers,
269 uint32_t service_ins,
270 struct notifier_block *nb);
271
272/**
273 * qmi_svc_event_notifier_unregister() - Unregister service event
274 * notifier block
275 * @service_id: Service ID to identify the QMI service.
276 * @service_vers: Version to identify the compatibility.
277 * @service_ins: Instance ID to identify the instance of the QMI service.
278 * @nb: Notifier block registered to receive the events.
279 *
280 * @return: 0 if successfully registered, < 0 on error.
281 */
282int qmi_svc_event_notifier_unregister(uint32_t service_id,
283 uint32_t service_vers,
284 uint32_t service_ins,
285 struct notifier_block *nb);
286
287/**
288 * qmi_svc_register() - Register a QMI service with a QMI handle
289 * @handle: QMI handle on which the service has to be registered.
290 * @ops_options: Service specific operations and options.
291 *
292 * @return: 0 if successfully registered, < 0 on error.
293 */
294int qmi_svc_register(struct qmi_handle *handle,
295 void *ops_options);
296
297/**
298 * qmi_send_resp() - Send response to a request
299 * @handle: QMI handle from which the response is sent.
300 * @clnt: Client to which the response is sent.
301 * @req_handle: Request for which the response is sent.
302 * @resp_desc: Descriptor explaining the response structure.
303 * @resp: Pointer to the response structure.
304 * @resp_len: Length of the response structure.
305 *
306 * @return: 0 on success, < 0 on error.
307 */
308int qmi_send_resp(struct qmi_handle *handle,
309 void *conn_handle,
310 void *req_handle,
311 struct msg_desc *resp_desc,
312 void *resp,
313 unsigned int resp_len);
314
315/**
316 * qmi_send_resp_from_cb() - Send response to a request from request_cb
317 * @handle: QMI handle from which the response is sent.
318 * @clnt: Client to which the response is sent.
319 * @req_handle: Request for which the response is sent.
320 * @resp_desc: Descriptor explaining the response structure.
321 * @resp: Pointer to the response structure.
322 * @resp_len: Length of the response structure.
323 *
324 * @return: 0 on success, < 0 on error.
325 */
326int qmi_send_resp_from_cb(struct qmi_handle *handle,
327 void *conn_handle,
328 void *req_handle,
329 struct msg_desc *resp_desc,
330 void *resp,
331 unsigned int resp_len);
332
333/**
334 * qmi_send_ind() - Send unsolicited event/indication to a client
335 * @handle: QMI handle from which the indication is sent.
336 * @clnt: Client to which the indication is sent.
337 * @ind_desc: Descriptor explaining the indication structure.
338 * @ind: Pointer to the indication structure.
339 * @ind_len: Length of the indication structure.
340 *
341 * @return: 0 on success, < 0 on error.
342 */
343int qmi_send_ind(struct qmi_handle *handle,
344 void *conn_handle,
345 struct msg_desc *ind_desc,
346 void *ind,
347 unsigned int ind_len);
348
349/**
350 * qmi_send_ind_from_cb() - Send indication to a client from registration_cb
351 * @handle: QMI handle from which the indication is sent.
352 * @clnt: Client to which the indication is sent.
353 * @ind_desc: Descriptor explaining the indication structure.
354 * @ind: Pointer to the indication structure.
355 * @ind_len: Length of the indication structure.
356 *
357 * @return: 0 on success, < 0 on error.
358 */
359int qmi_send_ind_from_cb(struct qmi_handle *handle,
360 void *conn_handle,
361 struct msg_desc *ind_desc,
362 void *ind,
363 unsigned int ind_len);
364
365/**
366 * qmi_svc_unregister() - Unregister the service from a QMI handle
367 * @handle: QMI handle from which the service has to be unregistered.
368 *
369 * return: 0 on success, < 0 on error.
370 */
371int qmi_svc_unregister(struct qmi_handle *handle);
372
373#else
374
375#define get_qmi_response_type_v01_ei() NULL
376
377static inline struct qmi_handle *qmi_handle_create(
378 void (*notify)(struct qmi_handle *handle,
379 enum qmi_event_type event, void *notify_priv),
380 void *notify_priv)
381{
382 return NULL;
383}
384
385static inline int qmi_handle_destroy(struct qmi_handle *handle)
386{
387 return -ENODEV;
388}
389
390static inline int qmi_register_ind_cb(struct qmi_handle *handle,
391 void (*ind_cb)(struct qmi_handle *handle,
392 unsigned int msg_id, void *msg,
393 unsigned int msg_len, void *ind_cb_priv),
394 void *ind_cb_priv)
395{
396 return -ENODEV;
397}
398
399static inline int qmi_send_req_wait(struct qmi_handle *handle,
400 struct msg_desc *req_desc,
401 void *req, unsigned int req_len,
402 struct msg_desc *resp_desc,
403 void *resp, unsigned int resp_len,
404 unsigned long timeout_ms)
405{
406 return -ENODEV;
407}
408
409static inline int qmi_send_req_nowait(struct qmi_handle *handle,
410 struct msg_desc *req_desc,
411 void *req, unsigned int req_len,
412 struct msg_desc *resp_desc,
413 void *resp, unsigned int resp_len,
414 void (*resp_cb)(struct qmi_handle *handle,
415 unsigned int msg_id, void *msg,
416 void *resp_cb_data),
417 void *resp_cb_data)
418{
419 return -ENODEV;
420}
421
422static inline int qmi_recv_msg(struct qmi_handle *handle)
423{
424 return -ENODEV;
425}
426
427static inline int qmi_connect_to_service(struct qmi_handle *handle,
428 uint32_t service_id,
429 uint32_t service_vers,
430 uint32_t service_ins)
431{
432 return -ENODEV;
433}
434
435static inline int qmi_svc_event_notifier_register(uint32_t service_id,
436 uint32_t service_vers,
437 uint32_t service_ins,
438 struct notifier_block *nb)
439{
440 return -ENODEV;
441}
442
443static inline int qmi_svc_event_notifier_unregister(uint32_t service_id,
444 uint32_t service_vers,
445 uint32_t service_ins,
446 struct notifier_block *nb)
447{
448 return -ENODEV;
449}
450
451static inline int qmi_svc_register(struct qmi_handle *handle,
452 void *ops_options)
453{
454 return -ENODEV;
455}
456
457static inline int qmi_send_resp(struct qmi_handle *handle,
458 void *conn_handle,
459 void *req_handle,
460 struct msg_desc *resp_desc,
461 void *resp,
462 unsigned int resp_len)
463{
464 return -ENODEV;
465}
466
467static inline int qmi_send_resp_from_cb(struct qmi_handle *handle,
468 void *conn_handle,
469 void *req_handle,
470 struct msg_desc *resp_desc,
471 void *resp,
472 unsigned int resp_len)
473{
474 return -ENODEV;
475}
476
477static inline int qmi_send_ind(struct qmi_handle *handle,
478 void *conn_handle,
479 struct msg_desc *ind_desc,
480 void *ind,
481 unsigned int ind_len)
482{
483 return -ENODEV;
484}
485
486static inline int qmi_send_ind_from_cb(struct qmi_handle *handle,
487 void *conn_handle,
488 struct msg_desc *ind_desc,
489 void *ind,
490 unsigned int ind_len)
491{
492 return -ENODEV;
493}
494
495static inline int qmi_svc_unregister(struct qmi_handle *handle)
496{
497 return -ENODEV;
498}
499
500#endif
501
502#endif