gigaset.h 27 KB

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