Merge branches 'release', 'asus', 'sony-laptop' and 'thinkpad' into release
[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 /* debug flags, combine by adding/bitwise OR */
74 enum debuglevel {
75         DEBUG_INTR        = 0x00008, /* interrupt processing */
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 */
80         DEBUG_DRIVER      = 0x00400, /* driver structure */
81         DEBUG_HDLC        = 0x00800, /* M10x HDLC processing */
82         DEBUG_WRITE       = 0x01000, /* M105 data write */
83         DEBUG_TRANSCMD    = 0x02000, /* AT-COMMANDS+RESPONSES */
84         DEBUG_MCMD        = 0x04000, /* COMMANDS THAT ARE SENT VERY OFTEN */
85         DEBUG_INIT        = 0x08000, /* (de)allocation+initialization of data
86                                         structures */
87         DEBUG_SUSPEND     = 0x10000, /* suspend/resume processing */
88         DEBUG_OUTPUT      = 0x20000, /* output to device */
89         DEBUG_ISO         = 0x40000, /* isochronous transfers */
90         DEBUG_IF          = 0x80000, /* character device operations */
91         DEBUG_USBREQ      = 0x100000, /* USB communication (except payload
92                                          data) */
93         DEBUG_LOCKCMD     = 0x200000, /* AT commands and responses when
94                                          MS_LOCKED */
95
96         DEBUG_ANY         = 0x3fffff, /* print message if any of the others is
97                                          activated */
98 };
99
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
107 #undef info
108 #undef warn
109 #undef notice
110
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)
119
120 #ifdef CONFIG_GIGASET_DEBUG
121
122 #define gig_dbg(level, format, arg...) \
123         do { \
124                 if (unlikely(((enum debuglevel)gigaset_debuglevel) & (level))) \
125                         printk(KERN_DEBUG KBUILD_MODNAME ": " format "\n", \
126                                ## arg); \
127         } while (0)
128 #define DEBUG_DEFAULT (DEBUG_TRANSCMD | DEBUG_CMD | DEBUG_USBREQ)
129
130 #else
131
132 #define gig_dbg(level, format, arg...) do {} while (0)
133 #define DEBUG_DEFAULT 0
134
135 #endif
136
137 void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
138                         size_t len, const unsigned char *buf);
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 */
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)
154
155 /* int-in-events 3070 */
156 #define HD_B1_FLOW_CONTROL              0x80
157 #define HD_B2_FLOW_CONTROL              0x81
158 #define HD_RECEIVEATDATA_ACK            (0x35)          // 3070
159                                                 // att: HD_RECEIVE>>AT<<DATA_ACK
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
185 /* number of B channels supported by base driver */
186 #define BAS_CHANNELS    2
187
188 /* USB frames for isochronous transfer */
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 */
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 */
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
242
243 /* input state */
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
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
257 #define ICALL_REJECT    0
258 #define ICALL_ACCEPT    1
259 #define ICALL_IGNORE    2
260
261 /* device state */
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
268
269 /* mode */
270 #define M_UNKNOWN       0
271 #define M_CONFIG        1
272 #define M_UNIMODEM      2
273 #define M_CID           3
274
275 /* start mode */
276 #define SM_LOCKED       0
277 #define SM_ISDN         1 /* default */
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 {
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 */
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 {
306         unsigned char           *rcvbuf;        /* usb-gigaset receive buffer */
307         struct bc_state         *bcs;
308         struct cardstate        *cs;
309         int                     inputstate;
310         int                     head, tail;
311         unsigned char           data[RBUFSIZE];
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
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
330  */
331 struct isowbuf_t {
332         int             read;
333         int             nextread;
334         int             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
347  * - status: URB completion status
348  */
349 struct isow_urbctx_t {
350         struct urb *urb;
351         struct bc_state *bcs;
352         int limit;
353         int status;
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 {
361         struct list_head        list;
362         int                     waiting;
363         int                     getstring;
364         unsigned                timer_index;
365         unsigned long           timer_expires;
366         int                     timer_active;
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 */
373         unsigned                seq_index;
374
375         struct cardstate        *cs;
376         struct bc_state         *bcs;
377 };
378
379 struct resp_type_t {
380         unsigned char   *response;
381         int             resp_code;      /* RSP_XXXX */
382         int             type;           /* RT_XXXX */
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 {
395         struct sk_buff *tx_skb;         /* Current transfer buffer to modem */
396         struct sk_buff_head squeue;     /* B-Channel send Queue */
397
398         /* Variables for debugging .. */
399         int corrupted;                  /* Counter for corrupted packages */
400         int trans_down;                 /* Counter of packages (downstream) */
401         int trans_up;                   /* Counter of packages (upstream) */
402
403         struct at_state_t at_state;
404         unsigned long rcvbytes;
405
406         __u16 fcs;
407         struct sk_buff *skb;
408         int inputstate;                 /* see INS_XXXX */
409
410         int channel;
411
412         struct cardstate *cs;
413
414         unsigned chstate;               /* bitmap (CHS_*) */
415         int ignore;
416         unsigned proto2;                /* Layer 2 protocol (ISDN_PROTO_L2_*) */
417         char *commands[AT_NUM];         /* see AT_XXXX */
418
419 #ifdef CONFIG_GIGASET_DEBUG
420         int emptycount;
421 #endif
422         int busy;
423         int use_count;
424
425         /* private data of hardware drivers */
426         union {
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) */
430         } hw;
431 };
432
433 struct cardstate {
434         struct gigaset_driver *driver;
435         unsigned minor_index;
436         struct device *dev;
437         struct device *tty_dev;
438         unsigned flags;
439
440         const struct gigaset_ops *ops;
441
442         /* Stuff to handle communication */
443         wait_queue_head_t waitqueue;
444         int waiting;
445         int mode;                       /* see M_XXXX */
446         int mstate;                     /* Modem state: see MS_XXXX */
447                                         /* only changed by the event layer */
448         int cmd_result;
449
450         int channels;
451         struct bc_state *bcs;           /* Array of struct bc_state */
452
453         int onechannel;                 /* data and commands transmitted in one
454                                            stream (M10x) */
455
456         spinlock_t lock;
457         struct at_state_t at_state;     /* at_state_t for cid == 0 */
458         struct list_head temp_at_states;/* list of temporary "struct
459                                            at_state_t"s without B channel */
460
461         struct inbuf_t *inbuf;
462
463         struct cmdbuf_t *cmdbuf, *lastcmdbuf;
464         spinlock_t cmdlock;
465         unsigned curlen, cmdbytes;
466
467         unsigned open_count;
468         struct tty_struct *tty;
469         struct tasklet_struct if_wake_tasklet;
470         unsigned control_state;
471
472         unsigned fwver[4];
473         int gotfwver;
474
475         unsigned running;               /* !=0 if events are handled */
476         unsigned connected;             /* !=0 if hardware is connected */
477         unsigned isdn_up;               /* !=0 after ISDN_STAT_RUN */
478
479         unsigned cidmode;
480
481         int myid;                       /* id for communication with LL */
482         isdn_if iif;
483
484         struct reply_t *tabnocid;
485         struct reply_t *tabcid;
486         int cs_init;
487         int ignoreframes;               /* frames to ignore after setting up the
488                                            B channel */
489         struct mutex mutex;             /* locks this structure:
490                                          *   connected is not changed,
491                                          *   hardware_up is not changed,
492                                          *   MState is not changed to or from
493                                          *   MS_LOCKED */
494
495         struct timer_list timer;
496         int retry_count;
497         int dle;                        /* !=0 if modem commands/responses are
498                                            dle encoded */
499         int cur_at_seq;                 /* sequence of AT commands being
500                                            processed */
501         int curchannel;                 /* channel those commands are meant
502                                            for */
503         int commands_pending;           /* flag(s) in xxx.commands_pending have
504                                            been set */
505         struct tasklet_struct event_tasklet;
506                                         /* tasklet for serializing AT commands.
507                                          * Scheduled
508                                          *   -> for modem reponses (and
509                                          *      incoming data for M10x)
510                                          *   -> on timeout
511                                          *   -> after setting bits in
512                                          *      xxx.at_state.pending_command
513                                          *      (e.g. command from LL) */
514         struct tasklet_struct write_tasklet;
515                                         /* tasklet for serial output
516                                          * (not used in base driver) */
517
518         /* event queue */
519         struct event_t events[MAX_EVENTS];
520         unsigned ev_tail, ev_head;
521         spinlock_t ev_lock;
522
523         /* current modem response */
524         unsigned char respdata[MAX_RESP_SIZE];
525         unsigned cbytes;
526
527         /* private data of hardware drivers */
528         union {
529                 struct usb_cardstate *usb; /* USB hardware driver (m105) */
530                 struct ser_cardstate *ser; /* serial hardware driver */
531                 struct bas_cardstate *bas; /* USB hardware driver (base) */
532         } hw;
533 };
534
535 struct gigaset_driver {
536         struct list_head list;
537         spinlock_t lock;                /* locks minor tables and blocked */
538         struct tty_driver *tty;
539         unsigned have_tty;
540         unsigned minor;
541         unsigned minors;
542         struct cardstate *cs;
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         int             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;
564         unsigned numsub;                /* submitted URB counter
565                                            (for diagnostic messages only) */
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];
572         struct urb *isoindone;          /* completed isoc read URB */
573         int isoinstatus;                /* status of completed URB */
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 */
581         /* statistics */
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 */
592         struct tasklet_struct rcvd_tasklet;
593 };
594
595 struct gigaset_ops {
596         /* Called from ev-layer.c/interface.c for sending AT commands to the
597            device */
598         int (*write_cmd)(struct cardstate *cs,
599                          const unsigned char *buf, int len,
600                          struct tasklet_struct *wake_tasklet);
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
621         /* Called by gigaset_bchannel_down() for resetting bcs->hw.xxx */
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
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);
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  */
653 #define DLE_FLAG        0x10
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 */
681 void gigaset_isoc_receive(unsigned char *src, unsigned count,
682                           struct bc_state *bcs);
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 */
718         gig_dbg(DEBUG_CMD, "sending L1ERR");
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 */
742 void gigaset_init_dev_sysfs(struct cardstate *cs);
743 void gigaset_free_dev_sysfs(struct cardstate *cs);
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,
751                      struct cardstate *cs, int cid);
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,
760                                           const char *procname,
761                                           const char *devname,
762                                           const struct gigaset_ops *ops,
763                                           struct module *owner);
764
765 /* Deallocate driver structure. */
766 void gigaset_freedriver(struct gigaset_driver *drv);
767 void gigaset_debugdrivers(void);
768 struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty);
769 struct cardstate *gigaset_get_cs_by_id(int id);
770 void gigaset_blockdriver(struct gigaset_driver *drv);
771
772 /* Allocate and initialize card state. Calls hardware dependent
773    gigaset_init[b]cs(). */
774 struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
775                                  int onechannel, int ignoreframes,
776                                  int cidmode, const char *modulename);
777
778 /* Free card state. Calls hardware dependent gigaset_free[b]cs(). */
779 void gigaset_freecs(struct cardstate *cs);
780
781 /* Tell common.c that hardware and driver are ready. */
782 int gigaset_start(struct cardstate *cs);
783
784 /* Tell common.c that the device is not present any more. */
785 void gigaset_stop(struct cardstate *cs);
786
787 /* Tell common.c that the driver is being unloaded. */
788 int gigaset_shutdown(struct cardstate *cs);
789
790 /* Tell common.c that an skb has been sent. */
791 void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
792
793 /* Append event to the queue.
794  * Returns NULL on failure or a pointer to the event on success.
795  * ptr must be kmalloc()ed (and not be freed by the caller).
796  */
797 struct event_t *gigaset_add_event(struct cardstate *cs,
798                                   struct at_state_t *at_state, int type,
799                                   void *ptr, int parameter, void *arg);
800
801 /* Called on CONFIG1 command from frontend. */
802 int gigaset_enterconfigmode(struct cardstate *cs); //0: success <0: errorcode
803
804 /* cs->lock must not be locked */
805 static inline void gigaset_schedule_event(struct cardstate *cs)
806 {
807         unsigned long flags;
808         spin_lock_irqsave(&cs->lock, flags);
809         if (cs->running)
810                 tasklet_schedule(&cs->event_tasklet);
811         spin_unlock_irqrestore(&cs->lock, flags);
812 }
813
814 /* Tell common.c that B channel has been closed. */
815 /* cs->lock must not be locked */
816 static inline void gigaset_bchannel_down(struct bc_state *bcs)
817 {
818         gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_CLOSED, NULL, 0, NULL);
819
820         gig_dbg(DEBUG_CMD, "scheduling BC_CLOSED");
821         gigaset_schedule_event(bcs->cs);
822 }
823
824 /* Tell common.c that B channel has been opened. */
825 /* cs->lock must not be locked */
826 static inline void gigaset_bchannel_up(struct bc_state *bcs)
827 {
828         gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_OPEN, NULL, 0, NULL);
829
830         gig_dbg(DEBUG_CMD, "scheduling BC_OPEN");
831         gigaset_schedule_event(bcs->cs);
832 }
833
834 /* handling routines for sk_buff */
835 /* ============================= */
836
837 /* pass received skb to LL
838  * Warning: skb must not be accessed anymore!
839  */
840 static inline void gigaset_rcv_skb(struct sk_buff *skb,
841                                    struct cardstate *cs,
842                                    struct bc_state *bcs)
843 {
844         cs->iif.rcvcallb_skb(cs->myid, bcs->channel, skb);
845         bcs->trans_down++;
846 }
847
848 /* handle reception of corrupted skb
849  * Warning: skb must not be accessed anymore!
850  */
851 static inline void gigaset_rcv_error(struct sk_buff *procskb,
852                                      struct cardstate *cs,
853                                      struct bc_state *bcs)
854 {
855         if (procskb)
856                 dev_kfree_skb(procskb);
857
858         if (bcs->ignore)
859                 --bcs->ignore;
860         else {
861                 ++bcs->corrupted;
862                 gigaset_isdn_rcv_err(bcs);
863         }
864 }
865
866 /* append received bytes to inbuf */
867 int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
868                        unsigned numbytes);
869
870 /* ===========================================================================
871  *  Functions implemented in interface.c
872  */
873
874 /* initialize interface */
875 void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
876                            const char *devname);
877 /* release interface */
878 void gigaset_if_freedriver(struct gigaset_driver *drv);
879 /* add minor */
880 void gigaset_if_init(struct cardstate *cs);
881 /* remove minor */
882 void gigaset_if_free(struct cardstate *cs);
883 /* device received data */
884 void gigaset_if_receive(struct cardstate *cs,
885                         unsigned char *buffer, size_t len);
886
887 #endif