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