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