gigaset.h 32 KB

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