gigaset.h 26 KB

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