gigaset.h 28 KB

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