gigaset.h 27 KB

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