2 * Siemens Gigaset 307x driver
3 * Common header file for all connection variants
5 * Written by Stefan Eilers
6 * and Hansjoerg Lipp <hjlipp@web.de>
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 * =====================================================================
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>
35 #define GIG_VERSION {0,5,0,0}
36 #define GIG_COMPAT {0,4,0,0}
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 */
42 #define MAX_EVENTS 64 /* size of event queue */
45 #define SBUFSIZE 4096 /* sk_buff payload size */
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 */
50 /* compile time options */
53 #define GIG_MAYINITONDIAL
57 #define GIG_TICK 100 /* in milliseconds */
59 /* timeout values (unit: 1 sec) */
60 #define INIT_TIMEOUT 1
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 */
67 #define BAS_RETRY 3 /* max. retries for base USB ops */
71 extern int gigaset_debuglevel; /* "needs" cast to (enum debuglevel) */
73 /* debug flags, combine by adding/bitwise OR */
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
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
93 DEBUG_LOCKCMD = 0x200000, /* AT commands and responses when
96 DEBUG_ANY = 0x3fffff, /* print message if any of the others is
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.
110 #define err(format, arg...) printk(KERN_ERR KBUILD_MODNAME ": " \
111 format "\n" , ## arg)
112 #define info(format, arg...) printk(KERN_INFO KBUILD_MODNAME ": " \
113 format "\n" , ## arg)
114 #define warn(format, arg...) printk(KERN_WARNING KBUILD_MODNAME ": " \
115 format "\n" , ## arg)
117 #ifdef CONFIG_GIGASET_DEBUG
119 #define gig_dbg(level, format, arg...) \
121 if (unlikely(((enum debuglevel)gigaset_debuglevel) & (level))) \
122 printk(KERN_DEBUG KBUILD_MODNAME ": " format "\n", \
125 #define DEBUG_DEFAULT (DEBUG_TRANSCMD | DEBUG_CMD | DEBUG_USBREQ)
129 #define gig_dbg(level, format, arg...) do {} while (0)
130 #define DEBUG_DEFAULT 0
134 void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
135 size_t len, const unsigned char *buf);
137 /* connection state */
139 #define ZSAU_DISCONNECT_IND 4
140 #define ZSAU_OUTGOING_CALL_PROCEEDING 1
141 #define ZSAU_PROCEEDING 1
142 #define ZSAU_CALL_DELIVERED 2
143 #define ZSAU_ACTIVE 3
145 #define ZSAU_DISCONNECT_REQ 6
146 #define ZSAU_UNKNOWN -1
148 /* USB control transfer requests */
149 #define OUT_VENDOR_REQ (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT)
150 #define IN_VENDOR_REQ (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT)
152 /* int-in-events 3070 */
153 #define HD_B1_FLOW_CONTROL 0x80
154 #define HD_B2_FLOW_CONTROL 0x81
155 #define HD_RECEIVEATDATA_ACK (0x35) // 3070
156 // att: HD_RECEIVE>>AT<<DATA_ACK
157 #define HD_READY_SEND_ATDATA (0x36) // 3070
158 #define HD_OPEN_ATCHANNEL_ACK (0x37) // 3070
159 #define HD_CLOSE_ATCHANNEL_ACK (0x38) // 3070
160 #define HD_DEVICE_INIT_OK (0x11) // ISurf USB + 3070
161 #define HD_OPEN_B1CHANNEL_ACK (0x51) // ISurf USB + 3070
162 #define HD_OPEN_B2CHANNEL_ACK (0x52) // ISurf USB + 3070
163 #define HD_CLOSE_B1CHANNEL_ACK (0x53) // ISurf USB + 3070
164 #define HD_CLOSE_B2CHANNEL_ACK (0x54) // ISurf USB + 3070
166 #define HD_SUSPEND_END (0x61) // ISurf USB
168 #define HD_RESET_INTERRUPT_PIPE_ACK (0xFF) // ISurf USB + 3070
170 /* control requests 3070 */
171 #define HD_OPEN_B1CHANNEL (0x23) // ISurf USB + 3070
172 #define HD_CLOSE_B1CHANNEL (0x24) // ISurf USB + 3070
173 #define HD_OPEN_B2CHANNEL (0x25) // ISurf USB + 3070
174 #define HD_CLOSE_B2CHANNEL (0x26) // ISurf USB + 3070
175 #define HD_RESET_INTERRUPT_PIPE (0x27) // ISurf USB + 3070
176 #define HD_DEVICE_INIT_ACK (0x34) // ISurf USB + 3070
177 #define HD_WRITE_ATMESSAGE (0x12) // 3070
178 #define HD_READ_ATMESSAGE (0x13) // 3070
179 #define HD_OPEN_ATCHANNEL (0x28) // 3070
180 #define HD_CLOSE_ATCHANNEL (0x29) // 3070
182 /* number of B channels supported by base driver */
183 #define BAS_CHANNELS 2
185 /* USB frames for isochronous transfer */
186 #define BAS_FRAMETIME 1 /* number of milliseconds between frames */
187 #define BAS_NUMFRAMES 8 /* number of frames per URB */
188 #define BAS_MAXFRAME 16 /* allocated bytes per frame */
189 #define BAS_NORMFRAME 8 /* send size without flow control */
190 #define BAS_HIGHFRAME 10 /* " " with positive flow control */
191 #define BAS_LOWFRAME 5 /* " " with negative flow control */
192 #define BAS_CORRFRAMES 4 /* flow control multiplicator */
194 #define BAS_INBUFSIZE (BAS_MAXFRAME * BAS_NUMFRAMES)
195 /* size of isoc in buf per URB */
196 #define BAS_OUTBUFSIZE 4096 /* size of common isoc out buffer */
197 #define BAS_OUTBUFPAD BAS_MAXFRAME /* size of pad area for isoc out buf */
200 #define BAS_OUTURBS 3
202 /* variable commands in struct bc_state */
212 /* variables in struct at_state_t */
226 #define EV_TIMEOUT -105
227 #define EV_IF_VER -106
228 #define EV_PROC_CIDMODE -107
229 #define EV_SHUTDOWN -108
230 #define EV_START -110
232 #define EV_IF_LOCK -112
233 #define EV_PROTO_L2 -113
234 #define EV_ACCEPT -114
237 #define EV_BC_OPEN -117
238 #define EV_BC_CLOSED -118
241 #define INS_command 0x0001
242 #define INS_DLE_char 0x0002
243 #define INS_byte_stuff 0x0004
244 #define INS_have_data 0x0008
245 #define INS_skip_frame 0x0010
246 #define INS_DLE_command 0x0020
247 #define INS_flag_hunt 0x0040
250 #define CHS_D_UP 0x01
251 #define CHS_B_UP 0x02
252 #define CHS_NOTIFY_LL 0x04
254 #define ICALL_REJECT 0
255 #define ICALL_ACCEPT 1
256 #define ICALL_IGNORE 2
259 #define MS_UNINITIALIZED 0
262 #define MS_SHUTDOWN 3
274 #define SM_ISDN 1 /* default */
277 struct gigaset_driver;
279 struct usb_cardstate;
280 struct ser_cardstate;
281 struct bas_cardstate;
289 int resp_code; /* RSP_XXXX */
290 int min_ConState; /* <0 => ignore */
291 int max_ConState; /* <0 => ignore */
292 int parameter; /* e.g. ZSAU_XXXX <0: ignore*/
293 int new_ConState; /* <0 => ignore */
294 int timeout; /* >0 => *HZ; <=0 => TOUT_XXXX*/
295 int action[MAXACT]; /* ACT_XXXX */
296 char *command; /* NULL==none */
299 extern struct reply_t gigaset_tab_cid_m10x[];
300 extern struct reply_t gigaset_tab_nocid_m10x[];
303 unsigned char *rcvbuf; /* usb-gigaset receive buffer */
304 struct bc_state *bcs;
305 struct cardstate *cs;
308 unsigned char data[RBUFSIZE];
311 /* isochronous write buffer structure
312 * circular buffer with pad area for extraction of complete USB frames
313 * - data[read..nextread-1] is valid data already submitted to the USB subsystem
314 * - data[nextread..write-1] is valid data yet to be sent
315 * - data[write] is the next byte to write to
316 * - in byte-oriented L2 procotols, it is completely free
317 * - in bit-oriented L2 procotols, it may contain a partial byte of valid data
318 * - data[write+1..read-1] is free
319 * - wbits is the number of valid data bits in data[write], starting at the LSB
320 * - writesem is the semaphore for writing to the buffer:
321 * if writesem <= 0, data[write..read-1] is currently being written to
322 * - idle contains the byte value to repeat when the end of valid data is
323 * reached; if nextread==write (buffer contains no data to send), either the
324 * BAS_OUTBUFPAD bytes immediately before data[write] (if
325 * write>=BAS_OUTBUFPAD) or those of the pad area (if write<BAS_OUTBUFPAD)
326 * are also filled with that value
334 unsigned char data[BAS_OUTBUFSIZE + BAS_OUTBUFPAD];
338 /* isochronous write URB context structure
339 * data to be stored along with the URB and retrieved when it is returned
340 * as completed by the USB subsystem
341 * - urb: pointer to the URB itself
342 * - bcs: pointer to the B Channel control structure
343 * - limit: end of write buffer area covered by this URB
344 * - status: URB completion status
346 struct isow_urbctx_t {
348 struct bc_state *bcs;
353 /* AT state structure
354 * data associated with the state of an ISDN connection, whether or not
355 * it is currently assigned a B channel
358 struct list_head list;
361 unsigned timer_index;
362 unsigned long timer_expires;
364 unsigned int ConState; /* State of connection */
365 struct reply_t *replystruct;
367 int int_var[VAR_NUM]; /* see VAR_XXXX */
368 char *str_var[STR_NUM]; /* see STR_XXXX */
369 unsigned pending_commands; /* see PC_XXXX */
372 struct cardstate *cs;
373 struct bc_state *bcs;
377 unsigned char *response;
378 int resp_code; /* RSP_XXXX */
379 int type; /* RT_XXXX */
387 struct at_state_t *at_state;
390 /* This buffer holds all information about the used B-Channel */
392 struct sk_buff *tx_skb; /* Current transfer buffer to modem */
393 struct sk_buff_head squeue; /* B-Channel send Queue */
395 /* Variables for debugging .. */
396 int corrupted; /* Counter for corrupted packages */
397 int trans_down; /* Counter of packages (downstream) */
398 int trans_up; /* Counter of packages (upstream) */
400 struct at_state_t at_state;
401 unsigned long rcvbytes;
405 int inputstate; /* see INS_XXXX */
409 struct cardstate *cs;
411 unsigned chstate; /* bitmap (CHS_*) */
413 unsigned proto2; /* Layer 2 protocol (ISDN_PROTO_L2_*) */
414 char *commands[AT_NUM]; /* see AT_XXXX */
416 #ifdef CONFIG_GIGASET_DEBUG
422 /* private data of hardware drivers */
424 struct ser_bc_state *ser; /* serial hardware driver */
425 struct usb_bc_state *usb; /* usb hardware driver (m105) */
426 struct bas_bc_state *bas; /* usb hardware driver (base) */
431 struct gigaset_driver *driver;
432 unsigned minor_index;
434 struct device *tty_dev;
437 const struct gigaset_ops *ops;
439 /* Stuff to handle communication */
440 wait_queue_head_t waitqueue;
442 int mode; /* see M_XXXX */
443 int mstate; /* Modem state: see MS_XXXX */
444 /* only changed by the event layer */
448 struct bc_state *bcs; /* Array of struct bc_state */
450 int onechannel; /* data and commands transmitted in one
454 struct at_state_t at_state; /* at_state_t for cid == 0 */
455 struct list_head temp_at_states;/* list of temporary "struct
456 at_state_t"s without B channel */
458 struct inbuf_t *inbuf;
460 struct cmdbuf_t *cmdbuf, *lastcmdbuf;
462 unsigned curlen, cmdbytes;
465 struct tty_struct *tty;
466 struct tasklet_struct if_wake_tasklet;
467 unsigned control_state;
472 unsigned running; /* !=0 if events are handled */
473 unsigned connected; /* !=0 if hardware is connected */
474 unsigned isdn_up; /* !=0 after ISDN_STAT_RUN */
478 int myid; /* id for communication with LL */
481 struct reply_t *tabnocid;
482 struct reply_t *tabcid;
484 int ignoreframes; /* frames to ignore after setting up the
486 struct mutex mutex; /* locks this structure:
487 * connected is not changed,
488 * hardware_up is not changed,
489 * MState is not changed to or from
492 struct timer_list timer;
494 int dle; /* !=0 if modem commands/responses are
496 int cur_at_seq; /* sequence of AT commands being
498 int curchannel; /* channel those commands are meant
500 int commands_pending; /* flag(s) in xxx.commands_pending have
502 struct tasklet_struct event_tasklet;
503 /* tasklet for serializing AT commands.
505 * -> for modem reponses (and
506 * incoming data for M10x)
508 * -> after setting bits in
509 * xxx.at_state.pending_command
510 * (e.g. command from LL) */
511 struct tasklet_struct write_tasklet;
512 /* tasklet for serial output
513 * (not used in base driver) */
516 struct event_t events[MAX_EVENTS];
517 unsigned ev_tail, ev_head;
520 /* current modem response */
521 unsigned char respdata[MAX_RESP_SIZE];
524 /* private data of hardware drivers */
526 struct usb_cardstate *usb; /* USB hardware driver (m105) */
527 struct ser_cardstate *ser; /* serial hardware driver */
528 struct bas_cardstate *bas; /* USB hardware driver (base) */
532 struct gigaset_driver {
533 struct list_head list;
534 spinlock_t lock; /* locks minor tables and blocked */
535 struct tty_driver *tty;
539 struct cardstate *cs;
542 const struct gigaset_ops *ops;
543 struct module *owner;
547 struct cmdbuf_t *next, *prev;
549 struct tasklet_struct *wake_tasklet;
550 unsigned char buf[0];
553 struct bas_bc_state {
554 /* isochronous output state */
557 spinlock_t isooutlock;
558 struct isow_urbctx_t isoouturbs[BAS_OUTURBS];
559 struct isow_urbctx_t *isooutdone, *isooutfree, *isooutovfl;
560 struct isowbuf_t *isooutbuf;
561 unsigned numsub; /* submitted URB counter
562 (for diagnostic messages only) */
563 struct tasklet_struct sent_tasklet;
565 /* isochronous input state */
566 spinlock_t isoinlock;
567 struct urb *isoinurbs[BAS_INURBS];
568 unsigned char isoinbuf[BAS_INBUFSIZE * BAS_INURBS];
569 struct urb *isoindone; /* completed isoc read URB */
570 int isoinstatus; /* status of completed URB */
571 int loststatus; /* status of dropped URB */
572 unsigned isoinlost; /* number of bytes lost */
573 /* state of bit unstuffing algorithm
574 (in addition to BC_state.inputstate) */
575 unsigned seqlen; /* number of '1' bits not yet
577 unsigned inbyte, inbits; /* collected bits for next byte */
579 unsigned goodbytes; /* bytes correctly received */
580 unsigned alignerrs; /* frames with incomplete byte at end */
581 unsigned fcserrs; /* FCS errors */
582 unsigned frameerrs; /* framing errors */
583 unsigned giants; /* long frames */
584 unsigned runts; /* short frames */
585 unsigned aborts; /* HDLC aborts */
586 unsigned shared0s; /* '0' bits shared between flags */
587 unsigned stolen0s; /* '0' stuff bits also serving as
589 struct tasklet_struct rcvd_tasklet;
593 /* Called from ev-layer.c/interface.c for sending AT commands to the
595 int (*write_cmd)(struct cardstate *cs,
596 const unsigned char *buf, int len,
597 struct tasklet_struct *wake_tasklet);
599 /* Called from interface.c for additional device control */
600 int (*write_room)(struct cardstate *cs);
601 int (*chars_in_buffer)(struct cardstate *cs);
602 int (*brkchars)(struct cardstate *cs, const unsigned char buf[6]);
604 /* Called from ev-layer.c after setting up connection
605 * Should call gigaset_bchannel_up(), when finished. */
606 int (*init_bchannel)(struct bc_state *bcs);
608 /* Called from ev-layer.c after hanging up
609 * Should call gigaset_bchannel_down(), when finished. */
610 int (*close_bchannel)(struct bc_state *bcs);
612 /* Called by gigaset_initcs() for setting up bcs->hw.xxx */
613 int (*initbcshw)(struct bc_state *bcs);
615 /* Called by gigaset_freecs() for freeing bcs->hw.xxx */
616 int (*freebcshw)(struct bc_state *bcs);
618 /* Called by gigaset_bchannel_down() for resetting bcs->hw.xxx */
619 void (*reinitbcshw)(struct bc_state *bcs);
621 /* Called by gigaset_initcs() for setting up cs->hw.xxx */
622 int (*initcshw)(struct cardstate *cs);
624 /* Called by gigaset_freecs() for freeing cs->hw.xxx */
625 void (*freecshw)(struct cardstate *cs);
627 /* Called from common.c/interface.c for additional serial port
629 int (*set_modem_ctrl)(struct cardstate *cs, unsigned old_state,
631 int (*baud_rate)(struct cardstate *cs, unsigned cflag);
632 int (*set_line_ctrl)(struct cardstate *cs, unsigned cflag);
634 /* Called from i4l.c to put an skb into the send-queue. */
635 int (*send_skb)(struct bc_state *bcs, struct sk_buff *skb);
637 /* Called from ev-layer.c to process a block of data
638 * received through the common/control channel. */
639 void (*handle_input)(struct inbuf_t *inbuf);
643 /* = Common structures and definitions ======================================= */
645 /* Parser states for DLE-Event:
646 * <DLE-EVENT>: <DLE_FLAG> "X" <EVENT> <DLE_FLAG> "."
648 * <EVENT>: ((a-z)* | (A-Z)* | (0-10)*)+
650 #define DLE_FLAG 0x10
652 /* ===========================================================================
653 * Functions implemented in asyncdata.c
656 /* Called from i4l.c to put an skb into the send-queue.
657 * After sending gigaset_skb_sent() should be called. */
658 int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb);
660 /* Called from ev-layer.c to process a block of data
661 * received through the common/control channel. */
662 void gigaset_m10x_input(struct inbuf_t *inbuf);
664 /* ===========================================================================
665 * Functions implemented in isocdata.c
668 /* Called from i4l.c to put an skb into the send-queue.
669 * After sending gigaset_skb_sent() should be called. */
670 int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb);
672 /* Called from ev-layer.c to process a block of data
673 * received through the common/control channel. */
674 void gigaset_isoc_input(struct inbuf_t *inbuf);
676 /* Called from bas-gigaset.c to process a block of data
677 * received through the isochronous channel */
678 void gigaset_isoc_receive(unsigned char *src, unsigned count,
679 struct bc_state *bcs);
681 /* Called from bas-gigaset.c to put a block of data
682 * into the isochronous output buffer */
683 int gigaset_isoc_buildframe(struct bc_state *bcs, unsigned char *in, int len);
685 /* Called from bas-gigaset.c to initialize the isochronous output buffer */
686 void gigaset_isowbuf_init(struct isowbuf_t *iwb, unsigned char idle);
688 /* Called from bas-gigaset.c to retrieve a block of bytes for sending */
689 int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size);
691 /* ===========================================================================
692 * Functions implemented in i4l.c/gigaset.h
695 /* Called by gigaset_initcs() for setting up with the isdn4linux subsystem */
696 int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid);
698 /* Called from xxx-gigaset.c to indicate completion of sending an skb */
699 void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
701 /* Called from common.c/ev-layer.c to indicate events relevant to the LL */
702 int gigaset_isdn_icall(struct at_state_t *at_state);
703 int gigaset_isdn_setup_accept(struct at_state_t *at_state);
704 int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data);
706 void gigaset_i4l_cmd(struct cardstate *cs, int cmd);
707 void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd);
710 static inline void gigaset_isdn_rcv_err(struct bc_state *bcs)
715 gig_dbg(DEBUG_CMD, "sending L1ERR");
716 response.driver = bcs->cs->myid;
717 response.command = ISDN_STAT_L1ERR;
718 response.arg = bcs->channel;
719 response.parm.errcode = ISDN_STAT_L1ERR_RECV;
720 bcs->cs->iif.statcallb(&response);
723 /* ===========================================================================
724 * Functions implemented in ev-layer.c
727 /* tasklet called from common.c to process queued events */
728 void gigaset_handle_event(unsigned long data);
730 /* called from isocdata.c / asyncdata.c
731 * when a complete modem response line has been received */
732 void gigaset_handle_modem_response(struct cardstate *cs);
734 /* ===========================================================================
735 * Functions implemented in proc.c
738 /* initialize sysfs for device */
739 void gigaset_init_dev_sysfs(struct cardstate *cs);
740 void gigaset_free_dev_sysfs(struct cardstate *cs);
742 /* ===========================================================================
743 * Functions implemented in common.c/gigaset.h
746 void gigaset_bcs_reinit(struct bc_state *bcs);
747 void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
748 struct cardstate *cs, int cid);
749 int gigaset_get_channel(struct bc_state *bcs);
750 void gigaset_free_channel(struct bc_state *bcs);
751 int gigaset_get_channels(struct cardstate *cs);
752 void gigaset_free_channels(struct cardstate *cs);
753 void gigaset_block_channels(struct cardstate *cs);
755 /* Allocate and initialize driver structure. */
756 struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
757 const char *procname,
759 const struct gigaset_ops *ops,
760 struct module *owner);
762 /* Deallocate driver structure. */
763 void gigaset_freedriver(struct gigaset_driver *drv);
764 void gigaset_debugdrivers(void);
765 struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty);
766 struct cardstate *gigaset_get_cs_by_id(int id);
767 void gigaset_blockdriver(struct gigaset_driver *drv);
769 /* Allocate and initialize card state. Calls hardware dependent
770 gigaset_init[b]cs(). */
771 struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
772 int onechannel, int ignoreframes,
773 int cidmode, const char *modulename);
775 /* Free card state. Calls hardware dependent gigaset_free[b]cs(). */
776 void gigaset_freecs(struct cardstate *cs);
778 /* Tell common.c that hardware and driver are ready. */
779 int gigaset_start(struct cardstate *cs);
781 /* Tell common.c that the device is not present any more. */
782 void gigaset_stop(struct cardstate *cs);
784 /* Tell common.c that the driver is being unloaded. */
785 int gigaset_shutdown(struct cardstate *cs);
787 /* Tell common.c that an skb has been sent. */
788 void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
790 /* Append event to the queue.
791 * Returns NULL on failure or a pointer to the event on success.
792 * ptr must be kmalloc()ed (and not be freed by the caller).
794 struct event_t *gigaset_add_event(struct cardstate *cs,
795 struct at_state_t *at_state, int type,
796 void *ptr, int parameter, void *arg);
798 /* Called on CONFIG1 command from frontend. */
799 int gigaset_enterconfigmode(struct cardstate *cs); //0: success <0: errorcode
801 /* cs->lock must not be locked */
802 static inline void gigaset_schedule_event(struct cardstate *cs)
805 spin_lock_irqsave(&cs->lock, flags);
807 tasklet_schedule(&cs->event_tasklet);
808 spin_unlock_irqrestore(&cs->lock, flags);
811 /* Tell common.c that B channel has been closed. */
812 /* cs->lock must not be locked */
813 static inline void gigaset_bchannel_down(struct bc_state *bcs)
815 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_CLOSED, NULL, 0, NULL);
817 gig_dbg(DEBUG_CMD, "scheduling BC_CLOSED");
818 gigaset_schedule_event(bcs->cs);
821 /* Tell common.c that B channel has been opened. */
822 /* cs->lock must not be locked */
823 static inline void gigaset_bchannel_up(struct bc_state *bcs)
825 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_OPEN, NULL, 0, NULL);
827 gig_dbg(DEBUG_CMD, "scheduling BC_OPEN");
828 gigaset_schedule_event(bcs->cs);
831 /* handling routines for sk_buff */
832 /* ============================= */
834 /* pass received skb to LL
835 * Warning: skb must not be accessed anymore!
837 static inline void gigaset_rcv_skb(struct sk_buff *skb,
838 struct cardstate *cs,
839 struct bc_state *bcs)
841 cs->iif.rcvcallb_skb(cs->myid, bcs->channel, skb);
845 /* handle reception of corrupted skb
846 * Warning: skb must not be accessed anymore!
848 static inline void gigaset_rcv_error(struct sk_buff *procskb,
849 struct cardstate *cs,
850 struct bc_state *bcs)
853 dev_kfree_skb(procskb);
859 gigaset_isdn_rcv_err(bcs);
863 /* append received bytes to inbuf */
864 int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
867 /* ===========================================================================
868 * Functions implemented in interface.c
871 /* initialize interface */
872 void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
873 const char *devname);
874 /* release interface */
875 void gigaset_if_freedriver(struct gigaset_driver *drv);
877 void gigaset_if_init(struct cardstate *cs);
879 void gigaset_if_free(struct cardstate *cs);
880 /* device received data */
881 void gigaset_if_receive(struct cardstate *cs,
882 unsigned char *buffer, size_t len);