smux.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /* include/linux/smux.h
  2. *
  3. * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #ifndef SMUX_H
  16. #define SMUX_H
  17. /**
  18. * Logical Channel IDs
  19. *
  20. * This must be identical between local and remote clients.
  21. */
  22. enum {
  23. /* Data Ports */
  24. SMUX_DATA_0,
  25. SMUX_DATA_1,
  26. SMUX_DATA_2,
  27. SMUX_DATA_3,
  28. SMUX_DATA_4,
  29. SMUX_DATA_5,
  30. SMUX_DATA_6,
  31. SMUX_DATA_7,
  32. SMUX_DATA_8,
  33. SMUX_DATA_9,
  34. SMUX_USB_RMNET_DATA_0,
  35. SMUX_USB_DUN_0,
  36. SMUX_USB_DIAG_0,
  37. SMUX_SYS_MONITOR_0,
  38. SMUX_CSVT_0,
  39. /* add new data ports here */
  40. /* Control Ports */
  41. SMUX_DATA_CTL_0 = 32,
  42. SMUX_DATA_CTL_1,
  43. SMUX_DATA_CTL_2,
  44. SMUX_DATA_CTL_3,
  45. SMUX_DATA_CTL_4,
  46. SMUX_DATA_CTL_5,
  47. SMUX_DATA_CTL_6,
  48. SMUX_DATA_CTL_7,
  49. SMUX_DATA_CTL_8,
  50. SMUX_DATA_CTL_9,
  51. SMUX_USB_RMNET_CTL_0,
  52. SMUX_USB_DUN_CTL_0_UNUSED,
  53. SMUX_USB_DIAG_CTL_0,
  54. SMUX_SYS_MONITOR_CTL_0,
  55. SMUX_CSVT_CTL_0,
  56. /* add new control ports here */
  57. SMUX_TEST_LCID,
  58. SMUX_NUM_LOGICAL_CHANNELS,
  59. };
  60. /**
  61. * Notification events that are passed to the notify() function.
  62. *
  63. * If the @metadata argument in the notifier is non-null, then it will
  64. * point to the associated struct smux_meta_* structure.
  65. */
  66. enum {
  67. SMUX_CONNECTED, /* @metadata is null */
  68. SMUX_DISCONNECTED,
  69. SMUX_READ_DONE,
  70. SMUX_READ_FAIL,
  71. SMUX_WRITE_DONE,
  72. SMUX_WRITE_FAIL,
  73. SMUX_TIOCM_UPDATE,
  74. SMUX_LOW_WM_HIT, /* @metadata is NULL */
  75. SMUX_HIGH_WM_HIT, /* @metadata is NULL */
  76. SMUX_RX_RETRY_HIGH_WM_HIT, /* @metadata is NULL */
  77. SMUX_RX_RETRY_LOW_WM_HIT, /* @metadata is NULL */
  78. SMUX_LOCAL_CLOSED,
  79. SMUX_REMOTE_CLOSED,
  80. };
  81. /**
  82. * Channel options used to modify channel behavior.
  83. */
  84. enum {
  85. SMUX_CH_OPTION_LOCAL_LOOPBACK = 1 << 0,
  86. SMUX_CH_OPTION_REMOTE_LOOPBACK = 1 << 1,
  87. SMUX_CH_OPTION_REMOTE_TX_STOP = 1 << 2,
  88. SMUX_CH_OPTION_AUTO_REMOTE_TX_STOP = 1 << 3,
  89. };
  90. /**
  91. * Metadata for SMUX_DISCONNECTED notification
  92. *
  93. * @is_ssr: Disconnect caused by subsystem restart
  94. */
  95. struct smux_meta_disconnected {
  96. int is_ssr;
  97. };
  98. /**
  99. * Metadata for SMUX_READ_DONE/SMUX_READ_FAIL notification
  100. *
  101. * @pkt_priv: Packet-specific private data
  102. * @buffer: Buffer pointer passed into msm_smux_write
  103. * @len: Buffer length passed into msm_smux_write
  104. */
  105. struct smux_meta_read {
  106. void *pkt_priv;
  107. void *buffer;
  108. int len;
  109. };
  110. /**
  111. * Metadata for SMUX_WRITE_DONE/SMUX_WRITE_FAIL notification
  112. *
  113. * @pkt_priv: Packet-specific private data
  114. * @buffer: Buffer pointer returned by get_rx_buffer()
  115. * @len: Buffer length returned by get_rx_buffer()
  116. */
  117. struct smux_meta_write {
  118. void *pkt_priv;
  119. void *buffer;
  120. int len;
  121. };
  122. /**
  123. * Metadata for SMUX_TIOCM_UPDATE notification
  124. *
  125. * @tiocm_old: Previous TIOCM state
  126. * @tiocm_new: Current TIOCM state
  127. */
  128. struct smux_meta_tiocm {
  129. uint32_t tiocm_old;
  130. uint32_t tiocm_new;
  131. };
  132. #ifdef CONFIG_N_SMUX
  133. /**
  134. * Starts the opening sequence for a logical channel.
  135. *
  136. * @lcid Logical channel ID
  137. * @priv Free for client usage
  138. * @notify Event notification function
  139. * @get_rx_buffer Function used to provide a receive buffer to SMUX
  140. *
  141. * @returns 0 for success, <0 otherwise
  142. *
  143. * A channel must be fully closed (either not previously opened or
  144. * msm_smux_close() has been called and the SMUX_DISCONNECTED has been
  145. * recevied.
  146. *
  147. * One the remote side is opened, the client will receive a SMUX_CONNECTED
  148. * event.
  149. */
  150. int msm_smux_open(uint8_t lcid, void *priv,
  151. void (*notify)(void *priv, int event_type, const void *metadata),
  152. int (*get_rx_buffer)(void *priv, void **pkt_priv,
  153. void **buffer, int size));
  154. /**
  155. * Starts the closing sequence for a logical channel.
  156. *
  157. * @lcid Logical channel ID
  158. * @returns 0 for success, <0 otherwise
  159. *
  160. * Once the close event has been acknowledge by the remote side, the client
  161. * will receive a SMUX_DISCONNECTED notification.
  162. */
  163. int msm_smux_close(uint8_t lcid);
  164. /**
  165. * Write data to a logical channel.
  166. *
  167. * @lcid Logical channel ID
  168. * @pkt_priv Client data that will be returned with the SMUX_WRITE_DONE or
  169. * SMUX_WRITE_FAIL notification.
  170. * @data Data to write
  171. * @len Length of @data
  172. *
  173. * @returns 0 for success, <0 otherwise
  174. *
  175. * Data may be written immediately after msm_smux_open() is called, but
  176. * the data will wait in the transmit queue until the channel has been
  177. * fully opened.
  178. *
  179. * Once the data has been written, the client will receive either a completion
  180. * (SMUX_WRITE_DONE) or a failure notice (SMUX_WRITE_FAIL).
  181. */
  182. int msm_smux_write(uint8_t lcid, void *pkt_priv, const void *data, int len);
  183. /**
  184. * Returns true if the TX queue is currently full (high water mark).
  185. *
  186. * @lcid Logical channel ID
  187. *
  188. * @returns 0 if channel is not full; 1 if it is full; < 0 for error
  189. */
  190. int msm_smux_is_ch_full(uint8_t lcid);
  191. /**
  192. * Returns true if the TX queue has space for more packets it is at or
  193. * below the low water mark).
  194. *
  195. * @lcid Logical channel ID
  196. *
  197. * @returns 0 if channel is above low watermark
  198. * 1 if it's at or below the low watermark
  199. * < 0 for error
  200. */
  201. int msm_smux_is_ch_low(uint8_t lcid);
  202. /**
  203. * Get the TIOCM status bits.
  204. *
  205. * @lcid Logical channel ID
  206. *
  207. * @returns >= 0 TIOCM status bits
  208. * < 0 Error condition
  209. */
  210. long msm_smux_tiocm_get(uint8_t lcid);
  211. /**
  212. * Set/clear the TIOCM status bits.
  213. *
  214. * @lcid Logical channel ID
  215. * @set Bits to set
  216. * @clear Bits to clear
  217. *
  218. * @returns 0 for success; < 0 for failure
  219. *
  220. * If a bit is specified in both the @set and @clear masks, then the clear bit
  221. * definition will dominate and the bit will be cleared.
  222. */
  223. int msm_smux_tiocm_set(uint8_t lcid, uint32_t set, uint32_t clear);
  224. /**
  225. * Set or clear channel option using the SMUX_CH_OPTION_* channel
  226. * flags.
  227. *
  228. * @lcid Logical channel ID
  229. * @set Options to set
  230. * @clear Options to clear
  231. *
  232. * @returns 0 for success, < 0 for failure
  233. */
  234. int msm_smux_set_ch_option(uint8_t lcid, uint32_t set, uint32_t clear);
  235. #else
  236. static inline int msm_smux_open(uint8_t lcid, void *priv,
  237. void (*notify)(void *priv, int event_type, const void *metadata),
  238. int (*get_rx_buffer)(void *priv, void **pkt_priv,
  239. void **buffer, int size))
  240. {
  241. return -ENODEV;
  242. }
  243. static inline int msm_smux_close(uint8_t lcid)
  244. {
  245. return -ENODEV;
  246. }
  247. static inline int msm_smux_write(uint8_t lcid, void *pkt_priv,
  248. const void *data, int len)
  249. {
  250. return -ENODEV;
  251. }
  252. static inline int msm_smux_is_ch_full(uint8_t lcid)
  253. {
  254. return -ENODEV;
  255. }
  256. static inline int msm_smux_is_ch_low(uint8_t lcid)
  257. {
  258. return -ENODEV;
  259. }
  260. static inline long msm_smux_tiocm_get(uint8_t lcid)
  261. {
  262. return 0;
  263. }
  264. static inline int msm_smux_tiocm_set(uint8_t lcid, uint32_t set, uint32_t clear)
  265. {
  266. return -ENODEV;
  267. }
  268. static inline int msm_smux_set_ch_option(uint8_t lcid, uint32_t set,
  269. uint32_t clear)
  270. {
  271. return -ENODEV;
  272. }
  273. #endif /* CONFIG_N_SMUX */
  274. #endif /* SMUX_H */