gigaset.h 26 KB

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