1 /* Siemens Gigaset 307x driver
2 * Common header file for all connection variants
4 * Written by Stefan Eilers <Eilers.Stefan@epost.de>
5 * and Hansjoerg Lipp <hjlipp@web.de>
7 * Version: $Id: gigaset.h,v 1.97.4.26 2006/02/04 18:28:16 hjlipp Exp $
8 * ===========================================================================
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>
31 #define GIG_VERSION {0,5,0,0}
32 #define GIG_COMPAT {0,4,0,0}
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 */
38 #define MAX_EVENTS 64 /* size of event queue */
41 #define SBUFSIZE 4096 /* sk_buff payload size */
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 */
46 /* compile time options */
49 #define GIG_MAYINITONDIAL
53 #define MAX_TIMER_INDEX 1000
54 #define MAX_SEQ_INDEX 1000
56 #define GIG_TICK (HZ / 10)
58 /* timeout values (unit: 1 sec) */
59 #define INIT_TIMEOUT 1
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 */
66 #define BAS_RETRY 3 /* max. retries for base USB ops */
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; }
76 extern int gigaset_debuglevel
; /* "needs" cast to (enum debuglevel) */
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 */
104 DEBUG_ANY
= 0x3fffff, /* print message if any of the others is activated */
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)
111 #define DEBUG_DEFAULT 0
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 */
117 #define info(format, arg...) printk(KERN_INFO "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg)
120 #define notice(format, arg...) printk(KERN_NOTICE "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg)
123 #define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg)
126 #define err(format, arg...) printk(KERN_ERR "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg)
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)
133 #define dbg(level, format, arg...) do {} while (0)
136 void gigaset_dbg_buffer(enum debuglevel level
, const unsigned char *msg
,
137 size_t len
, const unsigned char *buf
, int from_user
);
139 /* connection state */
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
147 #define ZSAU_DISCONNECT_REQ 6
148 #define ZSAU_UNKNOWN -1
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)
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
167 #define HD_SUSPEND_END (0x61) // ISurf USB
169 #define HD_RESET_INTERRUPT_PIPE_ACK (0xFF) // ISurf USB + 3070
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
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 */
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 */
197 #define BAS_OUTURBS 3
199 /* variable commands in struct bc_state */
209 /* variables in struct at_state_t */
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
229 #define EV_IF_LOCK -112
230 #define EV_PROTO_L2 -113
231 #define EV_ACCEPT -114
234 #define EV_BC_OPEN -117
235 #define EV_BC_CLOSED -118
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
247 #define CHS_D_UP 0x01
248 #define CHS_B_UP 0x02
249 #define CHS_NOTIFY_LL 0x04
251 #define ICALL_REJECT 0
252 #define ICALL_ACCEPT 1
253 #define ICALL_IGNORE 2
256 #define MS_UNINITIALIZED 0
259 #define MS_SHUTDOWN 3
271 #define SM_ISDN 1 /* default */
274 struct gigaset_driver
;
276 struct usb_cardstate
;
277 struct ser_cardstate
;
278 struct bas_cardstate
;
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 */
296 extern struct reply_t gigaset_tab_cid_m10x
[];
297 extern struct reply_t gigaset_tab_nocid_m10x
[];
300 unsigned char *rcvbuf
; /* usb-gigaset receive buffer */
301 struct bc_state
*bcs
;
302 struct cardstate
*cs
;
306 unsigned char data
[RBUFSIZE
];
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
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
339 unsigned char data
[BAS_OUTBUFSIZE
+ BAS_OUTBUFPAD
];
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
350 struct isow_urbctx_t
{
352 struct bc_state
*bcs
;
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
361 struct list_head list
;
364 atomic_t timer_index
;
365 unsigned long timer_expires
;
367 unsigned int ConState
; /* State of connection */
368 struct reply_t
*replystruct
;
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 */
375 struct cardstate
*cs
;
376 struct bc_state
*bcs
;
380 unsigned char *response
;
381 int resp_code
; /* RSP_XXXX */
382 int type
; /* RT_XXXX */
387 struct semaphore
*sem
;
396 struct at_state_t
*at_state
;
399 /* This buffer holds all information about the used B-Channel */
401 struct sk_buff
*tx_skb
; /* Current transfer buffer to modem */
402 struct sk_buff_head squeue
; /* B-Channel send Queue */
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) */
409 struct at_state_t at_state
;
410 unsigned long rcvbytes
;
414 int inputstate
; /* see INS_XXXX */
418 struct cardstate
*cs
;
420 unsigned chstate
; /* bitmap (CHS_*) */
422 unsigned proto2
; /* Layer 2 protocol (ISDN_PROTO_L2_*) */
423 char *commands
[AT_NUM
]; /* see AT_XXXX */
425 #ifdef CONFIG_GIGASET_DEBUG
431 /* hardware drivers */
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
;
440 struct gigaset_driver
*driver
;
441 unsigned minor_index
;
443 const struct gigaset_ops
*ops
;
445 /* Stuff to handle communication */
446 //wait_queue_head_t initwait;
447 wait_queue_head_t waitqueue
;
449 atomic_t mode
; /* see M_XXXX */
450 atomic_t mstate
; /* Modem state: see MS_XXXX */
451 /* only changed by the event layer */
455 struct bc_state
*bcs
; /* Array of struct bc_state */
457 int onechannel
; /* data and commands transmitted in one stream (M10x) */
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 */
463 struct inbuf_t
*inbuf
;
465 struct cmdbuf_t
*cmdbuf
, *lastcmdbuf
;
467 unsigned curlen
, cmdbytes
;
470 struct tty_struct
*tty
;
471 struct tasklet_struct if_wake_tasklet
;
472 unsigned control_state
;
477 atomic_t running
; /* !=0 if events are handled */
478 atomic_t connected
; /* !=0 if hardware is connected */
482 int myid
; /* id for communication with LL */
485 struct reply_t
*tabnocid
;
486 struct reply_t
*tabcid
;
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 */
494 struct timer_list timer
;
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)
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) */
509 struct event_t events
[MAX_EVENTS
];
510 atomic_t ev_tail
, ev_head
;
513 /* current modem response */
514 unsigned char respdata
[MAX_RESP_SIZE
];
517 /* hardware drivers */
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 */
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
;
533 struct cardstate
*cs
;
537 const struct gigaset_ops
*ops
;
538 struct module
*owner
;
542 struct cmdbuf_t
*next
, *prev
;
544 struct tasklet_struct
*wake_tasklet
;
545 unsigned char buf
[0];
548 struct bas_bc_state
{
549 /* isochronous output state */
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
;
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 */
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
;
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
);
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]);
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
);
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
);
601 /* Called by gigaset_initcs() for setting up bcs->hw.xxx */
602 int (*initbcshw
)(struct bc_state
*bcs
);
604 /* Called by gigaset_freecs() for freeing bcs->hw.xxx */
605 int (*freebcshw
)(struct bc_state
*bcs
);
607 /* Called by gigaset_stop() or gigaset_bchannel_down() for resetting bcs->hw.xxx */
608 void (*reinitbcshw
)(struct bc_state
*bcs
);
610 /* Called by gigaset_initcs() for setting up cs->hw.xxx */
611 int (*initcshw
)(struct cardstate
*cs
);
613 /* Called by gigaset_freecs() for freeing cs->hw.xxx */
614 void (*freecshw
)(struct cardstate
*cs
);
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);
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
);
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
);
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
);
635 /* = Common structures and definitions ======================================= */
637 /* Parser states for DLE-Event:
638 * <DLE-EVENT>: <DLE_FLAG> "X" <EVENT> <DLE_FLAG> "."
640 * <EVENT>: ((a-z)* | (A-Z)* | (0-10)*)+
642 #define DLE_FLAG 0x10
644 /* ===========================================================================
645 * Functions implemented in asyncdata.c
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
);
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
);
656 /* ===========================================================================
657 * Functions implemented in isocdata.c
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
);
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
);
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
);
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
);
676 /* Called from bas-gigaset.c to initialize the isochronous output buffer */
677 void gigaset_isowbuf_init(struct isowbuf_t
*iwb
, unsigned char idle
);
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
);
682 /* ===========================================================================
683 * Functions implemented in i4l.c/gigaset.h
686 /* Called by gigaset_initcs() for setting up with the isdn4linux subsystem */
687 int gigaset_register_to_LL(struct cardstate
*cs
, const char *isdnid
);
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
);
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
);
697 void gigaset_i4l_cmd(struct cardstate
*cs
, int cmd
);
698 void gigaset_i4l_channel_cmd(struct bc_state
*bcs
, int cmd
);
701 static inline void gigaset_isdn_rcv_err(struct bc_state
*bcs
)
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
);
714 /* ===========================================================================
715 * Functions implemented in ev-layer.c
718 /* tasklet called from common.c to process queued events */
719 void gigaset_handle_event(unsigned long data
);
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
);
725 /* ===========================================================================
726 * Functions implemented in proc.c
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
);
733 /* ===========================================================================
734 * Functions implemented in common.c/gigaset.h
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
);
746 /* Allocate and initialize driver structure. */
747 struct gigaset_driver
*gigaset_initdriver(unsigned minor
, unsigned minors
,
748 const char *procname
,
750 const char *devfsname
,
751 const struct gigaset_ops
*ops
,
752 struct module
*owner
);
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
);
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
);
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
);
771 /* Free card state. Calls hardware dependent gigaset_free[b]cs(). */
772 void gigaset_freecs(struct cardstate
*cs
);
774 /* Tell common.c that hardware and driver are ready. */
775 int gigaset_start(struct cardstate
*cs
);
777 /* Tell common.c that the device is not present any more. */
778 void gigaset_stop(struct cardstate
*cs
);
780 /* Tell common.c that the driver is being unloaded. */
781 void gigaset_shutdown(struct cardstate
*cs
);
783 /* Tell common.c that an skb has been sent. */
784 void gigaset_skb_sent(struct bc_state
*bcs
, struct sk_buff
*skb
);
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).
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
);
794 /* Called on CONFIG1 command from frontend. */
795 int gigaset_enterconfigmode(struct cardstate
*cs
); //0: success <0: errorcode
797 /* cs->lock must not be locked */
798 static inline void gigaset_schedule_event(struct cardstate
*cs
)
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
);
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
)
811 gigaset_add_event(bcs
->cs
, &bcs
->at_state
, EV_BC_CLOSED
, NULL
, 0, NULL
);
813 dbg(DEBUG_CMD
, "scheduling BC_CLOSED");
814 gigaset_schedule_event(bcs
->cs
);
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
)
821 gigaset_add_event(bcs
->cs
, &bcs
->at_state
, EV_BC_OPEN
, NULL
, 0, NULL
);
823 dbg(DEBUG_CMD
, "scheduling BC_OPEN");
824 gigaset_schedule_event(bcs
->cs
);
827 /* handling routines for sk_buff */
828 /* ============================= */
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.
837 static inline unsigned char *gigaset_skb_put_quick(struct sk_buff
*skb
,
840 unsigned char *tmp
= skb
->tail
;
841 /*SKB_LINEAR_ASSERT(skb);*/ /* not needed here */
847 /* pass received skb to LL
848 * Warning: skb must not be accessed anymore!
850 static inline void gigaset_rcv_skb(struct sk_buff
*skb
,
851 struct cardstate
*cs
,
852 struct bc_state
*bcs
)
854 cs
->iif
.rcvcallb_skb(cs
->myid
, bcs
->channel
, skb
);
858 /* handle reception of corrupted skb
859 * Warning: skb must not be accessed anymore!
861 static inline void gigaset_rcv_error(struct sk_buff
*procskb
,
862 struct cardstate
*cs
,
863 struct bc_state
*bcs
)
866 dev_kfree_skb(procskb
);
872 gigaset_isdn_rcv_err(bcs
);
877 /* bitwise byte inversion table */
878 extern __u8 gigaset_invtab
[]; /* in common.c */
881 /* append received bytes to inbuf */
882 static inline int gigaset_fill_inbuf(struct inbuf_t
*inbuf
,
883 const unsigned char *src
,
886 unsigned n
, head
, tail
, bytesleft
;
888 dbg(DEBUG_INTR
, "received %u bytes", numbytes
);
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
);
902 n
= (RBUFSIZE
-1) - tail
;
906 err("buffer overflow (%u bytes lost)", bytesleft
);
911 memcpy(inbuf
->data
+ tail
, src
, n
);
913 tail
= (tail
+ n
) % RBUFSIZE
;
916 dbg(DEBUG_INTR
, "setting tail to %u", tail
);
917 atomic_set(&inbuf
->tail
, tail
);
918 return numbytes
!= bytesleft
;
921 /* ===========================================================================
922 * Functions implemented in interface.c
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
);
931 void gigaset_if_init(struct cardstate
*cs
);
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
);