hfcsusb.h 12 KB

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