]>
Commit | Line | Data |
---|---|---|
917f5085 TS |
1 | /* |
2 | * Siemens Gigaset 307x driver | |
6fd5ea63 HL |
3 | * Common header file for all connection variants |
4 | * | |
70440cf2 | 5 | * Written by Stefan Eilers |
6fd5ea63 HL |
6 | * and Hansjoerg Lipp <hjlipp@web.de> |
7 | * | |
917f5085 TS |
8 | * ===================================================================== |
9 | * This program is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU General Public License as | |
11 | * published by the Free Software Foundation; either version 2 of | |
12 | * the License, or (at your option) any later version. | |
13 | * ===================================================================== | |
6fd5ea63 HL |
14 | */ |
15 | ||
16 | #ifndef GIGASET_H | |
17 | #define GIGASET_H | |
18 | ||
6fd5ea63 HL |
19 | #include <linux/kernel.h> |
20 | #include <linux/compiler.h> | |
21 | #include <linux/types.h> | |
6fd5ea63 HL |
22 | #include <linux/spinlock.h> |
23 | #include <linux/isdnif.h> | |
24 | #include <linux/usb.h> | |
25 | #include <linux/skbuff.h> | |
26 | #include <linux/netdevice.h> | |
27 | #include <linux/ppp_defs.h> | |
28 | #include <linux/timer.h> | |
29 | #include <linux/interrupt.h> | |
30 | #include <linux/tty.h> | |
31 | #include <linux/tty_driver.h> | |
32 | #include <linux/list.h> | |
917f5085 | 33 | #include <asm/atomic.h> |
6fd5ea63 HL |
34 | |
35 | #define GIG_VERSION {0,5,0,0} | |
36 | #define GIG_COMPAT {0,4,0,0} | |
37 | ||
917f5085 TS |
38 | #define MAX_REC_PARAMS 10 /* Max. number of params in response string */ |
39 | #define MAX_RESP_SIZE 512 /* Max. size of a response string */ | |
40 | #define HW_HDR_LEN 2 /* Header size used to store ack info */ | |
6fd5ea63 | 41 | |
917f5085 | 42 | #define MAX_EVENTS 64 /* size of event queue */ |
6fd5ea63 HL |
43 | |
44 | #define RBUFSIZE 8192 | |
917f5085 | 45 | #define SBUFSIZE 4096 /* sk_buff payload size */ |
6fd5ea63 | 46 | |
917f5085 TS |
47 | #define TRANSBUFSIZE 768 /* bytes per skb for transparent receive */ |
48 | #define MAX_BUF_SIZE (SBUFSIZE - 2) /* Max. size of a data packet from LL */ | |
6fd5ea63 HL |
49 | |
50 | /* compile time options */ | |
51 | #define GIG_MAJOR 0 | |
52 | ||
53 | #define GIG_MAYINITONDIAL | |
54 | #define GIG_RETRYCID | |
55 | #define GIG_X75 | |
56 | ||
ec81b5e6 | 57 | #define GIG_TICK 100 /* in milliseconds */ |
6fd5ea63 HL |
58 | |
59 | /* timeout values (unit: 1 sec) */ | |
60 | #define INIT_TIMEOUT 1 | |
61 | ||
62 | /* timeout values (unit: 0.1 sec) */ | |
63 | #define RING_TIMEOUT 3 /* for additional parameters to RING */ | |
64 | #define BAS_TIMEOUT 20 /* for response to Base USB ops */ | |
65 | #define ATRDY_TIMEOUT 3 /* for HD_READY_SEND_ATDATA */ | |
66 | ||
67 | #define BAS_RETRY 3 /* max. retries for base USB ops */ | |
68 | ||
69 | #define MAXACT 3 | |
70 | ||
6fd5ea63 HL |
71 | extern int gigaset_debuglevel; /* "needs" cast to (enum debuglevel) */ |
72 | ||
c652cbd8 | 73 | /* debug flags, combine by adding/bitwise OR */ |
73a88814 | 74 | enum debuglevel { |
c652cbd8 | 75 | DEBUG_INTR = 0x00008, /* interrupt processing */ |
6fd5ea63 HL |
76 | DEBUG_CMD = 0x00020, /* sent/received LL commands */ |
77 | DEBUG_STREAM = 0x00040, /* application data stream I/O events */ | |
78 | DEBUG_STREAM_DUMP = 0x00080, /* application data stream content */ | |
79 | DEBUG_LLDATA = 0x00100, /* sent/received LL data */ | |
6fd5ea63 HL |
80 | DEBUG_DRIVER = 0x00400, /* driver structure */ |
81 | DEBUG_HDLC = 0x00800, /* M10x HDLC processing */ | |
82 | DEBUG_WRITE = 0x01000, /* M105 data write */ | |
784d5858 TS |
83 | DEBUG_TRANSCMD = 0x02000, /* AT-COMMANDS+RESPONSES */ |
84 | DEBUG_MCMD = 0x04000, /* COMMANDS THAT ARE SENT VERY OFTEN */ | |
917f5085 TS |
85 | DEBUG_INIT = 0x08000, /* (de)allocation+initialization of data |
86 | structures */ | |
c652cbd8 | 87 | DEBUG_SUSPEND = 0x10000, /* suspend/resume processing */ |
6fd5ea63 | 88 | DEBUG_OUTPUT = 0x20000, /* output to device */ |
784d5858 | 89 | DEBUG_ISO = 0x40000, /* isochronous transfers */ |
6fd5ea63 | 90 | DEBUG_IF = 0x80000, /* character device operations */ |
917f5085 TS |
91 | DEBUG_USBREQ = 0x100000, /* USB communication (except payload |
92 | data) */ | |
784d5858 | 93 | DEBUG_LOCKCMD = 0x200000, /* AT commands and responses when |
917f5085 | 94 | MS_LOCKED */ |
6fd5ea63 | 95 | |
917f5085 TS |
96 | DEBUG_ANY = 0x3fffff, /* print message if any of the others is |
97 | activated */ | |
6fd5ea63 HL |
98 | }; |
99 | ||
784d5858 TS |
100 | /* Kernel message macros for situations where dev_printk and friends cannot be |
101 | * used for lack of reliable access to a device structure. | |
102 | * linux/usb.h already contains these but in an obsolete form which clutters | |
103 | * the log needlessly, and according to the USB maintainer those should be | |
104 | * removed rather than fixed anyway. | |
105 | */ | |
106 | #undef err | |
6fd5ea63 | 107 | #undef info |
6fd5ea63 | 108 | #undef warn |
784d5858 | 109 | #undef notice |
6fd5ea63 | 110 | |
784d5858 TS |
111 | #define err(format, arg...) printk(KERN_ERR KBUILD_MODNAME ": " \ |
112 | format "\n" , ## arg) | |
113 | #define info(format, arg...) printk(KERN_INFO KBUILD_MODNAME ": " \ | |
114 | format "\n" , ## arg) | |
115 | #define warn(format, arg...) printk(KERN_WARNING KBUILD_MODNAME ": " \ | |
116 | format "\n" , ## arg) | |
117 | #define notice(format, arg...) printk(KERN_NOTICE KBUILD_MODNAME ": " \ | |
118 | format "\n" , ## arg) | |
6fd5ea63 | 119 | |
6fd5ea63 | 120 | #ifdef CONFIG_GIGASET_DEBUG |
784d5858 TS |
121 | |
122 | #define gig_dbg(level, format, arg...) \ | |
917f5085 TS |
123 | do { \ |
124 | if (unlikely(((enum debuglevel)gigaset_debuglevel) & (level))) \ | |
784d5858 TS |
125 | printk(KERN_DEBUG KBUILD_MODNAME ": " format "\n", \ |
126 | ## arg); \ | |
917f5085 | 127 | } while (0) |
73a88814 | 128 | #define DEBUG_DEFAULT (DEBUG_TRANSCMD | DEBUG_CMD | DEBUG_USBREQ) |
784d5858 | 129 | |
6fd5ea63 | 130 | #else |
784d5858 TS |
131 | |
132 | #define gig_dbg(level, format, arg...) do {} while (0) | |
133 | #define DEBUG_DEFAULT 0 | |
134 | ||
6fd5ea63 HL |
135 | #endif |
136 | ||
137 | void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, | |
01371500 | 138 | size_t len, const unsigned char *buf); |
6fd5ea63 HL |
139 | |
140 | /* connection state */ | |
141 | #define ZSAU_NONE 0 | |
142 | #define ZSAU_DISCONNECT_IND 4 | |
143 | #define ZSAU_OUTGOING_CALL_PROCEEDING 1 | |
144 | #define ZSAU_PROCEEDING 1 | |
145 | #define ZSAU_CALL_DELIVERED 2 | |
146 | #define ZSAU_ACTIVE 3 | |
147 | #define ZSAU_NULL 5 | |
148 | #define ZSAU_DISCONNECT_REQ 6 | |
149 | #define ZSAU_UNKNOWN -1 | |
150 | ||
151 | /* USB control transfer requests */ | |
917f5085 TS |
152 | #define OUT_VENDOR_REQ (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT) |
153 | #define IN_VENDOR_REQ (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT) | |
6fd5ea63 HL |
154 | |
155 | /* int-in-events 3070 */ | |
156 | #define HD_B1_FLOW_CONTROL 0x80 | |
157 | #define HD_B2_FLOW_CONTROL 0x81 | |
917f5085 TS |
158 | #define HD_RECEIVEATDATA_ACK (0x35) // 3070 |
159 | // att: HD_RECEIVE>>AT<<DATA_ACK | |
6fd5ea63 HL |
160 | #define HD_READY_SEND_ATDATA (0x36) // 3070 |
161 | #define HD_OPEN_ATCHANNEL_ACK (0x37) // 3070 | |
162 | #define HD_CLOSE_ATCHANNEL_ACK (0x38) // 3070 | |
163 | #define HD_DEVICE_INIT_OK (0x11) // ISurf USB + 3070 | |
164 | #define HD_OPEN_B1CHANNEL_ACK (0x51) // ISurf USB + 3070 | |
165 | #define HD_OPEN_B2CHANNEL_ACK (0x52) // ISurf USB + 3070 | |
166 | #define HD_CLOSE_B1CHANNEL_ACK (0x53) // ISurf USB + 3070 | |
167 | #define HD_CLOSE_B2CHANNEL_ACK (0x54) // ISurf USB + 3070 | |
168 | // Powermangment | |
169 | #define HD_SUSPEND_END (0x61) // ISurf USB | |
170 | // Configuration | |
171 | #define HD_RESET_INTERRUPT_PIPE_ACK (0xFF) // ISurf USB + 3070 | |
172 | ||
173 | /* control requests 3070 */ | |
174 | #define HD_OPEN_B1CHANNEL (0x23) // ISurf USB + 3070 | |
175 | #define HD_CLOSE_B1CHANNEL (0x24) // ISurf USB + 3070 | |
176 | #define HD_OPEN_B2CHANNEL (0x25) // ISurf USB + 3070 | |
177 | #define HD_CLOSE_B2CHANNEL (0x26) // ISurf USB + 3070 | |
178 | #define HD_RESET_INTERRUPT_PIPE (0x27) // ISurf USB + 3070 | |
179 | #define HD_DEVICE_INIT_ACK (0x34) // ISurf USB + 3070 | |
180 | #define HD_WRITE_ATMESSAGE (0x12) // 3070 | |
181 | #define HD_READ_ATMESSAGE (0x13) // 3070 | |
182 | #define HD_OPEN_ATCHANNEL (0x28) // 3070 | |
183 | #define HD_CLOSE_ATCHANNEL (0x29) // 3070 | |
184 | ||
c652cbd8 TS |
185 | /* number of B channels supported by base driver */ |
186 | #define BAS_CHANNELS 2 | |
187 | ||
6fd5ea63 | 188 | /* USB frames for isochronous transfer */ |
917f5085 TS |
189 | #define BAS_FRAMETIME 1 /* number of milliseconds between frames */ |
190 | #define BAS_NUMFRAMES 8 /* number of frames per URB */ | |
191 | #define BAS_MAXFRAME 16 /* allocated bytes per frame */ | |
192 | #define BAS_NORMFRAME 8 /* send size without flow control */ | |
193 | #define BAS_HIGHFRAME 10 /* " " with positive flow control */ | |
194 | #define BAS_LOWFRAME 5 /* " " with negative flow control */ | |
195 | #define BAS_CORRFRAMES 4 /* flow control multiplicator */ | |
196 | ||
197 | #define BAS_INBUFSIZE (BAS_MAXFRAME * BAS_NUMFRAMES) | |
198 | /* size of isoc in buf per URB */ | |
199 | #define BAS_OUTBUFSIZE 4096 /* size of common isoc out buffer */ | |
200 | #define BAS_OUTBUFPAD BAS_MAXFRAME /* size of pad area for isoc out buf */ | |
6fd5ea63 HL |
201 | |
202 | #define BAS_INURBS 3 | |
203 | #define BAS_OUTURBS 3 | |
204 | ||
205 | /* variable commands in struct bc_state */ | |
206 | #define AT_ISO 0 | |
207 | #define AT_DIAL 1 | |
208 | #define AT_MSN 2 | |
209 | #define AT_BC 3 | |
210 | #define AT_PROTO 4 | |
211 | #define AT_TYPE 5 | |
212 | #define AT_HLC 6 | |
213 | #define AT_NUM 7 | |
214 | ||
215 | /* variables in struct at_state_t */ | |
917f5085 TS |
216 | #define VAR_ZSAU 0 |
217 | #define VAR_ZDLE 1 | |
218 | #define VAR_ZVLS 2 | |
219 | #define VAR_ZCTP 3 | |
220 | #define VAR_NUM 4 | |
221 | ||
222 | #define STR_NMBR 0 | |
223 | #define STR_ZCPN 1 | |
224 | #define STR_ZCON 2 | |
225 | #define STR_ZBC 3 | |
226 | #define STR_ZHLC 4 | |
227 | #define STR_NUM 5 | |
228 | ||
229 | #define EV_TIMEOUT -105 | |
230 | #define EV_IF_VER -106 | |
231 | #define EV_PROC_CIDMODE -107 | |
232 | #define EV_SHUTDOWN -108 | |
233 | #define EV_START -110 | |
234 | #define EV_STOP -111 | |
235 | #define EV_IF_LOCK -112 | |
236 | #define EV_PROTO_L2 -113 | |
237 | #define EV_ACCEPT -114 | |
238 | #define EV_DIAL -115 | |
239 | #define EV_HUP -116 | |
240 | #define EV_BC_OPEN -117 | |
241 | #define EV_BC_CLOSED -118 | |
6fd5ea63 HL |
242 | |
243 | /* input state */ | |
917f5085 TS |
244 | #define INS_command 0x0001 |
245 | #define INS_DLE_char 0x0002 | |
246 | #define INS_byte_stuff 0x0004 | |
247 | #define INS_have_data 0x0008 | |
248 | #define INS_skip_frame 0x0010 | |
249 | #define INS_DLE_command 0x0020 | |
6fd5ea63 HL |
250 | #define INS_flag_hunt 0x0040 |
251 | ||
252 | /* channel state */ | |
253 | #define CHS_D_UP 0x01 | |
254 | #define CHS_B_UP 0x02 | |
255 | #define CHS_NOTIFY_LL 0x04 | |
256 | ||
917f5085 TS |
257 | #define ICALL_REJECT 0 |
258 | #define ICALL_ACCEPT 1 | |
259 | #define ICALL_IGNORE 2 | |
6fd5ea63 HL |
260 | |
261 | /* device state */ | |
917f5085 TS |
262 | #define MS_UNINITIALIZED 0 |
263 | #define MS_INIT 1 | |
264 | #define MS_LOCKED 2 | |
265 | #define MS_SHUTDOWN 3 | |
266 | #define MS_RECOVER 4 | |
267 | #define MS_READY 5 | |
6fd5ea63 HL |
268 | |
269 | /* mode */ | |
917f5085 TS |
270 | #define M_UNKNOWN 0 |
271 | #define M_CONFIG 1 | |
272 | #define M_UNIMODEM 2 | |
273 | #define M_CID 3 | |
6fd5ea63 HL |
274 | |
275 | /* start mode */ | |
917f5085 TS |
276 | #define SM_LOCKED 0 |
277 | #define SM_ISDN 1 /* default */ | |
6fd5ea63 HL |
278 | |
279 | struct gigaset_ops; | |
280 | struct gigaset_driver; | |
281 | ||
282 | struct usb_cardstate; | |
283 | struct ser_cardstate; | |
284 | struct bas_cardstate; | |
285 | ||
286 | struct bc_state; | |
287 | struct usb_bc_state; | |
288 | struct ser_bc_state; | |
289 | struct bas_bc_state; | |
290 | ||
291 | struct reply_t { | |
917f5085 TS |
292 | int resp_code; /* RSP_XXXX */ |
293 | int min_ConState; /* <0 => ignore */ | |
294 | int max_ConState; /* <0 => ignore */ | |
295 | int parameter; /* e.g. ZSAU_XXXX <0: ignore*/ | |
296 | int new_ConState; /* <0 => ignore */ | |
297 | int timeout; /* >0 => *HZ; <=0 => TOUT_XXXX*/ | |
298 | int action[MAXACT]; /* ACT_XXXX */ | |
299 | char *command; /* NULL==none */ | |
6fd5ea63 HL |
300 | }; |
301 | ||
302 | extern struct reply_t gigaset_tab_cid_m10x[]; | |
303 | extern struct reply_t gigaset_tab_nocid_m10x[]; | |
304 | ||
305 | struct inbuf_t { | |
917f5085 | 306 | unsigned char *rcvbuf; /* usb-gigaset receive buffer */ |
6fd5ea63 | 307 | struct bc_state *bcs; |
917f5085 TS |
308 | struct cardstate *cs; |
309 | int inputstate; | |
310 | atomic_t head, tail; | |
311 | unsigned char data[RBUFSIZE]; | |
6fd5ea63 HL |
312 | }; |
313 | ||
314 | /* isochronous write buffer structure | |
315 | * circular buffer with pad area for extraction of complete USB frames | |
316 | * - data[read..nextread-1] is valid data already submitted to the USB subsystem | |
317 | * - data[nextread..write-1] is valid data yet to be sent | |
318 | * - data[write] is the next byte to write to | |
319 | * - in byte-oriented L2 procotols, it is completely free | |
320 | * - in bit-oriented L2 procotols, it may contain a partial byte of valid data | |
321 | * - data[write+1..read-1] is free | |
322 | * - wbits is the number of valid data bits in data[write], starting at the LSB | |
323 | * - writesem is the semaphore for writing to the buffer: | |
324 | * if writesem <= 0, data[write..read-1] is currently being written to | |
325 | * - idle contains the byte value to repeat when the end of valid data is | |
326 | * reached; if nextread==write (buffer contains no data to send), either the | |
917f5085 TS |
327 | * BAS_OUTBUFPAD bytes immediately before data[write] (if |
328 | * write>=BAS_OUTBUFPAD) or those of the pad area (if write<BAS_OUTBUFPAD) | |
329 | * are also filled with that value | |
6fd5ea63 HL |
330 | */ |
331 | struct isowbuf_t { | |
332 | atomic_t read; | |
333 | atomic_t nextread; | |
334 | atomic_t write; | |
335 | atomic_t writesem; | |
336 | int wbits; | |
337 | unsigned char data[BAS_OUTBUFSIZE + BAS_OUTBUFPAD]; | |
338 | unsigned char idle; | |
339 | }; | |
340 | ||
341 | /* isochronous write URB context structure | |
342 | * data to be stored along with the URB and retrieved when it is returned | |
343 | * as completed by the USB subsystem | |
344 | * - urb: pointer to the URB itself | |
345 | * - bcs: pointer to the B Channel control structure | |
346 | * - limit: end of write buffer area covered by this URB | |
dbd98231 | 347 | * - status: URB completion status |
6fd5ea63 HL |
348 | */ |
349 | struct isow_urbctx_t { | |
350 | struct urb *urb; | |
351 | struct bc_state *bcs; | |
352 | int limit; | |
dbd98231 | 353 | int status; |
6fd5ea63 HL |
354 | }; |
355 | ||
356 | /* AT state structure | |
357 | * data associated with the state of an ISDN connection, whether or not | |
358 | * it is currently assigned a B channel | |
359 | */ | |
360 | struct at_state_t { | |
917f5085 TS |
361 | struct list_head list; |
362 | int waiting; | |
363 | int getstring; | |
69049cc8 | 364 | unsigned timer_index; |
6fd5ea63 HL |
365 | unsigned long timer_expires; |
366 | int timer_active; | |
917f5085 TS |
367 | unsigned int ConState; /* State of connection */ |
368 | struct reply_t *replystruct; | |
369 | int cid; | |
370 | int int_var[VAR_NUM]; /* see VAR_XXXX */ | |
371 | char *str_var[STR_NUM]; /* see STR_XXXX */ | |
372 | unsigned pending_commands; /* see PC_XXXX */ | |
69049cc8 | 373 | unsigned seq_index; |
917f5085 TS |
374 | |
375 | struct cardstate *cs; | |
376 | struct bc_state *bcs; | |
6fd5ea63 HL |
377 | }; |
378 | ||
379 | struct resp_type_t { | |
380 | unsigned char *response; | |
917f5085 TS |
381 | int resp_code; /* RSP_XXXX */ |
382 | int type; /* RT_XXXX */ | |
6fd5ea63 HL |
383 | }; |
384 | ||
385 | struct event_t { | |
386 | int type; | |
387 | void *ptr, *arg; | |
388 | int parameter; | |
389 | int cid; | |
390 | struct at_state_t *at_state; | |
391 | }; | |
392 | ||
393 | /* This buffer holds all information about the used B-Channel */ | |
394 | struct bc_state { | |
917f5085 TS |
395 | struct sk_buff *tx_skb; /* Current transfer buffer to modem */ |
396 | struct sk_buff_head squeue; /* B-Channel send Queue */ | |
6fd5ea63 HL |
397 | |
398 | /* Variables for debugging .. */ | |
917f5085 TS |
399 | int corrupted; /* Counter for corrupted packages */ |
400 | int trans_down; /* Counter of packages (downstream) */ | |
401 | int trans_up; /* Counter of packages (upstream) */ | |
6fd5ea63 HL |
402 | |
403 | struct at_state_t at_state; | |
404 | unsigned long rcvbytes; | |
405 | ||
406 | __u16 fcs; | |
407 | struct sk_buff *skb; | |
917f5085 | 408 | int inputstate; /* see INS_XXXX */ |
6fd5ea63 HL |
409 | |
410 | int channel; | |
411 | ||
412 | struct cardstate *cs; | |
413 | ||
917f5085 | 414 | unsigned chstate; /* bitmap (CHS_*) */ |
6fd5ea63 | 415 | int ignore; |
917f5085 TS |
416 | unsigned proto2; /* Layer 2 protocol (ISDN_PROTO_L2_*) */ |
417 | char *commands[AT_NUM]; /* see AT_XXXX */ | |
6fd5ea63 HL |
418 | |
419 | #ifdef CONFIG_GIGASET_DEBUG | |
420 | int emptycount; | |
421 | #endif | |
422 | int busy; | |
423 | int use_count; | |
424 | ||
784d5858 | 425 | /* private data of hardware drivers */ |
6fd5ea63 | 426 | union { |
917f5085 TS |
427 | struct ser_bc_state *ser; /* serial hardware driver */ |
428 | struct usb_bc_state *usb; /* usb hardware driver (m105) */ | |
429 | struct bas_bc_state *bas; /* usb hardware driver (base) */ | |
6fd5ea63 HL |
430 | } hw; |
431 | }; | |
432 | ||
433 | struct cardstate { | |
434 | struct gigaset_driver *driver; | |
435 | unsigned minor_index; | |
784d5858 | 436 | struct device *dev; |
01107d34 | 437 | struct device *tty_dev; |
6fd5ea63 HL |
438 | |
439 | const struct gigaset_ops *ops; | |
440 | ||
441 | /* Stuff to handle communication */ | |
6fd5ea63 HL |
442 | wait_queue_head_t waitqueue; |
443 | int waiting; | |
917f5085 TS |
444 | atomic_t mode; /* see M_XXXX */ |
445 | atomic_t mstate; /* Modem state: see MS_XXXX */ | |
446 | /* only changed by the event layer */ | |
6fd5ea63 HL |
447 | int cmd_result; |
448 | ||
449 | int channels; | |
917f5085 | 450 | struct bc_state *bcs; /* Array of struct bc_state */ |
6fd5ea63 | 451 | |
917f5085 TS |
452 | int onechannel; /* data and commands transmitted in one |
453 | stream (M10x) */ | |
6fd5ea63 HL |
454 | |
455 | spinlock_t lock; | |
917f5085 TS |
456 | struct at_state_t at_state; /* at_state_t for cid == 0 */ |
457 | struct list_head temp_at_states;/* list of temporary "struct | |
458 | at_state_t"s without B channel */ | |
6fd5ea63 HL |
459 | |
460 | struct inbuf_t *inbuf; | |
461 | ||
462 | struct cmdbuf_t *cmdbuf, *lastcmdbuf; | |
463 | spinlock_t cmdlock; | |
464 | unsigned curlen, cmdbytes; | |
465 | ||
466 | unsigned open_count; | |
467 | struct tty_struct *tty; | |
468 | struct tasklet_struct if_wake_tasklet; | |
469 | unsigned control_state; | |
470 | ||
471 | unsigned fwver[4]; | |
472 | int gotfwver; | |
473 | ||
69049cc8 TS |
474 | unsigned running; /* !=0 if events are handled */ |
475 | unsigned connected; /* !=0 if hardware is connected */ | |
476 | unsigned isdn_up; /* !=0 after ISDN_STAT_RUN */ | |
6fd5ea63 | 477 | |
69049cc8 | 478 | unsigned cidmode; |
6fd5ea63 | 479 | |
917f5085 | 480 | int myid; /* id for communication with LL */ |
6fd5ea63 HL |
481 | isdn_if iif; |
482 | ||
483 | struct reply_t *tabnocid; | |
484 | struct reply_t *tabcid; | |
485 | int cs_init; | |
917f5085 TS |
486 | int ignoreframes; /* frames to ignore after setting up the |
487 | B channel */ | |
abfd1dc7 | 488 | struct mutex mutex; /* locks this structure: |
784d5858 TS |
489 | * connected is not changed, |
490 | * hardware_up is not changed, | |
491 | * MState is not changed to or from | |
492 | * MS_LOCKED */ | |
6fd5ea63 HL |
493 | |
494 | struct timer_list timer; | |
495 | int retry_count; | |
917f5085 TS |
496 | int dle; /* !=0 if modem commands/responses are |
497 | dle encoded */ | |
498 | int cur_at_seq; /* sequence of AT commands being | |
499 | processed */ | |
784d5858 | 500 | int curchannel; /* channel those commands are meant |
917f5085 TS |
501 | for */ |
502 | atomic_t commands_pending; /* flag(s) in xxx.commands_pending have | |
503 | been set */ | |
504 | struct tasklet_struct event_tasklet; | |
505 | /* tasklet for serializing AT commands. | |
506 | * Scheduled | |
507 | * -> for modem reponses (and | |
784d5858 | 508 | * incoming data for M10x) |
917f5085 TS |
509 | * -> on timeout |
510 | * -> after setting bits in | |
511 | * xxx.at_state.pending_command | |
512 | * (e.g. command from LL) */ | |
513 | struct tasklet_struct write_tasklet; | |
514 | /* tasklet for serial output | |
515 | * (not used in base driver) */ | |
6fd5ea63 HL |
516 | |
517 | /* event queue */ | |
518 | struct event_t events[MAX_EVENTS]; | |
69049cc8 | 519 | unsigned ev_tail, ev_head; |
6fd5ea63 HL |
520 | spinlock_t ev_lock; |
521 | ||
522 | /* current modem response */ | |
523 | unsigned char respdata[MAX_RESP_SIZE]; | |
524 | unsigned cbytes; | |
525 | ||
784d5858 | 526 | /* private data of hardware drivers */ |
6fd5ea63 | 527 | union { |
917f5085 TS |
528 | struct usb_cardstate *usb; /* USB hardware driver (m105) */ |
529 | struct ser_cardstate *ser; /* serial hardware driver */ | |
530 | struct bas_cardstate *bas; /* USB hardware driver (base) */ | |
6fd5ea63 HL |
531 | } hw; |
532 | }; | |
533 | ||
534 | struct gigaset_driver { | |
535 | struct list_head list; | |
917f5085 | 536 | spinlock_t lock; /* locks minor tables and blocked */ |
6fd5ea63 HL |
537 | struct tty_driver *tty; |
538 | unsigned have_tty; | |
539 | unsigned minor; | |
540 | unsigned minors; | |
541 | struct cardstate *cs; | |
542 | unsigned *flags; | |
543 | int blocked; | |
544 | ||
545 | const struct gigaset_ops *ops; | |
546 | struct module *owner; | |
547 | }; | |
548 | ||
549 | struct cmdbuf_t { | |
550 | struct cmdbuf_t *next, *prev; | |
551 | int len, offset; | |
552 | struct tasklet_struct *wake_tasklet; | |
553 | unsigned char buf[0]; | |
554 | }; | |
555 | ||
556 | struct bas_bc_state { | |
557 | /* isochronous output state */ | |
558 | atomic_t running; | |
559 | atomic_t corrbytes; | |
560 | spinlock_t isooutlock; | |
561 | struct isow_urbctx_t isoouturbs[BAS_OUTURBS]; | |
562 | struct isow_urbctx_t *isooutdone, *isooutfree, *isooutovfl; | |
563 | struct isowbuf_t *isooutbuf; | |
784d5858 TS |
564 | unsigned numsub; /* submitted URB counter |
565 | (for diagnostic messages only) */ | |
6fd5ea63 HL |
566 | struct tasklet_struct sent_tasklet; |
567 | ||
568 | /* isochronous input state */ | |
569 | spinlock_t isoinlock; | |
570 | struct urb *isoinurbs[BAS_INURBS]; | |
571 | unsigned char isoinbuf[BAS_INBUFSIZE * BAS_INURBS]; | |
784d5858 | 572 | struct urb *isoindone; /* completed isoc read URB */ |
dbd98231 | 573 | int isoinstatus; /* status of completed URB */ |
784d5858 TS |
574 | int loststatus; /* status of dropped URB */ |
575 | unsigned isoinlost; /* number of bytes lost */ | |
576 | /* state of bit unstuffing algorithm | |
577 | (in addition to BC_state.inputstate) */ | |
578 | unsigned seqlen; /* number of '1' bits not yet | |
579 | unstuffed */ | |
580 | unsigned inbyte, inbits; /* collected bits for next byte */ | |
6fd5ea63 | 581 | /* statistics */ |
784d5858 TS |
582 | unsigned goodbytes; /* bytes correctly received */ |
583 | unsigned alignerrs; /* frames with incomplete byte at end */ | |
584 | unsigned fcserrs; /* FCS errors */ | |
585 | unsigned frameerrs; /* framing errors */ | |
586 | unsigned giants; /* long frames */ | |
587 | unsigned runts; /* short frames */ | |
588 | unsigned aborts; /* HDLC aborts */ | |
589 | unsigned shared0s; /* '0' bits shared between flags */ | |
590 | unsigned stolen0s; /* '0' stuff bits also serving as | |
591 | leading flag bits */ | |
6fd5ea63 HL |
592 | struct tasklet_struct rcvd_tasklet; |
593 | }; | |
594 | ||
595 | struct gigaset_ops { | |
917f5085 TS |
596 | /* Called from ev-layer.c/interface.c for sending AT commands to the |
597 | device */ | |
6fd5ea63 | 598 | int (*write_cmd)(struct cardstate *cs, |
784d5858 TS |
599 | const unsigned char *buf, int len, |
600 | struct tasklet_struct *wake_tasklet); | |
6fd5ea63 HL |
601 | |
602 | /* Called from interface.c for additional device control */ | |
603 | int (*write_room)(struct cardstate *cs); | |
604 | int (*chars_in_buffer)(struct cardstate *cs); | |
605 | int (*brkchars)(struct cardstate *cs, const unsigned char buf[6]); | |
606 | ||
607 | /* Called from ev-layer.c after setting up connection | |
608 | * Should call gigaset_bchannel_up(), when finished. */ | |
609 | int (*init_bchannel)(struct bc_state *bcs); | |
610 | ||
611 | /* Called from ev-layer.c after hanging up | |
612 | * Should call gigaset_bchannel_down(), when finished. */ | |
613 | int (*close_bchannel)(struct bc_state *bcs); | |
614 | ||
615 | /* Called by gigaset_initcs() for setting up bcs->hw.xxx */ | |
616 | int (*initbcshw)(struct bc_state *bcs); | |
617 | ||
618 | /* Called by gigaset_freecs() for freeing bcs->hw.xxx */ | |
619 | int (*freebcshw)(struct bc_state *bcs); | |
620 | ||
73a88814 | 621 | /* Called by gigaset_bchannel_down() for resetting bcs->hw.xxx */ |
6fd5ea63 HL |
622 | void (*reinitbcshw)(struct bc_state *bcs); |
623 | ||
624 | /* Called by gigaset_initcs() for setting up cs->hw.xxx */ | |
625 | int (*initcshw)(struct cardstate *cs); | |
626 | ||
627 | /* Called by gigaset_freecs() for freeing cs->hw.xxx */ | |
628 | void (*freecshw)(struct cardstate *cs); | |
629 | ||
917f5085 TS |
630 | /* Called from common.c/interface.c for additional serial port |
631 | control */ | |
632 | int (*set_modem_ctrl)(struct cardstate *cs, unsigned old_state, | |
633 | unsigned new_state); | |
6fd5ea63 HL |
634 | int (*baud_rate)(struct cardstate *cs, unsigned cflag); |
635 | int (*set_line_ctrl)(struct cardstate *cs, unsigned cflag); | |
636 | ||
637 | /* Called from i4l.c to put an skb into the send-queue. */ | |
638 | int (*send_skb)(struct bc_state *bcs, struct sk_buff *skb); | |
639 | ||
640 | /* Called from ev-layer.c to process a block of data | |
641 | * received through the common/control channel. */ | |
642 | void (*handle_input)(struct inbuf_t *inbuf); | |
643 | ||
644 | }; | |
645 | ||
646 | /* = Common structures and definitions ======================================= */ | |
647 | ||
648 | /* Parser states for DLE-Event: | |
649 | * <DLE-EVENT>: <DLE_FLAG> "X" <EVENT> <DLE_FLAG> "." | |
650 | * <DLE_FLAG>: 0x10 | |
651 | * <EVENT>: ((a-z)* | (A-Z)* | (0-10)*)+ | |
652 | */ | |
784d5858 | 653 | #define DLE_FLAG 0x10 |
6fd5ea63 HL |
654 | |
655 | /* =========================================================================== | |
656 | * Functions implemented in asyncdata.c | |
657 | */ | |
658 | ||
659 | /* Called from i4l.c to put an skb into the send-queue. | |
660 | * After sending gigaset_skb_sent() should be called. */ | |
661 | int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb); | |
662 | ||
663 | /* Called from ev-layer.c to process a block of data | |
664 | * received through the common/control channel. */ | |
665 | void gigaset_m10x_input(struct inbuf_t *inbuf); | |
666 | ||
667 | /* =========================================================================== | |
668 | * Functions implemented in isocdata.c | |
669 | */ | |
670 | ||
671 | /* Called from i4l.c to put an skb into the send-queue. | |
672 | * After sending gigaset_skb_sent() should be called. */ | |
673 | int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb); | |
674 | ||
675 | /* Called from ev-layer.c to process a block of data | |
676 | * received through the common/control channel. */ | |
677 | void gigaset_isoc_input(struct inbuf_t *inbuf); | |
678 | ||
679 | /* Called from bas-gigaset.c to process a block of data | |
680 | * received through the isochronous channel */ | |
917f5085 TS |
681 | void gigaset_isoc_receive(unsigned char *src, unsigned count, |
682 | struct bc_state *bcs); | |
6fd5ea63 HL |
683 | |
684 | /* Called from bas-gigaset.c to put a block of data | |
685 | * into the isochronous output buffer */ | |
686 | int gigaset_isoc_buildframe(struct bc_state *bcs, unsigned char *in, int len); | |
687 | ||
688 | /* Called from bas-gigaset.c to initialize the isochronous output buffer */ | |
689 | void gigaset_isowbuf_init(struct isowbuf_t *iwb, unsigned char idle); | |
690 | ||
691 | /* Called from bas-gigaset.c to retrieve a block of bytes for sending */ | |
692 | int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size); | |
693 | ||
694 | /* =========================================================================== | |
695 | * Functions implemented in i4l.c/gigaset.h | |
696 | */ | |
697 | ||
698 | /* Called by gigaset_initcs() for setting up with the isdn4linux subsystem */ | |
699 | int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid); | |
700 | ||
701 | /* Called from xxx-gigaset.c to indicate completion of sending an skb */ | |
702 | void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb); | |
703 | ||
704 | /* Called from common.c/ev-layer.c to indicate events relevant to the LL */ | |
705 | int gigaset_isdn_icall(struct at_state_t *at_state); | |
706 | int gigaset_isdn_setup_accept(struct at_state_t *at_state); | |
707 | int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data); | |
708 | ||
709 | void gigaset_i4l_cmd(struct cardstate *cs, int cmd); | |
710 | void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd); | |
711 | ||
712 | ||
713 | static inline void gigaset_isdn_rcv_err(struct bc_state *bcs) | |
714 | { | |
715 | isdn_ctrl response; | |
716 | ||
717 | /* error -> LL */ | |
784d5858 | 718 | gig_dbg(DEBUG_CMD, "sending L1ERR"); |
6fd5ea63 HL |
719 | response.driver = bcs->cs->myid; |
720 | response.command = ISDN_STAT_L1ERR; | |
721 | response.arg = bcs->channel; | |
722 | response.parm.errcode = ISDN_STAT_L1ERR_RECV; | |
723 | bcs->cs->iif.statcallb(&response); | |
724 | } | |
725 | ||
726 | /* =========================================================================== | |
727 | * Functions implemented in ev-layer.c | |
728 | */ | |
729 | ||
730 | /* tasklet called from common.c to process queued events */ | |
731 | void gigaset_handle_event(unsigned long data); | |
732 | ||
733 | /* called from isocdata.c / asyncdata.c | |
734 | * when a complete modem response line has been received */ | |
735 | void gigaset_handle_modem_response(struct cardstate *cs); | |
736 | ||
737 | /* =========================================================================== | |
738 | * Functions implemented in proc.c | |
739 | */ | |
740 | ||
741 | /* initialize sysfs for device */ | |
b1d47464 TS |
742 | void gigaset_init_dev_sysfs(struct cardstate *cs); |
743 | void gigaset_free_dev_sysfs(struct cardstate *cs); | |
6fd5ea63 HL |
744 | |
745 | /* =========================================================================== | |
746 | * Functions implemented in common.c/gigaset.h | |
747 | */ | |
748 | ||
749 | void gigaset_bcs_reinit(struct bc_state *bcs); | |
750 | void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs, | |
784d5858 | 751 | struct cardstate *cs, int cid); |
6fd5ea63 HL |
752 | int gigaset_get_channel(struct bc_state *bcs); |
753 | void gigaset_free_channel(struct bc_state *bcs); | |
754 | int gigaset_get_channels(struct cardstate *cs); | |
755 | void gigaset_free_channels(struct cardstate *cs); | |
756 | void gigaset_block_channels(struct cardstate *cs); | |
757 | ||
758 | /* Allocate and initialize driver structure. */ | |
759 | struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, | |
784d5858 TS |
760 | const char *procname, |
761 | const char *devname, | |
784d5858 TS |
762 | const struct gigaset_ops *ops, |
763 | struct module *owner); | |
6fd5ea63 HL |
764 | |
765 | /* Deallocate driver structure. */ | |
766 | void gigaset_freedriver(struct gigaset_driver *drv); | |
767 | void gigaset_debugdrivers(void); | |
6fd5ea63 HL |
768 | struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty); |
769 | struct cardstate *gigaset_get_cs_by_id(int id); | |
770 | ||
771 | /* For drivers without fixed assignment device<->cardstate (usb) */ | |
772 | struct cardstate *gigaset_getunassignedcs(struct gigaset_driver *drv); | |
773 | void gigaset_unassign(struct cardstate *cs); | |
774 | void gigaset_blockdriver(struct gigaset_driver *drv); | |
775 | ||
917f5085 TS |
776 | /* Allocate and initialize card state. Calls hardware dependent |
777 | gigaset_init[b]cs(). */ | |
6fd5ea63 HL |
778 | struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, |
779 | int onechannel, int ignoreframes, | |
780 | int cidmode, const char *modulename); | |
781 | ||
782 | /* Free card state. Calls hardware dependent gigaset_free[b]cs(). */ | |
783 | void gigaset_freecs(struct cardstate *cs); | |
784 | ||
785 | /* Tell common.c that hardware and driver are ready. */ | |
786 | int gigaset_start(struct cardstate *cs); | |
787 | ||
788 | /* Tell common.c that the device is not present any more. */ | |
789 | void gigaset_stop(struct cardstate *cs); | |
790 | ||
791 | /* Tell common.c that the driver is being unloaded. */ | |
792 | void gigaset_shutdown(struct cardstate *cs); | |
793 | ||
794 | /* Tell common.c that an skb has been sent. */ | |
795 | void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb); | |
796 | ||
797 | /* Append event to the queue. | |
798 | * Returns NULL on failure or a pointer to the event on success. | |
799 | * ptr must be kmalloc()ed (and not be freed by the caller). | |
800 | */ | |
801 | struct event_t *gigaset_add_event(struct cardstate *cs, | |
784d5858 TS |
802 | struct at_state_t *at_state, int type, |
803 | void *ptr, int parameter, void *arg); | |
6fd5ea63 HL |
804 | |
805 | /* Called on CONFIG1 command from frontend. */ | |
806 | int gigaset_enterconfigmode(struct cardstate *cs); //0: success <0: errorcode | |
807 | ||
808 | /* cs->lock must not be locked */ | |
809 | static inline void gigaset_schedule_event(struct cardstate *cs) | |
810 | { | |
811 | unsigned long flags; | |
812 | spin_lock_irqsave(&cs->lock, flags); | |
69049cc8 | 813 | if (cs->running) |
6fd5ea63 HL |
814 | tasklet_schedule(&cs->event_tasklet); |
815 | spin_unlock_irqrestore(&cs->lock, flags); | |
816 | } | |
817 | ||
818 | /* Tell common.c that B channel has been closed. */ | |
819 | /* cs->lock must not be locked */ | |
820 | static inline void gigaset_bchannel_down(struct bc_state *bcs) | |
821 | { | |
822 | gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_CLOSED, NULL, 0, NULL); | |
823 | ||
784d5858 | 824 | gig_dbg(DEBUG_CMD, "scheduling BC_CLOSED"); |
6fd5ea63 HL |
825 | gigaset_schedule_event(bcs->cs); |
826 | } | |
827 | ||
828 | /* Tell common.c that B channel has been opened. */ | |
829 | /* cs->lock must not be locked */ | |
830 | static inline void gigaset_bchannel_up(struct bc_state *bcs) | |
831 | { | |
832 | gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_OPEN, NULL, 0, NULL); | |
833 | ||
784d5858 | 834 | gig_dbg(DEBUG_CMD, "scheduling BC_OPEN"); |
6fd5ea63 HL |
835 | gigaset_schedule_event(bcs->cs); |
836 | } | |
837 | ||
838 | /* handling routines for sk_buff */ | |
839 | /* ============================= */ | |
840 | ||
6fd5ea63 HL |
841 | /* pass received skb to LL |
842 | * Warning: skb must not be accessed anymore! | |
843 | */ | |
844 | static inline void gigaset_rcv_skb(struct sk_buff *skb, | |
784d5858 TS |
845 | struct cardstate *cs, |
846 | struct bc_state *bcs) | |
6fd5ea63 HL |
847 | { |
848 | cs->iif.rcvcallb_skb(cs->myid, bcs->channel, skb); | |
849 | bcs->trans_down++; | |
850 | } | |
851 | ||
852 | /* handle reception of corrupted skb | |
853 | * Warning: skb must not be accessed anymore! | |
854 | */ | |
855 | static inline void gigaset_rcv_error(struct sk_buff *procskb, | |
784d5858 TS |
856 | struct cardstate *cs, |
857 | struct bc_state *bcs) | |
6fd5ea63 HL |
858 | { |
859 | if (procskb) | |
860 | dev_kfree_skb(procskb); | |
861 | ||
862 | if (bcs->ignore) | |
863 | --bcs->ignore; | |
864 | else { | |
865 | ++bcs->corrupted; | |
866 | gigaset_isdn_rcv_err(bcs); | |
867 | } | |
868 | } | |
869 | ||
6fd5ea63 | 870 | /* append received bytes to inbuf */ |
714e8236 TS |
871 | int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src, |
872 | unsigned numbytes); | |
6fd5ea63 HL |
873 | |
874 | /* =========================================================================== | |
875 | * Functions implemented in interface.c | |
876 | */ | |
877 | ||
878 | /* initialize interface */ | |
879 | void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname, | |
f4eaa370 | 880 | const char *devname); |
6fd5ea63 HL |
881 | /* release interface */ |
882 | void gigaset_if_freedriver(struct gigaset_driver *drv); | |
883 | /* add minor */ | |
884 | void gigaset_if_init(struct cardstate *cs); | |
885 | /* remove minor */ | |
886 | void gigaset_if_free(struct cardstate *cs); | |
887 | /* device received data */ | |
888 | void gigaset_if_receive(struct cardstate *cs, | |
784d5858 | 889 | unsigned char *buffer, size_t len); |
6fd5ea63 HL |
890 | |
891 | #endif |