gigaset.h 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  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 (HZ / 10)
  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. #ifdef CONFIG_GIGASET_DEBUG
  117. #define DEBUG_DEFAULT (DEBUG_INIT | DEBUG_TRANSCMD | DEBUG_CMD | DEBUG_USBREQ)
  118. #else
  119. #define DEBUG_DEFAULT 0
  120. #endif
  121. /* redefine syslog macros to prepend module name instead of entire
  122. * source path */
  123. #undef info
  124. #define info(format, arg...) \
  125. printk(KERN_INFO "%s: " format "\n", \
  126. THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg)
  127. #undef notice
  128. #define notice(format, arg...) \
  129. printk(KERN_NOTICE "%s: " format "\n", \
  130. THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg)
  131. #undef warn
  132. #define warn(format, arg...) \
  133. printk(KERN_WARNING "%s: " format "\n", \
  134. THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg)
  135. #undef err
  136. #define err(format, arg...) \
  137. printk(KERN_ERR "%s: " format "\n", \
  138. THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg)
  139. #undef dbg
  140. #ifdef CONFIG_GIGASET_DEBUG
  141. #define dbg(level, format, arg...) \
  142. do { \
  143. if (unlikely(((enum debuglevel)gigaset_debuglevel) & (level))) \
  144. printk(KERN_DEBUG "%s: " format "\n", \
  145. THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" \
  146. , ## arg); \
  147. } while (0)
  148. #else
  149. #define dbg(level, format, arg...) do {} while (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. * - optionally, the following statistics on the buffer's usage can be
  318. * collected:
  319. * maxfill: maximum number of bytes occupied
  320. * idlefills: number of times a frame of idle bytes is prepared
  321. * emptygets: number of times the buffer was empty when a data frame was
  322. * requested
  323. * backtoback: number of times two data packets were entered into the buffer
  324. * without intervening idle flags
  325. * nakedback: set if no idle flags have been inserted since the last data
  326. * packet
  327. */
  328. struct isowbuf_t {
  329. atomic_t read;
  330. atomic_t nextread;
  331. atomic_t write;
  332. atomic_t writesem;
  333. int wbits;
  334. unsigned char data[BAS_OUTBUFSIZE + BAS_OUTBUFPAD];
  335. unsigned char idle;
  336. };
  337. /* isochronous write URB context structure
  338. * data to be stored along with the URB and retrieved when it is returned
  339. * as completed by the USB subsystem
  340. * - urb: pointer to the URB itself
  341. * - bcs: pointer to the B Channel control structure
  342. * - limit: end of write buffer area covered by this URB
  343. */
  344. struct isow_urbctx_t {
  345. struct urb *urb;
  346. struct bc_state *bcs;
  347. int limit;
  348. };
  349. /* AT state structure
  350. * data associated with the state of an ISDN connection, whether or not
  351. * it is currently assigned a B channel
  352. */
  353. struct at_state_t {
  354. struct list_head list;
  355. int waiting;
  356. int getstring;
  357. atomic_t timer_index;
  358. unsigned long timer_expires;
  359. int timer_active;
  360. unsigned int ConState; /* State of connection */
  361. struct reply_t *replystruct;
  362. int cid;
  363. int int_var[VAR_NUM]; /* see VAR_XXXX */
  364. char *str_var[STR_NUM]; /* see STR_XXXX */
  365. unsigned pending_commands; /* see PC_XXXX */
  366. atomic_t seq_index;
  367. struct cardstate *cs;
  368. struct bc_state *bcs;
  369. };
  370. struct resp_type_t {
  371. unsigned char *response;
  372. int resp_code; /* RSP_XXXX */
  373. int type; /* RT_XXXX */
  374. };
  375. struct event_t {
  376. int type;
  377. void *ptr, *arg;
  378. int parameter;
  379. int cid;
  380. struct at_state_t *at_state;
  381. };
  382. /* This buffer holds all information about the used B-Channel */
  383. struct bc_state {
  384. struct sk_buff *tx_skb; /* Current transfer buffer to modem */
  385. struct sk_buff_head squeue; /* B-Channel send Queue */
  386. /* Variables for debugging .. */
  387. int corrupted; /* Counter for corrupted packages */
  388. int trans_down; /* Counter of packages (downstream) */
  389. int trans_up; /* Counter of packages (upstream) */
  390. struct at_state_t at_state;
  391. unsigned long rcvbytes;
  392. __u16 fcs;
  393. struct sk_buff *skb;
  394. int inputstate; /* see INS_XXXX */
  395. int channel;
  396. struct cardstate *cs;
  397. unsigned chstate; /* bitmap (CHS_*) */
  398. int ignore;
  399. unsigned proto2; /* Layer 2 protocol (ISDN_PROTO_L2_*) */
  400. char *commands[AT_NUM]; /* see AT_XXXX */
  401. #ifdef CONFIG_GIGASET_DEBUG
  402. int emptycount;
  403. #endif
  404. int busy;
  405. int use_count;
  406. /* hardware drivers */
  407. union {
  408. struct ser_bc_state *ser; /* serial hardware driver */
  409. struct usb_bc_state *usb; /* usb hardware driver (m105) */
  410. struct bas_bc_state *bas; /* usb hardware driver (base) */
  411. } hw;
  412. };
  413. struct cardstate {
  414. struct gigaset_driver *driver;
  415. unsigned minor_index;
  416. const struct gigaset_ops *ops;
  417. /* Stuff to handle communication */
  418. wait_queue_head_t waitqueue;
  419. int waiting;
  420. atomic_t mode; /* see M_XXXX */
  421. atomic_t mstate; /* Modem state: see MS_XXXX */
  422. /* only changed by the event layer */
  423. int cmd_result;
  424. int channels;
  425. struct bc_state *bcs; /* Array of struct bc_state */
  426. int onechannel; /* data and commands transmitted in one
  427. stream (M10x) */
  428. spinlock_t lock;
  429. struct at_state_t at_state; /* at_state_t for cid == 0 */
  430. struct list_head temp_at_states;/* list of temporary "struct
  431. at_state_t"s without B channel */
  432. struct inbuf_t *inbuf;
  433. struct cmdbuf_t *cmdbuf, *lastcmdbuf;
  434. spinlock_t cmdlock;
  435. unsigned curlen, cmdbytes;
  436. unsigned open_count;
  437. struct tty_struct *tty;
  438. struct tasklet_struct if_wake_tasklet;
  439. unsigned control_state;
  440. unsigned fwver[4];
  441. int gotfwver;
  442. atomic_t running; /* !=0 if events are handled */
  443. atomic_t connected; /* !=0 if hardware is connected */
  444. atomic_t cidmode;
  445. int myid; /* id for communication with LL */
  446. isdn_if iif;
  447. struct reply_t *tabnocid;
  448. struct reply_t *tabcid;
  449. int cs_init;
  450. int ignoreframes; /* frames to ignore after setting up the
  451. B channel */
  452. struct semaphore sem; /* locks this structure: */
  453. /* connected is not changed, */
  454. /* hardware_up is not changed, */
  455. /* MState is not changed to or from
  456. MS_LOCKED */
  457. struct timer_list timer;
  458. int retry_count;
  459. int dle; /* !=0 if modem commands/responses are
  460. dle encoded */
  461. int cur_at_seq; /* sequence of AT commands being
  462. processed */
  463. int curchannel; /* channel, those commands are meant
  464. for */
  465. atomic_t commands_pending; /* flag(s) in xxx.commands_pending have
  466. been set */
  467. struct tasklet_struct event_tasklet;
  468. /* tasklet for serializing AT commands.
  469. * Scheduled
  470. * -> for modem reponses (and
  471. * incomming data for M10x)
  472. * -> on timeout
  473. * -> after setting bits in
  474. * xxx.at_state.pending_command
  475. * (e.g. command from LL) */
  476. struct tasklet_struct write_tasklet;
  477. /* tasklet for serial output
  478. * (not used in base driver) */
  479. /* event queue */
  480. struct event_t events[MAX_EVENTS];
  481. atomic_t ev_tail, ev_head;
  482. spinlock_t ev_lock;
  483. /* current modem response */
  484. unsigned char respdata[MAX_RESP_SIZE];
  485. unsigned cbytes;
  486. /* hardware drivers */
  487. union {
  488. struct usb_cardstate *usb; /* USB hardware driver (m105) */
  489. struct ser_cardstate *ser; /* serial hardware driver */
  490. struct bas_cardstate *bas; /* USB hardware driver (base) */
  491. } hw;
  492. };
  493. struct gigaset_driver {
  494. struct list_head list;
  495. spinlock_t lock; /* locks minor tables and blocked */
  496. struct tty_driver *tty;
  497. unsigned have_tty;
  498. unsigned minor;
  499. unsigned minors;
  500. struct cardstate *cs;
  501. unsigned *flags;
  502. int blocked;
  503. const struct gigaset_ops *ops;
  504. struct module *owner;
  505. };
  506. struct cmdbuf_t {
  507. struct cmdbuf_t *next, *prev;
  508. int len, offset;
  509. struct tasklet_struct *wake_tasklet;
  510. unsigned char buf[0];
  511. };
  512. struct bas_bc_state {
  513. /* isochronous output state */
  514. atomic_t running;
  515. atomic_t corrbytes;
  516. spinlock_t isooutlock;
  517. struct isow_urbctx_t isoouturbs[BAS_OUTURBS];
  518. struct isow_urbctx_t *isooutdone, *isooutfree, *isooutovfl;
  519. struct isowbuf_t *isooutbuf;
  520. unsigned numsub; /* submitted URB counter (for
  521. diagnostic messages only) */
  522. struct tasklet_struct sent_tasklet;
  523. /* isochronous input state */
  524. spinlock_t isoinlock;
  525. struct urb *isoinurbs[BAS_INURBS];
  526. unsigned char isoinbuf[BAS_INBUFSIZE * BAS_INURBS];
  527. struct urb *isoindone; /* completed isoc read URB */
  528. int loststatus; /* status of dropped URB */
  529. unsigned isoinlost; /* number of bytes lost */
  530. /* state of bit unstuffing algorithm (in addition to
  531. BC_state.inputstate) */
  532. unsigned seqlen; /* number of '1' bits not yet
  533. unstuffed */
  534. unsigned inbyte, inbits; /* collected bits for next byte
  535. */
  536. /* statistics */
  537. unsigned goodbytes; /* bytes correctly received */
  538. unsigned alignerrs; /* frames with incomplete byte
  539. at end */
  540. unsigned fcserrs; /* FCS errors */
  541. unsigned frameerrs; /* framing errors */
  542. unsigned giants; /* long frames */
  543. unsigned runts; /* short frames */
  544. unsigned aborts; /* HDLC aborts */
  545. unsigned shared0s; /* '0' bits shared between flags
  546. */
  547. unsigned stolen0s; /* '0' stuff bits also serving
  548. as leading flag bits */
  549. struct tasklet_struct rcvd_tasklet;
  550. };
  551. struct gigaset_ops {
  552. /* Called from ev-layer.c/interface.c for sending AT commands to the
  553. device */
  554. int (*write_cmd)(struct cardstate *cs,
  555. const unsigned char *buf, int len,
  556. struct tasklet_struct *wake_tasklet);
  557. /* Called from interface.c for additional device control */
  558. int (*write_room)(struct cardstate *cs);
  559. int (*chars_in_buffer)(struct cardstate *cs);
  560. int (*brkchars)(struct cardstate *cs, const unsigned char buf[6]);
  561. /* Called from ev-layer.c after setting up connection
  562. * Should call gigaset_bchannel_up(), when finished. */
  563. int (*init_bchannel)(struct bc_state *bcs);
  564. /* Called from ev-layer.c after hanging up
  565. * Should call gigaset_bchannel_down(), when finished. */
  566. int (*close_bchannel)(struct bc_state *bcs);
  567. /* Called by gigaset_initcs() for setting up bcs->hw.xxx */
  568. int (*initbcshw)(struct bc_state *bcs);
  569. /* Called by gigaset_freecs() for freeing bcs->hw.xxx */
  570. int (*freebcshw)(struct bc_state *bcs);
  571. /* Called by gigaset_stop() or gigaset_bchannel_down() for resetting
  572. bcs->hw.xxx */
  573. void (*reinitbcshw)(struct bc_state *bcs);
  574. /* Called by gigaset_initcs() for setting up cs->hw.xxx */
  575. int (*initcshw)(struct cardstate *cs);
  576. /* Called by gigaset_freecs() for freeing cs->hw.xxx */
  577. void (*freecshw)(struct cardstate *cs);
  578. /* Called from common.c/interface.c for additional serial port
  579. control */
  580. int (*set_modem_ctrl)(struct cardstate *cs, unsigned old_state,
  581. unsigned new_state);
  582. int (*baud_rate)(struct cardstate *cs, unsigned cflag);
  583. int (*set_line_ctrl)(struct cardstate *cs, unsigned cflag);
  584. /* Called from i4l.c to put an skb into the send-queue. */
  585. int (*send_skb)(struct bc_state *bcs, struct sk_buff *skb);
  586. /* Called from ev-layer.c to process a block of data
  587. * received through the common/control channel. */
  588. void (*handle_input)(struct inbuf_t *inbuf);
  589. };
  590. /* = Common structures and definitions ======================================= */
  591. /* Parser states for DLE-Event:
  592. * <DLE-EVENT>: <DLE_FLAG> "X" <EVENT> <DLE_FLAG> "."
  593. * <DLE_FLAG>: 0x10
  594. * <EVENT>: ((a-z)* | (A-Z)* | (0-10)*)+
  595. */
  596. #define DLE_FLAG 0x10
  597. /* ===========================================================================
  598. * Functions implemented in asyncdata.c
  599. */
  600. /* Called from i4l.c to put an skb into the send-queue.
  601. * After sending gigaset_skb_sent() should be called. */
  602. int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb);
  603. /* Called from ev-layer.c to process a block of data
  604. * received through the common/control channel. */
  605. void gigaset_m10x_input(struct inbuf_t *inbuf);
  606. /* ===========================================================================
  607. * Functions implemented in isocdata.c
  608. */
  609. /* Called from i4l.c to put an skb into the send-queue.
  610. * After sending gigaset_skb_sent() should be called. */
  611. int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb);
  612. /* Called from ev-layer.c to process a block of data
  613. * received through the common/control channel. */
  614. void gigaset_isoc_input(struct inbuf_t *inbuf);
  615. /* Called from bas-gigaset.c to process a block of data
  616. * received through the isochronous channel */
  617. void gigaset_isoc_receive(unsigned char *src, unsigned count,
  618. struct bc_state *bcs);
  619. /* Called from bas-gigaset.c to put a block of data
  620. * into the isochronous output buffer */
  621. int gigaset_isoc_buildframe(struct bc_state *bcs, unsigned char *in, int len);
  622. /* Called from bas-gigaset.c to initialize the isochronous output buffer */
  623. void gigaset_isowbuf_init(struct isowbuf_t *iwb, unsigned char idle);
  624. /* Called from bas-gigaset.c to retrieve a block of bytes for sending */
  625. int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size);
  626. /* ===========================================================================
  627. * Functions implemented in i4l.c/gigaset.h
  628. */
  629. /* Called by gigaset_initcs() for setting up with the isdn4linux subsystem */
  630. int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid);
  631. /* Called from xxx-gigaset.c to indicate completion of sending an skb */
  632. void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
  633. /* Called from common.c/ev-layer.c to indicate events relevant to the LL */
  634. int gigaset_isdn_icall(struct at_state_t *at_state);
  635. int gigaset_isdn_setup_accept(struct at_state_t *at_state);
  636. int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data);
  637. void gigaset_i4l_cmd(struct cardstate *cs, int cmd);
  638. void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd);
  639. static inline void gigaset_isdn_rcv_err(struct bc_state *bcs)
  640. {
  641. isdn_ctrl response;
  642. /* error -> LL */
  643. dbg(DEBUG_CMD, "sending L1ERR");
  644. response.driver = bcs->cs->myid;
  645. response.command = ISDN_STAT_L1ERR;
  646. response.arg = bcs->channel;
  647. response.parm.errcode = ISDN_STAT_L1ERR_RECV;
  648. bcs->cs->iif.statcallb(&response);
  649. }
  650. /* ===========================================================================
  651. * Functions implemented in ev-layer.c
  652. */
  653. /* tasklet called from common.c to process queued events */
  654. void gigaset_handle_event(unsigned long data);
  655. /* called from isocdata.c / asyncdata.c
  656. * when a complete modem response line has been received */
  657. void gigaset_handle_modem_response(struct cardstate *cs);
  658. /* ===========================================================================
  659. * Functions implemented in proc.c
  660. */
  661. /* initialize sysfs for device */
  662. void gigaset_init_dev_sysfs(struct usb_interface *interface);
  663. void gigaset_free_dev_sysfs(struct usb_interface *interface);
  664. /* ===========================================================================
  665. * Functions implemented in common.c/gigaset.h
  666. */
  667. void gigaset_bcs_reinit(struct bc_state *bcs);
  668. void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
  669. struct cardstate *cs, int cid);
  670. int gigaset_get_channel(struct bc_state *bcs);
  671. void gigaset_free_channel(struct bc_state *bcs);
  672. int gigaset_get_channels(struct cardstate *cs);
  673. void gigaset_free_channels(struct cardstate *cs);
  674. void gigaset_block_channels(struct cardstate *cs);
  675. /* Allocate and initialize driver structure. */
  676. struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
  677. const char *procname,
  678. const char *devname,
  679. const char *devfsname,
  680. const struct gigaset_ops *ops,
  681. struct module *owner);
  682. /* Deallocate driver structure. */
  683. void gigaset_freedriver(struct gigaset_driver *drv);
  684. void gigaset_debugdrivers(void);
  685. struct cardstate *gigaset_get_cs_by_minor(unsigned minor);
  686. struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty);
  687. struct cardstate *gigaset_get_cs_by_id(int id);
  688. /* For drivers without fixed assignment device<->cardstate (usb) */
  689. struct cardstate *gigaset_getunassignedcs(struct gigaset_driver *drv);
  690. void gigaset_unassign(struct cardstate *cs);
  691. void gigaset_blockdriver(struct gigaset_driver *drv);
  692. /* Allocate and initialize card state. Calls hardware dependent
  693. gigaset_init[b]cs(). */
  694. struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
  695. int onechannel, int ignoreframes,
  696. int cidmode, const char *modulename);
  697. /* Free card state. Calls hardware dependent gigaset_free[b]cs(). */
  698. void gigaset_freecs(struct cardstate *cs);
  699. /* Tell common.c that hardware and driver are ready. */
  700. int gigaset_start(struct cardstate *cs);
  701. /* Tell common.c that the device is not present any more. */
  702. void gigaset_stop(struct cardstate *cs);
  703. /* Tell common.c that the driver is being unloaded. */
  704. void gigaset_shutdown(struct cardstate *cs);
  705. /* Tell common.c that an skb has been sent. */
  706. void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
  707. /* Append event to the queue.
  708. * Returns NULL on failure or a pointer to the event on success.
  709. * ptr must be kmalloc()ed (and not be freed by the caller).
  710. */
  711. struct event_t *gigaset_add_event(struct cardstate *cs,
  712. struct at_state_t *at_state, int type,
  713. void *ptr, int parameter, void *arg);
  714. /* Called on CONFIG1 command from frontend. */
  715. int gigaset_enterconfigmode(struct cardstate *cs); //0: success <0: errorcode
  716. /* cs->lock must not be locked */
  717. static inline void gigaset_schedule_event(struct cardstate *cs)
  718. {
  719. unsigned long flags;
  720. spin_lock_irqsave(&cs->lock, flags);
  721. if (atomic_read(&cs->running))
  722. tasklet_schedule(&cs->event_tasklet);
  723. spin_unlock_irqrestore(&cs->lock, flags);
  724. }
  725. /* Tell common.c that B channel has been closed. */
  726. /* cs->lock must not be locked */
  727. static inline void gigaset_bchannel_down(struct bc_state *bcs)
  728. {
  729. gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_CLOSED, NULL, 0, NULL);
  730. dbg(DEBUG_CMD, "scheduling BC_CLOSED");
  731. gigaset_schedule_event(bcs->cs);
  732. }
  733. /* Tell common.c that B channel has been opened. */
  734. /* cs->lock must not be locked */
  735. static inline void gigaset_bchannel_up(struct bc_state *bcs)
  736. {
  737. gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_OPEN, NULL, 0, NULL);
  738. dbg(DEBUG_CMD, "scheduling BC_OPEN");
  739. gigaset_schedule_event(bcs->cs);
  740. }
  741. /* handling routines for sk_buff */
  742. /* ============================= */
  743. /* private version of __skb_put()
  744. * append 'len' bytes to the content of 'skb', already knowing that the
  745. * existing buffer can accomodate them
  746. * returns a pointer to the location where the new bytes should be copied to
  747. * This function does not take any locks so it must be called with the
  748. * appropriate locks held only.
  749. */
  750. static inline unsigned char *gigaset_skb_put_quick(struct sk_buff *skb,
  751. unsigned int len)
  752. {
  753. unsigned char *tmp = skb->tail;
  754. /*SKB_LINEAR_ASSERT(skb);*/ /* not needed here */
  755. skb->tail += len;
  756. skb->len += len;
  757. return tmp;
  758. }
  759. /* pass received skb to LL
  760. * Warning: skb must not be accessed anymore!
  761. */
  762. static inline void gigaset_rcv_skb(struct sk_buff *skb,
  763. struct cardstate *cs,
  764. struct bc_state *bcs)
  765. {
  766. cs->iif.rcvcallb_skb(cs->myid, bcs->channel, skb);
  767. bcs->trans_down++;
  768. }
  769. /* handle reception of corrupted skb
  770. * Warning: skb must not be accessed anymore!
  771. */
  772. static inline void gigaset_rcv_error(struct sk_buff *procskb,
  773. struct cardstate *cs,
  774. struct bc_state *bcs)
  775. {
  776. if (procskb)
  777. dev_kfree_skb(procskb);
  778. if (bcs->ignore)
  779. --bcs->ignore;
  780. else {
  781. ++bcs->corrupted;
  782. gigaset_isdn_rcv_err(bcs);
  783. }
  784. }
  785. /* bitwise byte inversion table */
  786. extern __u8 gigaset_invtab[]; /* in common.c */
  787. /* append received bytes to inbuf */
  788. static inline int gigaset_fill_inbuf(struct inbuf_t *inbuf,
  789. const unsigned char *src,
  790. unsigned numbytes)
  791. {
  792. unsigned n, head, tail, bytesleft;
  793. dbg(DEBUG_INTR, "received %u bytes", numbytes);
  794. if (!numbytes)
  795. return 0;
  796. bytesleft = numbytes;
  797. tail = atomic_read(&inbuf->tail);
  798. head = atomic_read(&inbuf->head);
  799. dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
  800. while (bytesleft) {
  801. if (head > tail)
  802. n = head - 1 - tail;
  803. else if (head == 0)
  804. n = (RBUFSIZE-1) - tail;
  805. else
  806. n = RBUFSIZE - tail;
  807. if (!n) {
  808. err("buffer overflow (%u bytes lost)", bytesleft);
  809. break;
  810. }
  811. if (n > bytesleft)
  812. n = bytesleft;
  813. memcpy(inbuf->data + tail, src, n);
  814. bytesleft -= n;
  815. tail = (tail + n) % RBUFSIZE;
  816. src += n;
  817. }
  818. dbg(DEBUG_INTR, "setting tail to %u", tail);
  819. atomic_set(&inbuf->tail, tail);
  820. return numbytes != bytesleft;
  821. }
  822. /* ===========================================================================
  823. * Functions implemented in interface.c
  824. */
  825. /* initialize interface */
  826. void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
  827. const char *devname, const char *devfsname);
  828. /* release interface */
  829. void gigaset_if_freedriver(struct gigaset_driver *drv);
  830. /* add minor */
  831. void gigaset_if_init(struct cardstate *cs);
  832. /* remove minor */
  833. void gigaset_if_free(struct cardstate *cs);
  834. /* device received data */
  835. void gigaset_if_receive(struct cardstate *cs,
  836. unsigned char *buffer, size_t len);
  837. #endif