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