gigaset.h 26 KB

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