1 Index: linux-2.4.35.4/drivers/Makefile
2 ===================================================================
3 --- linux-2.4.35.4.orig/drivers/Makefile 2007-12-15 05:19:39.306660996 +0100
4 +++ linux-2.4.35.4/drivers/Makefile 2007-12-15 05:19:59.111789629 +0100
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
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 2007-12-15 05:19:55.575588111 +0100
17 +++ linux-2.4.35.4/drivers/isdn/hisax/hfc_usb.c 2007-12-15 05:19:59.115789855 +0100
19 -/* $Id: hfc_usb.c,v 2.3 2001/07/06 21:30:11 werner Exp $
23 + * modular HiSax ISDN driver for Colognechip HFC-USB chip
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
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)
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
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
44 + * ported 2.6.8 hfc_usb.c to 2.4.20 format
45 + * Gregor Schaffrath <gschaff@ran-dom.org>
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>
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"
66 +static const char *hfcusb_revision = "4.0";
69 + to enable much mire debug messages in this driver, define
70 + VERBOSE_USB_DEBUG and VERBOSE_ISDN_DEBUG
74 +#define VERBOSE_USB_DEBUG
75 +#define VERBOSE_ISDN_DEBUG
77 #define INCLUDE_INLINE_FUNCS
86 -#define HFC_CTRL_TIMEOUT 5 /* 5ms timeout writing/reading regs */
87 -#define HFC_TIMER_T3 7000 /* timeout for l1 activation timer */
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 */
94 -#define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */
96 -#define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */
97 -#define HFCUSB_TX_THRESHOLD 64 /* threshold for fifo report bit tx */
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 */
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 */
116 +#define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */
118 +#define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */
119 +#define HFCUSB_TX_THRESHOLD 64 /* threshold for fifo report bit tx */
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
147 -#define HFCUSB_CHIPID 0x40 /* ID value of HFC-USB */
148 +#define HFCUSB_CHIPID 0x40 /* ID value of HFC-USB */
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
169 -#define LED_DRIVER 0x1
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
180 +#define ISOC_PACKETS_D 8
181 +#define ISOC_PACKETS_B 8
182 +#define ISO_BUFFER_SIZE 128
184 +// ISO send definitions
187 +#define SINK_DMIN 12
188 +#define SINK_DMAX 18
189 +#define BITLINE_INF (-64*8)
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)
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 */
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)
213 /*************************************************/
214 /* entry and size of output/input control buffer */
215 /*************************************************/
216 #define HFC_CTRL_BUFSIZE 32
220 __u8 hfc_reg; /* register number */
221 __u8 reg_val; /* value to be written (or read) */
222 + int action; /* data for action handler */
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
237 /***************************************************************/
238 /* structure defining input+output fifos (interrupt/bulk mode) */
239 /***************************************************************/
240 -struct hfcusb_data; /* forward definition */
242 - int fifonum; /* fifo index attached to this structure */
243 - __u8 fifo_mask; /* mask for this fifo */
244 - int active; /* fifo is currently active */
246 +struct usb_fifo; /* forward definition */
247 +typedef struct iso_urb_struct
250 + __u8 buffer[ISO_BUFFER_SIZE]; /* buffer incoming/outgoing data */
251 + struct usb_fifo *owner_fifo; // pointer to owner fifo
255 +struct hfcusb_data; /* forward definition */
256 +typedef struct usb_fifo
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? */
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 */
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
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 */
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
315 + int b_mode[2]; // B-channel mode
317 + int l1_activated; // layer 1 activated
319 + int packet_size,iso_packet_size;
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 */
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 */
340 + struct usb_ctrlrequest ctrl_write; /* buffer for control write request */
341 + struct usb_ctrlrequest ctrl_read; /* same for read request */
343 + __u8 led_state,led_new_data,led_b_active;
345 + volatile __u8 threshold_mask; /* threshold actually reported */
346 + volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */
348 usb_fifo fifos[HFCUSB_NUM_FIFOS]; /* structure holding all fifo data */
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 */
365 -usb_dump_urb(purb_t purb)
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);
387 -/*************************************************************************/
388 -/* bottom half handler for L1 activation/deactiavtaion + D-chan + E-chan */
389 -/*************************************************************************/
391 -usb_l1d_bh(hfcusb_data * hfc)
393 +static void collect_rx_frame(usb_fifo *fifo,__u8 *data,int len,int finish);
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;
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,
407 - 7) ? (PH_ACTIVATE |
409 - : (PH_DEACTIVATE | INDICATION),
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,
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,
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);
429 /******************************************************/
430 /* start next background transfer for control channel */
431 /******************************************************/
433 -ctrl_start_transfer(hfcusb_data * hfc)
434 +static void ctrl_start_transfer(hfcusb_data * hfc)
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].
447 - hfc->ctrl_urb.transfer_buffer =
448 - (char *) &hfc->dfifo_fill;
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].
460 - hfc->ctrl_write.value =
461 - hfc->ctrl_buff[hfc->ctrl_out_idx].
465 - usb_submit_urb(&hfc->ctrl_urb); /* start transfer */
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);
478 } /* ctrl_start_transfer */
480 @@ -293,897 +275,1418 @@
481 /* queue a control transfer request */
482 /* return 0 on success. */
483 /************************************/
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)
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);
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 */
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);
507 -} /* queue_control_request */
509 +} /* queue_control_request */
511 -/**************************************/
512 -/* called when timer t3 or t4 expires */
513 -/**************************************/
515 -l1_timer_expire(hfcusb_data * hfc)
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,
522 - queue_task(&hfc->l1_tq, &tq_immediate);
523 - mark_bh(IMMEDIATE_BH);
524 -} /* l1_timer_expire */
526 -/**************************************************/
527 -/* (re)fills a tx-fifo urb. Queuing is done later */
528 -/**************************************************/
530 -fill_tx_urb(usb_fifo * fifo)
532 - struct sk_buff *skb;
536 - fifo->urb.dev = fifo->hfc->dev;
538 - && (fifo->urb.transfer_buffer_length < fifo->usb_maxlen)) {
539 - switch (fifo->fifonum) {
544 - fifo->hfc->regd.bch_l1l2(fifo->hfc->regd.
552 - fifo->hfc->service_request |=
556 - dev_kfree_skb_any(fifo->buff);
560 - fifo->hfc->dfifo_fill = 0xff; /* currently invalid data */
561 - queue_control_request(fifo->hfc,
564 - queue_control_request(fifo->hfc,
565 - HFCUSB_F_USAGE, 0);
566 - restore_flags(flags);
569 - return; /* error, invalid fifo */
572 +static int control_action_handler(hfcusb_data *hfc,int reg,int val,int action)
574 + if(!action) return(1); // no action defined
580 +/***************************************************************/
581 +/* control completion routine handling background control cmds */
582 +/***************************************************************/
583 +static void ctrl_complete(struct urb *urb)
585 + hfcusb_data *hfc = (hfcusb_data *) urb->context;
588 + printk(KERN_DEBUG "ctrl_complete cnt %d\n", hfc->ctrl_cnt);
589 + urb->dev = hfc->dev;
592 + buf=&hfc->ctrl_buff[hfc->ctrl_out_idx];
593 + control_action_handler(hfc,buf->hfc_reg,buf->reg_val,buf->action);
595 + hfc->ctrl_cnt--; /* decrement actual count */
596 + if(++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE) hfc->ctrl_out_idx = 0; /* pointer wrap */
598 + ctrl_start_transfer(hfc); /* start next transfer */
600 +} /* ctrl_complete */
604 +#define LED_OFF 0 // no LED support
605 +#define LED_SCHEME1 1 // LED standard scheme
606 +#define LED_SCHEME2 2 // not used yet...
608 +#define LED_POWER_ON 1
609 +#define LED_POWER_OFF 2
611 +#define LED_S0_OFF 4
613 +#define LED_B1_OFF 6
614 +#define LED_B1_DATA 7
616 +#define LED_B2_OFF 9
617 +#define LED_B2_DATA 10
619 +#define LED_NORMAL 0 // LEDs are normal
620 +#define LED_INVERTED 1 // LEDs are inverted
622 +// time for LED flashing
623 +#define LED_TIME 250
625 +vendor_data vdata[]=
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 */
636 +/***************************************************/
637 +/* write led data to auxport & invert if necessary */
638 +/***************************************************/
639 +static void write_led(hfcusb_data * hfc,__u8 led_state)
641 + if(led_state!=hfc->led_state)
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);
648 +/******************************************/
649 +/* invert B-channel LEDs if data is sent */
650 +/******************************************/
651 +static void led_timer(hfcusb_data * hfc)
654 + __u8 led_state=hfc->led_state;
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];
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];
667 - /* check if new buffer needed */
669 - switch (fifo->fifonum) {
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;
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);
682 +/**************************/
683 +/* handle LED requests */
684 +/**************************/
685 +static void handle_led(hfcusb_data * hfc,int event)
687 + __u8 led_state=hfc->led_state;
689 + // if no scheme -> no LED action
690 + if(vdata[hfc->vend_idx].led_scheme==LED_OFF) return;
695 + led_state|=vdata[hfc->vend_idx].led_bits[0];
697 + case LED_POWER_OFF: // no Power off handling
700 + led_state|=vdata[hfc->vend_idx].led_bits[1];
703 + led_state&=~vdata[hfc->vend_idx].led_bits[1];
706 - if (fifo->hfc->regd.bsk[1])
707 - fifo->buff = *fifo->hfc->regd.bsk[1]; /* B2-channel tx buffer */
709 + hfc->led_b_active|=1;
712 - if (fifo->hfc->regd.dsq)
713 - fifo->buff = skb_dequeue(fifo->hfc->regd.dsq); /* D-channel tx queue */
715 + hfc->led_b_active&=~1;
718 - return; /* error, invalid fifo */
720 + hfc->led_new_data|=1;
723 + hfc->led_b_active|=2;
726 + hfc->led_b_active&=~2;
729 + hfc->led_new_data|=2;
733 + write_led(hfc,led_state);
736 +/********************************/
737 +/* called when timer t3 expires */
738 +/********************************/
739 +static void l1_timer_expire_t3(hfcusb_data * hfc)
741 + //printk (KERN_INFO "HFC-USB: l1_timer_expire_t3\n");
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");
747 + hfc->l1_activated=FALSE;
748 + handle_led(hfc,LED_S0_OFF);
751 +/********************************/
752 +/* called when timer t4 expires */
753 +/********************************/
754 +static void l1_timer_expire_t4(hfcusb_data * hfc)
756 + //printk (KERN_INFO "HFC-USB: l1_timer_expire_t4\n");
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");
762 + hfc->l1_activated=FALSE;
763 + handle_led(hfc,LED_S0_OFF);
766 +/*****************************/
767 +/* handle S0 state changes */
768 +/*****************************/
769 +static void state_handler(hfcusb_data * hfc,__u8 state)
773 + old_state=hfc->l1_state;
776 + if(state==old_state || state<1 || state>8) return;
778 +#ifdef VERBOSE_ISDN_DEBUG
779 + printk(KERN_INFO "HFC-USB: new S0 state:%d old_state:%d\n",state,old_state);
782 + if(state<4 || state==7 || state==8)
784 + if(timer_pending(&hfc->t3_timer)) del_timer(&hfc->t3_timer);
785 + //printk(KERN_INFO "HFC-USB: T3 deactivated\n");
790 + if(timer_pending(&hfc->t4_timer)) del_timer(&hfc->t4_timer);
791 + //printk(KERN_INFO "HFC-USB: T4 deactivated\n");
794 + if(state==7 && !hfc->l1_activated)
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);
802 + if(state<=3 /* && activated*/)
804 + if(old_state==7 || old_state==8)
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);
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,
818 - mark_bh(IMMEDIATE_BH);
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);
828 - fifo->act_ptr = fifo->buff->data; /* start of data */
831 - fifo->hfc->active_fifos |= fifo->fifo_mask;
832 - fifo->hfc->service_request &= ~fifo->fifo_mask;
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;
841 - memcpy(fifo->buffer + ii, fifo->act_ptr, i);
842 - fifo->urb.transfer_buffer_length = i + ii;
843 - fifo->rx_offset = ii;
846 -/************************************************/
847 -/* transmit completion routine for all tx fifos */
848 -/************************************************/
850 -tx_complete(purb_t urb)
853 + hfc->l1_state=state;
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)
861 - usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */
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 ?
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;
885 - /* check for deactivation or error */
886 - if ((!fifo->active) || (urb->status)) {
887 - fifo->hfc->active_fifos &= ~fifo->fifo_mask; /* we are inactive */
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)
896 +#ifdef VERBOSE_USB_DEBUG
897 + printk(KERN_INFO "HFC-USB: starting ISO-chain for Fifo %i\n", fifo->fifonum);
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;
907 + // Init the first iso
908 + if (ISO_BUFFER_SIZE >= (fifo->usb_packet_maxlen * num_packets_per_urb))
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]);
915 + memset(fifo->iso[i].buffer, 0, sizeof(fifo->iso[i].buffer));
917 + // defining packet delimeters in fifo->buffer
918 + for(k = 0; k < num_packets_per_urb; k++)
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;
928 + fifo->bit_line = BITLINE_INF;
930 + errcode = usb_submit_urb(fifo->iso[i].purb);
931 + fifo->active = (errcode >= 0) ? 1 : 0;
934 + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i.%i \n", errcode, i);
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 */
942 - fifo->hfc->service_request |= fifo->fifo_mask; /* need to restart */
945 -/***********************************************/
946 -/* receive completion routine for all rx fifos */
947 -/***********************************************/
949 -rx_complete(purb_t urb)
950 + // errcode = (usb_submit_urb(fifo->iso[0].purb, GFP_KERNEL));
951 + return(fifo->active);
954 +/* stops running iso chain and frees their pending urbs */
955 +static void stop_isoc_chain(usb_fifo * fifo)
957 - usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */
958 - hfcusb_data *hfc = fifo->hfc;
961 - int i, ii, currcnt, hdlci;
962 - struct sk_buff *skb;
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 */
970 - dev_kfree_skb_any(fifo->buff);
974 + for(i = 0; i < 2; i++)
976 + if(fifo->iso[i].purb)
978 +#ifdef VERBOSE_USB_DEBUG
979 + printk(KERN_INFO "HFC-USB: Stopping iso chain for fifo %i.%i\n", fifo->fifonum, i);
981 + usb_unlink_urb(fifo->iso[i].purb);
982 + usb_free_urb(fifo->iso[i].purb);
983 + fifo->iso[i].purb = NULL;
988 + usb_unlink_urb(fifo->urb);
989 + usb_free_urb(fifo->urb);
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 */
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);
1007 - /* check if rescheduling needed */
1009 - hfc->service_request & hfc->active_fifos & ~hfc->
1010 - threshold_mask)) {
1012 - usb_get_current_frame_number(hfc->dev);
1013 - txfifo = hfc->fifos + HFCUSB_B1_TX;
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);
1023 - usb_submit_urb(&txfifo->
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};
1029 +/*****************************************************/
1030 +/* transmit completion routine for all ISO tx fifos */
1031 +/*****************************************************/
1032 +static void tx_iso_complete(struct urb *urb)
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;
1039 + __u8 threshtable[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1041 + fifon=fifo->fifonum;
1043 + // very weird error code when using ohci drivers, for now : ignore this error ... (MB)
1044 + if(urb->status == -EOVERFLOW)
1047 +#ifdef VERBOSE_USB_DEBUG
1048 + printk(KERN_INFO "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",fifon);
1052 + if(fifo->active && !urb->status)
1055 + if(fifon<4 && hfc->b_mode[fifon/2]==L1_MODE_TRANS) transp_mode=TRUE;
1057 + threshbit = threshtable[fifon] & hfc->threshold_mask; // is threshold set for our channel?
1058 + num_isoc_packets=iso_packets[fifon];
1060 + if(fifon >= HFCUSB_D_TX)
1062 + sink = (threshbit) ? SINK_DMIN : SINK_DMAX; // how much bit go to the sink for D-channel?
1066 + sink = (threshbit) ? SINK_MIN : SINK_MAX; // how much bit go to the sink for B-channel?
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));
1074 + frame_complete=FALSE;
1076 + // Generate Iso Packets
1077 + for(k = 0; k < num_isoc_packets; ++k)
1081 + len = fifo->skbuff->len; // remaining length
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?
1089 + context_iso_urb->buffer[tx_offset] = 0;
1090 + if(current_len == len)
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
1097 + frame_complete = TRUE;
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);
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;
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);
1112 + if(fifon==HFCUSB_B1_TX) handle_led(hfc,LED_B1_DATA);
1113 + if(fifon==HFCUSB_B2_TX) handle_led(hfc,LED_B2_DATA);
1118 + // we have no more data - generate 1 byte ISO packets
1119 + urb->iso_frame_desc[k].offset = tx_offset++;
1121 + urb->iso_frame_desc[k].length = 1;
1122 + fifo->bit_line -= sink; // we lower data margin every msec
1124 + if(fifo->bit_line < BITLINE_INF)
1126 + fifo->bit_line = BITLINE_INF;
1127 + //printk (KERN_INFO "HFC-USB: BITLINE_INF underrun\n");
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);
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,
1152 - queue_task(&hfc->l1_tq, &tq_immediate);
1153 - mark_bh(IMMEDIATE_BH);
1154 + if(frame_complete)
1156 + // delete the buffer only once, here or in hfc_usb_l2l1() in a PH_DATA|REQUEST
1157 + fifo->delete_flg=TRUE;
1159 + fifo->hif->l1l2(fifo->hif,PH_DATA|CONFIRM,(void*)fifo->skbuff->truesize);
1161 + if(fifo->skbuff && fifo->delete_flg)
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;
1169 + frame_complete=FALSE;
1173 + errcode = usb_submit_urb(urb);
1176 + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i \n", errcode);
1183 + printk(KERN_INFO "HFC-USB: tx_iso_complete : urb->status %i, fifonum %i\n", urb->status,fifon);
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);
1196 - (urb->actual_length - fifo->rx_offset);
1197 - fifo->buff->len +=
1198 - (urb->actual_length - fifo->rx_offset);
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) {
1212 - skb_queue_tail(hfc->regd.
1218 - queue_task(&hfc->l1_tq,
1220 - mark_bh(IMMEDIATE_BH);
1222 +} /* tx_iso_complete */
1224 - case HFCUSB_B1_RX:
1225 - if (hfc->regd.brq[0]) {
1246 - case HFCUSB_B2_RX:
1247 - if (hfc->regd.brq[1]) {
1268 +/*****************************************************/
1269 +/* receive completion routine for all ISO tx fifos */
1270 +/*****************************************************/
1271 +static void rx_iso_complete(struct urb *urb)
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;
1279 - case HFCUSB_PCM_RX:
1280 - skb_queue_tail(&hfc->regd.
1286 - queue_task(&hfc->l1_tq,
1288 - mark_bh(IMMEDIATE_BH);
1290 + fifon=fifo->fifonum;
1291 + // very weird error code when using ohci drivers, for now : ignore this error ... (MB)
1292 + if(urb->status == -EOVERFLOW)
1295 +#ifdef VERBOSE_USB_DEBUG
1296 + printk(KERN_INFO "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",fifon);
1301 - dev_kfree_skb_any(fifo->
1304 + if(fifo->active && !urb->status)
1306 + num_isoc_packets=iso_packets[fifon];
1308 + // Generate D-Channel Iso Packets
1309 + for(k = 0; k < num_isoc_packets; ++k)
1311 + len=urb->iso_frame_desc[k].actual_length;
1312 + offset=urb->iso_frame_desc[k].offset;
1313 + buf=context_iso_urb->buffer+offset;
1315 + if(fifo->last_urblen!=fifo->usb_packet_maxlen)
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);
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);
1330 + fifo->last_urblen=len;
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);
1338 + errcode = usb_submit_urb(urb);
1341 + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i \n", errcode);
1348 + printk(KERN_INFO "HFC-USB: rx_iso_complete : urb->status %i, fifonum %i\n", urb->status,fifon);
1351 +} /* rx_iso_complete */
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)
1359 + hfcusb_data *hfc = fifo->hfc;
1360 + int transp_mode,fifon;
1362 + fifon=fifo->fifonum;
1364 + if(fifon<4 && hfc->b_mode[fifon/2]==L1_MODE_TRANS) transp_mode=TRUE;
1366 + //printk(KERN_INFO "HFC-USB: got %d bytes finish:%d max_size:%d fifo:%d\n",len,finish,fifo->max_size,fifon);
1369 + // allocate sk buffer
1370 + fifo->skbuff=dev_alloc_skb(fifo->max_size + 3);
1373 + printk(KERN_INFO "HFC-USB: cannot allocate buffer (dev_alloc_skb) fifo:%d\n",fifon);
1379 + if(len && fifo->skbuff->len+len<fifo->max_size)
1381 + memcpy(skb_put(fifo->skbuff,len),data,len);
1383 + else printk(KERN_INFO "HCF-USB: got frame exceeded fifo->max_size:%d\n",fifo->max_size);
1385 + // give transparent data up, when 128 byte are available
1386 + if(transp_mode && fifo->skbuff->len>=128)
1388 + fifo->hif->l1l2(fifo->hif,PH_DATA | INDICATION,fifo->skbuff);
1389 + fifo->skbuff = NULL; // buffer was freed from upper layer
1393 + // we have a complete hdlc packet
1396 + if(!fifo->skbuff->data[fifo->skbuff->len-1])
1398 + skb_trim(fifo->skbuff,fifo->skbuff->len-3); // remove CRC & status
1400 + //printk(KERN_INFO "HFC-USB: got frame %d bytes on fifo:%d\n",fifo->skbuff->len,fifon);
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);
1405 + fifo->skbuff = NULL; // buffer was freed from upper layer
1409 + printk(KERN_INFO "HFC-USB: got frame %d bytes but CRC ERROR!!!\n",fifo->skbuff->len);
1411 + skb_trim(fifo->skbuff,0); // clear whole buffer
1415 + // LED flashing only in HDLC mode
1418 + if(fifon==HFCUSB_B1_RX) handle_led(hfc,LED_B1_DATA);
1419 + if(fifon==HFCUSB_B2_RX) handle_led(hfc,LED_B2_DATA);
1423 +/***********************************************/
1424 +/* receive completion routine for all rx fifos */
1425 +/***********************************************/
1426 +static void rx_complete(struct urb *urb)
1430 + usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */
1431 + hfcusb_data *hfc = fifo->hfc;
1433 + urb->dev = hfc->dev; /* security init */
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);
1439 + fifo->urb->interval = 0; /* cancel automatic rescheduling */
1440 + if(fifo->skbuff) {
1441 + dev_kfree_skb_any(fifo->skbuff);
1442 + fifo->skbuff = NULL;
1446 - fifo->rx_offset = (urb->actual_length < fifo->usb_maxlen) ? 2 : 0;
1447 -} /* rx_complete */
1449 + len=urb->actual_length;
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);
1460 + collect_rx_frame(fifo,buf,urb->actual_length,0);
1462 + fifo->last_urblen=urb->actual_length;
1465 +} /* rx_complete */
1469 /***************************************************/
1470 /* start the interrupt transfer for the given fifo */
1471 /***************************************************/
1473 -start_rx_fifo(usb_fifo * fifo)
1474 +static void start_int_fifo(usb_fifo * fifo)
1477 - return; /* still active */
1480 - dev_alloc_skb(fifo->max_size + (fifo->transmode ? 0 : 3))))
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)) {
1492 +#ifdef VERBOSE_USB_DEBUG
1493 + printk(KERN_INFO "HFC-USB: starting intr IN fifo:%d\n", fifo->fifonum);
1496 + fifo->urb = usb_alloc_urb(0);
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);
1507 + printk(KERN_INFO "HFC-USB: submit URB error(start_int_info): status:%i\n", errcode);
1509 - fifo->hfc->active_fifos &= ~fifo->fifo_mask;
1510 - dev_kfree_skb_any(fifo->buff);
1511 - fifo->buff = NULL;
1512 + fifo->skbuff = NULL;
1514 -} /* start_rx_fifo */
1515 +} /* start_int_fifo */
1517 -/***************************************************************/
1518 -/* control completion routine handling background control cmds */
1519 -/***************************************************************/
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)
1527 - hfcusb_data *hfc = (hfcusb_data *) urb->context;
1528 + __u8 val,idx_table[2]={0,2};
1530 - urb->dev = hfc->dev;
1531 - if (hfc->ctrl_cnt) {
1532 - switch (hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg) {
1535 - hfc->ctrl_buff[hfc->ctrl_out_idx].
1538 - case HFCUSB_F_USAGE:
1539 - if (!hfc->dfifo_fill) {
1540 - fill_tx_urb(hfc->fifos +
1542 - if (hfc->fifos[HFCUSB_D_TX].buff)
1543 - usb_submit_urb(&hfc->
1548 - queue_control_request(hfc,
1551 - queue_control_request(hfc,
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->
1565 - case HFCUSB_B2_RX:
1566 - if (hfc->bch_enables & 2)
1567 - start_rx_fifo(hfc->
1573 - if (hfc->bch_enables & 3)
1574 - hfc->led_req |= LED_BCH;
1576 - hfc->led_req &= ~LED_BCH;
1578 - case HFCUSB_P_DATA:
1580 - hfc->ctrl_buff[hfc->ctrl_out_idx].
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);
1592 + hfc->b_mode[channel]=mode;
1596 + if(mode!=L1_MODE_NULL) val=8; // enable fifo?
1597 + if(mode==L1_MODE_TRANS) val|=2; // set transparent bit
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
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
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);
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);
1617 + if(mode==L1_MODE_NULL)
1619 + if(channel) handle_led(hfc,LED_B2_OFF);
1620 + else handle_led(hfc,LED_B1_OFF);
1622 -} /* ctrl_complete */
1625 + if(channel) handle_led(hfc,LED_B2_ON);
1626 + else handle_led(hfc,LED_B1_ON);
1630 -/*****************************************/
1631 -/* Layer 1 + D channel access from HiSax */
1632 -/*****************************************/
1634 -hfcusb_l1_access(void *drvarg, int pr, void *arg)
1636 - hfcusb_data *hfc = (hfcusb_data *) drvarg;
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].
1652 - case (PH_ACTIVATE | REQUEST):
1653 - switch (hfc->l1_state) {
1656 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
1658 - INDICATION), NULL);
1660 + --------------------------------------------------------------------------------------
1661 + from here : hisax_if callback routines :
1662 + - void hfc_usb_d_l2l1(struct hisax_if *hisax_d_if, int pr, void *arg) {
1666 - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
1668 - INDICATION), NULL);
1669 + l1 to l2 routines :
1670 + - static void hfc_usb_l1l2(hfcusb_data * hfc)
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);
1684 - case (PH_DEACTIVATE | REQUEST):
1685 - queue_control_request(hfc, HFCUSB_STATES, 0x40); /* start deactivation */
1688 - printk(KERN_INFO "unknown hfcusb l1_access 0x%x\n",
1692 -} /* hfcusb_l1_access */
1694 -/*******************************/
1695 -/* B channel access from HiSax */
1696 -/*******************************/
1698 -hfcusb_bch_access(void *drvarg, int chan, int pr, void *arg)
1700 - hfcusb_data *hfc = (hfcusb_data *) drvarg;
1701 - usb_fifo *fifo = hfc->fifos + (chan ? HFCUSB_B2_TX : HFCUSB_B1_TX);
1705 - case (PH_DATA | REQUEST):
1706 - case (PH_PULL | INDICATION):
1707 - save_flags(flags);
1709 - if (!fifo->active) {
1710 - fill_tx_urb(fifo);
1711 - hfc->active_fifos |= fifo->fifo_mask;
1712 - usb_submit_urb(&fifo->urb);
1714 - restore_flags(flags);
1716 - case (PH_ACTIVATE | REQUEST):
1717 - if (!((int) arg)) {
1718 - hfc->bch_enables &= ~(1 << chan);
1719 - if (fifo->active) {
1721 - usb_unlink_urb(&fifo->urb);
1722 +void hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg)
1724 + usb_fifo *fifo = my_hisax_if->priv;
1725 + hfcusb_data *hfc = fifo->hfc;
1728 + case PH_ACTIVATE | REQUEST:
1729 + if(fifo->fifonum==HFCUSB_D_TX)
1731 +#ifdef VERBOSE_ISDN_DEBUG
1732 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST\n");
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);
1738 - save_flags(flags);
1740 - queue_control_request(hfc, HFCUSB_FIFO,
1742 - queue_control_request(hfc,
1743 - HFCUSB_INC_RES_F, 2);
1744 - queue_control_request(hfc, HFCUSB_CON_HDLC,
1746 - queue_control_request(hfc, HFCUSB_SCTRL,
1748 - hfc->bch_enables);
1749 - queue_control_request(hfc, HFCUSB_SCTRL_R,
1750 - hfc->bch_enables);
1751 - restore_flags(flags);
1753 - if (fifo->active) {
1755 - usb_unlink_urb(&fifo->urb);
1758 +#ifdef VERBOSE_ISDN_DEBUG
1759 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_ACTIVATE | REQUEST\n");
1761 + set_hfcmode(hfc,(fifo->fifonum==HFCUSB_B1_TX) ? 0 : 1 ,(int)arg);
1762 + fifo->hif->l1l2(fifo->hif,PH_ACTIVATE | INDICATION, NULL);
1764 - return; /* fifo deactivated */
1766 - fifo->transmode = ((int) arg == L1_MODE_TRANS);
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);
1775 - queue_control_request(hfc, HFCUSB_FIFO,
1777 - queue_control_request(hfc, HFCUSB_CON_HDLC,
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,
1786 - queue_control_request(hfc, HFCUSB_FIFO,
1787 - fifo->fifonum + 1);
1788 - queue_control_request(hfc, HFCUSB_CON_HDLC,
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);
1800 - "unknown hfcusb bch_access chan %d 0x%x\n",
1804 -} /* hfcusb_bch_access */
1806 + case PH_DEACTIVATE | REQUEST:
1807 + if(fifo->fifonum==HFCUSB_D_TX)
1809 +#ifdef VERBOSE_ISDN_DEBUG
1810 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST\n");
1812 + printk (KERN_INFO "HFC-USB: ISDN TE device should not deativate...\n");
1816 +#ifdef VERBOSE_ISDN_DEBUG
1817 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST\n");
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);
1823 + case PH_DATA | REQUEST:
1824 + if(fifo->skbuff && fifo->delete_flg)
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;
1832 + fifo->skbuff=arg; // we have a new buffer
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");
1838 + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x\n", pr);
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
1851 + --------------------------------------------------------------------------------------
1852 + From here on USB initialization and deactivation related routines are implemented :
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
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
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
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
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.
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 /***************************************************************************/
1891 -usb_init(hfcusb_data * hfc)
1892 +static int usb_init(hfcusb_data * hfc)
1899 + struct hisax_b_if *p_b_if[2];
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");
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);
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
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));
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);
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 */
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));
1953 - for (i = 0, fifo = hfc->fifos + i; i < HFCUSB_NUM_FIFOS;
1955 - Write_hfc(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
1957 - fifo->transmode = 0; /* hdlc mode selected */
1958 - fifo->buff = NULL; /* init buffer pointer */
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 */
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++)
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 */
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 */
1987 + write_usb(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */
1988 + write_usb(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + capacitive mode */
1990 + // set both B-channel to not connected
1991 + hfc->b_mode[0]=L1_MODE_NULL;
1992 + hfc->b_mode[1]=L1_MODE_NULL;
1994 + hfc->l1_activated=FALSE;
1996 + hfc->led_new_data=0;
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;
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);
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);
2034 - /* init the E-buffer */
2035 - skb_queue_head_init(&hfc->regd.erq);
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 */
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);
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);
2072 + /* Init All Fifos */
2073 + for(i = 0; i < HFCUSB_NUM_FIFOS; i++)
2075 + hfc->fifos[i].iso[0].purb = NULL;
2076 + hfc->fifos[i].iso[1].purb = NULL;
2077 + hfc->fifos[i].active = 0;
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;
2085 + for (i=0; i<2; i++)
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];
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);
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;
2100 + // 3 (+1) INT IN + 3 ISO OUT
2101 + if(hfc->cfg_used == CNF_3INT3ISO || hfc->cfg_used == CNF_4INT3ISO)
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
2109 + // 3 (+1) ISO IN + 3 ISO OUT
2110 + if(hfc->cfg_used==CNF_3ISO3ISO || hfc->cfg_used==CNF_4ISO3ISO)
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);
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);
2122 + handle_led(hfc,LED_POWER_ON);
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 */
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");
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
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]=
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
2166 +// string description of chosen config
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"
2178 /*************************************************/
2179 /* function called to probe a new plugged device */
2180 /*************************************************/
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)
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)
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;
2200 -#ifdef COMPAT_HAS_USB_IDTAB
2201 - if (id_table && (dev->descriptor.idVendor == id_table->idVendor) &&
2202 - (dev->descriptor.idProduct == id_table->idProduct) &&
2204 - if ((((dev->descriptor.idVendor == 0x959) &&
2205 - (dev->descriptor.idProduct == 0x2bd0)) ||
2206 - ((dev->descriptor.idVendor == 0x7b0) &&
2207 - (dev->descriptor.idProduct == 0x0006))) &&
2209 - (ifdp->bNumEndpoints >= 6) && (ifdp->bNumEndpoints <= 16)) {
2210 - if (!(context = kmalloc(sizeof(hfcusb_data), GFP_KERNEL))) {
2211 - return (NULL); /* got no mem */
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)) {
2219 - idx = (((epd->bEndpointAddress & 0x7f) - 1) << 1); /* get endpoint base */
2221 - switch (epd->bmAttributes) {
2222 - case USB_ENDPOINT_XFER_INT:
2225 - bEndpointAddress &
2227 - break; /* only interrupt in allowed */
2228 - idx++; /* input index is odd */
2229 - context->fifos[idx].pipe =
2230 - usb_rcvintpipe(dev,
2232 - bEndpointAddress);
2235 - case USB_ENDPOINT_XFER_BULK:
2237 - bEndpointAddress &
2239 - break; /* only bulk out allowed */
2240 - context->fifos[idx].pipe =
2241 - usb_sndbulkpipe(dev,
2243 - bEndpointAddress);
2246 - context->fifos[idx].pipe = 0; /* reset data */
2247 - } /* switch attribute */
2249 - if (context->fifos[idx].pipe) {
2250 - context->fifos[idx].fifonum = idx;
2251 - context->fifos[idx].fifo_mask =
2253 - context->fifos[idx].hfc = context;
2254 - context->fifos[idx].usb_maxlen =
2255 - epd->wMaxPacketSize;
2256 - context->fifos[idx].intervall =
2258 - ep_msk |= (1 << idx);
2260 - ep_msk &= ~(1 << idx);
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;
2274 +// usb_show_device(dev);
2275 +// usb_show_device_descriptor(&dev->descriptor);
2276 +// usb_show_interface_descriptor(&iface->desc);
2278 + for(i=0;vdata[i].vendor;i++)
2280 + if(dev->descriptor.idVendor==vdata[i].vendor && dev->descriptor.idProduct==vdata[i].prod_id) vend_idx=i;
2284 - if ((ep_msk & 0x3f) != 0x3f) {
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 */
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);
2298 - /* init the chip and register the driver */
2299 - if (usb_init(context)) {
2301 - MOD_DEC_USE_COUNT;
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); */
2312 - "HFC-USB: New device if=%d alt=%d registered\n",
2313 - context->if_used, context->alt_used);
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);
2320 + /* if vendor and product ID is OK, start probing a matching alternate setting ... */
2322 + small_match=0xffff;
2323 + // default settings
2324 + iso_packet_size=16;
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;
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);
2338 + // check for config EOL element
2339 + while (validconf[cfg_used][0]) {
2341 + vcf=validconf[cfg_used];
2342 + ep = intfdesc->endpoint; /* first endpoint descriptor */
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);
2349 + memcpy(cmptbl,vcf,16*sizeof(int));
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)
2357 + attr = ep->bmAttributes;
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;
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;
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
2376 + printk(KERN_INFO "HFC-USB: Interrupt Endpoint interval < %d found - skipping config\n",
2379 + cfg_found = FALSE;
2385 + for (i = 0; i < 16; i++) {
2386 + // printk(KERN_INFO "HFC-USB: cmptbl[%d]:%d\n", i, cmptbl[i]);
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;
2393 + // we check for smallest match, to provide configuration priority
2394 + // configurations with smaller index have higher priority
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;
2402 +#ifdef VERBOSE_USB_DEBUG
2403 + printk(KERN_INFO "HFC-USB: small_match=%x %x\n", small_match, alt_used);
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);
2415 + // yiipiee, we found a valid config
2416 + if (small_match != 0xffff) {
2417 + //iface = iface_used;
2418 + intfdesc = intfdesc_used;
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 */
2424 + ep = intfdesc->endpoint; /* first endpoint descriptor */
2425 + vcf = validconf[small_match];
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)
2433 + attr = ep->bmAttributes;
2435 + // only initialize used endpoints
2436 + if (vcf[idx] != EP_NOP && vcf[idx] != EP_NUL) {
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);
2447 + case USB_ENDPOINT_XFER_BULK:
2448 + if (ep_addr & 0x80)
2449 + context->fifos[cidx].pipe = usb_rcvbulkpipe(dev, ep->bEndpointAddress);
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",
2459 + case USB_ENDPOINT_XFER_ISOC:
2460 + if (ep_addr & 0x80)
2461 + context->fifos[cidx].pipe = usb_rcvisocpipe(dev, ep->bEndpointAddress);
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",
2472 + context->fifos[cidx].pipe = 0; /* reset data */
2473 + } /* switch attribute */
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);
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;
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);
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);
2511 + /* init the chip and register the driver */
2512 + if (usb_init(context))
2514 + if (context->ctrl_urb) {
2515 + usb_unlink_urb(context->ctrl_urb);
2516 + usb_free_urb(context->ctrl_urb);
2517 + context->ctrl_urb = NULL;
2522 + //usb_set_intfdata(intf, context);
2523 + //intf->private_data = context;
2530 /****************************************************/
2531 /* function called when an active device is removed */
2532 /****************************************************/
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)
2538 - hfcusb_data *context = drv_context;
2539 + //hfcusb_data *context = intf->private_data;
2540 + hfcusb_data* context = drv_context;
2542 - struct sk_buff *skb;
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);
2550 - while (context->active_fifos) {
2551 - set_current_state(TASK_INTERRUPTIBLE);
2552 - /* Timeout 10ms */
2553 - schedule_timeout((10 * HZ) / 1000);
2555 + printk(KERN_INFO "HFC-USB: device disconnect\n");
2557 + //intf->private_data = NULL;
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);
2570 + hisax_unregister(&context->d_if);
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);
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);
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;
2594 + context->fifos[i].active = 0;
2596 + if (context->ctrl_urb) {
2597 + usb_unlink_urb(context->ctrl_urb);
2598 + usb_free_urb(context->ctrl_urb);
2599 + context->ctrl_urb = NULL;
2601 kfree(context); /* free our structure again */
2602 - MOD_DEC_USE_COUNT; /* and decrement the usage counter */
2603 } /* hfc_usb_disconnect */
2606 /************************************/
2607 /* our driver information structure */
2608 /************************************/
2609 static struct usb_driver hfc_drv = {
2611 -#ifdef COMPAT_HAS_USB_IDTAB
2612 id_table:hfc_usb_idtab,
2614 probe:hfc_usb_probe,
2615 disconnect:hfc_usb_disconnect,
2622 +static void __exit hfc_usb_exit(void)
2624 +#ifdef VERBOSE_USB_DEBUG
2625 + printk ("HFC-USB: calling \"hfc_usb_exit\" ...\n");
2627 usb_deregister(&hfc_drv); /* release our driver */
2628 printk(KERN_INFO "HFC-USB module removed\n");
2633 +static int __init hfc_usb_init(void)
2635 - struct hisax_drvreg drv;
2636 + printk ("HFC-USB: driver module revision %s loaded\n", hfcusb_revision);
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 */
2644 - if (usb_register(&hfc_drv)) {
2646 - "Unable to register HFC-USB module at usb stack\n");
2647 - return (-1); /* unable to register */
2648 + if(usb_register(&hfc_drv))
2650 + printk(KERN_INFO "HFC-USB: Unable to register HFC-USB module at usb stack\n");
2651 + return(-1); /* unable to register */
2654 - printk(KERN_INFO "HFC-USB module loaded\n");
2663 module_init(hfc_usb_init);
2664 module_exit(hfc_usb_exit);