1
2
3
4
5#ifndef __HFCSUSB_H__
6#define __HFCSUSB_H__
7
8
9#define DRIVER_NAME "HFC-S_USB"
10
11#define DBG_HFC_CALL_TRACE 0x00010000
12#define DBG_HFC_FIFO_VERBOSE 0x00020000
13#define DBG_HFC_USB_VERBOSE 0x00100000
14#define DBG_HFC_URB_INFO 0x00200000
15#define DBG_HFC_URB_ERROR 0x00400000
16
17#define DEFAULT_TRANSP_BURST_SZ 128
18
19#define HFC_CTRL_TIMEOUT 20
20#define CLKDEL_TE 0x0f
21#define CLKDEL_NT 0x6c
22
23
24#define HFC_L1_ACTIVATE_TE 1
25#define HFC_L1_ACTIVATE_NT 2
26#define HFC_L1_DEACTIVATE_NT 3
27#define HFC_L1_FORCE_DEACTIVATE_TE 4
28
29
30#define HFCUSB_LOAD_STATE 0x10
31#define HFCUSB_ACTIVATE 0x20
32#define HFCUSB_DO_ACTION 0x40
33#define HFCUSB_NT_G2_G3 0x80
34
35
36#define NT_ACTIVATION_TIMER 0x01
37#define NT_T1_COUNT 10
38
39#define MAX_BCH_SIZE 2048
40
41#define HFCUSB_RX_THRESHOLD 64
42#define HFCUSB_TX_THRESHOLD 96
43
44#define HFCUSB_CHIP_ID 0x16
45#define HFCUSB_CIRM 0x00
46#define HFCUSB_USB_SIZE 0x07
47#define HFCUSB_USB_SIZE_I 0x06
48#define HFCUSB_F_CROSS 0x0b
49#define HFCUSB_CLKDEL 0x37
50#define HFCUSB_CON_HDLC 0xfa
51#define HFCUSB_HDLC_PAR 0xfb
52#define HFCUSB_SCTRL 0x31
53#define HFCUSB_SCTRL_E 0x32
54#define HFCUSB_SCTRL_R 0x33
55#define HFCUSB_F_THRES 0x0c
56#define HFCUSB_FIFO 0x0f
57#define HFCUSB_F_USAGE 0x1a
58#define HFCUSB_MST_MODE0 0x14
59#define HFCUSB_MST_MODE1 0x15
60#define HFCUSB_P_DATA 0x1f
61#define HFCUSB_INC_RES_F 0x0e
62#define HFCUSB_B1_SSL 0x20
63#define HFCUSB_B2_SSL 0x21
64#define HFCUSB_B1_RSL 0x24
65#define HFCUSB_B2_RSL 0x25
66#define HFCUSB_STATES 0x30
67
68
69#define HFCUSB_CHIPID 0x40
70
71
72#define HFCUSB_NUM_FIFOS 8
73#define HFCUSB_B1_TX 0
74#define HFCUSB_B1_RX 1
75#define HFCUSB_B2_TX 2
76#define HFCUSB_B2_RX 3
77#define HFCUSB_D_TX 4
78#define HFCUSB_D_RX 5
79#define HFCUSB_PCM_TX 6
80#define HFCUSB_PCM_RX 7
81
82
83#define USB_INT 0
84#define USB_BULK 1
85#define USB_ISOC 2
86
87#define ISOC_PACKETS_D 8
88#define ISOC_PACKETS_B 8
89#define ISO_BUFFER_SIZE 128
90
91
92static int iso_packets[8] =
93{ ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B,
94 ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D
95};
96
97
98
99#define SINK_MAX 68
100#define SINK_MIN 48
101#define SINK_DMIN 12
102#define SINK_DMAX 18
103#define BITLINE_INF (-96 * 8)
104
105
106#define write_reg_atomic(a, b, c) \
107 usb_control_msg((a)->dev, (a)->ctrl_out_pipe, 0, 0x40, (c), (b), \
108 0, 0, HFC_CTRL_TIMEOUT)
109#define read_reg_atomic(a, b, c) \
110 usb_control_msg((a)->dev, (a)->ctrl_in_pipe, 1, 0xC0, 0, (b), (c), \
111 1, HFC_CTRL_TIMEOUT)
112#define HFC_CTRL_BUFSIZE 64
113
114struct ctrl_buf {
115 __u8 hfcs_reg;
116 __u8 reg_val;
117};
118
119
120
121
122
123struct hfcusb_symbolic_list {
124 const int num;
125 const char *name;
126};
127
128static struct hfcusb_symbolic_list urb_errlist[] = {
129 {-ENOMEM, "No memory for allocation of internal structures"},
130 {-ENOSPC, "The host controller's bandwidth is already consumed"},
131 {-ENOENT, "URB was canceled by unlink_urb"},
132 {-EXDEV, "ISO transfer only partially completed"},
133 {-EAGAIN, "Too match scheduled for the future"},
134 {-ENXIO, "URB already queued"},
135 {-EFBIG, "Too much ISO frames requested"},
136 {-ENOSR, "Buffer error (overrun)"},
137 {-EPIPE, "Specified endpoint is stalled (device not responding)"},
138 {-EOVERFLOW, "Babble (bad cable?)"},
139 {-EPROTO, "Bit-stuff error (bad cable?)"},
140 {-EILSEQ, "CRC/Timeout"},
141 {-ETIMEDOUT, "NAK (device does not respond)"},
142 {-ESHUTDOWN, "Device unplugged"},
143 {-1, NULL}
144};
145
146static inline const char *
147symbolic(struct hfcusb_symbolic_list list[], const int num)
148{
149 int i;
150 for (i = 0; list[i].name != NULL; i++)
151 if (list[i].num == num)
152 return list[i].name;
153 return "<unknown USB Error>";
154}
155
156
157#define CNF_4INT3ISO 1
158#define CNF_3INT3ISO 2
159#define CNF_4ISO3ISO 3
160#define CNF_3ISO3ISO 4
161
162#define EP_NUL 1
163#define EP_NOP 2
164#define EP_ISO 3
165#define EP_BLK 4
166#define EP_INT 5
167
168#define HFC_CHAN_B1 0
169#define HFC_CHAN_B2 1
170#define HFC_CHAN_D 2
171#define HFC_CHAN_E 3
172
173
174
175
176
177
178
179
180
181static int
182validconf[][19] = {
183
184 {EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NOP, EP_INT,
185 EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_NUL, EP_NUL,
186 CNF_4INT3ISO, 2, 1},
187 {EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NUL, EP_NUL,
188 EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_NUL, EP_NUL,
189 CNF_3INT3ISO, 2, 0},
190
191 {EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP,
192 EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_NOP, EP_ISO,
193 CNF_4ISO3ISO, 2, 1},
194 {EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL,
195 EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_NUL, EP_NUL,
196 CNF_3ISO3ISO, 2, 0},
197 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
198};
199
200
201static char *conf_str[] = {
202 "4 Interrupt IN + 3 Isochron OUT",
203 "3 Interrupt IN + 3 Isochron OUT",
204 "4 Isochron IN + 3 Isochron OUT",
205 "3 Isochron IN + 3 Isochron OUT"
206};
207
208
209#define LED_OFF 0
210#define LED_SCHEME1 1
211#define LED_SCHEME2 2
212
213#define LED_POWER_ON 1
214#define LED_POWER_OFF 2
215#define LED_S0_ON 3
216#define LED_S0_OFF 4
217#define LED_B1_ON 5
218#define LED_B1_OFF 6
219#define LED_B1_DATA 7
220#define LED_B2_ON 8
221#define LED_B2_OFF 9
222#define LED_B2_DATA 10
223
224#define LED_NORMAL 0
225#define LED_INVERTED 1
226
227
228#define LED_TIME 250
229
230
231
232struct hfcsusb;
233struct usb_fifo;
234
235
236struct iso_urb {
237 struct urb *urb;
238 __u8 buffer[ISO_BUFFER_SIZE];
239 struct usb_fifo *owner_fifo;
240 __u8 indx;
241#ifdef ISO_FRAME_START_DEBUG
242 int start_frames[ISO_FRAME_START_RING_COUNT];
243 __u8 iso_frm_strt_pos;
244#endif
245};
246
247struct usb_fifo {
248 int fifonum;
249 int active;
250 struct hfcsusb *hw;
251 int pipe;
252 __u8 usb_packet_maxlen;
253 unsigned int max_size;
254 __u8 intervall;
255 struct urb *urb;
256 __u8 buffer[128];
257 int bit_line;
258
259 __u8 usb_transfer_mode;
260 struct iso_urb iso[2];
261
262
263 struct dchannel *dch;
264 struct bchannel *bch;
265 struct dchannel *ech;
266 int last_urblen;
267 __u8 stop_gracefull;
268};
269
270struct hfcsusb {
271 struct list_head list;
272 struct dchannel dch;
273 struct bchannel bch[2];
274 struct dchannel ech;
275
276 struct usb_device *dev;
277 struct usb_interface *intf;
278 int if_used;
279 int alt_used;
280 int cfg_used;
281 int vend_idx;
282 int packet_size;
283 int iso_packet_size;
284 struct usb_fifo fifos[HFCUSB_NUM_FIFOS];
285
286
287 struct ctrl_buf ctrl_buff[HFC_CTRL_BUFSIZE];
288 int ctrl_in_idx, ctrl_out_idx, ctrl_cnt;
289 struct urb *ctrl_urb;
290 struct usb_ctrlrequest ctrl_write;
291 struct usb_ctrlrequest ctrl_read;
292 int ctrl_paksize;
293 int ctrl_in_pipe, ctrl_out_pipe;
294 spinlock_t ctrl_lock;
295 spinlock_t lock;
296
297 __u8 threshold_mask;
298 __u8 led_state;
299
300 __u8 protocol;
301 int nt_timer;
302 int open;
303 __u8 timers;
304 __u8 initdone;
305 char name[MISDN_MAX_IDLEN];
306};
307
308
309struct hfcsusb_vdata {
310 __u8 led_scheme;
311 signed short led_bits[8];
312 char *vend_name;
313};
314
315
316#define HFC_MAX_TE_LAYER1_STATE 8
317#define HFC_MAX_NT_LAYER1_STATE 4
318
319static const char *HFC_TE_LAYER1_STATES[HFC_MAX_TE_LAYER1_STATE + 1] = {
320 "TE F0 - Reset",
321 "TE F1 - Reset",
322 "TE F2 - Sensing",
323 "TE F3 - Deactivated",
324 "TE F4 - Awaiting signal",
325 "TE F5 - Identifying input",
326 "TE F6 - Synchronized",
327 "TE F7 - Activated",
328 "TE F8 - Lost framing",
329};
330
331static const char *HFC_NT_LAYER1_STATES[HFC_MAX_NT_LAYER1_STATE + 1] = {
332 "NT G0 - Reset",
333 "NT G1 - Deactive",
334 "NT G2 - Pending activation",
335 "NT G3 - Active",
336 "NT G4 - Pending deactivation",
337};
338
339
340static struct usb_device_id hfcsusb_idtab[] = {
341 {
342 USB_DEVICE(0x0959, 0x2bd0),
343 .driver_info = (unsigned long) &((struct hfcsusb_vdata)
344 {LED_OFF, {4, 0, 2, 1},
345 "ISDN USB TA (Cologne Chip HFC-S USB based)"}),
346 },
347 {
348 USB_DEVICE(0x0675, 0x1688),
349 .driver_info = (unsigned long) &((struct hfcsusb_vdata)
350 {LED_SCHEME1, {1, 2, 0, 0},
351 "DrayTek miniVigor 128 USB ISDN TA"}),
352 },
353 {
354 USB_DEVICE(0x07b0, 0x0007),
355 .driver_info = (unsigned long) &((struct hfcsusb_vdata)
356 {LED_SCHEME1, {0x80, -64, -32, -16},
357 "Billion tiny USB ISDN TA 128"}),
358 },
359 {
360 USB_DEVICE(0x0742, 0x2008),
361 .driver_info = (unsigned long) &((struct hfcsusb_vdata)
362 {LED_SCHEME1, {4, 0, 2, 1},
363 "Stollmann USB TA"}),
364 },
365 {
366 USB_DEVICE(0x0742, 0x2009),
367 .driver_info = (unsigned long) &((struct hfcsusb_vdata)
368 {LED_SCHEME1, {4, 0, 2, 1},
369 "Aceex USB ISDN TA"}),
370 },
371 {
372 USB_DEVICE(0x0742, 0x200A),
373 .driver_info = (unsigned long) &((struct hfcsusb_vdata)
374 {LED_SCHEME1, {4, 0, 2, 1},
375 "OEM USB ISDN TA"}),
376 },
377 {
378 USB_DEVICE(0x08e3, 0x0301),
379 .driver_info = (unsigned long) &((struct hfcsusb_vdata)
380 {LED_SCHEME1, {2, 0, 1, 4},
381 "Olitec USB RNIS"}),
382 },
383 {
384 USB_DEVICE(0x07fa, 0x0846),
385 .driver_info = (unsigned long) &((struct hfcsusb_vdata)
386 {LED_SCHEME1, {0x80, -64, -32, -16},
387 "Bewan Modem RNIS USB"}),
388 },
389 {
390 USB_DEVICE(0x07fa, 0x0847),
391 .driver_info = (unsigned long) &((struct hfcsusb_vdata)
392 {LED_SCHEME1, {0x80, -64, -32, -16},
393 "Djinn Numeris USB"}),
394 },
395 {
396 USB_DEVICE(0x07b0, 0x0006),
397 .driver_info = (unsigned long) &((struct hfcsusb_vdata)
398 {LED_SCHEME1, {0x80, -64, -32, -16},
399 "Twister ISDN TA"}),
400 },
401 {
402 USB_DEVICE(0x071d, 0x1005),
403 .driver_info = (unsigned long) &((struct hfcsusb_vdata)
404 {LED_SCHEME1, {0x02, 0, 0x01, 0x04},
405 "Eicon DIVA USB 4.0"}),
406 },
407 {
408 USB_DEVICE(0x0586, 0x0102),
409 .driver_info = (unsigned long) &((struct hfcsusb_vdata)
410 {LED_SCHEME1, {0x88, -64, -32, -16},
411 "ZyXEL OMNI.NET USB II"}),
412 },
413 {
414 USB_DEVICE(0x1ae7, 0x0525),
415 .driver_info = (unsigned long) &((struct hfcsusb_vdata)
416 {LED_SCHEME1, {0x88, -64, -32, -16},
417 "X-Tensions USB ISDN TA XC-525"}),
418 },
419 { }
420};
421
422MODULE_DEVICE_TABLE(usb, hfcsusb_idtab);
423
424#endif
425