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