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