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