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