gigaset.h 28 KB

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