temp revert rk change
[firefly-linux-kernel-4.4.55.git] / drivers / misc / ts27010mux / ts0710.h
1 /*
2  * File: ts0710.h
3  *
4  * Portions derived from rfcomm.c, original header as follows:
5  *
6  * Copyright (C) 2000, 2001  Axis Communications AB
7  * Copyright (C) 2002, 2004, 2009 Motorola
8  *
9  * Author: Mats Friden <mats.friden@axis.com>
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  *
25  * Exceptionally, Axis Communications AB grants discretionary and
26  * conditional permissions for additional use of the text contained
27  * in the company's release of the AXIS OpenBT Stack under the
28  * provisions set forth hereunder.
29  *
30  * Provided that, if you use the AXIS OpenBT Stack with other files,
31  * that do not implement functionality as specified in the Bluetooth
32  * System specification, to produce an executable, this does not by
33  * itself cause the resulting executable to be covered by the GNU
34  * General Public License. Your use of that executable is in no way
35  * restricted on account of using the AXIS OpenBT Stack code with it.
36  *
37  * This exception does not however invalidate any other reasons why
38  * the executable file might be covered by the provisions of the GNU
39  * General Public License.
40  *
41  */
42
43 #define TS0710_MAX_CHN 17
44
45 #define SET_PF(ctr) ((ctr) | (1 << 4))
46 #define CLR_PF(ctr) ((ctr) & 0xef)
47 #define GET_PF(ctr) (((ctr) >> 4) & 0x1)
48
49 #define SHORT_PAYLOAD_SIZE 127
50
51 #define EA 1
52 #define FCS_SIZE 1
53 #define FLAG_SIZE 2
54
55 #define TS0710_MAX_HDR_SIZE 5
56 #define DEF_TS0710_MTU 1024
57
58 #define TS0710_BASIC_FLAG 0xF9
59
60 /* the control field */
61 #define SABM 0x2f
62 #define SABM_SIZE 4
63 #define UA 0x63
64 #define UA_SIZE 4
65 #define DM 0x0f
66 #define DISC 0x43
67 #define UIH 0xef
68
69 /* the type field in a multiplexer command packet */
70 #define TEST 0x8
71 #define FCON 0x28
72 #define FCOFF 0x18
73 #define MSC 0x38
74 #define RPN 0x24
75 #define RLS 0x14
76 #define PN 0x20
77 #define NSC 0x4
78
79 /* V.24 modem control signals */
80 #define FC 0x2
81 #define RTC 0x4
82 #define RTR 0x8
83 #define IC 0x40
84 #define DV 0x80
85
86 #define CTRL_CHAN 0             /* The control channel is defined as DLCI 0 */
87 #define MCC_CR 0x2
88 #define MCC_CMD 1               /* Multiplexer command cr */
89 #define MCC_RSP 0               /* Multiplexer response cr */
90
91 static inline int mcc_is_cmd(u8 type)
92 {
93         return type & MCC_CR;
94 }
95
96 static inline int mcc_is_rsp(u8 type)
97 {
98         return !(type & MCC_CR);
99 }
100
101
102 #ifdef __LITTLE_ENDIAN_BITFIELD
103
104 struct address_field {
105         u8 ea:1;
106         u8 cr:1;
107         u8 d:1;
108         u8 server_chn:5;
109 } __attribute__ ((packed));
110
111 static inline int ts0710_dlci(u8 addr)
112 {
113         return (addr >> 2) & 0x3f;
114 }
115
116
117 struct short_length {
118         u8 ea:1;
119         u8 len:7;
120 } __attribute__ ((packed));
121
122 struct long_length {
123         u8 ea:1;
124         u8 l_len:7;
125         u8 h_len;
126 } __attribute__ ((packed));
127
128 struct short_frame_head {
129         struct address_field addr;
130         u8 control;
131         struct short_length length;
132 } __attribute__ ((packed));
133
134 struct short_frame {
135         struct short_frame_head h;
136         u8 data[0];
137 } __attribute__ ((packed));
138
139 struct long_frame_head {
140         struct address_field addr;
141         u8 control;
142         struct long_length length;
143         u8 data[0];
144 } __attribute__ ((packed));
145
146 struct long_frame {
147         struct long_frame_head h;
148         u8 data[0];
149 } __attribute__ ((packed));
150
151 /* Typedefinitions for structures used for the multiplexer commands */
152 struct mcc_type {
153         u8 ea:1;
154         u8 cr:1;
155         u8 type:6;
156 } __attribute__ ((packed));
157
158 struct mcc_short_frame_head {
159         struct mcc_type type;
160         struct short_length length;
161         u8 value[0];
162 } __attribute__ ((packed));
163
164 struct mcc_short_frame {
165         struct mcc_short_frame_head h;
166         u8 value[0];
167 } __attribute__ ((packed));
168
169 struct mcc_long_frame_head {
170         struct mcc_type type;
171         struct long_length length;
172         u8 value[0];
173 } __attribute__ ((packed));
174
175 struct mcc_long_frame {
176         struct mcc_long_frame_head h;
177         u8 value[0];
178 } __attribute__ ((packed));
179
180 /* MSC-command */
181 struct v24_sigs {
182         u8 ea:1;
183         u8 fc:1;
184         u8 rtc:1;
185         u8 rtr:1;
186         u8 reserved:2;
187         u8 ic:1;
188         u8 dv:1;
189 } __attribute__ ((packed));
190
191 struct brk_sigs {
192         u8 ea:1;
193         u8 b1:1;
194         u8 b2:1;
195         u8 b3:1;
196         u8 len:4;
197 } __attribute__ ((packed));
198
199 struct msc_msg_data {
200         struct address_field dlci;
201         u8 v24_sigs;
202 } __attribute__ ((packed));
203
204 struct pn_msg_data {
205         u8 dlci:6;
206         u8 res1:2;
207
208         u8 frame_type:4;
209         u8 credit_flow:4;
210
211         u8 prior:6;
212         u8 res2:2;
213
214         u8 ack_timer;
215         u8 frame_sizel;
216         u8 frame_sizeh;
217         u8 max_nbrof_retrans;
218         u8 credits;
219 } __attribute__ ((packed));
220
221 #else
222 #error Only littel-endianess supported now!
223 #endif
224
225 #define TS0710_FRAME_SIZE(len)                                          \
226         ((len) > SHORT_PAYLOAD_SIZE ?                                   \
227          (len) + FLAG_SIZE + sizeof(struct long_frame) + FCS_SIZE :     \
228          (len) + FLAG_SIZE + sizeof(struct short_frame) + FCS_SIZE)
229
230 #define TS0710_MCC_FRAME_SIZE(len) \
231         TS0710_FRAME_SIZE((len) + sizeof(struct mcc_short_frame))
232
233
234
235 enum {
236         REJECTED = 0,
237         DISCONNECTED,
238         CONNECTING,
239         NEGOTIATING,
240         CONNECTED,
241         DISCONNECTING,
242         FLOW_STOPPED
243 };
244
245 enum ts0710_events {
246         CONNECT_IND,
247         CONNECT_CFM,
248         DISCONN_CFM
249 };
250
251 struct dlci_struct {
252         u8 state;
253         u8 flow_control;
254         u16 mtu;
255         int clients;
256         struct mutex lock;
257         wait_queue_head_t open_wait;
258         wait_queue_head_t close_wait;
259 };
260
261 struct chan_struct {
262         struct mutex    write_lock;
263         u8              *buf;
264 };
265
266
267 /* user space interfaces */
268 struct ts0710_con {
269         u16 mtu;
270
271         struct dlci_struct      dlci[TS0710_MAX_CHN];
272         struct chan_struct      chan[NR_MUXS];
273 };