gigaset.h 27 KB

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