blob: 04457571923d15e892739ca032e0b015d019bd1a [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 *
5 * Written by Stefan Eilers <Eilers.Stefan@epost.de>
6 * 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
19#include <linux/config.h>
20#include <linux/kernel.h>
21#include <linux/compiler.h>
22#include <linux/types.h>
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080023#include <linux/spinlock.h>
24#include <linux/isdnif.h>
25#include <linux/usb.h>
26#include <linux/skbuff.h>
27#include <linux/netdevice.h>
28#include <linux/ppp_defs.h>
29#include <linux/timer.h>
30#include <linux/interrupt.h>
31#include <linux/tty.h>
32#include <linux/tty_driver.h>
33#include <linux/list.h>
Tilman Schmidt917f5082006-04-10 22:55:00 -070034#include <asm/atomic.h>
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080035
36#define GIG_VERSION {0,5,0,0}
37#define GIG_COMPAT {0,4,0,0}
38
Tilman Schmidt917f5082006-04-10 22:55:00 -070039#define MAX_REC_PARAMS 10 /* Max. number of params in response string */
40#define MAX_RESP_SIZE 512 /* Max. size of a response string */
41#define HW_HDR_LEN 2 /* Header size used to store ack info */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080042
Tilman Schmidt917f5082006-04-10 22:55:00 -070043#define MAX_EVENTS 64 /* size of event queue */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080044
45#define RBUFSIZE 8192
Tilman Schmidt917f5082006-04-10 22:55:00 -070046#define SBUFSIZE 4096 /* sk_buff payload size */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080047
Tilman Schmidt917f5082006-04-10 22:55:00 -070048#define TRANSBUFSIZE 768 /* bytes per skb for transparent receive */
49#define MAX_BUF_SIZE (SBUFSIZE - 2) /* Max. size of a data packet from LL */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080050
51/* compile time options */
52#define GIG_MAJOR 0
53
54#define GIG_MAYINITONDIAL
55#define GIG_RETRYCID
56#define GIG_X75
57
58#define MAX_TIMER_INDEX 1000
59#define MAX_SEQ_INDEX 1000
60
Tilman Schmidtec81b5e2006-04-10 22:55:03 -070061#define GIG_TICK 100 /* in milliseconds */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -080062
63/* timeout values (unit: 1 sec) */
64#define INIT_TIMEOUT 1
65
66/* timeout values (unit: 0.1 sec) */
67#define RING_TIMEOUT 3 /* for additional parameters to RING */
68#define BAS_TIMEOUT 20 /* for response to Base USB ops */
69#define ATRDY_TIMEOUT 3 /* for HD_READY_SEND_ATDATA */
70
71#define BAS_RETRY 3 /* max. retries for base USB ops */
72
73#define MAXACT 3
74
Tilman Schmidt917f5082006-04-10 22:55:00 -070075#define IFNULL(a) \
76 if (unlikely(!(a)))
77
78#define IFNULLRET(a) \
79 if (unlikely(!(a))) { \
80 err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); \
81 return; \
82 }
83
84#define IFNULLRETVAL(a,b) \
85 if (unlikely(!(a))) { \
86 err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); \
87 return (b); \
88 }
89
90#define IFNULLCONT(a) \
91 if (unlikely(!(a))) { \
92 err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); \
93 continue; \
94 }
95
96#define IFNULLGOTO(a,b) \
97 if (unlikely(!(a))) { \
98 err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); \
99 goto b; \
100 }
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800101
102extern int gigaset_debuglevel; /* "needs" cast to (enum debuglevel) */
103
Tilman Schmidt917f5082006-04-10 22:55:00 -0700104/* any combination of these can be given with the 'debug=' parameter to insmod,
105 * e.g. 'insmod usb_gigaset.o debug=0x2c' will set DEBUG_OPEN, DEBUG_CMD and
106 * DEBUG_INTR.
107 */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800108enum debuglevel { /* up to 24 bits (atomic_t) */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700109 DEBUG_REG = 0x0002, /* serial port I/O register operations */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800110 DEBUG_OPEN = 0x0004, /* open/close serial port */
111 DEBUG_INTR = 0x0008, /* interrupt processing */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700112 DEBUG_INTR_DUMP = 0x0010, /* Activating hexdump debug output on
Tilman Schmidt917f5082006-04-10 22:55:00 -0700113 interrupt requests, not available as
114 run-time option */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800115 DEBUG_CMD = 0x00020, /* sent/received LL commands */
116 DEBUG_STREAM = 0x00040, /* application data stream I/O events */
117 DEBUG_STREAM_DUMP = 0x00080, /* application data stream content */
118 DEBUG_LLDATA = 0x00100, /* sent/received LL data */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700119 DEBUG_INTR_0 = 0x00200, /* serial port interrupt processing */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800120 DEBUG_DRIVER = 0x00400, /* driver structure */
121 DEBUG_HDLC = 0x00800, /* M10x HDLC processing */
122 DEBUG_WRITE = 0x01000, /* M105 data write */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700123 DEBUG_TRANSCMD = 0x02000, /* AT-COMMANDS+RESPONSES */
124 DEBUG_MCMD = 0x04000, /* COMMANDS THAT ARE SENT VERY OFTEN */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700125 DEBUG_INIT = 0x08000, /* (de)allocation+initialization of data
126 structures */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800127 DEBUG_LOCK = 0x10000, /* semaphore operations */
128 DEBUG_OUTPUT = 0x20000, /* output to device */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700129 DEBUG_ISO = 0x40000, /* isochronous transfers */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800130 DEBUG_IF = 0x80000, /* character device operations */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700131 DEBUG_USBREQ = 0x100000, /* USB communication (except payload
132 data) */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700133 DEBUG_LOCKCMD = 0x200000, /* AT commands and responses when
Tilman Schmidt917f5082006-04-10 22:55:00 -0700134 MS_LOCKED */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800135
Tilman Schmidt917f5082006-04-10 22:55:00 -0700136 DEBUG_ANY = 0x3fffff, /* print message if any of the others is
137 activated */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800138};
139
Tilman Schmidt784d5852006-04-10 22:55:04 -0700140/* missing from linux/device.h ... */
141#ifndef dev_notice
142#define dev_notice(dev, format, arg...) \
143 dev_printk(KERN_NOTICE , dev , format , ## arg)
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800144#endif
145
Tilman Schmidt784d5852006-04-10 22:55:04 -0700146/* Kernel message macros for situations where dev_printk and friends cannot be
147 * used for lack of reliable access to a device structure.
148 * linux/usb.h already contains these but in an obsolete form which clutters
149 * the log needlessly, and according to the USB maintainer those should be
150 * removed rather than fixed anyway.
151 */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800152#undef err
Tilman Schmidt784d5852006-04-10 22:55:04 -0700153#undef info
154#undef warn
155#undef notice
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800156
Tilman Schmidt784d5852006-04-10 22:55:04 -0700157#define err(format, arg...) printk(KERN_ERR KBUILD_MODNAME ": " \
158 format "\n" , ## arg)
159#define info(format, arg...) printk(KERN_INFO KBUILD_MODNAME ": " \
160 format "\n" , ## arg)
161#define warn(format, arg...) printk(KERN_WARNING KBUILD_MODNAME ": " \
162 format "\n" , ## arg)
163#define notice(format, arg...) printk(KERN_NOTICE KBUILD_MODNAME ": " \
164 format "\n" , ## arg)
165
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800166#ifdef CONFIG_GIGASET_DEBUG
Tilman Schmidt784d5852006-04-10 22:55:04 -0700167
168#define gig_dbg(level, format, arg...) \
Tilman Schmidt917f5082006-04-10 22:55:00 -0700169 do { \
170 if (unlikely(((enum debuglevel)gigaset_debuglevel) & (level))) \
Tilman Schmidt784d5852006-04-10 22:55:04 -0700171 printk(KERN_DEBUG KBUILD_MODNAME ": " format "\n", \
172 ## arg); \
Tilman Schmidt917f5082006-04-10 22:55:00 -0700173 } while (0)
Tilman Schmidt784d5852006-04-10 22:55:04 -0700174#define DEBUG_DEFAULT (DEBUG_INIT | DEBUG_TRANSCMD | DEBUG_CMD | DEBUG_USBREQ)
175
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800176#else
Tilman Schmidt784d5852006-04-10 22:55:04 -0700177
178#define gig_dbg(level, format, arg...) do {} while (0)
179#define DEBUG_DEFAULT 0
180
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800181#endif
182
183void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700184 size_t len, const unsigned char *buf, int from_user);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800185
186/* connection state */
187#define ZSAU_NONE 0
188#define ZSAU_DISCONNECT_IND 4
189#define ZSAU_OUTGOING_CALL_PROCEEDING 1
190#define ZSAU_PROCEEDING 1
191#define ZSAU_CALL_DELIVERED 2
192#define ZSAU_ACTIVE 3
193#define ZSAU_NULL 5
194#define ZSAU_DISCONNECT_REQ 6
195#define ZSAU_UNKNOWN -1
196
197/* USB control transfer requests */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700198#define OUT_VENDOR_REQ (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT)
199#define IN_VENDOR_REQ (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT)
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800200
201/* int-in-events 3070 */
202#define HD_B1_FLOW_CONTROL 0x80
203#define HD_B2_FLOW_CONTROL 0x81
Tilman Schmidt917f5082006-04-10 22:55:00 -0700204#define HD_RECEIVEATDATA_ACK (0x35) // 3070
205 // att: HD_RECEIVE>>AT<<DATA_ACK
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800206#define HD_READY_SEND_ATDATA (0x36) // 3070
207#define HD_OPEN_ATCHANNEL_ACK (0x37) // 3070
208#define HD_CLOSE_ATCHANNEL_ACK (0x38) // 3070
209#define HD_DEVICE_INIT_OK (0x11) // ISurf USB + 3070
210#define HD_OPEN_B1CHANNEL_ACK (0x51) // ISurf USB + 3070
211#define HD_OPEN_B2CHANNEL_ACK (0x52) // ISurf USB + 3070
212#define HD_CLOSE_B1CHANNEL_ACK (0x53) // ISurf USB + 3070
213#define HD_CLOSE_B2CHANNEL_ACK (0x54) // ISurf USB + 3070
214// Powermangment
215#define HD_SUSPEND_END (0x61) // ISurf USB
216// Configuration
217#define HD_RESET_INTERRUPT_PIPE_ACK (0xFF) // ISurf USB + 3070
218
219/* control requests 3070 */
220#define HD_OPEN_B1CHANNEL (0x23) // ISurf USB + 3070
221#define HD_CLOSE_B1CHANNEL (0x24) // ISurf USB + 3070
222#define HD_OPEN_B2CHANNEL (0x25) // ISurf USB + 3070
223#define HD_CLOSE_B2CHANNEL (0x26) // ISurf USB + 3070
224#define HD_RESET_INTERRUPT_PIPE (0x27) // ISurf USB + 3070
225#define HD_DEVICE_INIT_ACK (0x34) // ISurf USB + 3070
226#define HD_WRITE_ATMESSAGE (0x12) // 3070
227#define HD_READ_ATMESSAGE (0x13) // 3070
228#define HD_OPEN_ATCHANNEL (0x28) // 3070
229#define HD_CLOSE_ATCHANNEL (0x29) // 3070
230
231/* USB frames for isochronous transfer */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700232#define BAS_FRAMETIME 1 /* number of milliseconds between frames */
233#define BAS_NUMFRAMES 8 /* number of frames per URB */
234#define BAS_MAXFRAME 16 /* allocated bytes per frame */
235#define BAS_NORMFRAME 8 /* send size without flow control */
236#define BAS_HIGHFRAME 10 /* " " with positive flow control */
237#define BAS_LOWFRAME 5 /* " " with negative flow control */
238#define BAS_CORRFRAMES 4 /* flow control multiplicator */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800239
Tilman Schmidt917f5082006-04-10 22:55:00 -0700240#define BAS_INBUFSIZE (BAS_MAXFRAME * BAS_NUMFRAMES)
241 /* size of isoc in buf per URB */
242#define BAS_OUTBUFSIZE 4096 /* size of common isoc out buffer */
243#define BAS_OUTBUFPAD BAS_MAXFRAME /* size of pad area for isoc out buf */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800244
245#define BAS_INURBS 3
246#define BAS_OUTURBS 3
247
248/* variable commands in struct bc_state */
249#define AT_ISO 0
250#define AT_DIAL 1
251#define AT_MSN 2
252#define AT_BC 3
253#define AT_PROTO 4
254#define AT_TYPE 5
255#define AT_HLC 6
256#define AT_NUM 7
257
258/* variables in struct at_state_t */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700259#define VAR_ZSAU 0
260#define VAR_ZDLE 1
261#define VAR_ZVLS 2
262#define VAR_ZCTP 3
263#define VAR_NUM 4
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800264
Tilman Schmidt917f5082006-04-10 22:55:00 -0700265#define STR_NMBR 0
266#define STR_ZCPN 1
267#define STR_ZCON 2
268#define STR_ZBC 3
269#define STR_ZHLC 4
270#define STR_NUM 5
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800271
Tilman Schmidt917f5082006-04-10 22:55:00 -0700272#define EV_TIMEOUT -105
273#define EV_IF_VER -106
274#define EV_PROC_CIDMODE -107
275#define EV_SHUTDOWN -108
276#define EV_START -110
277#define EV_STOP -111
278#define EV_IF_LOCK -112
279#define EV_PROTO_L2 -113
280#define EV_ACCEPT -114
281#define EV_DIAL -115
282#define EV_HUP -116
283#define EV_BC_OPEN -117
284#define EV_BC_CLOSED -118
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800285
286/* input state */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700287#define INS_command 0x0001
288#define INS_DLE_char 0x0002
289#define INS_byte_stuff 0x0004
290#define INS_have_data 0x0008
291#define INS_skip_frame 0x0010
292#define INS_DLE_command 0x0020
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800293#define INS_flag_hunt 0x0040
294
295/* channel state */
296#define CHS_D_UP 0x01
297#define CHS_B_UP 0x02
298#define CHS_NOTIFY_LL 0x04
299
Tilman Schmidt917f5082006-04-10 22:55:00 -0700300#define ICALL_REJECT 0
301#define ICALL_ACCEPT 1
302#define ICALL_IGNORE 2
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800303
304/* device state */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700305#define MS_UNINITIALIZED 0
306#define MS_INIT 1
307#define MS_LOCKED 2
308#define MS_SHUTDOWN 3
309#define MS_RECOVER 4
310#define MS_READY 5
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800311
312/* mode */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700313#define M_UNKNOWN 0
314#define M_CONFIG 1
315#define M_UNIMODEM 2
316#define M_CID 3
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800317
318/* start mode */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700319#define SM_LOCKED 0
320#define SM_ISDN 1 /* default */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800321
322struct gigaset_ops;
323struct gigaset_driver;
324
325struct usb_cardstate;
326struct ser_cardstate;
327struct bas_cardstate;
328
329struct bc_state;
330struct usb_bc_state;
331struct ser_bc_state;
332struct bas_bc_state;
333
334struct reply_t {
Tilman Schmidt917f5082006-04-10 22:55:00 -0700335 int resp_code; /* RSP_XXXX */
336 int min_ConState; /* <0 => ignore */
337 int max_ConState; /* <0 => ignore */
338 int parameter; /* e.g. ZSAU_XXXX <0: ignore*/
339 int new_ConState; /* <0 => ignore */
340 int timeout; /* >0 => *HZ; <=0 => TOUT_XXXX*/
341 int action[MAXACT]; /* ACT_XXXX */
342 char *command; /* NULL==none */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800343};
344
345extern struct reply_t gigaset_tab_cid_m10x[];
346extern struct reply_t gigaset_tab_nocid_m10x[];
347
348struct inbuf_t {
Tilman Schmidt917f5082006-04-10 22:55:00 -0700349 unsigned char *rcvbuf; /* usb-gigaset receive buffer */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800350 struct bc_state *bcs;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700351 struct cardstate *cs;
352 int inputstate;
353 atomic_t head, tail;
354 unsigned char data[RBUFSIZE];
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800355};
356
357/* isochronous write buffer structure
358 * circular buffer with pad area for extraction of complete USB frames
359 * - data[read..nextread-1] is valid data already submitted to the USB subsystem
360 * - data[nextread..write-1] is valid data yet to be sent
361 * - data[write] is the next byte to write to
362 * - in byte-oriented L2 procotols, it is completely free
363 * - in bit-oriented L2 procotols, it may contain a partial byte of valid data
364 * - data[write+1..read-1] is free
365 * - wbits is the number of valid data bits in data[write], starting at the LSB
366 * - writesem is the semaphore for writing to the buffer:
367 * if writesem <= 0, data[write..read-1] is currently being written to
368 * - idle contains the byte value to repeat when the end of valid data is
369 * reached; if nextread==write (buffer contains no data to send), either the
Tilman Schmidt917f5082006-04-10 22:55:00 -0700370 * BAS_OUTBUFPAD bytes immediately before data[write] (if
371 * write>=BAS_OUTBUFPAD) or those of the pad area (if write<BAS_OUTBUFPAD)
372 * are also filled with that value
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800373 */
374struct isowbuf_t {
375 atomic_t read;
376 atomic_t nextread;
377 atomic_t write;
378 atomic_t writesem;
379 int wbits;
380 unsigned char data[BAS_OUTBUFSIZE + BAS_OUTBUFPAD];
381 unsigned char idle;
382};
383
384/* isochronous write URB context structure
385 * data to be stored along with the URB and retrieved when it is returned
386 * as completed by the USB subsystem
387 * - urb: pointer to the URB itself
388 * - bcs: pointer to the B Channel control structure
389 * - limit: end of write buffer area covered by this URB
390 */
391struct isow_urbctx_t {
392 struct urb *urb;
393 struct bc_state *bcs;
394 int limit;
395};
396
397/* AT state structure
398 * data associated with the state of an ISDN connection, whether or not
399 * it is currently assigned a B channel
400 */
401struct at_state_t {
Tilman Schmidt917f5082006-04-10 22:55:00 -0700402 struct list_head list;
403 int waiting;
404 int getstring;
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800405 atomic_t timer_index;
406 unsigned long timer_expires;
407 int timer_active;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700408 unsigned int ConState; /* State of connection */
409 struct reply_t *replystruct;
410 int cid;
411 int int_var[VAR_NUM]; /* see VAR_XXXX */
412 char *str_var[STR_NUM]; /* see STR_XXXX */
413 unsigned pending_commands; /* see PC_XXXX */
414 atomic_t seq_index;
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800415
Tilman Schmidt917f5082006-04-10 22:55:00 -0700416 struct cardstate *cs;
417 struct bc_state *bcs;
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800418};
419
420struct resp_type_t {
421 unsigned char *response;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700422 int resp_code; /* RSP_XXXX */
423 int type; /* RT_XXXX */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800424};
425
426struct event_t {
427 int type;
428 void *ptr, *arg;
429 int parameter;
430 int cid;
431 struct at_state_t *at_state;
432};
433
434/* This buffer holds all information about the used B-Channel */
435struct bc_state {
Tilman Schmidt917f5082006-04-10 22:55:00 -0700436 struct sk_buff *tx_skb; /* Current transfer buffer to modem */
437 struct sk_buff_head squeue; /* B-Channel send Queue */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800438
439 /* Variables for debugging .. */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700440 int corrupted; /* Counter for corrupted packages */
441 int trans_down; /* Counter of packages (downstream) */
442 int trans_up; /* Counter of packages (upstream) */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800443
444 struct at_state_t at_state;
445 unsigned long rcvbytes;
446
447 __u16 fcs;
448 struct sk_buff *skb;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700449 int inputstate; /* see INS_XXXX */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800450
451 int channel;
452
453 struct cardstate *cs;
454
Tilman Schmidt917f5082006-04-10 22:55:00 -0700455 unsigned chstate; /* bitmap (CHS_*) */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800456 int ignore;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700457 unsigned proto2; /* Layer 2 protocol (ISDN_PROTO_L2_*) */
458 char *commands[AT_NUM]; /* see AT_XXXX */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800459
460#ifdef CONFIG_GIGASET_DEBUG
461 int emptycount;
462#endif
463 int busy;
464 int use_count;
465
Tilman Schmidt784d5852006-04-10 22:55:04 -0700466 /* private data of hardware drivers */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800467 union {
Tilman Schmidt917f5082006-04-10 22:55:00 -0700468 struct ser_bc_state *ser; /* serial hardware driver */
469 struct usb_bc_state *usb; /* usb hardware driver (m105) */
470 struct bas_bc_state *bas; /* usb hardware driver (base) */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800471 } hw;
472};
473
474struct cardstate {
475 struct gigaset_driver *driver;
476 unsigned minor_index;
Tilman Schmidt784d5852006-04-10 22:55:04 -0700477 struct device *dev;
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800478
479 const struct gigaset_ops *ops;
480
481 /* Stuff to handle communication */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800482 wait_queue_head_t waitqueue;
483 int waiting;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700484 atomic_t mode; /* see M_XXXX */
485 atomic_t mstate; /* Modem state: see MS_XXXX */
486 /* only changed by the event layer */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800487 int cmd_result;
488
489 int channels;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700490 struct bc_state *bcs; /* Array of struct bc_state */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800491
Tilman Schmidt917f5082006-04-10 22:55:00 -0700492 int onechannel; /* data and commands transmitted in one
493 stream (M10x) */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800494
495 spinlock_t lock;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700496 struct at_state_t at_state; /* at_state_t for cid == 0 */
497 struct list_head temp_at_states;/* list of temporary "struct
498 at_state_t"s without B channel */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800499
500 struct inbuf_t *inbuf;
501
502 struct cmdbuf_t *cmdbuf, *lastcmdbuf;
503 spinlock_t cmdlock;
504 unsigned curlen, cmdbytes;
505
506 unsigned open_count;
507 struct tty_struct *tty;
508 struct tasklet_struct if_wake_tasklet;
509 unsigned control_state;
510
511 unsigned fwver[4];
512 int gotfwver;
513
Tilman Schmidt917f5082006-04-10 22:55:00 -0700514 atomic_t running; /* !=0 if events are handled */
515 atomic_t connected; /* !=0 if hardware is connected */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800516
517 atomic_t cidmode;
518
Tilman Schmidt917f5082006-04-10 22:55:00 -0700519 int myid; /* id for communication with LL */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800520 isdn_if iif;
521
522 struct reply_t *tabnocid;
523 struct reply_t *tabcid;
524 int cs_init;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700525 int ignoreframes; /* frames to ignore after setting up the
526 B channel */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700527 struct semaphore sem; /* locks this structure:
528 * connected is not changed,
529 * hardware_up is not changed,
530 * MState is not changed to or from
531 * MS_LOCKED */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800532
533 struct timer_list timer;
534 int retry_count;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700535 int dle; /* !=0 if modem commands/responses are
536 dle encoded */
537 int cur_at_seq; /* sequence of AT commands being
538 processed */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700539 int curchannel; /* channel those commands are meant
Tilman Schmidt917f5082006-04-10 22:55:00 -0700540 for */
541 atomic_t commands_pending; /* flag(s) in xxx.commands_pending have
542 been set */
543 struct tasklet_struct event_tasklet;
544 /* tasklet for serializing AT commands.
545 * Scheduled
546 * -> for modem reponses (and
Tilman Schmidt784d5852006-04-10 22:55:04 -0700547 * incoming data for M10x)
Tilman Schmidt917f5082006-04-10 22:55:00 -0700548 * -> on timeout
549 * -> after setting bits in
550 * xxx.at_state.pending_command
551 * (e.g. command from LL) */
552 struct tasklet_struct write_tasklet;
553 /* tasklet for serial output
554 * (not used in base driver) */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800555
556 /* event queue */
557 struct event_t events[MAX_EVENTS];
558 atomic_t ev_tail, ev_head;
559 spinlock_t ev_lock;
560
561 /* current modem response */
562 unsigned char respdata[MAX_RESP_SIZE];
563 unsigned cbytes;
564
Tilman Schmidt784d5852006-04-10 22:55:04 -0700565 /* private data of hardware drivers */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800566 union {
Tilman Schmidt917f5082006-04-10 22:55:00 -0700567 struct usb_cardstate *usb; /* USB hardware driver (m105) */
568 struct ser_cardstate *ser; /* serial hardware driver */
569 struct bas_cardstate *bas; /* USB hardware driver (base) */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800570 } hw;
571};
572
573struct gigaset_driver {
574 struct list_head list;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700575 spinlock_t lock; /* locks minor tables and blocked */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800576 struct tty_driver *tty;
577 unsigned have_tty;
578 unsigned minor;
579 unsigned minors;
580 struct cardstate *cs;
581 unsigned *flags;
582 int blocked;
583
584 const struct gigaset_ops *ops;
585 struct module *owner;
586};
587
588struct cmdbuf_t {
589 struct cmdbuf_t *next, *prev;
590 int len, offset;
591 struct tasklet_struct *wake_tasklet;
592 unsigned char buf[0];
593};
594
595struct bas_bc_state {
596 /* isochronous output state */
597 atomic_t running;
598 atomic_t corrbytes;
599 spinlock_t isooutlock;
600 struct isow_urbctx_t isoouturbs[BAS_OUTURBS];
601 struct isow_urbctx_t *isooutdone, *isooutfree, *isooutovfl;
602 struct isowbuf_t *isooutbuf;
Tilman Schmidt784d5852006-04-10 22:55:04 -0700603 unsigned numsub; /* submitted URB counter
604 (for diagnostic messages only) */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800605 struct tasklet_struct sent_tasklet;
606
607 /* isochronous input state */
608 spinlock_t isoinlock;
609 struct urb *isoinurbs[BAS_INURBS];
610 unsigned char isoinbuf[BAS_INBUFSIZE * BAS_INURBS];
Tilman Schmidt784d5852006-04-10 22:55:04 -0700611 struct urb *isoindone; /* completed isoc read URB */
612 int loststatus; /* status of dropped URB */
613 unsigned isoinlost; /* number of bytes lost */
614 /* state of bit unstuffing algorithm
615 (in addition to BC_state.inputstate) */
616 unsigned seqlen; /* number of '1' bits not yet
617 unstuffed */
618 unsigned inbyte, inbits; /* collected bits for next byte */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800619 /* statistics */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700620 unsigned goodbytes; /* bytes correctly received */
621 unsigned alignerrs; /* frames with incomplete byte at end */
622 unsigned fcserrs; /* FCS errors */
623 unsigned frameerrs; /* framing errors */
624 unsigned giants; /* long frames */
625 unsigned runts; /* short frames */
626 unsigned aborts; /* HDLC aborts */
627 unsigned shared0s; /* '0' bits shared between flags */
628 unsigned stolen0s; /* '0' stuff bits also serving as
629 leading flag bits */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800630 struct tasklet_struct rcvd_tasklet;
631};
632
633struct gigaset_ops {
Tilman Schmidt917f5082006-04-10 22:55:00 -0700634 /* Called from ev-layer.c/interface.c for sending AT commands to the
635 device */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800636 int (*write_cmd)(struct cardstate *cs,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700637 const unsigned char *buf, int len,
638 struct tasklet_struct *wake_tasklet);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800639
640 /* Called from interface.c for additional device control */
641 int (*write_room)(struct cardstate *cs);
642 int (*chars_in_buffer)(struct cardstate *cs);
643 int (*brkchars)(struct cardstate *cs, const unsigned char buf[6]);
644
645 /* Called from ev-layer.c after setting up connection
646 * Should call gigaset_bchannel_up(), when finished. */
647 int (*init_bchannel)(struct bc_state *bcs);
648
649 /* Called from ev-layer.c after hanging up
650 * Should call gigaset_bchannel_down(), when finished. */
651 int (*close_bchannel)(struct bc_state *bcs);
652
653 /* Called by gigaset_initcs() for setting up bcs->hw.xxx */
654 int (*initbcshw)(struct bc_state *bcs);
655
656 /* Called by gigaset_freecs() for freeing bcs->hw.xxx */
657 int (*freebcshw)(struct bc_state *bcs);
658
Tilman Schmidt917f5082006-04-10 22:55:00 -0700659 /* Called by gigaset_stop() or gigaset_bchannel_down() for resetting
660 bcs->hw.xxx */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800661 void (*reinitbcshw)(struct bc_state *bcs);
662
663 /* Called by gigaset_initcs() for setting up cs->hw.xxx */
664 int (*initcshw)(struct cardstate *cs);
665
666 /* Called by gigaset_freecs() for freeing cs->hw.xxx */
667 void (*freecshw)(struct cardstate *cs);
668
Tilman Schmidt917f5082006-04-10 22:55:00 -0700669 /* Called from common.c/interface.c for additional serial port
670 control */
671 int (*set_modem_ctrl)(struct cardstate *cs, unsigned old_state,
672 unsigned new_state);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800673 int (*baud_rate)(struct cardstate *cs, unsigned cflag);
674 int (*set_line_ctrl)(struct cardstate *cs, unsigned cflag);
675
676 /* Called from i4l.c to put an skb into the send-queue. */
677 int (*send_skb)(struct bc_state *bcs, struct sk_buff *skb);
678
679 /* Called from ev-layer.c to process a block of data
680 * received through the common/control channel. */
681 void (*handle_input)(struct inbuf_t *inbuf);
682
683};
684
685/* = Common structures and definitions ======================================= */
686
687/* Parser states for DLE-Event:
688 * <DLE-EVENT>: <DLE_FLAG> "X" <EVENT> <DLE_FLAG> "."
689 * <DLE_FLAG>: 0x10
690 * <EVENT>: ((a-z)* | (A-Z)* | (0-10)*)+
691 */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700692#define DLE_FLAG 0x10
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800693
694/* ===========================================================================
695 * Functions implemented in asyncdata.c
696 */
697
698/* Called from i4l.c to put an skb into the send-queue.
699 * After sending gigaset_skb_sent() should be called. */
700int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb);
701
702/* Called from ev-layer.c to process a block of data
703 * received through the common/control channel. */
704void gigaset_m10x_input(struct inbuf_t *inbuf);
705
706/* ===========================================================================
707 * Functions implemented in isocdata.c
708 */
709
710/* Called from i4l.c to put an skb into the send-queue.
711 * After sending gigaset_skb_sent() should be called. */
712int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb);
713
714/* Called from ev-layer.c to process a block of data
715 * received through the common/control channel. */
716void gigaset_isoc_input(struct inbuf_t *inbuf);
717
718/* Called from bas-gigaset.c to process a block of data
719 * received through the isochronous channel */
Tilman Schmidt917f5082006-04-10 22:55:00 -0700720void gigaset_isoc_receive(unsigned char *src, unsigned count,
721 struct bc_state *bcs);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800722
723/* Called from bas-gigaset.c to put a block of data
724 * into the isochronous output buffer */
725int gigaset_isoc_buildframe(struct bc_state *bcs, unsigned char *in, int len);
726
727/* Called from bas-gigaset.c to initialize the isochronous output buffer */
728void gigaset_isowbuf_init(struct isowbuf_t *iwb, unsigned char idle);
729
730/* Called from bas-gigaset.c to retrieve a block of bytes for sending */
731int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size);
732
733/* ===========================================================================
734 * Functions implemented in i4l.c/gigaset.h
735 */
736
737/* Called by gigaset_initcs() for setting up with the isdn4linux subsystem */
738int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid);
739
740/* Called from xxx-gigaset.c to indicate completion of sending an skb */
741void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
742
743/* Called from common.c/ev-layer.c to indicate events relevant to the LL */
744int gigaset_isdn_icall(struct at_state_t *at_state);
745int gigaset_isdn_setup_accept(struct at_state_t *at_state);
746int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data);
747
748void gigaset_i4l_cmd(struct cardstate *cs, int cmd);
749void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd);
750
751
752static inline void gigaset_isdn_rcv_err(struct bc_state *bcs)
753{
754 isdn_ctrl response;
755
756 /* error -> LL */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700757 gig_dbg(DEBUG_CMD, "sending L1ERR");
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800758 response.driver = bcs->cs->myid;
759 response.command = ISDN_STAT_L1ERR;
760 response.arg = bcs->channel;
761 response.parm.errcode = ISDN_STAT_L1ERR_RECV;
762 bcs->cs->iif.statcallb(&response);
763}
764
765/* ===========================================================================
766 * Functions implemented in ev-layer.c
767 */
768
769/* tasklet called from common.c to process queued events */
770void gigaset_handle_event(unsigned long data);
771
772/* called from isocdata.c / asyncdata.c
773 * when a complete modem response line has been received */
774void gigaset_handle_modem_response(struct cardstate *cs);
775
776/* ===========================================================================
777 * Functions implemented in proc.c
778 */
779
780/* initialize sysfs for device */
Tilman Schmidtb1d47462006-04-10 22:55:07 -0700781void gigaset_init_dev_sysfs(struct cardstate *cs);
782void gigaset_free_dev_sysfs(struct cardstate *cs);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800783
784/* ===========================================================================
785 * Functions implemented in common.c/gigaset.h
786 */
787
788void gigaset_bcs_reinit(struct bc_state *bcs);
789void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700790 struct cardstate *cs, int cid);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800791int gigaset_get_channel(struct bc_state *bcs);
792void gigaset_free_channel(struct bc_state *bcs);
793int gigaset_get_channels(struct cardstate *cs);
794void gigaset_free_channels(struct cardstate *cs);
795void gigaset_block_channels(struct cardstate *cs);
796
797/* Allocate and initialize driver structure. */
798struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700799 const char *procname,
800 const char *devname,
801 const char *devfsname,
802 const struct gigaset_ops *ops,
803 struct module *owner);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800804
805/* Deallocate driver structure. */
806void gigaset_freedriver(struct gigaset_driver *drv);
807void gigaset_debugdrivers(void);
808struct cardstate *gigaset_get_cs_by_minor(unsigned minor);
809struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty);
810struct cardstate *gigaset_get_cs_by_id(int id);
811
812/* For drivers without fixed assignment device<->cardstate (usb) */
813struct cardstate *gigaset_getunassignedcs(struct gigaset_driver *drv);
814void gigaset_unassign(struct cardstate *cs);
815void gigaset_blockdriver(struct gigaset_driver *drv);
816
Tilman Schmidt917f5082006-04-10 22:55:00 -0700817/* Allocate and initialize card state. Calls hardware dependent
818 gigaset_init[b]cs(). */
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800819struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
820 int onechannel, int ignoreframes,
821 int cidmode, const char *modulename);
822
823/* Free card state. Calls hardware dependent gigaset_free[b]cs(). */
824void gigaset_freecs(struct cardstate *cs);
825
826/* Tell common.c that hardware and driver are ready. */
827int gigaset_start(struct cardstate *cs);
828
829/* Tell common.c that the device is not present any more. */
830void gigaset_stop(struct cardstate *cs);
831
832/* Tell common.c that the driver is being unloaded. */
833void gigaset_shutdown(struct cardstate *cs);
834
835/* Tell common.c that an skb has been sent. */
836void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
837
838/* Append event to the queue.
839 * Returns NULL on failure or a pointer to the event on success.
840 * ptr must be kmalloc()ed (and not be freed by the caller).
841 */
842struct event_t *gigaset_add_event(struct cardstate *cs,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700843 struct at_state_t *at_state, int type,
844 void *ptr, int parameter, void *arg);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800845
846/* Called on CONFIG1 command from frontend. */
847int gigaset_enterconfigmode(struct cardstate *cs); //0: success <0: errorcode
848
849/* cs->lock must not be locked */
850static inline void gigaset_schedule_event(struct cardstate *cs)
851{
852 unsigned long flags;
853 spin_lock_irqsave(&cs->lock, flags);
854 if (atomic_read(&cs->running))
855 tasklet_schedule(&cs->event_tasklet);
856 spin_unlock_irqrestore(&cs->lock, flags);
857}
858
859/* Tell common.c that B channel has been closed. */
860/* cs->lock must not be locked */
861static inline void gigaset_bchannel_down(struct bc_state *bcs)
862{
863 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_CLOSED, NULL, 0, NULL);
864
Tilman Schmidt784d5852006-04-10 22:55:04 -0700865 gig_dbg(DEBUG_CMD, "scheduling BC_CLOSED");
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800866 gigaset_schedule_event(bcs->cs);
867}
868
869/* Tell common.c that B channel has been opened. */
870/* cs->lock must not be locked */
871static inline void gigaset_bchannel_up(struct bc_state *bcs)
872{
873 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_OPEN, NULL, 0, NULL);
874
Tilman Schmidt784d5852006-04-10 22:55:04 -0700875 gig_dbg(DEBUG_CMD, "scheduling BC_OPEN");
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800876 gigaset_schedule_event(bcs->cs);
877}
878
879/* handling routines for sk_buff */
880/* ============================= */
881
882/* private version of __skb_put()
883 * append 'len' bytes to the content of 'skb', already knowing that the
884 * existing buffer can accomodate them
885 * returns a pointer to the location where the new bytes should be copied to
886 * This function does not take any locks so it must be called with the
887 * appropriate locks held only.
888 */
889static inline unsigned char *gigaset_skb_put_quick(struct sk_buff *skb,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700890 unsigned int len)
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800891{
892 unsigned char *tmp = skb->tail;
893 /*SKB_LINEAR_ASSERT(skb);*/ /* not needed here */
894 skb->tail += len;
895 skb->len += len;
896 return tmp;
897}
898
899/* pass received skb to LL
900 * Warning: skb must not be accessed anymore!
901 */
902static inline void gigaset_rcv_skb(struct sk_buff *skb,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700903 struct cardstate *cs,
904 struct bc_state *bcs)
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800905{
906 cs->iif.rcvcallb_skb(cs->myid, bcs->channel, skb);
907 bcs->trans_down++;
908}
909
910/* handle reception of corrupted skb
911 * Warning: skb must not be accessed anymore!
912 */
913static inline void gigaset_rcv_error(struct sk_buff *procskb,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700914 struct cardstate *cs,
915 struct bc_state *bcs)
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800916{
917 if (procskb)
918 dev_kfree_skb(procskb);
919
920 if (bcs->ignore)
921 --bcs->ignore;
922 else {
923 ++bcs->corrupted;
924 gigaset_isdn_rcv_err(bcs);
925 }
926}
927
928
929/* bitwise byte inversion table */
930extern __u8 gigaset_invtab[]; /* in common.c */
931
932
933/* append received bytes to inbuf */
934static inline int gigaset_fill_inbuf(struct inbuf_t *inbuf,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700935 const unsigned char *src,
936 unsigned numbytes)
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800937{
938 unsigned n, head, tail, bytesleft;
939
Tilman Schmidt784d5852006-04-10 22:55:04 -0700940 gig_dbg(DEBUG_INTR, "received %u bytes", numbytes);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800941
942 if (!numbytes)
943 return 0;
944
945 bytesleft = numbytes;
946 tail = atomic_read(&inbuf->tail);
947 head = atomic_read(&inbuf->head);
Tilman Schmidt784d5852006-04-10 22:55:04 -0700948 gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800949
950 while (bytesleft) {
951 if (head > tail)
952 n = head - 1 - tail;
953 else if (head == 0)
954 n = (RBUFSIZE-1) - tail;
955 else
956 n = RBUFSIZE - tail;
957 if (!n) {
Tilman Schmidt784d5852006-04-10 22:55:04 -0700958 dev_err(inbuf->cs->dev,
959 "buffer overflow (%u bytes lost)", bytesleft);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800960 break;
961 }
962 if (n > bytesleft)
963 n = bytesleft;
964 memcpy(inbuf->data + tail, src, n);
965 bytesleft -= n;
966 tail = (tail + n) % RBUFSIZE;
967 src += n;
968 }
Tilman Schmidt784d5852006-04-10 22:55:04 -0700969 gig_dbg(DEBUG_INTR, "setting tail to %u", tail);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800970 atomic_set(&inbuf->tail, tail);
971 return numbytes != bytesleft;
972}
973
974/* ===========================================================================
975 * Functions implemented in interface.c
976 */
977
978/* initialize interface */
979void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700980 const char *devname, const char *devfsname);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800981/* release interface */
982void gigaset_if_freedriver(struct gigaset_driver *drv);
983/* add minor */
984void gigaset_if_init(struct cardstate *cs);
985/* remove minor */
986void gigaset_if_free(struct cardstate *cs);
987/* device received data */
988void gigaset_if_receive(struct cardstate *cs,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700989 unsigned char *buffer, size_t len);
Hansjoerg Lipp6fd5ea62006-03-26 01:38:29 -0800990
991#endif