blob: 308f96904dc80eda6dc6daf0830f83ed6cc878d8 [file] [log] [blame]
Eric Holmberg8ed30f22012-05-10 19:16:51 -06001/* include/linux/smux.h
2 *
3 * Copyright (c) 2012, Code Aurora Forum. 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/**
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 */
80};
81
82/**
83 * Channel options used to modify channel behavior.
84 */
85enum {
86 SMUX_CH_OPTION_LOCAL_LOOPBACK = 1 << 0,
87 SMUX_CH_OPTION_REMOTE_LOOPBACK = 1 << 1,
88 SMUX_CH_OPTION_REMOTE_TX_STOP = 1 << 2,
89};
90
91/**
92 * Metadata for SMUX_DISCONNECTED notification
93 *
94 * @is_ssr: Disconnect caused by subsystem restart
95 */
96struct smux_meta_disconnected {
97 int is_ssr;
98};
99
100/**
101 * Metadata for SMUX_READ_DONE/SMUX_READ_FAIL notification
102 *
103 * @pkt_priv: Packet-specific private data
104 * @buffer: Buffer pointer passed into msm_smux_write
105 * @len: Buffer length passed into msm_smux_write
106 */
107struct smux_meta_read {
108 void *pkt_priv;
109 void *buffer;
110 int len;
111};
112
113/**
114 * Metadata for SMUX_WRITE_DONE/SMUX_WRITE_FAIL notification
115 *
116 * @pkt_priv: Packet-specific private data
117 * @buffer: Buffer pointer returned by get_rx_buffer()
118 * @len: Buffer length returned by get_rx_buffer()
119 */
120struct smux_meta_write {
121 void *pkt_priv;
122 void *buffer;
123 int len;
124};
125
126/**
127 * Metadata for SMUX_TIOCM_UPDATE notification
128 *
129 * @tiocm_old: Previous TIOCM state
130 * @tiocm_new: Current TIOCM state
131 */
132struct smux_meta_tiocm {
133 uint32_t tiocm_old;
134 uint32_t tiocm_new;
135};
136
137
138#ifdef CONFIG_N_SMUX
139/**
140 * Starts the opening sequence for a logical channel.
141 *
142 * @lcid Logical channel ID
143 * @priv Free for client usage
144 * @notify Event notification function
145 * @get_rx_buffer Function used to provide a receive buffer to SMUX
146 *
147 * @returns 0 for success, <0 otherwise
148 *
149 * A channel must be fully closed (either not previously opened or
150 * msm_smux_close() has been called and the SMUX_DISCONNECTED has been
151 * recevied.
152 *
153 * One the remote side is opened, the client will receive a SMUX_CONNECTED
154 * event.
155 */
156int msm_smux_open(uint8_t lcid, void *priv,
157 void (*notify)(void *priv, int event_type, const void *metadata),
158 int (*get_rx_buffer)(void *priv, void **pkt_priv,
159 void **buffer, int size));
160
161/**
162 * Starts the closing sequence for a logical channel.
163 *
164 * @lcid Logical channel ID
165 * @returns 0 for success, <0 otherwise
166 *
167 * Once the close event has been acknowledge by the remote side, the client
168 * will receive a SMUX_DISCONNECTED notification.
169 */
170int msm_smux_close(uint8_t lcid);
171
172/**
173 * Write data to a logical channel.
174 *
175 * @lcid Logical channel ID
176 * @pkt_priv Client data that will be returned with the SMUX_WRITE_DONE or
177 * SMUX_WRITE_FAIL notification.
178 * @data Data to write
179 * @len Length of @data
180 *
181 * @returns 0 for success, <0 otherwise
182 *
183 * Data may be written immediately after msm_smux_open() is called, but
184 * the data will wait in the transmit queue until the channel has been
185 * fully opened.
186 *
187 * Once the data has been written, the client will receive either a completion
188 * (SMUX_WRITE_DONE) or a failure notice (SMUX_WRITE_FAIL).
189 */
190int msm_smux_write(uint8_t lcid, void *pkt_priv, const void *data, int len);
191
192/**
193 * Returns true if the TX queue is currently full (high water mark).
194 *
195 * @lcid Logical channel ID
196 *
197 * @returns 0 if channel is not full; 1 if it is full; < 0 for error
198 */
199int msm_smux_is_ch_full(uint8_t lcid);
200
201/**
202 * Returns true if the TX queue has space for more packets it is at or
203 * below the low water mark).
204 *
205 * @lcid Logical channel ID
206 *
207 * @returns 0 if channel is above low watermark
208 * 1 if it's at or below the low watermark
209 * < 0 for error
210 */
211int msm_smux_is_ch_low(uint8_t lcid);
212
213/**
214 * Get the TIOCM status bits.
215 *
216 * @lcid Logical channel ID
217 *
218 * @returns >= 0 TIOCM status bits
219 * < 0 Error condition
220 */
221long msm_smux_tiocm_get(uint8_t lcid);
222
223/**
224 * Set/clear the TIOCM status bits.
225 *
226 * @lcid Logical channel ID
227 * @set Bits to set
228 * @clear Bits to clear
229 *
230 * @returns 0 for success; < 0 for failure
231 *
232 * If a bit is specified in both the @set and @clear masks, then the clear bit
233 * definition will dominate and the bit will be cleared.
234 */
235int msm_smux_tiocm_set(uint8_t lcid, uint32_t set, uint32_t clear);
236
237/**
238 * Set or clear channel option using the SMUX_CH_OPTION_* channel
239 * flags.
240 *
241 * @lcid Logical channel ID
242 * @set Options to set
243 * @clear Options to clear
244 *
245 * @returns 0 for success, < 0 for failure
246 */
247int msm_smux_set_ch_option(uint8_t lcid, uint32_t set, uint32_t clear);
248
249#else
Angshuman Sarkarceaa8bc2012-05-28 10:21:38 +0530250static inline int msm_smux_open(uint8_t lcid, void *priv,
Eric Holmberg8ed30f22012-05-10 19:16:51 -0600251 void (*notify)(void *priv, int event_type, const void *metadata),
252 int (*get_rx_buffer)(void *priv, void **pkt_priv,
253 void **buffer, int size))
254{
255 return -ENODEV;
256}
257
Angshuman Sarkarceaa8bc2012-05-28 10:21:38 +0530258static inline int msm_smux_close(uint8_t lcid)
Eric Holmberg8ed30f22012-05-10 19:16:51 -0600259{
260 return -ENODEV;
261}
262
Angshuman Sarkarceaa8bc2012-05-28 10:21:38 +0530263static inline int msm_smux_write(uint8_t lcid, void *pkt_priv,
264 const void *data, int len)
Eric Holmberg8ed30f22012-05-10 19:16:51 -0600265{
266 return -ENODEV;
267}
268
Angshuman Sarkarceaa8bc2012-05-28 10:21:38 +0530269static inline int msm_smux_is_ch_full(uint8_t lcid)
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_low(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 long msm_smux_tiocm_get(uint8_t lcid)
Eric Holmberg8ed30f22012-05-10 19:16:51 -0600280{
281 return 0;
282}
283
Angshuman Sarkarceaa8bc2012-05-28 10:21:38 +0530284static inline int msm_smux_tiocm_set(uint8_t lcid, uint32_t set, uint32_t clear)
Eric Holmberg8ed30f22012-05-10 19:16:51 -0600285{
286 return -ENODEV;
287}
288
Angshuman Sarkarceaa8bc2012-05-28 10:21:38 +0530289static inline int msm_smux_set_ch_option(uint8_t lcid, uint32_t set,
290 uint32_t clear)
Eric Holmberg8ed30f22012-05-10 19:16:51 -0600291{
292 return -ENODEV;
293}
294
295#endif /* CONFIG_N_SMUX */
296
297#endif /* SMUX_H */