gigaset.h 26 KB

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