hfcsusb.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /*
  2. * hfcsusb.h, HFC-S USB mISDN driver
  3. */
  4. #ifndef __HFCSUSB_H__
  5. #define __HFCSUSB_H__
  6. #define DRIVER_NAME "HFC-S_USB"
  7. #define DBG_HFC_CALL_TRACE 0x00010000
  8. #define DBG_HFC_FIFO_VERBOSE 0x00020000
  9. #define DBG_HFC_USB_VERBOSE 0x00100000
  10. #define DBG_HFC_URB_INFO 0x00200000
  11. #define DBG_HFC_URB_ERROR 0x00400000
  12. #define DEFAULT_TRANSP_BURST_SZ 128
  13. #define HFC_CTRL_TIMEOUT 20 /* 5ms timeout writing/reading regs */
  14. #define CLKDEL_TE 0x0f /* CLKDEL in TE mode */
  15. #define CLKDEL_NT 0x6c /* CLKDEL in NT mode */
  16. /* hfcsusb Layer1 commands */
  17. #define HFC_L1_ACTIVATE_TE 1
  18. #define HFC_L1_ACTIVATE_NT 2
  19. #define HFC_L1_DEACTIVATE_NT 3
  20. #define HFC_L1_FORCE_DEACTIVATE_TE 4
  21. /* cmd FLAGS in HFCUSB_STATES register */
  22. #define HFCUSB_LOAD_STATE 0x10
  23. #define HFCUSB_ACTIVATE 0x20
  24. #define HFCUSB_DO_ACTION 0x40
  25. #define HFCUSB_NT_G2_G3 0x80
  26. /* timers */
  27. #define NT_ACTIVATION_TIMER 0x01 /* enables NT mode activation Timer */
  28. #define NT_T1_COUNT 10
  29. #define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */
  30. #define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */
  31. #define HFCUSB_TX_THRESHOLD 96 /* threshold for fifo report bit tx */
  32. #define HFCUSB_CHIP_ID 0x16 /* Chip ID register index */
  33. #define HFCUSB_CIRM 0x00 /* cirm register index */
  34. #define HFCUSB_USB_SIZE 0x07 /* int length register */
  35. #define HFCUSB_USB_SIZE_I 0x06 /* iso length register */
  36. #define HFCUSB_F_CROSS 0x0b /* bit order register */
  37. #define HFCUSB_CLKDEL 0x37 /* bit delay register */
  38. #define HFCUSB_CON_HDLC 0xfa /* channel connect register */
  39. #define HFCUSB_HDLC_PAR 0xfb
  40. #define HFCUSB_SCTRL 0x31 /* S-bus control register (tx) */
  41. #define HFCUSB_SCTRL_E 0x32 /* same for E and special funcs */
  42. #define HFCUSB_SCTRL_R 0x33 /* S-bus control register (rx) */
  43. #define HFCUSB_F_THRES 0x0c /* threshold register */
  44. #define HFCUSB_FIFO 0x0f /* fifo select register */
  45. #define HFCUSB_F_USAGE 0x1a /* fifo usage register */
  46. #define HFCUSB_MST_MODE0 0x14
  47. #define HFCUSB_MST_MODE1 0x15
  48. #define HFCUSB_P_DATA 0x1f
  49. #define HFCUSB_INC_RES_F 0x0e
  50. #define HFCUSB_B1_SSL 0x20
  51. #define HFCUSB_B2_SSL 0x21
  52. #define HFCUSB_B1_RSL 0x24
  53. #define HFCUSB_B2_RSL 0x25
  54. #define HFCUSB_STATES 0x30
  55. #define HFCUSB_CHIPID 0x40 /* ID value of HFC-S USB */
  56. /* fifo registers */
  57. #define HFCUSB_NUM_FIFOS 8 /* maximum number of fifos */
  58. #define HFCUSB_B1_TX 0 /* index for B1 transmit bulk/int */
  59. #define HFCUSB_B1_RX 1 /* index for B1 receive bulk/int */
  60. #define HFCUSB_B2_TX 2
  61. #define HFCUSB_B2_RX 3
  62. #define HFCUSB_D_TX 4
  63. #define HFCUSB_D_RX 5
  64. #define HFCUSB_PCM_TX 6
  65. #define HFCUSB_PCM_RX 7
  66. #define USB_INT 0
  67. #define USB_BULK 1
  68. #define USB_ISOC 2
  69. #define ISOC_PACKETS_D 8
  70. #define ISOC_PACKETS_B 8
  71. #define ISO_BUFFER_SIZE 128
  72. /* defines how much ISO packets are handled in one URB */
  73. static int iso_packets[8] =
  74. { ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B,
  75. ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D
  76. };
  77. /* Fifo flow Control for TX ISO */
  78. #define SINK_MAX 68
  79. #define SINK_MIN 48
  80. #define SINK_DMIN 12
  81. #define SINK_DMAX 18
  82. #define BITLINE_INF (-96 * 8)
  83. /* HFC-S USB register access by Control-URSs */
  84. #define write_reg_atomic(a, b, c) \
  85. usb_control_msg((a)->dev, (a)->ctrl_out_pipe, 0, 0x40, (c), (b), \
  86. 0, 0, HFC_CTRL_TIMEOUT)
  87. #define read_reg_atomic(a, b, c) \
  88. usb_control_msg((a)->dev, (a)->ctrl_in_pipe, 1, 0xC0, 0, (b), (c), \
  89. 1, HFC_CTRL_TIMEOUT)
  90. #define HFC_CTRL_BUFSIZE 64
  91. struct ctrl_buf {
  92. __u8 hfcs_reg; /* register number */
  93. __u8 reg_val; /* value to be written (or read) */
  94. };
  95. /*
  96. * URB error codes
  97. * Used to represent a list of values and their respective symbolic names
  98. */
  99. struct hfcusb_symbolic_list {
  100. const int num;
  101. const char *name;
  102. };
  103. static struct hfcusb_symbolic_list urb_errlist[] = {
  104. {-ENOMEM, "No memory for allocation of internal structures"},
  105. {-ENOSPC, "The host controller's bandwidth is already consumed"},
  106. {-ENOENT, "URB was canceled by unlink_urb"},
  107. {-EXDEV, "ISO transfer only partially completed"},
  108. {-EAGAIN, "Too match scheduled for the future"},
  109. {-ENXIO, "URB already queued"},
  110. {-EFBIG, "Too much ISO frames requested"},
  111. {-ENOSR, "Buffer error (overrun)"},
  112. {-EPIPE, "Specified endpoint is stalled (device not responding)"},
  113. {-EOVERFLOW, "Babble (bad cable?)"},
  114. {-EPROTO, "Bit-stuff error (bad cable?)"},
  115. {-EILSEQ, "CRC/Timeout"},
  116. {-ETIMEDOUT, "NAK (device does not respond)"},
  117. {-ESHUTDOWN, "Device unplugged"},
  118. {-1, NULL}
  119. };
  120. static inline const char *
  121. symbolic(struct hfcusb_symbolic_list list[], const int num)
  122. {
  123. int i;
  124. for (i = 0; list[i].name != NULL; i++)
  125. if (list[i].num == num)
  126. return list[i].name;
  127. return "<unknown USB Error>";
  128. }
  129. /* USB descriptor need to contain one of the following EndPoint combination: */
  130. #define CNF_4INT3ISO 1 /* 4 INT IN, 3 ISO OUT */
  131. #define CNF_3INT3ISO 2 /* 3 INT IN, 3 ISO OUT */
  132. #define CNF_4ISO3ISO 3 /* 4 ISO IN, 3 ISO OUT */
  133. #define CNF_3ISO3ISO 4 /* 3 ISO IN, 3 ISO OUT */
  134. #define EP_NUL 1 /* Endpoint at this position not allowed */
  135. #define EP_NOP 2 /* all type of endpoints allowed at this position */
  136. #define EP_ISO 3 /* Isochron endpoint mandatory at this position */
  137. #define EP_BLK 4 /* Bulk endpoint mandatory at this position */
  138. #define EP_INT 5 /* Interrupt endpoint mandatory at this position */
  139. #define HFC_CHAN_B1 0
  140. #define HFC_CHAN_B2 1
  141. #define HFC_CHAN_D 2
  142. #define HFC_CHAN_E 3
  143. /*
  144. * List of all supported enpoints configiration sets, used to find the
  145. * best matching endpoint configuration within a devices' USB descriptor.
  146. * We need at least 3 RX endpoints, and 3 TX endpoints, either
  147. * INT-in and ISO-out, or ISO-in and ISO-out)
  148. * with 4 RX endpoints even E-Channel logging is possible
  149. */
  150. static int
  151. validconf[][19] = {
  152. /* INT in, ISO out config */
  153. {EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NOP, EP_INT,
  154. EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_NUL, EP_NUL,
  155. CNF_4INT3ISO, 2, 1},
  156. {EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NUL, EP_NUL,
  157. EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_NUL, EP_NUL,
  158. CNF_3INT3ISO, 2, 0},
  159. /* ISO in, ISO out config */
  160. {EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP,
  161. EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_NOP, EP_ISO,
  162. CNF_4ISO3ISO, 2, 1},
  163. {EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL,
  164. EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_NUL, EP_NUL,
  165. CNF_3ISO3ISO, 2, 0},
  166. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* EOL element */
  167. };
  168. /* string description of chosen config */
  169. static char *conf_str[] = {
  170. "4 Interrupt IN + 3 Isochron OUT",
  171. "3 Interrupt IN + 3 Isochron OUT",
  172. "4 Isochron IN + 3 Isochron OUT",
  173. "3 Isochron IN + 3 Isochron OUT"
  174. };
  175. #define LED_OFF 0 /* no LED support */
  176. #define LED_SCHEME1 1 /* LED standard scheme */
  177. #define LED_SCHEME2 2 /* not used yet... */
  178. #define LED_POWER_ON 1
  179. #define LED_POWER_OFF 2
  180. #define LED_S0_ON 3
  181. #define LED_S0_OFF 4
  182. #define LED_B1_ON 5
  183. #define LED_B1_OFF 6
  184. #define LED_B1_DATA 7
  185. #define LED_B2_ON 8
  186. #define LED_B2_OFF 9
  187. #define LED_B2_DATA 10
  188. #define LED_NORMAL 0 /* LEDs are normal */
  189. #define LED_INVERTED 1 /* LEDs are inverted */
  190. /* time in ms to perform a Flashing LED when B-Channel has traffic */
  191. #define LED_TIME 250
  192. struct hfcsusb;
  193. struct usb_fifo;
  194. /* structure defining input+output fifos (interrupt/bulk mode) */
  195. struct iso_urb {
  196. struct urb *urb;
  197. __u8 buffer[ISO_BUFFER_SIZE]; /* buffer rx/tx USB URB data */
  198. struct usb_fifo *owner_fifo; /* pointer to owner fifo */
  199. __u8 indx; /* Fifos's ISO double buffer 0 or 1 ? */
  200. #ifdef ISO_FRAME_START_DEBUG
  201. int start_frames[ISO_FRAME_START_RING_COUNT];
  202. __u8 iso_frm_strt_pos; /* index in start_frame[] */
  203. #endif
  204. };
  205. struct usb_fifo {
  206. int fifonum; /* fifo index attached to this structure */
  207. int active; /* fifo is currently active */
  208. struct hfcsusb *hw; /* pointer to main structure */
  209. int pipe; /* address of endpoint */
  210. __u8 usb_packet_maxlen; /* maximum length for usb transfer */
  211. unsigned int max_size; /* maximum size of receive/send packet */
  212. __u8 intervall; /* interrupt interval */
  213. struct urb *urb; /* transfer structure for usb routines */
  214. __u8 buffer[128]; /* buffer USB INT OUT URB data */
  215. int bit_line; /* how much bits are in the fifo? */
  216. __u8 usb_transfer_mode; /* switched between ISO and INT */
  217. struct iso_urb iso[2]; /* two urbs to have one always
  218. one pending */
  219. struct dchannel *dch; /* link to hfcsusb_t->dch */
  220. struct bchannel *bch; /* link to hfcsusb_t->bch */
  221. struct dchannel *ech; /* link to hfcsusb_t->ech, TODO: E-CHANNEL */
  222. int last_urblen; /* remember length of last packet */
  223. __u8 stop_gracefull; /* stops URB retransmission */
  224. };
  225. struct hfcsusb {
  226. struct list_head list;
  227. struct dchannel dch;
  228. struct bchannel bch[2];
  229. struct dchannel ech; /* TODO : wait for struct echannel ;) */
  230. struct usb_device *dev; /* our device */
  231. struct usb_interface *intf; /* used interface */
  232. int if_used; /* used interface number */
  233. int alt_used; /* used alternate config */
  234. int cfg_used; /* configuration index used */
  235. int vend_idx; /* index in hfcsusb_idtab */
  236. int packet_size;
  237. int iso_packet_size;
  238. struct usb_fifo fifos[HFCUSB_NUM_FIFOS];
  239. /* control pipe background handling */
  240. struct ctrl_buf ctrl_buff[HFC_CTRL_BUFSIZE];
  241. int ctrl_in_idx, ctrl_out_idx, ctrl_cnt;
  242. struct urb *ctrl_urb;
  243. struct usb_ctrlrequest ctrl_write;
  244. struct usb_ctrlrequest ctrl_read;
  245. int ctrl_paksize;
  246. int ctrl_in_pipe, ctrl_out_pipe;
  247. spinlock_t ctrl_lock; /* lock for ctrl */
  248. spinlock_t lock;
  249. __u8 threshold_mask;
  250. __u8 led_state;
  251. __u8 protocol;
  252. int nt_timer;
  253. int open;
  254. __u8 timers;
  255. __u8 initdone;
  256. char name[MISDN_MAX_IDLEN];
  257. };
  258. /* private vendor specific data */
  259. struct hfcsusb_vdata {
  260. __u8 led_scheme; /* led display scheme */
  261. signed short led_bits[8]; /* array of 8 possible LED bitmask */
  262. char *vend_name; /* device name */
  263. };
  264. #define HFC_MAX_TE_LAYER1_STATE 8
  265. #define HFC_MAX_NT_LAYER1_STATE 4
  266. static const char *HFC_TE_LAYER1_STATES[HFC_MAX_TE_LAYER1_STATE + 1] = {
  267. "TE F0 - Reset",
  268. "TE F1 - Reset",
  269. "TE F2 - Sensing",
  270. "TE F3 - Deactivated",
  271. "TE F4 - Awaiting signal",
  272. "TE F5 - Identifying input",
  273. "TE F6 - Synchronized",
  274. "TE F7 - Activated",
  275. "TE F8 - Lost framing",
  276. };
  277. static const char *HFC_NT_LAYER1_STATES[HFC_MAX_NT_LAYER1_STATE + 1] = {
  278. "NT G0 - Reset",
  279. "NT G1 - Deactive",
  280. "NT G2 - Pending activation",
  281. "NT G3 - Active",
  282. "NT G4 - Pending deactivation",
  283. };
  284. /* supported devices */
  285. static struct usb_device_id hfcsusb_idtab[] = {
  286. {
  287. USB_DEVICE(0x0959, 0x2bd0),
  288. .driver_info = (unsigned long) &((struct hfcsusb_vdata)
  289. {LED_OFF, {4, 0, 2, 1},
  290. "ISDN USB TA (Cologne Chip HFC-S USB based)"}),
  291. },
  292. {
  293. USB_DEVICE(0x0675, 0x1688),
  294. .driver_info = (unsigned long) &((struct hfcsusb_vdata)
  295. {LED_SCHEME1, {1, 2, 0, 0},
  296. "DrayTek miniVigor 128 USB ISDN TA"}),
  297. },
  298. {
  299. USB_DEVICE(0x07b0, 0x0007),
  300. .driver_info = (unsigned long) &((struct hfcsusb_vdata)
  301. {LED_SCHEME1, {0x80, -64, -32, -16},
  302. "Billion tiny USB ISDN TA 128"}),
  303. },
  304. {
  305. USB_DEVICE(0x0742, 0x2008),
  306. .driver_info = (unsigned long) &((struct hfcsusb_vdata)
  307. {LED_SCHEME1, {4, 0, 2, 1},
  308. "Stollmann USB TA"}),
  309. },
  310. {
  311. USB_DEVICE(0x0742, 0x2009),
  312. .driver_info = (unsigned long) &((struct hfcsusb_vdata)
  313. {LED_SCHEME1, {4, 0, 2, 1},
  314. "Aceex USB ISDN TA"}),
  315. },
  316. {
  317. USB_DEVICE(0x0742, 0x200A),
  318. .driver_info = (unsigned long) &((struct hfcsusb_vdata)
  319. {LED_SCHEME1, {4, 0, 2, 1},
  320. "OEM USB ISDN TA"}),
  321. },
  322. {
  323. USB_DEVICE(0x08e3, 0x0301),
  324. .driver_info = (unsigned long) &((struct hfcsusb_vdata)
  325. {LED_SCHEME1, {2, 0, 1, 4},
  326. "Olitec USB RNIS"}),
  327. },
  328. {
  329. USB_DEVICE(0x07fa, 0x0846),
  330. .driver_info = (unsigned long) &((struct hfcsusb_vdata)
  331. {LED_SCHEME1, {0x80, -64, -32, -16},
  332. "Bewan Modem RNIS USB"}),
  333. },
  334. {
  335. USB_DEVICE(0x07fa, 0x0847),
  336. .driver_info = (unsigned long) &((struct hfcsusb_vdata)
  337. {LED_SCHEME1, {0x80, -64, -32, -16},
  338. "Djinn Numeris USB"}),
  339. },
  340. {
  341. USB_DEVICE(0x07b0, 0x0006),
  342. .driver_info = (unsigned long) &((struct hfcsusb_vdata)
  343. {LED_SCHEME1, {0x80, -64, -32, -16},
  344. "Twister ISDN TA"}),
  345. },
  346. {
  347. USB_DEVICE(0x071d, 0x1005),
  348. .driver_info = (unsigned long) &((struct hfcsusb_vdata)
  349. {LED_SCHEME1, {0x02, 0, 0x01, 0x04},
  350. "Eicon DIVA USB 4.0"}),
  351. },
  352. {
  353. USB_DEVICE(0x0586, 0x0102),
  354. .driver_info = (unsigned long) &((struct hfcsusb_vdata)
  355. {LED_SCHEME1, {0x88, -64, -32, -16},
  356. "ZyXEL OMNI.NET USB II"}),
  357. },
  358. {
  359. USB_DEVICE(0x1ae7, 0x0525),
  360. .driver_info = (unsigned long) &((struct hfcsusb_vdata)
  361. {LED_SCHEME1, {0x88, -64, -32, -16},
  362. "X-Tensions USB ISDN TA XC-525"}),
  363. },
  364. { }
  365. };
  366. MODULE_DEVICE_TABLE(usb, hfcsusb_idtab);
  367. #endif /* __HFCSUSB_H__ */