blob: a2f6125739eb23f4ad14478391ed987a5f5136d8 [file] [log] [blame]
Tilman Schmidt917f5082006-04-10 22:55:00 -07001/*
2 * Siemens Gigaset 307x driver
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -08003 * Common header file for all connection variants
4 *
Tilman Schmidt70440cf2006-04-10 22:55:14 -07005 * Written by Stefan Eilers
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -08006 * and Hansjoerg Lipp <hjlipp@web.de>
7 *
Tilman Schmidt917f5082006-04-10 22:55:00 -07008 * =====================================================================
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 * =====================================================================
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080014 */
15
16#ifndef GIGASET_H
17#define GIGASET_H
18
Tilman Schmidtc8770dc2008-12-26 01:21:29 -080019/* define global prefix for pr_ macros in linux/kernel.h */
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080022#include <linux/kernel.h>
23#include <linux/compiler.h>
24#include <linux/types.h>
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080025#include <linux/spinlock.h>
26#include <linux/isdnif.h>
27#include <linux/usb.h>
28#include <linux/skbuff.h>
29#include <linux/netdevice.h>
30#include <linux/ppp_defs.h>
31#include <linux/timer.h>
32#include <linux/interrupt.h>
33#include <linux/tty.h>
34#include <linux/tty_driver.h>
35#include <linux/list.h>
Tilman Schmidt917f5082006-04-10 22:55:00 -070036#include <asm/atomic.h>
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080037
38#define GIG_VERSION {0,5,0,0}
39#define GIG_COMPAT {0,4,0,0}
40
Tilman Schmidt917f5082006-04-10 22:55:00 -070041#define MAX_REC_PARAMS 10 /* Max. number of params in response string */
42#define MAX_RESP_SIZE 512 /* Max. size of a response string */
43#define HW_HDR_LEN 2 /* Header size used to store ack info */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080044
Tilman Schmidt917f5082006-04-10 22:55:00 -070045#define MAX_EVENTS 64 /* size of event queue */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080046
47#define RBUFSIZE 8192
Tilman Schmidt917f5082006-04-10 22:55:00 -070048#define SBUFSIZE 4096 /* sk_buff payload size */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080049
Tilman Schmidt917f5082006-04-10 22:55:00 -070050#define TRANSBUFSIZE 768 /* bytes per skb for transparent receive */
51#define MAX_BUF_SIZE (SBUFSIZE - 2) /* Max. size of a data packet from LL */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080052
53/* compile time options */
54#define GIG_MAJOR 0
55
56#define GIG_MAYINITONDIAL
57#define GIG_RETRYCID
58#define GIG_X75
59
Tilman Schmidtec81b5e2006-04-10 22:55:03 -070060#define GIG_TICK 100 /* in milliseconds */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080061
62/* timeout values (unit: 1 sec) */
63#define INIT_TIMEOUT 1
64
65/* timeout values (unit: 0.1 sec) */
66#define RING_TIMEOUT 3 /* for additional parameters to RING */
67#define BAS_TIMEOUT 20 /* for response to Base USB ops */
68#define ATRDY_TIMEOUT 3 /* for HD_READY_SEND_ATDATA */
69
70#define BAS_RETRY 3 /* max. retries for base USB ops */
71
72#define MAXACT 3
73
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080074extern int gigaset_debuglevel; /* "needs" cast to (enum debuglevel) */
75
Tilman Schmidtc652cbd2008-02-06 01:38:24 -080076/* debug flags, combine by adding/bitwise OR */
Tilman Schmidt73a88812006-04-22 02:35:30 -070077enum debuglevel {
Tilman Schmidtc652cbd2008-02-06 01:38:24 -080078 DEBUG_INTR = 0x00008, /* interrupt processing */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080079 DEBUG_CMD = 0x00020, /* sent/received LL commands */
80 DEBUG_STREAM = 0x00040, /* application data stream I/O events */
81 DEBUG_STREAM_DUMP = 0x00080, /* application data stream content */
82 DEBUG_LLDATA = 0x00100, /* sent/received LL data */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080083 DEBUG_DRIVER = 0x00400, /* driver structure */
84 DEBUG_HDLC = 0x00800, /* M10x HDLC processing */
85 DEBUG_WRITE = 0x01000, /* M105 data write */
Tilman Schmidt784d5852006-04-10 22:55:04 -070086 DEBUG_TRANSCMD = 0x02000, /* AT-COMMANDS+RESPONSES */
87 DEBUG_MCMD = 0x04000, /* COMMANDS THAT ARE SENT VERY OFTEN */
Tilman Schmidt917f5082006-04-10 22:55:00 -070088 DEBUG_INIT = 0x08000, /* (de)allocation+initialization of data
89 structures */
Tilman Schmidtc652cbd2008-02-06 01:38:24 -080090 DEBUG_SUSPEND = 0x10000, /* suspend/resume processing */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080091 DEBUG_OUTPUT = 0x20000, /* output to device */
Tilman Schmidt784d5852006-04-10 22:55:04 -070092 DEBUG_ISO = 0x40000, /* isochronous transfers */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080093 DEBUG_IF = 0x80000, /* character device operations */
Tilman Schmidt917f5082006-04-10 22:55:00 -070094 DEBUG_USBREQ = 0x100000, /* USB communication (except payload
95 data) */
Tilman Schmidt784d5852006-04-10 22:55:04 -070096 DEBUG_LOCKCMD = 0x200000, /* AT commands and responses when
Tilman Schmidt917f5082006-04-10 22:55:00 -070097 MS_LOCKED */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080098
Tilman Schmidt917f5082006-04-10 22:55:00 -070099 DEBUG_ANY = 0x3fffff, /* print message if any of the others is
100 activated */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800101};
102
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800103#ifdef CONFIG_GIGASET_DEBUG
Tilman Schmidt784d5852006-04-10 22:55:04 -0700104
105#define gig_dbg(level, format, arg...) \
Tilman Schmidt917f5082006-04-10 22:55:00 -0700106 do { \
107 if (unlikely(((enum debuglevel)gigaset_debuglevel) & (level))) \
Tilman Schmidt784d5852006-04-10 22:55:04 -0700108 printk(KERN_DEBUG KBUILD_MODNAME ": " format "\n", \
109 ## arg); \
Tilman Schmidt917f5082006-04-10 22:55:00 -0700110 } while (0)
Tilman Schmidt73a88812006-04-22 02:35:30 -0700111#define DEBUG_DEFAULT (DEBUG_TRANSCMD | DEBUG_CMD | DEBUG_USBREQ)
Tilman Schmidt784d5852006-04-10 22:55:04 -0700112
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800113#else
Tilman Schmidt784d5852006-04-10 22:55:04 -0700114
115#define gig_dbg(level, format, arg...) do {} while (0)
116#define DEBUG_DEFAULT 0
117
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800118#endif
119
120void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
Tilman Schmidt01371502006-04-10 22:55:11 -0700121 size_t len, const unsigned char *buf);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800122
123/* connection state */
124#define ZSAU_NONE 0
125#define ZSAU_DISCONNECT_IND 4
126#define ZSAU_OUTGOING_CALL_PROCEEDING 1
127#define ZSAU_PROCEEDING 1
128#define ZSAU_CALL_DELIVERED 2
129#define ZSAU_ACTIVE 3
130#define ZSAU_NULL 5
131#define ZSAU_DISCONNECT_REQ 6
132#define ZSAU_UNKNOWN -1
133
134/* USB control transfer requests */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700135#define OUT_VENDOR_REQ (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT)
136#define IN_VENDOR_REQ (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT)
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800137
138/* int-in-events 3070 */
139#define HD_B1_FLOW_CONTROL 0x80
140#define HD_B2_FLOW_CONTROL 0x81
Tilman Schmidt917f5082006-04-10 22:55:00 -0700141#define HD_RECEIVEATDATA_ACK (0x35) // 3070
142 // att: HD_RECEIVE>>AT<<DATA_ACK
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800143#define HD_READY_SEND_ATDATA (0x36) // 3070
144#define HD_OPEN_ATCHANNEL_ACK (0x37) // 3070
145#define HD_CLOSE_ATCHANNEL_ACK (0x38) // 3070
146#define HD_DEVICE_INIT_OK (0x11) // ISurf USB + 3070
147#define HD_OPEN_B1CHANNEL_ACK (0x51) // ISurf USB + 3070
148#define HD_OPEN_B2CHANNEL_ACK (0x52) // ISurf USB + 3070
149#define HD_CLOSE_B1CHANNEL_ACK (0x53) // ISurf USB + 3070
150#define HD_CLOSE_B2CHANNEL_ACK (0x54) // ISurf USB + 3070
151// Powermangment
152#define HD_SUSPEND_END (0x61) // ISurf USB
153// Configuration
154#define HD_RESET_INTERRUPT_PIPE_ACK (0xFF) // ISurf USB + 3070
155
156/* control requests 3070 */
157#define HD_OPEN_B1CHANNEL (0x23) // ISurf USB + 3070
158#define HD_CLOSE_B1CHANNEL (0x24) // ISurf USB + 3070
159#define HD_OPEN_B2CHANNEL (0x25) // ISurf USB + 3070
160#define HD_CLOSE_B2CHANNEL (0x26) // ISurf USB + 3070
161#define HD_RESET_INTERRUPT_PIPE (0x27) // ISurf USB + 3070
162#define HD_DEVICE_INIT_ACK (0x34) // ISurf USB + 3070
163#define HD_WRITE_ATMESSAGE (0x12) // 3070
164#define HD_READ_ATMESSAGE (0x13) // 3070
165#define HD_OPEN_ATCHANNEL (0x28) // 3070
166#define HD_CLOSE_ATCHANNEL (0x29) // 3070
167
Tilman Schmidtc652cbd2008-02-06 01:38:24 -0800168/* number of B channels supported by base driver */
169#define BAS_CHANNELS 2
170
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800171/* USB frames for isochronous transfer */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700172#define BAS_FRAMETIME 1 /* number of milliseconds between frames */
173#define BAS_NUMFRAMES 8 /* number of frames per URB */
174#define BAS_MAXFRAME 16 /* allocated bytes per frame */
175#define BAS_NORMFRAME 8 /* send size without flow control */
176#define BAS_HIGHFRAME 10 /* " " with positive flow control */
177#define BAS_LOWFRAME 5 /* " " with negative flow control */
178#define BAS_CORRFRAMES 4 /* flow control multiplicator */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800179
Tilman Schmidt917f5082006-04-10 22:55:00 -0700180#define BAS_INBUFSIZE (BAS_MAXFRAME * BAS_NUMFRAMES)
181 /* size of isoc in buf per URB */
182#define BAS_OUTBUFSIZE 4096 /* size of common isoc out buffer */
183#define BAS_OUTBUFPAD BAS_MAXFRAME /* size of pad area for isoc out buf */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800184
185#define BAS_INURBS 3
186#define BAS_OUTURBS 3
187
188/* variable commands in struct bc_state */
189#define AT_ISO 0
190#define AT_DIAL 1
191#define AT_MSN 2
192#define AT_BC 3
193#define AT_PROTO 4
194#define AT_TYPE 5
195#define AT_HLC 6
196#define AT_NUM 7
197
198/* variables in struct at_state_t */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700199#define VAR_ZSAU 0
200#define VAR_ZDLE 1
201#define VAR_ZVLS 2
202#define VAR_ZCTP 3
203#define VAR_NUM 4
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800204
Tilman Schmidt917f5082006-04-10 22:55:00 -0700205#define STR_NMBR 0
206#define STR_ZCPN 1
207#define STR_ZCON 2
208#define STR_ZBC 3
209#define STR_ZHLC 4
210#define STR_NUM 5
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800211
Tilman Schmidt917f5082006-04-10 22:55:00 -0700212#define EV_TIMEOUT -105
213#define EV_IF_VER -106
214#define EV_PROC_CIDMODE -107
215#define EV_SHUTDOWN -108
216#define EV_START -110
217#define EV_STOP -111
218#define EV_IF_LOCK -112
219#define EV_PROTO_L2 -113
220#define EV_ACCEPT -114
221#define EV_DIAL -115
222#define EV_HUP -116
223#define EV_BC_OPEN -117
224#define EV_BC_CLOSED -118
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800225
226/* input state */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700227#define INS_command 0x0001
228#define INS_DLE_char 0x0002
229#define INS_byte_stuff 0x0004
230#define INS_have_data 0x0008
231#define INS_skip_frame 0x0010
232#define INS_DLE_command 0x0020
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800233#define INS_flag_hunt 0x0040
234
235/* channel state */
236#define CHS_D_UP 0x01
237#define CHS_B_UP 0x02
238#define CHS_NOTIFY_LL 0x04
239
Tilman Schmidt917f5082006-04-10 22:55:00 -0700240#define ICALL_REJECT 0
241#define ICALL_ACCEPT 1
242#define ICALL_IGNORE 2
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800243
244/* device state */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700245#define MS_UNINITIALIZED 0
246#define MS_INIT 1
247#define MS_LOCKED 2
248#define MS_SHUTDOWN 3
249#define MS_RECOVER 4
250#define MS_READY 5
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800251
252/* mode */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700253#define M_UNKNOWN 0
254#define M_CONFIG 1
255#define M_UNIMODEM 2
256#define M_CID 3
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800257
258/* start mode */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700259#define SM_LOCKED 0
260#define SM_ISDN 1 /* default */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800261
262struct gigaset_ops;
263struct gigaset_driver;
264
265struct usb_cardstate;
266struct ser_cardstate;
267struct bas_cardstate;
268
269struct bc_state;
270struct usb_bc_state;
271struct ser_bc_state;
272struct bas_bc_state;
273
274struct reply_t {
Tilman Schmidt917f5082006-04-10 22:55:00 -0700275 int resp_code; /* RSP_XXXX */
276 int min_ConState; /* <0 => ignore */
277 int max_ConState; /* <0 => ignore */
278 int parameter; /* e.g. ZSAU_XXXX <0: ignore*/
279 int new_ConState; /* <0 => ignore */
280 int timeout; /* >0 => *HZ; <=0 => TOUT_XXXX*/
281 int action[MAXACT]; /* ACT_XXXX */
282 char *command; /* NULL==none */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800283};
284
Tilman Schmidt528efc62009-05-13 12:44:17 +0000285extern struct reply_t gigaset_tab_cid[];
286extern struct reply_t gigaset_tab_nocid[];
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800287
288struct inbuf_t {
Tilman Schmidt917f5082006-04-10 22:55:00 -0700289 unsigned char *rcvbuf; /* usb-gigaset receive buffer */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800290 struct bc_state *bcs;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700291 struct cardstate *cs;
292 int inputstate;
Tilman Schmidt9d4bee22008-02-06 01:38:28 -0800293 int head, tail;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700294 unsigned char data[RBUFSIZE];
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800295};
296
297/* isochronous write buffer structure
298 * circular buffer with pad area for extraction of complete USB frames
299 * - data[read..nextread-1] is valid data already submitted to the USB subsystem
300 * - data[nextread..write-1] is valid data yet to be sent
301 * - data[write] is the next byte to write to
302 * - in byte-oriented L2 procotols, it is completely free
303 * - in bit-oriented L2 procotols, it may contain a partial byte of valid data
304 * - data[write+1..read-1] is free
305 * - wbits is the number of valid data bits in data[write], starting at the LSB
306 * - writesem is the semaphore for writing to the buffer:
307 * if writesem <= 0, data[write..read-1] is currently being written to
308 * - idle contains the byte value to repeat when the end of valid data is
309 * reached; if nextread==write (buffer contains no data to send), either the
Tilman Schmidt917f5082006-04-10 22:55:00 -0700310 * BAS_OUTBUFPAD bytes immediately before data[write] (if
311 * write>=BAS_OUTBUFPAD) or those of the pad area (if write<BAS_OUTBUFPAD)
312 * are also filled with that value
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800313 */
314struct isowbuf_t {
Tilman Schmidt9d4bee22008-02-06 01:38:28 -0800315 int read;
316 int nextread;
317 int write;
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800318 atomic_t writesem;
319 int wbits;
320 unsigned char data[BAS_OUTBUFSIZE + BAS_OUTBUFPAD];
321 unsigned char idle;
322};
323
324/* isochronous write URB context structure
325 * data to be stored along with the URB and retrieved when it is returned
326 * as completed by the USB subsystem
327 * - urb: pointer to the URB itself
328 * - bcs: pointer to the B Channel control structure
329 * - limit: end of write buffer area covered by this URB
Tilman Schmidtdbd98232008-02-06 01:38:23 -0800330 * - status: URB completion status
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800331 */
332struct isow_urbctx_t {
333 struct urb *urb;
334 struct bc_state *bcs;
335 int limit;
Tilman Schmidtdbd98232008-02-06 01:38:23 -0800336 int status;
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800337};
338
339/* AT state structure
340 * data associated with the state of an ISDN connection, whether or not
341 * it is currently assigned a B channel
342 */
343struct at_state_t {
Tilman Schmidt917f5082006-04-10 22:55:00 -0700344 struct list_head list;
345 int waiting;
346 int getstring;
Tilman Schmidt69049cc2006-04-10 22:55:16 -0700347 unsigned timer_index;
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800348 unsigned long timer_expires;
349 int timer_active;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700350 unsigned int ConState; /* State of connection */
351 struct reply_t *replystruct;
352 int cid;
353 int int_var[VAR_NUM]; /* see VAR_XXXX */
354 char *str_var[STR_NUM]; /* see STR_XXXX */
355 unsigned pending_commands; /* see PC_XXXX */
Tilman Schmidt69049cc2006-04-10 22:55:16 -0700356 unsigned seq_index;
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800357
Tilman Schmidt917f5082006-04-10 22:55:00 -0700358 struct cardstate *cs;
359 struct bc_state *bcs;
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800360};
361
362struct resp_type_t {
363 unsigned char *response;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700364 int resp_code; /* RSP_XXXX */
365 int type; /* RT_XXXX */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800366};
367
368struct event_t {
369 int type;
370 void *ptr, *arg;
371 int parameter;
372 int cid;
373 struct at_state_t *at_state;
374};
375
376/* This buffer holds all information about the used B-Channel */
377struct bc_state {
Tilman Schmidt917f5082006-04-10 22:55:00 -0700378 struct sk_buff *tx_skb; /* Current transfer buffer to modem */
379 struct sk_buff_head squeue; /* B-Channel send Queue */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800380
381 /* Variables for debugging .. */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700382 int corrupted; /* Counter for corrupted packages */
383 int trans_down; /* Counter of packages (downstream) */
384 int trans_up; /* Counter of packages (upstream) */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800385
386 struct at_state_t at_state;
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800387
388 __u16 fcs;
389 struct sk_buff *skb;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700390 int inputstate; /* see INS_XXXX */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800391
392 int channel;
393
394 struct cardstate *cs;
395
Tilman Schmidt917f5082006-04-10 22:55:00 -0700396 unsigned chstate; /* bitmap (CHS_*) */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800397 int ignore;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700398 unsigned proto2; /* Layer 2 protocol (ISDN_PROTO_L2_*) */
399 char *commands[AT_NUM]; /* see AT_XXXX */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800400
401#ifdef CONFIG_GIGASET_DEBUG
402 int emptycount;
403#endif
404 int busy;
405 int use_count;
406
Tilman Schmidt784d5852006-04-10 22:55:04 -0700407 /* private data of hardware drivers */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800408 union {
Tilman Schmidt917f5082006-04-10 22:55:00 -0700409 struct ser_bc_state *ser; /* serial hardware driver */
410 struct usb_bc_state *usb; /* usb hardware driver (m105) */
411 struct bas_bc_state *bas; /* usb hardware driver (base) */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800412 } hw;
413};
414
415struct cardstate {
416 struct gigaset_driver *driver;
417 unsigned minor_index;
Tilman Schmidt784d5852006-04-10 22:55:04 -0700418 struct device *dev;
Greg Kroah-Hartman01107d32006-08-07 22:19:37 -0700419 struct device *tty_dev;
Tilman Schmidte468c042008-02-06 01:38:29 -0800420 unsigned flags;
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800421
422 const struct gigaset_ops *ops;
423
424 /* Stuff to handle communication */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800425 wait_queue_head_t waitqueue;
426 int waiting;
Tilman Schmidt9d4bee22008-02-06 01:38:28 -0800427 int mode; /* see M_XXXX */
428 int mstate; /* Modem state: see MS_XXXX */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700429 /* only changed by the event layer */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800430 int cmd_result;
431
432 int channels;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700433 struct bc_state *bcs; /* Array of struct bc_state */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800434
Tilman Schmidt917f5082006-04-10 22:55:00 -0700435 int onechannel; /* data and commands transmitted in one
436 stream (M10x) */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800437
438 spinlock_t lock;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700439 struct at_state_t at_state; /* at_state_t for cid == 0 */
440 struct list_head temp_at_states;/* list of temporary "struct
441 at_state_t"s without B channel */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800442
443 struct inbuf_t *inbuf;
444
445 struct cmdbuf_t *cmdbuf, *lastcmdbuf;
446 spinlock_t cmdlock;
447 unsigned curlen, cmdbytes;
448
449 unsigned open_count;
450 struct tty_struct *tty;
451 struct tasklet_struct if_wake_tasklet;
452 unsigned control_state;
453
454 unsigned fwver[4];
455 int gotfwver;
456
Tilman Schmidt69049cc2006-04-10 22:55:16 -0700457 unsigned running; /* !=0 if events are handled */
458 unsigned connected; /* !=0 if hardware is connected */
459 unsigned isdn_up; /* !=0 after ISDN_STAT_RUN */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800460
Tilman Schmidt69049cc2006-04-10 22:55:16 -0700461 unsigned cidmode;
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800462
Tilman Schmidt917f5082006-04-10 22:55:00 -0700463 int myid; /* id for communication with LL */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800464 isdn_if iif;
465
466 struct reply_t *tabnocid;
467 struct reply_t *tabcid;
468 int cs_init;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700469 int ignoreframes; /* frames to ignore after setting up the
470 B channel */
Tilman Schmidtabfd1dc2006-04-10 22:55:12 -0700471 struct mutex mutex; /* locks this structure:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700472 * connected is not changed,
473 * hardware_up is not changed,
474 * MState is not changed to or from
475 * MS_LOCKED */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800476
477 struct timer_list timer;
478 int retry_count;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700479 int dle; /* !=0 if modem commands/responses are
480 dle encoded */
481 int cur_at_seq; /* sequence of AT commands being
482 processed */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700483 int curchannel; /* channel those commands are meant
Tilman Schmidt917f5082006-04-10 22:55:00 -0700484 for */
Tilman Schmidt9d4bee22008-02-06 01:38:28 -0800485 int commands_pending; /* flag(s) in xxx.commands_pending have
Tilman Schmidt917f5082006-04-10 22:55:00 -0700486 been set */
487 struct tasklet_struct event_tasklet;
488 /* tasklet for serializing AT commands.
489 * Scheduled
490 * -> for modem reponses (and
Tilman Schmidt784d5852006-04-10 22:55:04 -0700491 * incoming data for M10x)
Tilman Schmidt917f5082006-04-10 22:55:00 -0700492 * -> on timeout
493 * -> after setting bits in
494 * xxx.at_state.pending_command
495 * (e.g. command from LL) */
496 struct tasklet_struct write_tasklet;
497 /* tasklet for serial output
498 * (not used in base driver) */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800499
500 /* event queue */
501 struct event_t events[MAX_EVENTS];
Tilman Schmidt69049cc2006-04-10 22:55:16 -0700502 unsigned ev_tail, ev_head;
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800503 spinlock_t ev_lock;
504
505 /* current modem response */
506 unsigned char respdata[MAX_RESP_SIZE];
507 unsigned cbytes;
508
Tilman Schmidt784d5852006-04-10 22:55:04 -0700509 /* private data of hardware drivers */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800510 union {
Tilman Schmidt917f5082006-04-10 22:55:00 -0700511 struct usb_cardstate *usb; /* USB hardware driver (m105) */
512 struct ser_cardstate *ser; /* serial hardware driver */
513 struct bas_cardstate *bas; /* USB hardware driver (base) */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800514 } hw;
515};
516
517struct gigaset_driver {
518 struct list_head list;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700519 spinlock_t lock; /* locks minor tables and blocked */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800520 struct tty_driver *tty;
521 unsigned have_tty;
522 unsigned minor;
523 unsigned minors;
524 struct cardstate *cs;
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800525 int blocked;
526
527 const struct gigaset_ops *ops;
528 struct module *owner;
529};
530
531struct cmdbuf_t {
532 struct cmdbuf_t *next, *prev;
533 int len, offset;
534 struct tasklet_struct *wake_tasklet;
535 unsigned char buf[0];
536};
537
538struct bas_bc_state {
539 /* isochronous output state */
Tilman Schmidt9d4bee22008-02-06 01:38:28 -0800540 int running;
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800541 atomic_t corrbytes;
542 spinlock_t isooutlock;
543 struct isow_urbctx_t isoouturbs[BAS_OUTURBS];
544 struct isow_urbctx_t *isooutdone, *isooutfree, *isooutovfl;
545 struct isowbuf_t *isooutbuf;
Tilman Schmidt784d5852006-04-10 22:55:04 -0700546 unsigned numsub; /* submitted URB counter
547 (for diagnostic messages only) */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800548 struct tasklet_struct sent_tasklet;
549
550 /* isochronous input state */
551 spinlock_t isoinlock;
552 struct urb *isoinurbs[BAS_INURBS];
553 unsigned char isoinbuf[BAS_INBUFSIZE * BAS_INURBS];
Tilman Schmidt784d5852006-04-10 22:55:04 -0700554 struct urb *isoindone; /* completed isoc read URB */
Tilman Schmidtdbd98232008-02-06 01:38:23 -0800555 int isoinstatus; /* status of completed URB */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700556 int loststatus; /* status of dropped URB */
557 unsigned isoinlost; /* number of bytes lost */
558 /* state of bit unstuffing algorithm
559 (in addition to BC_state.inputstate) */
560 unsigned seqlen; /* number of '1' bits not yet
561 unstuffed */
562 unsigned inbyte, inbits; /* collected bits for next byte */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800563 /* statistics */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700564 unsigned goodbytes; /* bytes correctly received */
565 unsigned alignerrs; /* frames with incomplete byte at end */
566 unsigned fcserrs; /* FCS errors */
567 unsigned frameerrs; /* framing errors */
568 unsigned giants; /* long frames */
569 unsigned runts; /* short frames */
570 unsigned aborts; /* HDLC aborts */
571 unsigned shared0s; /* '0' bits shared between flags */
572 unsigned stolen0s; /* '0' stuff bits also serving as
573 leading flag bits */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800574 struct tasklet_struct rcvd_tasklet;
575};
576
577struct gigaset_ops {
Tilman Schmidt917f5082006-04-10 22:55:00 -0700578 /* Called from ev-layer.c/interface.c for sending AT commands to the
579 device */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800580 int (*write_cmd)(struct cardstate *cs,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700581 const unsigned char *buf, int len,
582 struct tasklet_struct *wake_tasklet);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800583
584 /* Called from interface.c for additional device control */
585 int (*write_room)(struct cardstate *cs);
586 int (*chars_in_buffer)(struct cardstate *cs);
587 int (*brkchars)(struct cardstate *cs, const unsigned char buf[6]);
588
589 /* Called from ev-layer.c after setting up connection
590 * Should call gigaset_bchannel_up(), when finished. */
591 int (*init_bchannel)(struct bc_state *bcs);
592
593 /* Called from ev-layer.c after hanging up
594 * Should call gigaset_bchannel_down(), when finished. */
595 int (*close_bchannel)(struct bc_state *bcs);
596
597 /* Called by gigaset_initcs() for setting up bcs->hw.xxx */
598 int (*initbcshw)(struct bc_state *bcs);
599
600 /* Called by gigaset_freecs() for freeing bcs->hw.xxx */
601 int (*freebcshw)(struct bc_state *bcs);
602
Tilman Schmidt73a88812006-04-22 02:35:30 -0700603 /* Called by gigaset_bchannel_down() for resetting bcs->hw.xxx */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800604 void (*reinitbcshw)(struct bc_state *bcs);
605
606 /* Called by gigaset_initcs() for setting up cs->hw.xxx */
607 int (*initcshw)(struct cardstate *cs);
608
609 /* Called by gigaset_freecs() for freeing cs->hw.xxx */
610 void (*freecshw)(struct cardstate *cs);
611
Tilman Schmidt917f5082006-04-10 22:55:00 -0700612 /* Called from common.c/interface.c for additional serial port
613 control */
614 int (*set_modem_ctrl)(struct cardstate *cs, unsigned old_state,
615 unsigned new_state);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800616 int (*baud_rate)(struct cardstate *cs, unsigned cflag);
617 int (*set_line_ctrl)(struct cardstate *cs, unsigned cflag);
618
619 /* Called from i4l.c to put an skb into the send-queue. */
620 int (*send_skb)(struct bc_state *bcs, struct sk_buff *skb);
621
622 /* Called from ev-layer.c to process a block of data
623 * received through the common/control channel. */
624 void (*handle_input)(struct inbuf_t *inbuf);
625
626};
627
628/* = Common structures and definitions ======================================= */
629
630/* Parser states for DLE-Event:
631 * <DLE-EVENT>: <DLE_FLAG> "X" <EVENT> <DLE_FLAG> "."
632 * <DLE_FLAG>: 0x10
633 * <EVENT>: ((a-z)* | (A-Z)* | (0-10)*)+
634 */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700635#define DLE_FLAG 0x10
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800636
637/* ===========================================================================
638 * Functions implemented in asyncdata.c
639 */
640
641/* Called from i4l.c to put an skb into the send-queue.
642 * After sending gigaset_skb_sent() should be called. */
643int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb);
644
645/* Called from ev-layer.c to process a block of data
646 * received through the common/control channel. */
647void gigaset_m10x_input(struct inbuf_t *inbuf);
648
649/* ===========================================================================
650 * Functions implemented in isocdata.c
651 */
652
653/* Called from i4l.c to put an skb into the send-queue.
654 * After sending gigaset_skb_sent() should be called. */
655int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb);
656
657/* Called from ev-layer.c to process a block of data
658 * received through the common/control channel. */
659void gigaset_isoc_input(struct inbuf_t *inbuf);
660
661/* Called from bas-gigaset.c to process a block of data
662 * received through the isochronous channel */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700663void gigaset_isoc_receive(unsigned char *src, unsigned count,
664 struct bc_state *bcs);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800665
666/* Called from bas-gigaset.c to put a block of data
667 * into the isochronous output buffer */
668int gigaset_isoc_buildframe(struct bc_state *bcs, unsigned char *in, int len);
669
670/* Called from bas-gigaset.c to initialize the isochronous output buffer */
671void gigaset_isowbuf_init(struct isowbuf_t *iwb, unsigned char idle);
672
673/* Called from bas-gigaset.c to retrieve a block of bytes for sending */
674int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size);
675
676/* ===========================================================================
677 * Functions implemented in i4l.c/gigaset.h
678 */
679
680/* Called by gigaset_initcs() for setting up with the isdn4linux subsystem */
681int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid);
682
683/* Called from xxx-gigaset.c to indicate completion of sending an skb */
684void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
685
686/* Called from common.c/ev-layer.c to indicate events relevant to the LL */
687int gigaset_isdn_icall(struct at_state_t *at_state);
688int gigaset_isdn_setup_accept(struct at_state_t *at_state);
689int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data);
690
691void gigaset_i4l_cmd(struct cardstate *cs, int cmd);
692void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd);
693
694
695static inline void gigaset_isdn_rcv_err(struct bc_state *bcs)
696{
697 isdn_ctrl response;
698
699 /* error -> LL */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700700 gig_dbg(DEBUG_CMD, "sending L1ERR");
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800701 response.driver = bcs->cs->myid;
702 response.command = ISDN_STAT_L1ERR;
703 response.arg = bcs->channel;
704 response.parm.errcode = ISDN_STAT_L1ERR_RECV;
705 bcs->cs->iif.statcallb(&response);
706}
707
708/* ===========================================================================
709 * Functions implemented in ev-layer.c
710 */
711
712/* tasklet called from common.c to process queued events */
713void gigaset_handle_event(unsigned long data);
714
715/* called from isocdata.c / asyncdata.c
716 * when a complete modem response line has been received */
717void gigaset_handle_modem_response(struct cardstate *cs);
718
719/* ===========================================================================
720 * Functions implemented in proc.c
721 */
722
723/* initialize sysfs for device */
Tilman Schmidtb1d47462006-04-10 22:55:07 -0700724void gigaset_init_dev_sysfs(struct cardstate *cs);
725void gigaset_free_dev_sysfs(struct cardstate *cs);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800726
727/* ===========================================================================
728 * Functions implemented in common.c/gigaset.h
729 */
730
731void gigaset_bcs_reinit(struct bc_state *bcs);
732void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700733 struct cardstate *cs, int cid);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800734int gigaset_get_channel(struct bc_state *bcs);
735void gigaset_free_channel(struct bc_state *bcs);
736int gigaset_get_channels(struct cardstate *cs);
737void gigaset_free_channels(struct cardstate *cs);
738void gigaset_block_channels(struct cardstate *cs);
739
740/* Allocate and initialize driver structure. */
741struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700742 const char *procname,
743 const char *devname,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700744 const struct gigaset_ops *ops,
745 struct module *owner);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800746
747/* Deallocate driver structure. */
748void gigaset_freedriver(struct gigaset_driver *drv);
749void gigaset_debugdrivers(void);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800750struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty);
751struct cardstate *gigaset_get_cs_by_id(int id);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800752void gigaset_blockdriver(struct gigaset_driver *drv);
753
Tilman Schmidt917f5082006-04-10 22:55:00 -0700754/* Allocate and initialize card state. Calls hardware dependent
755 gigaset_init[b]cs(). */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800756struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
757 int onechannel, int ignoreframes,
758 int cidmode, const char *modulename);
759
760/* Free card state. Calls hardware dependent gigaset_free[b]cs(). */
761void gigaset_freecs(struct cardstate *cs);
762
763/* Tell common.c that hardware and driver are ready. */
764int gigaset_start(struct cardstate *cs);
765
766/* Tell common.c that the device is not present any more. */
767void gigaset_stop(struct cardstate *cs);
768
769/* Tell common.c that the driver is being unloaded. */
Tilman Schmidte468c042008-02-06 01:38:29 -0800770int gigaset_shutdown(struct cardstate *cs);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800771
772/* Tell common.c that an skb has been sent. */
773void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
774
775/* Append event to the queue.
776 * Returns NULL on failure or a pointer to the event on success.
777 * ptr must be kmalloc()ed (and not be freed by the caller).
778 */
779struct event_t *gigaset_add_event(struct cardstate *cs,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700780 struct at_state_t *at_state, int type,
781 void *ptr, int parameter, void *arg);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800782
783/* Called on CONFIG1 command from frontend. */
784int gigaset_enterconfigmode(struct cardstate *cs); //0: success <0: errorcode
785
786/* cs->lock must not be locked */
787static inline void gigaset_schedule_event(struct cardstate *cs)
788{
789 unsigned long flags;
790 spin_lock_irqsave(&cs->lock, flags);
Tilman Schmidt69049cc2006-04-10 22:55:16 -0700791 if (cs->running)
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800792 tasklet_schedule(&cs->event_tasklet);
793 spin_unlock_irqrestore(&cs->lock, flags);
794}
795
796/* Tell common.c that B channel has been closed. */
797/* cs->lock must not be locked */
798static inline void gigaset_bchannel_down(struct bc_state *bcs)
799{
800 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_CLOSED, NULL, 0, NULL);
801
Tilman Schmidt784d5852006-04-10 22:55:04 -0700802 gig_dbg(DEBUG_CMD, "scheduling BC_CLOSED");
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800803 gigaset_schedule_event(bcs->cs);
804}
805
806/* Tell common.c that B channel has been opened. */
807/* cs->lock must not be locked */
808static inline void gigaset_bchannel_up(struct bc_state *bcs)
809{
810 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_OPEN, NULL, 0, NULL);
811
Tilman Schmidt784d5852006-04-10 22:55:04 -0700812 gig_dbg(DEBUG_CMD, "scheduling BC_OPEN");
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800813 gigaset_schedule_event(bcs->cs);
814}
815
816/* handling routines for sk_buff */
817/* ============================= */
818
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800819/* pass received skb to LL
820 * Warning: skb must not be accessed anymore!
821 */
822static inline void gigaset_rcv_skb(struct sk_buff *skb,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700823 struct cardstate *cs,
824 struct bc_state *bcs)
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800825{
826 cs->iif.rcvcallb_skb(cs->myid, bcs->channel, skb);
827 bcs->trans_down++;
828}
829
830/* handle reception of corrupted skb
831 * Warning: skb must not be accessed anymore!
832 */
833static inline void gigaset_rcv_error(struct sk_buff *procskb,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700834 struct cardstate *cs,
835 struct bc_state *bcs)
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800836{
837 if (procskb)
838 dev_kfree_skb(procskb);
839
840 if (bcs->ignore)
841 --bcs->ignore;
842 else {
843 ++bcs->corrupted;
844 gigaset_isdn_rcv_err(bcs);
845 }
846}
847
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800848/* append received bytes to inbuf */
Tilman Schmidt714e8232006-04-10 22:55:09 -0700849int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
850 unsigned numbytes);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800851
852/* ===========================================================================
853 * Functions implemented in interface.c
854 */
855
856/* initialize interface */
857void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
Greg Kroah-Hartmanf4eaa372005-06-20 21:15:16 -0700858 const char *devname);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800859/* release interface */
860void gigaset_if_freedriver(struct gigaset_driver *drv);
861/* add minor */
862void gigaset_if_init(struct cardstate *cs);
863/* remove minor */
864void gigaset_if_free(struct cardstate *cs);
865/* device received data */
866void gigaset_if_receive(struct cardstate *cs,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700867 unsigned char *buffer, size_t len);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800868
869#endif