backport mv88e6095 support for orion - this also fixes the non-working switch-port...
[openwrt.git] / target / linux / generic-2.4 / patches / 201-hfc_usb_backport.patch
1 Index: linux-2.4.35.4/drivers/Makefile
2 ===================================================================
3 --- linux-2.4.35.4.orig/drivers/Makefile
4 +++ linux-2.4.35.4/drivers/Makefile
5 @@ -38,7 +38,7 @@ subdir-$(CONFIG_FUSION) += message/fusi
6 subdir-$(CONFIG_MD) += md
7 subdir-$(CONFIG_IEEE1394) += ieee1394
8 subdir-$(CONFIG_PNP) += pnp
9 -subdir-$(CONFIG_ISDN_BOOL) += isdn
10 +subdir-$(CONFIG_ISDN) += isdn
11 subdir-$(CONFIG_ATM) += atm
12 subdir-$(CONFIG_FC4) += fc4
13
14 Index: linux-2.4.35.4/drivers/isdn/hisax/hfc_usb.c
15 ===================================================================
16 --- linux-2.4.35.4.orig/drivers/isdn/hisax/hfc_usb.c
17 +++ linux-2.4.35.4/drivers/isdn/hisax/hfc_usb.c
18 @@ -1,13 +1,11 @@
19 -/* $Id: hfc_usb.c,v 2.3 2001/07/06 21:30:11 werner Exp $
20 +/*
21 + * hfc_usb.c
22 *
23 + * modular HiSax ISDN driver for Colognechip HFC-USB chip
24 *
25 - *
26 - * Author (C) 2001 Werner Cornelius (werner@isdn-development.de)
27 - * modular driver for Colognechip HFC-USB chip
28 - * as plugin for HiSax isdn driver
29 - * type approval valid for HFC-S USB based TAs
30 - *
31 - * Copyright 2001 by Werner Cornelius (werner@isdn-development.de)
32 + * Authors : Peter Sprenger (sprenger@moving-byters.de)
33 + * Martin Bachem (info@colognechip.com)
34 + * based on the first hfc_usb driver of Werner Cornelius (werner@isdn-development.de)
35 *
36 * This program is free software; you can redistribute it and/or modify
37 * it under the terms of the GNU General Public License as published by
38 @@ -23,70 +21,90 @@
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
41 *
42 - */
43 + * 2005_Mar_16 grsch
44 + * ported 2.6.8 hfc_usb.c to 2.4.20 format
45 + * Gregor Schaffrath <gschaff@ran-dom.org>
46 +*/
47 +
48
49 #include <linux/types.h>
50 #include <linux/stddef.h>
51 #include <linux/timer.h>
52 #include <linux/config.h>
53 -#include <linux/isdn_compat.h>
54 #include <linux/init.h>
55 #include "hisax.h"
56 #include <linux/module.h>
57 #include <linux/kernel_stat.h>
58 -#include <linux/tqueue.h>
59 #include <linux/usb.h>
60 #include <linux/kernel.h>
61 #include <linux/smp_lock.h>
62 #include <linux/sched.h>
63 +#include "hisax_if.h"
64 #include "hisax_loadable.h"
65
66 +static const char *hfcusb_revision = "4.0";
67 +
68 +/*
69 + to enable much mire debug messages in this driver, define
70 + VERBOSE_USB_DEBUG and VERBOSE_ISDN_DEBUG
71 + below
72 +*/
73 +
74 +#define VERBOSE_USB_DEBUG
75 +#define VERBOSE_ISDN_DEBUG
76 +
77 #define INCLUDE_INLINE_FUNCS
78
79 +#define TRUE 1
80 +#define FALSE 0
81 +
82 +
83 /***********/
84 /* defines */
85 /***********/
86 -#define HFC_CTRL_TIMEOUT 5 /* 5ms timeout writing/reading regs */
87 -#define HFC_TIMER_T3 7000 /* timeout for l1 activation timer */
88 -
89 -#define HFCUSB_L1_STATECHANGE 0 /* L1 state changed */
90 -#define HFCUSB_L1_DRX 1 /* D-frame received */
91 -#define HFCUSB_L1_ERX 2 /* E-frame received */
92 -#define HFCUSB_L1_DTX 4 /* D-frames completed */
93 -
94 -#define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */
95 -
96 -#define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */
97 -#define HFCUSB_TX_THRESHOLD 64 /* threshold for fifo report bit tx */
98 -
99 -#define HFCUSB_CHIP_ID 0x16 /* Chip ID register index */
100 -#define HFCUSB_CIRM 0x00 /* cirm register index */
101 -#define HFCUSB_USB_SIZE 0x07 /* int length register */
102 -#define HFCUSB_USB_SIZE_I 0x06 /* iso length register */
103 -#define HFCUSB_F_CROSS 0x0b /* bit order register */
104 -#define HFCUSB_CLKDEL 0x37 /* bit delay register */
105 -#define HFCUSB_CON_HDLC 0xfa /* channel connect register */
106 +#define HFC_CTRL_TIMEOUT 20 //(HZ * USB_CTRL_GET_TIMEOUT)
107 +/* 5ms timeout writing/reading regs */
108 +#define HFC_TIMER_T3 8000 /* timeout for l1 activation timer */
109 +#define HFC_TIMER_T4 500 /* time for state change interval */
110 +
111 +#define HFCUSB_L1_STATECHANGE 0 /* L1 state changed */
112 +#define HFCUSB_L1_DRX 1 /* D-frame received */
113 +#define HFCUSB_L1_ERX 2 /* E-frame received */
114 +#define HFCUSB_L1_DTX 4 /* D-frames completed */
115 +
116 +#define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */
117 +
118 +#define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */
119 +#define HFCUSB_TX_THRESHOLD 64 /* threshold for fifo report bit tx */
120 +
121 +#define HFCUSB_CHIP_ID 0x16 /* Chip ID register index */
122 +#define HFCUSB_CIRM 0x00 /* cirm register index */
123 +#define HFCUSB_USB_SIZE 0x07 /* int length register */
124 +#define HFCUSB_USB_SIZE_I 0x06 /* iso length register */
125 +#define HFCUSB_F_CROSS 0x0b /* bit order register */
126 +#define HFCUSB_CLKDEL 0x37 /* bit delay register */
127 +#define HFCUSB_CON_HDLC 0xfa /* channel connect register */
128 #define HFCUSB_HDLC_PAR 0xfb
129 -#define HFCUSB_SCTRL 0x31 /* S-bus control register (tx) */
130 -#define HFCUSB_SCTRL_E 0x32 /* same for E and special funcs */
131 -#define HFCUSB_SCTRL_R 0x33 /* S-bus control register (rx) */
132 -#define HFCUSB_F_THRES 0x0c /* threshold register */
133 -#define HFCUSB_FIFO 0x0f /* fifo select register */
134 -#define HFCUSB_F_USAGE 0x1a /* fifo usage register */
135 +#define HFCUSB_SCTRL 0x31 /* S-bus control register (tx) */
136 +#define HFCUSB_SCTRL_E 0x32 /* same for E and special funcs */
137 +#define HFCUSB_SCTRL_R 0x33 /* S-bus control register (rx) */
138 +#define HFCUSB_F_THRES 0x0c /* threshold register */
139 +#define HFCUSB_FIFO 0x0f /* fifo select register */
140 +#define HFCUSB_F_USAGE 0x1a /* fifo usage register */
141 #define HFCUSB_MST_MODE0 0x14
142 #define HFCUSB_MST_MODE1 0x15
143 #define HFCUSB_P_DATA 0x1f
144 #define HFCUSB_INC_RES_F 0x0e
145 #define HFCUSB_STATES 0x30
146
147 -#define HFCUSB_CHIPID 0x40 /* ID value of HFC-USB */
148 +#define HFCUSB_CHIPID 0x40 /* ID value of HFC-USB */
149
150 /******************/
151 /* fifo registers */
152 /******************/
153 -#define HFCUSB_NUM_FIFOS 8 /* maximum number of fifos */
154 -#define HFCUSB_B1_TX 0 /* index for B1 transmit bulk/int */
155 -#define HFCUSB_B1_RX 1 /* index for B1 receive bulk/int */
156 +#define HFCUSB_NUM_FIFOS 8 /* maximum number of fifos */
157 +#define HFCUSB_B1_TX 0 /* index for B1 transmit bulk/int */
158 +#define HFCUSB_B1_RX 1 /* index for B1 receive bulk/int */
159 #define HFCUSB_B2_TX 2
160 #define HFCUSB_B2_RX 3
161 #define HFCUSB_D_TX 4
162 @@ -94,198 +112,162 @@
163 #define HFCUSB_PCM_TX 6
164 #define HFCUSB_PCM_RX 7
165
166 -/************/
167 -/* LED mask */
168 -/************/
169 -#define LED_DRIVER 0x1
170 -#define LED_L1 0x2
171 -#define LED_BCH 0x4
172 +/*
173 +* used to switch snd_transfer_mode for different TA modes e.g. the Billion USB TA just
174 +* supports ISO out, while the Cologne Chip EVAL TA just supports BULK out
175 +*/
176 +#define USB_INT 0
177 +#define USB_BULK 1
178 +#define USB_ISOC 2
179 +
180 +#define ISOC_PACKETS_D 8
181 +#define ISOC_PACKETS_B 8
182 +#define ISO_BUFFER_SIZE 128
183 +
184 +// ISO send definitions
185 +#define SINK_MAX 68
186 +#define SINK_MIN 48
187 +#define SINK_DMIN 12
188 +#define SINK_DMAX 18
189 +#define BITLINE_INF (-64*8)
190 +
191 +
192 +
193
194 /**********/
195 /* macros */
196 /**********/
197 -#define Write_hfc(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_out_pipe,0,0x40,(c),(b),0,0,HFC_CTRL_TIMEOUT)
198 -#define Read_hfc(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_in_pipe,1,0xC0,0,(b),(c),1,HFC_CTRL_TIMEOUT)
199 -
200 -#ifdef COMPAT_HAS_USB_IDTAB
201 -/****************************************/
202 -/* data defining the devices to be used */
203 -/****************************************/
204 -static __devinitdata const struct usb_device_id hfc_usb_idtab[3] = {
205 - {USB_DEVICE(0x959, 0x2bd0)}, /* Colognechip ROM */
206 - {USB_DEVICE(0x7b0, 0x0006)}, /* USB TA 128 */
207 - {} /* end with an all-zeroes entry */
208 -};
209 -#endif
210 +#define write_usb(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_out_pipe,0,0x40,(c),(b),NULL,0,HFC_CTRL_TIMEOUT)
211 +#define read_usb(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_in_pipe,1,0xC0,0,(b),(c),1,HFC_CTRL_TIMEOUT)
212
213 /*************************************************/
214 /* entry and size of output/input control buffer */
215 /*************************************************/
216 #define HFC_CTRL_BUFSIZE 32
217 -typedef struct {
218 +typedef struct
219 +{
220 __u8 hfc_reg; /* register number */
221 __u8 reg_val; /* value to be written (or read) */
222 + int action; /* data for action handler */
223 +
224 } ctrl_buft;
225
226 +typedef struct
227 +{
228 + int vendor; // vendor id
229 + int prod_id; // product id
230 + char *vend_name; // vendor string
231 + __u8 led_scheme; // led display scheme
232 + __u8 led_invert; // invert led aux port settings
233 + __u8 led_bits[8]; // array of 8 possible LED bitmask settings
234 +
235 +} vendor_data;
236 +
237 /***************************************************************/
238 /* structure defining input+output fifos (interrupt/bulk mode) */
239 /***************************************************************/
240 -struct hfcusb_data; /* forward definition */
241 -typedef struct {
242 - int fifonum; /* fifo index attached to this structure */
243 - __u8 fifo_mask; /* mask for this fifo */
244 - int active; /* fifo is currently active */
245 +
246 +struct usb_fifo; /* forward definition */
247 +typedef struct iso_urb_struct
248 +{
249 + struct urb *purb;
250 + __u8 buffer[ISO_BUFFER_SIZE]; /* buffer incoming/outgoing data */
251 + struct usb_fifo *owner_fifo; // pointer to owner fifo
252 +} iso_urb_struct;
253 +
254 +
255 +struct hfcusb_data; /* forward definition */
256 +typedef struct usb_fifo
257 +{
258 + int fifonum; /* fifo index attached to this structure */
259 + int active; /* fifo is currently active */
260 struct hfcusb_data *hfc; /* pointer to main structure */
261 - int pipe; /* address of endpoint */
262 - __u8 usb_maxlen; /* maximum length for usb transfer */
263 - int max_size; /* maximum size of receive/send packet */
264 - int transmode; /* transparent mode selected */
265 - int framenum; /* number of frame when last tx completed */
266 - int rx_offset; /* offset inside rx buffer */
267 - int next_complete; /* complete marker */
268 - __u8 *act_ptr; /* pointer to next data */
269 - __u8 intervall; /* interrupt interval */
270 - struct sk_buff *buff; /* actual used buffer */
271 - urb_t urb; /* transfer structure for usb routines */
272 - __u8 buffer[128]; /* buffer incoming/outgoing data */
273 + int pipe; /* address of endpoint */
274 + __u8 usb_packet_maxlen; /* maximum length for usb transfer */
275 + unsigned int max_size; /* maximum size of receive/send packet */
276 + __u8 intervall; /* interrupt interval */
277 + struct sk_buff *skbuff; /* actual used buffer */
278 + struct urb *urb; /* transfer structure for usb routines */
279 + __u8 buffer[128]; /* buffer incoming/outgoing data */
280 + int bit_line; /* how much bits are in the fifo? */
281 +
282 + volatile __u8 usb_transfer_mode;/* switched between ISO and INT */
283 + iso_urb_struct iso[2]; /* need two urbs to have one always for pending */
284 + struct hisax_if *hif; /* hisax interface */
285 + int delete_flg; /* only delete skbuff once */
286 + int last_urblen; /* remember length of last packet */
287 +
288 } usb_fifo;
289
290 +
291 /*********************************************/
292 /* structure holding all data for one device */
293 /*********************************************/
294 -typedef struct hfcusb_data {
295 - struct hisax_drvreg regd; /* register data and callbacks */
296 - struct usb_device *dev; /* our device */
297 - int if_used; /* used interface number */
298 - int alt_used; /* used alternate config */
299 - int ctrl_paksize; /* control pipe packet size */
300 +typedef struct hfcusb_data
301 +{
302 + // HiSax Interface for loadable Layer1 drivers
303 + struct hisax_d_if d_if; /* see hisax_if.h */
304 + struct hisax_b_if b_if[2]; /* see hisax_if.h */
305 + int protocol;
306 +
307 + struct usb_device *dev; /* our device */
308 + int if_used; /* used interface number */
309 + int alt_used; /* used alternate config */
310 + int ctrl_paksize; /* control pipe packet size */
311 int ctrl_in_pipe, ctrl_out_pipe; /* handles for control pipe */
312 + int cfg_used; /* configuration index used */
313 + int vend_idx; // vendor found
314 +
315 + int b_mode[2]; // B-channel mode
316 +
317 + int l1_activated; // layer 1 activated
318 +
319 + int packet_size,iso_packet_size;
320
321 /* control pipe background handling */
322 ctrl_buft ctrl_buff[HFC_CTRL_BUFSIZE]; /* buffer holding queued data */
323 - volatile int ctrl_in_idx, ctrl_out_idx, ctrl_cnt; /* input/output pointer + count */
324 - urb_t ctrl_urb; /* transfer structure for control channel */
325 - devrequest ctrl_write; /* buffer for control write request */
326 - devrequest ctrl_read; /* same for read request */
327 -
328 - volatile __u8 dfifo_fill; /* value read from tx d-fifo */
329 - volatile __u8 active_fifos; /* fifos currently active as bit mask */
330 - volatile __u8 threshold_mask; /* threshold actually reported */
331 - volatile __u8 service_request; /* fifo needs service from task */
332 - volatile __u8 ctrl_fifo; /* last selected fifo */
333 - volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */
334 - volatile __u8 led_req; /* request status of adapters leds */
335 - volatile __u8 led_act; /* active status of adapters leds */
336 + volatile int ctrl_in_idx, ctrl_out_idx,
337 + ctrl_cnt; /* input/output pointer + count */
338 + struct urb *ctrl_urb; /* transfer structure for control channel */
339 +
340 + struct usb_ctrlrequest ctrl_write; /* buffer for control write request */
341 + struct usb_ctrlrequest ctrl_read; /* same for read request */
342 +
343 + __u8 led_state,led_new_data,led_b_active;
344 +
345 + volatile __u8 threshold_mask; /* threshold actually reported */
346 + volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */
347 +
348 usb_fifo fifos[HFCUSB_NUM_FIFOS]; /* structure holding all fifo data */
349
350 - /* layer 1 activation/deactivation handling */
351 - volatile __u8 l1_state; /* actual l1 state */
352 - volatile ulong l1_event; /* event mask */
353 - struct tq_struct l1_tq; /* l1 bh structure */
354 - struct timer_list t3_timer; /* timer for activation/deactivation */
355 - struct timer_list t4_timer; /* timer for activation/deactivation */
356 + volatile __u8 l1_state; /* actual l1 state */
357 + struct timer_list t3_timer; /* timer 3 for activation/deactivation */
358 + struct timer_list t4_timer; /* timer 4 for activation/deactivation */
359 + struct timer_list led_timer; /* timer flashing leds */
360 +
361 } hfcusb_data;
362
363 -#if 0
364 -static void
365 -usb_dump_urb(purb_t purb)
366 -{
367 - printk("urb :%p\n", purb);
368 - printk("next :%p\n", purb->next);
369 - printk("dev :%p\n", purb->dev);
370 - printk("pipe :%08X\n", purb->pipe);
371 - printk("status :%d\n", purb->status);
372 - printk("transfer_flags :%08X\n", purb->transfer_flags);
373 - printk("transfer_buffer :%p\n", purb->transfer_buffer);
374 - printk("transfer_buffer_length:%d\n",
375 - purb->transfer_buffer_length);
376 - printk("actual_length :%d\n", purb->actual_length);
377 - printk("setup_packet :%p\n", purb->setup_packet);
378 - printk("start_frame :%d\n", purb->start_frame);
379 - printk("number_of_packets :%d\n", purb->number_of_packets);
380 - printk("interval :%d\n", purb->interval);
381 - printk("error_count :%d\n", purb->error_count);
382 - printk("context :%p\n", purb->context);
383 - printk("complete :%p\n", purb->complete);
384 -}
385 -#endif
386
387 -/*************************************************************************/
388 -/* bottom half handler for L1 activation/deactiavtaion + D-chan + E-chan */
389 -/*************************************************************************/
390 -static void
391 -usb_l1d_bh(hfcusb_data * hfc)
392 -{
393 +static void collect_rx_frame(usb_fifo *fifo,__u8 *data,int len,int finish);
394 +
395
396 - while (hfc->l1_event) {
397 - if (test_and_clear_bit
398 - (HFCUSB_L1_STATECHANGE, &hfc->l1_event)) {
399 - if (hfc->l1_state == 7)
400 - hfc->led_req |= LED_L1;
401 - else
402 - hfc->led_req &= ~LED_L1;
403 - if ((hfc->l1_state == 7) ||
404 - (hfc->l1_state == 3))
405 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
406 - (hfc->l1_state ==
407 - 7) ? (PH_ACTIVATE |
408 - INDICATION)
409 - : (PH_DEACTIVATE | INDICATION),
410 - NULL);
411 - }
412 - if (test_and_clear_bit(HFCUSB_L1_DRX, &hfc->l1_event)) {
413 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
414 - PH_DATA | INDICATION,
415 - (void *) 0);
416 - }
417 - if (test_and_clear_bit(HFCUSB_L1_ERX, &hfc->l1_event)) {
418 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
419 - PH_DATA | INDICATION,
420 - (void *) 1);
421 - }
422 - if (test_and_clear_bit(HFCUSB_L1_DTX, &hfc->l1_event)) {
423 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
424 - PH_DATA | CONFIRM, NULL);
425 - }
426 - } /* while */
427 -} /* usb_l1d_bh */
428
429 /******************************************************/
430 /* start next background transfer for control channel */
431 /******************************************************/
432 -static void
433 -ctrl_start_transfer(hfcusb_data * hfc)
434 +static void ctrl_start_transfer(hfcusb_data * hfc)
435 {
436 -
437 - if (hfc->ctrl_cnt) {
438 - switch (hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg) {
439 - case HFCUSB_F_USAGE:
440 - hfc->ctrl_urb.pipe = hfc->ctrl_in_pipe;
441 - hfc->ctrl_urb.setup_packet =
442 - (u_char *) & hfc->ctrl_read;
443 - hfc->ctrl_urb.transfer_buffer_length = 1;
444 - hfc->ctrl_read.index =
445 - hfc->ctrl_buff[hfc->ctrl_out_idx].
446 - hfc_reg;
447 - hfc->ctrl_urb.transfer_buffer =
448 - (char *) &hfc->dfifo_fill;
449 - break;
450 -
451 - default: /* write register */
452 - hfc->ctrl_urb.pipe = hfc->ctrl_out_pipe;
453 - hfc->ctrl_urb.setup_packet =
454 - (u_char *) & hfc->ctrl_write;
455 - hfc->ctrl_urb.transfer_buffer = NULL;
456 - hfc->ctrl_urb.transfer_buffer_length = 0;
457 - hfc->ctrl_write.index =
458 - hfc->ctrl_buff[hfc->ctrl_out_idx].
459 - hfc_reg;
460 - hfc->ctrl_write.value =
461 - hfc->ctrl_buff[hfc->ctrl_out_idx].
462 - reg_val;
463 - break;
464 - }
465 - usb_submit_urb(&hfc->ctrl_urb); /* start transfer */
466 + int err;
467 + if(hfc->ctrl_cnt)
468 + {
469 + hfc->ctrl_urb->pipe = hfc->ctrl_out_pipe;
470 + hfc->ctrl_urb->setup_packet = (u_char *) & hfc->ctrl_write;
471 + hfc->ctrl_urb->transfer_buffer = NULL;
472 + hfc->ctrl_urb->transfer_buffer_length = 0;
473 + hfc->ctrl_write.wIndex = hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg;
474 + hfc->ctrl_write.wValue = hfc->ctrl_buff[hfc->ctrl_out_idx].reg_val;
475 + err = usb_submit_urb(hfc->ctrl_urb); /* start transfer */
476 + printk(KERN_DEBUG "ctrl_start_transfer: submit %d\n", err);
477 }
478 } /* ctrl_start_transfer */
479
480 @@ -293,897 +275,1418 @@ ctrl_start_transfer(hfcusb_data * hfc)
481 /* queue a control transfer request */
482 /* return 0 on success. */
483 /************************************/
484 -static int
485 -queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val)
486 +static int queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val,int action)
487 {
488 ctrl_buft *buf;
489
490 - if (hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE)
491 - return (1); /* no space left */
492 - buf = hfc->ctrl_buff + hfc->ctrl_in_idx; /* pointer to new index */
493 +#ifdef VERBOSE_USB_DEBUG
494 + printk ("HFC_USB: queue_control_request reg: %x, val: %x\n", reg, val);
495 +#endif
496 +
497 + if(hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE) return(1); /* no space left */
498 + buf = &hfc->ctrl_buff[hfc->ctrl_in_idx]; /* pointer to new index */
499 buf->hfc_reg = reg;
500 buf->reg_val = val;
501 + buf->action=action;
502 if (++hfc->ctrl_in_idx >= HFC_CTRL_BUFSIZE)
503 hfc->ctrl_in_idx = 0; /* pointer wrap */
504 if (++hfc->ctrl_cnt == 1)
505 ctrl_start_transfer(hfc);
506 - return (0);
507 -} /* queue_control_request */
508 + return(0);
509 +} /* queue_control_request */
510
511 -/**************************************/
512 -/* called when timer t3 or t4 expires */
513 -/**************************************/
514 -static void
515 -l1_timer_expire(hfcusb_data * hfc)
516 -{
517 - if (timer_pending(&hfc->t4_timer))
518 - del_timer(&hfc->t4_timer);
519 - queue_control_request(hfc, HFCUSB_STATES, 0x40);
520 - test_and_set_bit(HFCUSB_L1_STATECHANGE,
521 - &hfc->l1_event);
522 - queue_task(&hfc->l1_tq, &tq_immediate);
523 - mark_bh(IMMEDIATE_BH);
524 -} /* l1_timer_expire */
525 -
526 -/**************************************************/
527 -/* (re)fills a tx-fifo urb. Queuing is done later */
528 -/**************************************************/
529 -static void
530 -fill_tx_urb(usb_fifo * fifo)
531 -{
532 - struct sk_buff *skb;
533 - long flags;
534 - int i, ii = 0;
535 -
536 - fifo->urb.dev = fifo->hfc->dev;
537 - if ((fifo->buff)
538 - && (fifo->urb.transfer_buffer_length < fifo->usb_maxlen)) {
539 - switch (fifo->fifonum) {
540 - case HFCUSB_B1_TX:
541 - case HFCUSB_B2_TX:
542 - skb = fifo->buff;
543 - fifo->buff = NULL;
544 - fifo->hfc->regd.bch_l1l2(fifo->hfc->regd.
545 - arg_hisax,
546 - (fifo->fifonum ==
547 - HFCUSB_B1_TX) ? 0
548 - : 1,
549 - (PH_DATA |
550 - CONFIRM),
551 - (void *) skb);
552 - fifo->hfc->service_request |=
553 - fifo->fifo_mask;
554 - return;
555 - case HFCUSB_D_TX:
556 - dev_kfree_skb_any(fifo->buff);
557 - fifo->buff = NULL;
558 - save_flags(flags);
559 - cli();
560 - fifo->hfc->dfifo_fill = 0xff; /* currently invalid data */
561 - queue_control_request(fifo->hfc,
562 - HFCUSB_FIFO,
563 - HFCUSB_D_TX);
564 - queue_control_request(fifo->hfc,
565 - HFCUSB_F_USAGE, 0);
566 - restore_flags(flags);
567 - return;
568 - default:
569 - return; /* error, invalid fifo */
570 - }
571 +
572 +static int control_action_handler(hfcusb_data *hfc,int reg,int val,int action)
573 +{
574 + if(!action) return(1); // no action defined
575 +
576 + return(0);
577 +}
578 +
579 +
580 +/***************************************************************/
581 +/* control completion routine handling background control cmds */
582 +/***************************************************************/
583 +static void ctrl_complete(struct urb *urb)
584 +{
585 + hfcusb_data *hfc = (hfcusb_data *) urb->context;
586 + ctrl_buft *buf;
587 +
588 + printk(KERN_DEBUG "ctrl_complete cnt %d\n", hfc->ctrl_cnt);
589 + urb->dev = hfc->dev;
590 + if(hfc->ctrl_cnt)
591 + {
592 + buf=&hfc->ctrl_buff[hfc->ctrl_out_idx];
593 + control_action_handler(hfc,buf->hfc_reg,buf->reg_val,buf->action);
594 +
595 + hfc->ctrl_cnt--; /* decrement actual count */
596 + if(++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE) hfc->ctrl_out_idx = 0; /* pointer wrap */
597 +
598 + ctrl_start_transfer(hfc); /* start next transfer */
599 + }
600 +} /* ctrl_complete */
601 +
602 +
603 +
604 +#define LED_OFF 0 // no LED support
605 +#define LED_SCHEME1 1 // LED standard scheme
606 +#define LED_SCHEME2 2 // not used yet...
607 +
608 +#define LED_POWER_ON 1
609 +#define LED_POWER_OFF 2
610 +#define LED_S0_ON 3
611 +#define LED_S0_OFF 4
612 +#define LED_B1_ON 5
613 +#define LED_B1_OFF 6
614 +#define LED_B1_DATA 7
615 +#define LED_B2_ON 8
616 +#define LED_B2_OFF 9
617 +#define LED_B2_DATA 10
618 +
619 +#define LED_NORMAL 0 // LEDs are normal
620 +#define LED_INVERTED 1 // LEDs are inverted
621 +
622 +// time for LED flashing
623 +#define LED_TIME 250
624 +
625 +vendor_data vdata[]=
626 +{
627 + {0x959, 0x2bd0, "ISDN USB TA (Cologne Chip HFC-S USB based)", LED_OFF,LED_NORMAL,{4,0,2,1}}, /* CologneChip Eval TA */
628 + {0x7b0, 0x0007, "Billion tiny USB ISDN TA 128", LED_SCHEME1, LED_INVERTED, {8,0x40,0x20,0x10}}, /* Billion TA */
629 + {0x742, 0x2008, "Stollmann USB TA", LED_SCHEME1, LED_NORMAL, {4,0,2,1}}, /* Stollmann TA */
630 + {0x8e3, 0x0301, "Olitec USB RNIS", LED_SCHEME1, LED_NORMAL, {2,0,1,4}}, /* Olitec TA */
631 + {0x675, 0x1688, "DrayTec USB ISDN TA", LED_SCHEME1, LED_NORMAL, {4,0,2,1}}, /* Draytec TA */
632 + {0x7fa, 0x0846, "Bewan Modem RNIS USB", LED_SCHEME1, LED_INVERTED, {8,0x40,0x20,0x10}}, /* Bewan TA */
633 + {0} // EOL element
634 +};
635 +
636 +/***************************************************/
637 +/* write led data to auxport & invert if necessary */
638 +/***************************************************/
639 +static void write_led(hfcusb_data * hfc,__u8 led_state)
640 +{
641 + if(led_state!=hfc->led_state)
642 + {
643 + hfc->led_state=led_state;
644 + queue_control_request(hfc, HFCUSB_P_DATA,(vdata[hfc->vend_idx].led_invert) ? ~led_state : led_state,1);
645 + }
646 +}
647 +
648 +/******************************************/
649 +/* invert B-channel LEDs if data is sent */
650 +/******************************************/
651 +static void led_timer(hfcusb_data * hfc)
652 +{
653 + static int cnt=0;
654 + __u8 led_state=hfc->led_state;
655 +
656 + if(cnt)
657 + {
658 + if(hfc->led_b_active&1) led_state|=vdata[hfc->vend_idx].led_bits[2];
659 + if(hfc->led_b_active&2) led_state|=vdata[hfc->vend_idx].led_bits[3];
660 + }
661 + else
662 + {
663 + if(!(hfc->led_b_active&1) || hfc->led_new_data&1) led_state&=~vdata[hfc->vend_idx].led_bits[2];
664 + if(!(hfc->led_b_active&2) || hfc->led_new_data&2) led_state&=~vdata[hfc->vend_idx].led_bits[3];
665 }
666
667 - /* check if new buffer needed */
668 - if (!fifo->buff) {
669 - switch (fifo->fifonum) {
670 - case HFCUSB_B1_TX:
671 - if (fifo->hfc->regd.bsk[0])
672 - fifo->buff = *fifo->hfc->regd.bsk[0]; /* B1-channel tx buffer */
673 + write_led(hfc,led_state);
674 + hfc->led_new_data=0;
675 +
676 + cnt=!cnt;
677 + // restart 4 hz timer
678 + hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000;
679 + if(!timer_pending(&hfc->led_timer)) add_timer(&hfc->led_timer);
680 +}
681 +
682 +/**************************/
683 +/* handle LED requests */
684 +/**************************/
685 +static void handle_led(hfcusb_data * hfc,int event)
686 +{
687 + __u8 led_state=hfc->led_state;
688 +
689 + // if no scheme -> no LED action
690 + if(vdata[hfc->vend_idx].led_scheme==LED_OFF) return;
691 +
692 + switch(event)
693 + {
694 + case LED_POWER_ON:
695 + led_state|=vdata[hfc->vend_idx].led_bits[0];
696 + break;
697 + case LED_POWER_OFF: // no Power off handling
698 + break;
699 + case LED_S0_ON:
700 + led_state|=vdata[hfc->vend_idx].led_bits[1];
701 + break;
702 + case LED_S0_OFF:
703 + led_state&=~vdata[hfc->vend_idx].led_bits[1];
704 break;
705 - case HFCUSB_B2_TX:
706 - if (fifo->hfc->regd.bsk[1])
707 - fifo->buff = *fifo->hfc->regd.bsk[1]; /* B2-channel tx buffer */
708 + case LED_B1_ON:
709 + hfc->led_b_active|=1;
710 break;
711 - case HFCUSB_D_TX:
712 - if (fifo->hfc->regd.dsq)
713 - fifo->buff = skb_dequeue(fifo->hfc->regd.dsq); /* D-channel tx queue */
714 + case LED_B1_OFF:
715 + hfc->led_b_active&=~1;
716 break;
717 - default:
718 - return; /* error, invalid fifo */
719 + case LED_B1_DATA:
720 + hfc->led_new_data|=1;
721 + break;
722 + case LED_B2_ON:
723 + hfc->led_b_active|=2;
724 + break;
725 + case LED_B2_OFF:
726 + hfc->led_b_active&=~2;
727 + break;
728 + case LED_B2_DATA:
729 + hfc->led_new_data|=2;
730 + break;
731 + }
732 +
733 + write_led(hfc,led_state);
734 +}
735 +
736 +/********************************/
737 +/* called when timer t3 expires */
738 +/********************************/
739 +static void l1_timer_expire_t3(hfcusb_data * hfc)
740 +{
741 + //printk (KERN_INFO "HFC-USB: l1_timer_expire_t3\n");
742 +
743 + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL);
744 +#ifdef VERBOSE_USB_DEBUG
745 + printk(KERN_INFO "PH_DEACTIVATE | INDICATION sent\n");
746 +#endif
747 + hfc->l1_activated=FALSE;
748 + handle_led(hfc,LED_S0_OFF);
749 +}
750 +
751 +/********************************/
752 +/* called when timer t4 expires */
753 +/********************************/
754 +static void l1_timer_expire_t4(hfcusb_data * hfc)
755 +{
756 + //printk (KERN_INFO "HFC-USB: l1_timer_expire_t4\n");
757 +
758 + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL);
759 +#ifdef VERBOSE_USB_DEBUG
760 + printk(KERN_INFO "PH_DEACTIVATE | INDICATION sent\n");
761 +#endif
762 + hfc->l1_activated=FALSE;
763 + handle_led(hfc,LED_S0_OFF);
764 +}
765 +
766 +/*****************************/
767 +/* handle S0 state changes */
768 +/*****************************/
769 +static void state_handler(hfcusb_data * hfc,__u8 state)
770 +{
771 + __u8 old_state;
772 +
773 + old_state=hfc->l1_state;
774 +
775 + // range check
776 + if(state==old_state || state<1 || state>8) return;
777 +
778 +#ifdef VERBOSE_ISDN_DEBUG
779 + printk(KERN_INFO "HFC-USB: new S0 state:%d old_state:%d\n",state,old_state);
780 +#endif
781 +
782 + if(state<4 || state==7 || state==8)
783 + {
784 + if(timer_pending(&hfc->t3_timer)) del_timer(&hfc->t3_timer);
785 + //printk(KERN_INFO "HFC-USB: T3 deactivated\n");
786 + }
787 +
788 + if(state>=7)
789 + {
790 + if(timer_pending(&hfc->t4_timer)) del_timer(&hfc->t4_timer);
791 + //printk(KERN_INFO "HFC-USB: T4 deactivated\n");
792 + }
793 +
794 + if(state==7 && !hfc->l1_activated)
795 + {
796 + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_ACTIVATE | INDICATION,NULL);
797 + //printk(KERN_INFO "HFC-USB: PH_ACTIVATE | INDICATION sent\n");
798 + hfc->l1_activated=TRUE;
799 + handle_led(hfc,LED_S0_ON);
800 + }
801 + else
802 + if(state<=3 /* && activated*/)
803 + {
804 + if(old_state==7 || old_state==8)
805 + {
806 + //printk(KERN_INFO "HFC-USB: T4 activated\n");
807 + hfc->t4_timer.expires = jiffies + (HFC_TIMER_T4 * HZ) / 1000;
808 + if(!timer_pending(&hfc->t4_timer)) add_timer(&hfc->t4_timer);
809 }
810 - if (!fifo->buff) {
811 - fifo->active = 0; /* we are inactive now */
812 - fifo->hfc->active_fifos &= ~fifo->fifo_mask;
813 - if (fifo->fifonum == HFCUSB_D_TX) {
814 - test_and_set_bit(HFCUSB_L1_DTX,
815 - &fifo->hfc->l1_event);
816 - queue_task(&fifo->hfc->l1_tq,
817 - &tq_immediate);
818 - mark_bh(IMMEDIATE_BH);
819 - }
820 - return;
821 + else
822 + {
823 + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL);
824 + //printk(KERN_INFO "HFC-USB: PH_DEACTIVATE | INDICATION sent\n");
825 + hfc->l1_activated=FALSE;
826 + handle_led(hfc,LED_S0_OFF);
827 }
828 - fifo->act_ptr = fifo->buff->data; /* start of data */
829 - fifo->active = 1;
830 - ii = 1;
831 - fifo->hfc->active_fifos |= fifo->fifo_mask;
832 - fifo->hfc->service_request &= ~fifo->fifo_mask;
833 - }
834 - /* fillup the send buffer */
835 - i = fifo->buff->len - (fifo->act_ptr - fifo->buff->data); /* remaining length */
836 - fifo->buffer[0] = !fifo->transmode; /* not eof */
837 - if (i > (fifo->usb_maxlen - ii)) {
838 - i = fifo->usb_maxlen - ii;
839 - }
840 - if (i)
841 - memcpy(fifo->buffer + ii, fifo->act_ptr, i);
842 - fifo->urb.transfer_buffer_length = i + ii;
843 - fifo->rx_offset = ii;
844 -} /* fill_tx_urb */
845 -
846 -/************************************************/
847 -/* transmit completion routine for all tx fifos */
848 -/************************************************/
849 -static void
850 -tx_complete(purb_t urb)
851 + }
852 +
853 + hfc->l1_state=state;
854 +}
855 +
856 +
857 +/* prepare iso urb */
858 +static void fill_isoc_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe, void *buf,
859 + int num_packets, int packet_size, int interval, usb_complete_t complete, void *context)
860 {
861 - usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */
862 + int k;
863
864 - fifo->hfc->service_request &= ~fifo->fifo_mask; /* no further handling */
865 - fifo->framenum = usb_get_current_frame_number(fifo->hfc->dev);
866 + spin_lock_init(&urb->lock); // do we really need spin_lock_init ?
867 + urb->dev = dev;
868 + urb->pipe = pipe;
869 + urb->complete = complete;
870 + urb->number_of_packets = num_packets;
871 + urb->transfer_buffer_length = packet_size * num_packets;
872 + urb->context = context;
873 + urb->transfer_buffer = buf;
874 + urb->transfer_flags = 0;
875 + urb->transfer_flags = USB_ISO_ASAP;
876 + urb->actual_length = 0;
877 + urb->interval = interval;
878 + for (k = 0; k < num_packets; k++) {
879 + urb->iso_frame_desc[k].offset = packet_size * k;
880 + urb->iso_frame_desc[k].length = packet_size;
881 + urb->iso_frame_desc[k].actual_length = 0;
882 + }
883 +}
884
885 - /* check for deactivation or error */
886 - if ((!fifo->active) || (urb->status)) {
887 - fifo->hfc->active_fifos &= ~fifo->fifo_mask; /* we are inactive */
888 - fifo->active = 0;
889 - if ((fifo->buff) && (fifo->fifonum == HFCUSB_D_TX)) {
890 - dev_kfree_skb_any(fifo->buff);
891 +/* allocs urbs and start isoc transfer with two pending urbs to avoid gaps in the transfer chain */
892 +static int start_isoc_chain(usb_fifo * fifo, int num_packets_per_urb,usb_complete_t complete,int packet_size)
893 +{
894 + int i, k, errcode;
895 +
896 +#ifdef VERBOSE_USB_DEBUG
897 + printk(KERN_INFO "HFC-USB: starting ISO-chain for Fifo %i\n", fifo->fifonum);
898 +#endif
899 +
900 +
901 + // allocate Memory for Iso out Urbs
902 + for (i = 0; i < 2; i++) {
903 + if (!(fifo->iso[i].purb)) {
904 + fifo->iso[i].purb = usb_alloc_urb(num_packets_per_urb);
905 + fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo;
906 +
907 + // Init the first iso
908 + if (ISO_BUFFER_SIZE >= (fifo->usb_packet_maxlen * num_packets_per_urb))
909 + {
910 +
911 + fill_isoc_urb(fifo->iso[i].purb, fifo->hfc->dev, fifo->pipe, fifo->iso[i].buffer,
912 + num_packets_per_urb, fifo->usb_packet_maxlen, fifo->intervall,
913 + complete, &fifo->iso[i]);
914 +
915 + memset(fifo->iso[i].buffer, 0, sizeof(fifo->iso[i].buffer));
916 +
917 + // defining packet delimeters in fifo->buffer
918 + for(k = 0; k < num_packets_per_urb; k++)
919 + {
920 + fifo->iso[i].purb->iso_frame_desc[k].offset = k*packet_size;
921 + fifo->iso[i].purb->iso_frame_desc[k].length = packet_size;
922 + }
923 + }
924 }
925 - fifo->buff = NULL;
926 - return;
927 +
928 + fifo->bit_line = BITLINE_INF;
929 +
930 + errcode = usb_submit_urb(fifo->iso[i].purb);
931 + fifo->active = (errcode >= 0) ? 1 : 0;
932 + if(errcode < 0)
933 + {
934 + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i.%i \n", errcode, i);
935 + };
936 +
937 }
938 - fifo->act_ptr += (urb->transfer_buffer_length - fifo->rx_offset); /* adjust pointer */
939 - fill_tx_urb(fifo); /* refill the urb */
940 - fifo->hfc->threshold_mask |= fifo->fifo_mask; /* assume threshold reached */
941 - if (fifo->buff)
942 - fifo->hfc->service_request |= fifo->fifo_mask; /* need to restart */
943 -} /* tx_complete */
944
945 -/***********************************************/
946 -/* receive completion routine for all rx fifos */
947 -/***********************************************/
948 -static void
949 -rx_complete(purb_t urb)
950 + // errcode = (usb_submit_urb(fifo->iso[0].purb, GFP_KERNEL));
951 + return(fifo->active);
952 +}
953 +
954 +/* stops running iso chain and frees their pending urbs */
955 +static void stop_isoc_chain(usb_fifo * fifo)
956 {
957 - usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */
958 - hfcusb_data *hfc = fifo->hfc;
959 - usb_fifo *txfifo;
960 - __u8 last_state;
961 - int i, ii, currcnt, hdlci;
962 - struct sk_buff *skb;
963 -
964 - urb->dev = hfc->dev; /* security init */
965 - if ((!fifo->active) || (urb->status)) {
966 - hfc->service_request &= ~fifo->fifo_mask; /* no further handling */
967 - hfc->active_fifos &= ~fifo->fifo_mask; /* we are inactive */
968 - fifo->urb.interval = 0; /* cancel automatic rescheduling */
969 - if (fifo->buff) {
970 - dev_kfree_skb_any(fifo->buff);
971 - fifo->buff = NULL;
972 + int i;
973 +
974 + for(i = 0; i < 2; i++)
975 + {
976 + if(fifo->iso[i].purb)
977 + {
978 +#ifdef VERBOSE_USB_DEBUG
979 + printk(KERN_INFO "HFC-USB: Stopping iso chain for fifo %i.%i\n", fifo->fifonum, i);
980 +#endif
981 + usb_unlink_urb(fifo->iso[i].purb);
982 + usb_free_urb(fifo->iso[i].purb);
983 + fifo->iso[i].purb = NULL;
984 }
985 - return;
986 }
987 + if (fifo->urb) {
988 + usb_unlink_urb(fifo->urb);
989 + usb_free_urb(fifo->urb);
990 + fifo->urb = NULL;
991 + }
992 + fifo->active = 0;
993 +}
994
995 - /* first check for any status changes */
996 - if ((urb->actual_length < fifo->rx_offset)
997 - || (urb->actual_length > fifo->usb_maxlen))
998 - return; /* error condition */
999 -
1000 - if (fifo->rx_offset) {
1001 - hfc->threshold_mask = fifo->buffer[1]; /* update threshold status */
1002 - fifo->next_complete = fifo->buffer[0] & 1;
1003 - if ((fifo->fifonum == HFCUSB_D_RX) &&
1004 - (hfc->led_req != hfc->led_act))
1005 - queue_control_request(hfc, HFCUSB_P_DATA, hfc->led_req);
1006 -
1007 - /* check if rescheduling needed */
1008 - if ((i =
1009 - hfc->service_request & hfc->active_fifos & ~hfc->
1010 - threshold_mask)) {
1011 - currcnt =
1012 - usb_get_current_frame_number(hfc->dev);
1013 - txfifo = hfc->fifos + HFCUSB_B1_TX;
1014 - ii = 3;
1015 - while (ii--) {
1016 - if ((i & txfifo->fifo_mask)
1017 - && (currcnt != txfifo->framenum)) {
1018 - hfc->service_request &=
1019 - ~txfifo->fifo_mask;
1020 - if (!txfifo->buff)
1021 - fill_tx_urb(txfifo);
1022 - if (txfifo->buff)
1023 - usb_submit_urb(&txfifo->
1024 - urb);
1025 +// defines how much ISO packets are handled in one URB
1026 +static int iso_packets[8]={ISOC_PACKETS_B,ISOC_PACKETS_B,ISOC_PACKETS_B,ISOC_PACKETS_B,
1027 + ISOC_PACKETS_D,ISOC_PACKETS_D,ISOC_PACKETS_D,ISOC_PACKETS_D};
1028 +
1029 +/*****************************************************/
1030 +/* transmit completion routine for all ISO tx fifos */
1031 +/*****************************************************/
1032 +static void tx_iso_complete(struct urb *urb)
1033 +{
1034 + iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
1035 + usb_fifo *fifo = context_iso_urb->owner_fifo;
1036 + hfcusb_data *hfc = fifo->hfc;
1037 + int k, tx_offset, num_isoc_packets, sink, len, current_len,errcode,frame_complete,transp_mode,fifon;
1038 + __u8 threshbit;
1039 + __u8 threshtable[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1040 +
1041 + fifon=fifo->fifonum;
1042 + tx_offset=0;
1043 + // very weird error code when using ohci drivers, for now : ignore this error ... (MB)
1044 + if(urb->status == -EOVERFLOW)
1045 + {
1046 + urb->status = 0;
1047 +#ifdef VERBOSE_USB_DEBUG
1048 + printk(KERN_INFO "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",fifon);
1049 +#endif
1050 + }
1051 +
1052 + if(fifo->active && !urb->status)
1053 + {
1054 + transp_mode=0;
1055 + if(fifon<4 && hfc->b_mode[fifon/2]==L1_MODE_TRANS) transp_mode=TRUE;
1056 +
1057 + threshbit = threshtable[fifon] & hfc->threshold_mask; // is threshold set for our channel?
1058 + num_isoc_packets=iso_packets[fifon];
1059 +
1060 + if(fifon >= HFCUSB_D_TX)
1061 + {
1062 + sink = (threshbit) ? SINK_DMIN : SINK_DMAX; // how much bit go to the sink for D-channel?
1063 + }
1064 + else
1065 + {
1066 + sink = (threshbit) ? SINK_MIN : SINK_MAX; // how much bit go to the sink for B-channel?
1067 + }
1068 +
1069 + // prepare ISO Urb
1070 + fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,context_iso_urb->buffer, num_isoc_packets,
1071 + fifo->usb_packet_maxlen, fifo->intervall, tx_iso_complete, urb->context);
1072 + memset(context_iso_urb->buffer, 0, sizeof(context_iso_urb->buffer));
1073 +
1074 + frame_complete=FALSE;
1075 +
1076 + // Generate Iso Packets
1077 + for(k = 0; k < num_isoc_packets; ++k)
1078 + {
1079 + if(fifo->skbuff)
1080 + {
1081 + len = fifo->skbuff->len; // remaining length
1082 +
1083 + fifo->bit_line -= sink; // we lower data margin every msec
1084 + current_len = (0 - fifo->bit_line) / 8;
1085 + if(current_len > 14) current_len = 14; // maximum 15 byte for every ISO packet makes our life easier
1086 + current_len = (len <= current_len) ? len : current_len;
1087 + fifo->bit_line += current_len * 8; // how much bit do we put on the line?
1088 +
1089 + context_iso_urb->buffer[tx_offset] = 0;
1090 + if(current_len == len)
1091 + {
1092 + if(!transp_mode)
1093 + {
1094 + context_iso_urb->buffer[tx_offset] = 1; // here frame completion
1095 + fifo->bit_line += 32; // add 2 byte flags and 16bit CRC at end of ISDN frame
1096 + }
1097 + frame_complete = TRUE;
1098 + }
1099 +
1100 + // copy bytes from buffer into ISO_URB
1101 + memcpy(context_iso_urb->buffer+tx_offset+1,fifo->skbuff->data,current_len);
1102 + skb_pull(fifo->skbuff,current_len);
1103 +
1104 + // define packet delimeters within the URB buffer
1105 + urb->iso_frame_desc[k].offset = tx_offset;
1106 + urb->iso_frame_desc[k].length = current_len + 1;
1107 +
1108 + tx_offset += (current_len + 1);
1109 + // printk(KERN_INFO "HFC-USB: fifonum:%d,%d bytes to send, %d bytes ISO packet,bitline:%d,sink:%d,threshbit:%d,threshmask:%x\n",fifon,len,current_len,fifo->bit_line,sink,threshbit,hfc->threshold_mask);
1110 + if(!transp_mode)
1111 + {
1112 + if(fifon==HFCUSB_B1_TX) handle_led(hfc,LED_B1_DATA);
1113 + if(fifon==HFCUSB_B2_TX) handle_led(hfc,LED_B2_DATA);
1114 + }
1115 + }
1116 + else
1117 + {
1118 + // we have no more data - generate 1 byte ISO packets
1119 + urb->iso_frame_desc[k].offset = tx_offset++;
1120 +
1121 + urb->iso_frame_desc[k].length = 1;
1122 + fifo->bit_line -= sink; // we lower data margin every msec
1123 +
1124 + if(fifo->bit_line < BITLINE_INF)
1125 + {
1126 + fifo->bit_line = BITLINE_INF;
1127 + //printk (KERN_INFO "HFC-USB: BITLINE_INF underrun\n");
1128 }
1129 - txfifo += 2;
1130 }
1131 - }
1132
1133 - /* handle l1 events */
1134 - if ((fifo->buffer[0] >> 4) != hfc->l1_state) {
1135 - last_state = hfc->l1_state;
1136 - hfc->l1_state = fifo->buffer[0] >> 4; /* update status */
1137 - if (timer_pending(&hfc->t4_timer))
1138 - del_timer(&hfc->t4_timer);
1139 - if (((hfc->l1_state == 3) &&
1140 - ((last_state == 7) ||
1141 - (last_state == 8))) ||
1142 - ((timer_pending(&hfc->t3_timer) &&
1143 - (hfc->l1_state == 8)))) {
1144 - hfc->t4_timer.expires = jiffies + 2;
1145 - add_timer(&hfc->t4_timer);
1146 - } else {
1147 - if (timer_pending(&hfc->t3_timer)
1148 - && (hfc->l1_state == 7))
1149 - del_timer(&hfc->t3_timer); /* no longer needed */
1150 - test_and_set_bit(HFCUSB_L1_STATECHANGE,
1151 - &hfc->l1_event);
1152 - queue_task(&hfc->l1_tq, &tq_immediate);
1153 - mark_bh(IMMEDIATE_BH);
1154 + if(frame_complete)
1155 + {
1156 + // delete the buffer only once, here or in hfc_usb_l2l1() in a PH_DATA|REQUEST
1157 + fifo->delete_flg=TRUE;
1158 +
1159 + fifo->hif->l1l2(fifo->hif,PH_DATA|CONFIRM,(void*)fifo->skbuff->truesize);
1160 +
1161 + if(fifo->skbuff && fifo->delete_flg)
1162 + {
1163 + dev_kfree_skb_any(fifo->skbuff);
1164 + //printk(KERN_INFO "HFC-USB: skbuff=NULL on fifo:%d\n",fifo->fifonum);
1165 + fifo->skbuff = NULL;
1166 + fifo->delete_flg=FALSE;
1167 + }
1168 +
1169 + frame_complete=FALSE;
1170 }
1171 + }
1172 +
1173 + errcode = usb_submit_urb(urb);
1174 + if(errcode < 0)
1175 + {
1176 + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i \n", errcode);
1177 + }
1178 + }
1179 + else
1180 + {
1181 + if(urb->status)
1182 + {
1183 + printk(KERN_INFO "HFC-USB: tx_iso_complete : urb->status %i, fifonum %i\n", urb->status,fifon);
1184 }
1185 }
1186
1187 - /* check the length for data and move if present */
1188 - if (fifo->next_complete || (urb->actual_length > fifo->rx_offset)) {
1189 - i = fifo->buff->len + urb->actual_length - fifo->rx_offset; /* new total length */
1190 - hdlci = (fifo->transmode) ? 0 : 3;
1191 - if (i <= (fifo->max_size + hdlci)) {
1192 - memcpy(fifo->act_ptr,
1193 - fifo->buffer + fifo->rx_offset,
1194 - urb->actual_length - fifo->rx_offset);
1195 - fifo->act_ptr +=
1196 - (urb->actual_length - fifo->rx_offset);
1197 - fifo->buff->len +=
1198 - (urb->actual_length - fifo->rx_offset);
1199 - } else
1200 - fifo->buff->len = fifo->max_size + 4; /* mark frame as to long */
1201 - if (fifo->next_complete && (urb->actual_length < fifo->usb_maxlen)) {
1202 - /* the frame is complete */
1203 - fifo->next_complete = 0;
1204 - if (((!*(fifo->act_ptr - 1)) || fifo->transmode) &&
1205 - (fifo->buff->len >= (hdlci + 1))
1206 - && (fifo->buff->len <=
1207 - (fifo->max_size + hdlci)) &&
1208 - ((skb = dev_alloc_skb(fifo->max_size + hdlci)) != NULL)) {
1209 - fifo->buff->len -= hdlci; /* adjust size */
1210 - switch (fifo->fifonum) {
1211 - case HFCUSB_D_RX:
1212 - skb_queue_tail(hfc->regd.
1213 - drq,
1214 - fifo->buff);
1215 - test_and_set_bit
1216 - (HFCUSB_L1_DRX,
1217 - &hfc->l1_event);
1218 - queue_task(&hfc->l1_tq,
1219 - &tq_immediate);
1220 - mark_bh(IMMEDIATE_BH);
1221 - break;
1222 +} /* tx_iso_complete */
1223
1224 - case HFCUSB_B1_RX:
1225 - if (hfc->regd.brq[0]) {
1226 - skb_queue_tail
1227 - (hfc->regd.
1228 - brq[0],
1229 - fifo->buff);
1230 - hfc->regd.
1231 - bch_l1l2(hfc->
1232 - regd.
1233 - arg_hisax,
1234 - 0,
1235 - PH_DATA
1236 - |
1237 - INDICATION,
1238 - (void *)
1239 - fifo->
1240 - buff);
1241 - } else
1242 - dev_kfree_skb_any
1243 - (fifo->buff);
1244 - break;
1245 -
1246 - case HFCUSB_B2_RX:
1247 - if (hfc->regd.brq[1]) {
1248 - skb_queue_tail
1249 - (hfc->regd.
1250 - brq[1],
1251 - fifo->buff);
1252 - hfc->regd.
1253 - bch_l1l2(hfc->
1254 - regd.
1255 - arg_hisax,
1256 - 1,
1257 - PH_DATA
1258 - |
1259 - INDICATION,
1260 - (void
1261 - *)
1262 - fifo->
1263 - buff);
1264 - } else
1265 - dev_kfree_skb_any
1266 - (fifo->buff);
1267 - break;
1268 +/*****************************************************/
1269 +/* receive completion routine for all ISO tx fifos */
1270 +/*****************************************************/
1271 +static void rx_iso_complete(struct urb *urb)
1272 +{
1273 + iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
1274 + usb_fifo *fifo = context_iso_urb->owner_fifo;
1275 + hfcusb_data *hfc = fifo->hfc;
1276 + int k, len, errcode, offset, num_isoc_packets,fifon;
1277 + __u8 *buf;
1278
1279 - case HFCUSB_PCM_RX:
1280 - skb_queue_tail(&hfc->regd.
1281 - erq,
1282 - fifo->buff);
1283 - test_and_set_bit
1284 - (HFCUSB_L1_ERX,
1285 - &hfc->l1_event);
1286 - queue_task(&hfc->l1_tq,
1287 - &tq_immediate);
1288 - mark_bh(IMMEDIATE_BH);
1289 - break;
1290 + fifon=fifo->fifonum;
1291 + // very weird error code when using ohci drivers, for now : ignore this error ... (MB)
1292 + if(urb->status == -EOVERFLOW)
1293 + {
1294 + urb->status = 0;
1295 +#ifdef VERBOSE_USB_DEBUG
1296 + printk(KERN_INFO "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",fifon);
1297 +#endif
1298 + }
1299
1300 - default:
1301 - dev_kfree_skb_any(fifo->
1302 - buff);
1303 - break;
1304 + if(fifo->active && !urb->status)
1305 + {
1306 + num_isoc_packets=iso_packets[fifon];
1307 +
1308 + // Generate D-Channel Iso Packets
1309 + for(k = 0; k < num_isoc_packets; ++k)
1310 + {
1311 + len=urb->iso_frame_desc[k].actual_length;
1312 + offset=urb->iso_frame_desc[k].offset;
1313 + buf=context_iso_urb->buffer+offset;
1314 +
1315 + if(fifo->last_urblen!=fifo->usb_packet_maxlen)
1316 + {
1317 + // the threshold mask is in the 2nd status byte
1318 + hfc->threshold_mask=buf[1];
1319 + // the S0 state is in the upper half of the 1st status byte
1320 + state_handler(hfc,buf[0] >> 4);
1321 + // if we have more than the 2 status bytes -> collect data
1322 + if(len>2) collect_rx_frame(fifo,buf+2,len-2,buf[0]&1);
1323 }
1324 - fifo->buff = skb;
1325 - }
1326 - fifo->buff->len = 0; /* reset counter */
1327 - fifo->act_ptr = fifo->buff->data; /* and pointer */
1328 + else collect_rx_frame(fifo,buf,len,0);
1329 +
1330 + fifo->last_urblen=len;
1331 +
1332 + }
1333 +
1334 + // prepare ISO Urb
1335 + fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,context_iso_urb->buffer, num_isoc_packets,
1336 + fifo->usb_packet_maxlen, fifo->intervall, rx_iso_complete, urb->context);
1337 +
1338 + errcode = usb_submit_urb(urb);
1339 + if(errcode < 0)
1340 + {
1341 + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i \n", errcode);
1342 + }
1343 + }
1344 + else
1345 + {
1346 + if(urb->status)
1347 + {
1348 + printk(KERN_INFO "HFC-USB: rx_iso_complete : urb->status %i, fifonum %i\n", urb->status,fifon);
1349 + }
1350 + }
1351 +} /* rx_iso_complete */
1352 +
1353 +
1354 +/*****************************************************/
1355 +/* collect data from interrupt or isochron in */
1356 +/*****************************************************/
1357 +static void collect_rx_frame(usb_fifo *fifo,__u8 *data,int len,int finish)
1358 +{
1359 + hfcusb_data *hfc = fifo->hfc;
1360 + int transp_mode,fifon;
1361 +
1362 + fifon=fifo->fifonum;
1363 + transp_mode=0;
1364 + if(fifon<4 && hfc->b_mode[fifon/2]==L1_MODE_TRANS) transp_mode=TRUE;
1365 +
1366 + //printk(KERN_INFO "HFC-USB: got %d bytes finish:%d max_size:%d fifo:%d\n",len,finish,fifo->max_size,fifon);
1367 + if(!fifo->skbuff)
1368 + {
1369 + // allocate sk buffer
1370 + fifo->skbuff=dev_alloc_skb(fifo->max_size + 3);
1371 + if(!fifo->skbuff)
1372 + {
1373 + printk(KERN_INFO "HFC-USB: cannot allocate buffer (dev_alloc_skb) fifo:%d\n",fifon);
1374 + return;
1375 + }
1376 +
1377 + }
1378 +
1379 + if(len && fifo->skbuff->len+len<fifo->max_size)
1380 + {
1381 + memcpy(skb_put(fifo->skbuff,len),data,len);
1382 + }
1383 + else printk(KERN_INFO "HCF-USB: got frame exceeded fifo->max_size:%d\n",fifo->max_size);
1384 +
1385 + // give transparent data up, when 128 byte are available
1386 + if(transp_mode && fifo->skbuff->len>=128)
1387 + {
1388 + fifo->hif->l1l2(fifo->hif,PH_DATA | INDICATION,fifo->skbuff);
1389 + fifo->skbuff = NULL; // buffer was freed from upper layer
1390 + return;
1391 + }
1392 +
1393 + // we have a complete hdlc packet
1394 + if(finish)
1395 + {
1396 + if(!fifo->skbuff->data[fifo->skbuff->len-1])
1397 + {
1398 + skb_trim(fifo->skbuff,fifo->skbuff->len-3); // remove CRC & status
1399 +
1400 + //printk(KERN_INFO "HFC-USB: got frame %d bytes on fifo:%d\n",fifo->skbuff->len,fifon);
1401 +
1402 + if(fifon==HFCUSB_PCM_RX) fifo->hif->l1l2(fifo->hif,PH_DATA_E | INDICATION,fifo->skbuff);
1403 + else fifo->hif->l1l2(fifo->hif,PH_DATA | INDICATION,fifo->skbuff);
1404 +
1405 + fifo->skbuff = NULL; // buffer was freed from upper layer
1406 + }
1407 + else
1408 + {
1409 + printk(KERN_INFO "HFC-USB: got frame %d bytes but CRC ERROR!!!\n",fifo->skbuff->len);
1410 +
1411 + skb_trim(fifo->skbuff,0); // clear whole buffer
1412 + }
1413 + }
1414 +
1415 + // LED flashing only in HDLC mode
1416 + if(!transp_mode)
1417 + {
1418 + if(fifon==HFCUSB_B1_RX) handle_led(hfc,LED_B1_DATA);
1419 + if(fifon==HFCUSB_B2_RX) handle_led(hfc,LED_B2_DATA);
1420 + }
1421 +}
1422 +
1423 +/***********************************************/
1424 +/* receive completion routine for all rx fifos */
1425 +/***********************************************/
1426 +static void rx_complete(struct urb *urb)
1427 +{
1428 + int len;
1429 + __u8 *buf;
1430 + usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */
1431 + hfcusb_data *hfc = fifo->hfc;
1432 +
1433 + urb->dev = hfc->dev; /* security init */
1434 +
1435 + if((!fifo->active) || (urb->status)) {
1436 +#ifdef VERBOSE_USB_DEBUG
1437 + printk(KERN_INFO "HFC-USB: RX-Fifo %i is going down (%i)\n", fifo->fifonum, urb->status);
1438 +#endif
1439 + fifo->urb->interval = 0; /* cancel automatic rescheduling */
1440 + if(fifo->skbuff) {
1441 + dev_kfree_skb_any(fifo->skbuff);
1442 + fifo->skbuff = NULL;
1443 }
1444 + return;
1445 }
1446 - fifo->rx_offset = (urb->actual_length < fifo->usb_maxlen) ? 2 : 0;
1447 -} /* rx_complete */
1448 +
1449 + len=urb->actual_length;
1450 + buf=fifo->buffer;
1451 +
1452 + if(fifo->last_urblen!=fifo->usb_packet_maxlen) {
1453 + // the threshold mask is in the 2nd status byte
1454 + hfc->threshold_mask=buf[1];
1455 + // the S0 state is in the upper half of the 1st status byte
1456 + state_handler(hfc,buf[0] >> 4);
1457 + // if we have more than the 2 status bytes -> collect data
1458 + if(len>2) collect_rx_frame(fifo,buf+2,urb->actual_length-2,buf[0]&1);
1459 + } else
1460 + collect_rx_frame(fifo,buf,urb->actual_length,0);
1461 +
1462 + fifo->last_urblen=urb->actual_length;
1463 +
1464 +
1465 +} /* rx_complete */
1466 +
1467 +
1468
1469 /***************************************************/
1470 /* start the interrupt transfer for the given fifo */
1471 /***************************************************/
1472 -static void
1473 -start_rx_fifo(usb_fifo * fifo)
1474 +static void start_int_fifo(usb_fifo * fifo)
1475 {
1476 - if (fifo->buff)
1477 - return; /* still active */
1478 - if (!
1479 - (fifo->buff =
1480 - dev_alloc_skb(fifo->max_size + (fifo->transmode ? 0 : 3))))
1481 - return;
1482 - fifo->act_ptr = fifo->buff->data;
1483 - FILL_INT_URB(&fifo->urb, fifo->hfc->dev, fifo->pipe, fifo->buffer,
1484 - fifo->usb_maxlen, rx_complete, fifo, fifo->intervall);
1485 - fifo->next_complete = 0;
1486 - fifo->rx_offset = 2;
1487 - fifo->active = 1; /* must be marked active */
1488 - fifo->hfc->active_fifos |= fifo->fifo_mask;
1489 - if (usb_submit_urb(&fifo->urb)) {
1490 + int errcode;
1491 +
1492 +#ifdef VERBOSE_USB_DEBUG
1493 + printk(KERN_INFO "HFC-USB: starting intr IN fifo:%d\n", fifo->fifonum);
1494 +#endif
1495 + if (!fifo->urb) {
1496 + fifo->urb = usb_alloc_urb(0);
1497 + if (!fifo->urb)
1498 + return;
1499 + }
1500 + usb_fill_int_urb(fifo->urb, fifo->hfc->dev, fifo->pipe, fifo->buffer,
1501 + fifo->usb_packet_maxlen, rx_complete, fifo, fifo->intervall);
1502 + fifo->active = 1; /* must be marked active */
1503 + errcode = usb_submit_urb(fifo->urb);
1504 +
1505 + if(errcode)
1506 + {
1507 + printk(KERN_INFO "HFC-USB: submit URB error(start_int_info): status:%i\n", errcode);
1508 fifo->active = 0;
1509 - fifo->hfc->active_fifos &= ~fifo->fifo_mask;
1510 - dev_kfree_skb_any(fifo->buff);
1511 - fifo->buff = NULL;
1512 + fifo->skbuff = NULL;
1513 }
1514 -} /* start_rx_fifo */
1515 +} /* start_int_fifo */
1516
1517 -/***************************************************************/
1518 -/* control completion routine handling background control cmds */
1519 -/***************************************************************/
1520 -static void
1521 -ctrl_complete(purb_t urb)
1522 +/*****************************/
1523 +/* set the B-channel mode */
1524 +/*****************************/
1525 +static void set_hfcmode(hfcusb_data *hfc,int channel,int mode)
1526 {
1527 - hfcusb_data *hfc = (hfcusb_data *) urb->context;
1528 + __u8 val,idx_table[2]={0,2};
1529
1530 - urb->dev = hfc->dev;
1531 - if (hfc->ctrl_cnt) {
1532 - switch (hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg) {
1533 - case HFCUSB_FIFO:
1534 - hfc->ctrl_fifo =
1535 - hfc->ctrl_buff[hfc->ctrl_out_idx].
1536 - reg_val;
1537 - break;
1538 - case HFCUSB_F_USAGE:
1539 - if (!hfc->dfifo_fill) {
1540 - fill_tx_urb(hfc->fifos +
1541 - HFCUSB_D_TX);
1542 - if (hfc->fifos[HFCUSB_D_TX].buff)
1543 - usb_submit_urb(&hfc->
1544 - fifos
1545 - [HFCUSB_D_TX].
1546 - urb);
1547 - } else {
1548 - queue_control_request(hfc,
1549 - HFCUSB_FIFO,
1550 - HFCUSB_D_TX);
1551 - queue_control_request(hfc,
1552 - HFCUSB_F_USAGE,
1553 - 0);
1554 - }
1555 - break;
1556 - case HFCUSB_SCTRL_R:
1557 - switch (hfc->ctrl_fifo) {
1558 - case HFCUSB_B1_RX:
1559 - if (hfc->bch_enables & 1)
1560 - start_rx_fifo(hfc->
1561 - fifos
1562 - +
1563 - HFCUSB_B1_RX);
1564 - break;
1565 - case HFCUSB_B2_RX:
1566 - if (hfc->bch_enables & 2)
1567 - start_rx_fifo(hfc->
1568 - fifos
1569 - +
1570 - HFCUSB_B2_RX);
1571 - break;
1572 - }
1573 - if (hfc->bch_enables & 3)
1574 - hfc->led_req |= LED_BCH;
1575 - else
1576 - hfc->led_req &= ~LED_BCH;
1577 - break;
1578 - case HFCUSB_P_DATA:
1579 - hfc->led_act =
1580 - hfc->ctrl_buff[hfc->ctrl_out_idx].
1581 - reg_val;
1582 - break;
1583 - }
1584 - hfc->ctrl_cnt--; /* decrement actual count */
1585 - if (++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE)
1586 - hfc->ctrl_out_idx = 0; /* pointer wrap */
1587 - ctrl_start_transfer(hfc); /* start next transfer */
1588 +#ifdef VERBOSE_ISDN_DEBUG
1589 + printk (KERN_INFO "HFC-USB: setting channel %d to mode %d\n",channel,mode);
1590 +#endif
1591 +
1592 + hfc->b_mode[channel]=mode;
1593 +
1594 + // setup CON_HDLC
1595 + val=0;
1596 + if(mode!=L1_MODE_NULL) val=8; // enable fifo?
1597 + if(mode==L1_MODE_TRANS) val|=2; // set transparent bit
1598 +
1599 + queue_control_request(hfc,HFCUSB_FIFO,idx_table[channel],1); // set FIFO to transmit register
1600 + queue_control_request(hfc,HFCUSB_CON_HDLC,val,1);
1601 + queue_control_request(hfc,HFCUSB_INC_RES_F,2,1); // reset fifo
1602 +
1603 + queue_control_request(hfc,HFCUSB_FIFO,idx_table[channel]+1,1); // set FIFO to receive register
1604 + queue_control_request(hfc,HFCUSB_CON_HDLC,val,1);
1605 + queue_control_request(hfc,HFCUSB_INC_RES_F,2,1); // reset fifo
1606 +
1607 + val=0x40;
1608 + if(hfc->b_mode[0]) val|=1;
1609 + if(hfc->b_mode[1]) val|=2;
1610 + queue_control_request(hfc,HFCUSB_SCTRL,val,1);
1611 +
1612 + val=0;
1613 + if(hfc->b_mode[0]) val|=1;
1614 + if(hfc->b_mode[1]) val|=2;
1615 + queue_control_request(hfc,HFCUSB_SCTRL_R,val,1);
1616 +
1617 + if(mode==L1_MODE_NULL)
1618 + {
1619 + if(channel) handle_led(hfc,LED_B2_OFF);
1620 + else handle_led(hfc,LED_B1_OFF);
1621 }
1622 -} /* ctrl_complete */
1623 + else
1624 + {
1625 + if(channel) handle_led(hfc,LED_B2_ON);
1626 + else handle_led(hfc,LED_B1_ON);
1627 + }
1628 +}
1629
1630 -/*****************************************/
1631 -/* Layer 1 + D channel access from HiSax */
1632 -/*****************************************/
1633 -static void
1634 -hfcusb_l1_access(void *drvarg, int pr, void *arg)
1635 -{
1636 - hfcusb_data *hfc = (hfcusb_data *) drvarg;
1637 -
1638 - switch (pr) {
1639 - case (PH_DATA | REQUEST):
1640 - case (PH_PULL | INDICATION):
1641 - skb_queue_tail(hfc->regd.dsq,
1642 - (struct sk_buff *) arg);
1643 - if (!hfc->fifos[HFCUSB_D_TX].active
1644 - && !hfc->dfifo_fill) {
1645 - fill_tx_urb(hfc->fifos + HFCUSB_D_TX);
1646 - hfc->active_fifos |=
1647 - hfc->fifos[HFCUSB_D_TX].fifo_mask;
1648 - usb_submit_urb(&hfc->fifos[HFCUSB_D_TX].
1649 - urb);
1650 - }
1651 - break;
1652 - case (PH_ACTIVATE | REQUEST):
1653 - switch (hfc->l1_state) {
1654 - case 6:
1655 - case 8:
1656 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
1657 - (PH_DEACTIVATE |
1658 - INDICATION), NULL);
1659 +/*
1660 + --------------------------------------------------------------------------------------
1661 + from here : hisax_if callback routines :
1662 + - void hfc_usb_d_l2l1(struct hisax_if *hisax_d_if, int pr, void *arg) {
1663
1664 - break;
1665 - case 7:
1666 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
1667 - (PH_ACTIVATE |
1668 - INDICATION), NULL);
1669 + l1 to l2 routines :
1670 + - static void hfc_usb_l1l2(hfcusb_data * hfc)
1671
1672 - break;
1673 - default:
1674 - queue_control_request(hfc, HFCUSB_STATES, 0x60); /* start activation */
1675 - hfc->t3_timer.expires =
1676 - jiffies + (HFC_TIMER_T3 * HZ) / 1000;
1677 - if (!timer_pending(&hfc->t3_timer))
1678 - add_timer(&hfc->t3_timer);
1679 - break;
1680 - }
1681 - break;
1682 +*/
1683
1684 - case (PH_DEACTIVATE | REQUEST):
1685 - queue_control_request(hfc, HFCUSB_STATES, 0x40); /* start deactivation */
1686 - break;
1687 - default:
1688 - printk(KERN_INFO "unknown hfcusb l1_access 0x%x\n",
1689 - pr);
1690 - break;
1691 - }
1692 -} /* hfcusb_l1_access */
1693 -
1694 -/*******************************/
1695 -/* B channel access from HiSax */
1696 -/*******************************/
1697 -static void
1698 -hfcusb_bch_access(void *drvarg, int chan, int pr, void *arg)
1699 -{
1700 - hfcusb_data *hfc = (hfcusb_data *) drvarg;
1701 - usb_fifo *fifo = hfc->fifos + (chan ? HFCUSB_B2_TX : HFCUSB_B1_TX);
1702 - long flags;
1703 -
1704 - switch (pr) {
1705 - case (PH_DATA | REQUEST):
1706 - case (PH_PULL | INDICATION):
1707 - save_flags(flags);
1708 - cli();
1709 - if (!fifo->active) {
1710 - fill_tx_urb(fifo);
1711 - hfc->active_fifos |= fifo->fifo_mask;
1712 - usb_submit_urb(&fifo->urb);
1713 - }
1714 - restore_flags(flags);
1715 - break;
1716 - case (PH_ACTIVATE | REQUEST):
1717 - if (!((int) arg)) {
1718 - hfc->bch_enables &= ~(1 << chan);
1719 - if (fifo->active) {
1720 - fifo->active = 0;
1721 - usb_unlink_urb(&fifo->urb);
1722 +void hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg)
1723 +{
1724 + usb_fifo *fifo = my_hisax_if->priv;
1725 + hfcusb_data *hfc = fifo->hfc;
1726 +
1727 + switch (pr) {
1728 + case PH_ACTIVATE | REQUEST:
1729 + if(fifo->fifonum==HFCUSB_D_TX)
1730 + {
1731 +#ifdef VERBOSE_ISDN_DEBUG
1732 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST\n");
1733 +#endif
1734 + queue_control_request(hfc, HFCUSB_STATES,0x60,1); /* make activation */
1735 + hfc->t3_timer.expires = jiffies + (HFC_TIMER_T3 * HZ) / 1000;
1736 + if(!timer_pending(&hfc->t3_timer)) add_timer(&hfc->t3_timer);
1737 }
1738 - save_flags(flags);
1739 - cli();
1740 - queue_control_request(hfc, HFCUSB_FIFO,
1741 - fifo->fifonum);
1742 - queue_control_request(hfc,
1743 - HFCUSB_INC_RES_F, 2);
1744 - queue_control_request(hfc, HFCUSB_CON_HDLC,
1745 - 9);
1746 - queue_control_request(hfc, HFCUSB_SCTRL,
1747 - 0x40 +
1748 - hfc->bch_enables);
1749 - queue_control_request(hfc, HFCUSB_SCTRL_R,
1750 - hfc->bch_enables);
1751 - restore_flags(flags);
1752 - fifo++;
1753 - if (fifo->active) {
1754 - fifo->active = 0;
1755 - usb_unlink_urb(&fifo->urb);
1756 + else
1757 + {
1758 +#ifdef VERBOSE_ISDN_DEBUG
1759 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_ACTIVATE | REQUEST\n");
1760 +#endif
1761 + set_hfcmode(hfc,(fifo->fifonum==HFCUSB_B1_TX) ? 0 : 1 ,(int)arg);
1762 + fifo->hif->l1l2(fifo->hif,PH_ACTIVATE | INDICATION, NULL);
1763 }
1764 - return; /* fifo deactivated */
1765 - }
1766 - fifo->transmode = ((int) arg == L1_MODE_TRANS);
1767 - fifo->max_size =
1768 - ((fifo->transmode) ? fifo->
1769 - usb_maxlen : MAX_BCH_SIZE);
1770 - (fifo + 1)->transmode = fifo->transmode;
1771 - (fifo + 1)->max_size = fifo->max_size;
1772 - hfc->bch_enables |= (1 << chan);
1773 - save_flags(flags);
1774 - cli();
1775 - queue_control_request(hfc, HFCUSB_FIFO,
1776 - fifo->fifonum);
1777 - queue_control_request(hfc, HFCUSB_CON_HDLC,
1778 - ((!fifo->
1779 - transmode) ? 9 : 11));
1780 - queue_control_request(hfc, HFCUSB_INC_RES_F, 2);
1781 - queue_control_request(hfc, HFCUSB_SCTRL,
1782 - 0x40 + hfc->bch_enables);
1783 - if ((int) arg == L1_MODE_HDLC)
1784 - queue_control_request(hfc, HFCUSB_CON_HDLC,
1785 - 8);
1786 - queue_control_request(hfc, HFCUSB_FIFO,
1787 - fifo->fifonum + 1);
1788 - queue_control_request(hfc, HFCUSB_CON_HDLC,
1789 - ((!fifo->
1790 - transmode) ? 8 : 10));
1791 - queue_control_request(hfc, HFCUSB_INC_RES_F, 2);
1792 - queue_control_request(hfc, HFCUSB_SCTRL_R,
1793 - hfc->bch_enables);
1794 - restore_flags(flags);
1795 -
1796 - break;
1797 -
1798 - default:
1799 - printk(KERN_INFO
1800 - "unknown hfcusb bch_access chan %d 0x%x\n",
1801 - chan, pr);
1802 - break;
1803 - }
1804 -} /* hfcusb_bch_access */
1805 + break;
1806 + case PH_DEACTIVATE | REQUEST:
1807 + if(fifo->fifonum==HFCUSB_D_TX)
1808 + {
1809 +#ifdef VERBOSE_ISDN_DEBUG
1810 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST\n");
1811 +#endif
1812 + printk (KERN_INFO "HFC-USB: ISDN TE device should not deativate...\n");
1813 + }
1814 + else
1815 + {
1816 +#ifdef VERBOSE_ISDN_DEBUG
1817 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST\n");
1818 +#endif
1819 + set_hfcmode(hfc,(fifo->fifonum==HFCUSB_B1_TX) ? 0 : 1 ,(int)L1_MODE_NULL);
1820 + fifo->hif->l1l2(fifo->hif,PH_DEACTIVATE | INDICATION, NULL);
1821 + }
1822 + break;
1823 + case PH_DATA | REQUEST:
1824 + if(fifo->skbuff && fifo->delete_flg)
1825 + {
1826 + dev_kfree_skb_any(fifo->skbuff);
1827 + //printk(KERN_INFO "skbuff=NULL on fifo:%d\n",fifo->fifonum);
1828 + fifo->skbuff = NULL;
1829 + fifo->delete_flg=FALSE;
1830 + }
1831 +
1832 + fifo->skbuff=arg; // we have a new buffer
1833 +
1834 + //if(fifo->fifonum==HFCUSB_D_TX) printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DATA | REQUEST\n");
1835 + //else printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DATA | REQUEST\n");
1836 + break;
1837 + default:
1838 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x\n", pr);
1839 + break;
1840 + }
1841 +}
1842 +
1843 +// valid configurations
1844 +#define CNF_4INT3ISO 1 // 4 INT IN, 3 ISO OUT
1845 +#define CNF_3INT3ISO 2 // 3 INT IN, 3 ISO OUT
1846 +#define CNF_4ISO3ISO 3 // 4 ISO IN, 3 ISO OUT
1847 +#define CNF_3ISO3ISO 4 // 3 ISO IN, 3 ISO OUT
1848 +
1849 +
1850 +/*
1851 + --------------------------------------------------------------------------------------
1852 + From here on USB initialization and deactivation related routines are implemented :
1853 +
1854 + - hfc_usb_init :
1855 + is the main Entry Point for the USB Subsystem when the device get plugged
1856 + in. This function calls usb_register with usb_driver as parameter.
1857 + Here, further entry points for probing (hfc_usb_probe) and disconnecting
1858 + the device (hfc_usb_disconnect) are published, as the id_table
1859 +
1860 + - hfc_usb_probe
1861 + this function is called by the usb subsystem, and steps through the alternate
1862 + settings of the currently plugged in device to detect all Endpoints needed to
1863 + run an ISDN TA.
1864 + Needed EndPoints are
1865 + 3 (+1) IntIn EndPoints (D-in, E-in, B1-in, B2-in, (E-in)) or
1866 + 3 (+1) Isochron In Endpoints (D-out, B1-out, B2-out) and 3 IsoOut Endpoints
1867 + The currently used transfer mode of on the Out-Endpoints will be stored in
1868 + hfc->usb_transfer_mode and is either USB_INT or USB_ISO
1869 + When a valid alternate setting could be found, the usb_init (see blow)
1870 + function is called
1871 +
1872 + - usb_init
1873 + Here, the HFC_USB Chip itself gets initialized and the USB framework to send/receive
1874 + Data to/from the several EndPoints are initialized:
1875 + The E- and D-Channel Int-In chain gets started
1876 + The IsoChain for the Iso-Out traffic get started
1877 +
1878 + - hfc_usb_disconnect
1879 + this function is called by the usb subsystem and has to free all resources
1880 + and stop all usb traffic to allow a proper hotplugging disconnect.
1881 +
1882 +*/
1883
1884 /***************************************************************************/
1885 /* usb_init is called once when a new matching device is detected to setup */
1886 -/* main parmeters. It registers the driver at the main hisax module. */
1887 +/* main parameters. It registers the driver at the main hisax module. */
1888 /* on success 0 is returned. */
1889 /***************************************************************************/
1890 -static int
1891 -usb_init(hfcusb_data * hfc)
1892 +static int usb_init(hfcusb_data * hfc)
1893 {
1894 usb_fifo *fifo;
1895 - int i;
1896 + int i, err;
1897 u_char b;
1898 -
1899 + struct hisax_b_if *p_b_if[2];
1900 +
1901 /* check the chip id */
1902 - if ((Read_hfc(hfc, HFCUSB_CHIP_ID, &b) != 1) ||
1903 - (b != HFCUSB_CHIPID)) {
1904 + printk(KERN_INFO "HFCUSB_CHIP_ID begin\n");
1905 + if (read_usb(hfc, HFCUSB_CHIP_ID, &b) != 1) {
1906 + printk(KERN_INFO "HFC-USB: cannot read chip id\n");
1907 + return(1);
1908 + }
1909 + printk(KERN_INFO "HFCUSB_CHIP_ID %x\n", b);
1910 + if (b != HFCUSB_CHIPID) {
1911 printk(KERN_INFO "HFC-USB: Invalid chip id 0x%02x\n", b);
1912 - return (1);
1913 + return(1);
1914 }
1915
1916 /* first set the needed config, interface and alternate */
1917 - usb_set_configuration(hfc->dev, 1);
1918 - usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used);
1919 + printk(KERN_INFO "usb_init 1\n");
1920 +// usb_set_configuration(hfc->dev, 1);
1921 + printk(KERN_INFO "usb_init 2\n");
1922 + err = usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used);
1923 + printk(KERN_INFO "usb_init usb_set_interface return %d\n", err);
1924 + /* now we initialize the chip */
1925 + write_usb(hfc, HFCUSB_CIRM, 8); // do reset
1926 + write_usb(hfc, HFCUSB_CIRM, 0x10); // aux = output, reset off
1927
1928 - /* init the led state request */
1929 - hfc->led_req = LED_DRIVER;
1930 + // set USB_SIZE to match the the wMaxPacketSize for INT or BULK transfers
1931 + write_usb(hfc, HFCUSB_USB_SIZE,(hfc->packet_size/8) | ((hfc->packet_size/8) << 4));
1932
1933 - /* now we initialise the chip */
1934 - Write_hfc(hfc, HFCUSB_CIRM, 0x10); /* aux = output, reset off */
1935 - Write_hfc(hfc, HFCUSB_P_DATA, 0); /* leds = off */
1936 - Write_hfc(hfc, HFCUSB_USB_SIZE,
1937 - (hfc->fifos[HFCUSB_B1_TX].usb_maxlen >> 3) |
1938 - ((hfc->fifos[HFCUSB_B1_RX].usb_maxlen >> 3) << 4));
1939 + // set USB_SIZE_I to match the the wMaxPacketSize for ISO transfers
1940 + write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size);
1941
1942 /* enable PCM/GCI master mode */
1943 - Write_hfc(hfc, HFCUSB_MST_MODE1, 0); /* set default values */
1944 - Write_hfc(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */
1945 + write_usb(hfc, HFCUSB_MST_MODE1, 0); /* set default values */
1946 + write_usb(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */
1947
1948 /* init the fifos */
1949 - Write_hfc(hfc, HFCUSB_F_THRES, (HFCUSB_TX_THRESHOLD >> 3) |
1950 - ((HFCUSB_RX_THRESHOLD >> 3) << 4));
1951 + write_usb(hfc, HFCUSB_F_THRES, (HFCUSB_TX_THRESHOLD/8) |((HFCUSB_RX_THRESHOLD/8) << 4));
1952
1953 - for (i = 0, fifo = hfc->fifos + i; i < HFCUSB_NUM_FIFOS;
1954 - i++, fifo++) {
1955 - Write_hfc(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
1956 -
1957 - fifo->transmode = 0; /* hdlc mode selected */
1958 - fifo->buff = NULL; /* init buffer pointer */
1959 - fifo->max_size =
1960 - (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN;
1961 - Write_hfc(hfc, HFCUSB_HDLC_PAR, ((i <= HFCUSB_B2_RX) ? 0 : 2)); /* data length */
1962 - Write_hfc(hfc, HFCUSB_CON_HDLC, ((i & 1) ? 0x08 : 0x09)); /* rx hdlc, tx fill 1 */
1963 - Write_hfc(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */
1964 - }
1965 -
1966 - Write_hfc(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */
1967 - Write_hfc(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */
1968 - Write_hfc(hfc, HFCUSB_STATES, 3); /* enable state machine */
1969 + fifo = hfc->fifos;
1970 + for(i = 0; i < HFCUSB_NUM_FIFOS; i++)
1971 + {
1972 + write_usb(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
1973 + fifo[i].skbuff = NULL; /* init buffer pointer */
1974 + fifo[i].max_size = (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN;
1975 + fifo[i].last_urblen=0;
1976 + write_usb(hfc, HFCUSB_HDLC_PAR, ((i <= HFCUSB_B2_RX) ? 0 : 2)); // set 2 bit for D- & E-channel
1977 + write_usb(hfc, HFCUSB_CON_HDLC, ((i==HFCUSB_D_TX) ? 0x09 : 0x08)); // rx hdlc, enable IFF for D-channel
1978 + write_usb(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */
1979 + }
1980
1981 - Write_hfc(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */
1982 - Write_hfc(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + cap mode */
1983 + write_usb(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */
1984 + write_usb(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */
1985 + write_usb(hfc, HFCUSB_STATES, 3); /* enable state machine */
1986 +
1987 + write_usb(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */
1988 + write_usb(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + capacitive mode */
1989 +
1990 + // set both B-channel to not connected
1991 + hfc->b_mode[0]=L1_MODE_NULL;
1992 + hfc->b_mode[1]=L1_MODE_NULL;
1993 +
1994 + hfc->l1_activated=FALSE;
1995 + hfc->led_state=0;
1996 + hfc->led_new_data=0;
1997
1998 - /* init the l1 timer */
1999 + /* init the t3 timer */
2000 init_timer(&hfc->t3_timer);
2001 hfc->t3_timer.data = (long) hfc;
2002 - hfc->t3_timer.function = (void *) l1_timer_expire;
2003 + hfc->t3_timer.function = (void *) l1_timer_expire_t3;
2004 + /* init the t4 timer */
2005 + init_timer(&hfc->t4_timer);
2006 hfc->t4_timer.data = (long) hfc;
2007 - hfc->t4_timer.function = (void *) l1_timer_expire;
2008 - hfc->l1_tq.routine = (void *) (void *) usb_l1d_bh;
2009 - hfc->l1_tq.sync = 0;
2010 - hfc->l1_tq.data = hfc;
2011 -
2012 - /* init the background control machinery */
2013 - hfc->ctrl_read.requesttype = 0xc0;
2014 - hfc->ctrl_read.request = 1;
2015 - hfc->ctrl_read.length = 1;
2016 - hfc->ctrl_write.requesttype = 0x40;
2017 - hfc->ctrl_write.request = 0;
2018 - hfc->ctrl_write.length = 0;
2019 - FILL_CONTROL_URB(&hfc->ctrl_urb, hfc->dev, hfc->ctrl_out_pipe,
2020 - (u_char *) & hfc->ctrl_write, NULL, 0,
2021 - ctrl_complete, hfc);
2022 -
2023 - /* init the TX-urbs */
2024 - fifo = hfc->fifos + HFCUSB_D_TX;
2025 - FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe,
2026 - (u_char *) fifo->buffer, 0, tx_complete, fifo);
2027 - fifo = hfc->fifos + HFCUSB_B1_TX;
2028 - FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe,
2029 - (u_char *) fifo->buffer, 0, tx_complete, fifo);
2030 - fifo = hfc->fifos + HFCUSB_B2_TX;
2031 - FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe,
2032 - (u_char *) fifo->buffer, 0, tx_complete, fifo);
2033 -
2034 - /* init the E-buffer */
2035 - skb_queue_head_init(&hfc->regd.erq);
2036 -
2037 - /* now register ourself at hisax */
2038 - hfc->regd.version = HISAX_LOAD_VERSION; /* set our version */
2039 - hfc->regd.cmd = HISAX_LOAD_REGISTER; /* register command */
2040 - hfc->regd.argl1 = (void *) hfc; /* argument for our local routine */
2041 - hfc->regd.dch_l2l1 = hfcusb_l1_access;
2042 - hfc->regd.bch_l2l1 = hfcusb_bch_access;
2043 - hfc->regd.drvname = "hfc_usb";
2044 - if (hisax_register_hfcusb(&hfc->regd)) {
2045 - printk(KERN_INFO "HFC-USB failed to register at hisax\n");
2046 - Write_hfc(hfc, HFCUSB_CIRM, 0x08); /* aux = input, reset on */
2047 - return (1);
2048 - }
2049 -
2050 - /* startup the D- and E-channel fifos */
2051 - start_rx_fifo(hfc->fifos + HFCUSB_D_RX); /* D-fifo */
2052 - if (hfc->fifos[HFCUSB_PCM_RX].pipe)
2053 - start_rx_fifo(hfc->fifos + HFCUSB_PCM_RX); /* E-fifo */
2054 + hfc->t4_timer.function = (void *) l1_timer_expire_t4;
2055 + /* init the led timer */
2056 + init_timer(&hfc->led_timer);
2057 + hfc->led_timer.data = (long) hfc;
2058 + hfc->led_timer.function = (void *) led_timer;
2059 + // trigger 4 hz led timer
2060 + hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000;
2061 + if(!timer_pending(&hfc->led_timer)) add_timer(&hfc->led_timer);
2062 +
2063 + // init the background machinery for control requests
2064 + hfc->ctrl_read.bRequestType = 0xc0;
2065 + hfc->ctrl_read.bRequest = 1;
2066 + hfc->ctrl_read.wLength = 1;
2067 + hfc->ctrl_write.bRequestType = 0x40;
2068 + hfc->ctrl_write.bRequest = 0;
2069 + hfc->ctrl_write.wLength = 0;
2070 + usb_fill_control_urb(hfc->ctrl_urb, hfc->dev, hfc->ctrl_out_pipe,(u_char *) & hfc->ctrl_write, NULL, 0, ctrl_complete, hfc);
2071 +
2072 + /* Init All Fifos */
2073 + for(i = 0; i < HFCUSB_NUM_FIFOS; i++)
2074 + {
2075 + hfc->fifos[i].iso[0].purb = NULL;
2076 + hfc->fifos[i].iso[1].purb = NULL;
2077 + hfc->fifos[i].active = 0;
2078 + }
2079 +
2080 + // register like Germaschewski :
2081 + hfc->d_if.owner = THIS_MODULE;
2082 + hfc->d_if.ifc.priv = &hfc->fifos[HFCUSB_D_TX];
2083 + hfc->d_if.ifc.l2l1 = hfc_usb_l2l1;
2084 +
2085 + for (i=0; i<2; i++)
2086 + {
2087 + hfc->b_if[i].ifc.priv = &hfc->fifos[HFCUSB_B1_TX+i*2];
2088 + hfc->b_if[i].ifc.l2l1 = hfc_usb_l2l1;
2089 + p_b_if[i] = &hfc->b_if[i];
2090 + }
2091 +
2092 + hfc->protocol = 2; /* default EURO ISDN, should be a module_param */
2093 + hisax_register(&hfc->d_if, p_b_if, "hfc_usb", hfc->protocol);
2094 +
2095 + for (i=0; i<4; i++)
2096 + hfc->fifos[i].hif=&p_b_if[i/2]->ifc;
2097 + for (i=4; i<8; i++)
2098 + hfc->fifos[i].hif=&hfc->d_if.ifc;
2099 +
2100 + // 3 (+1) INT IN + 3 ISO OUT
2101 + if(hfc->cfg_used == CNF_3INT3ISO || hfc->cfg_used == CNF_4INT3ISO)
2102 + {
2103 + start_int_fifo(hfc->fifos + HFCUSB_D_RX); // Int IN D-fifo
2104 + if(hfc->fifos[HFCUSB_PCM_RX].pipe) start_int_fifo(hfc->fifos + HFCUSB_PCM_RX); // E-fifo
2105 + start_int_fifo(hfc->fifos + HFCUSB_B1_RX); // Int IN B1-fifo
2106 + start_int_fifo(hfc->fifos + HFCUSB_B2_RX); // Int IN B2-fifo
2107 + }
2108 +
2109 + // 3 (+1) ISO IN + 3 ISO OUT
2110 + if(hfc->cfg_used==CNF_3ISO3ISO || hfc->cfg_used==CNF_4ISO3ISO)
2111 + {
2112 + start_isoc_chain(hfc->fifos + HFCUSB_D_RX, ISOC_PACKETS_D, rx_iso_complete,16);
2113 + if(hfc->fifos[HFCUSB_PCM_RX].pipe) start_isoc_chain(hfc->fifos + HFCUSB_PCM_RX, ISOC_PACKETS_D, rx_iso_complete,16);
2114 + start_isoc_chain(hfc->fifos + HFCUSB_B1_RX, ISOC_PACKETS_B, rx_iso_complete,16);
2115 + start_isoc_chain(hfc->fifos + HFCUSB_B2_RX, ISOC_PACKETS_B, rx_iso_complete,16);
2116 + }
2117 +
2118 + start_isoc_chain(hfc->fifos + HFCUSB_D_TX, ISOC_PACKETS_D, tx_iso_complete,1);
2119 + start_isoc_chain(hfc->fifos + HFCUSB_B1_TX, ISOC_PACKETS_B, tx_iso_complete,1);
2120 + start_isoc_chain(hfc->fifos + HFCUSB_B2_TX, ISOC_PACKETS_B, tx_iso_complete,1);
2121 +
2122 + handle_led(hfc,LED_POWER_ON);
2123 +
2124 + return(0);
2125 +} /* usb_init */
2126 +
2127 +
2128 +/****************************************/
2129 +/* data defining the devices to be used */
2130 +/****************************************/
2131 +// static __devinitdata const struct usb_device_id hfc_usb_idtab[3] = {
2132 +static struct usb_device_id hfc_usb_idtab[] = {
2133 + {USB_DEVICE(0x7b0, 0x0007)}, /* Billion USB TA 2 */
2134 + {USB_DEVICE(0x742, 0x2008)}, /* Stollmann USB TA */
2135 + {USB_DEVICE(0x959, 0x2bd0)}, /* Colognechip USB eval TA */
2136 + {USB_DEVICE(0x8e3, 0x0301)}, /* OliTec ISDN USB */
2137 + {USB_DEVICE(0x675, 0x1688)}, /* DrayTec ISDN USB */
2138 + {USB_DEVICE(0x7fa, 0x0846)}, /* Bewan ISDN USB TA */
2139 + {} /* end with an all-zeroes entry */
2140 +};
2141 +
2142 +MODULE_AUTHOR("Peter Sprenger (sprenger@moving-byters.de)/Martin Bachem (info@colognechip.com)");
2143 +MODULE_DESCRIPTION("HFC I4L USB driver");
2144 +MODULE_DEVICE_TABLE(usb, hfc_usb_idtab);
2145 +MODULE_LICENSE("GPL");
2146 +
2147 +#define EP_NUL 1 // Endpoint at this position not allowed
2148 +#define EP_NOP 2 // all type of endpoints allowed at this position
2149 +#define EP_ISO 3 // Isochron endpoint mandatory at this position
2150 +#define EP_BLK 4 // Bulk endpoint mandatory at this position
2151 +#define EP_INT 5 // Interrupt endpoint mandatory at this position
2152 +
2153 +// this array represents all endpoints possible in the HCF-USB
2154 +// the last 2 entries are the configuration number and the minimum interval for Interrupt endpoints
2155 +int validconf[][18]=
2156 +{
2157 + // INT in, ISO out config
2158 + {EP_NUL,EP_INT,EP_NUL,EP_INT,EP_NUL,EP_INT,EP_NOP,EP_INT,EP_ISO,EP_NUL,EP_ISO,EP_NUL,EP_ISO,EP_NUL,EP_NUL,EP_NUL,CNF_4INT3ISO,2},
2159 + {EP_NUL,EP_INT,EP_NUL,EP_INT,EP_NUL,EP_INT,EP_NUL,EP_NUL,EP_ISO,EP_NUL,EP_ISO,EP_NUL,EP_ISO,EP_NUL,EP_NUL,EP_NUL,CNF_3INT3ISO,2},
2160 + // ISO in, ISO out config
2161 + {EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_NOP,EP_ISO,CNF_4ISO3ISO,2},
2162 + {EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_NUL,EP_NUL,CNF_3ISO3ISO,2},
2163 + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} // EOL element
2164 +};
2165 +
2166 +// string description of chosen config
2167 +char *conf_str[]=
2168 +{
2169 + "4 Interrupt IN + 3 Isochron OUT",
2170 + "3 Interrupt IN + 3 Isochron OUT",
2171 + "4 Isochron IN + 3 Isochron OUT",
2172 + "3 Isochron IN + 3 Isochron OUT"
2173 +};
2174
2175 - return (0);
2176 -} /* usb_init */
2177
2178 /*************************************************/
2179 /* function called to probe a new plugged device */
2180 /*************************************************/
2181 -static void *
2182 -hfc_usb_probe(struct usb_device *dev, unsigned int interface
2183 -#ifdef COMPAT_HAS_USB_IDTAB
2184 - , const struct usb_device_id *id_table)
2185 -#else
2186 - )
2187 -#endif
2188 +//static int hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
2189 +static void* hfc_usb_probe(struct usb_device *dev, unsigned int ifnum, const struct usb_device_id *id)
2190 {
2191 + //struct usb_device *dev= interface_to_usbdev(intf);
2192 + struct usb_interface* intf = dev->actconfig->interface + ifnum;
2193 hfcusb_data *context;
2194 - struct usb_interface *ifp = dev->actconfig->interface + interface;
2195 - struct usb_interface_descriptor *ifdp =
2196 - ifp->altsetting + ifp->act_altsetting;
2197 - struct usb_endpoint_descriptor *epd;
2198 - int i, idx, ep_msk;
2199 -
2200 -#ifdef COMPAT_HAS_USB_IDTAB
2201 - if (id_table && (dev->descriptor.idVendor == id_table->idVendor) &&
2202 - (dev->descriptor.idProduct == id_table->idProduct) &&
2203 -#else
2204 - if ((((dev->descriptor.idVendor == 0x959) &&
2205 - (dev->descriptor.idProduct == 0x2bd0)) ||
2206 - ((dev->descriptor.idVendor == 0x7b0) &&
2207 - (dev->descriptor.idProduct == 0x0006))) &&
2208 -#endif
2209 - (ifdp->bNumEndpoints >= 6) && (ifdp->bNumEndpoints <= 16)) {
2210 - if (!(context = kmalloc(sizeof(hfcusb_data), GFP_KERNEL))) {
2211 - return (NULL); /* got no mem */
2212 - };
2213 - memset(context, 0, sizeof(hfcusb_data)); /* clear the structure */
2214 - i = ifdp->bNumEndpoints; /* get number of endpoints */
2215 - ep_msk = 0; /* none found */
2216 - epd = ifdp->endpoint; /* first endpoint descriptor */
2217 - while (i-- && ((ep_msk & 0xcf) != 0xcf)) {
2218 -
2219 - idx = (((epd->bEndpointAddress & 0x7f) - 1) << 1); /* get endpoint base */
2220 - if (idx < 7) {
2221 - switch (epd->bmAttributes) {
2222 - case USB_ENDPOINT_XFER_INT:
2223 - if (!
2224 - (epd->
2225 - bEndpointAddress &
2226 - 0x80))
2227 - break; /* only interrupt in allowed */
2228 - idx++; /* input index is odd */
2229 - context->fifos[idx].pipe =
2230 - usb_rcvintpipe(dev,
2231 - epd->
2232 - bEndpointAddress);
2233 - break;
2234 -
2235 - case USB_ENDPOINT_XFER_BULK:
2236 - if (epd->
2237 - bEndpointAddress &
2238 - 0x80)
2239 - break; /* only bulk out allowed */
2240 - context->fifos[idx].pipe =
2241 - usb_sndbulkpipe(dev,
2242 - epd->
2243 - bEndpointAddress);
2244 - break;
2245 - default:
2246 - context->fifos[idx].pipe = 0; /* reset data */
2247 - } /* switch attribute */
2248 -
2249 - if (context->fifos[idx].pipe) {
2250 - context->fifos[idx].fifonum = idx;
2251 - context->fifos[idx].fifo_mask =
2252 - 1 << idx;
2253 - context->fifos[idx].hfc = context;
2254 - context->fifos[idx].usb_maxlen =
2255 - epd->wMaxPacketSize;
2256 - context->fifos[idx].intervall =
2257 - epd->bInterval;
2258 - ep_msk |= (1 << idx);
2259 - } else
2260 - ep_msk &= ~(1 << idx);
2261 - } /* idx < 7 */
2262 - epd++;
2263 - }
2264 + //struct usb_host_interface *iface = intf->cur_altsetting;
2265 + //struct usb_host_interface *iface_used = NULL;
2266 + //struct usb_host_endpoint *ep;
2267 + struct usb_endpoint_descriptor* ep;
2268 + //int ifnum = iface->desc.bInterfaceNumber;
2269 + struct usb_interface_descriptor* intfdesc = intf->altsetting + intf->act_altsetting;
2270 + struct usb_interface_descriptor* intfdesc_used = NULL;
2271 + int i, idx, alt_idx, probe_alt_setting, vend_idx, cfg_used, *vcf, attr, cfg_found, cidx, ep_addr;
2272 + int cmptbl[16],small_match,iso_packet_size,packet_size,alt_used=0;
2273 +
2274 +// usb_show_device(dev);
2275 +// usb_show_device_descriptor(&dev->descriptor);
2276 +// usb_show_interface_descriptor(&iface->desc);
2277 + vend_idx=0xffff;
2278 + for(i=0;vdata[i].vendor;i++)
2279 + {
2280 + if(dev->descriptor.idVendor==vdata[i].vendor && dev->descriptor.idProduct==vdata[i].prod_id) vend_idx=i;
2281 + }
2282 +
2283
2284 - if ((ep_msk & 0x3f) != 0x3f) {
2285 - kfree(context);
2286 - return (NULL);
2287 - }
2288 - MOD_INC_USE_COUNT; /* lock our module */
2289 - context->dev = dev; /* save device */
2290 - context->if_used = interface; /* save used interface */
2291 - context->alt_used = ifp->act_altsetting; /* and alternate config */
2292 - context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */
2293 -
2294 - /* create the control pipes needed for register access */
2295 - context->ctrl_in_pipe = usb_rcvctrlpipe(context->dev, 0);
2296 - context->ctrl_out_pipe = usb_sndctrlpipe(context->dev, 0);
2297 -
2298 - /* init the chip and register the driver */
2299 - if (usb_init(context)) {
2300 - kfree(context);
2301 - MOD_DEC_USE_COUNT;
2302 - return (NULL);
2303 - }
2304 +#ifdef VERBOSE_USB_DEBUG
2305 + printk(KERN_INFO "HFC-USB: probing interface(%d) actalt(%d)\n",
2306 + ifnum, intfdesc->bAlternateSetting);
2307 + /* printk(KERN_INFO "HFC-USB: probing interface(%d) actalt(%d) minor(%d)\n",
2308 + ifnum, intfdesc->bAlternateSetting, intf->driver->minor); */
2309 +#endif
2310
2311 - printk(KERN_INFO
2312 - "HFC-USB: New device if=%d alt=%d registered\n",
2313 - context->if_used, context->alt_used);
2314 - return (context);
2315 - }
2316 + if (vend_idx != 0xffff) {
2317 +#ifdef VERBOSE_USB_DEBUG
2318 + printk(KERN_INFO "HFC-USB: found vendor idx:%d name:%s\n",vend_idx,vdata[vend_idx].vend_name);
2319 +#endif
2320 + /* if vendor and product ID is OK, start probing a matching alternate setting ... */
2321 + alt_idx = 0;
2322 + small_match=0xffff;
2323 + // default settings
2324 + iso_packet_size=16;
2325 + packet_size=64;
2326 +
2327 + while (alt_idx < intf->num_altsetting) {
2328 + //iface = intf->altsetting + alt_idx;
2329 + intfdesc = intf->altsetting + alt_idx;
2330 + probe_alt_setting = intfdesc->bAlternateSetting;
2331 + cfg_used=0;
2332
2333 - return (NULL); /* no matching entry */
2334 -} /* hfc_usb_probe */
2335 +#ifdef VERBOSE_USB_DEBUG
2336 + printk(KERN_INFO "HFC-USB: test alt_setting %d\n", probe_alt_setting);
2337 +#endif
2338 + // check for config EOL element
2339 + while (validconf[cfg_used][0]) {
2340 + cfg_found=TRUE;
2341 + vcf=validconf[cfg_used];
2342 + ep = intfdesc->endpoint; /* first endpoint descriptor */
2343 +
2344 +#ifdef VERBOSE_USB_DEBUG
2345 + printk(KERN_INFO "HFC-USB: (if=%d alt=%d cfg_used=%d)\n",
2346 + ifnum, probe_alt_setting, cfg_used);
2347 +#endif
2348 + // copy table
2349 + memcpy(cmptbl,vcf,16*sizeof(int));
2350 +
2351 + // check for all endpoints in this alternate setting
2352 + for (i=0; i < intfdesc->bNumEndpoints; i++) {
2353 + ep_addr = ep->bEndpointAddress;
2354 + idx = ((ep_addr & 0x7f)-1)*2; /* get endpoint base */
2355 + if (ep_addr & 0x80)
2356 + idx++;
2357 + attr = ep->bmAttributes;
2358 +
2359 + if (cmptbl[idx] == EP_NUL) {
2360 + printk(KERN_INFO "HFC-USB: cfg_found=FALSE in idx:%d attr:%d cmptbl[%d]:%d\n",
2361 + idx, attr, idx, cmptbl[idx]);
2362 + cfg_found = FALSE;
2363 + }
2364 +
2365 + if (attr == USB_ENDPOINT_XFER_INT && cmptbl[idx] == EP_INT)
2366 + cmptbl[idx] = EP_NUL;
2367 + if (attr == USB_ENDPOINT_XFER_BULK && cmptbl[idx] == EP_BLK)
2368 + cmptbl[idx] = EP_NUL;
2369 + if (attr == USB_ENDPOINT_XFER_ISOC && cmptbl[idx] == EP_ISO)
2370 + cmptbl[idx] = EP_NUL;
2371 +
2372 + // check if all INT endpoints match minimum interval
2373 + if (attr == USB_ENDPOINT_XFER_INT && ep->bInterval < vcf[17]) {
2374 +#ifdef VERBOSE_USB_DEBUG
2375 + if (cfg_found)
2376 + printk(KERN_INFO "HFC-USB: Interrupt Endpoint interval < %d found - skipping config\n",
2377 + vcf[17]);
2378 +#endif
2379 + cfg_found = FALSE;
2380 + }
2381 +
2382 + ep++;
2383 + }
2384 +
2385 + for (i = 0; i < 16; i++) {
2386 + // printk(KERN_INFO "HFC-USB: cmptbl[%d]:%d\n", i, cmptbl[i]);
2387 +
2388 + // all entries must be EP_NOP or EP_NUL for a valid config
2389 + if (cmptbl[i] != EP_NOP && cmptbl[i] != EP_NUL)
2390 + cfg_found = FALSE;
2391 + }
2392 +
2393 + // we check for smallest match, to provide configuration priority
2394 + // configurations with smaller index have higher priority
2395 + if (cfg_found) {
2396 + if (cfg_used < small_match) {
2397 + small_match = cfg_used;
2398 + alt_used = probe_alt_setting;
2399 + //iface_used = iface;
2400 + intfdesc_used = intfdesc;
2401 + }
2402 +#ifdef VERBOSE_USB_DEBUG
2403 + printk(KERN_INFO "HFC-USB: small_match=%x %x\n", small_match, alt_used);
2404 +#endif
2405 + }
2406 +
2407 + cfg_used++;
2408 + }
2409 +
2410 + alt_idx++;
2411 + } /* (alt_idx < intf->num_altsetting) */
2412 +#ifdef VERBOSE_USB_DEBUG
2413 + printk(KERN_INFO "HFC-USB: final small_match=%x alt_used=%x\n",small_match, alt_used);
2414 +#endif
2415 + // yiipiee, we found a valid config
2416 + if (small_match != 0xffff) {
2417 + //iface = iface_used;
2418 + intfdesc = intfdesc_used;
2419 +
2420 + if (!(context = kmalloc(sizeof(hfcusb_data), GFP_KERNEL)))
2421 + return(NULL); /* got no mem */
2422 + memset(context, 0, sizeof(hfcusb_data)); /* clear the structure */
2423 +
2424 + ep = intfdesc->endpoint; /* first endpoint descriptor */
2425 + vcf = validconf[small_match];
2426 +
2427 + for (i = 0; i < intfdesc->bNumEndpoints; i++) {
2428 + ep_addr = ep->bEndpointAddress;
2429 + idx = ((ep_addr & 0x7f)-1)*2; /* get endpoint base */
2430 + if (ep_addr & 0x80)
2431 + idx++;
2432 + cidx = idx & 7;
2433 + attr = ep->bmAttributes;
2434 +
2435 + // only initialize used endpoints
2436 + if (vcf[idx] != EP_NOP && vcf[idx] != EP_NUL) {
2437 + switch (attr) {
2438 + case USB_ENDPOINT_XFER_INT:
2439 + context->fifos[cidx].pipe = usb_rcvintpipe(dev, ep->bEndpointAddress);
2440 + context->fifos[cidx].usb_transfer_mode = USB_INT;
2441 + packet_size = ep->wMaxPacketSize; // remember max packet size
2442 +#ifdef VERBOSE_USB_DEBUG
2443 + printk (KERN_INFO "HFC-USB: Interrupt-In Endpoint found %d ms(idx:%d cidx:%d)!\n",
2444 + ep->bInterval, idx, cidx);
2445 +#endif
2446 + break;
2447 + case USB_ENDPOINT_XFER_BULK:
2448 + if (ep_addr & 0x80)
2449 + context->fifos[cidx].pipe = usb_rcvbulkpipe(dev, ep->bEndpointAddress);
2450 + else
2451 + context->fifos[cidx].pipe = usb_sndbulkpipe(dev, ep->bEndpointAddress);
2452 + context->fifos[cidx].usb_transfer_mode = USB_BULK;
2453 + packet_size = ep->wMaxPacketSize; // remember max packet size
2454 +#ifdef VERBOSE_USB_DEBUG
2455 + printk (KERN_INFO "HFC-USB: Bulk Endpoint found (idx:%d cidx:%d)!\n",
2456 + idx, cidx);
2457 +#endif
2458 + break;
2459 + case USB_ENDPOINT_XFER_ISOC:
2460 + if (ep_addr & 0x80)
2461 + context->fifos[cidx].pipe = usb_rcvisocpipe(dev, ep->bEndpointAddress);
2462 + else
2463 + context->fifos[cidx].pipe = usb_sndisocpipe(dev, ep->bEndpointAddress);
2464 + context->fifos[cidx].usb_transfer_mode = USB_ISOC;
2465 + iso_packet_size = ep->wMaxPacketSize; // remember max packet size
2466 +#ifdef VERBOSE_USB_DEBUG
2467 + printk (KERN_INFO "HFC-USB: ISO Endpoint found (idx:%d cidx:%d)!\n",
2468 + idx, cidx);
2469 +#endif
2470 + break;
2471 + default:
2472 + context->fifos[cidx].pipe = 0; /* reset data */
2473 + } /* switch attribute */
2474 +
2475 + if (context->fifos[cidx].pipe) {
2476 + context->fifos[cidx].fifonum = cidx;
2477 + context->fifos[cidx].hfc = context;
2478 + context->fifos[cidx].usb_packet_maxlen = ep->wMaxPacketSize;
2479 + context->fifos[cidx].intervall = ep->bInterval;
2480 + context->fifos[cidx].skbuff = NULL;
2481 +#ifdef VERBOSE_USB_DEBUG
2482 + printk (KERN_INFO "HFC-USB: fifo%d pktlen %d interval %d\n",
2483 + context->fifos[cidx].fifonum,
2484 + context->fifos[cidx].usb_packet_maxlen,
2485 + context->fifos[cidx].intervall);
2486 +#endif
2487 + }
2488 + }
2489 +
2490 + ep++;
2491 + }
2492 +
2493 + // now share our luck
2494 + context->dev = dev; /* save device */
2495 + context->if_used = ifnum; /* save used interface */
2496 + context->alt_used = alt_used; /* and alternate config */
2497 + context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */
2498 + context->cfg_used=vcf[16]; // store used config
2499 + context->vend_idx=vend_idx; // store found vendor
2500 + context->packet_size=packet_size;
2501 + context->iso_packet_size=iso_packet_size;
2502 +
2503 + /* create the control pipes needed for register access */
2504 + context->ctrl_in_pipe = usb_rcvctrlpipe(context->dev, 0);
2505 + context->ctrl_out_pipe = usb_sndctrlpipe(context->dev, 0);
2506 + context->ctrl_urb = usb_alloc_urb(0);
2507 +
2508 + printk(KERN_INFO "HFC-USB: detected \"%s\" configuration: %s (if=%d alt=%d)\n",
2509 + vdata[vend_idx].vend_name, conf_str[small_match], context->if_used, context->alt_used);
2510 +
2511 + /* init the chip and register the driver */
2512 + if (usb_init(context))
2513 + {
2514 + if (context->ctrl_urb) {
2515 + usb_unlink_urb(context->ctrl_urb);
2516 + usb_free_urb(context->ctrl_urb);
2517 + context->ctrl_urb = NULL;
2518 + }
2519 + kfree(context);
2520 + return(NULL);
2521 + }
2522 + //usb_set_intfdata(intf, context);
2523 + //intf->private_data = context;
2524 + return(context);
2525 + }
2526 + }
2527 + return(NULL);
2528 +}
2529
2530 /****************************************************/
2531 /* function called when an active device is removed */
2532 /****************************************************/
2533 -static void
2534 -hfc_usb_disconnect(struct usb_device *usbdev, void *drv_context)
2535 +//static void hfc_usb_disconnect(struct usb_interface *intf)
2536 +static void hfc_usb_disconnect(struct usb_device *usbdev, void* drv_context)
2537 {
2538 - hfcusb_data *context = drv_context;
2539 + //hfcusb_data *context = intf->private_data;
2540 + hfcusb_data* context = drv_context;
2541 int i;
2542 - struct sk_buff *skb;
2543
2544 - /* tell all fifos to terminate */
2545 - for (i = 0; i < HFCUSB_NUM_FIFOS; i++)
2546 - if (context->fifos[i].active) {
2547 - context->fifos[i].active = 0;
2548 - usb_unlink_urb(&context->fifos[i].urb);
2549 - }
2550 - while (context->active_fifos) {
2551 - set_current_state(TASK_INTERRUPTIBLE);
2552 - /* Timeout 10ms */
2553 - schedule_timeout((10 * HZ) / 1000);
2554 - }
2555 + printk(KERN_INFO "HFC-USB: device disconnect\n");
2556 +
2557 + //intf->private_data = NULL;
2558 + if (!context)
2559 + return;
2560 if (timer_pending(&context->t3_timer))
2561 del_timer(&context->t3_timer);
2562 - context->regd.release_driver(context->regd.arg_hisax);
2563 - while ((skb = skb_dequeue(&context->regd.erq)) != NULL)
2564 - dev_kfree_skb_any(skb);
2565 + if (timer_pending(&context->t4_timer))
2566 + del_timer(&context->t4_timer);
2567 + if (timer_pending(&context->led_timer))
2568 + del_timer(&context->led_timer);
2569 +
2570 + hisax_unregister(&context->d_if);
2571
2572 + /* tell all fifos to terminate */
2573 + for(i = 0; i < HFCUSB_NUM_FIFOS; i++) {
2574 + if(context->fifos[i].usb_transfer_mode == USB_ISOC) {
2575 + if(context->fifos[i].active > 0) {
2576 + stop_isoc_chain(&context->fifos[i]);
2577 +#ifdef VERBOSE_USB_DEBUG
2578 + printk (KERN_INFO "HFC-USB: hfc_usb_disconnect: stopping ISOC chain Fifo no %i\n", i);
2579 +#endif
2580 + }
2581 + } else {
2582 + if(context->fifos[i].active > 0) {
2583 + context->fifos[i].active = 0;
2584 +#ifdef VERBOSE_USB_DEBUG
2585 + printk (KERN_INFO "HFC-USB: hfc_usb_disconnect: unlinking URB for Fifo no %i\n", i);
2586 +#endif
2587 + }
2588 + if (context->fifos[i].urb) {
2589 + usb_unlink_urb(context->fifos[i].urb);
2590 + usb_free_urb(context->fifos[i].urb);
2591 + context->fifos[i].urb = NULL;
2592 + }
2593 + }
2594 + context->fifos[i].active = 0;
2595 + }
2596 + if (context->ctrl_urb) {
2597 + usb_unlink_urb(context->ctrl_urb);
2598 + usb_free_urb(context->ctrl_urb);
2599 + context->ctrl_urb = NULL;
2600 + }
2601 kfree(context); /* free our structure again */
2602 - MOD_DEC_USE_COUNT; /* and decrement the usage counter */
2603 } /* hfc_usb_disconnect */
2604
2605 +
2606 /************************************/
2607 /* our driver information structure */
2608 /************************************/
2609 static struct usb_driver hfc_drv = {
2610 name:"hfc_usb",
2611 -#ifdef COMPAT_HAS_USB_IDTAB
2612 id_table:hfc_usb_idtab,
2613 -#endif
2614 probe:hfc_usb_probe,
2615 disconnect:hfc_usb_disconnect,
2616 };
2617
2618 -static void __exit
2619 -hfc_usb_exit(void)
2620 -{
2621
2622 +static void __exit hfc_usb_exit(void)
2623 +{
2624 +#ifdef VERBOSE_USB_DEBUG
2625 + printk ("HFC-USB: calling \"hfc_usb_exit\" ...\n");
2626 +#endif
2627 usb_deregister(&hfc_drv); /* release our driver */
2628 printk(KERN_INFO "HFC-USB module removed\n");
2629 }
2630
2631 -static int __init
2632 -hfc_usb_init(void)
2633 +static int __init hfc_usb_init(void)
2634 {
2635 - struct hisax_drvreg drv;
2636 + printk ("HFC-USB: driver module revision %s loaded\n", hfcusb_revision);
2637
2638 - drv.version = HISAX_LOAD_VERSION; /* set our version */
2639 - drv.cmd = HISAX_LOAD_CHKVER; /* check command only */
2640 - if (hisax_register_hfcusb(&drv)) {
2641 - printk(KERN_INFO "HFC-USB <-> hisax version conflict\n");
2642 - return (-1); /* unable to register */
2643 - }
2644 - if (usb_register(&hfc_drv)) {
2645 - printk(KERN_INFO
2646 - "Unable to register HFC-USB module at usb stack\n");
2647 - return (-1); /* unable to register */
2648 + if(usb_register(&hfc_drv))
2649 + {
2650 + printk(KERN_INFO "HFC-USB: Unable to register HFC-USB module at usb stack\n");
2651 + return(-1); /* unable to register */
2652 }
2653 -
2654 - printk(KERN_INFO "HFC-USB module loaded\n");
2655 - return (0);
2656 + return(0);
2657 }
2658
2659 +
2660 +
2661 +
2662 +
2663 module_init(hfc_usb_init);
2664 module_exit(hfc_usb_exit);
2665 +
This page took 0.155011 seconds and 5 git commands to generate.