gigaset.h 30 KB

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