msm_qmi.txt 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. Introduction
  2. ============
  3. Qualcomm Technologies, Inc. MSM Interface(QMI) is a messaging format used
  4. to communicate between software components in the modem and other
  5. peripheral subsystems. This document proposes an architecture to introduce
  6. the QMI messaging into the kernel. This document proposes introducing a
  7. QMI encode/decode library to enable QMI message marshaling and an
  8. interface library to enable sending and receiving QMI messages through
  9. MSM IPC Router.
  10. Hardware description
  11. ====================
  12. QMI is a messaging format used to interface with the components in modem
  13. and other subsystems. QMI does not drive or manage any hardware resources.
  14. Software description
  15. ====================
  16. QMI communication is based on a client-server model, where clients and
  17. servers exchange messages in QMI wire format. A module can act as a client
  18. of any number of QMI services and a QMI service can serve any number of
  19. clients.
  20. QMI communication is of request/response type or an unsolicited event type.
  21. QMI client driver sends a request to a QMI service and receives a response.
  22. QMI client driver registers with the QMI service to receive indications
  23. regarding a system event and the QMI service sends the indications to the
  24. client when the event occurs in the system.
  25. The wire format of QMI message is as follows:
  26. ----------------------------------------------------
  27. | QMI Header | TLV 0 | TLV 1 | ... | TLV N |
  28. ----------------------------------------------------
  29. QMI Header:
  30. -----------
  31. --------------------------------------------------------
  32. | Flags | Transaction ID | Message ID | Message Length |
  33. --------------------------------------------------------
  34. The flags field is used to indicate the kind of QMI message - request,
  35. response or indication. The transaction ID is a client specific field
  36. to uniquely match the QMI request and the response. The message ID is
  37. also a client specific field to indicate the kind of information present
  38. in the QMI payload. The message length field holds the size information
  39. of the QMI payload.
  40. Flags:
  41. ------
  42. * 0 - QMI Request
  43. * 2 - QMI Response
  44. * 4 - QMI Indication
  45. TLV:
  46. ----
  47. QMI payload is represented using a series of Type, Length and Value fields.
  48. Each information being passed is encoded into a type, length and value
  49. combination. The type element identifies the type of information being
  50. encoded. The length element specifies the length of the information/values
  51. being encoded. The information can be of a primitive type or a structure
  52. or an array.
  53. -------------------------------------------
  54. | Type | Length | Value 0 | ... | Value N |
  55. -------------------------------------------
  56. QMI Message Marshaling and Transport:
  57. -------------------------------------
  58. QMI encode/decode library is designed to encode the kernel C data
  59. structures into QMI wire format and to decode the QMI messages into kernel
  60. C data strcuture format. This library will provide a single interface to
  61. transform any data structure into a QMI message and vice-versa.
  62. QMI interface library is designed to send and receive QMI messages over
  63. IPC Router.
  64. ----------------------------------
  65. | Kernel Drivers |
  66. ----------------------------------
  67. | |
  68. | |
  69. ----------------- -----------------
  70. | QMI Interface |___| QMI Enc/Dec |
  71. | Library | | Library |
  72. ----------------- -----------------
  73. |
  74. |
  75. -------------------
  76. | IPC Message |
  77. | Router |
  78. -------------------
  79. |
  80. |
  81. -------
  82. | SMD |
  83. -------
  84. Design
  85. ======
  86. The design goals of this proposed QMI messaging mechanism are:
  87. * To enable QMI messaging from within the kernel
  88. * To provide a common library to marshal QMI messages
  89. * To provide a common interface library to send/receive QMI messages
  90. * To support kernel QMI clients which have latency constraints
  91. The reason behind this design decision is:
  92. * To provide a simple QMI marshaling interface to the kernel users
  93. * To hide the complexities of QMI message transports
  94. * To minimize code redundancy
  95. In order to provide a single encode/decode API, the library expects
  96. the kernel drivers to pass the:
  97. * starting address of the data structure to be encoded/decoded
  98. * starting address of the QMI message buffer
  99. * a table containing information regarding the data structure to
  100. be encoded/decoded
  101. The design is based on the idea that any complex data structure is a
  102. collection of primary data elements. Hence the information about any
  103. data structure can be constructed as an array of information about its
  104. primary data elements. The following structure is defined to describe
  105. information about a primary data element.
  106. /**
  107. * elem_info - Data structure to specify information about an element
  108. * in a data structure. An array of this data structure
  109. * can be used to specify info about a complex data
  110. * structure to be encoded/decoded.
  111. * @data_type: Data type of this element
  112. * @elem_len: Array length of this element, if an array
  113. * @elem_size: Size of a single instance of this data type
  114. * @is_array: Array type of this element
  115. * @tlv_type: QMI message specific type to identify which element
  116. * is present in an incoming message
  117. * @offset: To identify the address of the first instance of this
  118. * element in the data structure
  119. * @ei_array: Array to provide information about the nested structure
  120. * within a data structure to be encoded/decoded.
  121. */
  122. struct elem_info {
  123. enum elem_type data_type;
  124. uint32_t elem_len;
  125. uint32_t elem_size;
  126. enum array_type is_array;
  127. uint8_t tlv_type;
  128. uint32_t offset;
  129. struct elem_info *ei_array;
  130. };
  131. The alternate design discussions include manual encoding/decoding of QMI
  132. messages. From RPC experience, this approach has mostly been error prone.
  133. This in turn lead to increased development and debugging effort. Another
  134. approach included data-structure specific marshaling API -- i.e. every
  135. data structure to be encoded/decoded should have a unique auto-generated
  136. marshaling API. This approach comes with the cost of code redundancy and
  137. was therefore rejected.
  138. Power Management
  139. ================
  140. N/A
  141. SMP/multi-core
  142. ==============
  143. The QMI encode/decode library does not access any global or shared data
  144. structures. Hence it does not require any locking mechanisms to ensure
  145. multi-core safety.
  146. The QMI interface library uses mutexes while accessing shared resources.
  147. Security
  148. ========
  149. N/A
  150. Performance
  151. ===========
  152. This design proposal is to support kernel QMI clients which have latency
  153. constraints. Hence the number and size of QMI messages are expected to be
  154. kept short, in order to achieve latency of less than 1 ms consistently.
  155. Interface
  156. =========
  157. Kernel-APIs:
  158. ------------
  159. Encode/Decode Library APIs:
  160. ---------------------------
  161. /**
  162. * elem_type - Enum to identify the data type of elements in a data
  163. * structure.
  164. */
  165. enum elem_type {
  166. QMI_OPT_FLAG = 1,
  167. QMI_DATA_LEN,
  168. QMI_UNSIGNED_1_BYTE,
  169. QMI_UNSIGNED_2_BYTE,
  170. QMI_UNSIGNED_4_BYTE,
  171. QMI_UNSIGNED_8_BYTE,
  172. QMI_SIGNED_2_BYTE_ENUM,
  173. QMI_SIGNED_4_BYTE_ENUM,
  174. QMI_STRUCT,
  175. QMI_END_OF_TYPE_INFO,
  176. };
  177. /**
  178. * array_type - Enum to identify if an element in a data structure is
  179. * an array. If so, then is it a static length array or a
  180. * variable length array.
  181. */
  182. enum array_type {
  183. NO_ARRAY = 0,
  184. STATIC_ARRAY = 1,
  185. VAR_LEN_ARRAY = 2,
  186. };
  187. /**
  188. * msg_desc - Describe about the main/outer structure to be
  189. * encoded/decoded.
  190. * @msg_id: Message ID to identify the kind of QMI message.
  191. * @max_msg_len: Maximum possible length of the QMI message.
  192. * @ei_array: Array to provide information about a data structure.
  193. */
  194. struct msg_desc {
  195. uint16_t msg_id;
  196. int max_msg_len;
  197. struct elem_info *ei_array;
  198. };
  199. /**
  200. * qmi_kernel_encode() - Encode to QMI message wire format
  201. * @desc: Structure describing the data structure to be encoded.
  202. * @out_buf: Buffer to hold the encoded QMI message.
  203. * @out_buf_len: Length of the buffer to hold the QMI message.
  204. * @in_c_struct: C Structure to be encoded.
  205. *
  206. * @return: size of encoded message on success,
  207. * -ve value on failure.
  208. */
  209. int qmi_kernel_encode(struct msg_desc *desc,
  210. void *out_buf, uint32_t out_buf_len,
  211. void *in_c_struct);
  212. /**
  213. * qmi_kernel_decode() - Decode to C Structure format
  214. * @desc: Structure describing the data structure format.
  215. * @out_c_struct: Buffer to hold the decoded C structure.
  216. * @in_buf: Buffer containg the QMI message to be decoded.
  217. * @in_buf_len: Length of the incoming QMI message.
  218. *
  219. * @return: 0 on success, -ve value on failure.
  220. */
  221. int qmi_kernel_decode(struct msg_desc *desc, void *out_c_struct,
  222. void *in_buf, uint32_t in_buf_len);
  223. Interface Library APIs:
  224. -----------------------
  225. /**
  226. * qmi_svc_event_notifier_register() - Register a notifier block to receive
  227. * events regarding a QMI service
  228. * @service_id: Service ID to identify the QMI service.
  229. * @instance_id: Instance ID to identify the instance of the QMI service.
  230. * @nb: Notifier block used to receive the event.
  231. *
  232. * @return: 0 if successfully registered, < 0 on error.
  233. */
  234. int qmi_svc_event_notifier_register(uint32_t service_id,
  235. uint32_t instance_id,
  236. struct notifier_block *nb);
  237. /**
  238. * qmi_handle_create() - Create a QMI handle
  239. * @notify: Callback to notify events on the handle created.
  240. * @notify_priv: Private info to be passed along with the notification.
  241. *
  242. * @return: Valid QMI handle on success, NULL on error.
  243. */
  244. struct qmi_handle *qmi_handle_create(
  245. void (*notify)(struct qmi_handle *handle,
  246. enum qmi_event_type event, void *notify_priv),
  247. void *notify_priv);
  248. /**
  249. * qmi_connect_to_service() - Connect the QMI handle with a QMI service
  250. * @handle: QMI handle to be connected with the QMI service.
  251. * @service_id: Service id to identify the QMI service.
  252. * @instance_id: Instance id to identify the instance of the QMI service.
  253. *
  254. * @return: 0 on success, < 0 on error.
  255. */
  256. int qmi_connect_to_service(struct qmi_handle *handle,
  257. uint32_t service_id, uint32_t instance_id);
  258. /**
  259. * qmi_register_ind_cb() - Register the indication callback function
  260. * @handle: QMI handle with which the function is registered.
  261. * @ind_cb: Callback function to be registered.
  262. * @ind_cb_priv: Private data to be passed with the indication callback.
  263. *
  264. * @return: 0 on success, < 0 on error.
  265. */
  266. int qmi_register_ind_cb(struct qmi_handle *handle,
  267. void (*ind_cb)(struct qmi_handle *handle,
  268. unsigned int msg_id, void *msg,
  269. unsigned int msg_len, void *ind_cb_priv),
  270. void *ind_cb_priv);
  271. /**
  272. * qmi_send_req_wait() - Send a synchronous QMI request
  273. * @handle: QMI handle through which the QMI request is sent.
  274. * @req_desc: Structure describing the request data structure.
  275. * @req: Buffer containing the request data structure.
  276. * @req_len: Length of the request data structure.
  277. * @resp_desc: Structure describing the response data structure.
  278. * @resp: Buffer to hold the response data structure.
  279. * @resp_len: Length of the response data structure.
  280. * @timeout_ms: Timeout before a response is received.
  281. *
  282. * @return: 0 on success, < 0 on error.
  283. */
  284. int qmi_send_req_wait(struct qmi_handle *handle,
  285. struct msg_desc *req_desc,
  286. void *req, unsigned int req_len,
  287. struct msg_desc *resp_desc,
  288. void *resp, unsigned int resp_len,
  289. unsigned long timeout_ms);
  290. /**
  291. * qmi_send_req_nowait() - Send an asynchronous QMI request
  292. * @handle: QMI handle through which the QMI request is sent.
  293. * @req_desc: Structure describing the request data structure.
  294. * @req: Buffer containing the request data structure.
  295. * @req_len: Length of the request data structure.
  296. * @resp_desc: Structure describing the response data structure.
  297. * @resp: Buffer to hold the response data structure.
  298. * @resp_len: Length of the response data structure.
  299. * @resp_cb: Callback function to be invoked when the response arrives.
  300. * @resp_cb_data: Private information to be passed along with the callback.
  301. *
  302. * @return: 0 on success, < 0 on error.
  303. */
  304. int qmi_send_req_nowait(struct qmi_handle *handle,
  305. struct msg_desc *req_desc,
  306. void *req, unsigned int req_len,
  307. struct msg_desc *resp_desc,
  308. void *resp, unsigned int resp_len,
  309. void (*resp_cb)(struct qmi_handle *handle,
  310. unsigned int msg_id, void *msg,
  311. void *resp_cb_data),
  312. void *resp_cb_data);
  313. /**
  314. * qmi_recv_msg() - Receive the QMI message
  315. * @handle: Handle for which the QMI message has to be received.
  316. *
  317. * @return: 0 on success, < 0 on error.
  318. */
  319. int qmi_recv_msg(struct qmi_handle *handle);
  320. /**
  321. * qmi_handle_destroy() - Destroy the QMI handle
  322. * @handle: QMI handle to be destroyed.
  323. *
  324. * @return: 0 on success, < 0 on error.
  325. */
  326. int qmi_handle_destroy(struct qmi_handle *handle);
  327. /**
  328. * qmi_svc_event_notifier_unregister() - Unregister service event notifier block
  329. * @service_id: Service ID to identify the QMI service.
  330. * @instance_id: Instance ID to identify the instance of the QMI service.
  331. * @nb: Notifier block registered to receive the events.
  332. *
  333. * @return: 0 if successfully registered, < 0 on error.
  334. */
  335. int qmi_svc_event_notifier_unregister(uint32_t service_id,
  336. uint32_t instance_id,
  337. struct notifier_block *nb);
  338. /**
  339. * qmi_svc_ops_options - Operations and options to be specified when
  340. * a service registers.
  341. * @version: Version field to identify the ops_options structure.
  342. * @service_id: Service ID of the service being registered.
  343. * @instance_id: Instance ID of the service being registered.
  344. * @connect_cb: Callback when a new client connects with the service.
  345. * @disconnect_cb: Callback when the client exits the connection.
  346. * @req_desc_cb: Callback to get request structure and its descriptor
  347. * for a message id.
  348. * @req_cb: Callback to process the request.
  349. */
  350. struct qmi_svc_ops_options {
  351. unsigned version;
  352. uint32_t service_id;
  353. uint32_t instance_id;
  354. int (*connect_cb)(struct qmi_handle *handle,
  355. struct qmi_svc_clnt *clnt);
  356. int (*disconnect_cb)(struct qmi_handle *handle,
  357. struct qmi_svc_clnt *clnt);
  358. struct msg_desc *(*req_desc_cb)(unsigned int msg_id,
  359. void **req,
  360. unsigned int req_len);
  361. int (*req_cb)(struct qmi_handle *handle,
  362. struct qmi_svc_clnt *clnt,
  363. void *req_handle,
  364. unsigned int msg_id,
  365. void *req);
  366. };
  367. /**
  368. * qmi_svc_register() - Register a QMI service with a QMI handle
  369. * @handle: QMI handle on which the service has to be registered.
  370. * @ops_options: Service specific operations and options.
  371. *
  372. * @return: 0 if successfully registered, < 0 on error.
  373. */
  374. int qmi_svc_register(struct qmi_handle *handle,
  375. void *ops_options);
  376. /**
  377. * qmi_send_resp() - Send response to a request
  378. * @handle: QMI handle from which the response is sent.
  379. * @clnt: Client to which the response is sent.
  380. * @req_handle: Request for which the response is sent.
  381. * @resp_desc: Descriptor explaining the response structure.
  382. * @resp: Pointer to the response structure.
  383. * @resp_len: Length of the response structure.
  384. *
  385. * @return: 0 on success, < 0 on error.
  386. */
  387. int qmi_send_resp(struct qmi_handle *handle,
  388. struct qmi_svc_clnt *clnt,
  389. void *req_handle,
  390. struct msg_desc *resp_desc,
  391. void *resp,
  392. unsigned int resp_len);
  393. /**
  394. * qmi_send_ind() - Send unsolicited event/indication to a client
  395. * @handle: QMI handle from which the indication is sent.
  396. * @clnt: Client to which the indication is sent.
  397. * @ind_desc: Descriptor explaining the indication structure.
  398. * @ind: Pointer to the indication structure.
  399. * @ind_len: Length of the indication structure.
  400. *
  401. * @return: 0 on success, < 0 on error.
  402. */
  403. int qmi_send_ind(struct qmi_handle *handle,
  404. struct qmi_svc_clnt *clnt,
  405. struct msg_desc *ind_desc,
  406. void *ind,
  407. unsigned int ind_len);
  408. /**
  409. * qmi_svc_unregister() - Unregister the service from a QMI handle
  410. * @handle: QMI handle from which the service has to be unregistered.
  411. *
  412. * return: 0 on success, < 0 on error.
  413. */
  414. int qmi_svc_unregister(struct qmi_handle *handle);
  415. User-space APIs:
  416. ----------------
  417. This proposal is meant only for kernel QMI clients/services and hence no
  418. user-space interface is defined as part of this proposal.
  419. Driver parameters
  420. =================
  421. N/A
  422. Config options
  423. ==============
  424. The QMI encode/decode library will be enabled by default in the kernel.
  425. It can be disabled using CONFIG_QMI_ENCDEC kernel config option.
  426. The QMI Interface library will be disabled by default in the kernel,
  427. since it depends on other components which are disabled by default.
  428. It can be enabled using CONFIG_MSM_QMI_INTERFACE kernel config option.
  429. Dependencies
  430. ============
  431. The QMI encode/decode library is a stand-alone module and is not
  432. dependent on any other kernel modules.
  433. The QMI Interface library depends on QMI Encode/Decode library and
  434. IPC Message Router.
  435. User space utilities
  436. ====================
  437. N/A
  438. Other
  439. =====
  440. N/A
  441. Known issues
  442. ============
  443. N/A
  444. To do
  445. =====
  446. Look into the possibility of making QMI Interface Library transport
  447. agnostic. This may involve the kernel drivers to register the transport,
  448. with the QMI Interface Library, to be used for transporting QMI messages.