gigaset.h 26 KB

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